 <!-- Main content -->
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <div class="row">
              <div class="col-sm-6">
                <h3 class="card-title">Master Desa</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                  <?php if(in_array("Tambah", $json_array[25]['sub_menu'])) { ?>
                  <a type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#staticBackdrop">Tambah</a> <?php } ?>
                </ol>
              </div>
              <!-- Modal Tambah -->
              <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <form method="post" enctype="multipart/form-data">
                      <div class="modal-header bg-primary">
                        <h5 class="modal-title" id="staticBackdropLabel">Tambah Master Desa</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <div class="row">
                          <div class="card-body pb-0">
                            <div class="form-group">
                              <label>Nama Desa</label>
                              <input type="text" class="form-control" name="nmk" required="required">
                            </div>
                            <div class="form-group">
                              <label>Nama Server</label>
                              <select class="form-control" name="ids">
                                <?php 
                                $List = new Listdata();
                                $List->set_list("data_server", $SqlDataWH);
                                foreach ($List->get_list() as $key => $value): ?>
                                <option value="<?php echo $value['id']; ?>" ><?php echo $value['nama_server']; ?></option>
                                <?php endforeach ?>
                              </select>
                            </div>
                          </div>
                        </div>
                      </div>
                      <?php if(in_array("Tambah", $json_array[25]['sub_menu'])) { ?>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <input type="submit" name="tambah" class="btn btn-primary" value="Tambah">
                      </div>
                    <?php } ?>
                    </form>
                    <?php
                    if (isset($_POST['tambah'])) 
                    {
                      $input = mysqli_query($con,"INSERT INTO master_desa (id_data_server, nama) VALUES ('$_POST[ids]','$_POST[nmk]')");
                      if ($input) 
                      {
                        sweetAlert("Data telah di tambah", "success");
                      }
                    }
                    ?>
                  </div>
                </div>
              </div>
              <!-- END Modal Tambah -->
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>Nama Server</th>
                <th>Nama Desa</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $aserver = mysqli_query($con,"SELECT * FROM master_desa $SqlDataWHId");
                while ($server = mysqli_fetch_assoc($aserver)) 
                {
              ?>
              <tr>
                <td>
                  <?php 
                    $datasv = explode("|", $server['id_data_server']);
                    foreach ($datasv as $isidata)
                    {
                      $asv = mysqli_query($con,"SELECT nama_server FROM data_server WHERE id = '$isidata'");
                      $sv = mysqli_fetch_assoc($asv);
                      echo $sv['nama_server'];
                    } 
                  ?>
                </td>
                <td><?php echo $server['nama']; ?></td>
                <td>
                  <form method="post">
                    <?php if(in_array("Ubah", $json_array[25]['sub_menu'])) { ?>
                    <a type="button" class="btn btn-secondary btn-sm ml-1" data-toggle="modal" data-target="#modal-edit<?php echo $server['id'];?>">Edit</a>
                    <?php } if(in_array("Hapus", $json_array[25]['sub_menu'])) { ?>
                    <input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm ml-1" />
                    <?php } ?>
                  </form>
                </td>
              </tr>
              <!-- Modal Edit -->
              <div class="modal fade" id="modal-edit<?php echo $server['id'];?>" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog modal-md">
                  <div class="modal-content">
                    <form method="post" enctype="multipart/form-data">
                      <div class="modal-header bg-secondary">
                        <h5 class="modal-title" id="staticBackdropLabel">Edit Master Desa</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <div class="row">
                          <div class="card-body pb-0">
                            <div class="form-group">
                              <label>Nama Desa</label>
                              <input type="text" class="form-control" value="<?php echo $server['nama']; ?>" name="nmk" required="required">
                            </div>
                            <div class="form-group">
                              <label>Nama Server</label>
                              <select class="form-control" name="ids">
                                <?php 
                                $List = new Listdata();
                                $List->set_list("data_server", $SqlDataWH);
                                foreach ($List->get_list() as $key => $value): ?>
                                <option value="<?php echo $value['id']; ?>" <?php if($value['id'] == $server['id_data_server']) { echo "selected";} ?> ><?php echo $value['nama_server']; ?></option>
                                <?php endforeach ?>
                              </select>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <input type="submit" name="edit<?php echo $server['id']; ?>" class="btn btn-warning" value="Edit">
                      </div>
                    </form>
                    <?php
                    if (isset($_POST['edit'.$server['id']])) 
                    {
                      $update = mysqli_query($con,"UPDATE master_desa SET 
                        id_data_server = '$_POST[ids]', 
                        nama = '$_POST[nmk]'
                        WHERE id = '$server[id]' ");
                      if ($update) 
                      {
                        sweetAlert("Data telah di ubah", "success");
                      }
                    }
                    if (isset($_POST['hapus'.$server['id']]))
                    {
                      $iddata = $server['id'];
                      deleteAlert("master_desa",$iddata );
                    } 
                    ?>
                  </div>
                </div>
              </div>
              <!-- END Modal Edit -->
            <?php } ?>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>
<!-- /.content -->