<?php
session_start();

error_reporting(0);
include("../../pidbco/pidbjoin.php");
$sujpath="./";
if((!isset($_SESSION['user_name'])) && ($_SESSION['user_name'] == '')){
    header("Location: ../index.php");
} 


?>
<input type="text" id="tfrom" value="<?php echo $_GET["tfrom"];?>">
<input type="text" id="tto" value="<?php echo $_GET["tto"];?>">
<input type="text" id="tstatus" value="<?php echo $_GET["tstatus"];?>">
<div class="box" >
   <div class="box-body" style=" overflow: auto;">
        <div class="box-body table-responsive no-padding" >
            

 <div class="row">  
  <div class="col-md-12" >

  <div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">          
  <div class="form-group">
  </div></div>

 <div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">           
 <div class="form-group">
   <select name="searchfrom" id="searchfrom" class="form-control" style=" height: 30px;">
    <option value="">From</option>
    <?php
    $sq1 = mysqli_query($con, "SELECT * FROM `employee_registration` WHERE `status`='1' ORDER BY `emp_name` ASC ");
    while($res1 = mysqli_fetch_array($sq1)){
        if($_GET['tfrom'] == $res1['id']){
    ?>
    <option value="<?php echo $res1['id']; ?>" selected><?php echo $res1['emp_name']; ?></option>
    <?php } else { ?>
    <option value="<?php echo $res1['id']; ?>"><?php echo $res1['emp_name']; ?></option>
    <?php } } ?>
   </select>        
 </div></div>
 <div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">           
 <div class="form-group">
  <select class="form-control" id="searchto" name="searchto" onchange="state_change(this.value);" style=" height: 30px;">
    <option value="">To</option>
    <?php
    $sq1 = mysqli_query($con, "SELECT * FROM `employee_registration` WHERE `status`='1' ORDER BY `emp_name` ASC ");
    while($res1 = mysqli_fetch_array($sq1)){
        if($_GET['tto'] == $res1['id']){
    ?>
    <option value="<?php echo $res1['id']; ?>" selected><?php echo $res1['emp_name']; ?></option>
    <?php } else { ?>
    <option value="<?php echo $res1['id']; ?>"><?php echo $res1['emp_name']; ?></option>
    <?php } } ?>  
  </select> 
 </div></div>  


<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">            
 <div class="form-group">
  <select class="form-control" id="srchstatus" name="srchstatus" style=" height: 30px;">
  
    <option value="All" <?php if($_GET['tstatus'] == 'All'){ ?> selected <?php } ?>>All</option>
    <option value="Open" <?php if($_GET['tstatus'] == 'Open'){ ?> selected <?php } ?>>Open</option>
    <option value="Closed" <?php if($_GET['tstatus'] == 'Closed'){ ?> selected <?php } ?>>Closed</option>
    <option value="Transfer" <?php if($_GET['tstatus'] == 'Transfer'){ ?> selected <?php } ?>>Transfer</option>
    <option value="Hold" <?php if($_GET['tstatus'] == 'Hold'){ ?> selected <?php } ?>>Hold</option>
    <option value="Reminder" <?php if($_GET['tstatus'] == 'Reminder'){ ?> selected <?php } ?>>Reminder</option>  
  </select> 
 </div></div>
 <div class="col-md-1"  style=" padding-left: 2px; padding-right: 0px; ">           
 <div class="form-group">
 <input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Search" onclick="search_task();" style=" float: left;margin-right: 5px; height: 30px;" />
 </div></div>
 
 <div class="col-md-2"  >           
 <div class="form-group">
 <span style=" font-size: 16px; " >
    <i class="fa fa-book" aria-hidden="true"></i>
    <a href="" data-toggle="modal" data-target="#myModal9data" style=" cursor: pointer;">Create Report</a>
    </span> 
 </div></div>
 
 <div class="col-md-1"  >           
 <div class="form-group">
 <span style=" font-size: 16px; " >
    <i class="fa fa-print" aria-hidden="true"></i>
    <a style=" cursor: pointer;" onclick="todo_print();" >Print</a>
    </span> 
 </div></div>
    
    
 </div></div></div>
 
 
  <div class="modal fade" id="myModal9data" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
  <div class="modal-dialog" role="document" style=" width: 800px; ">
    <div class="modal-content" style="overflow: hidden;">
      <div class="modal-header" style=" background-color: #E8E8E8;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Search / Create Report</h4>
        </div>
        <div class="modal-body" id="myModal2" >
        <div class="row">   
            
            <div class="col-md-12" >
                
    <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">                    
    <div class="form-group">
    <select name="searchemp" id="searchemp" class="form-control" style=" height: 32px;">
    <option value="">Employee</option>
    <?php
    $sq1 = mysqli_query($con, "SELECT * FROM `employee_registration` WHERE `status`='1' ORDER BY `emp_name` ASC ");
    while($res1 = mysqli_fetch_array($sq1)){
        if($rs['t_from'] == $res1['id']){
    ?>
    <option value="<?php echo $res1['id']; ?>" selected><?php echo $res1['emp_name']; ?></option>
    <?php } else { ?>
    <option value="<?php echo $res1['id']; ?>"><?php echo $res1['emp_name']; ?></option>
    <?php } } ?>
   </select>    
            </div></div>
             <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">                   
            <div class="form-group">
                <input type="text" name="searchdate" id="searchdat" class="form-control tcal" placeholder="YYYY/MM/DD"/> 
                    
            </div></div>    
            <div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">                    
            <div class="form-group">
            <input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Search" onclick="create_report();"  />      
            </div></div>    
            </div>
            
            
       </div>
       
            
       <div id="report_res"></div>
       
       
          
       
       
       </div></div></div></div>
       
       
       
       
       
       
       
       

                        
     <table id="example1" class="table table-bordered table-striped" >
                    <thead >
                    <tr >
                    <th style=" display: none;"></th>
                    <th>#</th>   
                    <th>Date/Time</th>                  
                    <th>From</th>
                    <th>To</th>
                    <th>Task Details</th>
                    <th>Status</th>
                    <th></th>
                    </tr>
                    </thead>
                    <tbody>
   <?php
   $tfrom = $_GET['tfrom'];
   $tto = $_GET['tto'];
  $tstatus = $_GET['tstatus'];
   
   if($tstatus == ''){
      if($tfrom == ''){
         $tfrom2 = $_SESSION['us_staff'];
      }
      if($tto == ''){
         $tto2 =  $_SESSION['us_staff'];
      }
   }
  
  if(($tfrom2 != '') && ($tto2 != '') && ($_SESSION['us_staff'] != 1)){
    $s4 = " ( `t_from`='$tfrom2' OR `t_to`='$tto2' ) AND ";
  } 
  
   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 if($tstatus == 'Hold'){
              $s1 = "`t_status`='3'";
          } else if($tstatus == 'Reminder'){
              $s1 = "`remind_set`!=''";
          }
                  
              
   } else {
      $s1 = "`t_status`!='1'";
   }
   if($tfrom != ''){
      $s2 = " AND `t_from`='$tfrom'";
   }
   if($tto != ''){
      $s3 = " AND `t_to`='$tto'";
   }
  $m=1;
   $sqtask = mysqli_query($con, "SELECT * FROM `p_task` WHERE ".$s4.$s1.$s2.$s3." ORDER BY `tid` DESC");
   while($rstask = mysqli_fetch_array($sqtask)){
    $empfrom = $rstask['t_from'];
    $empto = $rstask['t_to'];
    
    $task_id = $rstask['tid'];
    $sqw = mysqli_query($con, "SELECT * FROM `p_taswise_rep` WHERE `task_id`='$task_id'");
    $sqw_rwcount= mysqli_num_rows($sqw);
    if($sqw_rwcount != ''){
        $rep_count = "(".$sqw_rwcount.")";
    } else {
        $rep_count = "";
    }
    
    $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'];
    
    $taskdat = $rstask['t_dat'];
    $exp = explode("-",$taskdat);
    $yearr =  substr($exp[0], 2, 4);
    $taskdate = $exp[2].'/'.$exp[1].'/'.$yearr; 
   ?>
                   <tr >    
                    <td  style=" display: none; "><?php echo $m; ?></td>
                    <td>
<?php if($rstask['t_status'] == 1){
 $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;
}   
     ?>
 <small class="label label-danger" ><?php echo $days_between; ?></small>  
 <?php   } else {
 $datetime11 = new DateTime($rstask['t_dat']);
 $datetime22 = new DateTime(date('Y-m-d'));
 $interval = $datetime11->diff($datetime22);
 $days_between2 = $interval->format('%a');
if($days_between2 != 0){
 ?> 
 <small class="label label-info" title="Days"> <?php echo $days_between2; ?></small>
 <?php } } ?>
                     <?php echo $rstask['tid']; ?> 
                    </td>
                    <td <?php if($rstask['t_status'] == '1'){ ?> style="background:red;" <?php } else if($rstask['task_report'] != ''){ ?> style="background:#0000FF;" <?php }
                    else if($rstask['t_trans_to'] != ''){ ?> style="background:#DAA520;" <?php } else if($rstask['t_status'] == '3'){ ?> style="background:#2E8B57;" <?php } else if($rstask['t_sign'] == '1'){ ?> style="background:#00FFFF;" <?php } ?>>
                    <a href="" data-toggle="modal" data-to="<?php echo $toemp;?>" data-from="<?php echo $fromemp;?>" data-id="<?php echo $rstask['tid']; ?>" data-target="#myModal" <?php if(($rstask['t_status'] == '1') || ($rstask['task_report'] != '') || ($rstask['t_trans_to'] != '') || ($rstask['t_status'] == '3')){ ?> style=" cursor: pointer;color: #FFF;" <?php } else {?> style=" cursor: pointer;color: #000; " <?php } ?>>
                    <?php echo $taskdate; ?>&nbsp; <?php echo $rstask['t_time']; ?></a></td>
                    
                    <td <?php if($rstask['t_status'] == '1'){ ?> style="background:red;" <?php } else if($rstask['task_report'] != ''){ ?> style="background:#0000FF;" <?php }
                    else if($rstask['t_trans_to'] != ''){ ?> style="background:#DAA520;" <?php } else if($rstask['t_status'] == '3'){ ?> style="background:#2E8B57;" <?php } else if($rstask['t_sign'] == '1'){ ?> style="background:#00FFFF;" <?php } ?>>
                    <a href="" data-toggle="modal" data-to="<?php echo $toemp;?>"  data-id="<?php echo $rstask['tid']; ?>" data-from="<?php echo $fromemp;?>" data-target="#myModal" <?php if(($rstask['t_status'] == '1') || ($rstask['task_report'] != '') || ($rstask['t_trans_to'] != '') || ($rstask['t_status'] == '3')){ ?> style=" cursor: pointer;color: #FFF;" <?php } else {?> style=" cursor: pointer;color: #000; " <?php } ?>>  
                    <?php echo $fromemp; ?></a></td>
                    
                    <td <?php if($rstask['t_status'] == '1'){ ?> style="background:red;" <?php } else if($rstask['task_report'] != ''){ ?> style="background:#0000FF;color:#FFF;" <?php }
                    else if($rstask['t_trans_to'] != ''){ ?> style="background:#DAA520;" <?php } else if($rstask['t_status'] == '3'){ ?> style="background:#2E8B57;" <?php } else if($rstask['t_sign'] == '1'){ ?> style="background:#00FFFF;" <?php } ?>>
                    <a href="" data-toggle="modal"  data-to="<?php echo $toemp;?>"  data-id="<?php echo $rstask['tid']; ?>" data-from="<?php echo $fromemp;?>" data-target="#myModal" <?php if(($rstask['t_status'] == '1') || ($rstask['task_report'] != '') || ($rstask['t_trans_to'] != '') || ($rstask['t_status'] == '3')){ ?> style=" cursor: pointer;color: #FFF;" <?php } else {?> style=" cursor: pointer;color: #000; " <?php } ?>>
                    <?php echo $toemp; ?></a></td>
                    
                    <td <?php if($rstask['t_status'] == '1'){ ?> style="background:red;" <?php } else if($rstask['task_report'] != ''){ ?> style="background:#0000FF;color:#FFF;" <?php }
                    else if($rstask['t_trans_to'] != ''){ ?> style="background:#DAA520;" <?php } else if($rstask['t_status'] == '3'){ ?> style="background:#2E8B57;" <?php } else if($rstask['t_sign'] == '1'){ ?> style="background:#00FFFF;" <?php } ?>>
                    <a href="" data-toggle="modal" data-to="<?php echo $toemp;?>"  data-id="<?php echo $rstask['tid']; ?>"  data-from="<?php echo $fromemp;?>" data-target="#myModal" <?php if(($rstask['t_status'] == '1') || ($rstask['task_report'] != '') || ($rstask['t_trans_to'] != '') || ($rstask['t_status'] == '3')){ ?> style=" cursor: pointer;color: #FFF;" <?php } else {?> style=" cursor: pointer;color: #000; " <?php } ?>>  
                    <?php
                    $addcount=strlen($rstask['t_action']);
                    if($addcount <= 50) { echo substr($rstask['t_action'], 0, 50); ?> <span style=" color: red"><?php echo $rep_count; ?></span>  <?php } else {  echo substr($rstask['t_action'], 0, 50); echo '..'; ?> <span style=" color: red"><?php echo $rep_count; ?></span> <?php }
                    ?>
                    </a>
                    </td>
                    
                    <td <?php if($rstask['t_status'] == '1'){ ?> style="background:red;" <?php } else if($rstask['task_report'] != ''){ ?> style="background:#0000FF;color:#FFF;" <?php }
                    else if($rstask['t_trans_to'] != ''){ ?> style="background:#DAA520;" <?php } else if($rstask['t_status'] == '3'){ ?> style="background:#2E8B57;" <?php } else if($rstask['t_sign'] == '1'){ ?> style="background:#00FFFF;" <?php } ?>>
                    <a href="" data-toggle="modal" data-to="<?php echo $toemp;?>"  data-from="<?php echo $fromemp;?>" data-target="#myModal" data-id="<?php echo $rstask['tid']; ?>" <?php if(($rstask['t_status'] == '1') || ($rstask['task_report'] != '') || ($rstask['t_trans_to'] != '') || ($rstask['t_status'] == '3')){ ?> style=" cursor: pointer;color: #FFF;" <?php } else {?> style=" cursor: pointer;color: #000; " <?php } ?>>
                    <?php if($rstask['t_status'] == 1){ echo "Closed"; } else { echo "Open"; } ?></a></td>
                    <td>
    <?php if($rstask['t_status'] != 1){ ?>
          
    <?php if(($_SESSION['jay_proj_mngmnt'] == $empto) || ($_SESSION['jay_proj_mngmnt'] == $empfrom) || ($_SESSION['jay_proj_mngmnt'] == 1) ){ ?>
    <a href="" data-toggle="modal" data-id="<?php echo $rstask['tid'];?>" data-target="#myModaledit" style=" cursor: pointer;" title="Edit"><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp;
    <?php } else {?>
    <a onClick="no_permission();" style=" cursor: pointer;" title="Edit"><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp;
    <?php } ?>
    
     
    <?php if(($_SESSION['jay_proj_mngmnt'] == $empfrom) || ($_SESSION['jay_proj_mngmnt'] == 1) ){ ?>
    <a onClick="delete_task('<?php echo base64_encode($rstask['tid']); ?>');" style=" cursor: pointer;" title="Delete"><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;   
    <?php } else {?>
    <a onClick="no_permission();" style=" cursor: pointer;" title="Delete"><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;
    <?php } ?>
    <a href="" data-toggle="modal" data-target="#myModal6<?php echo $rstask['tid']; ?>" style=" cursor: pointer;" title="Reminder"><span class="fa fa-bell-o" <?php if($rstask['remind_set'] != ''){ ?> style="font-size:14px; color:red; " <?php } ?>></span></a> &nbsp;
    
    <?php } ?>
                    </td>
                   </tr>
                   
                               
                   
          
        <div id="report_todo_searh"></div>
        
        
       </div></div></div></div>
       
       
       
       
       
       
       
       
       
  <div class="modal fade" id="myModal6<?php echo $rstask['tid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
   <div class="modal-dialog" role="document" >
     <div class="modal-content">
       <div class="modal-header" style=" background-color: #E8E8E8;">
         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <h4 class="modal-title" id="myModalLabel"> #<?php echo $rstask['tid']; ?>  - Reminder</h4>
        </div>
        <div class="modal-body" id="myModal2" >
        <div class="row">   
            
            <div class="col-md-12" >
            <div class="col-md-8"  style=" padding-left: 2px; padding-right: 0px; ">                    
            <div class="form-group">
              <input type="text" name="reminderdat<?php echo $rstask['tid']; ?>" id="reminderdat<?php echo $rstask['tid']; ?>" class="form-control tcal" placeholder="Reminder- YYYY/MM/DD" value="<?php echo $rstask['remind_set']; ?>"/>
            </div></div>
            <div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">                    
            <div class="form-group">
            <input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" style=" float: right;margin-right: 5px; " onclick="reminder_set('<?php echo $rstask['tid']; ?>');" />       
            </div></div>    
            
            </div>
            
       </div></div></div></div></div>
       
       
            
            
            
                             
                   


 
</div> 





   <?php $m=$m+1; } ?>
                    </tbody>
                    </table>    <!-- FastClick -->
    <script src="<?php echo $sujpath; ?>plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo $sujpath; ?>dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <!--<script src="<?php echo $sujpath; ?>dist/js/demo.js"></script> -->
    <!-- page script -->
	<script>
     
        $("#example1").DataTable();
	  $(document).ready(function(){
    $('#myModaledit').on('show.bs.modal', function (e) {
		
       var taskid = $(e.relatedTarget).data('id');
		
		
        $.ajax({
            type : 'post',
            url : 'fetchforedit.php', //Here you will fetch records 
            data :  {taskid:taskid}, //Pass $id
            success : function(data){
            $("#fetchedit").html(data);//Show fetched data from database
			
            }
        });
     });
});
    </script>
      