<?php
require_once('config.php');

if (isset($_POST['add_page'])) {
  // Data Array
  $page_url_get = createUlink($_POST['page_title']);

  if (getSingleValue('tt_page', 'page_url', $page_url_get, 'page_title') !='') {
    $confirm_url = $page_url_get.'-'.rand(10, 99);
  }else {
    $confirm_url = $page_url_get;
  }


  $post_form_data = array(
    "page_title"=>$_POST['page_title'],
    "page_information"=>$_POST['page_information'],
    "page_url"=>$confirm_url,
    "page_admin "=>getSingleValue('admin_user', 'admin_security_key', $_COOKIE['Google_SLKA'] , 'admin_id'),
  );
   // Insert Database
   $insert_now = InsertData('tt_page', $post_form_data);

     if ($insert_now) {
       header("Location:page-edit.php?page_id=".$insert_now);
        $tt_alert = ttAlert('success', 'Addd Page !');
      }else {
        $tt_alert = ttAlert('danger', 'Something went wrong to add Page !');
   }
}

require_once('inc/header.php');
?>
<main id="main" class="main">
  <div class="row">
    <div class="col-6 align-items-center">
      <div class="pagetitle mb-2">
        <h1><?php echo $page_title ?></h1>
      </div>
    </div>
    <div class="col-6 text-end">
        <a href="page.php" class="btn btn-primary btn-sm"><i class="bi bi-grid"></i> All Page </a>
    </div>
  </div>
    <?php echo $tt_alert ?? ''; ?>
  <section class="section mt-4">
    <div class="row">
    <div class="col-md-12">
      <div class="bg-white rounded-2 p-3">
        <form class="" action="" method="post" enctype="multipart/form-data">
          <div class="form-group mb-2">
            <label>Page Title English <span class="text-danger">*</span> </label>
            <input name="page_title" type="text" class="form-control" placeholder="Title" required>
          </div>
          <div class="form-group mb-2">
            <label>Page Content  English<span class="text-danger">*</span></label>
            <textarea name="page_information" class="form-control editor" rows="3" required> </textarea>
          </div> 
          <button type="submit" class="mt-3 btn btn-primary" name="add_page"> Publish Page</button>
        </form>
      </div>
    </div>

    </div>
  </section>
</main>
<?php require_once('inc/footer.php'); ?>
