<?php
 defined("BASEPATH") or exit("No direct access allowed");
 $query1 = mysqli_query($con,"select count(*) from grup order by tgl_bikin desc");
   $statusbc1 = mysqli_fetch_array($query1,MYSQLI_NUM);
   $jml1 = $statusbc1[0];
   
if (isset($_GET['hapusalasan']) && is_numeric($_GET['hapusalasan'])) {
		$hapusalasan = $_GET['hapusalasan'];
		
		mysqli_query($con,"DELETE FROM alasan WHERE id=$hapusalasan");

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

if( isset( $_REQUEST['aksi'] )){
		$aksi = $_REQUEST['aksi'];
		switch($aksi){
			case 'baru':
				include 'newU.php';
				break;
			case 'edit':
				include 'editU.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="#"><i class="far fa-file"></i> Alasan</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. Buat alasan baru klik +alasan. <br>
            2. Jangan sampai data alasan tidak ada, minimal 1 alasan.<br>
            3. Link Penawaran Lain yaitu saat prospek mengklik tombol UNSUB maka akan menuju ke link penawaran tersebut.
            </div>
            </div>
        </div> 
            
            <!-- /.box-header -->
            
                
				<form class="form-horizontal" role="form" action="index.php?page=unsub&aksi=baru" method="POST">
				<button class="btn btn-secondary">
				<span class="btn-label">
					<i class="fa fa-plus"></i>
				</span>
				Alasan Unsub
				</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>Alasan (Jumlah yang memilih)</th>
                            <th>Link Penawaran Lain</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                             <th>Action</th>
                             <th>Alasan (Jumlah yang memilih)</th>
                             <th>Link Penawaran Lain</th>
                        </tr>
                    </tfoot>
                    <tbody>
                       <?php
                            
                            $qu=mysqli_query($con,"select * from alasan order by id desc");
                            while($data=mysqli_fetch_row($qu)){
                                $eid= md5($data[0]);
                                
                                $q1 = mysqli_query($con,"SELECT count(id) FROM unsub where alasan ='$data[1]'");
                                $s1 = mysqli_fetch_array($q1,MYSQLI_NUM);
                                $jml1 = $s1[0];

                                echo "
                                <tr>
                                    <td>   
									<a type='button' class='btn btn-icon btn-round btn-default' href='index.php?page=unsub&aksi=edit&id=$data[0]' >EDIT</a>
									
									<a type='button' class='btn btn-icon btn-round btn-default' onclick='return konfirmasi()' href='?page=unsub&hapusalasan=$data[0]'>DEL</a>
									
									</td>
									<td>
                                        $data[1] ($jml1)
                                    </td>
									<td>
                                        $data[2] 
                                    </td>
                                </tr>
                                ";
                            }
                       ?>
                    </tbody>
                </table>
                </div>
                
 </div>
            <!-- /.box-body -->
        


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