<?php if ($_GET['page'] == 'documentList'){  ?>
<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_TITLE']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php while ($allDocumentCheck=$allDocumentAsk->fetch(PDO::FETCH_ASSOC)){ ?>
          <tr>
            <td><?php echo $allDocumentCheck['order_sort']; ?></td>
            <td><?php echo $allDocumentCheck['name']; ?></td>
            <td>
              <?php if ($allDocumentCheck['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=documentEdit&document_id=<?php echo $allDocumentCheck['document_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
               <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allDocumentCheck['document_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
               <div class="modal fade" id="dataDelete-<?php echo $allDocumentCheck['document_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?document_id=<?php echo $allDocumentCheck['document_id']; ?>&image=<?php echo $allDocumentCheck['image']; ?>&documentDelete=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'] == 'documentAdd'){  ?>
<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="name"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                <input type="text" name="name" class="form-control">
              </div>
              <!-- #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[]" value="" checked data-bootstrap-switch data-off-color="danger" data-on-color="success">
                </div>
              </div>
              <!-- #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 $documentCount+1; ?>">
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="documentList" 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="documentAdd">
          </div>
          <div class="clearfix"></div>
        </div>
          <div class="col-md-8">
            <div class="card card-primary">
              <div class="card-body">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="image"><?php echo $langArray['GLOBAL_FORM_TABLE_LINK']; ?></label>
                  <div class="input-group">
                    <div class="custom-file">
                      <input type="file" name="image" class="custom-file-input">
                      <label class="custom-file-label"><?php echo $langArray['TABLE_CHOOSE_FILE']; ?></label>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'documentEdit'){  ?>
<?php
  $askData=$db->prepare("SELECT * FROM document where document_id=:document_id");
  $askData->execute(array(
    'document_id' => $_GET["document_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['document_id'] == null) {
    Header("Location:documentList");
  }elseif($_GET['document_id'] != $checkData['document_id']){
    Header("Location:documentList");
  }
?>
<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="document_id" value="<?=$checkData["document_id"] ?>">
      <input type="hidden" name="image" value="<?=$checkData["image"] ?>">
      <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="name"><?php echo $langArray['GLOBAL_FORM_TABLE_TITLE']; ?></label>
                <input type="text" name="name" class="form-control" value="<?php echo $checkData['name']; ?>">
              </div>
              <!-- #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[]" value="" <?php echo $checkData['status'] == "1" ? 'checked=""' : ''; ?> data-bootstrap-switch data-off-color="danger" data-on-color="success">
                </div>
              </div>
              <!-- #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 class="col-12">
            <a href="documentList" 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="documentUpdate">
          </div>
          <div class="clearfix"></div>
        </div>
          <div class="col-md-8">
            <div class="card card-primary">
              <div class="card-body">
                <!-- #form-group -->
                <div class="form-group">
                  <label for="image"><?php echo $langArray['GLOBAL_FORM_TABLE_LINK']; ?></label>
                  <div class="input-group">
                    <div class="custom-file">
                      <input type="file" name="image" class="custom-file-input">
                      <label class="custom-file-label"><?php echo $langArray['TABLE_CHOOSE_FILE']; ?></label>
                    </div>
                  </div>
                </div>
                <!-- #form-group -->
                <div class="form-group">
                  <img src="<?php echo $checkData['image']; ?>" class="img-responsive">
                </div>
              </div>
            </div>
          </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php } ?>
