<?php
include '../connection.php'; 
if(!isset($_SESSION)) session_start();
$direction = "../assets/img/main-image/";
$Data = "";
if(!isset($_SESSION["ID"])){header('Location: index.php');}
if(isset($_GET["ID"]) && isset($_GET["Type"]))
{
    $ID = $_GET["ID"];
    $deleteSql = "update main_image set status=1 WHERE ID={$ID}";
    $executeSql = mysqli_query($connection,$deleteSql);
    $_SESSION["recovery"] = 1;
    header('Location: show-main-images.php');
}
// retrive all image from table
$imageSql = "select ID ,nameImage,orderBy from main_image where status=2";
$executeSql = mysqli_query($connection,$imageSql);
while($retriveData = mysqli_fetch_row($executeSql))
{
    $Data .= "
    <div class='col-md-3 text-center' style='margin:10px 0;'>
        <img src='$direction{$retriveData[1]}'  class='img-fluid list-main-img {$selected}'>
        <a class='btn btn-info' href='deleteMain-image.php?ID={$retriveData[0]}&Type=recovery'> إستعادة<a>
        
    </div>
    ";
}


?>
<!doctype html>
<html lang="ar">
  <head>
    <title>خذ فرصة</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- assets / css -->
    <?php include 'cssFile.php'; ?>

  </head>
  <body dir="rtl">

<?php include 'navbar.php'; ?>
<div class="content-body">
    <div class='container' style='margin-top:30px;'>
        <div class="row justify-content-center">
            <div class="col-md-3 text-center col-main-image">
                <h3>الصور الرئيسية</h3>
            </div>
        </div>

        <div class='row'>

            <?php
            echo $Data;
            ?>
            
        </div>
        <!-- End row -->
    </div>
    <!-- End container -->
</div>
<!-- End content body -->
<!-- assets / js -->
    <?php include 'jsFile.php'; ?>
<script>
    <?php
if(!isset($_SESSION))
  session_start();
if(isset($_SESSION["DeleteImage"]) && $_SESSION["DeleteImage"] == 1)
{ 
?>
Swal.fire(
  'تم الحذف بنجاح',
  '',
  'error'
)
<?php
$_SESSION["DeleteImage"] = 0;
}
?>

  </script>

  </body>
</html>
<!-- onload="reloader()" -->
