<?php
include("../include/session.php");
if(!$session->isAdmin() && !$session->isRadstoneReceptionUser()){
	header("Location: ../Store/productionMenu.php");
}
else {
//	include("../include/db.php");
	include("../reportHeader.php");
	include("megaEmpSearch.php");
	$q = "SELECT * FROM nam_employees";
	$count = 0;
	
	foreach($_POST as $key => $value){
		if(strlen($value) > 0){
			if(!preg_match("/Check/i", $key) && $key !="submitok"){
				if($count > 0){
					$q.= " AND";
				}

				if($count < 1){
					$q .= " WHERE";
					$count++;
				}

				if($key == "age1"){
					$date = date("Y-m-d", mktime(0,0,0,date("m"),date("d"),date("Y")-$value));
					$q .= " empAge < '$date'";
				}else if($key == "age2"){
					$date = date("Y-m-d", mktime(0,0,0,date("m"),date("d"),date("Y")-$value));
					$q .= " empAge > '$date'";
				}else if($key == "empRate1"){
					$q .= " empRate > '$value'";
				}else if($key == "empRate2"){
					$q .= " empRate < '$value'";
				}else {
					$q .= " $key = '$value'";
				}

			}
		}
	}
	echo $q;
	$result = execsql($q);
	$num = mysql_num_rows($result);
	if($num == 0){
		echo "Sorry there are no results matching your search criteria";
	}else{
		?>
		<hr />
		<h1>Results:</h1>
<table id="test1" cellpadding="0" cellspacing="0" border="0"
	class="rowstyle-alt colstyle-alt no-arrow">
	<thead>
		<tr>
			<th class="sortable-text">Employee Name</th>
			<th class="sortable-numeric">Age</th>
			<th class="sortable-numeric">Rate</th>
			<?php
			$i = 0;
			while($i < $num){
				$a1 = mysql_result($result, $i, "empFName");
				$a2 = mysql_result($result, $i, "empLName");
				$a3 = mysql_result($result, $i, "empAge");
				$a4 = mysql_result($result, $i, "empRate");
				$a5 = mysql_result($result, $i, "empId");
					
				?>

		</tr>
	</thead>
	<tbody>
		<tr>
			<td><a href="../HR/searchAndDisplayE.php?id=<?php echo $a5?>"><?php echo "$a1 $a2";?></a></td>
			<td><?php echo $a3?></td>
			<td><?php echo $a4?></td>
		</tr>
		<?php 
				$i++;
			}
		?>
		</tbody></table><?php echo $a5?>



	<?php
			
	}

}