/home/mip/public_html_/old-website/employerxxx/edit_source_survey.php
<?
session_start();
require_once("func_all.php");

do_html_header("Sourcing Survey");
	
$position = getdata("select * from positions order by name");
$countries = getdata("select * from country order by name");
if(!isset($status)) $status = "On Pool";
?> 
	<form method=post action='<?=$PHP_SELF?>' name='form_source_survey'">
  <tr height=100%><td valign="top">
	<table align=center width=100%>
	<tr>
			<td align=center><br>
			<table cellpadding="2" cellspacing="2" border="0">
					<tr>
							<td>
									<b>Position :</b>
									<select name="position_id">
									<option value="0">-- Select Position --
									<?selectcode($position,"$position_id","position_id","name")?></select>
							</td>
					</tr>
					<!--<tr>
							<td>
									<b>Country :</b>
									<select name="country_id">
									<option value="">All 
									<?selectcode($countries,$country_id,"country_id","name")?></select>
									&nbsp;&nbsp;&nbsp;
									<b>Status :</b>
									<select name="status">
									<option value="0">All
									<?selectcode($applicant_status,$status,"status","status")?>
					    </td>
					</tr>-->		
					<tr>
							<td>
									<b>Gender :</b> 
									<input class="radio_white" type=radio name=gender value="" <?=(!$gender)? "checked" : ""?>>any 
								 	<input class="radio_white" type=radio name=gender value="M" <?=($gender=='M')? "checked" : ""?>>Male 
								 	<input class="radio_white" type=radio name=gender value="F" <?=($gender=='F')? "checked" : ""?>>Female
									&nbsp;&nbsp;&nbsp;			  
									<b>Age :</b> 
									Min <input type=text name="min_age" size=4 maxlength=2 value="<?=$min_age?>" onfocus="select()">&nbsp;&nbsp;
									Max <input type=text name="max_age" size=4 maxlength=2 value="<?=$max_age?>" onfocus="select()">
									&nbsp;&nbsp;<br>
									<div align="center"><input type=submit value="Get Applicants"></div>
					    </td>
					</tr>
				</table>
			</td>
	</tr>
	
<?
if($country_id) $sql_country = "AND (p.country_id = $country_id OR p.country_id2 = $country_id)";

if($status) $sql_status = "AND (p.status = '$status' OR p.status2 = '$status')";

if($gender) $sql_gender = "AND p.sex='$gender'"; // gender
		  
if($min_age){
	  $min_date = get_date($sqltoday,-$min_age);
		$sql_min_age = "and p.birthdate > 0 and p.birthdate <= '$min_date'";
}
	
if($max_age){
	  $max_date = get_date($sqltoday,-($max_age+1));
		$sql_max_age = "and p.birthdate >= '$max_date'";
}
	
$sql_age = "$sql_max_age $sql_min_age"; // age
	
if($position_id)
{
	
	if($sort_by){
	  $old_sort_order = $sort_order;
		$sort_order = ($old_sort_order=="asc")? "desc" : "asc";
		$sql_sort_by = "p.$sort_by";
		if($sort_by == 'position1_yrsofexp')  $add_sort = ",position1_mosofexp $sort_order";  			 
	}
  else{
	  $sql_sort_by = "p.lname";
		$sort_order = "asc";
	}	
	
	$result = getdata("SELECT distinct(p.applicant_id),
														p.birthdate,
														p.sex,
														p.height1,p.height2,
														p.weight1,p.weight2,		
														p.cellphone,
														p.position1_yrsofexp,
														p.position1_mosofexp,
														concat(p.lname,', ',p.fname,' ',left(p.mname,1),'.') as name																							                          																						
										 FROM   personal as p
										 WHERE  p.position_id1 = '$position_id'										     
										 $sql_status
										 $sql_country
										 $sql_gender				
										 $sql_age						 						 
										 ORDER BY $sql_sort_by $sort_order $add_sort");
  $found = count($result);
  echo mysql_error();

if($found){ ?> 
			<tr><td bgcolor="#e1e6e7" height="25">&nbsp;<font color=red>Note:</font> Click on the Applicant Name, Age, Yrs. of Experience to sort the applicants.</td></tr>			 	
			<tr><td>
			
			<table border="0" cellpadding="0" cellspacing="0" width=100%>
			<tr><td><img src="img/topleft-login.gif" border="0"></td>
					<td background="img/toptile-login.gif"><img src="img/toptile-login.gif" border="0"></td>
					<td><img src="img/topright-login.gif" border="0"></td></tr>
			<tr><td background="img/midleft-login.gif"><img src="img/midleft-login.gif" border="0"></td>
					<td width="100%" align="center" bgcolor="#dbdee3">
					<table width="100%" cellpadding='3' cellspacing='3'>
   				<tr>
			    		
							<td width=2%>&nbsp;</td>
							<td width=14% align=center><b>Applicant No.</td>
							<td width=24% align=center><a href="<?=$PHP_SELF?>?position_id=<?=$position_id?>&gender=<?=$gender?>&min_age=<?=$min_age?>&max_age=<?=$max_age?>&sort_by=lname&sort_order=<?=$sort_order?>"><b>Applicant Name</a></td>
							<td width=7% align=center><b>Sex</b></td>
							<td width=8% align=center><a href="<?=$PHP_SELF?>?position_id=<?=$position_id?>&gender=<?=$gender?>&min_age=<?=$min_age?>&max_age=<?=$max_age?>&sort_by=birthdate&sort_order=<?=$sort_order?>"><b>Age</b></a></td>
							<td width=7% align=center><b>Height</b></td>
							<td width=7% align=center><b>Weight</b></td>														
							<!--<td width=18% align=center><b>Cellphone No.</b></td>-->
							<td width=17% align=center><b>Education</td>
							<td width=10% align=center><a href="<?=$PHP_SELF?>?position_id=<?=$position_id?>&gender=<?=$gender?>&min_age=<?=$min_age?>&max_age=<?=$max_age?>&sort_by=position1_yrsofexp&sort_order=<?=$sort_order?>"><b>Yrs. of Experience</a></td>								
					</tr>
			<? for($i=1;$i<=$found;$i++){ 
						$applicant_id = $result[$i]["applicant_id"];
						$educ = getdata("SELECT education FROM education WHERE applicant_id = '$applicant_id' ORDER BY to_date DESC");
						$ref = getdata_one("mid_east_format","principals","principal_id",$myprincipalid);
						if($ref["mid_east_format"]=='1') { $page='report_applicant3'; }
						if($ref["mid_east_format"]=='2') { $page='report_applicant_dubai'; }
						if($ref["mid_east_format"]=='3') { $page='report_applicant_hongkong'; }
						if($ref["mid_east_format"]=='4') { $page='report_applicant_hongkong2'; }
						if($ref["mid_east_format"]=='5') { $page='report_applicant_taiwan'; }
						if($ref["mid_east_format"]=='6') { $page='report_applicant_taiwan2'; }
						if($ref["mid_east_format"]=='7') { $page='report_applicant2'; }
						if($ref["mid_east_format"]=='8') { $page='report_applicant_version2'; }
						
						print "<tr>";
						
    				print "<td class=box align=right valign=top>$i.&nbsp;</td>";
						print "<td class=box valign=top><a href=\"".$page.".php?applicant_id=".$applicant_id."\" target=\"page$applicant_id\">".$applicant_id."</a></td>";
						print "<td class=box valign=top>".$result[$i]["name"]."</td>";    				
    				print "<td class=box align=center valign=top>".$result[$i]["sex"]."</td>";
						print "<td class=box align=center valign=top>".get_age($result[$i]["birthdate"])."</td>";						
						print "<td valign=top class=box align=center>";
						print ($result[$i]["height1"])? $result[$i]["height1"]." ".$result[$i]["height2"] : "";
						print "</td>";
						print "<td valign=top class=box align=center>";
						print ($result[$i]["weight1"])? $result[$i]["weight1"]." ".$result[$i]["weight2"] : "";
						print "</td>";    			
						//print "<td class=box align=left valign=top>";
						//print ($result[$i]["cellphone"])? $result[$i]["cellphone"] : "&nbsp;";
						//print "</td>";
						print "<td  class=box valign=top>".$educ[1]["education"]."</td>";						
						//print "<td class=box align=center valign=top>".get_yrs_exp($applicant_id)."</td>";
						print "<td class=box align=left valign=top>";
						print ($result[$i]["position1_yrsofexp"])? ($result[$i]["position1_yrsofexp"])."yrs" : "";
						print ($result[$i]["position1_yrsofexp"] && $result[$i]["position1_mosofexp"])? " & " : "";
						print ($result[$i]["position1_mosofexp"])? ($result[$i]["position1_mosofexp"])."mos" : "";
						print "</td>";
												
						print "</tr>";
      } // end of for loop
			?> </table>
		
		</td>
		<td background="img/midright-login.gif"><img src="img/midright-login.gif" border="0"></td></tr>
		<tr><td><img src="img/botleft-login.gif" border="0"></td>
		<td background="img/bottile-login.gif"><img src="img/bottile-login.gif" border="0"></td>
		<td><img src="img/botright-login.gif" border="0"></td></tr>
		</table>			
	</td></tr>
			<?
  } // end of if there is a result in search
	else{?>	
	<tr><td height="25" align='center'><font color=red>No applicants for the above criteria(s).</font></td></tr>
	<?	
	} 
}// end of if there is position_id
else{?>	
	<tr><td height="25" align='center'><font color=red>Pls. choose a position.</font></td></tr>
	<?
}	
?>
</table>
</td></tr>
</form>
<?
do_html_footer();
?>