<?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 `flash_news` where id='$getid'";
    $query = mysqli_query($con, $sql);

    if ($query) {
        foreach ($query as $items) {
            $news = $items['news'];
        }
    }
}

if (isset($_POST['submit'])) {
    $news = $_POST['news'];



    $sql = $con->prepare("update `flash_news` set id=?,news=? where id=?");
    $sql->bind_param("ssi", $getid, $news, $getid);

    if ($sql->execute()) {
        echo "<script>
        alert('Data updated Successfully');
        window.location.href = 'flash-news-list.php'; 
      </script>";
    } else {
        echo "<script>alert('Failed to update data')</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 Flash News</h5>

                            </div>
                            <div class="row">

                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label>Flash News</label>
                                        <textarea class="form-control" name="news" required
                                            placeholder="Enter Flash News"><?php echo $news ?></textarea>
                                    </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>