<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Passenger Details</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function changeprint()
{
  document.getElementById('BUTTON').style.visibility="hidden";
  window.print();
  setTimeout("showprint()",1000);
}
function showprint()
{
  document.getElementById('BUTTON').style.visibility="visible";
}
</script>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	width:761px;
	height:31px;
	z-index:1;
	left: 106px;
	top: 5px;
}
#Layer2 {
	position:absolute;
	width:223px;
	height:38px;
	z-index:1;
	left: 42px;
	top: 61px;
}
.style2 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
</head>

<body>
    <h2 align="center">BUS INFORMATION MANAGEMENT SYSTEM</h2>  
    <h5>MOHANDAS COLLEGE OF ENGINEERING AND TECHNOLOGY</h5>

  <p>
  <?php
//print_r($_POST);
	include ("config.php");

//Generate Query
	if($_POST['category']=="Student")//If Student Is Selected
	{
			$q='SELECT * FROM student where ';
			//echo(strlen($q));
			
			if($_POST['Course']!="All")
			{
				  if(strlen($q)==28)
				  {
					$q=$q.'Batch="'.$_POST['Course'].'"';
				  }
				  else
				  {
				    $q=$q.' AND Batch="'.$_POST['Course'].'"';									     
				  }
				  if($_POST['Semester']!="All")
				  {
				 	 $q=$q.' AND Semester="'.$_POST['Semester'].'"';
				  }
			}
			if($_POST['Gender']!="All")
			{
			  	 if(strlen($q)==28)
			 	  {
						$q=$q.'Gender="'.$_POST['Gender'].'"';
			 	  }
				  else
				  {
				      $q=$q.' AND Gender="'.$_POST['Gender'].'"';
				  }
			}
			if($_POST['BusStop']!="All")
			{
			      if(strlen($q)==28)
			 	  {
					 $q=$q.'StopName="'.$_POST['BusStop'].'"';
				  }
				  else
				  {
				     $q=$q.' AND StopName="'.$_POST['BusStop'].'"';
				  }
			}
			if($_POST['BusNo']!="All")
			{ 
			      if(strlen($q)==28)
			 	  {
				     $q=$q.'BusNumber="'.$_POST['BusNo'].'"';
				  }
				  else
				  {
				     $q=$q.'AND BusNumber="'.$_POST['BusNo'].'"';
				  }
				     
			}
			if(strlen($q)==28)
			 	  {
				     $q=$q.' Status="1"';
				  }
				  else
				  {
				     $q=$q.' AND Status="1"';
				  }
			
						$i=0;
						$k=0;
						$q=$q." ORDER BY StopName";
						$result = mysql_query($q) or die(mysql_error());
						$num=mysql_num_rows($result);
						echo'<div class="style2" id="Layer2">Total Records:'.$num.' </div>';
						echo '<table width="80%"border="0" style="text-align:justify"  align="center"> <tr bgcolor="#72FAA2" style="font-weight:bold"> <td>Sl No</td><td>Ad No</td>
						<td>Name</td>
						<td>Gender</td>
						<td>Batch  </td>
						<td>Sem</td>
						<td>BusNo</td>
						<td>StopName</td>
					  </tr>';
						while($query_data = mysql_fetch_array($result))
						{
							$i++;
							if($k==0)
							{
							echo'<tr bgcolor="#FDE6B0"><td>'.$i.'</td><td>'.$query_data['AdmissionNo'].'</td><td>'.$query_data['Name'].'</td><td>'.$query_data['Gender'].'</td><td>'.$query_data['Batch'].'</td><td>'.$query_data['Semester'].'</td><td>'.$query_data['BusNumber'].'</td><td>'.$query_data['StopName'].'</tr>';
							$k=1;
							}
							else
							{
							  echo'<tr bgcolor="#F8FAAF"><td>'.$i.'</td><td>'.$query_data['AdmissionNo'].'</td><td>'.$query_data['Name'].'</td><td>'.$query_data['Gender'].'</td><td>'.$query_data['Batch'].'</td><td>'.$query_data['Semester'].'</td><td>'.$query_data['BusNumber'].'</td><td>'.$query_data['StopName'].'</tr>';
							  $k=0;
							}
						}	
						echo "</table>";
	}
	else//If Staff Is Selected
	{
			//////////////////////////////////////////////////////////////////
		//	print_r($_POST);
			
			$q='SELECT * FROM staff where ';			
			if($_POST['Department']!="All")
			{
				  if(strlen($q)==26)
				  {
					$q=$q.'Department="'.$_POST['Department'].'"';
				  }
				  else
				  {
				    $q=$q.' AND Department="'.$_POST['Department'].'"';									     
				  }
			}
			if($_POST['Gender']!="All")
			{
			  	 if(strlen($q)==26)
			 	  {
						$q=$q.'Gender="'.$_POST['Gender'].'"';
			 	  }
				  else
				  {
				      $q=$q.' AND Gender="'.$_POST['Gender'].'"';
				  }
			}
			if($_POST['BusStop']!="All")
			{
			      if(strlen($q)==26)
			 	  {
					 $q=$q.'StopName="'.$_POST['BusStop'].'"';
				  }
				  else
				  {
				     $q=$q.' AND StopName="'.$_POST['BusStop'].'"';
				  }
			}
			if($_POST['BusNo']!="All")
			{ 
			      if(strlen($q)==26)
			 	  {
				     $q=$q.'BusNumber="'.$_POST['BusNo'].'"';
				  }
				  else
				  {
				     $q=$q.'AND BusNumber="'.$_POST['BusNo'].'"';
				  }
				     
			}
				if(strlen($q)==26)
			 	  {
				     $q=$q.' Status="1"';
				  }
				  else
				  {
				     $q=$q.' AND Status="1"';
				  }
			
					
						$i=0;
						$k=0;
						$result = mysql_query($q) or die(mysql_error());
						$num=mysql_num_rows($result);
						echo'<div class="style2" id="Layer2">Total Records:'.$num.' </div>';
						echo '<table width="80%" border="0" style="text-align:justify"  align="center"> <tr bgcolor="#72FAA2" style="font-weight:bold"> <td>Serial No</td><td>Employee Id</td>
						<td>Name</td>
						<td>Gender</td>
						<td>Department</td>
						<td>BusNumber</td>
						<td>StopName</td>
					  </tr>';
						while($query_data = mysql_fetch_array($result))
						{
							$i++;
							if($k==0)
							{
							echo'<tr  bgcolor="#FDE6B0"><td>'.$i.'</td><td>'.$query_data['EmployeeId'].'</td><td>'.$query_data['Name'].'</td><td>'.$query_data['Gender'].'</td><td>'.$query_data['Department'].'</td><td>'.$query_data['BusNumber'].'</td><td>'.$query_data['StopName'].'</tr>';
							$k=1;
							}
							else
							{
							   echo'<tr bgcolor="#F8FAAF" ><td>'.$i.'</td><td>'.$query_data['EmployeeId'].'</td><td>'.$query_data['Name'].'</td><td>'.$query_data['Gender'].'</td><td>'.$query_data['Department'].'</td><td>'.$query_data['BusNumber'].'</td><td>'.$query_data['StopName'].'</tr>';
							   $k=0;
							}
						}	
						echo "</table>";
			//////////////////////////////////////////////////////////////////
	}
?>
  </h3>
</p>
  <p>&nbsp;  </p>
    
      <div class="style2" id="Layer2"></div>
 
    <table width="80%" border="0">
  <tr>
    <td align="right">
    <input name="BUTTON" id="BUTTON" type=BUTTON onclick="changeprint()"  value=" Print Data"/></td>
  </tr>
</table>
</body>
</html>
