<?php
 defined("BASEPATH") or exit("No direct access allowed");
 $query1 = mysqli_query($con,"select count(*) from qrcode order by id desc");
   $statusbc1 = mysqli_fetch_array($query1,MYSQLI_NUM);
   $jml1 = $statusbc1[0];
   
if (isset($_POST['ubah'])){
          
            $id = $_POST['id'] ;
            $st = mysqli_real_escape_string($con,$_POST['st']);
            
            IF($st==0){
                $st ='1';
            }else{
                $st ='0';
            }
            
            //simpan
                 mysqli_query($con,"update qrcode set stsqr='$st' where id='$id'"); 
        
}   
   
if (isset($_GET['hapus']) && is_numeric($_GET['hapus'])) {
		$hapus = $_GET['hapus'];
		
		mysqli_query($con,"DELETE FROM qrcode WHERE id=$hapus");

		echo '
		 
         <script>
        swal("Good Job","berhasil menghapus data qrcode ","success");
                </script>     
                
		';
		
	}
      

if( isset( $_REQUEST['aksi'] )){
		$aksi = $_REQUEST['aksi'];
		switch($aksi){
			case 'baru':
				include 'newQ.php';
				break;
			case 'edit':
				include 'editQ.php';
				break;
			case 'view':
				include 'qrdetail.php';
				break;	
		}
} else { 
 
?>
<div class="section-header">

<div class="card-header">
    
          <nav aria-label="breadcrumb">
                      <ol class="breadcrumb bg-warning text-white-all">
                        <li class="breadcrumb-item"><a href="#"><i class="fas fa-tachometer-alt"></i> Home</a></li>
                        <li class="breadcrumb-item"><a href="index.php?page=qrc"><i class="far fa-file"></i> QRcode</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i> List</li>
                      </ol>
                    </nav>

    <div class="card-body">
            <div class="alert alert-primary alert-has-icon p-4">
            <div class="alert-icon"><i class="far fa-lightbulb"></i></div>
            <div class="alert-body">
            <div class="alert-title">Petunjuk:</div>
            1. Fitur QRCode Diskon adalah Fitur yang Insya Allah dapat membuat member anda lebih loyal lagi dalam berbelanja. Fitur ini khusus ketika pelanggan datang ke Toko anda.<br>
            2. Fitur QRCode Event adalah fitur untuk memvalidasi peserta/member yang ikut kegiatan bisnis. Cocok untuk anda yang sering mengadakan kegiatan workshop/kursus/seminar bisnis.<br>  
            3. QRcode baru klik +Tambah Qrcode. <br>
            4. Jika Link Validasi belum aktif, klik tombol Aktifkan. <br>
            5. Lakukan <a href="index.php?page=broadnew">Broadcast Email</a> untuk mengirim QRcode ke prospek. <br>
            6. Buka Link Validasi via Komputer (yang ada webcame/kamera) atau HP Smartphone anda untuk mengecek QRCode member anda.<br>
            7. Saat Qrcode Event di scan terkirim notifikasi ke Telegram admin, dan pesan ucapan terima kasih ke WA peserta/prospek.
            </div>
            </div>
        </div> 
            
            <!-- /.box-header -->
            
                
				<form class="form-horizontal" role="form" action="index.php?page=qrc&aksi=baru" method="POST">
				<button class="btn btn-secondary">
				<span class="btn-label">
					<i class="fa fa-plus"></i>
				</span>
				Tambah QRCode
				</button>
				</form>
				
<div class="card-body">	
                <div class="table-responsive">
				<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Action</th>
                            <th>QRcode</th>
                            <th>Judul QRcode</th>
                            <th>Keterangan</th>
                            <th>Jenis</th>
                            <th>Tgl.Expire</th>
                            <th>Link Validasi</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                             <th>Action</th>
                             <th>QRcode</th>
                            <th>Judul QRcode</th>
                            <th>Keterangan</th>
                            <th>Jenis</th>
                            <th>Tgl.Expire</th>
                            <th>Link Validasi</th>
                        </tr>
                    </tfoot>
                    <tbody>
                       <?php
                            
                            $qu=mysqli_query($con,"select * from qrcode order by id desc");
                            while($data=mysqli_fetch_row($qu)){
                                
                                $eid= md5($data[0]);
                                IF($data[5]==0){
                                    $jq ='Diskont';
                                    $link = $weburl.'/qrcode/diskon.php';
                                }else{
                                    $jq ='Event/Kegiatan';
                                    $link = $weburl.'/qrcode/event.php';
                                }
                                
                                IF($data[6]==0){
                                    $st ='Aktifkan';
                                    $link = $link;
                                }else{
                                    $st ='Non Aktifkan';
                                    $link = $link;
                                }
                                echo "
                                <tr>
                                    <td>   
									<a type='button' class='btn btn-icon btn-round btn-default' href='index.php?page=qrc&aksi=edit&id=$data[0]' >EDIT</a>
									
									<a type='button' class='btn btn-icon btn-round btn-default' href='index.php?page=qrc&aksi=view&id=$data[0]' >VIEW</a>
									
									<a type='button' class='btn btn-icon btn-round btn-default' onclick='return konfirmasi()' href='?page=qrc&hapus=$data[0]'>DEL</a>
									
									</td>
									<td>
                                        $data[1] 
                                    </td>
									<td>
                                        $data[2] 
                                    </td>
                                    <td>
                                        $data[3] 
                                    </td>
                                    <td>
                                         $jq
                                         
                                    </td>
                                    <td>
                                        $data[4] 
                                    </td>
                                    <td>
                                        <a href='$link' target='_blank'>$link</a>
                                        <form action='' method='POST' enctype='multipart/form-data'>
                                         <input type='hidden' name='id' value='$data[0]'>
                                         <input type='hidden' name='st' value='$data[6]'>
                                         <button type='submit' class='btn btn-primary' name='ubah'><span class='glyphicon glyphicon-pencil'></span> $st</button>
                                         </form>
                                    </td>
                                </tr>
                                ";
                            }
                       ?>
                    </tbody>
                </table>
                </div>
                
 </div>
            <!-- /.box-body -->
        


<!-- /.row -->
<?php
}
?>