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) { ...@@ -24,19 +24,19 @@ function select_opts(Array $options, $selected = null, $echo = true) {
24 24
25 function select_opts_provinces($selected = null, $echo = true) { 25 function select_opts_provinces($selected = null, $echo = true) {
26 $return = "<option>Select a State/Province</option>"; 26 $return = "<option>Select a State/Province</option>";
27 27
28 $return .= '<optgroup label="Canada">'; 28 $return .= '<optgroup label="Canada">';
29 $return .= select_opts(Vars::$provinces['CA'], $selected, false); 29 $return .= select_opts(Vars::$provinces['CA'], $selected, false);
30 $return .= '</optgroup>'; 30 $return .= '</optgroup>';
31 31
32 $return .= '<optgroup label="United States">'; 32 $return .= '<optgroup label="United States">';
33 $return .= select_opts(Vars::$provinces['US'], $selected, false); 33 $return .= select_opts(Vars::$provinces['US'], $selected, false);
34 $return .= '</optgroup>'; 34 $return .= '</optgroup>';
35 35
36 $return .= '<optgroup label="Other">'; 36 $return .= '<optgroup label="Other">';
37 $return .= '<option value="other">Outside Canada/USA</option>'; 37 $return .= '<option value="other">Outside Canada/USA</option>';
38 $return .= '</optgroup>'; 38 $return .= '</optgroup>';
39 39
40 return $return; 40 return $return;
41 } 41 }
42 42
...@@ -99,11 +99,11 @@ function validateDate( $date, $format='YYYY-MM-DD') ...@@ -99,11 +99,11 @@ function validateDate( $date, $format='YYYY-MM-DD')
99 default: 99 default:
100 throw new Exception( "Invalid Date Format" ); 100 throw new Exception( "Invalid Date Format" );
101 } 101 }
102 102
103 return checkdate( $m, $d, $y ); 103 return checkdate( $m, $d, $y );
104 104
105 105
106 106
107 } 107 }
108 108
109 function validate_creditcard($cc_num, $type) { 109 function validate_creditcard($cc_num, $type) {
...@@ -114,7 +114,7 @@ function validate_creditcard($cc_num, $type) { ...@@ -114,7 +114,7 @@ function validate_creditcard($cc_num, $type) {
114 $verified = true; 114 $verified = true;
115 } else { 115 } else {
116 $verified = false; 116 $verified = false;
117 } 117 }
118 } elseif ($type == "mc") { 118 } elseif ($type == "mc") {
119 $pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard 119 $pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard
120 if (preg_match($pattern,$cc_num)) { 120 if (preg_match($pattern,$cc_num)) {
...@@ -130,7 +130,7 @@ function validate_creditcard($cc_num, $type) { ...@@ -130,7 +130,7 @@ function validate_creditcard($cc_num, $type) {
130 $verified = false; 130 $verified = false;
131 } 131 }
132 } 132 }
133 133
134 return $verified; 134 return $verified;
135 } 135 }
136 136
...@@ -190,7 +190,7 @@ if ( ! function_exists('form_dropdown')) ...@@ -190,7 +190,7 @@ if ( ! function_exists('form_dropdown'))
190 } 190 }
191 } 191 }
192 192
193 function form_linked_dropdown($name = '', $parent = '', $options = array(), $parent_selected = '', $selected = '', $extra = '') 193 function form_linked_dropdown($name = '', $parent = '', $options = array(), $parent_selected = '', $selected = '', $extra = '', $provide_js = true)
194 { 194 {
195 if ($extra != '') $extra = ' '.$extra; 195 if ($extra != '') $extra = ' '.$extra;
196 196
...@@ -204,23 +204,24 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par ...@@ -204,23 +204,24 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par
204 204
205 $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n"; 205 $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
206 } 206 }
207 } 207 }
208 208
209 $form .= '</select> 209 if ($provide_js) {
210 $form .= '</select>
210 <script> 211 <script>
211 function update_' . $name . '(value) { 212 function update_' . $name . '(value) {
212 213
213 if (value=="") { 214 if (value=="") {
214 return; 215 return;
215 } 216 }
216 217
217 jQuery("#'.$name.'_custom").attr("disabled","disabled").hide(); 218 jQuery("#' . $name . '_custom").attr("disabled","disabled").hide();
218 jQuery("#'.$name.'").show(); 219 jQuery("#' . $name . '").show();
219 220
220 221
221 var options = new Array(); 222 var options = new Array();
222 var select = document.getElementById("' . $name . '"); 223 var select = document.getElementById("' . $name . '");
223 select.disabled = false; 224 select.disabled = false;
224 while (select.firstChild) 225 while (select.firstChild)
225 select.removeChild(select.firstChild); 226 select.removeChild(select.firstChild);
226 switch (value.toString()) {'; 227 switch (value.toString()) {';
...@@ -230,41 +231,50 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par ...@@ -230,41 +231,50 @@ function form_linked_dropdown($name = '', $parent = '', $options = array(), $par
230 foreach ($v as $value => $content) { 231 foreach ($v as $value => $content) {
231 $form .= '"' . $value . '","' . $content . '",'; 232 $form .= '"' . $value . '","' . $content . '",';
232 } 233 }
233 $form = substr($form,0,-1); 234 $form = substr($form, 0, -1);
234 $form .= '); 235 $form .= ');
235 break;'; 236 break;';
236 } 237 }
237 $form .= 'default: 238 $form .= 'default:
238 select.disabled = true; 239 select.disabled = true;
239 240
240 jQuery("#'.$name.'").after("<input type=\'text\' name=\''.$name.'\' id=\''.$name.'_custom\' class=\'input-field-css input-large\' value=\''.$selected.'\' />").removeAttr("disabled").show(); 241 jQuery("#' . $name . '").after("<input type=\'text\' name=\'' . $name . '\' id=\'' . $name . '_custom\' class=\'input-field-css input-large\' value=\'' . $selected . '\' />").removeAttr("disabled").show();
241 jQuery("#'.$name.'").hide(); 242 jQuery("#' . $name . '").hide();
242 //options = new Array("other","Other"); 243 //options = new Array("other","Other");
243 return; 244 return;
244 } 245 }
245 246
246 var option = document.createElement("option"); 247 var option = document.createElement("option");
247 var val = ""; 248 var val = "";
248 option.val = val; 249 option.val = val;
249 option.innerHTML = "Select..."; 250 option.innerHTML = "Select...";
250 select.appendChild(option); 251 select.appendChild(option);
251 252
252 for(var i = 0; i < options.length;) { 253 for(var i = 0; i < options.length;) {
253 var option = document.createElement("option"); 254 var option = document.createElement("option");
254 var val = options[i++]; 255 var val = options[i++];
255 option.value = val; 256 option.value = val;
256 option.innerHTML = options[i++]; 257 option.innerHTML = options[i++];
257 if (val == "'.$selected.'") { 258 if (val == "' . $selected . '") {
258 option.selected = true; 259 option.selected = true;
259 } 260 }
260 select.appendChild(option); 261 select.appendChild(option);
261 } 262 }
262 263
263 } 264 }
264 update_'.$name.'(document.getElementById("'.$parent.'").value); 265 update_' . $name . '(document.getElementById("' . $parent . '").value);
265 document.getElementById("' . $parent . '").onchange = function() { update_' . $name . '(this.value); } 266 document.getElementById("' . $parent . '").onchange = function() { update_' . $name . '(this.value); }
266 </script> 267 </script>
267 '; 268 ';
269 } else {
270 $form = '';
271 if (array_key_exists($parent_selected, $options)) {
272 foreach ($options[$parent_selected] as $name => $option) {
273 $sel = ($selected == $name) ? ' selected="selected"' : '';
274 $form .= '<option value="' . $name . '"' . $sel . '>' . $option . "</option>\n";
275 }
276 }
277 }
268 278
269 return $form; 279 return $form;
270 } 280 }
...@@ -323,7 +333,7 @@ class Vars { ...@@ -323,7 +333,7 @@ class Vars {
323 , 'Dr.' => 'Dr.' 333 , 'Dr.' => 'Dr.'
324 , 'Prof.' => 'Prof.' 334 , 'Prof.' => 'Prof.'
325 ); 335 );
326 336
327 public static $company_types = Array( 337 public static $company_types = Array(
328 'advisory_firm' => "Advisory Firm" 338 'advisory_firm' => "Advisory Firm"
329 , 'litigation_firm' => "Litigation Firm" 339 , 'litigation_firm' => "Litigation Firm"
...@@ -340,7 +350,7 @@ class Vars { ...@@ -340,7 +350,7 @@ class Vars {
340 , 'mutual_fund_co' => "Mutual Fund Management Company" 350 , 'mutual_fund_co' => "Mutual Fund Management Company"
341 , 'merchant_bank' => "Merchant Bank" 351 , 'merchant_bank' => "Merchant Bank"
342 ); 352 );
343 353
344 public static $countries = Array( 354 public static $countries = Array(
345 'CA' => 'Canada' 355 'CA' => 'Canada'
346 , 'US' => 'United States' 356 , 'US' => 'United States'
...@@ -657,13 +667,13 @@ class Vars { ...@@ -657,13 +667,13 @@ class Vars {
657 , 'WY' => 'Wyoming' 667 , 'WY' => 'Wyoming'
658 ) 668 )
659 ); 669 );
660 670
661 public static $securities = Array( 671 public static $securities = Array(
662 'S01' => "What is your Mother's maiden name?" 672 'S01' => "What is your Mother's maiden name?"
663 , 'S02' => "Who was you childhood hero?" 673 , 'S02' => "Who was you childhood hero?"
664 , 'S03' => "What is/was the name of your first pet?" 674 , 'S03' => "What is/was the name of your first pet?"
665 ); 675 );
666 676
667 public static $creditcards = Array( 677 public static $creditcards = Array(
668 'visa' => "Visa" 678 'visa' => "Visa"
669 , 'mc' => "MasterCard" 679 , 'mc' => "MasterCard"
......