<?include_once($_SERVER['DOCUMENT_ROOT']."/gew2011/settings.php");?>
<table id='table'><tbody>
<tr>
	<td align='right' width='10%'>
		Enter Search Criteria :
	</td>
	<td width='70%' colspan='3'>
		<input type='text' name='searchTxt' size='50' value='<?=$_REQUEST['searchTxt'];?>'> <input type='submit' name='confirm' value='Search'>
	</td>
</tr>
<tr>
	<td align='right'>
		Criteria Type :
	</td>
	<td colspan='3'>
		<?
			if (isset($_REQUEST['searchType'])){
				if ($_REQUEST['searchType']=="Name"){
					echo "<input type='radio' name='searchType' value='All'>All <input type='radio' name='searchType' value='Name' checked>Name <input type='radio' name='searchType' value='Company'>Institute/Organisation<input type='radio' name='searchType' value='Number'>Delegate Number";
				}else if ($_REQUEST['searchType']=="Company"){
					echo "<input type='radio' name='searchType' value='All'>All <input type='radio' name='searchType' value='Name'>Name<input type='radio' name='searchType' value='Company' checked>Institute/Organisation<input type='radio' name='searchType' value='Number'>Delegate Number";
				}else if ($_REQUEST['searchType']=="Number"){
					echo "<input type='radio' name='searchType' value='All'>All <input type='radio' name='searchType' value='Name'>Name <input type='radio' name='searchType' value='Company'>Institute/Organisation<input type='radio' name='searchType' value='Number' checked>Delegate Number";
				}else{
					echo "<input type='radio' name='searchType' value='All' checked>All <input type='radio' name='searchType' value='Name'>Name <input type='radio' name='searchType' value='Company'>Institute/Organisation<input type='radio' name='searchType' value='Number'>Delegate Number";
				}
			}else{
				echo "<input type='radio' name='searchType' value='All' checked>All <input type='radio' name='searchType' value='Name'>Name <input type='radio' name='searchType' value='Company'>Institute/Organisation<input type='radio' name='searchType' value='Number'>Delegate Number";
			}
		?>
	</td>
</tr>
<tr>
	<td colspan='4'>
		&nbsp;
	</td>
</tr>
<?
	if (isset($_REQUEST['confirm'])){
		switch ($_REQUEST['searchType']){
			case "Name":
				$SQL = "SELECT * FROM tbl_registrants_test WHERE registrant_firstname LIKE '%".$_REQUEST['searchTxt']."%' OR registrant_lastname LIKE '%".$_REQUEST['searchTxt']."%' AND registrant_attendance='Yes' ORDER BY registrant_lastname;";
				break;
			case "Company":
				$SQL = "SELECT * FROM tbl_registrants_test WHERE registrant_institute LIKE '%".$_REQUEST['searchTxt']."%' AND registrant_attendance='Yes' ORDER BY registrant_lastname;";
				break;
			case "Number":
				$SQL = "SELECT * FROM tbl_registrants_test WHERE registrant_sn LIKE '%".$_REQUEST['searchTxt']."%' AND registrant_attendance='Yes' ORDER BY registrant_lastname;";
				break;
			case "All":
				$SQL = "SELECT * FROM tbl_registrants_test WHERE registrant_sn LIKE '%".$_REQUEST['searchTxt']."%' OR registrant_institute LIKE '%".$_REQUEST['searchTxt']."%' OR  registrant_firstname LIKE '%".$_REQUEST['searchTxt']."%' OR registrant_lastname LIKE '%".$_REQUEST['searchTxt']."%' AND registrant_attendance='Yes' ORDER BY registrant_lastname;";
				break;
		}
		$results=$qry->queryMultiSelect($SQL);
		$i=0;
		$output = "<tr><td align='left'><b>Delegate Number</b></td><td align='left' colspan='2'><b>Last Name, First Name</b></td><td align='left'><b>Institute/Organisation</b></td></tr>";
		foreach ($results as $result){
			$i++;
			$SQL = "SELECT count(*) as number FROM tbl_registrant_attendance WHERE registrant_id='".$result['registrant_id']."';";
			$exist = $qry->querySelectSingle($SQL);
			if ($exist['number']==0)
				$output.="<tr><td width='10%'>".$result['registrant_sn']."</td><td colspan='2'><a href='inc/admin_edit.php?registrant_id=".$result['registrant_id']."&KeepThis=true&TB_iframe=true&height=500&width=600' class='thickbox'>".$result['registrant_lastname'].", ".$result['registrant_firstname']." </td><td align='left'>".$result['registrant_institute']."</td></tr>";
			else
				$output.="<tr><td width='10%'><font color='red'>".$result['registrant_sn']."</font></td><td colspan='2'><a href='inc/admin_edit.php?registrant_id=".$result['registrant_id']."&KeepThis=true&TB_iframe=true&height=500&width=600' class='thickbox'>".$result['registrant_lastname'].", ".$result['registrant_firstname']." </a></td><td align='left'>".$result['registrant_institute']."</td></tr>";				
		}
		if ($i==0)
			echo "<tr><td colspan='3' align='center'><b>No such person found</b></td></tr>";
		else
			echo $output;
	}
?>
</tbody>
</table>
