<?php
session_start();
ob_start();

require("includes/config.php");
require("includes/dbcon.php");
//require_once('zipcode.class.php');      // zip code class
if($_SESSION['uid']==""){	
	header("location:index.php");
	exit();
}
$enrollee_id=$_SESSION['uid'];
//$enrollee_id=4;
$activeQuery = mysql_query("select activFlag from enrollee where enrollee_id=".$enrollee_id);
$activeValue = mysql_fetch_array($activeQuery);

if( !empty($_POST) )
{
	$insert_EnrolleeEo_sql="insert into enrollee_eo set 
							enrollee_id =".$enrollee_id.", 
							eo_id=".$_REQUEST['officerId'];	
	mysql_query($insert_EnrolleeEo_sql);	
		 
	$update_enrollee_sql="update enrollee SET activFlag=1";
	$update_enrollee_sql .= " WHERE enrollee_id=".$enrollee_id;		
	$rs=mysql_query($update_enrollee_sql) or die(mysql_error());
	//$_SESSION['eoId']=$_REQUEST['officerId'];
	header("location:getDocs.php");	
}

$EnrolOfficerQuery = mysql_query("select * from enrollment_officer");
$i = 0;
while($EnrolOfficerValue = mysql_fetch_array($EnrolOfficerQuery))
{    	     	  
	$officer_id=$EnrolOfficerValue['officer_id'];
	$name=$EnrolOfficerValue['fisrt_name']." ".$EnrolOfficerValue['middle_name']." ".$EnrolOfficerValue['last_name'];	
	$address_id=$EnrolOfficerValue['address_id'];

	$addressQuery = mysql_query("select * from address where address_id=".$address_id);
	$addressValue = mysql_fetch_array($addressQuery);
	 
	$street_number=$addressValue['street_number'];
	$street_line_01=$addressValue['street_line_01'];
	$street_line_02=$addressValue['street_line_02'];
	$street_line_03=$addressValue['street_line_03'];
	$zipCode=$addressValue['zipCode'];

	$lat=$addressValue['lat'];
	$lon=$addressValue['lon'];

	$building_numer=$addressValue['building_numer'];
	$building_name=$addressValue['building_name'];
	$apartment_numer=$addressValue['apartment_numer'];
	$room_numer=$addressValue['room_numer'];

	$countryQuery = mysql_query("select * from country where country_id=".$addressValue['country_id']);
	$countryValue = mysql_fetch_array($countryQuery);
	$country_name=$countryValue['country_name'];

	$stateQuery = mysql_query("select * from state where state_id=".$addressValue['state_id']);
	$stateValue = mysql_fetch_array($stateQuery);
	$state_name=$stateValue['state_name'];
	
	$address=$street_number.", ".$street_line_01.",<br>".$building_numer.", ".$building_name.",<br>".$apartment_numer.", ".$room_numer;



	$assoArr[$i]=array('Id'=>$officer_id,
					'Name'=>$name,
					'Address'=>$address,
					'Zip'=>$zipCode,
					'Country'=>$country_name,
					'State'=>$state_name,
					'lat'=>$lat,
					'lon'=>$lon);
	$i++;
}         
ob_end_flush();
?>
<!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>Enrollment Officer Selection Page</title>
</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");
?>
<?php
if( $activeValue['activFlag']== 0 )
{
?>
  <form name="frm" method="post" action="finalPage.php" onSubmit="return validate()">
	<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">	 
	 <tr>
	   <td width="30%" valign="top">
		<div class="bodySubHeader">
		<span class="bsht03">Step 3: Enrollment Officer Selection</span>		
		</div>
		</td>
	 </tr> 
	</table>	
	<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">	 
	 <tr>
	   <td height="30" align="center" valign="top" colspan="8" class="ErrorMessage"><strong><?=$err_msg?></strong></td>	   
	 </tr>	
	 <?php
		foreach($assoArr as $key=>$val)
		{				
			$nm=$val['Name'];
			//$zips = $z->get_zips_in_range('97214', 2, _ZIPS_SORT_BY_DISTANCE_ASC, true); 
	 ?>
	 <tr>
		<td align="left" valign="top" colspan="8">
			<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">		 
				<tr>			
					<td align="left" valign="top" class="whyJoinThree" width="20%"><b>Name:</b></td>		
					<td align="left" valign="top" class="whyJoinThree"><?=$nm?></td>
					<td align="right" valign="top"><input type="radio" name="oId" value=<?=$val['Id']?>></td>
				</tr>
				<tr>			
					<td align="left" valign="top" class="whyJoinThree"><b>Address:</b></td>		
					<td align="left" valign="top" class="whyJoinThree"><?=$val['Address']?></td>
					<td align="left" valign="top">&nbsp;</td>
				</tr>				
				<tr>			
					<td align="left" valign="top" class="whyJoinThree"><b>State:</b></td>		
					<td align="left" valign="top" class="whyJoinThree"><?=$val['State']?></td>
					<td align="left" valign="top">&nbsp;</td>
				</tr>
				<tr>			
					<td align="left" valign="top" class="whyJoinThree"><b>Country:</b></td>		
					<td align="left" valign="top" class="whyJoinThree"><?=$val['Country']?> - <?=$val['Zip']?></td>
					<td align="left" valign="top">&nbsp;</td>
				</tr>
			</table>
		</td>
	  </tr>
	  <tr>
		<td align="left" valign="top" colspan="8"><hr></td>
	  </tr>
	 <?php
		}
	 ?>
	  <tr>
	   <td height="35" align="left" valign="bottom" colspan="7"><!--input type="hidden" name="oId" value="<?=$officer_id?>"--></td>	   
	   <td height="35" align="right" valign="bottom"><input name="Submit" type="submit" value="Confirm" /></td>
	 </tr>
	</table>
  </form>
<?php
}
else
{
	$msg="You are already activated";
?>
	<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">		 
	 <tr>
	   <td height="30" align="center" valign="top" class="ErrorMessage"><strong><?=$msg?></strong></td>	   
	 </tr>
	</table>
<?php
}
?>
<?php
include_once("includes/footer.php");
?>
	   </td>
	 </tr> 	 
</table>
</body>
</html>
