<?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"] == "recovery")
    {
        $sql="update success_ar set status=1 where ID={$_GET["ID"]}";
        $excuteSql = mysqli_query($connection,$sql);
        $sql="update success_en set status=1 where ID={$_GET["ID"]}";
        $excuteSql = mysqli_query($connection,$sql);
        $_SESSION["recoveryStory"] = 1 ;
                header('Location: show-success.php');
    }
    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 = 0";
$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='delete-storySuccess.php?ID=$retriveData[0]&status=recovery' class='btn btn-info 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" style='margin-top:50px;'>
       <?php echo $Data; ?>
      </div>
        </div>
        <!-- End container -->
    </div>
    <!-- End content-body -->



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

</body>
</html>