<?php if ($_GET['page'] == 'languageList'){  ?>
<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['LANG_TABLE_LANG']; ?></th>
          <th><?php echo $langArray['LANG_TABLE_FLAG']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </thead>
      <tbody>
        <?php
         while ($allLangCheck=$allLangAsk->fetch(PDO::FETCH_ASSOC)){
           $langCodeAsk=$db->prepare("SELECT * FROM countries where alpha=:alpha");
           $langCodeAsk->execute(array(
             'alpha' => $allLangCheck['country_code']
           ));
           $langCodeCheck=$langCodeAsk->fetch(PDO::FETCH_ASSOC);
        ?>
          <tr>
            <td><?php echo $allLangCheck['order_sort']; ?></td>
            <td>
              <?php
               echo $langCodeCheck['country'];
              ?>
            </td>
            <td><i class='flag-icon flag-icon-<?php echo $allLangCheck['country_code'] ?> mr-2'></i></td>
            <td class="text-center">
              <?php if ($allLangCheck['status']== 1){ ?>
                <i class="fas fa-eye text-success"></i>
              <?php }else{ ?>
                <i class="fas fa-eye-slash text-danger"></i>
              <?php } ?>
            </td>
            <?php if($allLangCheck['country_code'] == "tr"){ ?>
              <td><a class="btn btn-light" href="index.php?page=languageEdit&language_id=<?php echo $allLangCheck['language_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a></td>
            <?php }else{ ?>
              <td>
                 <a class="btn btn-light" href="index.php?page=languageEdit&language_id=<?php echo $allLangCheck['language_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
                 <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allLangCheck['language_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
                 <div class="modal fade" id="dataDelete-<?php echo $allLangCheck['language_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?language_id=<?php echo $allLangCheck['language_id']; ?>&country_code=<?php echo $allLangCheck['country_code']; ?>&langDelete=success" class="btn btn-outline-light"><?php echo $langArray['TABLE_DELETE']; ?></a>
                       </div>
                     </div>
                   </div>
                 </div>
              </td>
            <?php } ?>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <th><?php echo $langArray['TABLE_ORDER_SORT']; ?></th>
          <th><?php echo $langArray['LANG_TABLE_LANG']; ?></th>
          <th><?php echo $langArray['LANG_TABLE_FLAG']; ?></th>
          <th><?php echo $langArray['TABLE_STATUS']; ?></th>
          <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>
<?php }elseif($_GET['page'] == 'languageAdd'){  ?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post">
      <div class="row">
        <div class="col-md-4">
          <div class="card card-primary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="inputName"><?php echo $langArray['LANG_FORM_COUNTRY']; ?></label>
                <select class="form-control select2" name="country_code">
                  <?php while ($countryCheck=$countryAsk->fetch(PDO::FETCH_ASSOC)){?>
                    <option value="<?php echo $countryCheck['alpha']; ?>"><?php echo $countryCheck['country']; ?></option>
                  <?php } ?>
                </select>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="inputName"><?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="inputName"><?php echo $langArray['TABLE_ORDER_SORT']; ?></label>
                <input type="number" name="order_sort" class="form-control" value="<?php echo $languageCount+1; ?>">
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="languageList" 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="langAdd">
          </div>
        </div>
        <div class="col-md-8">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <textarea id="codemirror" name="docs" rows="20" class="form-control"><?php $content = file_get_contents('lang/tr.php'); echo $content; ?></textarea>
              </div>
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'languageEdit'){  ?>
<?php
  $askData=$db->prepare("SELECT * FROM language where language_id=:language_id");
  $askData->execute(array(
    'language_id' => $_GET["language_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['language_id'] == null) {
    Header("Location:languageList");
  }elseif($_GET['language_id'] != $checkData['language_id']){
    Header("Location:languageList");
  }
?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post">
      <input type="hidden" name="language_id" value="<?=$checkData["language_id"] ?>">
      <div class="row">
        <div class="col-md-4">
          <div class="card card-warning">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="inputName"><?php echo $langArray['LANG_FORM_COUNTRY']; ?></label>
                <select class="form-control select2" name="country_code">
                  <?php while ($countryCheck=$countryAsk->fetch(PDO::FETCH_ASSOC)){?>
                    <option <?php echo $countryCheck['alpha'] == $checkData["country_code"] ? 'selected=""' : ''; ?> value="<?php echo $countryCheck['alpha']; ?>"><?php echo $countryCheck['country']; ?></option>
                  <?php } ?>
                </select>
              </div>
              <!-- #form-group -->
              <div class="form-group">
                <label for="inputName"><?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="inputName"><?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="languageList" 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="langUpdate">
          </div>
        </div>
        <div class="col-md-8">
          <div class="card card-secondary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <textarea id="codemirror" name="docs" rows="20" class="form-control"><?php $content = file_get_contents('lang/'.$checkData['country_code'].'.php'); echo $content; ?></textarea>
              </div>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<?php } ?>
