<?php
session_start();
ob_start();

require("includes/config.php");
require("includes/dbcon.php");
if($_SESSION['uid']==""){	
	header("location:index.php");
	exit();
}
$enrollee_id=$_SESSION['uid'];

$activeQuery = mysql_query("select * from enrollee where enrollee_id=".$enrollee_id);
$activeValue = mysql_fetch_array($activeQuery);    	  

$baseLat=$activeValue['lat'];
$baseLon=$activeValue['lon'];

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;	
	print $update_enrollee_sql;
	$rs=mysql_query($update_enrollee_sql) or die(mysql_error());		
	header("location:getDocs.php");	
}

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>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA2-41CEK7O6NgeZJ0etJsARQUkzM82cKzWubIcAGkgN9PIa9RdBQuj_kxz6sPByuX7WgnNF6u3ts1nw"
      type="text/javascript"></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");
?>
<?php
if( $activeValue['activFlag']== 0 )
{
?>  
	<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>
	 <tr>
	   <td align="center" valign="top" colspan="8">
	   	<div id="map" style="width:800px;height:600px"></div>
	   </td>
	 </tr>	
	</table>
<script type="text/javascript">

    //<![CDATA[

   var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(<?=$baseLat?>, <?=$baseLon?>), 13);
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
	index = 0;
	// Creates a marker whose info window displays the letter corresponding
	// to the given index.
	function createMarker(point, index1, adId) {
	  // Create a lettered icon for this point using our icon class
	  var letter = String.fromCharCode("A".charCodeAt(0) + index);
	  index = parseInt(index) + 1;
	  var letteredIcon = new GIcon(baseIcon);
	  letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	
	  // Set up our GMarkerOptions object
	  markerOptions = { icon:letteredIcon };
	  var marker = new GMarker(point, markerOptions);
	
	  GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<b>" + index1 + "</b>");
	  });
	  return marker;
	}	
	<?
		$EnrolOfficerQuery = mysql_query("select * from enrollment_officer");
		while($EnrolOfficerValue = mysql_fetch_array($EnrolOfficerQuery))
		{
			$officer_id=$EnrolOfficerValue['officer_id'];
			$name=$EnrolOfficerValue['fisrt_name']." ".$EnrolOfficerValue['middle_name']." ".$EnrolOfficerValue['last_name'];			
			$gender=$EnrolOfficerValue['gender'];

			$addressQuery = mysql_query("select * from address where address_id=".$EnrolOfficerValue['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'];

			$cityQuery = mysql_query("select * from city where city_id=".$addressValue['city_id']);
			$cityValue = mysql_fetch_array($cityQuery);
			$city_name=$cityValue['city_name'];

			$address=$street_number.", ".$street_line_01."<br>".$building_numer.", ".$building_name."<br>".$apartment_numer.", ".$room_numer."<br>".$state_name.", ".$city_name."<br>".$country_name." - ".$zipCode;

	?>
			var point = new GPoint(<?=$lat?>, <?=$lon?>);
	
			address = "			
			<font color=#660066 size=+1 face=Georgia, Times New Roman, Times, serif>
				<?=$name?>
			</font>
			<br />
			<font color=#660066 size=2 face=Georgia>
				<?=$address?>
			</font>
			<br>
			<form name=\"frm\" action=\"finalPage.php\" method=\"post\">
				<input type=\"hidden\" name=\"oId\" value=\"<?=$officer_id?>\">
				<input name=\"Submit\" type=\"submit\" value=\"Select Officer\" />
			</form>";
			
			var point = new GLatLng(<?=$lat?>,
							  <?=$lon?>);
	  		map.addOverlay(createMarker(point, address));
	<?	
		}
	?>
    //]]>
    </script>	 
<?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>
