<style>
  .pwbtn{
    width:50px;
	cursor:pointer;
  }
  .sortbtn{
    width:70px;
	cursor:pointer;
  }
  .tblfont{
    font-size:25px;
	margin: 0px 5px 0px 5px;
  }
  .infomsg{
    color:#0000FF; 
	font-size:18px;
  }
  .errmsg{
    color:#FF0000; 
	font-size:18px;
  }	
</style>

<script>
  var loadImage = function(event){
	  var myphoto = document.getElementById('myphoto');
	  myphoto.src = URL.createObjectURL(event.target.files[0]);
	  myphoto.onload = function(){
		  URL.revokeObjecjtURL(myphoto.src)
	  }
  };
  
  function saveSubmit(){
    document.getElementById("frmAdd").submit();
  }
</script>

<?php
  $myprod = new PRODUCT();
  $arrProd = $myprod->getProducts(" ORDER BY tb_order ");
?>
<?php
if( !empty($_SESSION["infomsg"])){
  echo "<span class='infomsg'>" . $_SESSION["infomsg"] . "</span>";
  unset($_SESSION["infomsg"]);
}
?>
<?php
if( !empty($_SESSION["errmsg"])){
  echo "<span class='errmsg'>" . $_SESSION["errmsg"] . "</span>";
  unset($_SESSION["errmsg"]);
}
?>
<table border="1" style="border-collapse:collapse">

  <tr>
    <td colspan="5" align="right" style="font-weight:bold;">Sorting... &nbsp;&nbsp;</td>
	<td align="center"><a href="main.php?pg=pdts"><img src="img/ico_sort.png" class="sortbtn"></a></td>
  </tr>

  <form id="frmAdd" action="pg_product_sav.php" method="post" enctype="multipart/form-data">
  <tr align="center">
    <td><span class="tblfont"><img style="height:35px" id="myphoto" src="../img/ico_image.png" /></span></td>
	<td><input type="text" name="cname" style="width:120px; font-size:18px; text-align:center" /></td>
	<td><input type="text" name="ename" maxlength="15" style="width:170px; font-size:18px; text-align:center" /></td>
	<td><input type="text" name="price" style="width:80px; text-align:center"/></td>
	<td style="width:70px"><input type="text" name="stock" value="100" style="width:50px; text-align:center"/></td>
	<td><img src="img/ico_save.png" class="pwbtn" onclick="saveSubmit()"></td>
  </tr>
  <tr>
    <td colspan="6"><input type="file" id="myphoto" name="myphoto" width="50px" onChange="loadImage(event)" ></td>
  </tr>
  </form>
  <tr>
    <td style="background-color:#000000" colspan="6"></td>
  </tr>
<?php
foreach($arrProd as $tid=>$tprod){
  if($tprod["pstatus"]==0){
    $mystyle="text-decoration:line-through; color:#999999";
  }else{
    $mystyle="";
  }
  ?>
  <tr style="<?= $mystyle ?>">
	<td><span class="tblfont"><img style="height:32px;" src="../img/<?= $tprod["photo"] ?>" /></span></td>
    <td><span class="tblfont"><?= $tprod["name"] ?></span></td>
	<td><span class="tblfont"><?= $tprod["ename"] ?></span></td>
	<td><span class="tblfont"><?= $myprod->getRinggit($tprod["price"]) ?></span></td>
	<td align="center"><span class="tblfont"><?= $tprod["stock"] ?></span></td>
	<td width="80px" align="center"><a href="main.php?pg=pdte&id=<?= $tid ?>"><img src="img/ico_edit.png" class="pwbtn"></a></td>
  </tr>
  <?php
}
?>
</table>