<?php

    // session_start();

    include "../db.php";

    require '../auth.php';

    restrictAccess(['master_admin']);

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y g:i a');



    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {

        header("Location: logout.php");

        exit();

    }



    if ( $_SESSION['utype'] != 'master_admin' && $_SESSION['uref'] != 'fssdf4543frts' ) {

        header("Location: logout.php");

        exit();

    }

?>



<!DOCTYPE html>

<html lang="en">



<head>

    <?php include "include/meta.php"; ?>

    <?php include "include/css.php"; ?>

    <?php include "include/php-functions.php"; ?>

    <script src="https://cdn.ckeditor.com/4.6.2/standard-all/ckeditor.js"></script>

</head>



<body>

    <!--  Header -->

    <?php 

    include "include/header.php"; 

    ?>

    <!-- #header -->



    <section id="inner-body">

        <div class="body-content">

            <div class="container-fluid">

                <?php

                    if ( isset($_GET["edit_id"]) ) {

                    $edit_run = mysqli_query($con, "SELECT * FROM data  WHERE data_sl_no = '$_GET[edit_id]'");

                    $edit_row = mysqli_fetch_assoc($edit_run);

                    // $sm=$edit_row['course_cat'];

                ?>

                <div class="card radius-10 mt-3">

                    <div class="card-header">

                        <h5 class="m-0"> <?php echo $edit_row["data_title"]; ?></h5>

                    </div>

                    <div class="card-body mb-4">

                        <form class="user" method="post" enctype="multipart/form-data">

                            <div class="row">

                                <div class="col-md-6">

                                    <div class="mb-3">

                                        <label for="data_title" class="form-label">Entrance Title</label>

                                        <input type="text" class="form-control form-control-sm mb-2" id="course_name"

                                            value="<?php echo $edit_row["data_title"]; ?>" name="data_title">

                                    </div>

                                    <div class=" mb-3">

                                        <label class="form-label" for="customFile">Entrance Short Description</label>

                                        <textarea name="data_short_des" class="form-control" id="" cols="30"

                                            rows="5"><?php echo $edit_row['data_short_des'];?></textarea>

                                    </div>

                                </div>

                                <div class="col-md-6 mb-3">

                                    <label class="form-label" for="customFile">Entrance Image</label>

                                    <div class="mb-4 d-flex justify-content-center">

                                        <img id="selectedImage"

                                            src="../upload/entrance/<?php echo $edit_row['data_img'];?>"

                                            alt="example placeholder" style="width: 150px;" />

                                    </div>

                                    <div class="d-flex justify-content-center">

                                        <div class="btn btn-primary btn-rounded btn-sm">

                                            <label class="form-label text-white m-1" for="customFile1">Edit

                                                Image</label>

                                            <input type="file" class="form-control d-none" id="customFile1" name="file"

                                                accept="image/*"

                                                onchange="displaySelectedImage(event, 'selectedImage')" />

                                        </div>

                                    </div>

                                </div>

                                <div class="col-md-12 mt-5 mb-3">

                                    <label for="content">Entrance ABOUT</label>

                                    <textarea name="content" id="content"

                                        class="form-control ckeditor"><?php echo $edit_row["data_long_des"]; ?></textarea>

                                </div>

                                <div class="col-md-12 mb-3">

                                    <label for="data_seo_title">Entrance SEO TITLE</label>

                                    <input type="text" class="form-control form-control-sm mb-2" id="course_seotitle"

                                        value="<?php echo $edit_row["data_seo_title"]; ?>" name="data_seo_title">

                                </div>



                                <div class="col-md-12 mb-3">

                                    <label for="data_seo_keyword">Entrance KEYWORD</label>

                                    <input type="text" class="form-control form-control-sm mb-2" id="course_keyword"

                                        value="<?php echo $edit_row["data_seo_keyword"]; ?>" name="data_seo_keyword">

                                </div>

                                <div class="col-md-12 mb-3">

                                    <label for="content1">Entrance Other Details</label>

                                    <textarea name="content1" id="content1"

                                        class="form-control ckeditor"><?php echo $edit_row["data_seo_tag"]; ?></textarea>

                                </div>

                                <div class="col-md-12">

                                    <button type="submit" class="btn btn-success btn-user" name="edit_users">

                                        <i class="fa fa-edit"></i> Update

                                    </button>

                                </div>

                            </div>

                        </form>

                    </div>

                </div>

                <?php

				}

                elseif ( isset($_GET["vm"]) ) 

                {

                $count = mysqli_query($con, "UPDATE data SET data_count = data_count + 1 WHERE data_sl_no = '$_GET[vm]'");

                if($count){

                $notice_sql = "SELECT * FROM data WHERE data_sl_no='$_GET[vm]'";

                $notice_data = mysqli_query($con,$notice_sql);

                while($notice_rows = mysqli_fetch_array($notice_data))

                {

                ?>

                <div class="card radius-10 mt-3">

                    <div class="card-header">

                        <h5 class="m-0">Entrance Title: <?php echo $notice_rows['data_title'];?></h5>

                    </div>

                    <div class="card-body mb-4">

                        <font color="black">

                            <?php if (!empty($notice_rows['data_img'])){

                                echo "

                                <h5>Catagory Image:</h5>";

                                echo " <a href='../upload/entrance/$notice_rows[data_img]' title='Click to open' target='_blank'> (<b>Already Uploaded - <img src='../upload/entrance/$notice_rows[data_img]' height='50' data-toggle='modal' data-target='#show-img' class='showModal'> </b> Click To View</a> )";

                                }

                            ?>

                        </font>

                        <br>

                        <?php if (!empty($edit_row['data_img']))

                            {

                            echo " <a href='../upload/entrance/$edit_row[data_img]' title='Click to open' target='_blank'> (<b>Already Uploaded - <img src='../upload/entrance/$edit_row[data_img]' height='50' data-toggle='modal' data-target='#show-img' class='showModal'>

                                                         </b> Click To View</a> )";

                            }

                        ?>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance Short Description:</h5>

                            <?php echo $notice_rows['data_short_des']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance About:</h5>

                            <?php echo $notice_rows['data_long_des']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance SEO:</h5>

                            <?php echo $notice_rows['data_seo_title']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance SEO Keywords:</h5>

                            <?php echo $notice_rows['data_seo_keyword']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance Other Details:</h5>

                            <?php echo $notice_rows['data_seo_tag']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance Upload By:</h5>

                            <?php echo $notice_rows['data_up_by']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance edit date:</h5>

                            <?php echo $notice_rows['data_edit_date']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance Visitor Count:</h5>

                            <?php echo $notice_rows['data_count']; ?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Entrance Tag List:</h5>

                            <?php

                            $catagory = $notice_rows['data_catagory'];

                            $tag_for = $notice_rows['data_title'];

                            $tag_get_for = $notice_rows['data_ref_id'];

                            $c=1;

                            $tag_sql = "SELECT * FROM all_tag WHERE all_tag_catagory = '$catagory' AND all_tag_get_id = '$tag_get_for' AND all_tag_recycle = '1'";

                            $tag_data = mysqli_query($con,$tag_sql);

                            while($tag_rows = mysqli_fetch_array($tag_data))

                            {

                            ?>

                            <p><?php echo $c;?> > Tag Title:

                                <a href="<?php echo $tag_rows['all_tag_url']; ?>">

                                    <?php echo $tag_rows['all_tag_title']; ?></a>

                            </p>

                            <?php $c++; }?>

                        </div>

                        <div class="mb-3">

                            <h5 class="m-0">Faq:</h5>

                            <?php

                            $catagory = $notice_rows['data_catagory'];

                            $faq_for = $notice_rows['data_title'];

                            $faq_get_for = $notice_rows['data_ref_id'];

                            $c=1;

                            $faq_sql = "SELECT * FROM faq WHERE faq_catagory = '$catagory' AND faq_get_id = '$faq_get_for' AND faq_recycle = '1'";

                            $faq_data = mysqli_query($con,$faq_sql);

                            while($faq_rows = mysqli_fetch_array($faq_data))

                            {

                            ?>

                            <br>

                            <div class="md-3">

                                <h4><?php echo $c;?> > <?php echo $faq_rows['faq_q']; ?></h4>

                                <p><?php echo $faq_rows['faq_ans']; ?></p>

                            </div>

                            <?php $c++; }?>

                        </div>

                    </div>

                </div>

                <?php } } } else{ ?>



                <div class="card radius-10 mt-3">

                    <div class="card-header">

                        <div class="d-flex justify-content-center">

                            <h4 class="card-title mb-0">Entrance</h4>

                        </div>

                    </div>

                    <div class="card-body">

                        <button id="toggleButton" class="btn btn-primary btn-sm" onclick="toggleDiv()">Add Entrance

                        </button>

                        <div id="toggleDiv"

                            style="display: none; padding: 10px; border: 1px solid #ddd; margin-top: 10px;">

                            <form action="" method="POST" enctype="multipart/form-data">

                                <div class="row">

                                    <div class="col-md-6 mb-3">

                                        <div class="mb-2">

                                            <label for="exampleFormControlInput1" class="form-label">Entrance

                                                Name</label>

                                            <input type="Text" class="form-control" name="data_title"

                                                placeholder="Enter entrance Name">

                                        </div>

                                        <div>

                                            <label for="exampleFormControlTextarea1" class="form-label">Entrance Short

                                                About</label>

                                            <textarea class="form-control " name="data_short_des" rows="3"></textarea>

                                        </div>

                                    </div>

                                    <div class="col-md-6 mb-3">

                                        <label for="exampleFormControlInput1" class="form-label">Entrance Image</label>

                                        <div class=row>

                                            <div class="col-md-7 d-flex justify-content-center">

                                                <img id="selectedImage" src="../upload/entrance/img.png"

                                                    alt="example placeholder" style="height:150px;" />

                                            </div>

                                            <div class="col-md-5 d-flex justify-content-center"

                                                style="padding:50px 0px;">

                                                <div class="btn btn-primary btn-rounded">

                                                    <label class="form-label text-white m-1" for="customFile1">Select

                                                        Image</label>

                                                    <input type="file" class="form-control d-none" id="customFile1"

                                                        name="file"

                                                        onchange="displaySelectedImage(event, 'selectedImage')" />

                                                </div>

                                            </div>

                                        </div>

                                    </div>



                                    <div class="col-md-12 mb-3">

                                        <label for="exampleFormControlTextarea1" class="form-label">Entrance

                                            Description</label>

                                        <textarea class="form-control ckeditor" name="content" id="content"

                                            rows="3"></textarea>

                                    </div>

                                    <br><br>

                                    <div class="col-md-6 mb-3">

                                        <label for="exampleFormControlInput1" class="form-label">Entrance SEO

                                            Title</label>

                                        <input type="Text" class="form-control" name="data_seo_title"

                                            placeholder="Enter Catagory SEO Title">

                                    </div>

                                    <div class="col-md-6 mb-3">

                                        <label for="exampleFormControlInput1" class="form-label">Entrance SEO Keyword

                                            With

                                            Coma</label>

                                        <input type="Text" class="form-control" name="data_seo_keyword"

                                            placeholder="SEO Keyword">

                                    </div>

                                    <div class="col-md-12 mb-3">

                                        <label for="exampleFormControlTextarea1" class="form-label">Entrance Other

                                            Details</label>

                                        <textarea class="form-control ckeditor" name="content1" id="content1"

                                            rows="3"></textarea>

                                    </div>

                                    <div class=" mb-3 d-grid gap-2 d-md-flex justify-content-md-end">

                                        <button class="btn btn-success text-white me-md-2" name="addsubmit"

                                            type="submit">Submit</button>

                                    </div>

                                </div>

                            </form>

                        </div>

                    </div>

                    <div class="card-body mt-2">

                        <div class="row m-0">

                            <?php if(isset($_GET['recycle_table'])){ ?>

                            <div class="col-md-12 p-0">

                                <div class="d-flex justify-content-between mb-2">

                                    <div>

                                        <h5>Recycle Entrance List</h5>

                                    </div>

                                    <div>

                                        <a href="entrance.php" class="btn btn-primary btn-sm">Active Entrances</a>

                                    </div>

                                </div>



                                <div class="table-responsive">

                                    <table class="table table-hover table-bordered table-sm" id="thisismytable">

                                        <thead>

                                            <tr>

                                                <th>No.</th>

                                                <th>Entrance</th>

                                                <th>Action</th>

                                            </tr>

                                        </thead>

                                        <tbody>

                                            <?php

                                            $sql = "SELECT * FROM data WHERE data_catagory='entrance' AND data_recycle = '0' ORDER BY data_sl_no DESC";



                                            $run = mysqli_query($con, $sql);



                                            $c = 1;

                                            while ( $rows = mysqli_fetch_assoc($run) ) {

                                                                                                                        

                                            echo "

                                            <tr id='$rows[data_sl_no]'>

                                                <td>

                                                    <span class='badge badge-info badge-pill text-dark'>$c</span>

                                                </td>

                                                <td>

                                                    $rows[data_title]

                                                </td>";

                                                ?>

                                            <td class='text-center align-middle'>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entrance.php?vm=<?php echo $rows['data_sl_no']; ?>">View</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entrance.php?edit_id=<?php echo $rows['data_sl_no']; ?>">

                                                    Edit</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="tagentrance.php?entrance_tag=<?php echo $rows['data_sl_no']; ?>">Tag</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entranceCourse.php?course=<?php echo $rows['data_sl_no']; ?>">Course</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entranceFAQ.php?faq=<?php echo $rows['data_sl_no']; ?>">FAQ</a>



                                                <a href='entrance.php?rec_id=<?php echo $rows["data_sl_no"]; ?>'

                                                    class='delete m-2 btn btn-danger btn-sm rounded-circle'

                                                    title='Click to Delete'>

                                                    <i class="fa fa-recycle" aria-hidden="true"></i>

                                                </a>

                                                <a href='entrance.php?del_id=<?php echo $rows["data_sl_no"]; ?>'

                                                    class='delete m-2 btn btn-danger btn-sm rounded-circle'

                                                    title='Click to Delete'>

                                                    <i class="fa fa-trash" aria-hidden="true"></i>

                                                </a>

                                            </td>

                                            </tr>

                                            <?php $c++;}?>

                                        </tbody>

                                    </table>

                                </div>

                            </div>

                            <?php } else{ ?>

                            <div class="col-md-12 p-0">

                                <div class="d-flex justify-content-between mb-2">

                                    <div>

                                        <h3>Active Entrance List</h3>

                                    </div>

                                    <div>

                                        <a href="entrance.php?recycle_table"

                                            class="btn btn-info btn-sm text-white">Recycle

                                            Entrances</a>

                                    </div>

                                </div>

                                <div class="table-responsive">

                                    <table class="table table-hover table-bordered table-sm" id="thisismytable">

                                        <thead>

                                            <tr>

                                                <th>No.</th>

                                                <th>Entrance Title</th>

                                                <th>Action</th>

                                            </tr>

                                        </thead>

                                        <tbody>

                                            <?php

                                            $sql = "SELECT * FROM data WHERE data_catagory = 'entrance' AND data_recycle = '1' ORDER BY data_sl_no DESC";

                                            $run = mysqli_query($con, $sql);



                                            $c = 1;

                                            while ( $rows = mysqli_fetch_assoc($run) ) {

                                                                                                                        

                                            echo "

                                            <tr id='$rows[data_sl_no]'>

                                                <td>

                                                    <span class='badge badge-info badge-pill text-dark'>$c</span>

                                                </td>

                                                <td>

                                                    $rows[data_title]

                                                </td>";

                                                ?>

                                            <td class='text-center align-middle'>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entrance.php?vm=<?php echo $rows['data_sl_no']; ?>">View</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entrance.php?edit_id=<?php echo $rows['data_sl_no']; ?>">

                                                    Edit</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="tagentrance.php?entrance_tag=<?php echo $rows['data_sl_no']; ?>">Tag</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entranceCourse.php?course=<?php echo $rows['data_sl_no']; ?>">Course</a>

                                                <a class="btn btn-primary btn-sm" style="margin-left:5px;"

                                                    href="entranceFAQ.php?faq=<?php echo $rows['data_sl_no']; ?>">FAQ</a>

                                                <a href='entrance.php?rec_id=<?php echo $rows["data_sl_no"]; ?>'

                                                    class='delete m-2 btn btn-danger btn-sm rounded-circle'

                                                    title='Click to Recycle'>

                                                    <i class="fa fa-recycle" aria-hidden="true"></i>

                                                </a>

                                            </td>

                                            </tr>

                                            <?php $c++; } ?>

                                        </tbody>

                                    </table>

                                </div>

                            </div>

                            <?php } ?>

                        </div>

                    </div>

                </div>

                <?php } ?>

            </div>

        </div>



        <?php include "include/footer.php"; ?>

    </section>



    <!-- JavaScript Libraries -->



    <?php include "include/js.php"; ?>

    <script>

    function toggleDiv() {

        const div = document.getElementById('toggleDiv');

        const button = document.getElementById('toggleButton');



        if (div.style.display === 'none' || div.style.display === '') {

            div.style.display = 'block';

            button.textContent = 'Hide';

        } else {

            div.style.display = 'none';

            button.textContent = 'Add Entrance';

        }

    }



    function displaySelectedImage(event, elementId) {

        const selectedImage = document.getElementById(elementId);

        const fileInput = event.target;



        if (fileInput.files && fileInput.files[0]) {

            const reader = new FileReader();



            reader.onload = function(e) {

                selectedImage.src = e.target.result;

            };



            reader.readAsDataURL(fileInput.files[0]);

        }

    }



    CKEDITOR.replace('content', {

        height: 300,

        filebrowserUploadUrl: "upload.php"

    });



    CKEDITOR.replace('content1', {

        height: 300,

        filebrowserUploadUrl: "upload.php"

    });

    </script>



</body>



</html>





<!-- Add to database -->

<?php

  if (isset($_POST['addsubmit'])) {

    $title = mysqli_real_escape_string($con, strip_tags($_POST['data_title']));

    $short_des = mysqli_real_escape_string($con, strip_tags($_POST['data_short_des']));

    $seo_title = mysqli_real_escape_string($con, strip_tags($_POST['data_seo_title']));

    $seo_keyword = mysqli_real_escape_string($con, strip_tags($_POST['data_seo_keyword']));

    $seo_tag = $_POST['content1'];

    $long_des = $_POST['content'];



    $prefix = "ENTRANCE"; // Your prefix

    $random_number = str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT);

    $timestamp = date("YmdHis"); 



    $ref_id = $prefix . $random_number . $timestamp;

    

    $up_date = date("j F, Y, g:i a");

    $recycle = "1";

    $up_by= $_SESSION['utype'];

    $catagory= 'entrance';



    // new File Upload

    $file = $_FILES["file"]["tmp_name"];

    $f = $_FILES["file"]["name"];

    $ext = pathinfo($f,PATHINFO_EXTENSION);

    $fname = rand(10000, 999999).".".$ext;

  



    $courseCatagory_sql = "INSERT INTO data ( data_ref_id, data_catagory, data_title, data_img, data_short_des, data_long_des, data_seo_title, data_seo_keyword, data_seo_tag, data_up_by, data_up_date, data_recycle) VALUES ( '$ref_id', '$catagory', '$title',  '$fname', '$short_des', '$long_des', '$seo_title', '$seo_keyword', '$seo_tag', '$up_by', '$up_date', $recycle)";

    

    if( mysqli_query($con, $courseCatagory_sql) ){

        // Move Files

      move_uploaded_file($file,'../upload/entrance/'.$fname);

        ?>

<script>

alert("Details Sent Successfully");

window.location = "entrance.php";

</script>

<?php

    }

    else{

        ?>

<script>

alert("Something's Wrong");

window.location = "dashboard.php";

</script>

<?php

    }

  }

?>





<!-- Edit database -->

<?php

    if(isset($_POST['edit_users'])){ 

	$title = mysqli_real_escape_string($con, strip_tags($_POST['data_title']));

    $short_des = mysqli_real_escape_string($con, strip_tags($_POST['data_short_des']));

    $seo_title = mysqli_real_escape_string($con, strip_tags($_POST['data_seo_title']));

    $seo_keyword = mysqli_real_escape_string($con, strip_tags($_POST['data_seo_keyword']));

    $seo_tag = $_POST['content1'];

    $long_des = $_POST['content'];

        

    $edit_date = date("j F, Y, g:i a");



        

        if ($_FILES["file"]["tmp_name"]) {

            // new File Upload

            $file = $_FILES["file"]["tmp_name"];

            $f = $_FILES["file"]["name"];

            $ext = pathinfo($f, PATHINFO_EXTENSION);

            $fname = rand(10000, 999999) . "." . $ext;

            $sql_select = "SELECT data_img FROM data WHERE data_ref_id = '$_GET[edit_id]'";

            $result = $con->query($sql_select);

            if ($result && $row = $result->fetch_assoc()) {

                $previous_logo = $row['data_img'];

                if (!empty($previous_logo)) {

                    $previous_image_path = '../upload/entrance/' . $previous_logo;

                    if (file_exists($previous_image_path)) {

                        unlink($previous_image_path);

                    }

                }

            }

        } else {

            // If no new file is uploaded, keep the previous image filename

            $fname = $edit_row['data_img'];

        }

	

        {

            $up_sql = "UPDATE data SET data_title='$title', data_short_des='$short_des', data_seo_title='$seo_title', data_seo_keyword='$seo_keyword', data_seo_tag = '$seo_tag', data_long_des='$long_des', data_img = '$fname', data_edit_date = '$edit_date' ";

   

        $up_sql .= " WHERE data_sl_no = '$_GET[edit_id]'";

		 if(mysqli_query($con, $up_sql)){



         // Move Files

         move_uploaded_file($file,'../upload/entrance/'.$fname);

       

            ?>

<script>

alert("Data Updated Successfully");

window.location = 'entrance.php';

</script>

<?php

        }

     else{

?>

<script>

alert('OOPS !!!!');

setTimeout(() => {

    window.location = 'entrance.php';

}, 1200);

</script>

<?php

        }

        

?>

<?php

        }

    }



?>





<!-- Recycle database -->

<?php

  if ( isset($_GET["rec_id"]) ) {

    $find_sql = "SELECT * FROM data WHERE data_sl_no = '$_GET[rec_id]'";

    $find_run = mysqli_query($con, $find_sql);

    if ($f_rows = mysqli_fetch_assoc($find_run)) {

        $old_rec = $f_rows["data_recycle"];

    

        if ($old_rec == 1) {

            $new_rec = 0;

        } elseif ($old_rec == 0) {

            $new_rec = 1;

        }

    

        $update_sql = "UPDATE data SET data_recycle = '$new_rec' WHERE data_sl_no = '$_GET[rec_id]'";

        $update_run = mysqli_query($con, $update_sql);



        if ( $update_run ) {

            ?>

<script>

alert("Sent to Recycle Successfully");

window.location = "entrance.php";

</script>

<?php

        } else {

            ?>

<script>

alert('OOPS !!!!');

setTimeout(() => {

    window.location = 'entrance.php';

}, 1200);

</script>

<?php

        }

        

    }



}

?>





<!-- delete database -->

<?php

if (isset($_GET["del_id"])) {

    $id = mysqli_real_escape_string($con, $_GET["del_id"]);

    

    $find_sql = "SELECT * FROM data WHERE data_sl_no = '$id'";

    $find_run = mysqli_query($con, $find_sql);



    if ($f_rows = mysqli_fetch_assoc($find_run)) {

        $old_img = $f_rows['data_img'];



        if (!empty($old_img)) {

            $previous_image_path = '../upload/entrance/' . $old_img;



            if (file_exists($previous_image_path)) {

                if (unlink($previous_image_path)) {

                    // Image deleted successfully

                } else {

                    // Failed to delete image

                    echo "Error deleting image: " . mysqli_error($con);

                }

            }

        }

    }



    $delete_sql = "DELETE FROM data WHERE data_sl_no = '$id'";

    

    if (mysqli_query($con, $delete_sql)) {

        ?>

<script>

alert("Deleted Successfully");

window.location = "entrance.php";

</script>

<?php

    } else {

        ?>

<script>

alert("Failed to delete");

window.location = "entrance.php";

</script>

<?php

    }

}

?>