<?php
session_start();
include('include/config.php');
if(strlen($_SESSION['alogin'])==0){ 
    header('location:index.php');
} else {
  if(isset($_POST['update'])) {
    $complaintnumber = $_GET['cid'];
    $status = $_POST['status'];
    $remark = $_POST['remark'];

    $query = mysqli_query($bd, "INSERT INTO complaintremark(complaintNumber,status,remark) VALUES('$complaintnumber','$status','$remark')");
    $sql = mysqli_query($bd, "UPDATE tblcomplaints SET status='$status' WHERE complaintNumber='$complaintnumber'");

    echo "<script>alert('Complaint details updated successfully');</script>";
  }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Update Complaint</title>

<!-- Bootstrap + Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">

<style>
body {
    font-family: 'Poppins', sans-serif;
    background: #f7f8fa;
    padding: 40px;
}
.card {
    max-width: 700px;
    margin: auto;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    overflow: hidden;
}
.card-header {
    background: linear-gradient(90deg, #ff7b00, #ff9500);
    color: #fff;
    font-weight: 600;
    font-size: 1.2rem;
    text-align: center;
}
.card-body label {
    font-weight: 600;
}
.card-body textarea {
    resize: none;
}
.btn-submit {
    background: linear-gradient(90deg, #ff7b00, #ff9500);
    border: none;
    color: #fff;
    border-radius: 8px;
    padding: 8px 20px;
    transition: 0.3s;
}
.btn-submit:hover {
    opacity: 0.9;
}
.btn-close {
    background: #f1f1f1;
    border: none;
    color: #333;
    border-radius: 8px;
    padding: 8px 20px;
    margin-left: 10px;
}
</style>

<script type="text/javascript">
function f2() { window.close(); }
function f3() { window.print(); }
</script>
</head>

<body>

<div class="card">
    <div class="card-header">
        <i class="fa-solid fa-pen-to-square me-2"></i> Update Complaint
    </div>
    <div class="card-body">
        <form name="updatecomplaint" id="updatecomplaint" method="post">
            <div class="mb-3">
                <label>Complaint Number</label>
                <input type="text" class="form-control" value="<?php echo htmlentities($_GET['cid']); ?>" readonly>
            </div>

            <div class="mb-3">
                <label>Status</label>
                <select name="status" class="form-select" required>
                    <option value="">Select Status</option>
                    <option value="in process">In Process</option>
                    <option value="closed">Closed</option>
                </select>
            </div>

            <div class="mb-3">
                <label>Remark</label>
                <textarea name="remark" class="form-control" rows="6" required></textarea>
            </div>

            <div class="d-flex justify-content-start">
                <button type="submit" name="update" class="btn btn-submit"><i class="fa-solid fa-paper-plane me-1"></i> Submit</button>
                <button type="button" class="btn btn-close" onclick="f2()"><i class="fa-solid fa-x-circle me-1"></i> Close</button>
            </div>
        </form>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

<?php } ?>
