<section class="content" style="zoom : 85%;">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <div class="row">
              <div class="col-6">
                <h3 class="card-title">Proses Order</h3>
              </div>
              <div class="col-6">
              </div>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>Time</th>
                <th>Id Pelanggan</th>
                <th>Nama</th>
                <th>Alamat</th>
                <th>Koordinat</th>
                <th>Nomor WhatsApp</th>
                <th>Server</th>
                <th>Paket</th>
                <th>Topologi</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $aserver = mysqli_query($con,"SELECT * FROM v_order_list WHERE $SqlSvData status = 'pending'");
                while ($server = mysqli_fetch_assoc($aserver)) 
                {
                  // echo "<pre>";
                  // print_r($server);
                  // echo "</pre>";
              ?>
              <tr>
                <td style="max-width: 100px;"><?php echo $server['time_update']; ?></td>
                <td><?php echo $server['akun']; ?></td>
                <td><?php echo $server['nama']; ?></td>
                <td style="max-width: 200px;"><?php echo $server['alamat']; ?></td>
                <td><a href="https://google.com/maps/?q=<?php echo $server['latitude'].','.$server['longitude']; ?>" target="_blank"><?php echo $server['latitude'].', '.$server['longitude']; ?></a></td>
                <td><?php echo $server['nomor_whatsapp']; ?> <a href="https://wa.me/<?php echo $server['nomor_whatsapp']; ?>" target="_blank" style="border-radius: 20px; " class="btn btn-sm btn-success">Chat</a></td>
                <td><?php echo $server['nama_server']; ?></td>
                <td><?php echo $server['nama_paket']; ?></td>
                <td style="max-width: 100px;"><?php echo $server['nama_topologi'].' Port '.$server['port_odp']; ?></td>
                <td>
                  <div class="row">
                    <?php if(in_array("Ubah", $json_array[18]['sub_menu'])){ ?>
                    <a type="button" class="btn btn-warning btn-sm m-1" data-toggle="modal" data-target="#modal-proses<?php echo $server['id'];?>">Proses
                    </a>
                    <a type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#modal-batal<?php echo $server['id'];?>">Batalkan</a>
                  <?php } ?>
                  </div>
                </td>
              </tr>
              <?php 
              // echo "<pre>";
              // print_r($_SESSION);
              // echo "</pre>";
              ?>
              <!-- Modal Proses -->
              <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-warning">
                      <h4 class="modal-title">Lanjutan Proses</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                      </button>
                    </div>
                    <div class="modal-body">
                      <h5>Sebelum melanjutakan proses pastikan hal-hal berikut</h5>
                      <ul>
                        <li>Peralatan sudah di siapkan</li>
                        <li>Pelanggan sudah di hubungi</li>
                      </ul>
                      <hr>
                      <form method="post" enctype="multipart/form-data">
                        <div class="form-container">
                          <div class="row">
                            <div class="col-md-6">
                              <center>
                                <label>Upload Foto Port ODP</label>
                                <div class="uploadImage" data-id="odp<?php echo $server['id']; ?>">
                                    <span>Click to upload image</span>
                                    <img src="#" alt="Image preview">
                                    <div class="progressContainer">
                                        <div class="progressBar"></div>
                                    </div>
                                </div><hr>
                                <label>Upload Foto Rumah</label>
                                <div class="uploadImage" data-id="rmh<?php echo $server['id']; ?>">
                                    <span>Click to upload image</span>
                                    <img src="#" alt="Image preview">
                                    <div class="progressContainer">
                                        <div class="progressBar"></div>
                                    </div>
                                </div>
                              </center>
                            </div>
                            <div class="col-md-6">
                              <center>
                                <label>Upload Foto ONU terinstalasi</label>
                                <div class="uploadImage" data-id="onu<?php echo $server['id']; ?>">
                                    <span>Click to upload image</span>
                                    <img src="#" alt="Image preview">
                                    <div class="progressContainer">
                                        <div class="progressBar"></div>
                                    </div>
                                </div><hr>
                                <label>Upload SpeedTest</label>
                                <div class="uploadImage" data-id="tes<?php echo $server['id']; ?>">
                                    <span>Click to upload image</span>
                                    <img src="#" alt="Image preview">
                                    <div class="progressContainer">
                                        <div class="progressBar"></div>
                                    </div>
                                </div>
                              </center>
                            </div>
                          </div>
                        </div>
                      </form>
                    </div>
                    <form method="post" enctype="multipart/form-data">
                    <div class="modal-footer justify-content-between">
                        <button type="submit" name="lanjut<?php echo $server['id'];?>" class="btn btn-primary">Lanjutkan Proses</button>
                    </form>
                      <?php
                       if (isset($_POST['lanjut'.$server['id']])) 
                        {
                          $fotoodp    = $_SESSION['uploaded_files']['odp'.$server['id']];
                          $fotorumah  = $_SESSION['uploaded_files']['rmh'.$server['id']];
                          $fotoonu    = $_SESSION['uploaded_files']['onu'.$server['id']];
                          $fototes    = $_SESSION['uploaded_files']['tes'.$server['id']];

                          if (isset($fotoodp) AND isset($fotorumah) AND isset($fotoonu) AND isset($fototes) ) {
                  
                            // Insert ke DB Pelanggan
                              $update = mysqli_query($con,"INSERT INTO pelanggan (id_data_server, id_profile_paket, id_master_topologi, id_marketing, id_master_desa, port_odp, jenis_layanan, nama, nik, alamat, latitude, longitude, nomor_whatsapp, email, status, akun, foto_odp, foto_rumah, foto_onu, foto_test) VALUES
                               
                                ('$server[id_data_server]', '$server[id_profile_paket]', '$server[id_master_topologi]', '$server[id_marketing]', '$server[id_master_desa]', '$server[port_odp]', '$server[jenis_layanan]', '$server[nama]', '$server[nik]', '$server[alamat]',  '$server[latitude]', '$server[longitude]', '$server[nomor_whatsapp]', '$server[email]', 'register', '$server[akun]', '$fotoodp', '$fotorumah', '$fotoonu', '$fototes')");
                              // Update Order List
                              $update = mysqli_query($con,"UPDATE order_list SET status = 'instalasi', time_update = '$date' WHERE id = '$server[id]' ");

                              if ($update) 
                              {
                                unset($_SESSION['uploaded_files']['odp'.$server['id']]); 
                                unset($_SESSION['uploaded_files']['rmh'.$server['id']]); 
                                unset($_SESSION['uploaded_files']['onu'.$server['id']]); 
                                unset($_SESSION['uploaded_files']['tes'.$server['id']]);

                                sweetAlert("Proses oder sudah masuk ke data registrasi", "success", "?".encrypt_url('user_register'));
                              }
                              else { echo "UPLOAD GAGAL .. !!!";}

                              // Bikin Notif WhatsApp ke Teknisi / Pelanggan untuk kirim akun PPPOE / Hotspot...
                              // Buat Form Akun Hotspot Jika Pelanggan berlangganan Hotspot Bulanan
                            }
                          else
                          {

                              sweetAlert("Proses GAGAL..! Ada gambar yang belum di isi", "error");
                          }

                        }
                      ?>
                    </div>
                  </div>
                </div>
              </div>
              <!-- END Modal Proses -->
              <!-- Modal Batal -->
              <div class="modal fade" id="modal-batal<?php echo $server['id'];?>">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header bg-danger">
                      <h4 class="modal-title">Batalkan Order</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                      </button>
                    </div>
                    <div class="modal-body">
                      <h4>Order <b><?php echo $server['nama'] ?></b> <small>akan di batalkan</small></h4>
                      <form method="post" enctype="multipart/form-data">
                      <div class="form-group">
                        <label>Keterangan</label>
                        <textarea type="text" class="form-control" name="ket" rows="4"></textarea>
                      </div>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="submit" name="batal<?php echo $server['id'];?>" class="btn btn-danger">Batalkan Order</button>
                      </form>
                      <?php
                         if (isset($_POST['batal'.$server['id']])) 
                          {
                            $update = mysqli_query($con,"UPDATE order_list SET status = 'batal', time_update = '$date', keterangan_batal = '$_POST[ket]'
                              WHERE id = '$server[id]' ");
                            if ($update) 
                            {
                              sweetAlert("Data telah order telah di batalkan", "success", "?".encrypt_url('order_list_cancel'));
                            }
                          }
                      ?>
                    </div>
                  </div>
                </div>
              </div>
            <?php } ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>