<?php if ($_GET['page'] == 'referenceList'){ ?>
<div class="card">
  <div class="card-body table-responsive">
    <table id="dataTable" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th><?php echo $langArray['TABLE_ORDER_SORT']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_CATEGORIES']; ?></th>
          <th><?php echo $langArray['TABLE_IMAGE']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php while ($allRefCheck=$allRefAsk->fetch(PDO::FETCH_ASSOC)){ ?>
          <tr>
            <td><?php echo $allRefCheck['order_sort']; ?></td>
            <td>
              <?php
                // All Reference Category List
                $refCatAsk=$db->prepare("SELECT * FROM categories where categories_id=:categories_id");
                $refCatAsk->execute(array(
                  'categories_id' => $allRefCheck['categories']
                ));
                $refCatCheck=$refCatAsk->fetch(PDO::FETCH_ASSOC);
                echo $refCatCheck['title'];
               ?>
            </td>
            <td><img src="../<?php echo $allRefCheck['banner']; ?>" width="60"></td>
            <td><?php echo $allRefCheck['name']; ?></td>
            <td>
              <?php if ($allRefCheck['status']== 1){ ?>
                <i class="fas fa-eye text-success"></i>
              <?php }else{ ?>
                <i class="fas fa-eye-slash text-danger"></i>
              <?php } ?>
            </td>
            <td>
               <a class="btn btn-light" href="index.php?page=referenceEdit&reference_id=<?php echo $allRefCheck['reference_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
               <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allRefCheck['reference_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
               <div class="modal fade" id="dataDelete-<?php echo $allRefCheck['reference_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?reference_id=<?php echo $allRefCheck['reference_id']; ?>&banner=<?php echo $allRefCheck['banner']; ?>&referenceDelete=success" class="btn btn-outline-light"><?php echo $langArray['TABLE_DELETE']; ?></a>
                     </div>
                   </div>
                 </div>
               </div>
            </td>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <th><?php echo $langArray['TABLE_ORDER_SORT']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_CATEGORIES']; ?></th>
          <th><?php echo $langArray['TABLE_IMAGE']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>
<?php }elseif($_GET['page'] == 'referenceAdd'){ ?>
<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"] ?>">
      <div class="row">
        <div class="col-md-12">
          <div class="card card-secondary">
            <div class="card-body row">
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="categories"><?php echo $langArray['GLOBAL_FORM_TABLE_CATEGORIES']; ?></label>
                  <select class="form-control select2" name="categories">
                    <?php
                      $allCategoriesAsk->execute(array(
                        'categories_type' => "reference_categories",
                        'language'        => $getLangCheck['language_id']
                      ));
                      while ($allCategoriesCheck=$allCategoriesAsk->fetch(PDO::FETCH_ASSOC)){
                    ?>
                      <option value="<?php echo $allCategoriesCheck['categories_id']; ?>"><?php echo $allCategoriesCheck['title']; ?></option>
                    <?php } ?>
                  </select>
                </div>
              </div>
              <div class="col-md-6">
                <!-- #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>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="name"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                  <input type="text" name="name" class="form-control">
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="link"><?php echo $langArray['GLOBAL_FORM_TABLE_LINK']; ?></label>
                  <input type="text" name="link" class="form-control">
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="status"><?php echo $langArray['TABLE_STATUS']; ?></label>
                  <div class="input-group">
                    <input type="checkbox" id="status" name="status[]" checked data-bootstrap-switch data-off-color="danger" data-on-color="success">
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="order_sort"><?php echo $langArray['TABLE_ORDER_SORT']; ?></label>
                  <input type="number" name="order_sort" class="form-control" value="<?php echo $referenceCount+1; ?>">
                </div>
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="referenceList" 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="referenceAdd">
          </div>
          <div class="clearfix"></div>
        </div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'referenceEdit'){ ?>
<?php
  $askData=$db->prepare("SELECT * FROM reference where reference_id=:reference_id");
  $askData->execute(array(
    'reference_id' => $_GET["reference_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['reference_id'] == null) {
    Header("Location:referenceList");
  }elseif($_GET['reference_id'] != $checkData['reference_id']){
    Header("Location:referenceList");
  }
?>
<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="reference_id" value="<?=$checkData["reference_id"] ?>">
      <input type="hidden" name="isset_banner" value="<?=$checkData["banner"] ?>">
      <div class="row">
        <div class="col-md-12">
          <div class="card card-secondary">
            <div class="card-body row">
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="categories"><?php echo $langArray['GLOBAL_FORM_TABLE_CATEGORIES']; ?></label>
                  <select class="form-control select2" name="categories">
                    <?php
                      $allCategoriesAsk->execute(array(
                        'categories_type' => "reference_categories",
                        'language'        => $getLangCheck['language_id']
                      ));
                      while ($allCategoriesCheck=$allCategoriesAsk->fetch(PDO::FETCH_ASSOC)){
                    ?>
                      <option <?php echo $checkData['categories'] == $allCategoriesCheck['categories_id'] ? 'selected=""' : ''; ?> value="<?php echo $allCategoriesCheck['categories_id']; ?>"><?php echo $allCategoriesCheck['title']; ?></option>
                    <?php } ?>
                  </select>
                </div>
              </div>
              <div class="col-md-6">
                <!-- #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>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="name"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                  <input type="text" name="name" class="form-control" value="<?php echo $checkData['name'] ?>">
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="link"><?php echo $langArray['GLOBAL_FORM_TABLE_LINK']; ?></label>
                  <input type="text" name="link" class="form-control" value="<?php echo $checkData['link'] ?>">
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="status"><?php echo $langArray['TABLE_STATUS']; ?></label>
                  <div class="input-group">
                    <input type="checkbox" id="status" name="status[]" <?php echo $checkData['status'] == "1" ? 'checked=""' : ''; ?> data-bootstrap-switch data-off-color="danger" data-on-color="success">
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="order_sort"><?php echo $langArray['TABLE_ORDER_SORT']; ?></label>
                  <input type="number" name="order_sort" class="form-control" value="<?php echo $checkData['order_sort'] ?>">
                </div>
              </div>
              <div class="col-md-12">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="image"><?php echo $langArray['TABLE_IMAGE']; ?></label>
                  <img src="../<?php echo $checkData['banner'] ?>" width="250">
                </div>
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="referenceList" 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="referenceUpdate">
          </div>
          <div class="clearfix"></div>
        </div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'referenceCategoriesList'){ ?>
<div class="card">
  <div class="card-body">
    <table id="dataTable" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th><?php echo $langArray['TABLE_ORDER_SORT']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php
          $allCategoriesAsk->execute(array(
            'categories_type' => "reference_categories",
            'language'        => $getLangCheck['language_id']
          ));
         while ($allCategoriesCheck=$allCategoriesAsk->fetch(PDO::FETCH_ASSOC)){
         ?>
          <tr>
            <td><?php echo $allCategoriesCheck['order_sort']; ?></td>
            <td><?php echo $allCategoriesCheck['title']; ?></td>
            <td>
              <?php if ($allCategoriesCheck['status']== 1){ ?>
                <i class="fas fa-eye text-success"></i>
              <?php }else{ ?>
                <i class="fas fa-eye-slash text-danger"></i>
              <?php } ?>
            </td>
            <td>
               <a class="btn btn-light" href="index.php?page=referenceCategoriesEdit&categories_id=<?php echo $allCategoriesCheck['categories_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
               <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allCategoriesCheck['categories_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
               <div class="modal fade" id="dataDelete-<?php echo $allCategoriesCheck['categories_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?categories_id=<?php echo $allCategoriesCheck['categories_id']; ?>&referenceCategoriesDelete=success" class="btn btn-outline-light"><?php echo $langArray['TABLE_DELETE']; ?></a>
                     </div>
                   </div>
                 </div>
               </div>
            </td>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <th><?php echo $langArray['TABLE_ORDER_SORT']; ?></th>
          <th><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>
<?php }elseif($_GET['page'] == 'referenceCategoriesAdd'){ ?>
<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"] ?>">
      <div class="row">
        <div class="col-md-4">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #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>
            </div>
          </div>
          <div class="col-12">
            <a href="referenceCategoriesList" 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="referenceCategoriesAdd">
          </div>
          <div class="clearfix"></div>
        </div>
        <div class="col-md-8">
          <div class="card card-primary">
            <div class="card-body">
              <div class="row">
                <div class="col-md-6">
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="status"><?php echo $langArray['TABLE_STATUS']; ?></label>
                    <div class="input-group">
                      <input type="checkbox" id="status" name="status[]" checked data-bootstrap-switch data-off-color="danger" data-on-color="success">
                    </div>
                  </div>
                </div>
                <div class="col-md-6">
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="order_sort"><?php echo $langArray['TABLE_ORDER_SORT']; ?></label>
                    <input type="number" name="order_sort" class="form-control" value="<?php echo $referenceCategoriesCount+1 ?>">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'referenceCategoriesEdit'){ ?>
<?php
  $askData=$db->prepare("SELECT * FROM categories where categories_id=:categories_id");
  $askData->execute(array(
    'categories_id' => $_GET["categories_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);
  $foo = $checkData["categories_top_id"];
  // $_GET null or nothing
  if ($_GET['categories_id'] == null) {
    Header("Location:categoriesList");
  }elseif($_GET['categories_id'] != $checkData['categories_id']){
    Header("Location:categoriesList");
  }
?>
<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="categories_id" value="<?=$checkData["categories_id"] ?>">
      <div class="row">
        <div class="col-md-4">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #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>
            </div>
          </div>
          <div class="col-12">
            <a href="referenceCategoriesList" 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="referenceCategoriesUpdate">
          </div>
          <div class="clearfix"></div>
        </div>
        <div class="col-md-8">
          <div class="card card-primary">
            <div class="card-body">
              <div class="row">
                <div class="col-md-6">
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="status"><?php echo $langArray['TABLE_STATUS']; ?></label>
                    <div class="input-group">
                      <input type="checkbox" id="status" name="status[]" <?php echo $checkData['status'] == "1" ? 'checked=""' : ''; ?> data-bootstrap-switch data-off-color="danger" data-on-color="success">
                    </div>
                  </div>
                </div>
                <div class="col-md-6">
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="order_sort"><?php echo $langArray['TABLE_ORDER_SORT']; ?></label>
                    <input type="number" name="order_sort" class="form-control" value="<?php echo $checkData['order_sort'] ?>">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php } ?>
