<?php
include "header.php";
?>

<!-- Main Working Space Start -->

<div class="col-md-12">
<div
          class="mt-4 grid grid-cols-12 gap-4 px-[var(--margin-x)] transition-all duration-[.25s] sm:mt-5 sm:gap-5 lg:mt-6 lg:gap-6"
        >
        <div style="" class="">
        <div class="card mt-2">
        <div class="col-md-12 card-header ">
            <div class="row">
              <div class="col-md-2">
                <h3 class=""> Lead List </h3>
              </div>
              <div class="col-md-6">
              <nav style="--bs-breadcrumb-divider: url(&#34;data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='%236c757d'/%3E%3C/svg%3E&#34;);" aria-label="breadcrumb">
                <ol class="breadcrumb mt-2">
                  <li class="breadcrumb-item"><a href="index.php">Leads</a></li>
                  <li class="breadcrumb-item active" aria-current="page">Lead List</li>
                </ol>
              </nav>
              </div>
            </div>
          </div>
            <div class="card-body">
              <form action="" method="post">
              <div class="col-md-12">
                <div class="row">
                  <div class="col-md-4">
                    <label for="">From Date</label>
                    <input type="date" id="search1" name="from" class="form-control">
                  </div>
                  <div class="col-md-4">
                    <label for="">To Date</label>
                    <input type="date" id="search2" name="to" class="form-control">
                  </div>
                  <div class="col-md-4">
                    <label for="">Lead Status</label>
                    <select name="status" id="lead_status" class="form-select">
                      <option value="NULL">--Select--</option>
                      <option value="Pipeline">Pipeline</option>
                      <option value="Sure Pipeline">Sure Pipeline</option>
                      <option value="Projected">Projected</option>
                      <option value="Not Interested">Not Interested</option>
                      <option value="Converted">Converted</option>
                    </select>
                  </div>
                </div>
              </div>
              <div class="col-md-12 mt-4">
                <div class="row">
                  <div class="col-md-4">
                    <label for="">Team Manager</label>
                    <select name="manager" autocomplete="off" id="manager" class="form-select">
                    <option value="">--Select--</option>
                      <option value="AKILA">AKILA</option>
                    </select>
                  </div>
                  <div class="col-md-4">
                    <label for="">Team Leader</label>
                    <select name="leader"  autocomplete="off"  id="ddl1" onchange="configureDropDownLists(this, document.getElementById('ddl2'))"  class="form-select">
                        <option value="">--Select--</option>
                        <option value="BAKIYALAKSHMI">BAKIYALAKSHMI</option>    
                        <option value="VIJAYAKUMARI">VIJAYAKUMARI</option>    
                </select>
                  </div>
                  <div class="col-md-3">
                    <label for="">Tele Caller</label>
                    <select name="telecaller"  autocomplete="off"  id="ddl2" class="form-select">                    
                    </select>

                  </div>
                  <div class="col-md-1">
                    <button class="btn btn-warning btn-sm" name="btn" type="submit" style="margin-top: 20px;"><span class="material-symbols-outlined">search</span></button>
                  </div>
                </div>
              </div>
              </form>
            </div>
        </div>
        <div>
          <div class="col-md-12">
          <div class="card mt-5">
            <div class="card-header">
              <div class="row">
                <div>
                <h3 style="float: left;">View Table</h3>
                <a href="new_lead.php" style="float: right;" class="btn btn-success"><span class="material-symbols-outlined">add_circle</span></a>

                </div>

              </div>
            </div>
            <div class="card-body">
              <div class="col-md-12" style=" margin: 0 auto; width: 100%; overflow: scroll;">
                <center><table class="table table-striped ">
                  <thead>
                    <tr>
                      <th style="width: 200px;">S.No</th>
                      <th style="width: 200px;">Date</th>
                      <th style="width: 200px;">Lead Name</th>
                      <th style="width: 200px;">Contact No</th>
                      <th style="width: 200px;">Email</th>
                      <th style="width: 200px;">Lead Status</th>
                      <th style="width: 200px;">Lead Source</th>
                      <th style="width: 200px;">Lead Micro Source</th>
                      <th style="width: 200px;">Team Manager</th>
                      <th style="width: 200px;">Team Leader</th>
                      <th style="width: 200px;">Telecaller</th>
                      <th style="width: 200px;">Action</th>
                    </tr>

                  </thead>
                  <tbody>

                  <?php
include "dbconfig.php";
$link = opencon();

if (isset($_POST['btn'])) {
    if(isset($_POST['from']) && (isset($_POST['to']))){
        $from = $_POST['from'];
        $to = $_POST['to'];
        $count = 1;
        $query = "SELECT * FROM new_lead WHERE Date BETWEEN '$from' AND '$to' ";
        echo $query;
        $result = mysqli_query($link,$query);
        while($fetch_qr = mysqli_fetch_array($result)){
            echo "<tr>
                  <td>" . $count . "</td>
                  <td>" . $fetch_qr['Date'] . "</td>
                  <td>" . $fetch_qr['Name'] . "</td>
                  <td>" . $fetch_qr['Contact_No'] . "</td>
                  <td>" . $fetch_qr['Email'] . "</td>
                  <td>" . $fetch_qr['Lead_Status'] . "</td>
                  <td>" . $fetch_qr['Lead_Source'] . "</td>
                  <td>" . $fetch_qr['Lead_Micro_Source'] . "</td>
                  <td>" . $fetch_qr['Team_Manager'] . "</td>
                  <td>" . $fetch_qr['Team_Leader'] . "</td>
                  <td>" . $fetch_qr['Telecaller'] . "</td>
                  <td class=\"\">
                    <a href=\"lead_edit.php?id='" . $fetch_qr['id'] . "'\"><span class=\"material-symbols-outlined\" style=\"float:left;\">edit</span></a>
                    <a onclick=\"return confirm('Are You Want to Delete this Item ?..')\" style=\"font-size: 23px; color: red;\" href=\"lead_delete.php?id=" . $fetch_qr['id'] . "\"><span class=\"material-symbols-outlined\" style=\"color: red;\">delete</span></a>
                  </td>
                </tr>";
    
        }
        $count = $count + 1;

    }
    
}else{
    $count = 1;
    $query="SELECT * FROM new_lead";
    $result = mysqli_query($link, $query);

    while ($row = mysqli_fetch_array($result)) {
        echo "<tr>
                  <td>" . $count . "</td>
                  <td>" . $row['Date'] . "</td>
                  <td>" . $row['Name'] . "</td>
                  <td>" . $row['Contact_No'] . "</td>
                  <td>" . $row['Email'] . "</td>
                  <td>" . $row['Lead_Status'] . "</td>
                  <td>" . $row['Lead_Source'] . "</td>
                  <td>" . $row['Lead_Micro_Source'] . "</td>
                  <td>" . $row['Team_Manager'] . "</td>
                  <td>" . $row['Team_Leader'] . "</td>
                  <td>" . $row['Telecaller'] . "</td>
                  <td class=\"\">
                    <a href=\"lead_edit.php?id='" . $row['id'] . "'\"><span class=\"material-symbols-outlined\" style=\"float:left;\">edit</span></a>
                    <a onclick=\"return confirm('Are You Want to Delete this Item ?..')\" style=\"font-size: 23px; color: red;\" href=\"lead_delete.php?id=" . $row['id'] . "\"><span class=\"material-symbols-outlined\" style=\"color: red;\">delete</span></a>
                  </td>
                </tr>";
        $count = $count + 1;
    }
    
    
}
?>


                  </tbody>
                </table></center>
              </div>
            </div>
          </div>
          </div>
        </div>
      </div>
            

            
          </div>

</div>
<!-- Main Working Space End -->
<!-- Changing dropdown Start -->
<script type="text/javascript">
    function configureDropDownLists(ddl1,ddl2) {
    var BAKIYALAKSHMI = ['PRADEEPRAJA', 'RAMAPRABA.G','YOKESH.M','SURUTHIKA'];
    var VIJAYAKUMARI = ['ANI JOLLA', 'MANIVEL.S','POONGODI M'];
    var bleads = ['select', 'NA'];
    // var names = ['John', 'David', 'Sarah'];

    switch (ddl1.value) {
        case 'BAKIYALAKSHMI':
            ddl2.options.length = 0;
            for (i = 0; i < BAKIYALAKSHMI.length; i++) {
                createOption(ddl2, BAKIYALAKSHMI[i], BAKIYALAKSHMI[i]);
            }
            break;
        case 'VIJAYAKUMARI':
            ddl2.options.length = 0; 
            for (i = 0; i < VIJAYAKUMARI.length; i++) {
            createOption(ddl2, VIJAYAKUMARI[i], VIJAYAKUMARI[i]);
            }
            break;
        case 'bleads':
            ddl2.options.length = 0; 
            for (i = 0; i < bleads.length; i++) {
            createOption(ddl2, bleads[i], bleads[i]);
            }
            break;
        // case 'direct':
        //     ddl2.options.length = 0; 
        //     for (i = 0; i < direct.length; i++) {
        //     createOption(ddl2, direct[i], direct[i]);
        //     }
        //     break;
    //     case 'Names':
    //         ddl2.options.length = 0;
    //         for (i = 0; i < names.length; i++) {
    //             createOption(ddl2, names[i], names[i]);
    //         }
    //         break;
    //         default:
    //             ddl2.options.length = 0;
    //         break;
    }

}

    function createOption(ddl, text, value) {
        var opt = document.createElement('option');
        opt.value = value;
        opt.text = text;
        ddl.options.add(opt);
    }
</script>
    <!-- Changing dropdown END -->


<script>
  $(document).ready(function(){
    $("#lead_status").click(function(){
      var a1=$(this).val();
      $('table tbody tr').hide();
      var len =$('table tbody tr:not(.notfound) td:nth-child(6):contains("'+a1+'")').length;
      if(len>0){
        $('table tbody tr:not(.notfound) td:contains("'+a1+'")').each(function(){
          $(this).closest('tr').show();
        });
      }else{
        $('.notfound').show();
      }
      // alert("working");
    });
  });
</script>
<script>
  $(document).ready(function(){
    $("#manager").click(function(){
      var a1=$(this).val();
      $('table tbody tr').hide();
      var len =$('table tbody tr:not(.notfound) td:nth-child(9):contains("'+a1+'")').length;
      if(len>0){
        $('table tbody tr:not(.notfound) td:contains("'+a1+'")').each(function(){
          $(this).closest('tr').show();
        });
      }else{
        $('.notfound').show();
      }
      // alert("working");
    });
  });
</script>
<script>
  $(document).ready(function(){
    $("#ddl1").click(function(){
      var a1=$(this).val();
      $('table tbody tr').hide();
      var len =$('table tbody tr:not(.notfound) td:nth-child(10):contains("'+a1+'")').length;
      if(len>0){
        $('table tbody tr:not(.notfound) td:contains("'+a1+'")').each(function(){
          $(this).closest('tr').show();
        });
      }else{
        $('.notfound').show();
      }
      // alert("working");
    });
  });
</script>
<script>
  $(document).ready(function(){
    $("#ddl2").click(function(){
      var a1=$(this).val();
      $('table tbody tr').hide();
      var len =$('table tbody tr:not(.notfound) td:nth-child(11):contains("'+a1+'")').length;
      if(len>0){
        $('table tbody tr:not(.notfound) td:contains("'+a1+'")').each(function(){
          $(this).closest('tr').show();
        });
      }else{
        $('.notfound').show();
      }
      // alert("working");
    });
  });
</script>
<script>
  $(document).ready(function(){
    $("#search1").click(function(){
      var a1=$(this).val();
      $('table tbody tr').hide();
      var len =$('table tbody tr:not(.notfound) td:nth-child(2):contains("'+a1+'")').length;
      if(len>0){
        $('table tbody tr:not(.notfound) td:contains("'+a1+'")').each(function(){
          $(this).closest('tr').show();
        });
      }else{
        $('.notfound').show();
      }
      // alert("working");
    });
  });
</script>
        <!-- LIVE SEARCH END -->


<?php
include "footer.php";
?>