<?php
defined("BASEPATH") or exit("No direct access allowed");
if (isset($_POST['simpan'])){
    if (!empty($_POST['e1'])) {
        
        $rand = randomString();
        $rand = substr($rand,0,5);
    	$e1 = mysqli_real_escape_string($con,$_POST['e1']);
    	$e2 = mysqli_real_escape_string($con,$_POST['e2']);
    	$e3 = mysqli_real_escape_string($con,$_POST['e3']);
    	$e4 = mysqli_real_escape_string($con,$_POST['e4']);
    	$pesan1 = mysqli_real_escape_string($con,$_POST['pesan1']);
                
        mysqli_query($con,"INSERT INTO qrcode VALUE (NULL,'".$rand."','".$e1."','".$e2."',NOW() + INTERVAL $e3 DAY,'".$e4."',0,'$pesan1')");
                
    	echo '
             <script>
            	        swal("Good Job","berhasil menyimpan data","success");
                    </script>        
                    
                    <script language="JavaScript">document.location="index.php?page=qrc"</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=qrc"><i class="far fa-file"></i> qrcode </a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i> Buat Baru</li>
                      </ol>
                    </nav>
                    
          </div>
<div class="card-body">		  
<form action="" method="post" enctype="multipart/form-data">
<p><label>Judul QRCode</label><input type="text" name="e1" maxlength="250" class="form-control" placeholder="Cth.: Diskon Menjelang 17 Agustus 2019" required/></p>
<p><label>Keterangan QRCode</label><input type="text" name="e2" maxlength="250" class="form-control" placeholder="Cth.Anda mendapatkan Diskon Produk Baju Gamis, dst" required/></p>
<p><label>Jumlah Hari Aktif (Terhitung mulai hari ini)</label><input type="text" name="e3" maxlength="11" class="form-control" placeholder="Ketik angka" onkeypress="return hanyaAngka(event)" required/></p>
<p><label>Jenis QRCode</label>
	<select name="e4" class="form-control">
	    <option value='0'>Diskont</option>
	    <option value='1'>Event/Kegiatan</option>
	</select></p>   
<p>Pesan dari Pemilik/Panitia ke Prospek saat Validasi Kehadiran.<br><i>Pakai tag [judul], [nama], [email]</i></p>
    <textarea name="pesan1" cols="20" class='ckeditor' required>
    </textarea>

<input class="btn btn-secondary btn-border" type="submit" name="simpan" value="Simpan"/>
</form>
</div>