7f16456c by Kevin Burton

new drop downs for province/country

1 parent 0d72c06e
......@@ -116,6 +116,131 @@ function validate_creditcard($cc_num, $type) {
return $verified;
}
if ( ! function_exists('form_dropdown'))
{
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
if ( ! is_array($selected))
{
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name]))
{
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' '.$extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
$key = (string) $key;
if (is_array($val) && ! empty($val))
{
$form .= '<optgroup label="'.$key.'">'."\n";
foreach ($val as $optgroup_key => $optgroup_val)
{
$sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
}
$form .= '</optgroup>'."\n";
}
else
{
$sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
}
}
$form .= '</select>';
return $form;
}
}
function form_linked_dropdown($name = '', $parent = '', $options = array(), $parent_selected = '', $selected = '', $extra = '')
{
if ($extra != '') $extra = ' '.$extra;
$form = '<select name="'.$name.'" id="'.$name.'"'.$extra.">\n";
if (isset($options[$parent_selected]))
{
foreach ($options[$parent_selected] as $key => $val)
{
$sel = ($selected != $key) ? '' : ' selected="selected"';
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
}
$form .= '</select>
<script>
function update_' . $name . '(value) {
jQuery("#'.$name.'_custom").attr("disabled","disabled").hide();
jQuery("#'.$name.'").show();
var options = new Array();
var select = document.getElementById("' . $name . '");
select.disabled = false;
while (select.firstChild)
select.removeChild(select.firstChild);
switch (value.toString()) {';
foreach ($options as $k => $v) {
$form .= 'case "' . $k . '":
options = new Array(';
foreach ($v as $value => $content) {
$form .= '"' . $value . '","' . $content . '",';
}
$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();
//options = new Array("other","Other");
return;
}
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.'") {
option.selected = true;
}
select.appendChild(option);
}
}
update_'.$name.'(document.getElementById("'.$parent.'").value);
document.getElementById("' . $parent . '").onchange = function() { update_' . $name . '(this.value); }
</script>
';
return $form;
}
class Vars {
public static $prefixes = Array(
......@@ -130,26 +255,321 @@ class Vars {
);
public static $countries = Array(
'CA' => 'Canada'
, 'US' => 'United States'
, 'MX' => 'Mexico'
, 'Other' => 'Other'
'CA' => 'Canada'
, 'US' => 'United States'
, 'MX' => 'Mexico'
, 'AF' => 'Afghanistan'
, 'AR' => 'Argentina'
, 'AX' => 'Åland Islands'
, 'AL' => 'Albania'
, 'DZ' => 'Algeria'
, 'AS' => 'American Samoa'
, 'AD' => 'Andorra'
, 'AO' => 'Angola'
, 'AI' => 'Anguilla'
, 'AQ' => 'Antarctica'
, 'AG' => 'Antigua and Barbuda'
, 'AM' => 'Armenia'
, 'AW' => 'Aruba'
, 'AU' => 'Australia'
, 'AT' => 'Austria'
, 'AZ' => 'Azerbaijan'
, 'BS' => 'Bahamas'
, 'BH' => 'Bahrain'
, 'BD' => 'Bangladesh'
, 'BB' => 'Barbados'
, 'BY' => 'Belarus'
, 'BE' => 'Belgium'
, 'BZ' => 'Belize'
, 'BJ' => 'Benin'
, 'BM' => 'Bermuda'
, 'BT' => 'Bhutan'
, 'BO' => 'Bolivia'
, 'BA' => 'Bosnia and Herzegovina'
, 'BW' => 'Botswana'
, 'BV' => 'Bouvet Island'
, 'BR' => 'Brazil'
, 'IO' => 'British Indian Ocean Territory'
, 'BN' => 'Brunei Darussalam'
, 'BG' => 'Bulgaria'
, 'BF' => 'Burkina Faso'
, 'BI' => 'Burundi'
, 'KH' => 'Cambodia'
, 'CM' => 'Cameroon'
, 'CV' => 'Cape Verde'
, 'KY' => 'Cayman Islands'
, 'CF' => 'Central African Republic'
, 'TD' => 'Chad'
, 'CL' => 'Chile'
, 'CN' => 'China'
, 'CX' => 'Christmas Island'
, 'CC' => 'Cocos (Keeling) Islands'
, 'CO' => 'Columbia'
, 'KM' => 'Comoros'
, 'CG' => 'Congo'
, 'CD' => 'Congo, The Democratic Republic'
, 'CK' => 'Cook Islands'
, 'CR' => 'Costa Rica'
, 'CI' => 'Cote d’Ivoire – Really Ivory Coast'
, 'HR' => 'Croatia'
, 'CU' => 'Cuba'
, 'CY' => 'Cyprus'
, 'CZ' => 'Czech Republic'
, 'DK' => 'Denmark'
, 'DJ' => 'Djibouti'
, 'DM' => 'Dominica'
, 'DO' => 'Dominican Republic'
, 'TL' => 'East Timor'
, 'EC' => 'Ecuador'
, 'EG' => 'Egypt'
, 'SV' => 'El Salvador'
, 'GQ' => 'Equatorial Guinea'
, 'ER' => 'Eritrea'
, 'EE' => 'Estonia'
, 'ET' => 'Ethiopia'
, 'FK' => 'Falkland Islands'
, 'FO' => 'Faroe Islands'
, 'FJ' => 'Fiji'
, 'FI' => 'Finland'
, 'FR' => 'France'
, 'GF' => 'French Guiana'
, 'PF' => 'French Polynesia'
, 'TF' => 'French Southern Territories'
, 'GA' => 'Gabon'
, 'GM' => 'Gambia'
, 'GE' => 'Georgia'
, 'DE' => 'Germany'
, 'GH' => 'Ghana'
, 'GI' => 'Gibraltar'
, 'GB' => 'Great Britain'
, 'GR' => 'Greece'
, 'GL' => 'Greenland'
, 'GD' => 'Grenada'
, 'GP' => 'Guadeloupe'
, 'GU' => 'Guam'
, 'GT' => 'Guatemala'
, 'GN' => 'Guinea'
, 'GW' => 'Guinea Bissau'
, 'GY' => 'Guyana'
, 'HT' => 'Haiti'
, 'HM' => 'Heard and McDonald Islands'
, 'HN' => 'Honduras'
, 'HK' => 'Hong Kong'
, 'HU' => 'Hungary'
, 'IS' => 'Iceland'
, 'IN' => 'India'
, 'ID' => 'Indonesia'
, 'IR' => 'Iran, Islamic Republic of'
, 'IQ' => 'Iraq'
, 'IE' => 'Ireland'
, 'IL' => 'Israel'
, 'IT' => 'Italy'
, 'JM' => 'Jamaica'
, 'JP' => 'Japan'
, 'JO' => 'Jordan'
, 'KZ' => 'Kazakhstan'
, 'KE' => 'Kenya'
, 'KI' => 'Kiribati'
, 'KP' => "Korea, Democratic People's Republic"
, 'KR' => 'Korea, Republic of'
, 'KW' => 'Kuwait'
, 'KG' => 'Kyrgyzstan'
, 'LA' => "Lao People's Democratic Republic"
, 'LV' => 'Latvia'
, 'LB' => 'Lebanon'
, 'LI' => 'Liechtenstein'
, 'LS' => 'Lesotho'
, 'LR' => 'Liberia'
, 'LY' => 'Libyan Arab Jamahiriya'
, 'LT' => 'Lithuania'
, 'LU' => 'Luxembourg'
, 'MO' => 'Macau'
, 'MK' => 'Macedonia'
, 'MG' => 'Madagascar'
, 'MW' => 'Malawi'
, 'MY' => 'Malaysia'
, 'MV' => 'Maldives'
, 'ML' => 'Mali'
, 'MT' => 'Malta'
, 'MH' => 'Marshall Islands'
, 'MQ' => 'Martinique'
, 'MR' => 'Mauritania'
, 'MU' => 'Mauritius'
, 'YT' => 'Mayotte'
, 'MX' => 'Mexico'
, 'FM' => "Micronesia, Federated States of"
, 'MD' => 'Moldova, Republic of'
, 'MC' => 'Monaco'
, 'MN' => 'Mongolia'
, 'MS' => 'Montserrat'
, 'MA' => 'Morocco'
, 'MZ' => "Mozambique"
, 'MM' => 'Myanmar'
, 'NA' => 'Namibia'
, 'NR' => 'Nauru'
, 'NP' => 'Nepal'
, 'NL' => 'Netherlands'
, 'NA' => 'Netherlands Antilles'
, 'NC' => 'New Caledonia'
, 'NZ' => 'New Zealand'
, 'NI' => 'Nicaragua'
, 'NE' => 'Niger'
, 'NG' => 'Nigeria'
, 'NU' => 'Niue'
, 'NF' => 'Norfolk Island'
, 'MP' => 'Northern Mariana Islands'
, 'NO' => "Norway"
, 'OM' => 'Oman'
, 'PK' => 'Pakistan'
, 'PW' => 'Palau'
, 'PS' => 'Palestinian Territory, Occupied'
, 'PA' => 'Panama'
, 'PG' => 'Papua New Guinea'
, 'PY' => 'Paraguay'
, 'PE' => 'Peru'
, 'PH' => 'Philippines'
, 'PN' => 'Pitcairn'
, 'PL' => 'Poland'
, 'PT' => 'Portugal'
, 'PR' => 'Puerto Rico'
, 'QA' => 'Qatar'
, 'RE' => 'Reunion'
, 'RO' => 'Romania'
, 'RU' => 'Russian Federation'
, 'RW' => 'Rwanda'
, 'KN' => 'Saint Kitts and Nevis'
, 'LC' => 'Saint Lucia'
, 'VC' => 'Saint Vincent and the Grenadines'
, 'WS' => 'Samoa'
, 'SM' => 'San Marino'
, 'ST' => 'Sao Tome and Principe'
, 'SA' => 'Saudi Arabia'
, 'SN' => 'Senegal'
, 'CS' => 'Serbia and Montenegro'
, 'SC' => 'Seychelles'
, 'SL' => 'Sierra Leone'
, 'SG' => 'Singapore'
, 'SK' => 'Slovakia'
, 'SI' => 'Slovenia'
, 'SB' => 'Solomon Islands'
, 'SO' => 'Somalia'
, 'ZA' => 'South Africa'
, 'GS' => 'South Georgia – South Sandwich Islands'
, 'ES' => 'Spain'
, 'LK' => 'Sri Lanka'
, 'SH' => 'St. Helena'
, 'PM' => 'St. Pierre and Miquelon'
, 'SD' => 'Sudan'
, 'SR' => 'Suriname'
, 'SJ' => 'Svalbard and Jan Mayen'
, 'SZ' => 'Swaziland'
, 'SE' => 'Sweden'
, 'CH' => 'Switzerland'
, 'SY' => 'Syrian Arab Republic'
, 'TW' => 'Taiwan'
, 'TJ' => 'Tajikistan'
, 'TZ' => 'Tanzania, United Republic of'
, 'TH' => 'Thailand'
, 'TG' => 'Togo'
, 'TK' => 'Tokelau'
, 'TO' => 'Tonga'
, 'TT' => 'Trinidad and Tobago'
, 'TN' => 'Tunisia'
, 'TR' => 'Turkey'
, 'TM' => 'Turkmenistan'
, 'TC' => 'Turks and Caicos Islands'
, 'TV' => 'Tuvalu'
, 'UG' => 'Uganda'
, 'UA' => 'Ukraine'
, 'AE' => 'United Arab Emirates'
, 'UM' => 'United States Minor Outlying Islands'
, 'UY' => 'Uruguay'
, 'UZ' => 'Uzbekistan'
, 'VU' => 'Vanuatu'
, 'VA' => 'Vatican City state'
, 'VE' => 'Venezuela'
, 'VN' => 'Viet Nam'
, 'VG' => 'Virgin Islands (British)'
, 'VI' => 'Virgin Islands (US)'
, 'WF' => 'Wallis and Futuna'
, 'EH' => 'Western Sahara'
, 'YE' => 'Yemen'
, 'ZM' => 'Zambia'
, 'ZW' => 'Zimbabwe'
);
public static $provinces = Array(
'AB' => 'Alberta'
, 'BC' => 'British Columbia'
, 'MB' => 'Manitoba'
, 'NB' => 'New Brunswick'
, 'NL' => 'Newfoundland and Labrador'
, 'NT' => 'Northwest Territories'
, 'NS' => 'Nova Scotia'
, 'NU' => 'Nunavut'
, 'PE' => 'Prince Edward Island'
, 'SK' => 'Saskatchewan'
, 'ON' => 'Ontario'
, 'QC' => 'Quebec'
, 'YT' => 'Yukon'
'CA' => array(
'AB' => 'Alberta'
, 'BC' => 'British Columbia'
, 'MB' => 'Manitoba'
, 'NB' => 'New Brunswick'
, 'NL' => 'Newfoundland and Labrador'
, 'NT' => 'Northwest Territories'
, 'NS' => 'Nova Scotia'
, 'NU' => 'Nunavut'
, 'PE' => 'Prince Edward Island'
, 'SK' => 'Saskatchewan'
, 'ON' => 'Ontario'
, 'QC' => 'Quebec'
, 'YT' => 'Yukon'
)
, 'US' => array(
'AL' => 'Alabama'
, 'AK' => 'Alaska'
, 'AZ' => 'Arizona'
, 'AR' => 'Arkansas'
, 'CA' => 'California'
, 'CO' => 'Colorado'
, 'CT' => 'Connecticut'
, 'DE' => 'Delaware'
, 'DC' => 'District of Columbia'
, 'FL' => 'Florida'
, 'GA' => 'Georgia'
, 'GU' => 'Guam'
, 'HI' => 'Hawaii'
, 'ID' => 'Idaho'
, 'IL' => 'Illinois'
, 'IN' => 'Indiana'
, 'IA' => 'Iowa'
, 'KS' => 'Kansas'
, 'KY' => 'Kentucky'
, 'LA' => 'Louisiana'
, 'ME' => 'Maine'
, 'MD' => 'Maryland'
, 'MA' => 'Massachusetts'
, 'MI' => 'Michigan'
, 'MN' => 'Minnesota'
, 'MS' => 'Mississippi'
, 'MO' => 'Missouri'
, 'MT' => 'Montana'
, 'NE' => 'Nebraska'
, 'NV' => 'Nevada'
, 'NH' => 'New Hampshire'
, 'NJ' => 'New Jersey'
, 'NM' => 'New Mexico'
, 'NY' => 'New York'
, 'NC' => 'North Carolina'
, 'ND' => 'North Dakota'
, 'OH' => 'Ohio'
, 'OK' => 'Oklahoma'
, 'OR' => 'Oregon'
, 'PA' => 'Pennyslvania'
, 'PR' => 'Puerto Rico'
, 'RI' => 'Rhode Island'
, 'SC' => 'South Carolina'
, 'SD' => 'South Dakota'
, 'TN' => 'Tennessee'
, 'TX' => 'Texas'
, 'UT' => 'Utah'
, 'VT' => 'Vermont'
, 'VA' => 'Virginia'
, 'VI' => 'Virgin Islands'
, 'WA' => 'Washington'
, 'WV' => 'West Virginia'
, 'WI' => 'Wisconsin'
, 'WY' => 'Wyoming'
)
);
public static $securities = Array(
......
......@@ -16,18 +16,20 @@ use WP_User, WP_Roles;
$uid = $user->ID;
$account = new User\Account($uid);
$pp = get_user_meta($uid, 'profile_preference', true).'_';
$first_name = get_user_meta($uid, 'first_name', true);
$last_name = get_user_meta($uid, 'last_name', true);
// contact info.
$country = get_user_meta($uid, 'country', true);
$country = get_user_meta($uid, $pp.'country', true);
$mobile = get_user_meta($uid, 'mobile', true);
$email = $user->user_email;//get_user_meta($uid, 'email', true);
// professional stuff
$title = get_user_meta($uid, 'title', true);
$company = get_user_meta($uid, 'company', true);
$company = get_user_meta($uid, 'company_name', true);
// status
$status = get_user_meta($uid, 'status', true);
......@@ -80,54 +82,7 @@ use WP_User, WP_Roles;
</tr>
<?php endif; ?>
<?php if (!empty($address)): ?>
<tr>
<th>Address:</th>
<td><?php echo $address; if (!empty($address2)) { echo "<br />".$address2; }?></td>
</tr>
<?php endif; ?>
<?php if (!empty($city)): ?>
<tr>
<th>City:</th>
<td><?php echo $city; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($province)): ?>
<tr>
<th>Province:</th>
<td><?php echo $province; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($country)): ?>
<tr>
<th>Country:</th>
<td><?php echo $country; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($phone)): ?>
<tr>
<th>Phone:</th>
<td><?php echo $phone; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($fax)): ?>
<tr>
<th>Fax:</th>
<td><?php echo $fax; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($mobile)): ?>
<tr>
<th>Mobile:</th>
<td><?php echo $mobile; ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($email)): ?>
<tr>
......@@ -136,12 +91,7 @@ use WP_User, WP_Roles;
</tr>
<?php endif; ?>
<?php if (!empty($website)): ?>
<tr>
<th>Website:</th>
<td><?php echo $website; ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
......
......@@ -131,32 +131,18 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
<td><input type="text" name="home_city" value="<?php echo get_user_meta($_GET['uid'], 'home_city', true);?>" /></td>
</tr>
<tr>
<th>Country:</th>
<td><?php echo HTML\form_dropdown('home_country', HTML\Vars::$countries, get_user_meta($_GET['uid'], 'home_country', true), "id='home_country'"); ?></td>
</tr>
<tr>
<th>State/Province:</th>
<td>
<select name="home_province">
<option disabled value="">Select a State/Province</option>
<optgroup label="Canada">
<?php HTML\select_opts_provinces(get_user_meta($_GET['uid'], 'home_province', true)); ?>
</optgroup>
<optgroup label="United States">
<?php HTML\select_opts_states(get_user_meta($_GET['uid'], 'home_province', true)); ?>
</optgroup>
</select>
</td>
<td><?php echo HTML\form_linked_dropdown('home_province', 'home_country', HTML\Vars::$provinces,get_user_meta($_GET['uid'], 'home_country', true), get_user_meta($_GET['uid'], 'home_province', true)); ?></td>
</tr>
<tr>
<th>Postal:</th>
<td><input type="text" name="home_postal" value="<?php echo get_user_meta($_GET['uid'], 'home_postal', true); ?>" /></td>
</tr>
<tr>
<th>Country:</th>
<td>
<select name="home_country">
<?php HTML\select_opts_countries(get_user_meta($_GET['uid'], 'home_country', true)); ?>
</select>
</td>
</tr>
<tr>
<th>Phone:</th>
<td><input type="text" name="home_phone" value="<?php echo get_user_meta($_GET['uid'], 'home_phone', true);?>" rel="mask-phone" /></td>
......@@ -200,32 +186,19 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
<td><input type="text" name="work_city" value="<?php echo get_user_meta($_GET['uid'], 'work_city', true);?>" /></td>
</tr>
<tr>
<th>Country:</th>
<td><?php echo HTML\form_dropdown('work_country', HTML\Vars::$countries, get_user_meta($_GET['uid'], 'work_country', true), "id='work_country'"); ?></td>
</tr>
<tr>
<th>State/Province:</th>
<td>
<select name="work_province">
<option disabled value="">Select a State/Province</option>
<optgroup label="Canada">
<?php HTML\select_opts_provinces(get_user_meta($_GET['uid'], 'work_province', true)); ?>
</optgroup>
<optgroup label="United States">
<?php HTML\select_opts_states(get_user_meta($_GET['uid'], 'work_province', true)); ?>
</optgroup>
</select>
</td>
<td><?php echo HTML\form_linked_dropdown('work_province', 'work_country', HTML\Vars::$provinces,get_user_meta($_GET['uid'], 'work_country', true), get_user_meta($_GET['uid'], 'work_province', true)); ?></td>
</tr>
<tr>
<th>Postal:</th>
<td><input type="text" name="work_postal" value="<?php echo get_user_meta($_GET['uid'], 'work_postal', true); ?>" /></td>
</tr>
<tr>
<th>Country:</th>
<td>
<select name="work_country">
<?php HTML\select_opts_countries(get_user_meta($_GET['uid'], 'work_country', true)); ?>
</select>
</td>
</tr>
<tr>
<th>Phone:</th>
<td><input type="text" name="work_phone" value="<?php echo get_user_meta($_GET['uid'], 'work_phone', true);?>" rel="mask-phone" /></td>
......