<script type="text/javascript">
    $(document).ready(function () {
        $('#next_follow_up').daterangepicker({
            singleDatePicker: true,
            calender_style: "picker_4"
        }, function (start, end, label) {
            console.log(start.toISOString(), end.toISOString(), label);
        });
    });
</script>
<script>
    $(document).ready(function () {
        $(".country").select2({
            placeholder: "Select a Country",
            allowClear: true
        });
        $(".state").select2({
            placeholder: "Select a State",
            allowClear: true
        });
        $(".district").select2({
            placeholder: "Select a district",
            allowClear: true
        });
        $(".bdo").select2({
            placeholder: "Select a Telecaller (BDO)",
            allowClear: true
        });
    });
</script>
<!-- /select2 -->
<?php
include "../../pidbco/pidbjoin.php";
include "../ses_write.php";

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

//fetching Client IP address
function get_client_ip()
{
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
        $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
$ip=get_client_ip();

if(isset($_POST['btn_edt_tele_data']))
{
    $id = strip_tags(trim($_POST['id']));
    $stmt = $con->prepare("SELECT id, entered_date, comp_name, person_name, phone, phone2, country, state, district, location, bdo, email, status, follow_up,source FROM tele_calls_det WHERE id = ?");
    $stmt -> bind_param("i",$id);
    $stmt -> execute();
    $stmt -> store_result();
    $stmt -> bind_result($id, $entered_date, $comp_name, $person_name, $phone, $phone2, $country, $state, $district, $location, $bdo, $email, $status, $follow_up,$source);
    $all_posts = Array();
    while($stmt->fetch())
    {
        $individual_post = Array(
        'id' => $id,
        'entered_date' => $entered_date,
        'comp_name' => $comp_name,
        'person_name' => $person_name,
        'phone' => $phone,
        'phone2' => $phone2,
        'country'   => $country,
        'state'   => $state,
        'district'   => $district,
        'location'   => $location,
        'bdo'   => $bdo,
        'email'   => $email,
        'status' => $status,
        'follow_up' => $follow_up,
        'source'    =>  $source
        
        );
        array_push($all_posts, $individual_post);
    }
    $stmt->close();

?>
    <?php
    $bdo1 = mysqli_query($con,"SELECT id,emp_name FROM employee_registration WHERE id='{$individual_post['bdo']}'");
    $bdo1_fet = mysqli_fetch_array($bdo1);

    $tele_id = $individual_post['id'];
    $rep = mysqli_query($con,"SELECT id, telecall_id, tele_bdo_id, entered_date, report FROM tele_reports WHERE telecall_id = '$tele_id' ORDER BY id DESC LIMIT 0,1");
    $rep_res = mysqli_fetch_object($rep);

    ?>
<br />

<form id="frm_1" name="frm_1" data-parsley-validate class="form-horizontal form-label-left">

    <div class="form-group">
        <div class="col-md-3 col-sm-3 col-xs-12">
            <input id="phone" class="form-control col-md-7 col-xs-12" value="<?php echo $individual_post['phone']; ?>" placeholder="Enter Mobile *" required="required"  type="number" min="0" name="phone" >
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <input id="phone2" class="form-control col-md-7 col-xs-12" value="<?php echo $individual_post['phone2']; ?>" placeholder="Enter Second Mobile Number"  type="number" min="0" name="phone" >
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <input type="text" id="person" name="person" required="required" value="<?php echo $individual_post['person_name']; ?>" placeholder="Enter Person Name*" class="form-control col-md-7 col-xs-12">
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <input type="text" id="company" name="company" required="required" value="<?php echo $individual_post['comp_name']; ?>" placeholder="Enter Company Name*" class="form-control col-md-7 col-xs-12">
            <input type="hidden" id="cid" name="cid" value="<?php echo base64_encode($id); ?>">
        </div>

    </div>

    <div class="form-group">
        <div class="col-md-3 col-sm-3 col-xs-12">
            <!--<input id="country" class="form-control col-md-7 col-xs-12" placeholder="Enter Country"  type="text" name="country" >-->
            <select class="country form-control " id="country" tabindex="-1">
                <option value="<?php echo $individual_post['country']; ?>"><?php echo $individual_post['country']; ?></option>
                <?php
                $stmt01 = mysqli_query($con,"SELECT * FROM `countries` ORDER BY id ASC");
                while($res01 = mysqli_fetch_object($stmt01))
                {
                    ?>
                    <option value="<?php echo $res01->country_name; ?>"><?php echo $res01->country_name; ?></option>
                <?php
                }
                ?>
            </select>
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <!--<input id="state" class="form-control col-md-7 col-xs-12" placeholder="Enter State"  type="text" name="state">-->
            <select class="state form-control" id="state" tabindex="-1">
                <option value="<?php echo $individual_post['state']; ?>"><?php echo $individual_post['state']; ?></option>
                <?php
                $stmt01 = mysqli_query($con,"SELECT * FROM `states` ");
                while($res01 = mysqli_fetch_object($stmt01))
                {
                    ?>
                    <option value="<?php echo $res01->state_name; ?>"><?php echo $res01->state_name; ?></option>
                <?php
                }
                ?>
            </select>
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <!-- <input id="dist" class="form-control col-md-7 col-xs-12" placeholder="Enter District"  type="text" name="dist">-->
            <select class="district form-control" id="district" tabindex="-1">
                <option value="<?php echo $individual_post['cities_name']; ?>"><?php echo $individual_post['cities_name']; ?></option>
                <?php
                $stmt01 = mysqli_query($con,"SELECT * FROM `cities` ");
                while($res01 = mysqli_fetch_object($stmt01))
                {
                    ?>
                    <option value="<?php echo $res01->cities_name; ?>"><?php echo $res01->cities_name; ?></option>
                <?php
                }
                ?>
            </select>
        </div>
        <div class="col-md-3 col-sm-3 col-xs-12">
            <input id="loc" class="form-control col-md-7 col-xs-12" value="<?php echo $individual_post['location']; ?>" placeholder="Enter Location*" required="required" type="text" name="loc" >
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-3 col-sm-3 col-xs-12">
            <select class="bdo form-control col-md-7 col-xs-12" id="bdo" required="required" name="bdo">

                <option value="<?php echo $bdo1_fet['id']; ?>"><?php echo $bdo1_fet['emp_name']; ?></option>
                <?php
                $emp = mysqli_query($con,"SELECT id,emp_name FROM employee_registration");
                while($emp_list = mysqli_fetch_object($emp))
                {
                    ?>
                    <option value="<?php echo $emp_list->id; ?>"><?php echo $emp_list->emp_name; ?></option>
                <?php
                }
                ?>
            </select>
        </div>

        <div class="col-md-3 col-sm-3 col-xs-12">
            <input id="email" class="form-control col-md-7 col-xs-12" value="<?php echo $individual_post['email']; ?>" placeholder="Enter Email"  type="email" name="email" >
        </div>

        <div class="col-md-2 col-sm-2 col-xs-12">
            <select id="status" class="form-control col-md-7 col-xs-12" name="status"  required="required">
                <?php
                if($individual_post['status'] == 1)
                {
                    ?>
                    <option value="1">Interested</option>
                    <option value="2">Not-Interested</option>
                    <option value="3">Future</option>
                    <option value="4">Visit Scheduled</option>
                <?php
                }
                elseif($individual_post['status'] == 2)
                {
                    ?>
                    <option value="2">Not-Interested</option>
                    <option value="1">Interested</option>
                    <option value="3">Future</option>
                    <option value="4">Visit Scheduled</option>
                <?php
                }
                elseif($individual_post['status'] == 3)
                {
                    ?>
                    <option value="3">Future</option>
                    <option value="1">Interested</option>
                    <option value="2">Not-Interested</option>
                    <option value="4">Visit Scheduled</option>
                <?php
                }
                elseif($individual_post['status'] == 4)
                {
                    ?>
                    <option value="4">Visit Scheduled</option>
                    <option value="1">Interested</option>
                    <option value="2">Not-Interested</option>
                    <option value="3">Future</option>
                <?php
                }
                else
                {
                 ?>
                    <option value="">Select Status*</option>
                    <option value="1">Interested</option>
                    <option value="2">Not-Interested</option>
                    <option value="3">Future</option>
                    <option value="4">Visit Scheduled</option>
                <?php
                }
                ?>
            </select>
        </div>

        <div class="col-md-2 col-sm-2 col-xs-12">
            <input id="next_follow_up" class="date-picker form-control col-md-7 col-xs-12" value="<?php echo $individual_post['follow_up']; ?>" placeholder="Enter Followup Date"  type="text">
        </div>
        <div class="col-md-2 col-sm-2 col-xs-12">
            <select id="source" name="source" class="form-control">
                <?php
                if(!empty($individual_post['source']) && $individual_post['source'] == 1)
                {
                ?>
                    <option value="1">NewsPaper</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 2)
                {
                    ?>
                    <option value="2">E-Directory</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 3)
                {
                    ?>
                    <option value="3">Magazine</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 4)
                {
                    ?>
                    <option value="4">Staff</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 5)
                {
                    ?>
                    <option value="5">Referred</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 6)
                {
                    ?>
                    <option value="6">Marketing</option>
                <?php
                }
                elseif(!empty($individual_post['source']) && $individual_post['source'] == 7)
                {
                    ?>
                    <option value="7">Other</option>
                <?php
                }
                ?>
                <option value="1">NewsPaper</option>
                <option value="2">E-Directory</option>
                <option value="3">Magazine</option>
                <option value="4">Staff</option>
                <option value="5">Referred</option>
                <option value="6">Marketing</option>
                <option value="7">Other</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-11 col-sm-11 col-xs-12">
            <textarea id="report" class="form-control col-md-12 col-xs-12"  placeholder="Enter Report*" required="required" name="report" ><?php echo $rep_res->report; ?></textarea>
        </div>
        <br>
        <div class="col-md-1 col-sm-1 col-xs-12 " id="btn_data">
            <a class="btn btn-default hidden-xs hidden-sm hidden-md" data-toggle="modal" data-target=".bs-example-modal-lg<?php echo $id; ?>" title="View"><i class="glyphicon glyphicon-list-alt"></i><span class="small"> View</span></a>
            <button type="button" name="save" onclick="upd_tele_data();" class="btn btn-primary">Update</button>
        </div>
    </div>
</form>
    <!-- Large modal Popup -->
    <div class="modal fade bs-example-modal-lg<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"  aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <div><h4 class="modal-title" id="myLargeModalLabel">TeleCall Details </h4></div>
            </div>
            <div class="modal-body">
                <?php
                    $fw = $individual_post['follow_up'];
                    list($year,$month,$day) = explode('-', $fw);

                ?>
                <span>Last Follow  Up On</span><span style="margin-left: 10px;"><?php echo $day.'-'.$month.'-'.$year; ?></span>
                <?php

                    $rep = mysqli_query($con,"SELECT * FROM `tele_reports` WHERE `telecall_id` = '{$individual_post['id']}'");

                while($rep_fet = mysqli_fetch_object($rep))
                {
                    $ed = $rep_fet->entered_date;
                    list($eyear,$emonth,$eday) = explode('-', $ed);

                    $bdo = $rep_fet->tele_bdo_id;
                    $qry = mysqli_query($con,"SELECT `id`, `emp_name` FROM `employee_registration` WHERE id='$bdo'");
                    $qry_02 = mysqli_fetch_object($qry);
                ?>
                   <div class="well">
                       <p><span>Report On</span><span style="margin-left: 10px;font-weight: bold;font-style: italic;"><?php echo $eday.'-'.$emonth.'-'.$eyear; ?></span>,</p>
                       <p><span>By</span><span style="margin-left: 10px;font-weight: bold;font-style: italic;"><?php echo $qry_02->emp_name; ?></span>,</p>
                       <p><?php echo $rep_fet->report; ?></p>
                       <p class="text-right text-muted "></p>
                   </div>
                <?php
                }
                ?>

                <?php
                /*
                ?><div class="row">
                <div class="col-lg-12 ">
                    <div class="col-lg-6">
                        <div class="row" style="height: 5px;">
                        </div>
                        <div class="row bg-primary" style="height: 35px;line-height: 35px;">
                            &nbsp;&nbsp;<label>Head</label>
                        </div>
                        <div class="row" style="height: 5px;">
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Register Number</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Registered Date</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Company Name</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Person Name</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Mob1</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Mob2</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>country</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>State</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>District</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Location</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>BDO</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Email</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Status</label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Follow Up Date</label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>Report</label>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="row" style="height: 5px;">
                        </div>
                        <div class="row bg-primary" style="height: 35px;line-height: 35px;">
                            &nbsp;&nbsp;<label>Details</label>
                        </div>
                        <div class="row" style="height: 5px;">
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $id; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;
                            <label>
                                <?php
                                $dt = $individual_post['entered_date'];
                                list($year,$month,$day) = explode('-',$dt);
                                echo $day.' - '.$month.' - '.$year;
                                ?>
                            </label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['comp_name']; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['person_name']; ?></label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['phone']; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['phone2']; ?></label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['country']; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['state']; ?></label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['district']; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['location']; ?></label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $bdo1_fet['emp_name']; ?></label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $individual_post['email']; ?></label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>
                                <?php
                                if($individual_post['status'] == 1)
                                {
                                   echo "Interested";
                                }
                                elseif($individual_post['status'] == 2)
                                {
                                    echo "Not-Interested";
                                }
                                elseif($individual_post['status'] == 3)
                                {
                                    echo "Future";
                                }
                                elseif($individual_post['status'] == 4)
                                {
                                    echo "Visit Scheduled";
                                }
                                ?>
                            </label>
                        </div>
                        <div class="row" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label>
                                <?php
                                $fw_dt = $individual_post['follow_up'];
                                list($year,$month,$day) = explode('-',$fw_dt);
                                echo $day.' - '.$month.' - '.$year;
                                ?>
                            </label>
                        </div>
                        <div class="row bg-info" style="height: 25px;line-height: 25px;">
                            &nbsp;&nbsp;<label><?php echo $rep_res->report; ?></label>
                        </div>
                    </div>
                </div>
                </div><?php
                */
                ?>


            </div>
            </div>
        </div>
    </div>
<?php
    exit();
}
?>

<script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>