Advertisement
cahyadsn

multiple countdown timer js

Aug 12th, 2016
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.56 KB | None | 0 0
  1. <?php
  2.   $id_user = $this->session->userdata('id_user');
  3. ?>
  4. <div class="container">
  5.     <h4><?php echo $judul;?></h4>
  6. </div>
  7. <div class="container panel panel-default">
  8.     <div class="panel-body">
  9.         <?php
  10.         if($this->session->flashdata('psn_success') <> '') {
  11.         ?>
  12.             <div class="alert alert-dismissible alert-success">
  13.               <button type="button" class="close" data-dismiss="alert">&times;</button>
  14.               <strong><span class="glyphicon glyphicon-ok"></span> <?php echo $this->session->flashdata('psn_success');?></strong>
  15.             </div>
  16.         <?php
  17.         }
  18.         if($this->session->flashdata('psn_gagal') <> '') {
  19.         ?>
  20.             <div class="alert alert-dismissible alert-danger">
  21.               <button type="button" class="close" data-dismiss="alert">&times;</button>
  22.               <strong>&times; <?php echo $this->session->flashdata('psn_gagal');?></strong>
  23.             </div>
  24.         <?php
  25.         }
  26.         ?>
  27.         <table class='table table-striped table-hover display' id='example'>
  28.             <thead style="text-align:center">
  29.                 <tr>
  30.                     <th>No.</th>
  31.                     <th>Kode Pesanan</th>
  32.                     <th>Nama Pembeli</th>
  33.                     <th>Jumlah Pesanan</th>
  34.                     <th>Total Harga</th>
  35.                     <th>Deadline Lunas</th>
  36.                     <th>Status</th>
  37.                     <th>Opsi</th>
  38.                 </tr>
  39.             </thead>
  40.             <tbody>
  41.             <script>
  42.             var timerData = [];
  43.             function countdown(id_pembeli) {
  44.                 var seconds = timerData[id_pembeli].remaining;
  45.                 var hour = Math.floor(seconds/(60*60))%24;
  46.                 var min = Math.floor(seconds/60) % 60;
  47.                 var sec = seconds % 60;
  48.                 if (sec < 10) {
  49.                     sec = "0" + sec;
  50.                 }
  51.                 document.getElementById('waktu'+id_pembeli).innerHTML = hour+":"+min+":"+sec;
  52.                 if (seconds <= 0) {
  53.                     clearInterval(timerData[id_pembeli].timerId);
  54.                     document.getElementById('waktu' + id_pembeli).innerHTML = "DEADLINE!";
  55.                 } else {
  56.                     seconds--;
  57.                 }
  58.                 timerData[id_pembeli].remaining = seconds;
  59.             }
  60.  
  61.             function timer(id_pembeli, seconds) {
  62.                 timerData[id_pembeli] = {
  63.                     remaining: seconds,
  64.                     timerId: setInterval(function () { countdown(id_pembeli); }, 1000)
  65.                 };
  66.             }
  67.             </script>
  68.             <?php
  69.                 $no = 1;
  70.                 $countpembeli = $this->M_reseller->getpembeliwuser($id_user)->num_rows();
  71.                 if($countpembeli == 0){
  72.                     /*
  73.                      $this->session->set_flashdata(
  74.                           "psn_success",
  75.                           "<div class=\"alert alert-danger\" id=\"alert\">
  76.                            <i class=\"glyphicon glyphicon-ok\"></i> Data Kosong !
  77.                            <button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button> </div>");
  78.                      redirect('reseller/entry_data');
  79.                     */
  80.                 } else {
  81.                     $getpembeli = $this->M_reseller->getpembeliwuser($id_user)->result();
  82.                     foreach($getpembeli as $gp) {
  83.                         $id_pembeli = $gp->id_pembeli;
  84.                         $getmaster  = $this->M_reseller->getmasterwpemuser($id_pembeli, $id_user)->result();
  85.                         $getjml  = $this->M_reseller->getdetailwpembeli($id_pembeli)->num_rows();
  86.                         //Ambil/SUM total harga
  87.                         $total = $this->db->query("
  88.                             SELECT id_t_sales_master, sum(total_harga) as total
  89.                             FROM t_reseller_sales_detail
  90.                             WHERE id_t_sales_master = '$id_pembeli' ")->result();
  91.                         $total_harga = 'Rp.&nbsp;'.number_format($total[0]->total,2,".",",");
  92.                         //DEADLINE LUNASAN
  93.                         $sla = strtotime($getmaster[0]->waktu_deadline);
  94.                         $now = time();
  95.                         $seconds = $sla - $now;
  96.                         if($seconds<= 0) {
  97.                             $waktu_deadline = 'Waktu Habis';
  98.                             $update = $this->db->query("
  99.                                 UPDATE t_reseller_sales_master
  100.                                 SET status='canceled'
  101.                                 WHERE id_t_sales_master='$id_pembeli' ");
  102.                         } else {
  103.                             $waktu_deadline =  '<div style="font-size:40px;margin-top:7px;" id="waktu'.$id_pembeli.'" >
  104.                                                 DEADLINE!</div>';
  105.                         }
  106.                         ?>
  107.                     <tr>
  108.                         <td><?php echo $no++;?>.</td>
  109.                         <td><?php echo $getmaster[0]->id_t_sales_master;?></td>
  110.                         <td><?php echo $gp->nama;?></td>
  111.                         <td><?php echo $getjml; ?></td>
  112.                         <td><?php echo $total_harga; ?></td>
  113.                         <td><?php echo $waktu_deadline; ?></td>
  114.                         <td><?php echo $getmaster[0]->status;?></td>
  115.                         <td>
  116.                         <button class="btn btn-warning btn-xs" data-toggle="modal"
  117.                                 data-target="#data_sales_master_edit<?php echo $gp->id_pembeli; ?>" >
  118.                         <span class="glyphicon glyphicon-pencil"></span> Edit</button>
  119.                         <a href="<?php echo base_url('reseller/data_sales_detail/'.$id_pembeli);?>"
  120.                            class="btn btn-success btn-xs" >
  121.                         <span class="glyphicon glyphicon-plus"></span> Olah Sapi</a>
  122.                         <a href="<?php echo base_url('reseller/data_sales_master_hapus/'.$id_pembeli);?>"
  123.                            class="btn btn-danger btn-xs" onclick="return confirm('Hapus data?')">&times; Hapus</a></td>
  124.                     </tr>
  125.                      <script type="text/javascript">
  126.                          timer(<?php echo "{$id_pembeli},{$seconds}";?>);
  127.                      </script>
  128.                     <?php
  129.                         include('data_sales_bukti_bayar.php');
  130.                         include('data_sales_master_edit.php');
  131.                     }
  132.                 }
  133.                 ?>
  134.             </tbody>
  135.         </table>
  136.     </div>
  137. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement