<?php

require_once 'auth.php';

// Check if the user is authenticated as an admin
checkAdminAuth();




include("config.php");

if (isset($_GET['edit'])) {
    $getid = $_GET['edit'];

    $sql = "select * from `officer_details` where id='$getid'";
    $query = mysqli_query($con, $sql);

    if ($query) {
        foreach ($query as $items) {
            $name = $items['name'];
            $designation = $items['designation'];
            $email = $items['email'];
            $address = $items['address'];
        }
    }
}


if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $designation = $_POST['designation'];
    $email = $_POST['email'];
    $address = $_POST['address'];

   
    // Update Database
    $sql = $con->prepare("UPDATE `officer_details` SET name=?, designation=?, email=?,address=? WHERE id=?");
    $sql->bind_param("ssssi", $name, $designation, $email, $address, $getid);

    if ($sql->execute()) {
        echo "<script>
        alert('officer details Updated Successfully');
        window.location.href = 'officer-details-list.php'; 
      </script>";
    } else {
        echo "<script>alert('Failed to update officer details')</script>";
    }
}



?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <title>Admin</title>

    <link rel="shortcut icon" href="assets/img/favicon.png">

    <link rel="stylesheet" href="assets/css/select2.min.css">

    <link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/plugins/bootstrap-tagsinput/css/bootstrap-tagsinput.css">

    <link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
    <link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">

    <link rel="stylesheet" href="assets/css/dataTables.bootstrap4.min.css">

    <link rel="stylesheet" href="assets/plugins/feather/feather.css">

    <link rel="stylesheet" href="assets/css/style.css">
    <script src="ckeditornci/ckeditor_l/ckeditor.js"></script>
</head>

<body>
    <div class="main-wrapper">

        <?php

        include("header.php");
        include("sidebar.php");


        ?>

        <div class="page-wrapper">
            <div class="content">
                <form method="post" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-lg-7 col-sm-12 m-auto">
                            <div class="content-page-header">
                                <h5 class="mb-2">Update Officer Details</h5>

                            </div>
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>Name</label>
                                        <input type="text" name="name" class="form-control" value="<?php echo $name ?>"
                                            placeholder="Enter Name" required>
                                    </div>
                                </div>
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>Designation</label>
                                        <input type="text" name="designation" value="<?php echo $designation ?>" class="form-control"
                                            placeholder="Enter Designation" required>
                                    </div>
                                </div>
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>Email</label>
                                       <input type="email" name="email" value="<?php echo $email ?>" class="form-control"
                                            placeholder="Enter Email" required>
                                    </div>
                                </div>

                               
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>Address</label>
                                        <input type="text" name="address" value="<?php echo $address ?>" class="form-control"
                                            placeholder="Enter Address" required>
                                    </div>
                                </div>
                              

                                
                                <div class="col-lg-12">
                                    <div class="btn-path">
                                        <button type="submit" name="submit" class="btn btn-submit "> Submit</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <script data-cfasync="false" src="../../cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>
    <script src="assets/js/jquery-3.6.4.min.js"></script>

    <script src="assets/js/select2.min.js"></script>

    <script src="assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

    <script src="assets/js/feather.min.js"></script>

    <script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
    <script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

    <script src="assets/js/admin.js"></script>
    <script>
        CKEDITOR.replace('description');
    </script>


</body>

</html>