<?php
session_start();
ob_start();
include("../../pidbco/pidbjoin.php");

$tfrom   = strip_tags($_GET['tfrom']);
$tto     = strip_tags($_GET['tto']);
$tstatus = strip_tags($_GET['tstatus']);

$tod_dat = date('d-m-Y h:i a');
$ipp = $_SERVER['REMOTE_ADDR'];

$sqemp2 = mysqli_query($con, "SELECT emp_name FROM `employee_registration` WHERE `id`='$tto' ");
$resemp2 = mysqli_fetch_array($sqemp2);
$emp_nam = $resemp2['emp_name'];
 ?>
  
   <style>
   	@media print {
   thead {display: table-header-group;}
    }
   </style>	
   <body style="margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:12px;">
     <div id="invoice" style="height:1010px; margin:0px auto; background-color:#FFFFFF; padding:25px 0px;">
            <div style="  height:1100px; margin:0px auto;">
              
            <div style="text-align:left; margin-top:5px;font-weight:bold; font-size:20px;">
              <!--   <?php echo 'Task Register'; ?> -->
              <strong style="float: left; color:red;"><u><?php echo $emp_nam.'&nbsp;'.':- Daily Tasks'; ?> <?php echo 'Generated from'.'&nbsp;'.$ipp.'&nbsp;'.'on'.'&nbsp;'.$tod_dat; ?></u></strong>
            </div>
            <br />
         <div style="width:100%; ">

            <table style="width:100%; font-size:11px; border:none; ">
            <thead>
                <tr style="text-align:center; background-color:#CCCCCC;">
                    <th style="width:5%; border:solid 1px #999999;">
                        No. 
                    </th>
                    <th style="width:9%; border:solid 1px #999999;">
                        Date/Time
                    </th>
                     <th style="width:4%; border:solid 1px #999999;">
                        Age 
                    </th>
                    <th style="border:solid 1px #999999;">
                        From    
                    </th>
                    <th style=" border:solid 1px #999999;">
                        To
                    </th>
                    <th style=" border:solid 1px #999999;">
                        Task Details
                    </th>     
                    <th style=" border:solid 1px #999999;">
                        Status
                    </th>         
                </tr>
     </thead>  
      <?php

      if($tstatus != ''){
   	      if($tstatus == 'All'){
   	          $s1 = " 1=1";
		  } else if($tstatus == 'Open'){
		  	  $s1 = "`t_status`='0'";
		  } else if($tstatus == 'Closed'){
		  	  $s1 = "`t_status`='1'";
		  } else if($tstatus == 'Transfer'){
		  	  $s1 = "`t_trans_to`!=''";
		  }
		  		  
			  
   } else {
   	  $s1 = "`t_status`='0'";
   }
   if($tfrom != ''){
   	  $s2 = " AND `t_from`='$tfrom' AND `t_status`='0'";
   }
   if($tto != ''){
   	  $s3 = " AND `t_to`='$tto' AND `t_status`='0'";
   }
   
   $s2 = isset($s2) ? $s2: '';
    $s3 = isset($s3) ? $s3: '';
 
    $sq = mysqli_query($con,"SELECT * FROM `p_task` WHERE ".$s1.$s2.$s3."   ORDER BY `tid` DESC");
	while($rstask = mysqli_fetch_array($sq)){
	  	  $empfrom = $rstask['t_from'];
	      $empto = $rstask['t_to'];
   	
   	$sqemp = mysqli_query($con, "SELECT emp_name FROM `employee_registration` WHERE `id`='$empfrom' ");
	$resemp = mysqli_fetch_array($sqemp);
   	$fromemp = $resemp['emp_name'];
	
	$sqemp2 = mysqli_query($con, "SELECT emp_name FROM `employee_registration` WHERE `id`='$empto' ");
	$resemp2 = mysqli_fetch_array($sqemp2);
   	$toemp = $resemp2['emp_name'];
	
	
	
	$datetime1 = new DateTime($rstask['t_dat']);
    $datetime2 = new DateTime($rstask['t_closedat']);
    $interval = $datetime1->diff($datetime2);
    $days_between = $interval->format('%a');
    if($days_between == 0){
        $days_between = 1;
    }
	
	$taskdat = $rstask['t_dat'];
	$exp = explode("-",$taskdat);
	$yearr =  substr($exp[0], 2, 4);
	
	$taskdate = $exp[2].'/'.$exp[1].'/'.$yearr; 
		
    ?>
       <tr style="font-weight:bold; height:30px; width:100%; border:none; font-size:12px;margin-bottom:0px;">
         <td style="text-align:center; border:solid 1px #999999;border-top:none;">
         	 <?php echo $rstask['tid']; ?>
         </td>
         <td style="text-align:center;border:solid 1px #999999;border-top:none;">
         	<?php echo $taskdate; ?>&nbsp;<br><?php $th=$rstask['t_time'];
                    	 $expd4 = explode(" ",$th);
                    	 echo $expd4['0'];   ?>
         </td>
         <td style="text-align:center; border:solid 1px #999999;border-top:none;">
         	 <?php echo $days_between; ?>
         </td>
         <td style="text-align:center;border:solid 1px #999999;border-top:none; font-weight: bold;">
         	<?php echo$results = substr($fromemp, 0, 5);  ?>
         </td>
         <td style="text-align:center; border:solid 1px #999999;border-top:none;">
         	<?php       
         	// singlebyte strings
     
echo$result = substr($toemp, 0, 5);  ?>
         </td>
         <td style="text-align:left; border:solid 1px #999999;border-top:none;font-size: 12px;font-weight: 200;">
         	<?php echo $rstask['t_action']; ?>
        </td>
        <td style="text-align:center; border:solid 1px #999999;border-top:none;">
        	<?php if($rstask['t_status'] == 1){ echo "Closed"; } else { echo "Open"; } ?>
        </td> 
       </tr>
       <?php } ?> 
</table>


</div>

<br />
<br />


</div>

</div>

</body>
