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

$flag = true;
$errors = array();
$errorList = "";
$ar_company = isset($_POST["ar_company"]) ? $_POST["ar_company"] : "";
$en_company = isset($_POST["en_company"]) ? $_POST["en_company"] : "";
$ar_bank = isset($_POST["ar_bank"]) ? $_POST["ar_bank"] : "";
$en_bank = isset($_POST["en_bank"]) ? $_POST["en_bank"] : "";
$ar_denark = isset($_POST["ar_denark"]) ? $_POST["ar_denark"] : "";
$en_denark = isset($_POST["en_denark"]) ? $_POST["en_denark"] : "";
$ar_Financial = isset($_POST["ar_Financial"]) ? $_POST["ar_Financial"] : "";
$en_Financial = isset($_POST["en_Financial"]) ? $_POST["en_Financial"] : "";

if(isset($_POST["save"]))
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST')
    { 
      //nothing
    }
    else
    {
        header( 'Location: show-donate.php');
    }
    if(empty($ar_company) || empty($en_company) ||
       empty($ar_bank) || empty($en_bank) ||
       empty($ar_denark) || empty($en_denark)||
       empty($ar_Financial) || empty($en_Financial)
       )
    {
        $errors["empty"] = "يرجى تعبئة جميع الحقول";
        $flag = false; 
    }  //check if any textbox empty
    
  if($flag === true)
  {
    $updateSql = "UPDATE donate_ar set company='{$ar_company}',bank='{$ar_bank}',denark='{$ar_denark}',Financialcollection='{$ar_Financial}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $updateSql = "UPDATE donate_en set company='{$en_company}',bank='{$en_bank}',denark='{$en_denark}',Financialcollection='{$en_Financial}'";
    $executeSql = mysqli_query($connection,$updateSql);
    $_SESSION["updatesuccessapp"] = 1;
    header( 'Location: show-donate.php');
  }
  else
  {
    foreach($errors as $error)
    {
      $errorList .= $error."<br>";
    }
  }
}
$sqlretriveAR = "select ID,company,bank,denark,Financialcollection from donate_ar";
$executeSqlAR = mysqli_query($connection,$sqlretriveAR);
$retriveDataAR = mysqli_fetch_row($executeSqlAR);
$sqlretriveEN = "select ID,company,bank,denark,Financialcollection from donate_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_Financial" rows="2" class="form-control" style='resize:none'><?php echo $retriveDataAR[4];?></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_company" 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_bank" 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">عن طريق دينارك</label>
                            <textarea name="ar_denark" rows="2" class="form-control" style='resize:none'><?php echo $retriveDataAR[3];?></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="ar-label">تحصيل مالي</label>
                            <textarea name="en_Financial" rows="2" class="form-control" style='resize:none;text-align:left;direction:ltr'><?php echo $retriveDataEN[4];?></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="en_company" 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="ar-label">عن طريق البنك</label>
                            <textarea name="en_bank" 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="ar-label">عن طريق دينارك</label>
                            <textarea name="en_denark" 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 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()" -->
