<script language='javascript'>
	function btnCancel(){
		window.location = 'main.php?pg=sys&ac=evt';
	}
	function cfmdel(pid,pname){
		var response = confirm("Are you sure to delete ["+pname+"]?");
		
		if(response==true){
            document.getElementById("delid").value = pid;
            document.getElementById("frmdel").submit();
		}else{
		    return false;
		}
	}
</script>
<form id="frmdel" action="sysevtdel.php" method="post">
    <input type="hidden" id="delid" name="id">
</form>

<style>
  .mytable{
    font-size:16px;
	width:700px;
	margin-top:10px;
	color:#FFFFFF;
  }
  
  .mytableth{
    background-color:#000000;
	color:#FFCC00;
	padding:5px 5px 5px 5px;
  }
  
    .mytabletd{
        background-color: #EEEEEE;
        text-align: center;
        color: #000000;
    }
    
  .mybtn{
    width:100px;
	font-size:14px;
	font-weight: bold;
	font-family: Arial;
  }
    
    .mybtnsubmit{
        padding: 3px 10px 3px 10px;
	    font-size:14px;
	    font-weight: bold;
	    font-family: Arial;
        color: #0000FF;
    }
    
  .mytext{
    text-align: center;
    padding: 3px;
  }
</style>

<center>
<?php
  if($_SESSION["errmsg"]!==""){
    echo $_SESSION["errmsg"];
    unset($_SESSION["errmsg"]);
  }
?>

<?php
  //----- add new remark list --------------------
  if($_GET["ac2"]!="edt"){
?>

<form action="sysevtsav.php" method="post">
<table border="0" cellpadding="0" cellspacing="1" class="mytable">
  <tr>
    <th class="mytableth" colspan="3">ADD REMARK TYPE</th>
  </tr>
  <tr>
    <td class="mytabletd"><input type="text" name="remark" class="mytext" style="width: 230px" placeholder="remark type..."></td>
  </tr>
  <tr>
    <th class="mytableth" colspan="3">
        <input type="submit" value="ADD REMARK TYPE" class="mybtnsubmit">
    </th>
  </tr>
</table>
</form>
    
<hr>
    
<?php
  }
  //----- end add new remark --------------------
?>
    
<?php
  //----- edit remark list --------------------
  if($_GET["ac2"]=="edt"){
      
    $pid = $_GET["pid"];

    $query = "SELECT * FROM punchsys_remarkevent WHERE id=" . $pid;
    $result = mysqli_query($conn,$query);
    while($myrow = mysqli_fetch_array($result)){
        $pid = $myrow["id"];
        $pevent = $myrow["event"];
    }
?>

<form action="sysevtup.php" method="post">
<input type="hidden" name="pid" value="<?= $pid ?>">
<table border="0" cellpadding="0" cellspacing="1" class="mytable">
  <tr>
    <th class="mytableth" colspan="3">EDIT REMARK TYPE</th>
  </tr>
  <tr>
    <td class="mytabletd"><input type="text" name="remark" class="mytext" style="width: 230px; background-color: #FFFF00" value="<?= $pevent ?>" placeholder="remark type..."></td>
  </tr>
  <tr>
    <th class="mytableth" colspan="3">
        <input type="submit" value="UPDATE REMARK TYPE" class="mybtnsubmit">
		<input type="button" value="DELETE" onclick="cfmdel('<?= $pid ?>','<?= $pevent ?>')" class="mybtnsubmit" style="color:#FF0000" />
    </th>
  </tr>
</table>
</form>
    
<hr>
    
<?php
  }
  //----- end edit new remark --------------------
?>
    
<?php
  //----- remark page --------------------
  $qremark = "SELECT * FROM punchsys_remarkevent ORDER BY tb_ord, event";
  $rremark = mysqli_query($conn,$qremark);
  $nremark = mysqli_num_rows($rremark);
?>

    <table border="0" cellpadding="0" cellspacing="1" class="mytable">
      <tr>
        <th class="mytableth" style="width: 12px"></th>
        <th class="mytableth">EVENT LIST</th>
        <th class="mytableth">ACTION</th>
      </tr>
      <?php
      if($nremark>0){
      $i = 1;
      while($myrow = mysqli_fetch_array($rremark)){
        if( ($i%2)==0 ){
          $tcolor = "#EEEEEE";
        }else{
          $tcolor = "#DDDDDD";
        }
        ?>
      <tr>
        <td class="mytabletd" style="background-color: <?= $tcolor ?>"><?= $i ?></td>
        <td class="mytabletd" style="background-color: <?= $tcolor ?>"><?= $myrow["event"] ?></td>
        <td class="mytabletd" style="background-color: <?= $tcolor ?>"><input type="button" value="EDIT" class="mybtnsubmit" onClick="frmEdit('<?= $myrow["id"] ?>')"></td>
      </tr>
        <?php
          $i++;
      }
      }
      ?>
    </table>
    
    <script>
        function frmEdit(pid){
           document.getElementById("pid").value = pid;
           document.getElementById("frmedit").submit();
        }
    </script>
    
    <form id="frmedit" action="main.php" method="get">
        <input type="hidden" name="pg" value="sys">
        <input type="hidden" name="ac" value="evt">
        <input type="hidden" name="ac2" value="edt">
        <input type="hidden" name="pid" id="pid" value="">
    </form>
    
    <br>
    

    

</center>
	</center>