<?php
	$newby=7;
	require("includes/.htconfig.php");
	
	if( !empty($_POST) )
	{	
		$first_name=trim($_REQUEST['first_name']);
		$middle_name=trim($_REQUEST['middle_name']);
		$last_name=trim($_REQUEST['last_name']);
		$sex=trim($_REQUEST['sex']);
		$ssn=trim($_REQUEST['ssn']);
		$city_born=trim($_REQUEST['city_born']);
		$country=trim($_REQUEST['country']);
		$state=trim($_REQUEST['state']);
		$city=trim($_REQUEST['city']);
		$street_line_01=trim($_REQUEST['street_line_01']);
		$street_line_02=trim($_REQUEST['street_line_02']);
		$street_line_03=trim($_REQUEST['street_line_03']);
		$zipCode=trim($_REQUEST['zipCode']);
		$landPhone=trim($_REQUEST['landPhone']);
		$mobilePhone=trim($_REQUEST['mobilePhone']);	
		
		$state_id=getStateId($state,$country);
		$city_id=getCityId($city,$state_id,$country);
		
		if(!empty($landPhone))
		{
			$insert_landPhone_sql="insert into phone set "
			."owner_id=$enrollee_id"
			.",phone_type_code='ehom'"
			.",phone_number='".mysql_escape_string($landPhone)."'";
			if (!mysql_query($insert_landPhone_sql))
				baderror(__LINE__,"inserting a land phone",$insert_landPhone_sql);
		}
		if(!empty($mobilePhone))
		{
			$insert_mobilePhone_sql="insert into phone set "
			."owner_id=$enrollee_id"
			.",phone_type_code='emob'"
			.",phone_number='".mysql_escape_string($mobilePhone)."'";
			if (!mysql_query($insert_mobilePhone_sql))
				baderror(__LINE__,"inserting a land phone",$insert_mobilePhone_sql);
		}
		
		$zipCode_sql="select * from zip_code where zip_code=".$zipCode;
		$latLonValue=mysql_getRow($zipCode_sql);
		if (is_null($latLonValue))
		{
			$lat=0;
			$lon=0;
		}
		else
		{
			$lat=$latLonValue['lat'];
			$lon=$latLonValue['lon'];
		}
		
		$insert_address_sql="insert into address set "
		."owner_id=$enrollee_id"
		.",address_type_id='ehom'"
		.",city_id=".$city_id
		.",state_id=".$state_id
		.",country_id=".$country 
		.",street_line_01='".mysql_escape_string($street_line_01)."'"
		.",street_line_02='".mysql_escape_string($street_line_02)."'"
		.",street_line_03='".mysql_escape_string($street_line_03)."'"
		.",zipCode='".mysql_escape_string($zipCode)."'"
		.",lat=".mysql_escape_string($lat)
		.",lon=".mysql_escape_string($lon);	
		if(mysql_query($insert_address_sql))
		{
			$insrt_address_id= mysql_insert_id();
		}   ##address didn't insert
		else
		{
			$insrt_address_id="NULL";
			$errmsgs.="<BR>We had trouble recording your address in our database.  Could you try again?";
			baderror(__LINE__,"inserting the address",$insert_address_sql);
		}
		
		$update_sql="update enrollee SET "
		."first_name='".mysql_escape_string($first_name)."'"
		.",middle_name='".mysql_escape_string($middle_name)."'"
		.",last_name='".mysql_escape_string($last_name)."'"
		.",gender='".mysql_escape_string($sex)."'"
		.",address_id=".$insrt_address_id
		.=" WHERE enrollee_id=".$enrollee_id;		
		if (!mysql_query($update_sql))
		{
			baderror(__LINE__,"updating the enrollee",$query);
			$errmsgs.="<BR>We couldn't add the new information.  Can you try again?";
		}
		if (strlen($errmsgs) == 0) advancePage($enrollee_id,$newby);
	}
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="./style/design.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {font-size: 0.8em}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Personally Identifiable Information</title>
<script language="JavaScript" src="includes/js/common.js"></script>
<!--script language='javascript' src='datepicker/popcalendar.js'></script-->
<link rel="stylesheet" type="text/css" media="all" href="cal/calendar-win2k-cold-1.css" title="win2k-cold-1"><!-- main calendar program -->  
<script type="text/javascript" src="cal/calendar.js"></script><!-- language for the calendar -->  
<script type="text/javascript" src="cal/calendar-en.js"></script><!-- the following script defines the Calendar.setup helper function, which makes
adding a calendar a matter of 1 or 2 lines of code. -->  
<script type="text/javascript" src="cal/calendar-setup.js"></script>
<script language="JavaScript">
function validate()
{
	var is_valid=true
	is_valid = blank_check( document.frm.first_name.value, "PLEASE INPUT FIRST NAME" )
	if( is_valid == false ) { document.frm.first_name.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.last_name.value, "PLEASE INPUT LAST NAME" )
	if( is_valid == false ) { document.frm.last_name.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.dob.value, "PLEASE INPUT DATE OF BIRTH" )
	if( is_valid == false ) { document.frm.dob.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.city_born.value, "PLEASE INPUT CITY OF BIRTH" )
	if( is_valid == false ) { document.frm.city_born.focus(); return is_valid }	
	
	is_valid = blank_check( document.frm.state.value, "PLEASE INPUT STATE" )
	if( is_valid == false ) { document.frm.state.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.city.value, "PLEASE INPUT CITY" )
	if( is_valid == false ) { document.frm.city.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.zipCode.value, "PLEASE INPUT ZIP" )
	if( is_valid == false ) { document.frm.zipCode.focus(); return is_valid }
	
	is_valid = chosen_check( document.frm.country.value, "PLEASE SELECT COUNTRY" )
	if( is_valid == false ) { document.frm.country.focus(); return is_valid }
	
	##is_valid = blank_check( document.frm.street_number.value, "PLEASE INPUT STREET NUMBER" )
	##	if( is_valid == false ) { document.frm.street_number.focus(); return is_valid }
	
	
	is_valid = blank_check( document.frm.street_line_01.value, "PLEASE INPUT A STREET ADDRESS" )
	if( is_valid == false ) { document.frm.street_line_01.focus(); return is_valid }
	
	
	is_valid = blank_check( document.frm.landPhone.value, "PLEASE INPUT A PHONE NUMBER" )
	if( is_valid == false ) { document.frm.landPhone.focus(); return is_valid }	
	
	##is_valid = blank_check( document.frm.mobilePhone.value, "PLEASE INPUT MOBILE NUMBER" )
	##	if( is_valid == false ) { document.frm.mobilePhone.focus(); return is_valid }
	
	##is_valid = blank_check( document.frm.userImage.value, "PLEASE UPLOAD YOUR IMAGE" )
	##	if( is_valid == false ) { document.frm.userImage.focus(); return is_valid }
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">

<?php
	include_once("includes/header.php");
	?>
<form name="frm" method="post" action="" enctype="multipart/form-data" onSubmit="return validate()">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" valign="top">
<div class="bodySubHeader">
<span class="bsht03">Personal Information</span>
</div>
</td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
<tr>
<td width="65%" align="left" valign="top" colspan="8" class="TopMenu2">Personal Details</td>
</tr>
<tr>
<td align="left" valign="top" colspan="8">&nbsp;</td>
</tr>
<tr>
<td height="30" align="left" valign="top" class="browseEventContents">First Name:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="first_name" value="
<?PHP
	echo $enrollee['first_name']
?>" type="text" class="textField" />
</td>
<td height="30" align="left" valign="top" width="1%">&nbsp;</td>
<td height="30" align="left" valign="top" class="browseEventContents">Middle Name:</td>
<td height="30" align="left" valign="top">
<input name="middle_name" value="
<?PHP
	echo $enrollee['middle_name']
?>" type="text" class="textField" />
</td>
<td height="30" align="left" valign="top" width="1%">&nbsp;</td>
<td height="30" align="left" valign="top" class="browseEventContents">
Surname:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="last_name" value="
<?PHP
	echo $enrollee['last_name']
?>" type="text" class="textField" />
</td>
</tr>
<tr>
<td height="30" align="left" valign="top" class="browseEventContents">Sex:</td>
<td height="30" align="left" valign="top">
<select name="sex">
<option value="m" Selected="">Male</option>
<option value="f">Female</option>
</select>
</td>
</tr>
<tr>
<?PHP
	echo inputcells("Social Security Number","ssn");
	?>
</tr>
<tr>

</tr>
<tr>
<td align="left" valign="top" colspan="8">&nbsp;</td>
</tr>


<TR valign="top">
<td colspan="6">
<TABLE>
<TR>
<td width="65%" align="left" valign="top" colspan="8" class="TopMenu2">Residential Address</td>
</TR>
<TR>
<td height="30" align="left" valign="top" class="browseEventContents">Street Address:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="street_line_01" type="text" class="textField"/>
</td>
</TR>
<TR>
<td height="30" align="left" valign="top" class="browseEventContents"></td>
<td height="30" align="left" valign="top">
<input name="street_line_02" type="text" class="textField"/>
</td>
</TR>
<TR>
<td height="30" align="left" valign="top" class="browseEventContents"></td>
<td height="30" align="left" valign="top">
<input name="street_line_03" type="text" class="textField"/>
</td>
</TR>

<tr>
<td height="30" align="left" valign="top" class="browseEventContents">City:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="city" type="text" class="textField"/>
</td>
<td height="30" align="left" valign="top">&nbsp;</td>

<td height="30" align="left" valign="top" class="browseEventContents">
State:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="state" type="text" class="textField"/>
</td>
<td height="30" align="left" valign="top">&nbsp;</td>
<td height="30" align="left" valign="top" class="browseEventContents">
Zip Code:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="zipCode" type="text" class="textField"/>
</td>
</tr>
<tr>
<td height="30" align="left" valign="top" class="browseEventContents">
Country:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top" colspan="7">
<select name='country' id='country'>
<option value='0' Selected='' >--- Select Country ---</option>
<?php					
	$countryQuery = mysql_query("select country_id, country_name from country order by country_name asc");
	while($countryValue = mysql_fetch_array($countryQuery))
	{
		if($countryValue['country_id'] == $_REQUEST['country_id'])
		{
			echo"<option value='".$countryValue['country_id']."' Selected >".$countryValue['country_name']."</option>";
		}
		else
		{
			echo"<option value='".$countryValue['country_id']."' >".$countryValue['country_name']."</option>";
		}
	}
	?>
</select>
</td>
</tr>
</TABLE>
</td>
<td colspan='4'>
<TABLE>
<TR>
<td width="65%" align="left" valign="top" colspan="8" class="TopMenu2">Phone Numbers</td>
</TR>
<tr>
<td height="30" align="left" valign="top" class="browseEventContents">
Primary Phone Number:
<?PHP
	echo $redstar;
?>
</td>
<td height="30" align="left" valign="top">
<input name="landPhone" type="text" class="textField"/>
</td>
<td height="30" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td height="30" align="left" valign="top" class="browseEventContents">
Cell Phone Number:
<?PHP
	echo $redstar;
?>
<td height="30" align="left" valign="top">
<input name="mobilePhone" type="text" class="textField"/>
</td>
<td height="30" align="left" valign="top">&nbsp;</td>
<td height="30" align="left" valign="top" class="browseEventContents">&nbsp;</td>
<td height="30" align="left" valign="top">&nbsp;</td>
</tr>
</TABLE>
</td>
</TR>

</tr>
<tr>
<td height="35" align="left" valign="bottom" colspan="7">&nbsp;</td>	   
<td height="35" align="left" valign="bottom"><input name="command" type="submit" value="Next" /></td>
</tr>
</table>
</form>
<?php
	include_once("includes/footer.php");
?>
</td>
</tr> 	 
</table>
</body>
</html>
<?php
	function thumbnail($filethumb,$file,$Twidth,$Theight,$tag)
	{	
		list($width,$height,$type,$attr)=getimagesize($file);
		switch($type)
		{
			case 1:
				$img = ImageCreateFromGIF($file);
				break;
			case 2:
				$img=ImageCreateFromJPEG($file);
				break;
			case 3:
				$img=ImageCreateFromPNG($file);
				break;
		}
		if($tag == "width") //width contraint
		{
			$Theight=round(($height/$width)*$Twidth);
		}
		elseif($tag == "height") //height constraint
		{
			$Twidth=round(($width/$height)*$Theight);
		}
		else
		{
			if($width > $height)
				$Theight=round(($height/$width)*$Twidth);
			else
				$Twidth=round(($width/$height)*$Theight);
		}
		$thumb=imagecreatetruecolor($Twidth,$Theight);
		if(imagecopyresampled($thumb,$img,0,0,0,0,$Twidth,$Theight,$width,$height))
		{		
			switch($type)
			{
				case 1:
					ImageGIF($thumb,$filethumb);
					break;
				case 2:
					ImageJPEG($thumb,$filethumb);
					break;
				case 3:
					ImagePNG($thumb,$filethumb);
					break;
			}
			chmod($filethumb,0666);
			return true;
		}
	}
?>