<?php
  include "include/dbcon.php";
//  include "include/lang.php";
//  include "../admsys/include/CTEACHER.php";
//  include "include/CFUNCTION2.php";
//  include "../admsys/include/CSYSTEM.php";

  date_default_timezone_set("Asia/Kuala_Lumpur");
?>
<?php
//  $mysys = new CSYSTEM();
?>
<?php
  global $conn;
  $todate = date('Y-m-d');

  $arrExsttgval[] = "enable_adminpage_login";
  $arrExsttgval[] = "enable_punchpage";
  $strExsttgval = "'".implode("','",$arrExsttgval)."'";

  $qexsttg = "SELECT * FROM punchsys_exsttg WHERE name IN ($strExsttgval)";
  $rexsttg = mysqli_query($conn,$qexsttg);
  while($myrow = mysqli_fetch_array($rexsttg)){
	$tname = $myrow["name"];
	$tval = $myrow["val"];
	$arrExsttg[$tname] = $tval;
  }
?>

<html>
<head>
<title>EZ ATTENDANCE SYSTEM v.2.0</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--meta http-equiv="Content-Type" content="text/html; charset=utf-8"-->

	<style>
		@font-face {
			font-family: "mytechfont";
			src: url("font/Technology.woff") format("woff");
			font-weight: normal;
			font-style: normal;
		}
		
	  .div_btn{
	    text-align:center;
	  }
        
	  .div_report{
	    width:700px;
	    height:250px;
	    border-style:inset;
	    overflow:auto;
	    text-align:left;
	  }
	
	  .div_notice{
		position:absolute;
		left:400px;
		top:30px;
		background-color:#EEEEEE;
		color:#0000FF;
		width:700px;
		border-style:outset;
		text-align:center;
		font-family:Arial;
		font-size:25px;
		position:absolute;
	  }
		
	 .spanlogin{
	   font-family:Arial;
	   font-size:18px;
      }
        
     .txtlogin{
  	   width:380px;
	   text-align:center;
	   border-radius: 5px;
	   font-size:22px;
	   height:40px;
     }
        
	.divAnnouce{
		height: 100px; 
		width: 780px; 
		font-family: Arial;
        font-size: 20px;
		text-align: left;
		background-color: black; 
		color: #00FF00;
		padding-left: 10px;
		padding-top: 10px;
	}
	
	</style>
	<script>
	var alpha = 50;
	var refreshIntervalId;
	
	function setOpacity() {
		myfield.style.opacity = alpha/10;
		myfield.style.filter = 'alpha(opacity=' + alpha*10 + ')';
		alpha = alpha - 1;
		if(alpha<0){
		  clearInterval(refreshIntervalId);
		  myfield.style.display = "none";
		}
	}
	
	function disMsg(pmsg){
	  myfield.innerHTML = "<br>" + pmsg + "<br><br>";
	  refreshIntervalId = setInterval("setOpacity()",100);
	}
	
	</script>
	

	</head>
	<body background="img/bg2.jpg">
	<br>
	
	<center>

	<table background="img/bg.jpg" border="0" style="border-collapse: collapse;">
	<tr align="center" >
	  <th bgcolor="#1B1B19">
		<img src="img/title.png" height="100px">
	  </th>
	</tr>
	<tr>
	  <th style="background: #1B1B19">
		<iframe marginheight="0" marginwidth="0" width="1000px" height="110px" src="timepage.php" style="overflow:inherit; margin-top:0" frameborder="0"></iframe>
	  </th>
	</tr>
	
	
	<tr>
	  <th style="font-family:Arial; font-size:16px; text-align:center;">
          
		<table style="width: 100%" border="0">
		<tr>
            
          <form name="myform" action="punch.php" method="post">
          <th width="250px" valign="top" rowspan="2">
            <span style="text-shadow: 0 0 6px #FFFFFF; font-size: 20px">
            <?php
              if($_SESSION["errmsg"]!==""){
				echo $_SESSION["errmsg"];
				unset($_SESSION["errmsg"]);
              }else{
				echo "asdf";
			  }
			?>
            </span>
			<br>
			<input type="text" name="txtId" id="txtId" class="txtlogin" style="width: 200px; margin-top: 10px; margin-bottom: 10px" placeholder="PUNCH ID" />
		  </th>
          </form>
                
            
<?php
  $qannouce = "SELECT * FROM punchsys_announce WHERE dateFrom<='$todate' AND dateEnd>='$todate' ORDER BY dateFrom";
  $rannouce = mysqli_query($conn,$qannouce);
  $nannouce = mysqli_num_rows($rannouce);
  if($nannouce>0){
      $strAnnouce0 = "<marquee behavior='scroll' direction='up' hspace='10px' scrollamount='1' style='height: 90px'><ul>";
      $strAnnouce1 = "</ul></marquee>";
      
      while($myrow = mysqli_fetch_array($rannouce)){
          $tannouce .= "<li>" . $myrow["descr"] . "</li>";
      }
      
      $strAnnouce = $strAnnouce0 . $tannouce . $strAnnouce1;
  }else{
      $strAnnouce = "NO ANNOUNCEMENT";
  }
?>
		  <th>
		  <div class="divAnnouce">
              <?= $strAnnouce ?>
                        <!--marquee behavior="scroll" direction="up" hspace="10px" scrollamount=1 style="height: 90px">[28-06-2026] CUTI PERGANTIAN SEKOLAH</marquee-->
                        <!--NO ANNOUNCEMENT-->
          </div>
		  </th>
		</tr>
            
		<tr>
		  <th align="center">
	          
	<?php
		$qstaff = "SELECT * FROM punchsys_staff WHERE id NOT IN ('admin','pejabat')";
		$rstaff = mysqli_query($conn,$qstaff);
		while($myrow = mysqli_fetch_array($rstaff)){
			$tid = $myrow["id"];
			$tname = $myrow["eName"];
			$arrStaff[$tid] = $tname;
		}
	?>
	<?php
		$query = "SELECT * FROM punchsys_punchrecord WHERE punchDate='$todate'";
		$result = mysqli_query($conn,$query);
		$num = mysqli_num_rows($result);
	?>
            <div style="width: 800px; height: 200px; overflow: auto">
	        <table border="1" style=" width: 780px; border-collapse: collapse; background-color: #FFFFFF; font-family: Arial; font-size: 14px">
		    <tr style="background-color: #636363; color: #FFFFFF;">
			    <th></th>
			    <th>STAFF</th>
			    <th>IN</th>
			    <th>OUT</th>
		    </tr>
		<?php
		if($num>0){
			$i=1;
			while($myrow = mysqli_fetch_array($result)){
			?>
		    <tr>
			    <td align="center" width="50px"><?= $i ?></td>
			    <td style="padding-left: 10px">
				<?php
				if( isset($arrStaff[$myrow["staffId"]])){
					echo $arrStaff[$myrow["staffId"]];
				}else{
					echo "UNKNOW [".$myrow["staffId"]."]";
				}
				?>
			    </td>
			    <td align="center" width="150px"><?= $myrow["punchIn"] ?></td>
			    <td align="center" width="150px"><?= $myrow["punchOut"] ?></td>
		    </tr>
			<?php
			$i++;
			}
		}
		?>
		
            </table>
            </div>      
                    
          </th>
		</tr>
        </table>
          
	  </th>
	</tr>
	</table>

<script>
    document.getElementById("txtId").focus();
</script>
        
	</center>
	
	</body>
	
</html>