<link href="wstyle.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<div align="center">
<? if ($_GET['stat'] == '' ) { ?>
  <form name="form1" method="post" action="index.php?page=6&stat=search">
    <table width="50%" border="0">
        <tr>
          <td class="td1">Search By</td>
          <td class="td2"><label>
<select name="search_by" id="search_by">
              <option value="Receipt">Receipt No.</option>
              <option value="Plate">Plate No</option>
              <option value="traf_recpt">Traf .Rcpt No.</option>
              <option value="cpr">CPR</option>
            <option value="mobile">Mobile</option>
            	
          </select>
          </label></td>
        </tr>
        <tr>
          <td class="td1">Search</td>
          <td class="td2"><span id="sprytextfield1">
            <label>
            <input type="text" name="Search" id="Search">
            </label>
          <span class="textfieldRequiredMsg">A value is required.</span></span></td>
        </tr>
      </table>
    <p>&nbsp;</p>
  <table width="90%" border="0" align="center">
    <tr>
      <td class="td1">Long</td>
      <td class="td1">Short</td>
      <td class="td1">Name</td>
      <td class="td1">Date</td>
      <td class="td1"><div align="center">Plate No.</div></td>
      <td class="td1">Request time</td>
      <td class="td1">Status</td>
    </tr>
		<?
            $result = mysql_query("select outid,Size1,Size2,Name,Date_a,Plate,outid,p1_out_order.status,status0_dt from p1_out_order, p1_order_info where p1_out_order.oid =  p1_order_info.oid and p1_out_order.stop1 =0"); 
            while($row = mysql_fetch_array($result)){ 
        
        ?>
    <tr>
      <td class="td2"><div align="center"><? echo $row['Size1']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Size2']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Name']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Date_a']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Plate']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['status0_dt']; ?></div></td>
      <td class="td2"><? if ( $row['status'] == 0 ) { ?>Requested<? } ?><? if ( $row['status'] == 1 ) { ?><a href="index.php?page=6&stat=deleverd1&outid=<? echo $row['outid']; ?>" class="link">delivered</a><? } ?><? if ( $row['status'] == 2 ) { ?><a href="index.php?page=6&stat=underfixing&outid=<? echo $row['outid']; ?>" class="link">Under fixing</a><? } ?><? if ( $row['status'] == 3 ) { ?><a href="index.php?page=6&stat=fixed&outid=<? echo $row['outid']; ?>" class="link">Fixed</a><? } ?></td>
    </tr>  
		<?
			}
		?>    
  </table>
  </form>
 <? } if ( $_GET['stat'] == 'search' ) { ?>
  <table width="100%" border="0" align="center">
    <tr>
      <td class="td1"><div align="center">Date</div></td>
      <td class="td1"><div align="center">Time</div></td>
      <td class="td1"><div align="center">Plate No.</div></td>
      <td class="td1"><div align="center">urgency</div></td>
      <td class="td1"><div align="center">Type</div></td>
      <td class="td1"><div align="center">Number <br>
      of <br>
      Plate</div></td>
      <td class="td1"><div align="center">CPR</div></td>
      <td class="td1"><div align="center">Name</div></td>
      <td class="td1"><div align="center">Mobile</div></td>
      <td class="td1"><div align="center">Status</div></td>
      <td class="td1">Rack</td>
      <td class="td1">Send Request</td>
    </tr>
		<?
         
		 
		 if ($_POST['search_by'] == 'Receipt' ) {
		 

			$year = substr($_POST['Search'], 0, 2)+2000;
			$month = substr($_POST['Search'], 2, 2);
			$serial = substr($_POST['Search'], 6, 20)*1;
			
			$result = mysql_query("SELECT *  FROM p1_order_info where year = $year and month = $month and serial = $serial"); 
		 }else{  	
		    $result = mysql_query("SELECT *  FROM p1_order_info where ".$_POST['search_by']." = '".$_POST['Search']."'"); 
          }
		   
		    while($row = mysql_fetch_array($result)){ 
        
        ?>
    <tr>
      <td class="td2"><div align="center"><? echo $row['Date_a']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Time_a']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Plate']; ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Plate']; ?></div></td>
      <td class="td2"><div align="center"><?	
                        $result1 = mysql_query('select * from p1_plate_type where tyid = '.$row['Type1']); 
                        while($row1 = mysql_fetch_array($result1)){ 
                				echo $row1['plate_type'] ;
								
            
					}
				?></div></td>
      <td class="td2"><div align="center"><? echo $row['number_of_plate']; ?> </div></td>
      <td class="td2"><div align="center"><? echo $row['cpr']; ?> </div></td>
      <td class="td2"><div align="center"><? echo $row['Name']; ?> </div></td>
      <td class="td2"><div align="center"><? echo $row['mobile']; ?> </div></td>
      <td class="td2"><div align="center"><? 
	  					
						if ($row['status']=='0' ) {
							echo 'Factory';
						}	
						if ($row['status']=='1' ) {
							echo 'Printed';
						}	
						if ($row['status'] =='2' ) {
							$oid = $row['oid'];
							$query1 = mysql_query("SELECT * FROM p1_out_order where oid = ".$oid." order by outid desc"); 		
								if (mysql_num_rows($query1) <> "0")	{
								
										$status_24 = mysql_result($query1,0,"status");
										
										if ( $status_24 == 0 ){ echo 'Requested'; } 
										if ( $status_24 == 1 ){ echo 'delivered'; }
										if ( $status_24 == 2 ){ echo 'Under fixing'; }
										if ( $status_24 == 3 ){ echo 'Fixed'; }
								
									}else{
										echo 'Delivery';
									}
							
							
						}
						 ?></div></td>
      <td class="td2"><div align="center"><? echo $row['Rack'];	 ?>
      </div>      </td>
      <td class="td2"><a href="index.php?page=6&stat=send&oid=<? echo $row['oid']; ?>" class="link">Send Request</a></td>
    </tr>
		<?
			}
		?>    
  </table>
 <? } if ( $_GET['stat'] == 'add' ) { ?>
  <p class="td4">The Order is Sent</p>
  
  
 <? } if ( $_GET['stat'] == 'deleverd1' ) { ?>
  <form id="form2" name="form2" method="post" action="index.php?page=6&stat=deleverd&outid=<? echo $_GET['outid'];?>">
    <table width="95%" border="0">
      <tr>
        <td class="td1">Technitian Name</td>
        <td class="td2"><span id="spryselect1">
          <label>
          <select name="tid" id="tid">
            <option value="">Select ---></option>
   				 <?	
                        $result = mysql_query('select * from p1_technitian where stop_technitian = 0'); 
                        while($row = mysql_fetch_array($result)){ 
                ?>
                        <option value="<? echo $row['tid'] ?>"><? echo $row['technitian']?></option>
				<?
                      }
                ?>
          </select>
          </label>
        <span class="selectRequiredMsg">Please select technitian Name.</span></span></td>
      </tr>
    </table>
    <p>
      <input name="Submit" type="submit" class="Submit" id="Submit" value="Submit" />
    </p>
  </form>
  <p>&nbsp;</p>
  
<? } if ($_GET['stat'] == 'Error102' ) { ?>

		<span class="td4">The Order already Exists</span>
  <? } ?>
</div>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
//-->
</script>
