<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	
	$umid = $_SESSION['umid'];

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	$aa2 ="";
	if(isset($_SESSION['taskstatus']))
	{
		 $status = $_SESSION['taskstatus'];
		$aa2 = "and res_taskallocation_detail.taskstatus = $status";
	}
	
	$eve = "select * from res_task_master,res_taskallocation_detail where res_taskallocation_detail.taskmid = res_task_master.taskmid and res_taskallocation_detail.umid = $umid $aa2 ";
	$re = mysqli_query($conn, $eve);	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
			 
				$taskmid=$rt['taskmid'];
				$tadid=$rt['tadid'];
				$taskname=$rt['taskname'];
				$taskstatus=$rt['taskstatus'];
				$taskpriority=$rt['taskpriority'];
				
				$taskduedate=date("d-m-Y",strtotime($rt['taskduedate']));
				
				
				
				
				
				$pidedit="<a href='taskedit.php?id=".$rt['taskmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				
				$piddetail="<a href='taskdetail.php?id=".$rt['taskmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-eye fa-lg'>  </a>";
				
				
				
				
				$piddelete="<a href='taskdelete.php?id=".$rt['taskmid']."'onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";			
                $op=$piddetail."&nbsp;&nbsp;&nbsp; ".$piddelete;
				
				
				if($taskstatus == 'Completed')
				{
					$aa = "<div class='badge badge-light-success fw-bold'>Completed</div>";
				}else if($taskstatus == 'Completed')
				{
								
						 $aa = "<a href='#' data-bs-toggle='modal' data-id='".$tadid."' data-bs-target='#kt_modal_close_task' class='btn btn-sm btn-success align-self-center' id='closetask'>$taskstatus</a>";	
				}else {
					 $aa = "<a href='#' data-bs-toggle='modal' data-id='".$tadid."' data-bs-target='#kt_modal_close_task' class='btn btn-sm btn-primary align-self-center' id='closetask'>$taskstatus</a>";	
				}						 
				
				
								
				$posts[] = array('srno'=> $i++, 'taskname'=> $taskname, 'taskpriority'=> $taskpriority,  'taskduedate'=> $taskduedate,  'taskstatus'=> $aa,  'op'=> $piddetail);
		 }
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}
	
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }   
	mysqli_close($conn);	
	
?>