<section class="content" style="zoom : 88%;">
  <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">WhatsApp Gateway</h3>
              </div>
              <div class="col-sm-6">
              </div>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <table id="example2" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th style="max-width: 20px">No</th>
                <th>Nama Server</th>
                <th>Nomor WhatsApp</th>
                <th>Url</th>
                <th>API Key</th>
                <th>Status</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
            <?php
            if($SvId == '1'){
              $SQL = "SELECT id,nama_server,nomor_whatsapp,url_whatsapp_gateway,apikey_whatsapp,status_whatsapp FROM data_server WHERE id != '1'";
            }
            else{
              $SQL = "SELECT id,nama_server,nomor_whatsapp,url_whatsapp_gateway,apikey_whatsapp,status_whatsapp FROM data_server WHERE id IN (".$SvId.")";
            }
            $no = 1;
            $aserver = mysqli_query($con,$SQL);
            while ($server = mysqli_fetch_assoc($aserver))
            {
            ?>
              <tr>
                <td style="max-width: 20px"><?php echo $no; ?></td>
                <td><?php echo $server['nama_server']; ?></td>
                <td><?php echo $server['nomor_whatsapp']; ?></td>
                <td><?php echo $server['url_whatsapp_gateway']; ?></td>
                <td><?php echo $server['apikey_whatsapp']; ?></td>
                <td>
                  <?php
                    if ($server['status_whatsapp'] == 'Connected') 
                    {
                      echo '<span class="badge badge-success">'.$server['status_whatsapp'].'</span>';
                    }
                    else
                    {
                      echo '<span class="badge badge-danger">'.$server['status_whatsapp'].'</span>';
                    }
                  ?>
                </td>
                <td>
                   <a href="?<?php echo encrypt_url('whatsapp_gateway_scan|'.$server['id']);?>" class="text-success"><i class="fas fa-qrcode fa-2x"></i></a>
                   <a type="button" class="btn btn-sm btn-secondary btn-sm ml-3" data-toggle="modal" data-target="#modal-proses<?php echo $server['id'];?>" style="margin-top: -15px;">Edit</a>
                </td>
              </tr>
              <div class="modal fade" id="modal-proses<?php echo $server['id'];?>">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header bg-secondary">
                      <h4 class="modal-title">Edit Profile WhatsApp Gateway</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                      </button>
                    </div>
                    <form method="post" enctype="multipart/form-data">
                    <div class="modal-body">
                      <div class="form-group">
                        <label>Nomor WhatsApp</label>
                        <input type="text" class="form-control" name="nowa" value="<?php echo $server['nomor_whatsapp']; ?>">
                      </div>
                      <div class="form-group">
                        <label>Url WhatsApp Gateway</label>
                        <input type="text" class="form-control" name="url" value="<?php echo $server['url_whatsapp_gateway']; ?>">
                      </div>
                      <div class="form-group">
                        <label>APIKey WhatsApp Gateway</label>
                        <input type="text" class="form-control" name="apikey" value="<?php echo $server['apikey_whatsapp']; ?>">
                      </div>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="submit" name="lanjut<?php echo $server['id'];?>" class="btn btn-primary">Edit</button>
                    </div>
                    </form>
                    <?php
                      if (isset($_POST['lanjut'.$server['id']])) 
                        {
                          $up = mysqli_query($con,"UPDATE data_server SET nomor_whatsapp = '$_POST[nowa]', url_whatsapp_gateway = '$_POST[url]', apikey_whatsapp = '$_POST[apikey]' WHERE id = '$server[id]'");
                          if ($up) 
                          {
                            sweetAlert("Data telah di ubah", "success");
                          }
                        }
                    ?>
                  </div>
                </form>
              </div>
            <?php $no++; } ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
