746e8fd0 by Marty Penner

Admin user now able to set no location for country and province/state on event e…

…dit page; select lists now populate properly. refs #1222
1 parent deeada06
......@@ -24,19 +24,19 @@ function select_opts(Array $options, $selected = null, $echo = true) {
function select_opts_provinces($selected = null, $echo = true) {
$return = "<option>Select a State/Province</option>";
$return .= '<optgroup label="Canada">';
$return .= select_opts(Vars::$provinces['CA'], $selected, false);
$return .= '</optgroup>';
$return .= '<optgroup label="United States">';
$return .= select_opts(Vars::$provinces['US'], $selected, false);
$return .= '</optgroup>';
$return .= '<optgroup label="Other">';
$return .= '<option value="other">Outside Canada/USA</option>';
$return .= '</optgroup>';
return $return;
}
......@@ -99,11 +99,11 @@ function validateDate( $date, $format='YYYY-MM-DD')
default:
throw new Exception( "Invalid Date Format" );
}
return checkdate( $m, $d, $y );
}
function validate_creditcard($cc_num, $type) {
......@@ -114,7 +114,7 @@ function validate_creditcard($cc_num, $type) {
$verified = true;
} else {
$verified = false;
}
}
} elseif ($type == "mc") {
$pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard
if (preg_match($pattern,$cc_num)) {
......@@ -130,7 +130,7 @@ function validate_creditcard($cc_num, $type) {
$verified = false;
}
}
return $verified;
}
......@@ -190,7 +190,7 @@ if ( ! function_exists('form_dropdown'))
}
}
function form_linked_dropdown($name = '', $parent = '', $options = array(), $parent_selected = '', $selected = '', $extra = '')
function form_linked_dropdown($name = '', $parent = '', $options = array(), $parent_selected = '', $selected = '', $extra = '', $provide_js = true)
{
if ($extra != '') $extra = ' '.$extra;
......@@ -204,23 +204,24 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
}
}
$form .= '</select>
if ($provide_js) {
$form .= '</select>
<script>
function update_' . $name . '(value) {
if (value=="") {
return;
}
jQuery("#'.$name.'_custom").attr("disabled","disabled").hide();
jQuery("#'.$name.'").show();
jQuery("#' . $name . '_custom").attr("disabled","disabled").hide();
jQuery("#' . $name . '").show();
var options = new Array();
var select = document.getElementById("' . $name . '");
select.disabled = false;
select.disabled = false;
while (select.firstChild)
select.removeChild(select.firstChild);
switch (value.toString()) {';
......@@ -230,41 +231,50 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par
foreach ($v as $value => $content) {
$form .= '"' . $value . '","' . $content . '",';
}
$form = substr($form,0,-1);
$form = substr($form, 0, -1);
$form .= ');
break;';
}
$form .= 'default:
select.disabled = true;
jQuery("#'.$name.'").after("<input type=\'text\' name=\''.$name.'\' id=\''.$name.'_custom\' class=\'input-field-css input-large\' value=\''.$selected.'\' />").removeAttr("disabled").show();
jQuery("#'.$name.'").hide();
jQuery("#' . $name . '").after("<input type=\'text\' name=\'' . $name . '\' id=\'' . $name . '_custom\' class=\'input-field-css input-large\' value=\'' . $selected . '\' />").removeAttr("disabled").show();
jQuery("#' . $name . '").hide();
//options = new Array("other","Other");
return;
}
var option = document.createElement("option");
var val = "";
option.val = val;
option.innerHTML = "Select...";
select.appendChild(option);
for(var i = 0; i < options.length;) {
var option = document.createElement("option");
var val = options[i++];
option.value = val;
option.innerHTML = options[i++];
if (val == "'.$selected.'") {
if (val == "' . $selected . '") {
option.selected = true;
}
select.appendChild(option);
}
}
update_'.$name.'(document.getElementById("'.$parent.'").value);
update_' . $name . '(document.getElementById("' . $parent . '").value);
document.getElementById("' . $parent . '").onchange = function() { update_' . $name . '(this.value); }
</script>
';
} else {
$form = '';
if (array_key_exists($parent_selected, $options)) {
foreach ($options[$parent_selected] as $name => $option) {
$sel = ($selected == $name) ? ' selected="selected"' : '';
$form .= '<option value="' . $name . '"' . $sel . '>' . $option . "</option>\n";
}
}
}
return $form;
}
......@@ -323,7 +333,7 @@ class Vars {
, 'Dr.' => 'Dr.'
, 'Prof.' => 'Prof.'
);
public static $company_types = Array(
'advisory_firm' => "Advisory Firm"
, 'litigation_firm' => "Litigation Firm"
......@@ -340,7 +350,7 @@ class Vars {
, 'mutual_fund_co' => "Mutual Fund Management Company"
, 'merchant_bank' => "Merchant Bank"
);
public static $countries = Array(
'CA' => 'Canada'
, 'US' => 'United States'
......@@ -657,13 +667,13 @@ class Vars {
, 'WY' => 'Wyoming'
)
);
public static $securities = Array(
'S01' => "What is your Mother's maiden name?"
, 'S02' => "Who was you childhood hero?"
, 'S03' => "What is/was the name of your first pet?"
);
public static $creditcards = Array(
'visa' => "Visa"
, 'mc' => "MasterCard"
......