<?php 
include('session.php');
include('complaint_scope.php');
$sql = "SELECT * FROM admin WHERE id = '".$_SESSION['admin']."'";
	$query = $conn->query($sql);
	$admin = $query->fetch_assoc();
$complaintScope = complaint_department_scope($admin);
$isDepartmentComplaintUser = $complaintScope['enabled'];
$complaintJoinScope = $complaintScope['building_where'];
$complaintPlainScope = $complaintScope['plain_where'];
if(isset($_POST['submit'])) { 
 $insert = $conn->query("UPDATE users_complaint SET department='".$_POST['dept_id']."', engineer='0' WHERE ucid='".$_POST['ucid']."'"); 
 $conn->query("INSERT INTO complaint_assignment_ofc (cid, did, date) VALUES ('".$_POST['ucid']."', '".$_POST['dept_id']."', '".date('Y-m-d H:i:s')."')");
 echo '<script>alert("Department assigned Successfully.");window.location.href="dashboard.php"</script>';
}
if(isset($_POST['submiteng'])) {
 $insert = $conn->query("UPDATE users_complaint SET engineer='".$_POST['engineer_id']."', department='".$_POST['did']."', c_status='1' WHERE ucid='".$_POST['ucid']."'");  
 $conn->query("INSERT INTO complaint_assignment (cid, eid, did, date) VALUES ('".$_POST['ucid']."', '".$_POST['engineer_id']."','".$_POST['did']."', '".date('Y-m-d H:i:s')."')");
 echo '<script>alert("Engineer assigned Successfully.");window.location.href="dashboard.php"</script>';
}
if(isset($_POST['sendsms'])) {
    $ofcids = $_POST['ofcid'];
    foreach($ofcids as $ofcid) {
        $officerdata=$conn->query("SELECT * FROM admin WHERE id='".$ofcid."'")->fetch_assoc();
        $User=$officerdata['name'];
    	$apiKey = urlencode('NjY2MjczNTI1NTMxNTA0ODcyNDI0NzY1Mzg2MTZjNzI=');
    	$username = $officerdata['mobile'];
    	$numbers = urlencode('91'.$username);
    	$sender = urlencode('MEDVER');
    	$message = rawurlencode("Dear user,\n" .
                "\n" .
                "Your OTP for login to Mediveri is 123456 . Please do not share this OTP.\n" .
                "\n" .
                "Regards,\n" .
                "Mediveri Health care");
     	$data = 'apikey=' . $apiKey . '&numbers=' . $numbers . "&sender=" . $sender . "&message=" . $message;
    	$ch = curl_init('https://api.textlocal.in/send/?' . $data);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	$response = curl_exec($ch);
    	curl_close($ch);
    }
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | COMPLAINTS LIST</title>
    <?php include('includes/head.php'); ?>
    <style>
        th,td { text-align:center; }
        input, select {height:32px;}
        .modal-body b {line-height:1.9;}
        #ofcersul input {height:12px;}
        @media print 
{
	input[type=checkbox], .select-item 
	{ 
		display: none; 
	}
		input[type=checkbox]:checked ~ td 
	{ 
		display: block; 
	}
}
    </style>
  </head>
  <body>
    <div class="container-scroller">
      <div class="horizontal-menu">
        <?php include('includes/header.php'); ?>
      </div>
      <div class="container-fluid page-body-wrapper">
        <div class="main-panel">
          <div class="content-wrapper">
                    <form class="forms-sample grid-margin" method="POST" id="Filterform">
                        <div class="row">
                          <div class="col-lg-3">
                            <label for="Complno">Complaint/Mobile No./Building Name</label>
                            <input type="text" style="padding: 1.39rem 1.375rem;" class="form-control" name="compno" id="Complno" value="<?php if(isset($_POST['compno'])) { echo $_POST['compno'] != "" ? $_POST['compno'] : ""; } ?>">
                          </div>
                          <div class="col-lg-2">
                            <label for="subdivision">Subdivision</label>
                            <select class="form-control" name="subdivision" id="subdivision">
                              <option value="">Select</option>
                                <?php  $subdiv = $conn->query("SELECT * FROM subdivision WHERE isDeleted='0'");
                                while($fetchsubdiv = $subdiv->fetch_assoc()) {
                                ?>
                              <option value="<?php echo $fetchsubdiv['id']; ?>" <?php if(isset($_POST['subdivision'])) { echo $_POST['subdivision'] == $fetchsubdiv['id'] ? "selected" : ""; } ?>><?php echo $fetchsubdiv['value']; ?></option>
                              <?php }  ?>
                              <option value="0">All Subdivision</option>
                            </select>
                          </div>
                          <div class="col-lg-2">
                            <label for="qutno">Building/Quarter No.</label>
                            <select class="form-control" name="qutno" id="qutno">
                              <option value="">Select</option>
                                <?php 
                                $buildi = $conn->query("SELECT * FROM building_list WHERE isDeleted='0' ".$complaintScope['building_filter']);
                                while($fetchbuild = $buildi->fetch_assoc()) {
                                ?>
                              <option value="<?php echo $fetchbuild['bid']; ?>" <?php if(isset($_POST['qutno'])) { echo $_POST['qutno'] == $fetchbuild['bid'] ? "selected" : ""; } ?>><?php echo $fetchbuild['bNo']; ?></option>
                              <?php } ?>
                            </select>
                          </div>
                          <div class="col-lg-3">
                            <label for="engineer">Tradesman</label>
                            <select class="form-control" name="engineer" id="engineer">
                              <option value="">Select</option>
                                <?php 
                                if($isDepartmentComplaintUser) {
                                    $subdiv = $conn->query("SELECT * FROM engineers_list WHERE status='1' ".$complaintScope['engineer_filter']);
                                } else {
                                    $subdiv = $conn->query("SELECT * FROM engineers_list WHERE status='1'");
                                }
                                while($fetchsubdiv = $subdiv->fetch_assoc()) {
                                $ftchdep = $conn->query("SELECT * FROM admin WHERE type='dept' AND id='".$fetchsubdiv['dept_id']."'")->fetch_assoc();
                                ?>
                              <option value="<?php echo $fetchsubdiv['id']; ?>" <?php if(isset($_POST['engineer'])) { echo $_POST['engineer'] == $fetchsubdiv['id'] ? "selected" : ""; } ?>><?php echo $fetchsubdiv['name'].' ('.$ftchdep['name'].' ,'.$ftchdep['designation'].')'; ?></option>
                              <?php } ?>
                            </select>
                          </div>
                          <div class="col-lg-2">
                            <label for="c_status">Status</label>
                            <select class="form-control" name="c_status" id="c_status">
                              <option value="">Select</option>
                              <option value="0" <?php if(isset($_POST['c_status'])) { echo $_POST['c_status'] == "0" ? "selected" : ""; } ?>>New Complaint Received</option>
                              <option value="1" <?php if(isset($_POST['c_status'])) { echo $_POST['c_status'] == "1" ? "selected" : ""; } ?>>Assigned</option>
                              <option value="2" <?php if(isset($_POST['c_status'])) { echo $_POST['c_status'] == "2" ? "selected" : ""; } ?>>Completed</option>
                              <option value="3" <?php if(isset($_POST['c_status'])) { echo $_POST['c_status'] == "3" ? "selected" : ""; } ?>>Cancelled</option>
                            </select>
                          </div>
                          <div class="col-lg-4 pt-3">
                          <button type="submit" name="setfilters" class="btn btn-sm btn-primary me-2">SUBMIT</button>
                          <button class="btn btn-sm btn-light" type="button" id="resetbtn">RESET</button>
                          </div>
                        </div>
                    </form>
                    <?php $tomdate = date('d/m/Y',strtotime("-1 days"));
                    if(isset($_POST['setfilters'])) {
                                $compno = mysqli_real_escape_string($conn, $_POST['compno']);
                                $subdivision = $_POST['subdivision'];
                                //$section = $_POST['section'];
                                $qutno = mysqli_real_escape_string($conn, $_POST['qutno']);
                                $engineer = $_POST['engineer'];
                                $c_status = $_POST['c_status'];
                                if($isDepartmentComplaintUser) {
                                $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope; 
                                $tcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope;
                                $pcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='0'";
                                $ccomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='1'";
                                $acomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='2'";
                                $icomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='3'";
                                $inqcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='4'";
                                } else {
                                $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE users_complaint.ucid <> 0"; 
                                $tcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE users_complaint.ucid <> 0";
                                $pcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  c_status='0'";
                                $ccomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  c_status='1'";
                                $acomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  c_status='2'";
                                $icomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  c_status='3'";
                                $inqcomplaintsquery = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE c_status='4'";
                                }
                                if(!empty($compno)){
                                    $phone = $compno;
                                    $compno = $compno;//substr($compno, 6);
                                    $tcomplaints1 .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."' or building_list.bName like '%".$phone."%')";
                                    $tcomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."'  or building_list.bName like '%".$phone."%')";
                                    $pcomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."'  or building_list.bName like '%".$phone."%')";
                                    $ccomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."'  or building_list.bName like '%".$phone."%')";
                                    $acomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."' or building_list.bName like '%".$phone."%')";
                                    $icomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."' or building_list.bName like '%".$phone."%')";
                                    $inqcomplaintsquery .= " and (users_complaint.docketNumber = '".$compno."' OR users.phone = '".$phone."' or building_list.bName like '%".$phone."%')";
                                }
                                if(!empty($subdivision)){
                                    $tcomplaints1 .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $tcomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $pcomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $ccomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $acomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $icomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                    $inqcomplaintsquery .= " and users_complaint.subdivision = '".$subdivision."'";
                                }
                                if(!empty($qutno)){
                                    $tcomplaints1 .= " and building_list.bid = '".$qutno."'";
                                    $tcomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                    $pcomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                    $ccomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                    $acomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                    $icomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                    $inqcomplaintsquery .= " and building_list.bid = '".$qutno."'";
                                }
                                if(!empty($engineer)){
                                    $tcomplaints1 .= " and users_complaint.engineer = '".$engineer."'";
                                    $tcomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                    $pcomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                    $ccomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                    $acomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                    $icomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                    $inqcomplaintsquery .= " and users_complaint.engineer = '".$engineer."'";
                                }
                                if(!empty($c_status)){
                                    $tcomplaints1 .= " and users_complaint.c_status = '".$c_status."'";
                                    $tcomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                    $pcomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                    $ccomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                    $acomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                    $icomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                    $inqcomplaintsquery .= " and users_complaint.c_status = '".$c_status."'";
                                }
                                $tcomplaintsquery .= " AND date = '".date('d/m/Y')."'";
                                $pcomplaintsquery .= " AND date = '".date('d/m/Y')."'";
                                $ccomplaintsquery .= " AND date = '".date('d/m/Y')."'";
                                $acomplaintsquery .= " AND date = '".date('d/m/Y')."'";
                                $icomplaintsquery .= " AND date = '".date('d/m/Y')."'";
                                $inqcomplaintsquery .= " AND date = '".$tomdate."'";
                                $tcomplaints = $conn->query("$tcomplaintsquery")->num_rows; //pending complaint
                                $pcomplaints = $conn->query("$pcomplaintsquery")->num_rows; //pending complaint
                                $ccomplaints = $conn->query("$ccomplaintsquery")->num_rows; //confirmed complaint
                                $acomplaints = $conn->query("$acomplaintsquery")->num_rows; //complete complaint
                                $icomplaints = $conn->query("$icomplaintsquery")->num_rows;
                                $inqcomplaints = $conn->query("$inqcomplaintsquery")->num_rows;
                            } else {
                                if($isDepartmentComplaintUser) {
                                    if(isset($_GET['st'])) {
                                        $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope." AND c_status='".$_GET['st']."'"; 
                                    } else {
                                        $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  ".$complaintJoinScope; 
                                    }
                                } else {
                                    if(isset($_GET['st'])) {
                                        $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE  c_status='".$_GET['st']."'"; 
                                    } else {
                                        $tcomplaints1 = "SELECT *, users_complaint.priority as proaarav, users_complaint.details as compdetails FROM users inner join users_complaint on users.uid=users_complaint.uid inner join complaint_list ON users_complaint.c_list=complaint_list.cid  inner join building_list on users_complaint.b_list=building_list.bid WHERE users_complaint.ucid <> 0"; 
                                    }
                                }
                                if($_SESSION['admintype'] == 'admin') {
                                    $tcomplaints = $conn->query("SELECT * FROM users_complaint WHERE ucid <> '0' AND date = '".date('d/m/Y')."'")->num_rows; //pending complaint
                                    $pcomplaints = $conn->query("SELECT * FROM users_complaint WHERE c_status='0' AND date = '".date('d/m/Y')."'")->num_rows; //pending complaint
                                    $ccomplaints = $conn->query("SELECT * FROM users_complaint WHERE c_status='1' AND date = '".date('d/m/Y')."'")->num_rows; //confirmed complaint
                                    $acomplaints = $conn->query("SELECT * FROM users_complaint WHERE c_status='2' AND date = '".date('d/m/Y')."'")->num_rows; //complete complaint
                                    $icomplaints = $conn->query("SELECT * FROM users_complaint WHERE c_status='3' AND date = '".date('d/m/Y')."'")->num_rows; //cancelled complaint
                                    $inqcomplaints = $conn->query("SELECT * FROM users_complaint WHERE c_status='4' AND date = '".$tomdate."'")->num_rows; //inqueue complaint
                                    } else {
                                    $tcomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  ucid <> '0' AND date = '".date('d/m/Y')."'")->num_rows; //pending complaint
                                    $pcomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  c_status='0' AND date = '".date('d/m/Y')."'")->num_rows; //pending complaint
                                    $ccomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  c_status='1' AND date = '".date('d/m/Y')."'")->num_rows; //confirmed complaint
                                    $acomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  c_status='2' AND date = '".date('d/m/Y')."'")->num_rows; //complete complaint
                                    $icomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  c_status='3' AND date = '".date('d/m/Y')."'")->num_rows; //cancelled complaint
                                    $inqcomplaints = $conn->query("SELECT * FROM users_complaint WHERE ".$complaintPlainScope." AND  c_status='4' AND date = '".$tomdate."'")->num_rows; //cancelled complaint
                                    }
                            }
                            $tcomplaints1 .= " AND date = '".date('d/m/Y')."'";
                            //echo $tcomplaints1;
                    ?>
              <div class="row quick-action-toolbar">
              <div class="col-md-12 grid-margin">
                <div class="card">
                  <div class="d-md-flex row m-0 quick-action-btns justify-content-center" role="group" aria-label="Quick action buttons">
                    <div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-primary">
                      <a href="dashboard.php" class="btn px-0 text-white"> Total Complaints : <?php echo sprintf("%02d", $tcomplaints); ?></a>
                    </div>
                    <div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-success">
                      <a href="dashboard.php?st=2" class="btn px-0 text-white">Resolved Complaints : <?php echo sprintf("%02d", $acomplaints); ?></a>
                    </div>
                    <!--<div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-info">-->
                    <!--  <a href="dashboard.php?st=0" class="btn px-0 text-white">Pending Complaints : <?php //echo sprintf("%02d", $pcomplaints); ?></a>-->
                    <!--</div>-->
                    <div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-warning">
                      <a href="dashboard.php?st=1" class="btn px-0 text-white">In-Progress Complaints : <?php echo sprintf("%02d", $ccomplaints); ?></a>
                    </div>
                    <div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-danger">
                      <a href="dashboard.php?st=3" class="btn px-0 text-white">Cancelled Complaints : <?php echo sprintf("%02d", $icomplaints); ?></a>
                    </div>
                    <div class="col-sm-6 col-md-2 p-0 text-center btn-wrapper bg-info">
                      <a href="dashboard.php?st=4" class="btn px-0 text-white">In-Queue Complaints : <?php echo sprintf("%02d", $inqcomplaints); ?></a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="card grid-margin">
              <div class="card-body">
                <div class="row">
                  <div class="col-12">
                      <form action="printComplaint.php" method="POST">
                          <input type="submit" class="btn btn-primary" value="Print Slip" style="position: absolute;top: 0;right: 0;padding: 0px 30px;"/>
                    <div class="table-responsive">
                      <table class="table table-striped table-bordered" width="100%">
                        <thead>
                          <tr>
                            <th>Select <span><input type="checkbox"  class="select-all checkbox" name="select-all" /></span></th>
                            <th>Complaint No.</th>
                            <th>Date/Time of Complaint Received</th>
                            <th>Building/Mobile No.</th>
                            <th>Complaint Details<br>Subdivision</th>
                            <th>Complaint Description</th>
                            <th>Linked Images</th>
                            <th>Priority</th>
                            <?php if($isDepartmentComplaintUser) { ?>
                            <th>Assign to Tradesman</th> <?php } ?>
                            <th>Assign to Officer</th>
                            <th>Tradesman Engineer</th>
                            <th>Date/Time of Completion</th>
                            <th>Official Remarks</th>
                            <th>User Satisfaction</th>
                            <?php if($isDepartmentComplaintUser) { ?>
                            <th>Tradesman Assignment List</th>
                            <th>Officer Assignment List</th>
                            <?php } ?>
                            <th>Update Complaint</th>
                            <?php if(!$isDepartmentComplaintUser) { ?>
                            <th>Delete</th>
                            <th>SMS</th>
                            <?php } ?>
                          </tr>
                        </thead>
                        <tbody>
                            
                    <?php 
                            
                            $users_complaint = $conn->query($tcomplaints1);$bgclass='';
                            if($users_complaint->num_rows > 0) {
                            while($fetchusers_complaint = $users_complaint->fetch_assoc()) {
                                $building_list = $conn->query("SELECT * FROM building_list WHERE bid = '".$fetchusers_complaint['b_list']."'")->fetch_assoc();
                                $complaint_list = $conn->query("SELECT * FROM complaint_list WHERE cid = '".$fetchusers_complaint['c_list']."'")->fetch_assoc();
                                $subdivision_list = $conn->query("SELECT * FROM subdivision WHERE id = '".$fetchusers_complaint['subdivision']."'")->fetch_assoc();
                                $users = $conn->query("SELECT * FROM users WHERE uid = '".$fetchusers_complaint['uid']."'")->fetch_assoc();
                                $deptname=$engname='';
                                if($fetchusers_complaint['department'] != '0' || $fetchusers_complaint['department'] != 0 || !empty($fetchusers_complaint['department'])) {
                                    $departmentr1236 = $conn->query("SELECT * FROM admin WHERE id = '".$fetchusers_complaint['department']."'")->num_rows;
                                    if($departmentr1236 > 0) {
                                    $department = $conn->query("SELECT * FROM admin WHERE id = '".$fetchusers_complaint['department']."'")->fetch_assoc();
                                    $deptname = $department['name'].'('.$department['designation'].')';
                                    }
                                }
                                if($fetchusers_complaint['engineer'] != '0' || $fetchusers_complaint['engineer'] != 0 || !empty($fetchusers_complaint['engineer'])) {
                                    $engineer1236 = $conn->query("SELECT * FROM engineers_list WHERE id = '".$fetchusers_complaint['engineer']."'")->num_rows;
                                    if($engineer1236 > 0) {
                                    $engineer = $conn->query("SELECT * FROM engineers_list WHERE id = '".$fetchusers_complaint['engineer']."'")->fetch_assoc();
                                    $engname = $engineer['name'];
                                    }
                                }
                                if($fetchusers_complaint['c_status'] == '0') {
                                    $bgclass = 'bg-warning';
                                } else if($fetchusers_complaint['c_status'] == '1') {
                                    $bgclass = 'bg-warning';
                                } else if($fetchusers_complaint['c_status'] == '2') {
                                    $bgclass = 'bg-success';
                                } else if($fetchusers_complaint['c_status'] == '3') {
                                    $bgclass = 'bg-danger';
                                } else if($fetchusers_complaint['c_status'] == '4') {
                                    $bgclass = 'bg-info';
                                } else {
                                    $bgclass = 'bg-primary';
                                }
                                $imagesdata = $conn->query("SELECT * FROM users_complaint_images WHERE ucid='".$fetchusers_complaint['ucid']."'")->num_rows;
                            ?>
                              <tr class="<?php echo $fetchusers_complaint['ucid']; ?>">
                                <td><input type="checkbox" class="select-item checkbox record " name="records[]" value="<?php echo $fetchusers_complaint['ucid']; ?>" /></td>
                                <td class="<?php echo $bgclass; ?> text-white"><?php echo $fetchusers_complaint['docketNumber']; ?></td>
                                <td><?php $date =  $fetchusers_complaint['date'];
                                    $timestamp = strtotime($date);
                                    if ($timestamp === FALSE) {
                                      $timestamp = strtotime(str_replace('/', '-', $date));
                                    }
                                    echo $date;//date('d-m-y',$timestamp); ?>
                                    <br>(<?php echo date ( 'H:i:s' , strtotime($fetchusers_complaint['time']) ); ?>)</td>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignBModal<?php echo $fetchusers_complaint['ucid']; ?>"><?php echo $building_list['bNo'].'<br>'.$users['phone']; ?></a></td>
                                <td><?php echo $complaint_list['details']; ?><br><?php echo $subdivision_list['value']; ?></td>
                                <td><?php echo $fetchusers_complaint['compdetails']; ?></td>
                                <td><a href="javascript:" <?php if($imagesdata >0) {} else {echo 'style="pointer-events:none;background-color: #cccccc;text-decoration:none;border: 1px solid #999999;cursor: not-allowed;color: #666666;"';} ?> data-bs-toggle="modal" data-bs-target="#assignIModal<?php echo $fetchusers_complaint['ucid']; ?>">View Images</a></td>
                                <td><input type="text" maxlength="1" oninput="this.value = this.value.replace(/[^1-4.]/g, '').replace(/(\..*?)\..*/g, '$1');" style="width:55px;padding:10px;" min="1" max="4" value="<?php echo $fetchusers_complaint['proaarav']; ?>" onchange="updatePrority(this.value, '<?php echo $fetchusers_complaint['ucid']; ?>');"/></td>
                                <?php if($isDepartmentComplaintUser) { ?>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignEModal<?php echo $fetchusers_complaint['ucid']; ?>">Assign Complaint to Tradesman</a></td>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignModal<?php echo $fetchusers_complaint['ucid']; ?>">Assign Complaint to Officer</a><br><?php if(!empty($deptname)) { echo $deptname; } else {echo '';} ?></td>
                                <?php } else { ?>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignModal<?php echo $fetchusers_complaint['ucid']; ?>">Assign Complaint to Officer</a><br><?php if(!empty($deptname)) { echo $deptname; } else {echo '';} ?></td>
                                <?php } ?>
                                <td><?php if(!empty($engname)) { echo $engname; } else {echo 'N/A';} ?></td>
                                <td><?php if($fetchusers_complaint['c_status'] == '2') { echo date('d-m-y H:i:s', strtotime($fetchusers_complaint['completiondate'])); } else {echo 'N/A<br>N/A';} ?></td>
                                <td><?php echo $fetchusers_complaint['remarks']; ?></td>
                                <td><div class="stars">
                                <?php $user_ratings = $fetchusers_complaint['user_ratings'];
                                        $whole = intval($user_ratings);
                                        $rem = 5 - $whole;
                                        $decimal1 = $user_ratings - $whole;
                                        $decimal2 = round($decimal1, 2);
                                        $decimal = substr($decimal2, 2);
                                    for($i=0;$i<$whole;$i++) {
                                        echo '<span class="star on"></span>';
                                    } ;
                                    if($decimal > 0) {
                                        $rem = $rem - 1;
                                        echo '<span class="star half"></span>';
                                    } else {
                                        $rem = $rem;
                                    }
                                    for($i=0;$i<$rem;$i++) {
                                        echo '<span class="star"></span>';
                                    } ;
                                    ?><br><?php echo $fetchusers_complaint['user_feedback']; ?>
                                    </div>
                                </td>
                                <?php if($isDepartmentComplaintUser) { ?>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignAModal<?php echo $fetchusers_complaint['ucid']; ?>">Assigned Tradesman List</a></td>
                                <td><a href="javascript:" data-bs-toggle="modal" data-bs-target="#assignAOModal<?php echo $fetchusers_complaint['ucid']; ?>">Assigned Officers List</a></td>
                                <?php } ?>
                                <td><a onclick="edit(<?php echo $fetchusers_complaint['ucid']; ?>)" data-id="<?php echo $fetchusers_complaint['ucid']; ?>" <?php //if($fetchusers_complaint['engineer'] != '0' || $fetchusers_complaint['engineer'] != 0 || !empty($fetchusers_complaint['engineer'])) { } else { echo 'style="pointer-events:none;background-color: #cccccc;border: 1px solid #999999;cursor: not-allowed;color: #666666;"';}?> class="btn btn-xs btn-outline-primary">Update</a></td>
                                <?php if(!$isDepartmentComplaintUser) { ?>
                                <td><?php if($fetchusers_complaint['status'] == '1') { ?><a onClick="javascript: return confirm('Are you Sure?');" href="deleteComplaint.php?id=<?php echo $fetchusers_complaint['ucid']; ?>&st=0" class="btn btn-xs btn-outline-danger">Cancel</a><?php } else { ?><a onClick="javascript: return confirm('Are you Sure?');" href="deleteComplaint.php?id=<?php echo $fetchusers_complaint['ucid']; ?>&st=1" class="btn btn-xs btn-outline-danger">Undo Cancel</a><?php } ?></td>
                                <td><a href="javascript:" class="btn btn-xs btn-outline-primary" data-bs-toggle="modal" data-bs-target="#assignSModal<?php echo $fetchusers_complaint['ucid']; ?>">Send SMS</a></td>
                                <?php } ?>
                                
                    </form>
                                <div class="modal demo-modal">
                                  <div class="modal fade" id="assignModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Assign to Officer</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body">
                                            <form class="forms-sample" method="POST">
                                                <input type="hidden" name="ucid" value="<?php echo $fetchusers_complaint['ucid']; ?>"/>
                                                <div class="form-group">
                                                    <label for="dept_id">Officers</label>
                                                    <select class="form-control dept_id" name="dept_id" required id="dept_id">
                                                        <option value="">Select</option>
                            						  <?php $dept = $conn->query("SELECT * FROM admin WHERE type='dept' AND status='1' AND subdivision = '".$fetchusers_complaint['subdivision']."'"); 
                            						  while($fetchdept = $dept->fetch_assoc()) { ?>
                                                      <option value="<?php echo $fetchdept['id']; ?>" <?php if($fetchusers_complaint['department'] != '0' || $fetchusers_complaint['department'] != 0 || !empty($fetchusers_complaint['department'])) { if($fetchdept['id'] == $fetchusers_complaint['department']) {echo 'selected';} } ?>><?php echo $fetchdept['name']; ?>(<?php echo $fetchdept['designation']; ?>)</option>
                            						  <?php } ?>
                                                    </select>
                                                  </div>
                                                  </div>
                                                  <div class="modal-footer">
                                                    <button type="submit" name="submit" class="btn btn-success">Submit</button>
                                                    <button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
                                                  </div>
                                            </form>
                                        </div>
                                      </div>
                                    </div>
                                    </div>
                                    <div class="modal fade" id="assignEModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Assign Engineer</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body">
                                            <form class="forms-sample" method="POST">
                                                <input type="hidden" name="ucid" value="<?php echo $fetchusers_complaint['ucid']; ?>"/>
                                                <input type="hidden" name="did" id="did<?php echo $fetchusers_complaint['ucid']; ?>"/>
                                                <div class="form-group">
                                                    <label for="engineer_id">Engineer</label>
                                                    <select class="form-control engineer_id" name="engineer_id" required id="engineer_id" onchange="getmyparent(this.value, '<?php echo $fetchusers_complaint['ucid']; ?>')">
                                                        <option value="">Select</option>
                            						  <?php //$dept = $conn->query("SELECT * FROM engineers_list WHERE status='1' AND dept_id='".$_SESSION['admin']."'"); 
                            						  $dept = $conn->query("SELECT * FROM engineers_list WHERE status='1'");
                            						  while($fetchdept = $dept->fetch_assoc()) { ?>
                                                      <option value="<?php echo $fetchdept['id']; ?>" <?php if($fetchusers_complaint['engineer'] != '0' || $fetchusers_complaint['engineer'] != 0 || !empty($fetchusers_complaint['engineer'])) { if($fetchdept['id'] == $fetchusers_complaint['engineer']) {echo 'selected';} } ?>><?php echo $fetchdept['name']; ?></option>
                            						  <?php } ?>
                                                    </select>
                                                  </div>
                                                  </div>
                                                  <div class="modal-footer">
                                                    <button type="submit" name="submiteng" class="btn btn-success">Submit</button>
                                                    <button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
                                                  </div>
                                            </form>
                                        </div>
                                      </div>
                                    </div>
                                    <div class="modal fade" id="assignBModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Complaint Details</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body">
                                              <b>Complaint No. : </b><?php echo $fetchusers_complaint['docketNumber']; ?><br>
                                              <b>Date/Time of Complaint Received : </b><?php $date =  $fetchusers_complaint['date'];
                                    $timestamp = strtotime($date);
                                    if ($timestamp === FALSE) {
                                      $timestamp = strtotime(str_replace('/', '-', $date));
                                    }
                                    echo date('d-m-y',$timestamp); ?> (<?php echo date ( 'H:i:s' , strtotime($fetchusers_complaint['time']) ); ?>)<br>
                    						 <?php $buildingls = $conn->query("SELECT * FROM building_list WHERE bid='".$fetchusers_complaint['b_list']."'")->fetch_assoc(); ?>
                    						 <b> Building Name : </b><?php echo $buildingls['bName']; ?><br>
                    						 <b> Building No. : </b><?php echo $buildingls['bNo']; ?><br>
                    						 <b> Complaint Details : </b><?php echo $complaint_list['details']; ?><br>
                    						 <b> Subdivision : </b><?php echo $subdivision_list['value']; ?><br>
                    						 <b> Complaint Description : </b><?php echo $fetchusers_complaint['compdetails']; ?><br>
                    						 <b> Priority : </b><?php echo $fetchusers_complaint['proaarav']; ?><br>
                    						 <b> Tradesman Engineer : </b><?php if(!empty($engname)) { echo $engname; } else {echo 'N/A';} ?><br>
                    						 <b> Date/Time of Completion : </b><?php if($fetchusers_complaint['c_status'] == '2') { echo date('d-m-y H:i:s', strtotime($fetchusers_complaint['completiondate'])); } else {echo 'N/A';} ?><br>
                    						 <b> Official Remarks : </b><?php echo $fetchusers_complaint['remarks']; ?><br>
                    						 <b> User Satisfaction : </b><div class="stars" style="display:inline">
                                                                        <?php $user_ratings = $fetchusers_complaint['user_ratings'];
                                                                                $whole = intval($user_ratings);
                                                                                $rem = 5 - $whole;
                                                                                $decimal1 = $user_ratings - $whole;
                                                                                $decimal2 = round($decimal1, 2);
                                                                                $decimal = substr($decimal2, 2);
                                                                            for($i=0;$i<$whole;$i++) {
                                                                                echo '<span class="star on"></span>';
                                                                            } ;
                                                                            if($decimal > 0) {
                                                                                $rem = $rem - 1;
                                                                                echo '<span class="star half"></span>';
                                                                            } else {
                                                                                $rem = $rem;
                                                                            }
                                                                            for($i=0;$i<$rem;$i++) {
                                                                                echo '<span class="star"></span>';
                                                                            } ;
                                                                            ?><br><?php echo $fetchusers_complaint['user_feedback']; ?>
                                                                            </div>
                                        </div>
                                      </div>
                                    </div>
                                    </div>
                                    <div class="modal fade" id="assignAModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Assigned Tradesman</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body row">
                                            <div class="col-lg-12">
                                                <div class="row">
                                                <div class="col-lg-6" style="border:1px solid #000;">
                                                    <p>On Date</p>
                                                </div>
                                                <div class="col-lg-6" style="border:1px solid #000;">
                                                    <p>Tradesman</p>
                                                </div>
                                                     <?php $complaint_assignment = $conn->query("SELECT * FROM complaint_assignment WHERE cid='".$fetchusers_complaint['ucid']."'");
                                                while($fethass = $complaint_assignment->fetch_assoc()) {
                                                $engineer11 = $conn->query("SELECT * FROM engineers_list WHERE id = '".$fethass['eid']."'")->fetch_assoc();
                                                ?>
                                                <div class="col-lg-6" style="border:1px solid #000;"><p><?php echo date('d-m-Y H:i:s', strtotime($fethass['date'])); ?></p></div>
                                                <div class="col-lg-6" style="border:1px solid #000;"><p><?php echo $engineer11['name']; ?></p></div>
                                                <?php } ?>
                                                </div></div>
                                            </div>
                                        </div>
                                      </div>
                                    </div><div class="modal fade" id="assignAOModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Assigned Officers</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body row">
                                            <div class="col-lg-12">
                                                <div class="row">
                                                <div class="col-lg-6" style="border:1px solid #000;">
                                                    <p>On Date</p>
                                                </div>
                                                <div class="col-lg-6" style="border:1px solid #000;">
                                                    <p>Officer</p>
                                                </div>
                                                     <?php $complaint_assignment_ofc = $conn->query("SELECT * FROM complaint_assignment_ofc WHERE cid='".$fetchusers_complaint['ucid']."'");
                                                while($fethassofc = $complaint_assignment_ofc->fetch_assoc()) {
                                                $engineer112 = $conn->query("SELECT * FROM admin WHERE id = '".$fethassofc['did']."'")->fetch_assoc();
                                                ?>
                                                <div class="col-lg-6" style="border:1px solid #000;"><p><?php echo date('d-m-Y H:i:s', strtotime($fethassofc['date'])); ?></p></div>
                                                <div class="col-lg-6" style="border:1px solid #000;"><p><?php echo $engineer112['name']; ?></p></div>
                                                <?php } ?>
                                                </div></div>
                                            </div>
                                        </div>
                                      </div>
                                    </div>
                                    <div class="modal fade" id="assignIModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog modal-lg" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Complaint Images</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body">
                                              
                                              <div class="row grid-margin">
                                                  <div class="col-lg-12">
                                                    <iframe frameborder="0" scrolling="no" style="overflow:hidden;height:450px;width:100%;background:transparent;" src="gallery.php?id=<?php echo $fetchusers_complaint['ucid']; ?>"></iframe>
                                                  </div>
                                                </div>
                                            </div>
                                        </div>
                                      </div>
                                    </div>
                                    <div class="modal fade" id="assignSModal<?php echo $fetchusers_complaint['ucid']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-2" aria-hidden="true">
                                      <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel-2">Send SMS to Officers</h5>
                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                            <div class="modal-body">
                                                <h5><b>Complaint No. : </b><?php echo $fetchusers_complaint['docketNumber']; ?></h5>
                                                <h5><b> Complaint Details : </b><?php echo $complaint_list['details']; ?></h5>
                                                <h5><b> Subdivision : </b><?php echo $subdivision_list['value']; ?></h5>
                                                <form class="forms-sample" method="POST">
                                                    <input type="hidden" name="ucid" value="<?php echo $fetchusers_complaint['ucid']; ?>"/>
                                                    <div class="form-group">
                                                        <label for="ofcid"><b>Select Officers : </b></label>
                                                        <ul type="none" id="ofcersul" style="border: 1px solid;padding-top: 5px;height: 320px;overflow: scroll;">
                                                            <?php $dept = $conn->query("SELECT * FROM admin WHERE type='dept' AND status='1'"); 
                                                            while($fetchdept = $dept->fetch_assoc()) { ?>
                                                            <li><label><input type="checkbox" value="<?php echo $fetchdept['id']; ?>" name="ofcid[]"> <?php echo $fetchdept['name']; ?>(<?php echo $fetchdept['designation']; ?>)</label></li>
                                                            <?php } ?>
                                                        </ul>
                                                    </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="submit" name="sendsms" class="btn btn-success">Submit</button>
                                                <button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
                                            </div>
                                                </form>
                                            <!--<iframe frameborder="0" scrolling="no" style="overflow:hidden;height:520px;width:100%;background:transparent;" src="sms.php?id=<?php echo $fetchusers_complaint['ucid']; ?>"></iframe>-->
                                        </div>
                                      </div>
                                    </div>
                              </tr>
                          <?php }} else {
                          echo '<tr><td colspan="17"><center>No Records Found!</center></td></tr>';
                          } ?>
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
		  <?php include('includes/footer.php'); ?>
        </div>
      </div>
    </div>
    <?php include 'compModal.php'; ?>
    </div>
    <?php include('includes/foot.php'); ?>
    <script>
    $( document ).ready(function() {
        $('#resetbtn').click(function(){
            $('#Filterform')[0].reset();
            $('input[type="text"]').val('');
            $('select').val('');
      });
    });
    function updatePrority(priority, id) {
        $.ajax({
				type: "POST",
				url: "updatePrority.php",
				data: {priority: priority, id: id},
				success: function (r) {
					alert('Priority updated successfully.');
				}
			});
    }
    function getmyparent(engineer, comp) {
        $.ajax({
				type: "POST",
				url: "getDept.php",
				data: {engineer: engineer},
				success: function (r) {
					$('#did'+comp).val(r);
				}
			});
    }
    $('.dept_id').removeClass('select2-hidden-accessible');
    $('#select2-dept_id-container').parents('.select2-selection').css('display','none');
    $('.engineer_id').removeClass('select2-hidden-accessible');
    $('#select2-engineer_id-container').parents('.select2-selection').css('display','none');
    $('#ofcid').removeClass('select2-hidden-accessible');
    $('#select2-ofcid-container').parents('.select2-selection').css('display','none');
    function edit(id){
        $('#edit').modal('show');
       getRow(id);
      }
    function getRow(id){
      $.ajax({
        type: 'POST',
        url: 'getComplaint.php',
        data: {id:id},
        dataType: 'json',
        success: function(response){
          $('#ucid').val(response.ucid);
          $('#remarks').val(response.remarks);
          $('#ptype').val('dashboard');
          $("#c_status"+response.c_status).attr('checked', 'checked');
        }
      });
    }
    $('.close').click(function(){
 $("#edit").modal('toggle');
});
$(function(){

        //button select all or cancel
        $("#select-all").click(function () {
            var all = $("input.select-all")[0];
            all.checked = !all.checked
            var checked = all.checked;
            $("input.select-item").each(function (index,item) {
                item.checked = checked;
            });
        });

        //button select invert
        $("#select-invert").click(function () {
            $("input.select-item").each(function (index,item) {
                item.checked = !item.checked;
            });
            checkSelected();
        });

        //button get selected info
        $("#selected").click(function () {
            var items=[];
            $("input.select-item:checked:checked").each(function (index,item) {
                items[index] = item.value;
            });
            if (items.length < 1) {
                alert("no selected items!!!");
            }else {
                var values = items.join(',');
                console.log(values);
                var html = $("<div></div>");
                html.html("selected:"+values);
                html.appendTo("body");
            }
        });

        //column checkbox select all or cancel
        $("input.select-all").click(function () {
            var checked = this.checked;
            $("input.select-item").each(function (index,item) {
                item.checked = checked;
            });
        });

        //check selected items
        $("input.select-item").click(function () {
            var checked = this.checked;
            console.log(checked);
            checkSelected();
        });

        //check is all selected
        function checkSelected() {
            var all = $("input.select-all")[0];
            var total = $("input.select-item").length;
            var len = $("input.select-item:checked:checked").length;
            console.log("total:"+total);
            console.log("len:"+len);
            all.checked = len===total;
        }
    });
    </script>
  </body>
</html>
