<!-- Main content -->
<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-sm-6">
                <h3 class="card-title">Tiket Gangguan</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                  <?php if(in_array("Tambah", $json_array[36]['sub_menu'])) { ?>
                  <a class="btn btn-danger btn-sm" href="?<?php echo encrypt_url('tiket_buat_baru') ?>">Buat Tiket</a>
                  <?php } ?>
                </ol>
              </div>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead class="bg-warning">
              <tr>
                <th>No</th>
                <th>Time</th>
                <th>Nama Server</th>
                <th>Jenis</th>
                <th>Keterangan</th>
                <th>Lokasi</th>
                <th>Koordinat</th>
                <th>URL Tracking</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $no = 1;
                $aserver = mysqli_query($con,"SELECT * FROM v_tiket_gangguan WHERE status = '1' $SqlDataId");
                while ($server = mysqli_fetch_assoc($aserver)) {
                  if ($server['jenis_tiket'] == 'Pelanggan') {
                    $ket = '<a href="?'.encrypt_url('user_detail|'.$server['id_pelanggan']).'"><b>'.$server['nama_pelanggan'].'</b></a><br>'.$server['permasalahan'];
                  } else {
                    $ket = $server['permasalahan'];
                  }
              ?>
              <tr>
                <td style="max-width: 30px;"><?php echo $no; ?></td>
                <td style="max-width: 75px;"><?php echo $server['start_time']; ?></td>
                <td><?php echo $server['nama_server']; ?></td>
                <td><?php echo $server['jenis_tiket']; ?></td>
                <td style="max-width: 150px;"><?php echo $ket; ?></td>
                <td style="max-width: 150px;"><?php echo $server['lokasi']; ?></td>
                <td style="max-width: 150px;"><a href="https://www.google.com/maps/search/?api=1&query=<?php echo $server['latitude'].', '.$server['longitude']; ?>" target="_blank"><?php echo $server['latitude'].', '.$server['longitude']; ?></a></td>
                <td style="max-width: 150px;"><a href="<?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?>" target="_blank"><?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?></a></td>
                <td>
                  <form method="post">
                    <?php if(in_array("Ubah", $json_array[36]['sub_menu'])) { ?>
                    <input type="submit" name="proses<?php echo $server['id'];?>" value="Proses Tiket" class="btn btn-primary btn-sm ml-1" />
                    <?php } if(in_array("Hapus", $json_array[36]['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>
            <?php
              if (isset($_POST['proses'.$server['id']])) {
                $waktu = date('Y-m-d H:i:s');
                $stmt = $pdo->prepare("UPDATE tiket_gangguan SET id_penyelesai_tiket = :idpenyet, sebelum_proses_time = :waktu, status = '2' WHERE id = :idtik");
                $stmt->bindParam(':waktu', $waktu);
                $stmt->bindParam(':idpenyet', $UserId, PDO::PARAM_INT);
                $stmt->bindParam(':idtik', $server['id'], PDO::PARAM_INT);
                $stmt->execute();
                sweetAlert("Tiket akan di proses", "success", "?".encrypt_url('tiket_proses'));
              }
              if (isset($_POST['hapus'.$server['id']])) {
                $iddata = $server['id'];
                deleteAlert("tiket_gangguan", $iddata);
              }
            $no++; } ?>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>
<!-- /.content -->