<?php 
require 'lock.php';

function checkTaskData($user_id, $role, $type,$con)
{
if($type=='Total')
{
if($role=='Admin')
{
$gettaskqry="select task_id from task_master where task_deleted='No'";
}
else{
$gettaskqry="select task_id from task_master where task_deleted='No' AND (task_userid='$user_id' OR task_cby='$user_id')";
}	
}
else{
if($role=='Admin')
{
$gettaskqry="select task_id from task_master where task_deleted='No' AND task_status='$type'";
}
else{
$gettaskqry="select task_id from task_master where task_deleted='No' AND task_status='$type' AND (task_userid='$user_id' OR task_cby='$user_id')";
}
}
$gettaskres=mysqli_query($con, $gettaskqry);
return $gettaskroe=mysqli_num_rows($gettaskres);
}

?>
<!DOCTYPE html>
<html lang="en">
<?php require 'head.php'; ?>
<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 Header Ends                              -->
      <!-- 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-sm-6">
                  <h3>Users List</h3>
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="index">Home</a></li>
                    <li class="breadcrumb-item active">Users List</li>
                  </ol>
                </div>
                <div class="col-sm-6">
                </div>
              </div>
            </div>
          </div>
          <!-- Container-fluid starts-->
          <div class="container-fluid user-card">
            <div class="row">
			<div class="col-md-12 project-list">
                <div class="card">
                  <div class="row">
                    <div class="col-md-8 p-0">
                    </div>
                    <div class="col-md-4 p-0">                    
                      <div class="form-group mb-0 me-0"></div>
					  <a class="btn btn-primary" href="user-add"> <i data-feather="plus-square"> </i> New User Add</a>
                    </div>
                  </div>
                </div>
              </div>
			  
			<?php
			$sn=1;
			$customerqry=mysqli_query($con,"select * from user_master where user_status='Enable' order by user_id DESC");
			while($customerdata=mysqli_fetch_assoc($customerqry))
			{
			$userid = $customerdata['user_id'];
			$depatmentuser = $customerdata['user_department'];
			?>
			<div class="col-md-6 col-lg-6 col-xl-4 box-col-6">
			<div class="card custom-card">
			<div class="card-profile"><img class="rounded-circle" src="task-image/<?php echo $customerdata['user_photo']; ?>" alt=""></div>
			<div class="text-center profile-details">
			<h4><?php echo $customerdata['user_name']; ?></h4>
			<p style="margin-bottom:3px"><?php echo $customerdata['user_email']; ?></p>
			<p style="margin-bottom:3px"><?php echo $customerdata['user_mobile']; ?></p>
			<!-- <p><?php echo $customerdata['user_department']; ?></p> -->
			</div>
			<div class="card-footer row">
			<div class="col-4 col-sm-4">
			<h6>Tasks</h6>
			<h3 class="counter"><?php echo $totaltask = checkTaskData($userid, $depatmentuser, "Total", $con); ?></h3>
			</div>
			<div class="col-4 col-sm-4">
			<h6>Pending</h6>
			<h3><span class="counter"><?php echo $totaltask = checkTaskData($userid, $depatmentuser, "Pending", $con); ?></h3>
			</div>
			<div class="col-4 col-sm-4">
			<h6>In Progress</h6>
			<h3><span class="counter"><?php echo $totaltask = checkTaskData($userid, $depatmentuser, "In Progress", $con); ?></h3>
			</div>
			<div class="col-4 col-sm-4">
			<h6>On Hold</h6>
			<h3><span class="counter"><?php echo $totaltask = checkTaskData($userid, $depatmentuser, "On Hold", $con); ?></h3>
			</div>
			<div class="col-4 col-sm-4">
			<h6>Completed</h6>
			<h3><span class="counter"><?php echo $totaltask = checkTaskData($userid, $depatmentuser, "Completed", $con); ?></h3>
			</div>
			</div>
			<ul class="card-social">
			<li><a href="user-edit?getuserid=<?php echo $customerdata['user_id']; ?>"><i class="icon-pencil-alt"></i></a></li>
			<!-- <li><a href=""><i class="icon-settings"></i></a></li> -->
			</ul>
			</div>
			</div>
			<?php
			}
			?>
			 
            </div>
          </div>
          <!-- Container-fluid Ends-->
        </div>
        
		<?php include 'footer.php'; ?>
  </body>
</html>