<?php 
include '../connection.php'; 
if(!isset($_SESSION)) session_start();
if(!isset($_SESSION["ID"])){header('Location: index.php');}

$flag = true;
$errors = array();
$errorList = "";
$ar_about = isset($_POST["ar_about"]) ? $_POST["ar_about"] : "";
$en_about = isset($_POST["en_about"]) ? $_POST["en_about"] : "";
$ar_imageapp = isset($_POST["ar_imageapp"]) ? $_POST["ar_imageapp"] : "";
$en_imageapp = isset($_POST["en_imageapp"]) ? $_POST["en_imageapp"] : "";
$ar_downloadios = isset($_POST["ar_downloadios"]) ? $_POST["ar_downloadios"] : "";
$en_downloadios = isset($_POST["en_downloadios"]) ? $_POST["en_downloadios"] : "";
$ar_downloadandroid = isset($_POST["ar_downloadandroid"]) ? $_POST["ar_downloadandroid"] : "";
$en_downloadandroid = isset($_POST["en_downloadandroid"]) ? $_POST["en_downloadandroid"] : "";
if(isset($_POST["save"]))
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    { 
      //nothing
    }
    else
    {
      header( 'Location: show-app.php');
    }
    if(empty($ar_about) || empty($en_about) ||
       empty($ar_imageapp) || empty($en_imageapp) ||
       empty($ar_downloadios) || empty($en_downloadios) ||
       empty($ar_downloadandroid) || empty($en_downloadandroid))
    {
        $errors["empty"] = "يرجى تعبئة جميع الحقول";
        $flag = false; 
    }  //check if any textbox empty
    
  if($flag === true)
  {
    $updateSql = "update app_ar set about_app='{$ar_about}',image_app='{$ar_imageapp}',download_app_ios='{$ar_downloadios}',download_app_android='{$ar_downloadandroid}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $updateSql = "update app_en set about_app='{$en_about}',image_app='{$en_imageapp}',download_app_ios='{$en_downloadios}',download_app_android='{$en_downloadandroid}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $_SESSION["updatesuccessapp"] = 1;
    header( 'Location: show-app.php');
  }
  else
  {
    foreach($errors as $error)
    {
      $errorList .= $error."<br>";
    }
  }
}
$sqlretriveAR = "select ID,about_app,image_app,download_app_ios,download_app_android from app_ar";
$executeSqlAR = mysqli_query($connection,$sqlretriveAR);
$retriveDataAR = mysqli_fetch_row($executeSqlAR);
$sqlretriveEN = "select ID,about_app,image_app,download_app_ios,download_app_android from app_en";
$executeSqlEN = mysqli_query($connection,$sqlretriveEN);
$retriveDataEN = mysqli_fetch_row($executeSqlEN);
?>
<!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'; ?>
    <style>
    .drag-text h1
    {
        padding: 30px 0;
    }
    </style>
  </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-8'>
            <?php
            if($flag === false)
            {
            echo "
            <div class='alert alert-danger text-right'>
            $errorList
            </div>";
            }
        ?>
            <div class="card text-right" id="add-info">
                <div class="card-header"><h3>تعديل عن التطبيق</h3></div>
                <div class="card-body">
                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post' enctype="multipart/form-data">
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label class='ar-info' for="ar-info">المعلومات باللغة العربية</label>                        
                        </div>
                        <!-- end form group -->

                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">عن التطبيق</label>
                            <textarea name="ar_about" rows="2" class="form-control" style='resize:none'><?php echo $retriveDataAR[1];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">صور التطبيق</label>
                            <textarea name="ar_imageapp" rows="2" class="form-control" style='resize:none'><?php echo $retriveDataAR[2];?></textarea>
                        </div>
                        <!-- end form group -->

                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">حمل التطبيق <small>ios</small></label>
                            <textarea name="ar_downloadios" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataAR[3];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">حمل التطبيق <small>android</small></label>
                            <textarea name="ar_downloadandroid" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataAR[4];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class="form-row">
                        <div class='form-group col'>
                            <label class='en-info' for="en-info">المعلومات باللغة الإنجليزية</label>                        
                        </div>
                        <!-- end form group -->
                    </div>

                    <div class="form-row">
                    <div class='form-group col'>
                            <label for="en-label">عن التطبيق</label>
                            <textarea name="en_about" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataEN[1];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <div class="form-row">
                    <div class='form-group col'>
                            <label for="en-label">صور التطبيق</label>
                            <textarea name="en_imageapp" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataEN[2];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <div class="form-row">
                    <div class='form-group col'>
                            <label for="en-label">حمل التطبيق  <small>ios</small></label>
                            <textarea name="en_downloadios" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataEN[3];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <div class="form-row">
                    <div class='form-group col'>
                            <label for="en-label">حمل التطبيق  <small>android</small></label>
                            <textarea name="en_downloadandroid" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataEN[4];?></textarea>
                        </div>
                        <!-- end form group -->
                    </div>
                    <div class="form-row">
                        <div class="form-group col text-center">
                            <button type="submit" name="save" class="save-image">حفظ</button>
                        </div>
                    </div>
                    </form>
                    <!-- End form -->
                </div>
                <!-- End card-body -->
            </div>
            <!-- End Card -->
        </div>
        <!-- end col -->
    </div>
    <!-- end row -->
</div>
<!-- end container -->
</div>
<!-- End content body -->
<!-- assets / js -->
    <?php include 'jsFile.php'; ?>

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