<?php
require_once("../config/config.php");

$login_flag = mysqli_fetch_array(mysqli_query($link1, " SELECT login_time FROM hrms_emp_login_detail  WHERE in_out_date = '".$today."' and login_time != '00:00:00' "));
$logout_flag = mysqli_fetch_array(mysqli_query($link1, " SELECT logout_time FROM hrms_emp_login_detail  WHERE in_out_date = '".$today."' and logout_time != '00:00:00' "));

if($_POST['login']=="Login"){
	$in = mysqli_fetch_array(mysqli_query($link1, " SELECT login_time FROM hrms_emp_login_detail  WHERE in_out_date = '".$today."' and login_time != '00:00:00' "));
	if($in[0] == ""){
		$res1 = mysqli_query($link1, " INSERT INTO hrms_emp_login_detail SET emp_code = '".$_SESSION['userid']."', emp_name = '".$_SESSION['uname']."', login_time = '".$currtime."', in_out_date = '".$today."' ");
	}
	///// move to parent page
	header("location:attendance_emp_list.php?msg=".$msg."&sts=fail".$pagenav);
	exit;
}

if($_POST['logout']=="Logout"){
	$out = mysqli_fetch_array(mysqli_query($link1, " SELECT logout_time FROM hrms_emp_login_detail  WHERE in_out_date = '".$today."' and logout_time != '00:00:00' "));
	if($out[0] == ""){
		$res2 = mysqli_query($link1, " INSERT INTO hrms_emp_login_detail SET emp_code = '".$_SESSION['userid']."', emp_name = '".$_SESSION['uname']."', logout_time = '".$currtime."', in_out_date = '".$today."' ");
	}
	///// move to parent page
	header("location:attendance_emp_list.php?msg=".$msg."&sts=fail".$pagenav);
	exit;
}

?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title><?=siteTitle?></title>
 <script src="../js/jquery.min.js"></script>
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 
</head>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
      <div class="col-sm-9 tab-pane fade in active table-responsive" id="home">
      <h2 align="center"><i class="fa fa-book"></i> Attendance </h2>
      <?php /*?><h5 align="center"> ( Activity No. -  <?=$info['activity_no'];?> ) </h5><?php */?>
      <?php if($_REQUEST['msg']!=''){?>
      	<h4 align="center">
        	<span 
			<?php if($_REQUEST['sts']=="success"){ echo "class='info-success' style='color: #090;'"; } if($_REQUEST['sts']=="fail"){ echo "class='info-fail' style='color:#FF0033'";} else echo "class='info-fail' style='color:#FF0033'";?>>
			<?php echo $_REQUEST['msg'];?>
			</span>
        </h4>
	  <?php }?>
      <br>     
      <form name="frm1" id="frm1" class="form-horizontal" action="" method="post" >
                               
          <div class="panel-group">
            <div class="panel panel-info table-responsive">
                <div class="panel-heading heading1"><i class="fa fa-id-card fa-lg"></i>&nbsp;&nbsp;Attendance Details</div>
                 <div class="panel-body">
                 	  <div style="text-align:center; padding:10px; margin-bottom:30px;">
                          <div style="color: red;"> Date -  <?=$today;?></div>
                      </div>
					  <div class="row">
                      	<div class="col-sm-6">
                        	<div style="text-align:center;margin: 20px;" > 
                             <?php if($login_flag[0] == ""){ ?>
                             <input type="submit" class="btn <?=$btncolor?>" name="login" id="login" value="Login" />  
                             <?php }else{ ?>
                             <div style="background-color: green;padding: 5px;border-radius: 5px;color: white;font-weight: 600;" > Your log in time is: <?=$login_flag[0];?></div>
                             <?php } ?>
                            </div>
                        </div>
                        <div class="col-sm-6">
                        	<div style="text-align:center;margin: 20px;" > 
                            <?php if($logout_flag[0] == ""){ ?>
                            <input type="submit" class="btn <?=$btncolor?>" name="logout" id="logout" value="Logout" /> 
                            <?php }else{ ?>
                            <div style="background-color: green;padding: 5px;border-radius: 5px;color: white;font-weight: 600;" > Your log out time is: <?=$logout_flag[0];?></div>
                            <?php } ?>
                            </div>
                        </div>
                      </div>                                                     
                </div><!--close panel body-->
            </div><!--close panel-->
          </div>
         
      </form>    
    </div>
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>