<!--Notice: (c)2013 This page is part of the management program for Tlhomeso Timbers, Gaborone, 
and developed by Customized Software (Pty) Ltd, Gaborone, Botswana. 
Customized Software holds the copyright on the source code on this and all other pages in the 
management program. For more info contact Customized Software on email: info@bwcustomized.com-->

<?php 
$page_name = "HR-timekeeping";
include ("../navigation/access.php");

require_once('../include/tc_calendar.php');
$cal_today = date('Y-m-d');
//$cal_today = '2013-02-19';
$_SESSION['out_date'] = $cal_today;
if ($permission_num==1) {
	 
//$table_name = $_SESSION['db_prefix']."_time_record";
//$check_query = "SELECT emp_id, date FROM $table_name WHERE (checked = 1 OR checked = 4) ";
//$check_result = mySQL_query($check_query);
//$check_num = mysql_num_rows($check_result);
//if ($check_num!=0) {
//      $_SESSION['record_date'] = mysql_result($check_result, 0, "date");
//	  
//}
//
//$table_name = $_SESSION['db_prefix']."_time_record";
//$uncheck_query = "SELECT emp_id, date FROM $table_name WHERE (checked = 0 OR checked = 3)  AND date = '".$_SESSION['out_date']."' ";
//$uncheck_result = mySQL_query($uncheck_query);
//$uncheck_num = mysql_num_rows($uncheck_result);
//if ($uncheck_num!=0) {
//      $_SESSION['out_date'] = mysql_result($uncheck_result, 0, "date");
//}


//$table_name = $_SESSION['db_prefix']."_time_record";
//$check2_query = "SELECT emp_id FROM $table_name WHERE date = '". $cal_today." ' ";
//$check2_result = mySQL_query($check2_query);
//$check2_num = mysql_num_rows($check2_result);
//
//$week_day=1;
//
//if ((date('l', strtotime($cal_today))=="Saturday") OR (date('l', strtotime($cal_today))=="Sunday")) {
//	$week_day=0;
//}

$checked='0';

//$table_name = $_SESSION['db_prefix']."_time_record";
//$check4_query = "SELECT emp_id, date  FROM $table_name WHERE (status_2='') ";
//$check4_result = mySQL_query($check4_query);
//$check4_num = mysql_num_rows($check4_result);
//$_SESSION['out_date']=mysql_result($check4_result, 0, "date");


$table_name = $_SESSION['db_prefix']."_time_record";
$check3_query = "SELECT emp_id, date FROM $table_name WHERE (status='P' OR status='L') AND status_2='' AND type='N' AND date = '".$_SESSION['record_date']."' ";
$check3_result = mySQL_query($check3_query);
$check3_num = mysql_num_rows($check3_result);
if ($check3_num!=0) {
      $checked = 3;
	  $_SESSION['out_date']=mysql_result($check3_result, 0, "date");
}

$table_name = $_SESSION['db_prefix']."_time_record";
$check6_query = "SELECT emp_id, date FROM $table_name WHERE status_2<>'' AND type='N' AND date = '".$_SESSION['record_date']."' ";
$check6_result = mySQL_query($check6_query);
$check6_num = mysql_num_rows($check6_result);
if ($check6_num!=0) {
      $checked = 6;
	  
}

$table_name = $_SESSION['db_prefix']."_time_record";
$check0_query = "SELECT emp_id, date  FROM $table_name WHERE (status='N') AND status_2='' AND type='N' AND date = '".$_SESSION['record_date']."' ";
$check0_result = mySQL_query($check0_query);
$check0_num = mysql_num_rows($check0_result);
if ($check0_num!=0) {
      $checked = 0;
	  $_SESSION['out_date']=mysql_result($check0_result, 0, "date");
}


$table_name = $_SESSION['db_prefix']."_time_record";
$check2_query = "SELECT emp_id, date  FROM $table_name WHERE status='U' AND status_2='' AND type='N'  AND date = '".$_SESSION['record_date']."' ";
$check2_result = mySQL_query($check2_query);
$check2_num = mysql_num_rows($check2_result);
if ($check2_num!=0) {
      $checked = 2;
	  $_SESSION['out_date']=mysql_result($check2_result, 0, "date");
}

$table_name = $_SESSION['db_prefix']."_time_record";
$check_query = "SELECT emp_id, date FROM $table_name WHERE status='N' AND status_2='' AND type='N' AND date = '".$_SESSION['record_date']."' ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);
if ($check_num!=0) {
      $checked = 1;
	  $_SESSION['out_date']=mysql_result($check_result, 0, "date");
}




?>


<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<body>

<div class="page_middle_frame">
<form id="form1" name="form1" method="get" action="timeOutWizbase.php">
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" ><div class="wizard_frame">
         <label class="std"><font size="3"><b>Clock-out recording for &nbsp;&nbsp; <?php echo date("l, d-m-Y", strtotime($_SESSION['out_date'] )) ?></b></font></label><br />
          </div>
          
          
                   
          
          
      <?php if ($checked == 0 ) {
			 $next='false';?>
		<div class="wizard_frame">
		  <br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="73"><img src="../images/error.png" width="32" height="32"></td>
		      <td width="527"><label class="label_std">There are no employees clocked in on &nbsp;<?php echo date("l, d-m-Y", strtotime($_SESSION['record_date'])) ?>.</label> <br>
                  <br>
<label class="label_std">Click&nbsp;
<input name="button" type="submit" class="imagebutton" id="button" onClick="MM_goToURL('parent','timeWiz0.php');return document.MM_returnValue" value="Clock-in">
&nbsp;
to start the 'Clock-in' wizard </label></td>
	        </tr>
	      </table>
      <b><br>
      <br>
      </b>
		
		</div>
		
		<?php } ?>
           
      <?php if ($checked == 1 ) {
			 $next='false';?>
		<div class="wizard_frame">
		  <br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="73"><img src="../images/error.png" width="32" height="32"></td>
		      <td width="527"><label class="label_std">There are <?php echo $check_num ?> employees  not clocked in <?php echo date("l, d-m-Y", strtotime($_SESSION['record_date'])) ?>. These employees need to be clocked in first.</label><br>
                  <br>
<label class="label_std">Click&nbsp;
  <input name="button2" type="submit" class="imagebutton" id="button2" onClick="MM_goToURL('parent','timeWiz0.php');return document.MM_returnValue" value="Clock-in">
  &nbsp;
to start the 'Clock-in' wizard</label></td>
	        </tr>
	      </table>
      <b><br>
      <br>
      </b>
		
		</div>
		
		<?php } ?>
        
     <?php if ($checked == 2 ) {
			 $next='true';?>
		<div class="wizard_frame">
		  <br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="73"><img src="../images/warning.png" width="32" height="32">></td>
		      <td width="527"><label class="label_std">There are <?php echo $check2_num ?> employees  having the absent-unknown status on&nbsp;<?php echo date("l, d-m-Y", strtotime($_SESSION['out_date'])) ?>. You can still change this or leave them on absent status before you start this wizard.</label>
		        <br>
                  <br>
<label class="label_std">Click&nbsp;
<input name="button" type="submit" class="imagebutton" id="button" onClick="MM_goToURL('parent','timeWiz0.php');return document.MM_returnValue" value="Clock-in">
&nbsp;
to start the 'Clock-in' wizard  or &quot;Next&quot; to continue.</label></td>
	        </tr>
	      </table>
      <b><br>
      <br>
      </b>
		
		</div>
		
		<?php } ?>   
        
        <?php if ($checked == 3 ) {
			 $next='true';?>
		<div class="wizard_frame">
		  <br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="73"><b><img src="../images/info.png" width="32" height="32"></b></td>
		      <td width="527"><label class="label_std">There are <?php echo $check3_num ?> employees  to be clocked out on&nbsp;<?php echo date("l, d-m-Y", strtotime($_SESSION['out_date'])) ?></label>. <br>
                  <br>
<label class="label_std">Click&nbsp;&quot;Next&quot; to continue.. </label></td>
	        </tr>
	      </table>
      <b><br>
      <br>
      </b>
		
		</div>
		
		<?php } ?>  
        
        <?php if ($checked == 6 ) {
			 $next='false';?>
		<div class="wizard_frame">
		  <br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="73"><b><img src="../images/info.png" width="32" height="32"></b></td>
		      <td width="527"><label class="label_std">All employees were clocked out on&nbsp;<?php echo date("l, d-m-Y", strtotime($_SESSION['record_date'])) ?></label>. <br>
                  <br>
<label class="label_std">Click&nbsp;&quot;Cancel&quot; to leave this wizard. </label></td>
	        </tr>
	      </table>
      <b><br>
      <br>
      </b>
		
		</div>
		
		<?php } ?>   
        
	  </td>
    </tr>
    <tr>
      <td>
      <div class="wizard_frame">
      <table width="675" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117">&nbsp;</td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="p" type="hidden" id="p" value="1" />
              <input name="error" type="hidden" id="error" value="0" />
              <input name="s" type="hidden" id="s" value="1" />
            </span></td>
            <td width="125"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../hr_module/hr_main.php?date=0');" value="Cancel" /></td>
            <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" <?php if ($next=='false') { ?> disabled="disabled"  <?php } ?>  value="Next" onClick="needToConfirm = false; "  /></td>
          </tr>
        </table>
        </div></td>
    </tr>
  </table>
 </form>
 </div>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("first_name_text","req","Please enter the first name of the employee.");
  frmvalidator.addValidation("last_name_text","req","Please enter the last name of the employee.");
  </script>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "hr_module/hr_main.php?date=";	?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>