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

$flag = true;
$errors = array();
$errorList = "";
$phone_ar = isset($_POST["phone_ar"]) ? $_POST["phone_ar"] : "";
$mobile_ar = isset($_POST["mobile_ar"]) ? $_POST["mobile_ar"] : "";
$email_ar = isset($_POST["email_ar"]) ? $_POST["email_ar"] : "";
$location_ar = isset($_POST["location_ar"]) ? $_POST["location_ar"] : "";
$accountNumber_ar = isset($_POST["accountNumber_ar"]) ? $_POST["accountNumber_ar"] : "";
$iban_ar = isset($_POST["iban_ar"]) ? $_POST["iban_ar"] : "";

$phone_en = isset($_POST["phone_en"]) ? $_POST["phone_en"] : "";
$mobile_en = isset($_POST["mobile_en"]) ? $_POST["mobile_en"] : "";
$email_en = isset($_POST["email_en"]) ? $_POST["email_en"] : "";
$location_en = isset($_POST["location_en"]) ? $_POST["location_en"] : "";
$accountNumber_en = isset($_POST["accountNumber_en"]) ? $_POST["accountNumber_en"] : "";
$iban_en = isset($_POST["iban_en"]) ? $_POST["iban_en"] : "";

if(isset($_POST["save"]))
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    { 
      //nothing
    }
    else
    {
        header( 'Location: show-manager.php');
    }
    if(empty($phone_ar) || empty($mobile_ar) ||
       empty($email_ar) || empty($location_ar) ||
       empty($accountNumber_ar) || empty($iban_ar)||
       empty($phone_en) || empty($mobile_en) ||
       empty($email_en) || empty($location_en) ||
       empty($accountNumber_en) || empty($iban_en)
       )
    {
        $errors["empty"] = "يرجى تعبئة جميع الحقول";
        $flag = false; 
    }  //check if any textbox empty
    
  if($flag === true)
  {
    $updateSql = "UPDATE manager_ar SET phone='{$phone_ar}',mobile='{$mobile_ar}',email='{$email_ar}',location='{$location_ar}',accountNumber='{$accountNumber_ar}',ibanNumber='{$iban_ar}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $updateSql = "UPDATE manager_en SET phone='{$phone_en}',mobile='{$mobile_en}',email='{$email_en}',location='{$location_en}',accountNumber='{$accountNumber_en}',ibanNumber='{$iban_en}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $_SESSION["updatesuccessmanager"] = 1;
    header( 'Location: show-manager.php');
  }
  else
  {
    foreach($errors as $error)
    {
      $errorList .= $error."<br>";
    }
  }
}
$sqlretriveAR = "select ID,phone,mobile,email,location,accountNumber,ibanNumber from manager_ar";
$executeSqlAR = mysqli_query($connection,$sqlretriveAR);
$retriveDataAR = mysqli_fetch_row($executeSqlAR);
$sqlretriveEN = "select ID,phone,mobile,email,location,accountNumber,ibanNumber from manager_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'>
                    <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>
                            <input type="text" class='form-control' name='phone_ar' value='<?php echo $retriveDataAR[1]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">الهاتف</label>
                            <input type="text" class='form-control' name='mobile_ar' value='<?php echo $retriveDataAR[2]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">البريد الإلكتروني</label>
                            <input type="email" class='form-control' name='email_ar' value='<?php echo $retriveDataAR[3]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">موقعنا</label>
                            <input type="text" class='form-control' name='location_ar' value='<?php echo $retriveDataAR[4]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">رقم الحساب</label>
                            <input type="text" class='form-control' name='accountNumber_ar' value='<?php echo $retriveDataAR[5]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">الرقم الدولي للحساب البنكي</label>
                            <input type="text" class='form-control' name='iban_ar' value='<?php echo $retriveDataAR[6]?>'>
                        </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="ar-label">موبايل</label>
                            <input type="text" class='form-control' name='phone_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[1]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">الهاتف</label>
                            <input type="text" class='form-control' name='mobile_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[2]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">البريد الإلكتروني</label>
                            <input type="email" class='form-control' name='email_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[3]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">موقعنا</label>
                            <input type="text" class='form-control' name='location_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[4]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">رقم الحساب</label>
                            <input type="text" class='form-control' name='accountNumber_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[5]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <div class='form-row'>
                        <div class='form-group col'>
                            <label for="ar-label">الرقم الدولي للحساب البنكي</label>
                            <input type="text" class='form-control' name='iban_en' style='text-align:left;direction:ltr;' value='<?php echo $retriveDataEN[6]?>'>
                        </div>
                        <!-- end form group -->
                    </div>
                    <!-- end form row -->
                    <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()" -->
