<?php
defined("BASEPATH") or exit("No direct access allowed");
if (isset($_POST['simpan'])){
    if (!empty($_POST['e1'])) {
    	$e1 = mysqli_real_escape_string($con,$_POST['e1']);
        
        $namafolder="template/upload/"; 
        
        $ekstensi_diperbolehkan	= array('html');
        $logox = $_FILES['filegbr']['name'];
        $x = explode('.', $logox);
        $ekstensi = strtolower(end($x));
        
        if (in_array($ekstensi, $ekstensi_diperbolehkan) === false){
          
         echo "<script>alert('Upload Gagal !!! Typle File template email harus html)'); window.location = 'index.php?page=tempe'</script>"; 
            exit;
        }
        
        $file = $namafolder . basename($_FILES['filegbr']['name']);
            
            if (move_uploaded_file($_FILES['filegbr']['tmp_name'], $file)) {
            
                //simpan
                
                mysqli_query($con,"INSERT INTO template VALUE (NULL,'".$e1."','".$file."')");
                
                echo '
                <script>
                	swal("Good Job","Anda sukses menyimpan template","success");
                </script>
                 <script language="JavaScript">document.location="index.php?page=tempe"</script>
        		';
            } else {
                echo '
                <script>
                	swal("Good Error","Template gagal diupload","error");
                </script>
        		';
            }
    
    } else {
    	
    	echo "<div class='alert alert-warning 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 harus diisi
                </div>";
    }

}
?>
<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> Upload</li>
                      </ol>
                    </nav>
                    
          </div>
<div class="card-body">		  


<form action="" method="post" enctype="multipart/form-data">
<p><label>Nama Template Email</label><input type="text" name="e1" maxlength="75" class="form-control" placeholder="" required/></p>
<p><label>Link</label>
<input type='file' name='filegbr' id='Filegambar' required/>
</p>
<input class="btn btn-secondary btn-border" type="submit" name="simpan" value="Simpan"/>
</form>
</div>