<?php
 defined("BASEPATH") or exit("No direct access allowed");
 $query1 = mysqli_query($con,"select count(*) from template order by id desc");
   $statusbc1 = mysqli_fetch_array($query1,MYSQLI_NUM);
   $jml1 = $statusbc1[0];
   
if (isset($_GET['hapus']) && is_numeric($_GET['hapus'])) {
		$hapus = $_GET['hapus'];
		
		$query = mysqli_query($con,"SELECT * FROM template WHERE id=$hapus");
	        $check = mysqli_fetch_array($query,MYSQLI_NUM);
	        if (isset($check[0])) {
				$link =$check[2];
				unlink($link);
	        }    
	        
		mysqli_query($con,"DELETE FROM template WHERE id=$hapus");

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

if( isset( $_REQUEST['aksi'] )){
		$aksi = $_REQUEST['aksi'];
		switch($aksi){
			case 'baru':
				include 'newT.php';
				break;
			case 'edit':
				include 'editT.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=tempe"><i class="far fa-file"></i> Template Email</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. Upload Template Email baru klik +Upload Template Email. <br>
            2. Anda dapat membuat template email <a href="https://beefree.io/templates/" target="_blank"> DISINI </a>.<br>
            3. tambahkan tag [judul], [nama], [email], [isi], [unsub] pada template email anda.<br>
            4. File Template email berekstensi .html <br>
            5. Anda dapat mendownload aplikasi Notepad ++  <a href="https://notepad-plus-plus.org/downloads/" target="_blank"> DISINI </a> sebagai editor template email. <br>
            6. Jika ingin menempatkan gambar dalam template, upload gambar <a href="https://postimages.org/" target="_blank">Klik Disini</a>. Kemudian copy dan paste link gambarnya dalam template. Contoh: &lt;a href=&quot;paste url gambar disini&quot;&gt;<br>
            7. Buat Countdown Timer  <a href="https://www.sendtric.com/" target="_blank">DISINI</a> 100% layanannya gratis. Kemudian copy dan paste script atau link gambarnya ditemplate. <br>
            8. Silahkan download template dalam <a href="index.php?page=bonus" target="_blank"> BONUS </a>. Sesuaikan dengan kebutuhan anda.<br>
            9. Anda juga dapat membuat template email <a href="https://stripo.email/" target="_blank"> DISINI</a>. Register, design dan export ke File .html. Layanan ini sesuai yang tercantum di webnya bersifat <i>no credit card needed and no time limits</i>. 
            </div>
            </div>
        </div> 
            
            <!-- /.box-header -->
            
                
				<form class="form-horizontal" role="form" action="index.php?page=tempe&aksi=baru" method="POST">
				<button class="btn btn-secondary">
				<span class="btn-label">
					<i class="fa fa-plus"></i>
				</span>
				Upload Template Email
				</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>Nomor / Nama Template Email</th>
                            <th>Link</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                             <th>Action</th>
                             <th>Nomor / Nama Template Email</th>
                            <th>Link</th>
                        </tr>
                    </tfoot>
                    <tbody>
                       <?php
                            
                            $qu=mysqli_query($con,"select * from template order by id asc");
                            while($data=mysqli_fetch_row($qu)){
                                
                                $eid= md5($data[0]);
                                        $data2 = explode("/" , $data['2']);
                                echo "
                                <tr>
                                    <td>   
									<a type='button' class='btn btn-icon btn-round btn-default' href='index.php?page=tempe&aksi=edit&id=$data[0]' >EDIT</a>
									
									<a type='button' class='btn btn-icon btn-round btn-default' onclick='return konfirmasi()' href='?page=tempe&hapus=$data[0]'>DEL</a>
									
									</td>
									<td>
                                        ($data[0]) $data[1] 
                                    </td>
									<td>
                                        $data2[2] 
                                    </td>
                                </tr>
                                ";
                            }
                       ?>
                    </tbody>
                </table>
                </div>
                
 </div>
            <!-- /.box-body -->
        


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