<?php if ($_GET['page'] == 'usersList'){ ?>
<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['TABLE_IMAGE']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_NAME']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_LASTNAME']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_EMAIL']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php
         $lineNumber=0;
         while ($allUserCheck=$allUsersAsk->fetch(PDO::FETCH_ASSOC)){ $lineNumber++
        ?>
          <tr>
            <td><?php echo $lineNumber ?></td>
            <td><img alt="Avatar" class="img-circle" width="30" src="../<?php echo $allUserCheck['image']; ?>"></td>
            <td><?php echo $allUserCheck['firstname']; ?></td>
            <td><?php echo $allUserCheck['lastname']; ?></td>
            <td><?php echo $allUserCheck['email']; ?></td>
            <?php if($allUserCheck['user_id'] == 1){ ?>
              <td>
                <a class="btn btn-light" href="index.php?page=usersEdit&user_id=<?php echo $allUserCheck['user_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
              </td>
            <?php }else{ ?>
              <td>
                <a class="btn btn-light" href="index.php?page=usersEdit&user_id=<?php echo $allUserCheck['user_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
                <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allUserCheck['user_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
                <div class="modal fade" id="dataDelete-<?php echo $allUserCheck['user_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?user_id=<?php echo $allUserCheck['user_id']; ?>&image=<?php echo $allUserCheck['image']; ?>&usersDelete=success" class="btn btn-outline-light"><?php echo $langArray['TABLE_DELETE']; ?></a>
                      </div>
                    </div>
                  </div>
                </div>
              </td>
            <?php } ?>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <th>#</th>
          <th><?php echo $langArray['TABLE_IMAGE']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_NAME']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_LASTNAME']; ?></th>
          <th><?php echo $langArray['USERS_TABLE_FIRST_EMAIL']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>
<?php }elseif($_GET['page'] == 'userAdd'){ ?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post" enctype="multipart/form-data" data-parsley-validate>
      <div class="row">
        <div class="col-md-8">
          <div class="card card-primary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="firstname"><?php echo $langArray['USERS_TABLE_FIRST_NAME']; ?></label>
                <input type="text" name="firstname" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="lastname"><?php echo $langArray['USERS_TABLE_FIRST_LASTNAME']; ?></label>
                <input type="text" name="lastname" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="email"><?php echo $langArray['USERS_TABLE_FIRST_EMAIL']; ?></label>
                <input type="text" name="email" class="form-control">
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="password"><?php echo $langArray['USERS_TABLE_PASSWORD']; ?></label>
                <input type="password" name="password" class="form-control">
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="usersList" 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="userAdd">
          </div>
        </div>
        <div class="col-md-4">
          <div class="card card-secondary">
            <div class="card-body">
              <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="upload_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'] == 'usersEdit'){ ?>
<?php
  $askData=$db->prepare("SELECT * FROM user where user_id=:user_id");
  $askData->execute(array(
    'user_id' => $_GET["user_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['user_id'] == null) {
    Header("Location:usersList");
  }elseif($_GET['user_id'] != $checkData['user_id']){
    Header("Location:usersList");
  }
?>
<div class="card">
  <div class="card-body">
    <div class="row">
      <div class="col-md-8">
        <form action="system/operation.php" method="post">
          <input type="hidden" name="user_id" value="<?=$checkData["user_id"] ?>">
          <div class="row">
            <div class="col-md-12">
              <div class="card card-warning">
                <div class="card-body">
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="firstname"><?php echo $langArray['USERS_TABLE_FIRST_NAME']; ?></label>
                    <input type="text" name="firstname" class="form-control" value="<?php echo $checkData['firstname']; ?>">
                  </div>
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="lastname"><?php echo $langArray['USERS_TABLE_FIRST_LASTNAME']; ?></label>
                    <input type="text" name="lastname" class="form-control" value="<?php echo $checkData['lastname']; ?>">
                  </div>
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="email"><?php echo $langArray['USERS_TABLE_FIRST_EMAIL']; ?></label>
                    <input type="text" name="email" class="form-control" value="<?php echo $checkData['email']; ?>">
                  </div>
                  <!-- #form-group -->
                  <div class="form-group">
                    <label for="password"><?php echo $langArray['USERS_TABLE_PASSWORD']; ?></label>
                    <input type="password" name="password" class="form-control" autocomplete="new-password">
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-12">
              <a href="usersList" 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="userUpdate">
            </div>
            <div class="clearfix"></div>
          </div>
        </form>
      </div>
      <div class="col-md-4">
        <form class="" action="system/operation.php" method="post" enctype="multipart/form-data" data-parsley-validate>
          <input type="hidden" name="user_id" value="<?=$checkData["user_id"] ?>">
          <input type="hidden" name="image" value="<?=$checkData["image"] ?>">
          <div class="card card-secondary">
            <div class="card-body">
              <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="upload_image" class="custom-file-input">
                    <label class="custom-file-label"><?php echo $langArray['TABLE_CHOOSE_FILE']; ?></label>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <?php if ($checkData['image'] != null) { ?>
                  <img src="../<?php echo $checkData['image']; ?>" class="img-responsive">
                <?php } ?>
              </div>
              <div class="form-group">
                <input type="submit" value="<?php echo $langArray['UPDATE_FORM']; ?>" class="btn btn-warning float-right" name="userImageUpdate">
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<?php } ?>
