 <!-- 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">Data Customer</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                  <a type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#staticBackdrop">Tambah</a>
                </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 Customer</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>Pilih 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 class="form-group">
                              <label>Nama</label>
                              <input type="text" class="form-control" name="nama" required="required">
                            </div>
                            <div class="form-group">
                              <label>Alamat</label>
                              <input type="text" class="form-control" name="alamat" required="required">
                            </div>
                            <div class="form-group">
                              <label>Nomor Whatsapp</label>
                              <input type="text" class="form-control" name="nomor" required="required">
                            </div>
                          </div>
                        </div>
                      </div>
                      <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>
                    </form>
                    <?php
                    if (isset($_POST['tambah'])) 
                    {
                      $input = mysqli_query($con,"INSERT INTO customer (id_data_server, nama, alamat, nomor_whatsapp) 
                        VALUES ('$_POST[ids]', '$_POST[nama]', '$_POST[alamat]', '$_POST[nomor]')");
                      if ($input) 
                      {
                        sweetAlert("Customer ".$_POST['nama']." telah di tambahkan", "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>No</th>
                <th>Nama</th>
                <th>Alamat</th>
                <th>Nomor WhatsApp</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $no = 1;
                $aserver = mysqli_query($con,"SELECT * FROM customer $SqlDataWHId ");
                while ($server = mysqli_fetch_assoc($aserver)) 
                {
              ?>
              <tr>
                <td style="max-width: 30px;"><?php echo $no; ?></td>
                <td><?php echo $server['nama']; ?></td>
                <td><?php echo $server['alamat']; ?></td>
                <td><?php echo $server['nomor_whatsapp']; ?></td>
                <td>
                  <form method="post">
                    <a type="button" class="btn btn-secondary btn-sm ml-1" data-toggle="modal" data-target="#modal-edit<?php echo $server['id'];?>">Edit</a>
                    <input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm ml-1" />
                  </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 Customer</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 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 class="form-group">
                              <label>Nama</label>
                              <input type="text" class="form-control" value="<?php echo $server['nama']; ?>" name="nama" required="required">
                            </div>
                            <div class="form-group">
                              <label>Alamat</label>
                              <input type="text" class="form-control" value="<?php echo $server['alamat']; ?>" name="alamat" required="required">
                            </div>
                            <div class="form-group">
                              <label>Nomor WhatsApp</label>
                              <input type="text" class="form-control" value="<?php echo $server['nomor_whatsapp']; ?>" name="nomor" required="required">
                            </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 customer SET
                        id_data_server  ='$_POST[ids]', 
                        nama            ='$_POST[nama]',
                        alamat          ='$_POST[alamat]',
                        nomor_whatsapp  ='$_POST[nomor]'
                        WHERE id        = '$server[id]' ");
                      if ($update) 
                      {
                        sweetAlert("Customer ".$_POST['nama']." telah di edit", "success");
                      }
                    }
                    if (isset($_POST['hapus'.$server['id']]))
                    {
                      $iddata = $server['id'];
                      deleteAlert("customer",$iddata );
                    }
                    ?>
                  </div>
                </div>
              </div>
              <!-- END Modal Edit -->
            <?php $no++; } ?>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>
<!-- /.content -->