<?php if ($_GET['page'] == 'pagesList'){  ?>
<div class="card">
  <div class="card-body table-responsive">
    <table id="dataTable" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th>#</th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_DATE']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php
            $allPostAsk->execute(array(
              'post_type' => 'post_page',
              'language'  => $getLangCheck['language_id']
            ));
            while ($allPostCheck=$allPostAsk->fetch(PDO::FETCH_ASSOC)){
          ?>
          <tr>
            <td><?php echo $allPostCheck['post_id']; ?></td>
            <td><a target="_blank" href="<?php echo $generalSettingCheck['site_url'] . $allPostCheck['seo_url']; ?>"><?php echo $allPostCheck['title']; ?></a></td>
            <td><?php echo addAgo($allPostCheck['dates']); ?></td>
            <td>
               <a class="btn btn-light" href="index.php?page=pagesEdit&post_id=<?php echo $allPostCheck['post_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
               <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allPostCheck['post_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
               <div class="modal fade" id="dataDelete-<?php echo $allPostCheck['post_id'] ?>">
                 <div class="modal-dialog customDialog">
                   <div class="modal-content bg-danger">
                     <div class="modal-header">
                       <h4 class="modal-title"><?php echo $langArray['ARE_YOU_SURE']; ?></h4>
                     </div>
                     <div class="modal-footer justify-content-between">
                       <button type="button" class="btn btn-outline-light" data-dismiss="modal"><?php echo $langArray['CANCEL_FORM']; ?></button>
                       <a href="system/operation.php?post_id=<?php echo $allPostCheck['post_id']; ?>&banner=<?php echo $allPostCheck['banner']; ?>&pagesDelete=success" class="btn btn-outline-light"><?php echo $langArray['TABLE_DELETE']; ?></a>
                     </div>
                   </div>
                 </div>
               </div>
            </td>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <th>#</th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_DATE']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>
<?php }elseif($_GET['page'] == 'pagesAdd'){  ?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post" enctype="multipart/form-data" data-parsley-validate>
      <input type="hidden" name="language_id" value="<?=$getLangCheck["language_id"] ?>">
      <input type="hidden" name="dates" value="<?=$dates;?>">
      <input type="hidden" name="prefix" value="<?=$langArray['PREFIX_PAGE']?>">
      <div class="row">
        <div class="col-md-5">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="firstname"><?php echo $langArray['PAGES_FORM_PAGE_TEMPLATE']; ?></label>
                 <select class="select2 form-control" name="template" id="pageTemplate">
                   <option value="emptytemplate"><?php echo $langArray['FORM_DEFAULT_TEMPLATE']; ?></option>
                   <option value="branchestemplate"><?php echo $langArray['FORM_BRANCHES_TEMPLATE']; ?></option>
                   <option value="dealerstemplate"><?php echo $langArray['FORM_DEALERS_TEMPLATE']; ?></option>
                   <option value="teamtemplate"><?php echo $langArray['FORM_TEAM_TEMPLATE']; ?></option>
                   <option value="catalogstemplate"><?php echo $langArray['FORM_CATALOGS_TEMPLATE']; ?></option>
                   <option value="documentstemplate"><?php echo $langArray['FORM_DOCUMENTS_TEMPLATE']; ?></option>
                   <option value="bankaccountstemplate"><?php echo $langArray['FORM_BANKACC_TEMPLATE']; ?></option>
                   <option value="faqtemplate"><?php echo $langArray['FORM_FAQ_TEMPLATE']; ?></option>
                   <option value="servicestemplate"><?php echo $langArray['FORM_SERVICES_TEMPLATE']; ?></option>
                   <option value="producttemplate"><?php echo $langArray['FORM_PRODUCT_TEMPLATE']; ?></option>
                   <option value="projecttemplate"><?php echo $langArray['FORM_PROJECT_TEMPLATE']; ?></option>
                   <option value="blogtemplate"><?php echo $langArray['FORM_BLOG_TEMPLATE']; ?></option>
                   <option value="referencetemplate"><?php echo $langArray['FORM_REFERENCE_TEMPLATE']; ?></option>
                   <option value="gallerytemplate"><?php echo $langArray['FORM_PHOTOGALLERY_TEMPLATE']; ?></option>
                   <option value="announcementstemplate"><?php echo $langArray['FORM_ANNOUNCEMENTS_TEMPLATE']; ?></option>
                   <option value="contacttemplate"><?php echo $langArray['FORM_CONTACT_TEMPLATE']; ?></option>
                 </select>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="image"><?php echo $langArray['TABLE_IMAGE']; ?></label>
                <div class="input-group">
                  <div class="custom-file">
                    <input type="file" name="banner" class="custom-file-input"  id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
                    <label class="custom-file-label"><?php echo $langArray['TABLE_CHOOSE_FILE']; ?></label>
                  </div>
                </div>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="title"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                <input type="text" name="title" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_url"><?php echo $langArray['FORM_SEO_URL']; ?></label>
                <input type="text" name="seo_url" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_title"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_TITLE']; ?></label>
                <input type="text" name="seo_title" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_description"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_DESCRIPTION']; ?></label>
                <input type="text" name="seo_description" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_keywords"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_KEYWORDS']; ?></label>
                <input type="text" placeholder="<?php echo $langArray['WRITE_ENTER_PRESS']; ?>" name="seo_keywords" class="form-control"  data-role="tagsinput">
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="pagesList" class="btn btn-secondary"><?php echo $langArray['CANCEL_FORM']; ?></a>
            <input type="submit" value="<?php echo $langArray['CREATE_FORM']; ?>" class="btn btn-success float-right" name="pagesAdd">
          </div>
          <div class="clearfix"></div>
        </div>
        <div class="col-md-7">
            <div class="card card-primary">
              <div class="card-body">
                <!-- #form-group -->
                <div class="form-group" id="pageContent">
                  <label for="content"><?php echo $langArray['GLOBAL_FORM_TABLE_CONTENT']; ?></label>
                  <textarea class="textarea" name="content"></textarea>
                </div>
                <div class="alert alert-danger alert-dismissible" id="pageAlert">
                  <h5 class="text-info"><i class="icon fas fa-info"></i> <?php echo $langArray['FORM_ALERT_HEAD']; ?></h5>
                  <?php echo $langArray['FORM_ALERT_DESCRIPTION']; ?>
                </div>
              </div>
            </div>
          </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'pagesEdit'){  ?>
<?php
  $askData=$db->prepare("SELECT * FROM posts where post_id=:post_id");
  $askData->execute(array(
    'post_id' => $_GET["post_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['post_id'] == null) {
    Header("Location:pagesList");
  }elseif($_GET['post_id'] != $checkData['post_id']){
    Header("Location:pagesList");
  }
?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post" enctype="multipart/form-data" data-parsley-validate>
      <input type="hidden" name="post_id" value="<?=$checkData["post_id"] ?>">
      <input type="hidden" name="isset_banner" value="<?=$checkData["banner"] ?>">
      <input type="hidden" name="language_id" value="<?=$checkData["language"] ?>">
      <input type="hidden" name="prefix" value="<?=$langArray['PREFIX_PAGE']?>">
      <div class="row">
        <div class="col-md-5">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="firstname"><?php echo $langArray['PAGES_FORM_PAGE_TEMPLATE']; ?></label>
                 <select class="select2 form-control" name="template" id="pageTemplate">
                   <option <?php echo $checkData['template'] == "emptytemplate" ? 'selected=""' : ''; ?> value="emptytemplate"><?php echo $langArray['FORM_DEFAULT_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "branchestemplate" ? 'selected=""' : ''; ?> value="branchestemplate"><?php echo $langArray['FORM_BRANCHES_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "dealerstemplate" ? 'selected=""' : ''; ?> value="dealerstemplate"><?php echo $langArray['FORM_DEALERS_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "teamtemplate" ? 'selected=""' : ''; ?> value="teamtemplate"><?php echo $langArray['FORM_TEAM_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "catalogstemplate" ? 'selected=""' : ''; ?> value="catalogstemplate"><?php echo $langArray['FORM_CATALOGS_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "documentstemplate" ? 'selected=""' : ''; ?> value="documentstemplate"><?php echo $langArray['FORM_DOCUMENTS_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "bankaccountstemplate" ? 'selected=""' : ''; ?> value="bankaccountstemplate"><?php echo $langArray['FORM_BANKACC_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "faqtemplate" ? 'selected=""' : ''; ?> value="faqtemplate"><?php echo $langArray['FORM_FAQ_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "servicestemplate" ? 'selected=""' : ''; ?> value="servicestemplate"><?php echo $langArray['FORM_SERVICES_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "producttemplate" ? 'selected=""' : ''; ?> value="producttemplate"><?php echo $langArray['FORM_PRODUCT_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "projecttemplate" ? 'selected=""' : ''; ?> value="projecttemplate"><?php echo $langArray['FORM_PROJECT_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "blogtemplate" ? 'selected=""' : ''; ?> value="blogtemplate"><?php echo $langArray['FORM_BLOG_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "referencetemplate" ? 'selected=""' : ''; ?> value="referencetemplate"><?php echo $langArray['FORM_REFERENCE_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "gallerytemplate" ? 'selected=""' : ''; ?> value="gallerytemplate"><?php echo $langArray['FORM_PHOTOGALLERY_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "announcementstemplate" ? 'selected=""' : ''; ?> value="announcementstemplate"><?php echo $langArray['FORM_ANNOUNCEMENTS_TEMPLATE']; ?></option>
                   <option <?php echo $checkData['template'] == "contacttemplate" ? 'selected=""' : ''; ?> value="contacttemplate"><?php echo $langArray['FORM_CONTACT_TEMPLATE']; ?></option>
                  </select>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="image"><?php echo $langArray['TABLE_IMAGE']; ?></label>
                <div class="input-group">
                  <div class="custom-file">
                    <input type="file" name="banner" class="custom-file-input"  id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
                    <label class="custom-file-label"><?php echo $langArray['TABLE_CHOOSE_FILE']; ?></label>
                  </div>
                </div>
              </div>
              <?php if ($checkData['banner']){ ?>
              <!-- #form-group -->
              <div class="form-group">
                <label for="image"><?php echo $langArray['TABLE_IMAGE']; ?></label>
                <div class="input-group">
                  <img style="max-width:100%;" src="../<?php echo $checkData['banner']; ?>">
                </div>
              </div>
            <?php } ?>
              <!-- #form-group -->
              <div class="form-group">
                <label for="title"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                <input type="text" name="title" class="form-control" value="<?php echo $checkData['title']; ?>">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_url"><?php echo $langArray['FORM_SEO_URL']; ?></label>
                <?php $prefixDivide = explode($langArray['PREFIX_PAGE'],$checkData['seo_url']); ?>
                <div class="row">
                  <div class="col-md-3">
                    <input type="text" disabled class="form-control" value="<?php echo $langArray['PREFIX_PAGE']; ?>">
                  </div>
                  <div class="col-md-9">
                    <input type="text" name="seo_url" class="form-control" value="<?php echo $prefixDivide[1]; ?>">
                  </div>
                  <div class="clearfix"></div>
                </div>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_title"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_TITLE']; ?></label>
                <input type="text" name="seo_title" class="form-control" value="<?php echo $checkData['seo_title']; ?>">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_keywords"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_KEYWORDS']; ?></label>
                <input type="text" placeholder="<?php echo $langArray['WRITE_ENTER_PRESS']; ?>" name="seo_keywords" class="form-control" value="<?php echo $checkData['seo_keywords']; ?>" data-role="tagsinput">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="seo_description"><?php echo $langArray['GLOBAL_FORM_TABLE_SEO_DESCRIPTION']; ?></label>
                <input type="text" name="seo_description" class="form-control" value="<?php echo $checkData['seo_description']; ?>">
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="pagesList" class="btn btn-secondary"><?php echo $langArray['CANCEL_FORM']; ?></a>
            <input type="submit" value="<?php echo $langArray['UPDATE_FORM']; ?>" class="btn btn-warning float-right" name="pagesUpdate">
          </div>
          <div class="clearfix"></div>
        </div>
        <div class="col-md-7">
          <div class="card card-primary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group" id="pageContent">
                <label for="content"><?php echo $langArray['GLOBAL_FORM_TABLE_CONTENT']; ?></label>
                <textarea class="textarea" name="content"><?php echo $checkData['content']; ?></textarea>
              </div>
              <div class="alert alert-danger alert-dismissible" id="pageAlert">
                <h5 class="text-info"><i class="icon fas fa-info"></i> <?php echo $langArray['FORM_ALERT_HEAD']; ?></h5>
                <?php echo $langArray['FORM_ALERT_DESCRIPTION']; ?>
              </div>
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php } ?>
