<?php
include '../connection.php';
if(!isset($_SESSION)){session_start();}
if(!isset($_SESSION["ID"])){header('Location: index.php');}
$direction = "../assets/img/storySuccess/";
$Data = "";
if(isset($_GET["ID"]) && isset($_GET["status"]))
{
    if($_GET["status"] == "delete")
    {
        $sql="update success_ar set status=0 where ID={$_GET["ID"]}";
        $excuteSql = mysqli_query($connection,$sql);
        $sql="update success_en set status=0 where ID={$_GET["ID"]}";
        $excuteSql = mysqli_query($connection,$sql);
        $_SESSION["deleteStory"] = 1 ;
    }
    else
    {
        header('Location: show-success.php');
    }
}
$sqlRetrive = "select success_ar.ID , success_ar.name, success_ar.story , success_ar.image ,
success_en.ID , success_en.name, success_en.story , success_en.image
from success_ar,success_en where success_ar.ID = success_en.ID and success_ar.status = 1";
$excuteSql = mysqli_query($connection,$sqlRetrive);
while($retriveData = mysqli_fetch_row($excuteSql))
{
    $Data .= "<div class='col-12 text-right'>
    <div class='card mb-3'>
        <div class='row no-gutters'>
            <div class='col-md-3'>
                <img src='$direction{$retriveData[3]}' class='card-img' alt='...' style='max-width:300px;height:200px;'>
            </div>
            <div class='col-md-6'>
                <div class='card-body'>
                    <h5 class='card-title'>{$retriveData[1]}</h5>
                    <p class='card-text' style='text-align:justify'>{$retriveData[2]}</p>
                    <hr>
                    <h5 class='card-title' style='text-align:left;direction:ltr;'>{$retriveData[5]}</h5>
                    <p class='card-text' style='text-align:justify;direction:ltr;'>{$retriveData[6]}</p>
                </div>
            </div>
            <div class='col-md-3' style='padding: 10px;border-right:1px solid #c5c5c5'>
                <a href='edit-success.php?ID=$retriveData[0]' class='btn btn-warning btn-block'>تعديل</a>
                <a href='show-success.php?ID=$retriveData[0]&status=delete' class='btn btn-danger btn-block'>حذف</a>
                
            </div>
        </div>
        <!-- End row -->
    </div>
    <!-- End card -->
</div>
<!-- End col -->";
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>خذ فرصة</title>
    <?php include 'cssFile.php'; ?>
    <link rel="stylesheet" href="../assets/css/galleryStyle.css">

</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-success">
                <h3>قصص نجاح</h3>
            </div>
        </div>
        <!-- End row -->
<div class='row'>
            <div class='col-md text-right' style='margin:0 10px 10px 0px;'>
        <a class='btn btn-pink' href='add-storySuccess.php' style='font-weight:bold'>إضافة جديد </a>
      </div>
      <!-- End col -->
              <div class='col-md text-left' style='margin:0 10px 10px 0px;'>
        <a class='btn btn-pink' href='delete-storySuccess.php' style='font-weight:bold'>عرض المحذوف</a>
      </div>
      <!-- End col -->
</div>
      <div class="row" style='margin-top:50px;'>
       <?php echo $Data; ?>
      </div>
        </div>
        <!-- End container -->
    </div>
    <!-- End content-body -->



    <?php include 'jsFile.php'; ?>

    <script>
<?php
if(!isset($_SESSION))
  session_start();
if(isset($_SESSION["deleteStory"]) && $_SESSION["deleteStory"] == 1)
{ 
?>
Swal.fire(
  'تم الحذف بنجاح',
  '',
  'success'
)
<?php
$_SESSION["deleteStory"] = 0;
}
?>

  </script>
  <script>
<?php
if(!isset($_SESSION))
  session_start();
if(isset($_SESSION["updateSucess"]) && $_SESSION["updateSucess"] == 1)
{ 
?>
Swal.fire(
  'تم تعديل الشخص بنجاح',
  '',
  'success'
)
<?php
$_SESSION["updateSucess"] = 0;
}
?>

  </script>
    <script>
<?php
if(!isset($_SESSION))
  session_start();
if(isset($_SESSION["recoveryStory"]) && $_SESSION["recoveryStory"] == 1)
{ 
?>
Swal.fire(
  'تم الإستعادة بنجاح',
  '',
  'success'
)
<?php
$_SESSION["recoveryStory"] = 0;
}
?>

  </script>
</body>
</html>