<?php

include "../../pidbco/pidbjoin.php";
include "../ses_write.php";

if(!isset($_SESSION))
{
    session_start();
}


if(isset($_POST['btn_search_tele_data']))
{
    $s_state = strip_tags(trim($_POST['s_state']));
    $s_district = strip_tags(trim($_POST['s_district']));
    $s_loc = strip_tags(trim($_POST['s_loc']));
    $date = strip_tags(trim($_POST['date']));
    $s_status = strip_tags(trim($_POST['s_status']));
	$bdocall = strip_tags(trim($_POST['bdocall']));

    if ($s_state != '') {
        $where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "state = '$s_state'";
    }

    if ($s_district != '') {
        $where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "district= '$s_district'";
    }

    if ($s_loc != '') {
        $where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "location= '$s_loc'";
    }
    if ($date != '') {
        $where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "entered_date= '$date'";
    }
    if ($s_status != '') {
        $where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "status= '$s_status'";
    }
	if($bdocall != ''){
		$where .= ($where == '') ? ' WHERE ' : ' AND ';
        $where .= "bdo= '$bdocall'";
	}

    $qry = mysqli_query($con,'SELECT * FROM tele_calls_det ' . $where);
    $num = mysqli_num_rows($qry);
    if($num > 0)
    {
    ?>
    <div class="dataTables_wrapper">
    <table class="table table-striped table-bordered table-hover table-responsive" id="dataTables-example">
    <thead>
    <tr>
        <th>#</th>
        <th>Date</th>
        <th>Tele Caller</th>
        <th>Company</th>
        <th class="hidden-xs">Person</th>
        <th class="hidden-xs">Phone</th>
        <th class="hidden-xs">Last Follow Up</th>
        <th>Status</th>
    </tr>
    </thead>
    <tbody>
        <?php

        while($res = mysqli_fetch_object($qry))
        {
                   $fw = $res->follow_up;
                   list($year,$month,$day) = explode('-', $fw);

                   $en = $res->entered_date;
                   list($eyear,$emonth,$eday) = explode('-', $en);

                   $id_bdo = $res->bdo;
                   $stmt11 = mysqli_query($con,"SELECT id,emp_name FROM employee_registration WHERE id='$id_bdo'");
                   $stmt11_res = mysqli_fetch_object($stmt11);


                   ?>
                   <tr  <?php if($res->status == 4 && $res->executive_status == 2){ ?> class="odd gradeX danger" <?php }else{?> class="odd gradeX" <?php } ?>  style="cursor: pointer;" title="Edit" >
                       <td>
                           <?php
                           if($res->status == 2)
                           {
                               ?>
                               <input type="checkbox" class="checkbox"  id="<?php echo $res->id; ?>" style="cursor: pointer;" />
                           <?php
                           }
                           elseif($res->cust_or_not == 1)
                           {
                               ?>
                               <input disabled type="checkbox" class="checkbox"  id="<?php  ?>" style="cursor: pointer;" />
                           <?php
                           }
                           else
                           {
                               ?>
                               <input disabled type="checkbox" class="checkbox"  id="<?php  ?>" style="cursor: pointer;" />
                           <?php
                           }
                           ?>
                       </td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" ><?php echo $eday.'-'.$emonth.'-'.$eyear; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" ><?php echo $stmt11_res->emp_name; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" ><?php echo $res->comp_name; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" class="hidden-xs"><?php echo $res->person_name; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" class="hidden-xs"><?php echo $res->phone; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" class="hidden-xs"><?php echo $day.'-'.$month.'-'.$year; ?></td>
                       <td onclick="edt_tele_call(<?php echo $res->id; ?>);mylinkfunction();" class="center"><?php if($res->status == 1){ echo 'Interested'; }elseif($res->status == 2){ echo 'Not-Interested'; }elseif($res->status == 3){ echo 'Future'; }elseif($res->status == 4){ echo 'Visit Scheduled'; } ?></td>
                   </tr>
                   <?php
                   //$i++;
               }
               ?>
               </tbody>
           </table>
       </div>
   <?php
    }
    else
    {
     ?><h4>No Data Found..!</h4><?php
    }
}

?>