<head>

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

require_once('../include/tc_calendar.php');
//$cal_today = date('Y-m-d');
$cal_today = '2015-06-01';
$_SESSION['record_date'] = $cal_today;

if ($permission_num==1) {
$_SESSION['new'] = 0;	
$check_num = 0;

$week_day=1;
if ((date('l', strtotime($cal_today))=="Saturday") OR (date('l', strtotime($cal_today))=="Sunday")) {
	$week_day=0;
	$check_num='';
	$check2_num='';
	$check3_num='';
	$check4_num='';
	$check6_num='';
	
}
else {
	
$table_name = $_SESSION['db_prefix']."_time_record";
$not_query = "SELECT DISTINCT date  FROM $table_name WHERE type='N' AND status_2='' AND date < '".$_SESSION['record_date']."' ";
$not_result = mySQL_query($not_query);
$not_num = mysql_num_rows($not_result);
$check5_num = $not_num;
$i=0;
$not_date_line = '';
while ($i<$not_num) {
	$not_date = mysql_result($not_result, $i, "date");
	$not_date_line = $not_date_line.'<br>'.'<a href=add_timeOutWiz0.php?record_date='.$not_date.'>'.$not_date.'</a>';
	$i++;
}
if ($not_num!=0) {
	$attMessage = $not_date_line;
}
else {
	$attMessage='';
}

$table_name = $_SESSION['db_prefix']."_time_record";
$checking_query = "UPDATE $table_name SET checked = '0' WHERE date = '".$_SESSION['record_date']."' AND checked='2' AND type='N' ";
$checking_result = mySQL_query($checking_query);


$table_name = $_SESSION['db_prefix']."_time_record";
$check_query = "SELECT emp_id, date FROM $table_name WHERE status='N' AND date = '".$_SESSION['record_date']."' AND type='N' ";
$check_result = mySQL_query($check_query);
$checkb_num = mysql_num_rows($check_result);

$checka_query = "SELECT emp_id, date FROM $table_name WHERE status='U' AND status_2='' AND date = '".$_SESSION['record_date']."' AND type='N' ";

$checka_result = mySQL_query($checka_query);
$checka_num = mysql_num_rows($checka_result);
$check_num = $checkb_num + $checka_num;


if ($check_num!=0) {
	   	$check_date = mysql_result($check_result, 0, "date");
	  	$_SESSION['new']=1;
	  	$check3_num = 0; 
		$check6_num = 0; 
}
else {
	
$table_name = $_SESSION['db_prefix']."_time_record";
$check6_query = "SELECT emp_id, date FROM $table_name WHERE checked = 0  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) {
      $check6_date = mysql_result($check6_result, 0, "date");
	  $_SESSION['new']=2;
	  $_SESSION['record_date'] = $check6_date;
	  
}
	
$table_name = $_SESSION['db_prefix']."_time_record";
$check3_query = "SELECT emp_id, date FROM $table_name WHERE checked = 1  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) {
      $check3_date = mysql_result($check3_result, 0, "date");
}
}


$table_name = $_SESSION['db_prefix']."_time_record";
$check2_query = "SELECT emp_id FROM $table_name WHERE date = '". $cal_today." '  AND type='N' AND date = '".$_SESSION['record_date']."'  ";
$check2_result = mySQL_query($check2_query);
$check2_num = mysql_num_rows($check2_result);


$table_name = $_SESSION['db_prefix']."_time_record";
$check4_query = "SELECT emp_id, date FROM $table_name WHERE status_2='' AND date <> '". $cal_today." ' AND type='N'  AND date = '".$_SESSION['record_date']."' ";
$check4_result = mySQL_query($check4_query);
$check4_num = mysql_num_rows($check4_result);

}

?>
<head>

<body>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<div class="wizard_page_middle_frame">
<form id="form1" name="form1" method="get" action="timeWizbase.php">
<div class="wizard_frame">
         <label class="std"><font size="3"><b>Today is&nbsp;&nbsp; <?php echo date('l', strtotime($cal_today));?>,&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($cal_today )) ?></b></font></label><br />
          </div>
     <?php if ($week_day==0){
		$next='false'; ?>     
      <div class="wizard_frame">
        <table width="599" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="48"><img src="../images/error.png" width="30" height="30"></td>
            <td width="551"><label class="label_std">
              This is not a working day. You can only enter over time hours for today.</label><br>
              <br>
              <label class="label_std">Click&nbsp;&nbsp; 
              <input name="button2" type="submit" class="imagebutton" id="button2" onClick="MM_goToURL('parent','overtimeWiz0.php');return document.MM_returnValue" value="Overtime">
              &nbsp;&nbsp;</b>to start the overtime wizard.</label></td>
            </tr>
        </table>
      <br><br>
      </div>
	  <?php } ?>
	  
      <?php if ($check_num!=0) { 
	   $next='true';?>
		<div class="wizard_frame"><br>
		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="57"><img src="../images/Info.png" width="32" height="32"></td>
		      <td width="543"><label class="label_std"><?php echo $checkb_num ?>  employees are not recorded yet and <?php echo $checka_num ?> employees have the &quot;unknown&quot; status on&nbsp;<?php echo date("l, d-m-Y", strtotime($check_date)) ?>. <br>
                <br>
                Click next to make clock-in recordings of these employees.</label> </td>
	        </tr>
	      </table>
		  <br>
		  <input type="hidden" name="confirm_select" id="confirm_select" value="later">
		
		</div> 
		<?php } ?>
		<?php  
       if ( ($check_num==0) && ($check2_num!=0) ) {
	   $next='false';?>
		<div class="wizard_frame"><br>
<br>

		  <table width="600" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="56"><img src="../images/warning.png" width="32" height="32"></td>
		      <td width="544"><label class="label_std">The clock-in time entries for today are done.      Click cancel to leave this wizard.</label></td>
	        </tr>
	      </table>
		  <br>
		  <input type="hidden" name="confirm_select" id="confirm_select" value="later">
		</div>
		<?php } else { ?>
        <?php  
       if  ($check3_num!=0) {
	   $next='false';?>
		<div class="wizard_frame">
		  <table width="585" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="48"><img src="../images/error.png" width="32" height="32"></td>
		      <td width="446">
		        <label class="label_std"><br>
		          Not all employees were clocked-out on <?php echo date("l, d-m-Y", strtotime($check3_date )) ?>. These need to be clocked-out first.<br>
		          <br>
  Click </label>
		         &nbsp;
                <input name="button" type="submit" class="imagebutton" id="button" onClick="MM_goToURL('parent','timeOutWiz0.php');return document.MM_returnValue" value="Clock-out">
                <label class="label_std"> to leave this wizard and start the clock-out wizard. </label>
                <input type="hidden" name="confirm_select2" id="confirm_select2" value="later">
              </td>
	        </tr>
	      </table>
		  <br><br>
		</div>
        <?php } 
        
        if  ($check6_num!=0) {
	   $next='true';?>
		<div class="wizard_frame">
		  <table width="585" border="0" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="48"><img src="../images/error.png" width="32" height="32"></td>
		      <td width="446">
		        <label class="label_std"><br>
		          Not all employees were clocked-in on <?php echo date("l, d-m-Y", strtotime($check6_date )) ?>. These need to be clocked-in first.<br>
		          <br>
  Click </label>
		         &nbsp;
                <input name="button" type="submit" class="imagebutton" id="button" onClick="MM_goToURL('parent','timeOutWiz0.php');return document.MM_returnValue" value="Clock-out">
                <label class="label_std"> to leave this wizard and start the clock-out wizard. </label>
                <input type="hidden" name="confirm_select2" id="confirm_select2" value="later">
              </td>
	        </tr>
	      </table>
		  <br><br>
		</div>
        
		<?php } 
		}?>
        
        
        
	<?php 
	  if ( ($check_num==0) && ($check2_num==0) && ($check3_num==0) && ($check4_num==0) && ($check5_num==0) && ($week_day==1) ){
	  $next='true';?>
        <div class="wizard_frame">
          <table width="600" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="68" valign="top"><img src="../images/Info.png" width="32" height="32"></td>
              <td width="532" valign="top"><label class="label_std"><br>
                To enter the clock-in entries for today, the time list for today has to be made.<br>
                <br>
&nbsp;&nbsp;By clicking &quot;Next&quot;, the list will be prepared.<br>

              </label></td>
            </tr>
          </table>
 
        </div>
        <?php } ?>
        
    <?php 
	  if ($check5_num!=0){
	  $next='false';?>
        <div class="wizard_frame">
          <table width="600" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="68" height="32" valign="top"><br>                <img src=../images/exclamation-mark_small.png width=24 height=24 /></td>
              <td width="532"><label class="label_red_bold" style="color:#FF0000">&nbsp;<br>
              There are days not all employees were clocked out. You cannot clock-in before all employees are clocked out. Click on the date below to clock out the employees on that day.<br>
              <br>
              <?php echo $attMessage ?><br>
              <br>
Click cancel to leave this wizard. 
             </label></td>
            </tr>
          </table>
          <br>
          
<br>
          <br />
        </div>
        <?php } ?>    
        
 <div class="wizard_spacer_frame" style="height:120px;"></div>
      <div class="wizard_frame">
      <table width="645" 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" id="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " <?php if ($next=="false") { ?> disabled="disabled" <?php } ?> /></td>
          </tr>
        </table>
        </div>
 </form>
 </div>
<!--form validation-->

</body>
<?php } else { 
    $_SESSION['denied_return'] = "hr_module/hr_main.php";	?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>