<?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['hapus']) && is_numeric($_GET['hapus'])) {
		$hapus = $_GET['hapus'];
		
		mysqli_query($con,"DELETE FROM emailsender WHERE id=$hapus");

		echo '
		<!-- <div class="alert alert-success alert-dismissable" style="margin-top:20px">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon glyphicon glyphicon-remove"></i> Data Email dengan id '.$hapus.' Telah Dihapus
            </div> -->
            
         <script>
        	        swal("Good Job","berhasil menghapus data email sender","success");
                </script>     
                
		';
		
	}
      

if( isset( $_REQUEST['aksi'] )){
		$aksi = $_REQUEST['aksi'];
		switch($aksi){
			case 'baru':
				include 'newemail.php';
				break;
			case 'edit':
				include 'editemail.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=emailsender"><i class="far fa-file"></i> Email Sender</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 Email Sender baru klik +Email Sender. <br>
            2. Setingan email sender sama dengan setingan email default.<br>
            3. Email Sender ini digunakan saat broadcast email.<br>
            4. Penggunaan Email Sender dari layanan SendGrid.com ada sedikit problem. Silahkan <a href="https://blog.biznis.top/2019/12/permasalahan-email-root-di-layanan.html" target="_blank">BACA DISINI</a>.<br>
            5. Jika pakai SMTP Mailgun dapat melakukan Setup SMTP terlebih dahulu. Ikuti petunjuk <a href="https://www.youtube.com/watch?v=lR0gV6E8GW8" target="_blank">DISINI</a>. <br>
            6. Jika pakai SMTP SendGrid dapat melakukan Setup SMTP terlebih dahulu. Ikuti petunjuk <a href="https://blog.biznis.top/2019/12/smtp-sendgrid.html" target="_blank">DISINI</a>.
            </div>
            </div>
        </div> 
            
            <!-- /.box-header -->
            
                
				<form class="form-horizontal" role="form" action="index.php?page=emailsender&aksi=baru" method="POST">
				<button class="btn btn-secondary">
				<span class="btn-label">
					<i class="fa fa-plus"></i>
				</span>
				Email Sender
				</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>Nama Sender</th>
							<th>Nama Email</th>
							<th>Url Host</th>
                            <th>Port</th>
                            <th>Email Refly To</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                             <th>Action</th>
                             <th>Nama Sender</th>
							<th>Nama Email</th>
							<th>Url Host</th>
                            <th>Port</th>
                            <th>Email Refly To</th>
                        </tr>
                    </tfoot>
                    <tbody>
                       <?php
                            
                            $qu=mysqli_query($con,"select * from emailsender order by id desc");
                            while($data=mysqli_fetch_row($qu)){
                                
                                $eid= md5($data[0]);

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


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