<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" />

<? if ($_GET['stat'] == '' ) { ?>
<style type="text/css">
<!--
.style1 {color: #EFB410}
.style2 {color: #004684}
-->
</style>

<p align="center" class="td4"><span>Damage</span> Report</p>
<table width="80%" border="0" align="center">
<tr>
      <td class="td3"><div align="center">Date</div></td>
      <td class="td3">Number of damage</td>
      <td class="td3">Show all damage</td>
    <td class="td3">Add</td>
    </tr>
				<?	
                        $uid=$_SESSION['Login_uid'];
                        $result = mysql_query('select * from p1_date where date_stop = 0 order by did desc'); 
                        while($row = mysql_fetch_array($result)){ 
                ?>	
    <tr>
      <td class="td2"><? echo $row['date_name']?></td>
      <td class="td2"><?
	  	$did = $row['did'];
      	$query = mysql_query("select count(*) as count from p1_damage where create_date = '".$row['date_name']."'");
		echo mysql_result($query,0,"count");
	  ?></td>
      <td class="td2"><a href="index.php?page=27&stat=show_all&datec=<? echo $row['date_name'] ?>" class="link">Show all damage to day</a></td>
      <td class="td2"><a href="index.php?page=27&stat=save_date&did=<? echo $row['did'] ?>&date_name=<? echo $row['date_name']?>" class="text1">Add</a></td>
    </tr>
    	<? } ?>
  </table>
<? } if ($_GET['stat'] == 'add_damage' ) {?>
<form id="form1" name="form1" method="post" action="index.php?page=27&stat=adddamagedb">
  <table width="90%" border="0" align="center">
    <tr>
      <td colspan="4" class="td5">Add Damage</td>
    </tr>
    <tr>
      <td width="25%" class="td1"><div align="center">Date</div></td>
      <td class="td2"><? echo $_SESSION['27_date_name'] ?></td>
      <td width="25%" class="td1">Plate No.</td>
      <td class="td2"><span id="sprytextfield1">
      <input type="text" name="plate" id="plate" />
      <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
    </tr>
    <tr>
      <td class="td1">Plate Type</td>
      <td class="td2"><span id="spryselect3">
        <select name="tyid" id="tyid">
          <option value=""></option>
          <?
		$result_lest = mysql_query("select * from p1_plate_type"); 
		while($row = mysql_fetch_array($result_lest)){ 
	?>
          <option value="<? echo $row['tyid']; ?>"><? echo $row['plate_type']; ?></option>
          <? } ?>
        </select>
      <span class="selectRequiredMsg">*</span></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="td1">Staff</td>
      <td class="td2"><span id="spryselect1">
        <select name="sid" id="sid">
          <option value=""></option>
     <?
		$result_lest = mysql_query("SELECT * FROM p1_staff where stop_staff = 0"); 
		while($row = mysql_fetch_array($result_lest)){ 
	?>
          <option value="<? echo $row['sid']; ?>"><? echo $row['staff']; ?></option>
    <? } ?>      
        </select>
      <span class="selectRequiredMsg">*</span></span></td>
      <td class="td1">Reason of Damage</td>
      <td class="td2"><span id="spryselect2">
        <select name="reason_of_damage" id="reason_of_damage">
          <option value=""></option>
          <option value="Counter">Counter</option>
          <option value="Printing">Printing</option>
          <option value="Hot stamp">Hot stamp</option>
	  <option value="Wrong Hole">Wrong hole</option>
	   <option value="Others">Others</option>
        </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
    </tr>
    <tr>
      <td class="td1">Number of Plate Short</td>
      <td class="td2"><span id="sprytextfield2">
        <input type="text" name="plate_no_s" id="plate_no_s" />
        <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
      <td class="td1">Number of Plate Long</td>
      <td class="td2"><span id="sprytextfield2"><span id="sprytextfield3">
      <input type="text" name="plate_no_l" id="plate_no_l" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
    </tr>
    <tr>
      <td class="td1">Note</td>
      <td colspan="3" class="td2"><input name="note" type="text" id="note" size="70" /></td>
    </tr>
  </table>
<p align="center">
      <label>
      <input name="Submit" type="submit" class="Submit" id="Submit" value="   Save   " />
      </label>
    </p>
</form>
<? }if ($_GET['stat'] == 'show_all' ) { 
$_SESSION['27_date_name'] = $_GET['datec'];

?>
	<table width="95%" border="0" align="center">
      <tr>
        <td rowspan="2" class="td1">ID</td>
        <td rowspan="2" class="td1">Plate No</td>
        <td rowspan="2" class="td1">Staff</td>
        <td rowspan="2" class="td1">Plate Type</td>
        <td colspan="2" class="td1">Number of Plate</td>
        <td rowspan="2" class="td1">Reason of Damage</td>
        <td rowspan="2" class="td1">Note</td>
       <? if($_SESSION['P1_Login_control_user'] == 1 ) { ?>  <td rowspan="2" class="td1">Edit</td><? } ?>
      </tr>
      <tr>
        <td class="td1">Short</td>
        <td class="td1">Long</td>
      </tr>
     <?
		 $i = 0;
		 //$did = $_GET['did'];
		//$result_lest = mysql_query("SELECT * FROM p1_damage where did = $did"); 
		$create_date = $_GET['datec'];
		$result_lest = mysql_query("SELECT * FROM p1_damage where create_date = '$create_date'"); 
		
		while($row = mysql_fetch_array($result_lest)){ 
		
		$i = $i + 1;
	?>
      <tr>
        <td class="td2"><? echo $i  ?></td>
        <td class="td2"><? echo $row['plate'] ?></td>
        <td class="td2"><? 
					$query = mysql_query("SELECT * FROM p1_staff where sid  = ".$row['sid']); 		
					echo  mysql_result($query,0,"staff");
		
		
		  ?></td>
        <td class="td2"><?	
                        $result1 = mysql_query('select * from p1_plate_type where tyid = '.$row['tyid']); 
                        while($row1 = mysql_fetch_array($result1)){ 
                				echo $row1['plate_type'] ;
					}
				?></td>
        <td class="td2"><? echo $row['plate_no_s'] ?></td>
        <td class="td2"><? echo $row['plate_no_l'] ?></td>
        <td class="td2"><? echo $row['reason_of_damage'] ?></td>
        <td class="td2"><? echo $row['note'] ?></td>
       <? if($_SESSION['P1_Login_control_user'] == 1 ) { ?>  <td class="td2"><a href="index.php?page=27&stat=edit&id=<? echo  $row['damid'];?>" class="link">Edit</a></td><? } ?>
      </tr>
     <? } ?> 
    </table>
<? }if ($_GET['stat'] == 'edit' ) { 
			$query = mysql_query("SELECT * FROM p1_damage where damid  = ".$_GET['id']); 		
			$_SESSION["27_damid"] = $_GET['id'];
?>
    
<form id="form1" name="form1" method="post" action="index.php?page=27&stat=updatedamagedb">
  <table width="90%" border="0" align="center">
    <tr>
      <td colspan="4" class="td5">Add Damage</td>
    </tr>
    <tr>
      <td width="25%" class="td1"><div align="center">Date</div></td>
      <td class="td2"><? echo $_SESSION['27_date_name'] ?></td>
      <td width="25%" class="td1">Plate No.</td>
      <td class="td2"><span id="sprytextfield1">
      <input type="text" name="plate" id="plate" value="<? echo  mysql_result($query,0,"plate"); ?>" />
      <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
    </tr>
    <tr>
      <td class="td1">Plate Type</td>
      <td class="td2"><span id="spryselect3">
        <select name="tyid" id="tyid">
          <option value=""></option>
          <?
		$result_lest = mysql_query("select * from p1_plate_type"); 
		while($row = mysql_fetch_array($result_lest)){ 
	?>
          <option value="<? echo $row['tyid']; ?>" <? if ( $row['tyid'] == mysql_result($query,0,"tyid") ){ ?>selected="selected"<? } ?> ><? echo $row['plate_type']; ?></option>
          <? } ?>
        </select>
      <span class="selectRequiredMsg">*</span></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="td1">Staff</td>
      <td class="td2"><span id="spryselect1">
        <select name="sid" id="sid">
          <option value=""></option>
     <?
		$result_lest = mysql_query("SELECT * FROM p1_staff where stop_staff = 0"); 
		while($row = mysql_fetch_array($result_lest)){ 
	?>
          <option value="<? echo $row['sid']; ?>" <? if ( $row['sid'] == mysql_result($query,0,"sid") ){ ?>selected="selected"<? } ?> ><? echo $row['staff']; ?></option>
    <? } ?>      
        </select>
      <span class="selectRequiredMsg">*</span></span></td>
      <td class="td1">Reason of Damage</td>
      <td class="td2"><span id="spryselect2">
        <select name="reason_of_damage" id="reason_of_damage">
          <option value=""></option>
          <option value="Counter" <? if (mysql_result($query,0,"reason_of_damage")  == "Counter" ){ ?>selected="selected"<? } ?> >Counter</option>
          <option value="Printing" <? if (mysql_result($query,0,"reason_of_damage")  == "Printing" ){ ?>selected="selected"<? } ?> >Printing</option>
          <option value="Hot stamp" <? if (mysql_result($query,0,"reason_of_damage")  == "Hot stamp"){ ?>selected="selected"<? } ?> >Hot stamp</option>
        </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
    </tr>
    <tr>
      <td class="td1">Number of Plate Short</td>
      <td class="td2"><span id="sprytextfield2">
        <input type="text" name="plate_no_s" id="plate_no_s" value="<? echo  mysql_result($query,0,"plate_no_s"); ?>" />
        <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
      <td class="td1">Number of Plate Long</td>
      <td class="td2"><span id="sprytextfield2"><span id="sprytextfield3">
      <input type="text" name="plate_no_l" id="plate_no_l" value="<? echo  mysql_result($query,0,"plate_no_l"); ?>" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></td>
    </tr>
    <tr>
      <td class="td1">Note</td>
      <td colspan="3" class="td2"><input name="note" type="text" id="note" size="70" value="<? echo  mysql_result($query,0,"note"); ?>" /></td>
    </tr>
  </table>
<p align="center">
      <label>
      <input name="Submit" type="submit" class="Submit" id="Submit" value="   Update   " />
      </label>
    </p>
</form>

<?  } ?>
  <script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "integer", {useCharacterMasking:true});
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "integer", {useCharacterMasking:true});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "integer", {useCharacterMasking:true});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "integer", {useCharacterMasking:true});
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3");
//-->
</script>
