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

if(!isset($_POST["table"]))
{
  header('Loaction: edit-style.php');
}
if(isset($_POST["table"]) )
{
  $_SESSION["table"] = $arrLabel = $_POST["table"];
  $_SESSION["lang"] = $lang =  "ar";
}
$errors = array();
$flag = true;
$errorList = "";
$arrLabel = $_SESSION["table"];
$lang =  $_SESSION["lang"];

$arrLabel =  explode("@",$arrLabel);
$table = $arrLabel[0]."_".$lang;
$label = $arrLabel[1];

$checkItalic = "";
$checkBold = "";





if(isset($_POST["submit"]))
{
  $fontStyle = "";
  $fontWeight = "";
  if(empty($_POST["fontColor"]))
  {
    $errors["colorEmpty"] = "يجب تعئبة حقل لون الخط";
    $flag = false;
  }

  if(empty($_POST["fontStyle"]))
  {
    $fontStyle= "unset";
  }
  else
  {
    $fontStyle= $_POST["fontStyle"];

  }
  if(empty($_POST["fontWeight"]))
  {
    $fontWeight= "unset";
  }
  else
  {
    $fontWeight= $_POST["fontWeight"];
  }
  if($flag === true)
  {
    $sql="update style_en set  fontColor='{$_POST["fontColor"]}', fontFamily='{$_POST["fontFamily"]}',fontStyle='{$fontStyle}',fontWeight='{$fontWeight}' where ID={$_SESSION["idEdit"]}";
    mysqli_query($connection,$sql);
    $_SESSION["updateSuccess"] = 1;
  }
  else
  {
    foreach($errors as $error)
    {
      $errorList .= $error."<br>";
    }
  }
}
if($label == "paragraph")
{
  $_SESSION["idEdit"] = $ID = 4;
}
elseif($label == "label")
{
  $_SESSION["idEdit"] = $ID = 3;
}
elseif($label == "mainlabel")
{
  $_SESSION["idEdit"] = $ID = 5;
}
$sqlRetrive = "select * from style_en where ID = {$_SESSION["idEdit"]}";
$excueteSql = mysqli_query($connection,$sqlRetrive);
$rowSql = mysqli_fetch_row($excueteSql);
if($rowSql[3] == "italic")
{
  $checkItalic = "checked";
} 
if($rowSql[4] == "bold")
{
  $checkBold = "checked";
} 
  ?>
<!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'; ?>
  </head>
  <body dir="rtl">

<?php include 'navbar.php';?>
<div class='content-body'>
    <div class="container" style='margin-top:150px;'>
    <form action="" method='post'>
        <div class="row justify-content-center text-center">
            <div class="col-md-4">
            <?php
              if($flag === false)
              {
                echo "<div class='alert alert-danger'>{$errorList}</div>";
              }
            ?>

            <p style='margin-top:5px'>لون الخط</p>
            <input type="text" name='fontColor' class='form-control' style='direction:ltr;text-align:left' value='<?php echo $rowSql[1]?>'>
            <p style='margin-top:5px'>نوع الخط</p>
            <select name="fontFamily" id="" style='direction:ltr;text-align:left' class="form-control custom-select">
            <option value='Bebas Neue'>Bebas Neue</option>
            <option value='Solway'>Solway</option>
            <option value='Raleway'>Raleway</option>
            <option value='Tomorrow'>Tomorrow</option>
            <option value='Quicksand'>Quicksand</option>
            </select>
            <p style='margin-top:5px'>شكل الخط</p>
                <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" name='fontStyle' id="inlineCheckbox1" <?php echo $checkItalic;?> value="italic">
                <label class="form-check-label" for="inlineCheckbox1" style='margin-right:5px'>italic</label>
                </div>
                <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" name='fontWeight' id="inlineCheckbox1" <?php echo $checkBold;?> value="bold">
                <label class="form-check-label" for="inlineCheckbox1" style='margin-right:5px'>bold</label>
                </div>
                <br>
                <button type='submit' class='btn btn-primary' name='submit' style='margin-top:20px'>حفظ</button>
            </div>
        </div>
    </form>
    </div>
</div>
<!-- End content-body -->
<!-- assets / js -->
    <?php include 'jsFile.php'; ?>
  </body>
</html>
<!-- onload="reloader()" -->
