<?php include 'header.php'; ?>
<div class="content-wrapper">
   <section class="content-header">
      <h1>
         Result
         <small>Data Jam Result</small>
      </h1>
      <ol class="breadcrumb">
         <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
         <li class="active">Dashboard</li>
      </ol>
   </section>
   <section class="content">
      <div class="row">
         <section class="col-lg-12">
            <div class="box box-info">
               <div class="box-header">
                  <h3 class="box-title">Data Jam Result</h3>
                  <div class="form-group">
                     <label for="draw_type">Draw Type:</label>
                     <form method="GET" action="">
                        <select id="draw_type" name="draw_type" class="form-control" onchange="this.form.submit()">
                           <option value="">Pilih Draw Type</option>
                           <option value="talaga" <?php if (isset($_GET['draw_type']) && $_GET['draw_type'] == 'talaga')
                              echo 'selected'; ?>>LOTTERY</option>

                        </select>
                     </form>
                  </div>
                  <div class="btn-group pull-right"></div>
               </div>
               <div class="box-body">
                  <div class="table-responsive">
                     <table class="table table-bordered table-striped" id="table-datatable">
                        <thead>
                           <tr>
                              <th width="1%">NO</th>
                              <th>JAM AWAL</th>
                              <th>JAM AKHIR</th>
                              <th width="10%">OPSI</th>
                           </tr>
                        </thead>
                        <tbody>
                           <?php
                           if (isset($_GET['draw_type']) && !empty($_GET['draw_type'])) {
                              $draw_type = $_GET['draw_type'];
                              // Tentukan nama tabel berdasarkan draw_type
                              switch ($draw_type) {
                                 case 'talaga':
                                    $table_name = 'atur_talaga';
                                    break;
                                 case 'bogor':
                                    $table_name = 'atur_bogor';
                                    break;
                                 case 'Evening':
                                    $table_name = 'atur_evening';
                                    break;
                                 case 'Night':
                                    $table_name = 'atur_night';
                                    break;
                                 default:
                                    $table_name = '';
                              }

                              if (!empty($table_name)) {
                                 $no = 1;
                                 $qry_voucher = mysqli_query($koneksi, "SELECT * FROM $table_name ORDER BY `id_situs` DESC");
                                 while ($dt_voucher = mysqli_fetch_array($qry_voucher)) {
                                    $id_situs = $dt_voucher['id_situs'];
                                    $draw_time = $dt_voucher['draw_time'];
                                    $draw_end = $dt_voucher['draw_end'];
                                    $identitas = $dt_voucher['identitas'];
                                    ?>
                                    <tr>
                                       <td><?php echo $no++; ?></td>
                                       <td><?php echo $draw_time; ?></td>
                                       <td><?php echo $draw_end; ?></td>
                                       <td>
                                          <button type="button" class="btn btn-warning btn-sm" data-toggle="modal"
                                             data-target="#edit_bank_<?php echo $id_situs; ?>">
                                             <i class="fa fa-cog"></i>
                                          </button>
                                          <form action="situs_update.php" method="post">
                                             <div class="modal fade" id="edit_bank_<?php echo $id_situs; ?>" tabindex="-1"
                                                role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                <div class="modal-dialog" role="document">
                                                   <div class="modal-content">
                                                      <div class="modal-header">
                                                         <input type="hidden" name="id_situs" value="<?php echo $id_situs; ?>">
                                                         <h4 class="modal-title" id="exampleModalLabel">Edit Jam Keluaran</h4>
                                                         <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="form-group" style="width:100%;margin-bottom:20px">
                                                            <label>Jam Awal</label>
                                                            <input type="text" style="width:100%" name="draw_time"
                                                               required="required" class="form-control"
                                                               value="<?php echo $draw_time; ?>">
                                                         </div>
                                                         <div class="form-group" style="width:100%;margin-bottom:20px">
                                                            <label>Jam Akhir</label>
                                                            <input type="text" style="width:100%" name="draw_end"
                                                               required="required" class="form-control"
                                                               value="<?php echo $draw_end; ?>">
                                                            <input type="hidden" style="width:100%" name="identitas"
                                                               value="<?php echo $identitas; ?>">
                                                         </div>
                                                      </div>
                                                      <div class="modal-footer">
                                                         <button type="button" class="btn btn-secondary"
                                                            data-dismiss="modal">Tutup</button>
                                                         <button type="submit" class="btn btn-primary">Simpan</button>
                                                      </div>
                                                   </div>
                                                </div>
                                             </div>
                                          </form>
                                       </td>
                                    </tr>
                                    <?php
                                 } // end while
                              } else {
                                 echo "<tr><td colspan='4'>Pilih draw type untuk melihat data.</td></tr>";
                              }
                           } else {
                              echo "<tr><td colspan='4'>Pilih draw type untuk melihat data.</td></tr>";
                           }
                           ?>
                        </tbody>
                     </table>
                  </div>
               </div>
            </div>
         </section>
      </div>
   </section>
</div>
<?php include 'footer.php'; ?>