<?php 
require 'lock.php';

function checkTaskData($user_id, $role, $type,$con)
{
if($type=='Total')
{
if($role=='Manager')
{
$gettaskqry="select task_master.*,user_master.user_name,user_photo from task_master 
inner join user_master ON user_master.user_id=task_master.task_userid 
where task_deleted='No' order by task_id DESC";
}
else{
$gettaskqry="select task_master.*,user_master.user_name ,user_photo from task_master 
inner join user_master ON user_master.user_id=task_master.task_userid
where task_deleted='No' AND (task_userid='$user_id' OR task_cby='$user_id')";
}	
}
else{
if($role=='Manager')
{
$gettaskqry="select task_master.*,user_master.user_name,user_photo from task_master 
inner join user_master ON user_master.user_id=task_master.task_userid
where task_deleted='No' AND task_status='$type'";
}
else{
$gettaskqry="select task_master.*,user_master.user_name,user_photo from task_master 
inner join user_master ON user_master.user_id=task_master.task_userid
where task_deleted='No' AND task_status='$type' AND (task_userid='$user_id' OR task_cby='$user_id')";
}
}
return $gettaskres=mysqli_query($con, $gettaskqry);
}

$type = isset($_GET['type']) ? strtolower($_GET['type']) : 'total';

switch($type){
    case 'pending':
        $activeTab = 'top-pending';
        break;
    case 'progress':
        $activeTab = 'top-progress';
        break;
    case 'hold':
        $activeTab = 'top-hold';
        break;
    case 'review':
        $activeTab = 'top-review';
        break;
    case 'completed':
        $activeTab = 'top-completed';
        break;
    default:
        $activeTab = 'top-all';
}

?>
<!DOCTYPE html>
<html lang="en">
<?php require 'head.php'; ?>
<script>
document.addEventListener("DOMContentLoaded", function () {
    let tabId = "<?php echo $activeTab; ?>";
    
    let triggerEl = document.querySelector('[href="#' + tabId + '"]');
    
    if (triggerEl) {
        let tab = new bootstrap.Tab(triggerEl);
        tab.show();
    }
});
</script>
<body>
    <!-- Loader starts-->
    <div class="loader-wrapper">
      <div class="theme-loader">    
        <div class="loader-p"></div>
      </div>
    </div>
    <!-- Loader ends-->
    <!-- page-wrapper Start-->
    <div class="page-wrapper" id="pageWrapper">
      <?php include 'top.php'; ?>
      <!-- Page Body Start-->
      <div class="page-body-wrapper horizontal-menu">
        <?php include 'header.php'; ?>
        <!-- Page Sidebar Ends-->
        <div class="page-body">
          <div class="container-fluid">
            <div class="page-header">
              <div class="row">
                <div class="col-6">
                  <h3>Task list</h3>
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="index">Home</a></li>
                    <li class="breadcrumb-item active">Task list</li>
                  </ol>
                </div>
                <div class="col-6">
                 <a href="index" class="btn btn-secondary me-3">Back</a>   
                </div>
              </div>
            </div>
          </div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">		  
<style>
.bg-pending {
    background-color: #fff3cd; /* light yellow */
}

.bg-progress {
    background-color: #cce5ff; /* light blue */
}

.bg-hold {
    background-color: #e2e3e5; /* gray */
}

.bg-completed {
    background-color: #d4edda; /* light green */
}

.bg-default {
    background-color: #f8f9fa;
}

.project-list span {
  margin-right: 8px;
  font-size: 8px;
}

.project-list i {
  margin-right: 5px;
}

/* Colors */
.fa-list { color: #555; }
.fa-clock { color: orange; }
.fa-spinner { color: blue; }
.fa-pause { color: purple; }
.fa-star { color: #f4b400; }
.fa-circle-check { color: green; }

.badge-review {
    background-color: #f4b400;
    color: #fff;
}

.bg-review {
    background-color: #fff8e1; /* light golden background */
}

</style>
          <!-- Container-fluid starts-->
          <div class="container-fluid">
            <div class="row project-cards">
              <div class="col-md-12 project-list">
                <div class="card">
                  <div class="row">
                    <div class="col-md-8 p-0">
                      <ul class="nav nav-tabs border-tab" id="top-tab" role="tablist">
                        <li class="nav-item"><a class="nav-link active" id="all-tab" data-bs-toggle="tab" href="#top-all" role="tab" aria-controls="top-all" aria-selected="true"> <span><i class="fa-solid fa-list"></i> All</span> </a></li>
                        <li class="nav-item"><a class="nav-link" id="pending-tab" data-bs-toggle="tab" href="#top-pending" role="tab" aria-controls="top-pending" aria-selected="false"> <span><i class="fa-regular fa-clock"></i> Pending</span> </a></li>
                        <li class="nav-item"><a class="nav-link" id="progress-tab" data-bs-toggle="tab" href="#top-progress" role="tab" aria-controls="top-progress" aria-selected="false"> <span><i class="fa-solid fa-spinner"></i> In Progress</span> </a></li>
                        <li class="nav-item"><a class="nav-link" id="hold-tab" data-bs-toggle="tab" href="#top-hold" role="tab" aria-controls="top-hold" aria-selected="false"> <span><i class="fa-solid fa-pause"></i> On Hold</span> </a></li>
						<li class="nav-item"><a class="nav-link" id="review-tab" data-bs-toggle="tab" href="#top-review" role="tab" aria-controls="top-review" aria-selected="false"><span><i class="fa-solid fa-star"></i> Review</span></a></li>
                        <li class="nav-item"><a class="nav-link" id="completed-tab" data-bs-toggle="tab" href="#top-completed" role="tab" aria-controls="top-completed" aria-selected="false"><span><i class="fa-solid fa-circle-check"></i> Completed</span></a></li>
                      </ul>
                    </div>
                    <div class="col-md-4 p-0">                    
                      <div class="form-group mb-0 me-0"></div>
					  <a class="btn btn-primary" href="task-add"> <i data-feather="plus-square"> </i>Create New Task</a>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-sm-12">
                <div class="card">
                  <div class="card-body">
                    <div class="tab-content" id="top-tabContent">
                      <div class="tab-pane fade show active" id="top-all" role="tabpanel" aria-labelledby="all-tab">
                        <div class="row">
						<?php
						$taskquery = checkTaskData($user_id, $user_type, "Total", $con);
						if($taskquery && mysqli_num_rows($taskquery) > 0) 
						{
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

                        switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
						
						case 'Review':
                        $badgeClass = 'badge-review';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						
                        switch($status){
                        case 'Pending':
                        $bgClass = 'bg-pending';
                        break;
                        
                        case 'In Progress':
                        $bgClass = 'bg-progress';
                        break;
                        
                        case 'On Hold':
                        $bgClass = 'bg-hold';
                        break;
						
						case 'Review':
                        $bgClass = 'bg-review';
                        break;
                        
                        case 'Completed':
                        $bgClass = 'bg-completed';
                        break;
                        
                        default:
                        $bgClass = 'bg-default';
                        }

						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box <?php echo $bgClass; ?>">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body">
						<p> Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
						
						<a href="task-cancel.php?task_id=<?php echo $encrypted ?>" 
                        class="btn btn-danger btn-xs"
                        onclick="return confirm('Are you sure you want to cancel this task?');">
                        <i class="fa-solid fa-ban"></i> Cancel
                        </a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						} else {
						echo "No Task Found";
						}
						?>
                        </div>
                      </div>
					  <!-- ALL TASK SECTION END -->
					  
					  
					  <div class="tab-pane fade" id="top-pending" role="tabpanel" aria-labelledby="pending-tab">
                        <div class="row">
                        <?php
						$taskquery = checkTaskData($user_id, $user_type, "Pending", $con);
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

						switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						
						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p>  Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
						
						<a href="task-cancel.php?task_id=<?php echo $encrypted ?>" 
                        class="btn btn-danger btn-xs"
                        onclick="return confirm('Are you sure you want to cancel this task?');">
                        <i class="fa-solid fa-ban"></i> Cancel
                        </a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						?>
                        </div>
                      </div>
                      <!-- PENDING SECTION END -->
					 
					 
					 <div class="tab-pane fade" id="top-progress" role="tabpanel" aria-labelledby="progress-tab">
                        <div class="row">
                        <?php
						$taskquery= checkTaskData($user_id, $user_type, "In Progress", $con);
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

						switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
						
						<a href="task-cancel.php?task_id=<?php echo $encrypted ?>" 
                        class="btn btn-danger btn-xs"
                        onclick="return confirm('Are you sure you want to cancel this task?');">
                        <i class="fa-solid fa-ban"></i> Cancel
                        </a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						?>
                        </div>
                      </div>
                      <!-- Progress SECTION END -->
					  
					  <div class="tab-pane fade" id="top-hold" role="tabpanel" aria-labelledby="hold-tab">
                        <div class="row">
                        <?php
						$taskquery= checkTaskData($user_id, $user_type, "On Hold", $con);
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

						switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
						
						<a href="task-cancel.php?task_id=<?php echo $encrypted ?>" 
                        class="btn btn-danger btn-xs"
                        onclick="return confirm('Are you sure you want to cancel this task?');">
                        <i class="fa-solid fa-ban"></i> Cancel
                        </a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						?>
                        </div>
                      </div>
                      <!-- On Hold SECTION END -->
					  
					  <div class="tab-pane fade" id="top-review" role="tabpanel" aria-labelledby="review-tab">
                        <div class="row">
                        <?php
						$taskquery=checkTaskData($user_id, $user_type, "Review", $con);
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

						switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
						
						<a href="task-cancel.php?task_id=<?php echo $encrypted ?>" 
                        class="btn btn-danger btn-xs"
                        onclick="return confirm('Are you sure you want to cancel this task?');">
                        <i class="fa-solid fa-ban"></i> Cancel
                        </a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						?>
                        </div>
                      </div>
                      <!-- Review SECTION END -->
					  
					  <div class="tab-pane fade" id="top-completed" role="tabpanel" aria-labelledby="completed-tab">
                        <div class="row">
                        <?php
						$taskquery=checkTaskData($user_id, $user_type, "Completed", $con);
						while($taskgetdata=mysqli_fetch_assoc($taskquery))
						{
						$task_id = $taskgetdata['task_id'];
						$status = $taskgetdata['task_status'] ?? '';

						switch($status){
                        case 'Pending':
                        $badgeClass = 'badge-warning';
                        break;
                        
                        case 'In Progress':
                        $badgeClass = 'badge-info';
                        break;
                        
                        case 'On Hold':
                        $badgeClass = 'badge-secondary';
                        break;
                        
                        case 'Completed':
                        $badgeClass = 'badge-success';
                        break;
                        
                        default:
                        $badgeClass = 'badge-primary';
                        }
						$encrypted = encryptId($task_id);
						?>
						<div class="col-xxl-4 col-lg-6">
						<div class="project-box">
						<span class="badge <?php echo $badgeClass; ?>"><?php echo $taskgetdata['task_status'] ?></span>
						<h6><a href="task-track?task_id=<?php echo $encrypted ?>" class="text-dark">
						<?php echo $taskgetdata['task_title'] ?></a>
						</h6>
						
						<?php
						$task_cby = $taskgetdata['task_cby'];
                        $createduserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby' ");
                        $createduserdata=mysqli_fetch_array($createduserqry);
						?>
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $createduserdata['user_photo']; ?>" alt="" data-original-title="" title="">
						<div class="media-body"><p> Created By :  <?php echo $createduserdata['user_name'] ?></p></div>
						</div>
						
						<div class="media">
						<img class="img-20 me-2 rounded-circle" src="task-image/<?php echo $taskgetdata['user_photo'] ?>" alt="" data-original-title="" title="">
						<div class="media-body">
						<p> Assigned To :  <?php echo $taskgetdata['user_name'] ?></p>
						</div>
						</div>
						
						<p><?php echo $taskgetdata['task_detail'] ?></p>
						<div class="row details">
						<div class="col-6"><span>Priority </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_priority'] ?> </div>
						<div class="col-6"><span>Type </span></div>
						<div class="col-6 font-primary"><?php echo $taskgetdata['task_type'] ?> </div>
						<?php
						if($taskgetdata['task_enddate']!='')
						{
						?>
						<div class="col-6"> <span>Task Deadline</span></div>
						<div class="col-6 font-primary"><?php echo date('d-M-Y',strtotime($taskgetdata['task_enddate'])) ?> : <?php echo date('h:i A',strtotime($taskgetdata['task_endtime'])) ?></div>
						<?php
						}

						if($taskgetdata['task_file']!='')
						{
						?>
						<div class="col-6"> <span>File</span></div>
						<div class="col-6 font-primary"><a href="task-image/<?php echo $taskgetdata['task_file'] ?>" target="_blank">
						<i data-feather="file-plus"></i></a></div>
						<?php
						}
						?>
						</div>
						
						<div class="d-flex gap-2">
						<?php 
						if($task_cby==$user_id)
						{
						?>
						<a href="task-edit?task_id=<?php echo $encrypted ?>" class="btn btn-primary btn-xs">
						<i class="fa-solid fa-pen-to-square"></i> Edit
						</a>
                        <?php
						}
						?>

						<a href="task-status?task_id=<?php echo $encrypted ?>" class="btn btn-info btn-xs text-white">
						<i class="fa-solid fa-list-check"></i> Status
						</a>

						<a href="task-remark.php?task_id=<?php echo $encrypted ?>" class="btn btn-success btn-xs">
						<i class="fa-regular fa-comment"></i> Comment
						</a>
						
						</div>
						
						</div>
						</div>
						<?php
						}
						?>
                        </div>
                      </div>
                      <!-- Completed SECTION END -->
					 
					 
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- Container-fluid Ends-->
        </div>
        <?php include 'footer.php'; ?>
  </body>
  
</html>
