<?php include "check_login.php"; ?>
<?php
include 'dbcon.php';


$seenQuery = "UPDATE notifications SET is_seen = 1 WHERE role='pm' and user_id='$userpmid' AND is_seen=0";
mysqli_query($conn, $seenQuery);


/* Total Leads */
$totalLeadQuery = "SELECT COUNT(*) AS total_leads FROM projects";
$totalResult = mysqli_query($conn, $totalLeadQuery);
$totalLeads = mysqli_fetch_assoc($totalResult)['total_leads'];

/* Active Leads */
$activeLeadQuery = "SELECT COUNT(*) AS active_leads 
                    FROM projects 
                    WHERE lead_status = 'active'";
$activeResult = mysqli_query($conn, $activeLeadQuery);
$activeLeads = mysqli_fetch_assoc($activeResult)['active_leads'];
?>

<!DOCTYPE html>
<html lang="zxx">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <title>Leads</title>
  
    <link rel="shortcut icon" type="image/x-icon" href="assets/images/favicon.ico">
  
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
 
    <link rel="stylesheet" type="text/css" href="assets/vendors/css/vendors.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendors/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendors/css/select2-theme.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendors/css/datepicker.min.html">
    
    <link rel="stylesheet" type="text/css" href="assets/css/theme.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

</head>

<body>
<?php include("sidebar.php"); ?>
<?php include("header.php"); ?>   

 <main class="nxl-container">
        <div class="nxl-content">
            <!-- [ page-header ] start -->
            <div class="page-header">
                <div class="page-header-left d-flex align-items-center">
                    <div class="page-header-title">
                        <h5 class="m-b-10">Leads</h5>
                    </div>
                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                        <li class="breadcrumb-item">Leads</li>
                    </ul>
                </div>
                <div class="page-header-right ms-auto">
                    <div class="page-header-right-items">
                        <div class="d-flex d-md-none">
                            <a href="javascript:void(0)" class="page-header-right-close-toggle">
                                <i class="feather-arrow-left me-2"></i>
                                <span>Back</span>
                            </a>
                        </div>
                        <div class="d-flex align-items-center gap-2 page-header-right-items-wrapper">
                            <a href="javascript:void(0);" class="btn btn-icon btn-light-brand" data-bs-toggle="collapse" data-bs-target="#collapseOne">
                                <i class="feather-bar-chart"></i>
                            </a>
                     
                        </div>
                    </div>
                    <div class="d-md-none d-flex align-items-center">
                        <a href="javascript:void(0)" class="page-header-right-open-toggle">
                            <i class="feather-align-right fs-20"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div id="collapseOne" class="accordion-collapse collapse page-header-collapse">
                <div class="accordion-body pb-2">
                    <div class="row">
                        <div class="col-xxl-3 col-md-6">
                            <div class="card stretch stretch-full">
                                <div class="card-body">
                                    <div class="d-flex align-items-center justify-content-between">
                                        <div class="d-flex align-items-center gap-3">
                                            <div class="avatar-text avatar-xl rounded">
                                                <i class="feather-users"></i>
                                            </div>
                                            <a href="javascript:void(0);" class="fw-bold d-block">
                                                <span class="d-block">Total Leads</span>
                                                <span class="fs-24 fw-bolder d-block"><?php echo $totalLeads; ?></span>
                                            </a>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xxl-3 col-md-6">
                            <div class="card stretch stretch-full">
                                <div class="card-body">
                                    <div class="d-flex align-items-center justify-content-between">
                                        <div class="d-flex align-items-center gap-3">
                                            <div class="avatar-text avatar-xl rounded">
                                                <i class="feather-user-check"></i>
                                            </div>
                                            <a href="javascript:void(0);" class="fw-bold d-block">
                                                <span class="d-block">Active Leads</span>
                                                <span class="fs-24 fw-bolder d-block"><?php echo $activeLeads; ?></span>
                                            </a>
                                        </div>
                                     
                                    </div>
                                </div>
                            </div>
                        </div>
                      
                    </div>
                </div>
            </div>
            <!-- [ page-header ] end -->
            <!-- [ Main Content ] start -->
            <div class="main-content">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card stretch stretch-full">
                            <div class="card-body p-0">
                                <div class="table-responsive">

         
                                    <table class="table table-hover" id="leadList">
                                        <thead>
                                            <tr>
                                                <th>
                                               S.no.
                                                </th>
                                                <th>Name</th>
                                                <th>Company Name</th>
                                                <th>Mobile</th>
                                               
                                                <th>Project Location</th>
                                                 
                                                  <th>Status</th>
                                                   <th>Lead Date</th>
                                                   <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                             <?php
	
    require_once 'dbcon.php';
	
	$rs1=mysql_query("select * from projects where pm_id='$userpmid' order by id desc") or die(mysql_error());
	while($arr1=mysql_fetch_array($rs1))
{
	
	$id=$arr1["id"];
	
	$i++;
	
?>
                                            <tr class="single-item">
                                                <td>
                                                 <?php echo $i; ?>
                                                </td>

                                                <td>
                                                  
                                              <span class="text-truncate-1-line"><?php echo $arr1['name']; ?></span>
                                                    
                                                </td>
                                                <td><?php echo $arr1['company_name']; ?></td>
                                                <td>
                                                <?php echo $arr1['mobile']; ?>
                                                </td>
                                                
                                                <td>
                                                <?php echo $arr1['project_location']; ?>
                                                </td>
                                              
                                                 <td>
                                                  <?php echo $arr1['status']; ?>
                                                </td>
                                                 <td>
                                                  <?php echo $arr1['created_at']; ?>
                                                </td>
                                                  <td>
                                                   <a href="enquiry_view.php?project_id=<?php echo $arr1['id']; ?>" class="avatar-text avatar-md">
                                                            <i class="feather feather-eye"></i>
                                                        </a>
                                                </td>
                                            </tr>
                                     <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- [ Main Content ] end -->
        </div>
        <!-- [ Footer ] start -->
<?php include("footer.php"); ?>
        <!-- [ Footer ] end -->
    </main>

    <!--! BEGIN: Vendors JS !-->
    <script src="assets/vendors/js/vendors.min.js"></script>
    <!-- vendors.min.js {always must need to be top} -->
    <script src="assets/vendors/js/select2.min.js"></script>
    <script src="assets/vendors/js/select2-active.min.js"></script>
    <script src="assets/vendors/js/datepicker.min.html"></script>
    <script src="assets/vendors/js/lslstrength.min.html"></script>
    <!--! END: Vendors JS !-->
    <!--! BEGIN: Apps Init  !-->
    <script src="assets/js/common-init.min.js"></script>
    <script src="assets/js/customers-create-init.min.js"></script>
    <!--! END: Apps Init !-->
    <!--! BEGIN: Theme Customizer  !-->
    <script src="assets/js/theme-customizer-init.min.js"></script>
    <!--! END: Theme Customizer !-->
</body>
</html>
