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


if($msg) echo "<script>alert('$msg')</script>";
	do_html_header("Sourcing Survey");
	
	$position = getdata("select * from positions order by name");
	$status = getdata("select * from applicant_status order by status");
	$get_dubai_id = getdata("select country_id from country where name like 'Dubai%'");
	$dubai_id  = $get_dubai_id[1]["country_id"];

	$get_hongkong_id = getdata("select country_id from country where name like 'Hong%'");
	$hongkong_id  = $get_hongkong_id[1]["country_id"];

	$get_taiwan_id = getdata("select country_id from country where name like 'Taiwan%'");
	$taiwan_id  = $get_taiwan_id[1]["country_id"];

	if($status_id){
     $sql_status = " AND status='$status_id'";
  }else{
     $sql_status = " AND status='For Selection'"; 
     $status_id = "For Selection"; 
	}
	  
  $mideast_access = getfield("mid_east_format", "principals", "principal_id" , $myprincipalid); 	
	$prin_country_id =getfield("country_id", "principals", "principal_id", $myprincipalid);
					if($prin_country_id){
					    $sql_country = " AND (p.country_id=" . $prin_country_id . " OR p.country_id2 =" . $prin_country_id . ")";
					}
	?> 
	<form method=post action='<?=$PHP_SELF?>' name='source_survey_form'">
  <tr height=100%><td valign="top"><br>
	<table align=center width=100%>
	<tr class=white height=30>
			<td align=center>
			<table border=0 cellpadding='0' cellspacing='0'>
					<tr>
					<td>
					<?
				
					?>
					<b>Position :</b>
					<select name="position_id">
					<option value="0">-- Select Position --
					<?selectcode($position,"$position_id","position_id","name")?></select>
					&nbsp;&nbsp;
					<!--<b>Status :</b>
					<select name="status_id">
					<option value="0">-- Select status --
					<?selectcode($status,"$status_id","status","status")?></select>-->
					
					<br>
					<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;
					<input type=submit value="Get Applicants" clas="button">
					</td></tr>
					</table>
			</td>
	</tr>
 </form>
<?

if($status_id){
     $sql_status = " AND status='$status_id'";
}else{
     $sql_status = " AND status='For Selection'"; 
}
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)
{
 $sql_position = " AND p.position_id1 = '$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";
	}	


$sql= "SELECT distinct(p.applicant_id),
														p.picture_body,					 
														p.birthdate,
														p.passport,
														p.picture,
														p.sex,
														p.video,
														p.height1,p.height2,
														p.weight1,p.weight2,	
														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_gender				
										 $sql_country
										 $sql_status
										 $sql_age						 						 
										 ORDER BY $sql_sort_by $sort_order $add_sort
										 ";
	
	$result1 = getdata($sql);
  $search_found = count($result1);
?>
	<tr>
	 <td>
	 <table width=100% border=1 class='box'>
	 		<tr>			
	 		<td valign="top" align='left' class="box">
			
			<b>Search found:&nbsp;<?=$search_found?>&nbsp;<?=($search_found>1)?"applicants":"applicant"?></b></td>
			<td valign="top" align='right' class="box" style='padding-right:30px;'><?require("list_personal.inc");?></td>
			</tr>
	</table>
	</td>
	</tr>
	
<?
	$begin1=$begin-1;
	
	$sql= "SELECT distinct(p.applicant_id),
														p.country_id,
														p.country_id2,
														p.passport,
														p.birthdate,
														p.picture_body,
														p.picture,
														p.sex,
														p.video,
														p.height1,p.height2,
														p.weight1,p.weight2,	
														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_gender	
										 $sql_country			
										 $sql_age	
										 $sql_status					 						 
										 ORDER BY $sql_sort_by $sort_order $add_sort
										 limit $begin1,$range";
	
	$result = getdata($sql);
  $found = count($result);
  echo mysql_error();


if($found){ ?> 
			 
			<tr><td bgcolor="#dbdee3">
			
			  <table border=0>

			  <tr><td><font color=red>Note:</font></td>
				<td>&nbsp;</td><td>To reserve applicant(s), click on the checkbox and hit the "Reserve" button found at the bottom left of this page.</td></tr>
				</table>
			</td></tr>			 	
			<tr><td>
			<table border="0" cellpadding="0" cellspacing="0" >
			<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' border=0>
   			
			<form name='thisOnly' action='sqlupdate.php?what=status' method='get'>
						<input type="hidden" name="what" value="<?=status?>">
						<input type="hidden" name="gender" value="<?=$gender?>">
						<input type="hidden" name="age_min" value="<?=$age_min?>">
						<input type="hidden" name="age_max" value="<?=$age_max?>">
						<input type="hidden" name="position_id" value="<?=$position_id?>">
						<input type="hidden" name="principal_id" value="<?=$myprincipalid?>">
						
			 <tr>
			
					
					
			</tr>					
			<? 
			$count1=$begin; 
			for($i=1;($i <= $range) &&($count1 <= $total);$i++){
			      
			      if($i > $found){ break;}
						$applicant_id = $result[$i]["applicant_id"];																		
						$counter=($begin + $i)-1;
		        if($i==1){
						    $first = $counter;
						}
      } // end of for loop
			?>
			 <tr>
			 <td bgcolor="#f1f1f1" colspan=2>
			    showing <?=$first?>-<?=$counter?> of <?=$search_found?> <?=($search_found>1)?"applicants":"applicant";?>
			 </td>
			
			 </tr>    
			<?for($i=1;($i <= $range) &&($count1 <= $total);$i++){
			
			      if($i > $found){ break;}
						$applicant_id = $result[$i]["applicant_id"];
						$educ = getdata("SELECT education FROM education WHERE applicant_id = '$applicant_id' ORDER BY to_date DESC"); ?>
						
						<?if(!(($i%2)==0)){ ?>
						<tr>
						<? } ?>
						<td align=<?=($search_found==1)?"left":"center";?>>
						<table border=1 width=<?=($search_found==1)?480:"100%";?> cellpadding=3 cellspacing=3>
						   <tr>
							 		<td class="box">&nbsp;</td> 						 
							 		<td class='box' colspan=3><b>(<?=($begin + $i)-1?>)&nbsp;
									
									<?=$applicant_id?> <?=strtoupper($result[$i]["name"])?></b></td>	
							 </tr>
							 <tr>			
									<td bgcolor="#f1f1f1" rowspan=5 height=100 width=100 valign='middle' align='center'>
									<?if($result[$i][picture]){?>
									<img border=0 src="<?=$pic_dir1?><?=$result[$i][picture]?>" width=100 height=100>
									<?}else{ ?>
									photo
								 <? }?>
									
									</td>
							 		<td class='box'><b>sex:</b></td>
									<td class='box'><?=($result[$i][sex]=="M")?"Male":"Female";?></td>									 
							 </tr>		 
							 <tr>
							    <td class='box'><b>Age:</b></td><td class='box'><?=get_age($result[$i]["birthdate"])?></td>																														
							 </tr>
							 <tr>
							 <td class='box'><b>Height:</b></td><td class='box'><?=($result[$i]["height1"])? $result[$i]["height1"]." ".$result[$i]["height2"] : ""?></td>
							 </tr>
							  <tr>
							 <td class='box'><b>Weight:</b></td><td class='box'><?=($result[$i]["weight1"])? $result[$i]["weight1"]." ".$result[$i]["weight2"] : ""?></td>
							 </tr>	
							  <tr>
							 <td class='box'><b>Education:</b></td><td class='box'><?=$educ[1]["education"]?></td>
							 </tr>	
							 <tr>
							 <td class='box'>&nbsp;</td>
							 <td class='box' width=150><b>Years of Experience:</b></td><td class='box'>
							 <?=($result[$i]["position1_yrsofexp"])? ($result[$i]["position1_yrsofexp"])."yrs" : "";?>
						   <?=($result[$i]["position1_yrsofexp"] && $result[$i]["position1_mosofexp"])? " & " : "";?>
						   <?=($result[$i]["position1_mosofexp"])? ($result[$i]["position1_mosofexp"])."mos" : "";?>
							 </td>
							 </tr>
							 <tr><td class='box' valign="top"><b>Resume Format</b></td>
							 <td colspan=1 class='box'>
							 
							  <?
								if(($dubai_id == $result[$i]["country_id"]) || ($dubai_id == $result[$i]["country_id2"])){
								?>										
							  <a href="report_applicant_dubai.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">Middle East format</a><br>
								<?}
								?>
								<?if(($hongkong_id == $result[$i]["country_id"]) || ($hongkong_id == $result[$i]["country_id2"]) ){
								?>
								<a href="report_applicant_hongkong.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">Hongkong format</a><br>
								<?}
								?>
								
								<?if(($taiwan_id == $result[$i]["country_id"]) || ($taiwan_id == $result[$i]["country_id2"]) ){
								?>
								<a href="report_applicant_taiwan.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">Taiwan format (DH)</a><br>
								<a href="report_applicant_taiwan2.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">Taiwan format (Skilled)</a>
								<br>
								<?}
																
							 if(($dubai_id != $result[$i]["country_id"]) && ($dubai_id != $result[$i]["country_id2"])){
								  if($mideast_access == "Y"){ ?>								   
									 <a href="report_applicant_dubai.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">Middle East Format</a>
								   <br>
								<?}}
								
								/*if(($result[$i]["country_id"] != $taiwan_id) && ($result[$i]["country_id2"] != $taiwan_id) 
								    && ($result[$i]["country_id"] != $hongkong_id) && ($result[$i]["country_id2"] != $hongkong_id)
										&& ($result[$i]["country_id"] != $dubai_id) && ($result[$i]["country_id2"] != $dubai_id)){ */?>
										    <a href="report_applicant3.php?applicant_id=<?=$applicant_id?>" target="page$applicant_id">View Resume</a><br>
								<?	//	} 
								?>
							 </td>							
							 <td class=box align='left' valign='top'><input type='checkbox' name='reserve[]' value='<?=$applicant_id?>' class='radio_gray'>Click to include</td>							
							 </tr>
							 
							
							
							 <tr><td class='box'><b><?=($result[$i]["picture"])?"Pictures":"&nbsp;"?></b></td>			
							 <td colspan=2 class='box'>
							 <?if($result[$i]["picture"]){?>		
							   									 
						      <a href=# onclick="window.open('<?=$pic_dir1.$result[$i][picture]?>', 'picture', 
										             config='height=200, width=200, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no, copyhistory=no')">[2x2]</a>				 
							 <?echo "&nbsp;&nbsp;&nbsp;"; } ?>
							  
								<?if($result[$i]["picture_body"]){?>														 
						     <a href=# onclick="window.open('<?=$pic_dir1.$result[$i][picture_body]?>', 'picture_body', 
										             config='height=500, width=400, align=center, valign=top, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no, copyhistory=no')">[Whole body]</a>						 
							 <? } ?>
							 </td>
							 </tr>
							  <tr><td class='box'><b><?=($result[$i]["video"] && is_file($video_dir . "/" . $result[$i]["video"]))?"Video":"&nbsp;"?></b></td>
							 <td colspan=2 class='box'>
							 <?
							 if($result[$i]["video"] && is_file($video_dir . "/" . $result[$i]["video"])){ ?>
							 <!--
							 <a href=# onclick="window.open('display_video.php?path=<?=$video_dir.$result[$i][video]?>&title=<?=$name?>', 'video', 
										 config='height=400, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, directories=no, status=no, copyhistory=no')">[View video]</a>
										 -->
							 <a href=<?="../irisadmin/videos/".$result[$i][video]?>>[View video]</a>
										 
					  <?} ?>
							 
							 </td>
							 <?if(!(($i%2)==0)){ ?>
							 </tr>
							 <? }?>
						
						</tr>
						 <tr><td class='box'><b><?=($result[$i]["passport"] && is_file($passport_dir . $result[$i]["passport"]))?"Passport":"&nbsp;"?></b></td>			
							 <td colspan=2 class='box'>
							 	<?
						    if($result[$i]["passport"] && is_file($passport_dir . $result[$i]["passport"])){?>
							   									 
						    <!--  <a href=# onclick="window.open('<?=$pic_dir1.$result[$i][passport]?>', 'passport', 
										             config='height=200, width=200, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no, copyhistory=no')">[2x2]</a>-->				 
							   <a href=<?=$passport_dir.$result[$i]["passport"]?> target=_blank>[View passport]</a> 
							 <?echo "&nbsp;&nbsp;&nbsp;"; } ?>
							  
							 </td>
							 </tr>	
						</table>	
						
    <?  } // end of for loop
	          print "<tr><td><input type='submit' value='Reserve'></td></tr>"; 		
			?> </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>
	<!--additional -->
	
	<!--additional -->
			<?
  } // end of if there is a result in search
	else{?>	
	<tr><td height="25" align=center><font color=red>There is no on pool applicants under the above criteria(s).</font></td></tr>
	<?	
	} 
}// end of if there is position_id
?>
</table>
</td></tr>
 </form>
<?
do_html_footer();
?>