<?php
include('include/session.php');
include('include/config.php');
date_default_timezone_set('Asia/Kolkata');// change according timezone
$currentTime = date( 'd-m-Y h:i:s A', time () );
  if(isset($_POST['update']))
  {
$complaintnumber=$_GET['cid'];
$status=$_POST['status'];
$person=$_POST['person'];
$priority=$_POST['priority'];
//$mobile=$_POST['mobile'];
$remark=$_POST['remark'];
$sql1=mysqli_query($conn, "select id,Name,Mobile from workers WHERE Name='$person' ");
while ($row=mysqli_fetch_array($sql1)) 
{
	$mobile = $row['Mobile'];
	$workerid = $row['id'];
}
	  
$query=mysqli_query($conn,"insert into complaintremark(complaintNumber,status,AssignedPerson,remark) values('$complaintnumber','$status','$person','$remark')");
	  
$sql=mysqli_query($conn,"update tblcomplaints set status='$status', priority='$priority' where complaintNumber='$complaintnumber'");
	  
$sql2=mysqli_query($conn,"select userId from tblcomplaints WHERE complaintNumber='$complaintnumber' ");
while ($ret=mysqli_fetch_array($sql2)) 
{
	$uid = $ret['userId'];
} 
$sql3=mysqli_query($conn,"select fullName,contactNo from users WHERE id='$uid' ");
while ($ret2=mysqli_fetch_array($sql3)) 
{
	$cno = $ret2['contactNo'];
	$fullname = $ret2['fullName'];
} 
	  
$sql4=mysqli_query($conn,"select * from tblcomplaints WHERE complaintNumber='$complaintnumber' ");
while ($ret3=mysqli_fetch_array($sql4)) 
{
	$location = $ret3['Location'];
	$noc = $ret3['noc'];
	$cat = $ret3['category'];
	$subcat = $ret3['subcategory'];
	$role = $ret3['role'];
	$prioritys = $ret3['priority'];
}
	  if($status=='in process'){
$date= date("d/m/Y");
$query4=mysqli_query($conn,"insert into workerlog(WorkerId,Name,Mobile,Role,complaintNumber,Location,category,subcategory,noc,priority,status,remark,Date) values('$workerid','$person','$mobile','$role','$complaintnumber','$location','$cat','$subcat','$noc','$prioritys','$status','$remark','$date')");
	  }
if($status=='Resolved'){
$query5=mysqli_query($conn,"update workerlog set status='$status' where complaintNumber='$complaintnumber'");
	  }
	  
		  // Account details
	$apiKey = urlencode('E+26OVuZiFk-YO1EFkmL8VFlls3deisFc9b7TcoeWY');
	
	// Message details
	$no = "9840814303";
	$numbers = array($no);
	$sender = urlencode('VMAVIT');
	
	$message = rawurlencode('Scholarship Registration Successful! You will be getting a detailed acknowledgement in your registered e-mail. Admission Team');
	
	//$message = rawurlencode('CNO: '.$complaintnumber.', NOC: '.$noc.', Contact- '.$fullname.'- '.$cno. ', Location - '.$location.' ');
 
	$numbers = implode(',', $numbers);
 	
	// Prepare data for POST request
	$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);
 
	// Send the POST request with cURL
	$ch = curl_init('https://api.textlocal.in/send/');
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);

echo "<script>alert('Complaint details updated successfully');</script>";
echo "<script>window.location.href = 'https://vinayakamissions.com/vmcc-ticket/admin/complaint-details.php?cid=$complaintnumber';</script>";
  }

 ?>
<script language="javascript" type="text/javascript">
function f2()
{
window.close();
}ser
function f3()
{
window.print(); 
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>AVIT | Complaint Details</title>
	<link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link type="text/css" href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
	<link type="text/css" href="css/theme.css" rel="stylesheet">
	<link type="text/css" href="images/icons/css/font-awesome.css" rel="stylesheet">
	<link type="text/css" href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600' rel='stylesheet'>
<script type="text/javascript">
function CheckStatus(val){
 var element=document.getElementById('person');
 if(val=='in process' || val=='' )
   element.style.display='block';
 else  
   element.style.display='none';
}
</script>
</head>
<body>
<?php
	
	$compno=$_GET['cid'];
	
	?>
<?php include("include/header.php"); ?>
	
	<div class="wrapper">
		<div class="container-full">
			<div class="row">
<?php include("include/sidebar.php"); ?>				
			<div class="span9">
					<div class="content">

						


	<div class="module">
		
							<div class="module-head">
								<h3>ASSIGN/ UPDATE COMPLAINT DETAILS</h3>
							</div>
							<div class="module-body">
 <form name="updateticket" id="updatecomplaint" class="form-horizontal" method="post"> 
<div class="form-group col-sm-6">
	<label style="color: crimson; font-size: 20px; font-weight: bold;">Complaint Number : <?php echo htmlentities($_GET['cid']); ?></label>
   </div><br/>
   <div class="form-group col-sm-6">
	   <label><b>Status</b></label>
      <select name="status" onchange='CheckStatus(this.value);' required>
      <option value="">Select Status</option>
      <option value="in process">In Process</option>
    	<option value="Resolved">Resolved</option>
        
	   </select>
	   </div><br/>
<div id="person" style="margin-bottom: 20px; ">
<div class="form-group col-sm-6">
	<label><b>Assign a Person</b></label>
<select name="person"  class="form-control">
<option value="">Select Person</option>
<?php $sql=mysqli_query($conn,"select id,Name,Mobile from workers WHERE Role='$login_role'");
while ($rw=mysqli_fetch_array($sql)) {
  ?>
<option value="<?php echo htmlentities($rw['Name']);?>"><?php echo htmlentities($rw['Name']);?></option>
<?php
}
?>
</select>
	</div>
	  <br/>
	  <div class="form-group col-sm-6">
	<label><b>Change Priority</b></label>
<select name="priority"  class="form-control">
<?php $sql8=mysqli_query($conn,"select * from tblcomplaints WHERE complaintNumber='$compno' ");
while ($rw8=mysqli_fetch_array($sql8)) {
  ?>
<option value="<?php echo htmlentities($rw8['priority']);?>"><?php echo htmlentities($rw8['priority']);?></option>
<?php
}
?>
<option value="">------Change Priority------</option>
<option value="Critical">Critical- 30 minutes</option>
<option value="High">High- 1 hour</option>
<option value="Medium">Medium- 4 hour</option>
<option value="Normal">Normal- 24 hour</option>
</select>
	</div>
	  
		  </div>
 <div class="form-group col-sm-6">
	 <label><b>Remark</b></label>
      <textarea name="remark" cols="50" rows="5" required></textarea>
	 </div><br/>
      <div class="form-group col-sm-6">
<input type="submit" name="update" class="form-control btn btn-success" value="Submit">
</div><br/>
 </form>

		</div>
						</div>
				</div>
				</div>
			</div>
		</div>
	</div>
	
<?php include('include/footer.php');?>

	<script src="scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
	<script src="scripts/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>
	<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="scripts/flot/jquery.flot.js" type="text/javascript"></script>
	<script src="scripts/datatables/jquery.dataTables.js"></script>
	<script>
		$(document).ready(function() {
			$('.datatable-1').dataTable();
			$('.dataTables_paginate').addClass("btn-group datatable-pagination");
			$('.dataTables_paginate > a').wrapInner('<span />');
			$('.dataTables_paginate > a:first-child').append('<i class="icon-chevron-left shaded"></i>');
			$('.dataTables_paginate > a:last-child').append('<i class="icon-chevron-right shaded"></i>');
		} );
	</script>

</body>
</html>