<?php if ($_GET['page'] == 'branchDealerList'){  ?>
<div class="card">
  <div class="card-body">
    <div class="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['BD_TABLE_TYPE']; ?></th>
            <th><?php echo $langArray['BD_TABLE_NAME']; ?></th>
            <th><?php echo $langArray['BD_TABLE_EMAIL']; ?></th>
            <th><?php echo $langArray['BD_TABLE_PHONE']; ?></th>
            <th><?php echo $langArray['TABLE_STATUS']; ?></th>
            <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
          </tr>
        </thead>
        <tbody>
          <?php while ($allbdCheck=$allbdAsk->fetch(PDO::FETCH_ASSOC)){ ?>
            <tr>
              <td><?php echo $allbdCheck['order_sort']; ?></td>
              <td>
                <?php
                 if ($allbdCheck['type'] == 0) {
                   echo $langArray['BD_TABLE_TYPE_BRANCH'];
                 }elseif($allbdCheck['type'] == 1){
                   echo $langArray['BD_TABLE_TYPE_DEALER'];
                 }
                ?>
              </td>
              <td><?php echo $allbdCheck['name']; ?></td>
              <td><?php echo $allbdCheck['email']; ?></td>
              <td><?php echo $allbdCheck['phone']; ?></td>
              <td>
                <?php if ($allbdCheck['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=branchDealerEdit&bd_id=<?php echo $allbdCheck['bd_id'] ?>"><?php echo $langArray['TABLE_EDIT']; ?></a>
                 <a class="btn btn-danger" data-toggle="modal" data-target="#dataDelete-<?php echo $allbdCheck['bd_id'] ?>"><?php echo $langArray['TABLE_DELETE']; ?></a>
                 <div class="modal fade" id="dataDelete-<?php echo $allbdCheck['bd_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?bd_id=<?php echo $allbdCheck['bd_id']; ?>&branchDealerDelete=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['BD_TABLE_TYPE']; ?></th>
            <th><?php echo $langArray['BD_TABLE_NAME']; ?></th>
            <th><?php echo $langArray['BD_TABLE_EMAIL']; ?></th>
            <th><?php echo $langArray['BD_TABLE_PHONE']; ?></th>
            <th><?php echo $langArray['TABLE_STATUS']; ?></th>
            <th><?php echo $langArray['TABLE_OPERATION']; ?></th>
          </tr>
        </tfoot>
      </table>
    </div>
  </div>
</div>
<?php }elseif($_GET['page'] == 'branchDealerAdd'){  ?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post">
      <div class="row">
        <div class="col-md-8">
          <div class="card card-primary">
            <div class="card-body">
              <div class="row">
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="firstname"><?php echo $langArray['BD_TABLE_TYPE']; ?></label>
                    <select class="form-control select2" name="type">
                      <option value="0"><?php echo $langArray['BD_TABLE_TYPE_BRANCH']; ?></option>
                      <option value="1"><?php echo $langArray['BD_TABLE_TYPE_DEALER']; ?></option>
                    </select>
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="name"><?php echo $langArray['BD_TABLE_NAME']; ?></label>
                    <input type="text" name="name" class="form-control">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="email"><?php echo $langArray['BD_TABLE_EMAIL']; ?></label>
                    <input type="text" name="email" class="form-control">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="phone"><?php echo $langArray['BD_TABLE_PHONE']; ?></label>
                    <input type="text" name="phone" class="form-control">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <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>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <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 $branchCount+1; ?>">
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-12">
            <a href="branchDealerList" 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="branchDealerAdd">
          </div>
        </div>
        <div class="col-md-4">
          <div class="card card-primary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="firstname"><?php echo $langArray['BD_TABLE_MAP']; ?></label>
                <textarea class="form-control" name="map" rows="7"></textarea>
              </div>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<?php }elseif($_GET['page'] == 'branchDealerEdit'){  ?>
<?php
  $askData=$db->prepare("SELECT * FROM branchdealer where bd_id=:bd_id");
  $askData->execute(array(
    'bd_id' => $_GET["bd_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['bd_id'] == null) {
    Header("Location:branchDealerList");
  }elseif($_GET['bd_id'] != $checkData['bd_id']){
    Header("Location:branchDealerList");
  }
?>
<div class="card">
  <div class="card-body">
    <form action="system/operation.php" method="post">
      <input type="hidden" name="bd_id" value="<?=$checkData["bd_id"] ?>">
      <div class="row">
        <div class="col-md-8">
          <div class="card card-primary">
            <div class="card-body">
              <div class="row">
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="firstname"><?php echo $langArray['BD_TABLE_TYPE']; ?></label>
                    <select class="form-control select2" name="type">
                      <option <?php echo $checkData['type'] == "0" ? 'selected=""' : ''; ?> value="0"><?php echo $langArray['BD_TABLE_TYPE_BRANCH']; ?></option>
                      <option <?php echo $checkData['type'] == "1" ? 'selected=""' : ''; ?> value="1"><?php echo $langArray['BD_TABLE_TYPE_DEALER']; ?></option>
                    </select>
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="name"><?php echo $langArray['BD_TABLE_NAME']; ?></label>
                    <input type="text" name="name" class="form-control" value="<?php echo $checkData['name'] ?>">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="email"><?php echo $langArray['BD_TABLE_EMAIL']; ?></label>
                    <input type="text" name="email" class="form-control" value="<?php echo $checkData['email'] ?>">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <div class="form-group">
                    <label for="phone"><?php echo $langArray['BD_TABLE_PHONE']; ?></label>
                    <input type="text" name="phone" class="form-control" value="<?php echo $checkData['phone'] ?>">
                  </div>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <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>
                </div>
                <!-- #form-group -->
                <div class="col-md-6">
                  <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 class="col-12">
            <a href="branchDealerList" 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="branchDealerEdit">
          </div>
        </div>
        <div class="col-md-4">
          <div class="card card-primary">
            <div class="card-body">
              <!-- #form-group -->
              <div class="form-group">
                <label for="firstname"><?php echo $langArray['BD_TABLE_MAP']; ?></label>
                <textarea class="form-control" name="map" rows="7"><?php echo $checkData['map'] ?></textarea>
              </div>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<?php } ?>
