<?php
require('header.php');
include "dbconfig.php";
$link =opencon();
$chck_id=$_SESSION["session_id"];

if($chck_id=='1' || $chck_id=='13'){
    $add="";
}else{
    
$fullname=$_SESSION["fullname"];
     $add=" and assigned_to='$fullname'";
}


?>

<div class="breadcome-area mg-b-30 small-dn">
                <div class="container-fluid">
                    <div class="row">

                                                
                        <div class="col-lg-12">
                            <div class="breadcome-list shadow-reset">
                                <div class="row">
                             <div class="col-lg-12">
                                 <!--<h4 style="text-align: center;font-size: 26px;background-color: antiquewhite;height: 36px;margin-top: -20px;">Search</h4>-->
                                  </div>
                               </div>
                                <div class="row" style="
    width: 100%;
">
                                    <form method='post'>
    <div class="col-lg-3"  >
                 <label for="">Client Name</label>
                     <input type="text" name="client_name" class="form-control">
            </div>
             <div class="col-lg-3"  >
                 <label for="">Client Number</label>
                     <input type="number" name="client_number" class="form-control">
            </div>
             <div class="col-lg-3"  >
                 <label for="">Client Email</label>
                     <input type="text" name="client_email" class="form-control">
            </div> 
            <div class="col-lg-3"  >
                 <label for="">Client status</label>
                       <select name="client_status" id="client_status" class="form-control">
                           <option value="">Select</option>
                                          <option value="Under Projection">Under Projection</option>
<option value="Visiting Completed">Visiting Completed</option>
<option value="Booking completed">Booking completed</option>
<option value="Registration completed">Registration completed</option>
<option value="Not Interested">Not Interested</option>
<option value="Not connected">Not connected</option>
                                    </select>
            </div>
            

    
             <div class="col-lg-3"  style="margin-top: 2%;">
                 <label for="">Lead Given Date From</label>
                     <input type="Date" name="lead_given_date_from" class="form-control">
            </div>
            <div class="col-lg-3"  style="margin-top: 2%;">
                 <label for="">Lead Given Date To</label>
                     <input type="Date" name="lead_given_date_to" class="form-control">
            </div>
            
            
            <div class="col-lg-3" style="margin-top: 2%;" >
                 <label for="">Assigned to</label>
                       <select name="assigned_to" id="assigned_to" class="form-control">
                           <option value="">Select</option>
                                         <?php
                                $query = "SELECT DISTINCT assigned_to FROM new_leads where assigned_to!='' $add";
$result = mysqli_query($link, $query);


while ($row = mysqli_fetch_assoc($result)) {

    ?>
    <option ><?php echo $row['assigned_to'];?></option>
    <?php
    
    
}

?>
                                
                                    </select>
            </div>
            
            
  <div class="col-lg-3"  style="margin-top: 4%;">
                 
                     <button type="submit" name="btn1" class=" btn btn-primary">Search</button>
            </div>
            </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Breadcome End-->
          
         
            <!-- stockprice, feed area end-->
            <div class="admin-dashone-data-table-area mg-b-15">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="sparkline8-list shadow-reset">
                                <div class="sparkline8-hd">
                                    <div class="main-sparkline8-hd">
                                        <h1>Lead List</h1>
                                        <div class="sparkline8-outline-icon">
                                            <span class="sparkline8-collapse-link"><i class="fa fa-chevron-up"></i></span>
                                            <span><i class="fa fa-wrench"></i></span>
                                            <span class="sparkline8-collapse-close"><i class="fa fa-times"></i></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="sparkline8-graph">
                                    <div class="datatable-dashv1-list custom-datatable-overright">
                                        <div id="toolbar">
                                            <select class="form-control">
                                                <option value="">Export Basic</option>
                                                <option value="all">Export All</option>
                                                <option value="selected">Export Selected</option>
                                            </select>
                                        </div>
                                        <table id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true" data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
                                            <thead>
                                                <tr >
                                            <th >S.No</th>
                                            <th>Entry Date</th>
                                            <th>Lead Source</th>

                                            <th>Lead Generated By</th>

<th>Lead Given Date</th>






<th>Client Name</th>
<th>Client Number</th>
<th>Client Email</th>
<th>Client Location</th>


<th>Client Job Type</th>

<th>Designation</th>
<th>Salary Per Month</th>

<th>Remarks</th>

<th>Property Type</th>

<th>Total Cents</th>
<th>Per Cent - Budget</th>
<th>Home - Budget</th>
<th>Total - Budget</th>



<th>Assigned To</th>
<th>Lead Status</th>
<th>Client Status</th>

                                           
                                            <th>Action</th>
                                        </tr>
                                            </thead>
                                             <tbody id="myTable">
<?php
if(isset($_GET['delete']))
{
$id=$_GET['delete'];
$sql="DELETE FROM `new_leads` WHERE id='$id'";

if (mysqli_query($link,$sql)) {
      echo " <div class='alert-area' >
                <div class='container-fluid'>
				<div class='row'>
				<div class='col-lg-6'> 
				<div class='alert-icon shadow-reset wrap-alert-b'>
                                <div class='alert-title'>
                                
                                </div>
                                <div class='alert alert-success alert-success-style1'>
                                    <button type='button' class='close sucess-op' data-dismiss='alert' aria-label='Close'>
                                        <span class='icon-sc-cl' aria-hidden='true'>&times;</span>
                                    </button>
                                    <p><span class='adminpro-icon adminpro-checked-pro admin-check-sucess'></span>
                                    <strong>Successfully! </strong> Deleted your Lead</p>
                             </div>
							 </div>
							 </div>
							 </div>
							 </div>
							 </div>";

}   
else {
  echo "<div class='alert-area' >
                <div class='container-fluid'>
				<div class='row'>
				<div class='col-lg-6'> 
				<div class='alert-icon shadow-reset wrap-alert-b'>
                                <div class='alert-title'>
                                
                                </div>
                               <div class='alert alert-danger alert-mg-b alert-success-style4'>
                                    <button type='button' class='close sucess-op' data-dismiss='alert' aria-label='Close'>
                                        <span class='icon-sc-cl' aria-hidden='true'>&times;</span>
                                    </button>
                                    <span class='adminpro-icon adminpro-danger-error admin-check-sucess'></span>
                                    <p><strong>Danger!</strong> A dangerous or potentially negative action.</p>
                                </div>
							 </div>
							 </div>
							 </div>
							 </div>
							 </div>";
}
  
}

$where7="limit 50";
if(isset($_POST['btn1'])){
   $client_name=$_POST['client_name'];
   $client_number=$_POST['client_number'];
   $client_email=$_POST['client_email'];
   $client_status=$_POST['client_status'];
   $lead_generated_by=$_POST['lead_generated_by'];
    $lead_given_to=$_POST['lead_given_to'];
   $from=$_POST['lead_given_date_from'];
   $to=$_POST['lead_given_date_to'];
   $assigned_to=$_POST['assigned_to'];
   
     $where7="";
   if($client_name!='')
   {
       $where1=" and client_name='$client_name'";
   }
   if($client_number!='')
   {
       $where2=" and client_number='$client_number'";
   }
   if($client_email!='')
   {
       $where3=" and client_email='$client_email'";
   }
   if($client_status!='')
   {
       $where4=" and client_status='$client_status'";
   }
   if($lead_generated_by!='')
   {
       $where5=" and lead_generated_by='$lead_generated_by'";
   }
   if($lead_given_to!='')
   {
       $where6=" and lead_given_to='$lead_given_to'";
   }
    if($from!='')
   {
       $where7=" and lead_given_date between '$from' and '$to'";
   }
   
    if($assigned_to!='')
   {
       $where8=" and assigned_to='$assigned_to' and  assigned_to!='' ";
   }
   
}
$sql = "SELECT * FROM new_leads where id!='' and assigned_to!='' $where1 $where2 $where3 $where4 $where5 $where6 $where8 $add $where7";


$sql_exe = mysqli_query($link,$sql);
$count = 1;
while($fetch_qr = mysqli_fetch_array($sql_exe)){

?>
 <tr>
                            <td ><?php echo $count; ?></td>
                             <td ><?php echo $fetch_qr['entry_date']; ?></td>
                             <td ><?php echo $fetch_qr['lead_source']; ?></td>
                            <td ><?php echo $fetch_qr['lead_generated_by']; ?></td>
                            <td ><?php echo $fetch_qr['lead_given_date']; ?></td>
                           
                            <td ><?php echo $fetch_qr['client_name']; ?></td>
                            <td ><?php echo $fetch_qr['client_number']; ?></td>
                             <td ><?php echo $fetch_qr['client_email']; ?></td>
                            <td ><?php echo $fetch_qr['client_location']; ?></td>
                           
                            <td ><?php echo $fetch_qr['client_job_type']; ?></td>
                            <td ><?php echo $fetch_qr['designation']; ?></td>
                            <td ><?php echo $fetch_qr['salary_per_month']; ?></td>
                            
                             <td ><?php echo $fetch_qr['remarks']; ?></td>
                         
                            <td ><?php echo $fetch_qr['property_type']; ?></td>
                            <td ><?php echo $fetch_qr['total_cents']; ?></td>
                            <td ><?php echo $fetch_qr['per_cent_budget']; ?></td>
                            <td ><?php echo $fetch_qr['home_budget']; ?></td>
                             <td ><?php echo $fetch_qr['total_budget']; ?></td>
                       
                          
                        <td ><?php echo $fetch_qr['assigned_to']; ?></td>
                           
                           <td ><?php echo $fetch_qr['lead_status']; ?></td>
                            
                         
                            <td ><?php echo $fetch_qr['client_status']; ?></td>
                           
                            
                            
                            
                <td><div class="d-flex">
                                                    
                             
  <?php echo can_edit("lead_list",$edit_acess,"new_lead.php?id=".$fetch_qr['id']."");?>
    
    
      <?php echo can_delete("lead_list",$delete_access,"delete_id.php?delete=".$fetch_qr['id']."&table=new_leads&page=lead_list");?>  
    
    
 

                 
                                                    
</div>
 </td>
 </tr>
<?php
$count = $count+1;
}
?>
                                    </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
<?php
require('footer.php');
?>