Skip to content
Snippets Groups Projects
Select Git revision
  • 8ca9ad1ce84aa50f99941bcac8555e99e9cf4d9a
  • master default
  • develop
  • git-fixes
  • 4.1_templates-symlink
  • 4.0_templates
6 results

enhanceProfileForm.php

Blame
  • enhanceProfileForm.php 16.06 KiB
    (function(){
    	// Edit Profile Stuff
    	function updateLL () {
    		var city = $("input[name=form_data_profile_city]").val(), state = $("select[name=form_data_profile_state]").val(), country = $("select[name=form_data_profile_country]").val();
    		$.get("<?php echo $vars['url']; ?>mod/unl_theme/scripts/latlon.php",{city:city,state:state,country:country},function(response){
    			try {
    				var data = eval(response);
    				$("input[name=form_data_latitude]").val(data.latitude);
    				$("input[name=form_data_longitude]").val(data.longitude);
    			} catch (e) {}
    		});
    	};
    
    	function updateLLhome () {
    		var city = $("input[name=form_data_profile_homecity]").val(), state = $("select[name=form_data_profile_homestate]").val(), country = $("select[name=form_data_profile_homecountry]").val();
    		$.get("<?php echo $vars['url']; ?>mod/unl_theme/scripts/latlon.php",{city:city,state:state,country:country},function(response){
    			try {
    				var data = eval(response);
    				$("input[name=form_data_hometown_latitude]").val(data.latitude);
    				$("input[name=form_data_hometown_longitude]").val(data.longitude);
    			} catch (e) {}
    		});
    	};
    			
    	$(document).ready(function(){
    		/* SET UP PROFILE EDIT FORM */
    		$("form.cool fieldset:first-child").css("margin-top","0");
    		$("p.form-description").remove();
    		
    		// get the year and country values for later use
    		var dob_year = $("input[name=form_data_profile_dob_year]").val();
    		var from_year = $("input[name=form_data_profile_attended_from]").val();
    		var to_year = $("input[name=form_data_profile_attended_to]").val();
    		var home_country = $("input[name=form_data_profile_homecountry]").val();
    		var home_state = $("input[name=form_data_profile_homestate]").val();
    		var current_country = $("input[name=form_data_profile_country]").val();
    		var current_state = $("input[name=form_data_profile_state]").val();
    		// remove the text inputs. will be replacing with selectors
    		$("input[name=form_data_profile_dob_year]").remove();
    		
    		
    		
    		
    		// wrap the fields in <li>s
    		$("form.cool label").wrap("<li></li>").addClass("element");
    		$("form.cool label br").remove();
    		$("form.cool p.form-field-description").each(function(){
    			$(this).appendTo($(this).prev()).css({
    				marginLeft: "164px",
    				marginTop: "36px",
    				fontSize: "75%",
    				color: "#1091D1"
    			});
    		});
    		$("form.cool fieldset input, form.cool fieldset select").wrap('<div class="element"></div>');
    		$("form.cool label div").each(function(){
    			$(this).insertAfter($(this).parent());
    		});
    
    		// remove the country input
    		var country_parent = $("input[name=form_data_profile_country]").parent();
    		$("input[name=form_data_profile_country]").remove();
    		var state_parent = $("input[name=form_data_profile_state]").parent();
    		$("input[name=form_data_profile_state]").remove();
    		var homecountry_parent = $("input[name=form_data_profile_homecountry]").parent();
    		$("input[name=form_data_profile_homecountry]").remove();
    		var homestate_parent = $("input[name=form_data_profile_homestate]").parent();
    		$("input[name=form_data_profile_homestate]").remove();
    		var from_parent = $("input[name=form_data_profile_attended_from]").parent();
    		$("input[name=form_data_profile_attended_from]").remove();
    		var to_parent = $("input[name=form_data_profile_attended_to]").parent();
    		$("input[name=form_data_profile_attended_to]").remove();
    
    		$("input[name=form_data_map_explanation]").parent().parent().css("border-bottom","#CCC 1px dotted");
    		$("input[name=form_data_profile_city]").parent().parent().prepend('<h6 style="width:150px;margin:0;text-align:right;"><strong>Your Map Location</strong></h6>'
    				+ '<p>Please enter the location you want to use for yourself on the map.</p>');
    
    
    		/* set up various year inputs */
    		
    		var x = 1900, html = '<option value="">--</option>';
    		var curYear = (new Date()).getFullYear();
    		
    		var selYear = document.createElement("select");
    		selYear.name = "form_data_profile_dob_year";
    		
    		while (x++ < curYear) {
    			html+= '<option';
    			if (x == dob_year) {
    				html += ' selected="selected"'
    			}
    			html += '>' + x + '</option>';
    			
    		}
    		$(selYear).html(html);
    		
    		
    		var selFrom = document.createElement("select");
    		selFrom.name = "form_data_profile_attended_from";
    		x = 1940;
    		html = '<option></option>';
    		while (x++ < curYear + 6) {
    			html+= '<option';
    			if (x == from_year) {
    				html += ' selected="selected"'
    			}
    			html += '>' + x + '</option>';
    			
    		}
    		$(selFrom).html(html);
    		from_parent.append(selFrom);
    
    		var selTo = document.createElement("select");
    		selTo.name = "form_data_profile_attended_to";
    		x = 1940;
    		html = '<option></option>';
    		while (x++ < curYear + 6) {
    			html+= '<option';
    			if (x == to_year) {
    				html += ' selected="selected"'
    			}
    			html += '>' + x + '</option>';
    			
    		}
    		$(selTo).html(html);
    		from_parent.append(" to ");
    		from_parent.append(selTo);
    		to_parent.parent().remove();
    
    		var states = ["AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"];
    		
    		var countries = ["USA",
    		         		"Afghanistan",
    		         		"Albania",
    		        		"Algeria",
    		        		"Andorra",
    		        		"Angola",
    		        		"Antigua and Barbuda",
    		        		"Argentina",
    		        		"Armenia",
    		        		"Australia",
    		        		"Austria",
    		        		"Azerbaijan",
    		        		"Bahamas",
    		        		"Bahrain",
    		        		"Bangladesh",
    		        		"Barbados",
    		        		"Belarus",
    		        		"Belgium",
    		        		"Belize",
    		        		"Benin",
    		        		"Bhutan",
    		        		"Bolivia",
    		        		"Bosnia and Herzegovina",
    		        		"Botswana",
    		        		"Brazil",
    		        		"Brunei",
    		        		"Bulgaria",
    		        		"Burkina Faso",
    		        		"Burundi",
    		        		"Cambodia",
    		        		"Cameroon",
    		        		"Canada",
    		        		"Cape Verde",
    		        		"Central African Republic",
    		        		"Chad",
    		        		"Chile",
    		        		"China",
    		        		"Colombia",
    		        		"Comoros",
    		        		"Congo (Brazzaville)",
    		        		"Congo",
    		        		"Costa Rica",
    		        		"Cote d'Ivoire",
    		        		"Croatia",
    		        		"Cuba",
    		        		"Cyprus",
    		        		"Czech Republic",
    		        		"Denmark",
    		        		"Djibouti",
    		        		"Dominica",
    		        		"Dominican Republic",
    		        		"East Timor (Timor Timur)",
    		        		"Ecuador",
    		        		"Egypt",
    		        		"El Salvador",
    		        		"Equatorial Guinea",
    		        		"Eritrea",
    		        		"Estonia",
    		        		"Ethiopia",
    		        		"Fiji",
    		        		"Finland",
    		        		"France",
    		        		"Gabon",
    		        		"Gambia, The",
    		        		"Georgia",
    		        		"Germany",
    		        		"Ghana",
    		        		"Greece",
    		        		"Grenada",
    		        		"Guatemala",
    		        		"Guinea",
    		        		"Guinea-Bissau",
    		        		"Guyana",
    		        		"Haiti",
    		        		"Honduras",
    		        		"Hungary",
    		        		"Iceland",
    		        		"India",
    		        		"Indonesia",
    		        		"Iran",
    		        		"Iraq",
    		        		"Ireland",
    		        		"Israel",
    		        		"Italy",
    		        		"Jamaica",
    		        		"Japan",
    		        		"Jordan",
    		        		"Kazakhstan",
    		        		"Kenya",
    		        		"Kiribati",
    		        		"Korea, North",
    		        		"Korea, South",
    		        		"Kuwait",
    		        		"Kyrgyzstan",
    		        		"Laos",
    		        		"Latvia",
    		        		"Lebanon",
    		        		"Lesotho",
    		        		"Liberia",
    		        		"Libya",
    		        		"Liechtenstein",
    		        		"Lithuania",
    		        		"Luxembourg",
    		        		"Macedonia",
    		        		"Madagascar",
    		        		"Malawi",
    		        		"Malaysia",
    		        		"Maldives",
    		        		"Mali",
    		        		"Malta",
    		        		"Marshall Islands",
    		        		"Mauritania",
    		        		"Mauritius",
    		        		"Mexico",
    		        		"Micronesia",
    		        		"Moldova",
    		        		"Monaco",
    		        		"Mongolia",
    		        		"Morocco",
    		        		"Mozambique",
    		        		"Myanmar",
    		        		"Namibia",
    		        		"Nauru",
    		        		"Nepa",
    		        		"Netherlands",
    		        		"New Zealand",
    		        		"Nicaragua",
    		        		"Niger",
    		        		"Nigeria",
    		        		"Norway",
    		        		"Oman",
    		        		"Pakistan",
    		        		"Palau",
    		        		"Panama",
    		        		"Papua New Guinea",
    		        		"Paraguay",
    		        		"Peru",
    		        		"Philippines",
    		        		"Poland",
    		        		"Portugal",
    		        		"Qatar",
    		        		"Romania",
    		        		"Russia",
    		        		"Rwanda",
    		        		"Saint Kitts and Nevis",
    		        		"Saint Lucia",
    		        		"Saint Vincent",
    		        		"Samoa",
    		        		"San Marino",
    		        		"Sao Tome and Principe",
    		        		"Saudi Arabia",
    		        		"Senegal",
    		        		"Serbia and Montenegro",
    		        		"Seychelles",
    		        		"Sierra Leone",
    		        		"Singapore",
    		        		"Slovakia",
    		        		"Slovenia",
    		        		"Solomon Islands",
    		        		"Somalia",
    		        		"South Africa",
    		        		"Spain",
    		        		"Sri Lanka",
    		        		"Sudan",
    		        		"Suriname",
    		        		"Swaziland",
    		        		"Sweden",
    		        		"Switzerland",
    		        		"Syria",
    		        		"Taiwan",
    		        		"Tajikistan",
    		        		"Tanzania",
    		        		"Thailand",
    		        		"Togo",
    		        		"Tonga",
    		        		"Trinidad and Tobago",
    		        		"Tunisia",
    		        		"Turkey",
    		        		"Turkmenistan",
    		        		"Tuvalu",
    		        		"Uganda",
    		        		"Ukraine",
    		        		"United Arab Emirates",
    		        		"United Kingdom",
    		        		"Uruguay",
    		        		"Uzbekistan",
    		        		"Vanuatu",
    		        		"Vatican City",
    		        		"Venezuela",
    		        		"Vietnam",
    		        		"Yemen",
    		        		"Zambia",
    		        		"Zimbabwe"];
    		
    		var selCountry = document.createElement("select");
    		selCountry.name = "form_data_profile_country";
    		html = "";
    		for (var i = 0, l = countries.length; i < l; i++){
    			html+= '<option';
    			if (countries[i] == current_country) {
    				html += ' selected="selected"'
    			}
    			html += '>' + countries[i] + '</option>';
    		}
    		/*if (current_country == "") {
    			html += '<option selected="selected" value="">-Select your country-</option>';
    		}*/
    		$(selCountry).html(html);
    
    		var selState = document.createElement("select");
    		selState.name = "form_data_profile_state";
    		html = '<option value="">&nbsp;</option>';
    		for (var i = 0, l = states.length; i < l; i++){
    			html+= '<option';
    			if (states[i] == current_state) {
    				html += ' selected="selected"'
    			}
    			html += '>' + states[i] + '</option>';
    		}
    		/*if (current_state == "") {
    			html += '<option selected="selected" value="">&nbsp;</option>';
    		}*/
    		$(selState).html(html);
    
    		var selhomeCountry = document.createElement("select");
    		selhomeCountry.name = "form_data_profile_homecountry";
    		html = "";
    		for (var i = 0, l = countries.length; i < l; i++){
    			html+= '<option';
    			if (countries[i] == home_country) {
    				html += ' selected="selected"'
    			}
    			html += '>' + countries[i] + '</option>';
    		}
    		/*if (home_country == "") {
    			html += '<option selected="selected" value="">-Select your country-</option>';
    		}*/
    		$(selhomeCountry).html(html);
    
    		var selhomeState = document.createElement("select");
    		selhomeState.name = "form_data_profile_homestate";
    		html = '<option value="">&nbsp;</option>';
    		for (var i = 0, l = states.length; i < l; i++){
    			html+= '<option';
    			if (states[i] == home_state) {
    				html += ' selected="selected"'
    			}
    			html += '>' + states[i] + '</option>';
    		}
    		/*if (home_state == "") {
    			html += '<option selected="selected" value="">&nbsp;</option>';
    		}*/
    		
    		$(selhomeState).html(html);
    		
    		 $("input[name=form_data_profile_dob_month]").parent().append(selYear);
    		 country_parent.append(selCountry);
    		 state_parent.append(selState);
    		 homecountry_parent.append(selhomeCountry);
    		 homestate_parent.append(selhomeState);
    		 
    		 $("input[name=form_data_profile_dob_day]").insertBefore($("select[name=form_data_profile_dob_year]"));
    		
    		// don't display the latitude/longitude fields
    		$("input[name=form_data_latitude],input[name=form_data_longitude]").parent().parent().hide();
    		// update the lat/long automatically whenever current location is changed
    		$("input[name=form_data_profile_city],select[name=form_data_profile_state],select[name=form_data_profile_country]").change(function(){
    			updateLL();
    		});
    
    		$("input[name=form_data_hometown_latitude],input[name=form_data_hometown_longitude]").parent().parent().hide();
    		// update the lat/long automatically whenever current location is changed
    		$("input[name=form_data_profile_homecity],select[name=form_data_profile_homestate],select[name=form_data_profile_homecountry]").change(function(){
    			updateLLhome();
    		});
    
    		$("form.cool label").each(function(){
    			if (this.innerHTML.match(/day/i) ||  this.innerHTML.match(/year\s*$/i) ){
    				$(this).parent().remove();
    
    			} else if (this.innerHTML.match(/month/i)) {
    				this.innerHTML = "Birthday";
    			}
    		});
    
    		var unlrole = $('form input[name=form_data_profile_role]').val();
    		if (unlrole == "alum") {
    			$('form input[name=form_data_profile_role]').val("alumnus");
    		}
    		
    
    		
    		
    		$('form input[name=form_data_profile_role]').replaceWith('<select name="form_data_profile_role" class="input-pulldown">'+
    				'<option value="Prospective Student">Prospective Student</option>'+
    				'<option value="Current Student">Current Student</option>'+
    				'<option value="Parent of a Student">Parent of a Prospective Student and/or Current Student</option>'+
    				'<option value="Alumnus">Alumnus</option>'+
    				'<option value="Faculty/Staff">Faculty/Staff</option>'+
    				'<option value="Nebraska Resident">Nebraska Resident</option>'+
    				'<option value="Friend of the University">Friend of the University</option>'+ 
    				'</select>');
    		
    		switch (unlrole) {
    			case "prospective student":
    				$("form select[name=form_data_profile_role] option[value='Prospective Student']").attr('selected','selected');
    				break;
    			case "current student" :
    				$("form select[name=form_data_profile_role] option[value='Current Student']").attr('selected','selected');
    				break;
    			case "parent of a student" :
    				$("form select[name=form_data_profile_role] option[value='Parent of a Student']").attr('selected','selected');
    				break;
    			case "alumnus":
    				$("form select[name=form_data_profile_role] option[value='Alumnus']").attr('selected','selected');
    				break;
    			case "faculty/staff" : 
    				$("form select[name=form_data_profile_role] option[value='Faculty/Staff']").attr('selected','selected');
    				break;
    			case "nebraska resident" :
    				$("form select[name=form_data_profile_role] option[value='Nebraska Resident']").attr('selected','selected');
    				break;
    			case "friend of the university" :
    				$("form select[name=form_data_profile_role] option[value='Friend of the University']").attr('selected','selected');
    				break;
    		}
    		$('form select[name=form_data_profile_role] option[value='+unlrole+']').attr('selected','selected');
    		
    		var dob_month = $("input[name=form_data_profile_dob_month]").val(),
    		    dob_day = $("input[name=form_data_profile_dob_day]").val();
    	    var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    	    var monthsHTML = '<option value="">--</option>';
    		for (var i = 0, l = months.length; i < l; i++){
    			monthsHTML+= '<option value="' + months[i] + '">' + months[i] + '</option>';
    		}
    	    $('form input[name=form_data_profile_dob_month]').replaceWith('<select name="form_data_profile_dob_month" class="input-pulldown">'+monthsHTML+'</select>');
    	     
    		$("select[name=form_data_profile_dob_month] option[value=" + dob_month + "]").attr("selected","selected");
    		var daysHTML = '<option value="">--</option>';
    		for (var i = 1, l = 32; i < l; i++){
    			daysHTML+= '<option value="' + i + '">' + i + '</option>';
    		}
    	    $('form input[name=form_data_profile_dob_day]').replaceWith('<select name="form_data_profile_dob_day" class="input-pulldown">'+daysHTML+'</select>');
    	     
    		$("select[name=form_data_profile_dob_day] option[value=" + dob_day + "]").attr("selected","selected");
    
    		
    		$("#formloading").remove();
    		$("#maincontent form.cool").show();
    	});
    })();