<?php
defined("BASEPATH") or exit("No direct access allowed");
if (isset($_POST['simpan'])){
if (!empty($_POST['nama']) && !empty($_POST['diskripsi'])) {
	$nama = mysqli_real_escape_string($con,$_POST['nama']);
	$diskripsi = mysqli_real_escape_string($con,$_POST['diskripsi']);
	$success =  mysqli_real_escape_string($con,$_POST['success']);
	$unsub = mysqli_real_escape_string($con,$_POST['unsubscribe']);
	$terdaftar = mysqli_real_escape_string($con,$_POST['terdaftar']);
	$nextemail = mysqli_real_escape_string($con,$_POST['nextemail']);
	$link1 = mysqli_real_escape_string($con,$_POST['link1']);
	$cap = mysqli_real_escape_string($con,$_POST['cap']);
	$membership = mysqli_real_escape_string($con,$_POST['membership']);
	
	//$dbcustom = '';
	if (isset($_POST['custom']) && is_array($_POST['custom'])) {
		foreach ($_POST['custom'] as $custom) {
			$clear = mysqli_real_escape_string($con,$custom);
			$dbcustom[txtonly($custom)] = $custom;			
		}
		$dbcustom = serialize($dbcustom);
	}

	mysqli_query($con,"INSERT INTO grup VALUE (NULL,'".$nama."','".$diskripsi."','$nowtgl','".$success."',".$unsub.",0,'".$terdaftar."','".$dbcustom."',".$nextemail.",'".$link1."','Masukkan Nama, Email dan HP Anda','Dijamin, Data anda kami rahasiakan','Subscriber','".$cap."',0,'https://yantonaim.web.id/bonus/','Ini adalah bonus untuk [nama] karena telah membagikan informasi ini.','Dishare ya, anda langsung mendapat bonus secara otomatis terkirim ke email anda',0,'".$membership."')");
	echo mysqli_error($con);
	$idgrup = mysqli_insert_id($con);
	$_SESSION['sesgrup'] = $idgrup;
	
	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 Berhasil Disimpan
                </div>
        <script>
        	        swal("Good Job","berhasil membuat baru data grup","success");
                </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> Nama, Penjelasan dan URL Sukses harus diisi
            </div>
    
    <script>
        	        swal('Good Job','ada masalah sehingga gagal menyimpan ','error');
                </script>     
            
            ";
}

}
?>
<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=listgrup"><i class="far fa-file"></i> Grup</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i> Baru</li>
                      </ol>
                    </nav>
                    
          </div>
          
          <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. Perhatikan semua isian. <br>
            2. URL Google Sheet untuk mengambil data otomatis dari Google Form/Sheet. Jadi saat ada prospek yang mengisi data di Google Form secara otomatis tersimpan di Auto BiznisTop dan secara otomatis juga prospek tersebut mendapatkan email.<br>
            3. Pastikan setting cronjob berjalan baik. Lihat panduan ebook dan video yang tersedia.
            </div>
            </div>
        </div> 
            
<div class="card-body">		  

<script type="text/javascript">
	var counter = 0;
	var limit = 15;
	function addInput(divName){
		if (counter > limit)  {
			alert("Batas Kedalaman " + (counter-1) + " level");
		} else {
			var newdiv = document.createElement('div');
			newdiv.innerHTML = "<p><label>New Field " + counter + " :</label><input type=\"text\" name=\"custom[" + counter + "]\"/> (Penulisan boleh spasi)</p>";
			document.getElementById(divName).appendChild(newdiv);
			counter++;
		}
	}
</script>

<form action="" method="post">
<p><label>Nama Grup</label><input type="text" name="nama" maxlength="100" class="form-control" placeholder="Contoh: Grup Penjualan Produk A" required/></p>
<p><label>Penjelasan Grup</label><input type="text" name="diskripsi" maxlength="250" class="form-control" placeholder="Grup Penjualan Produk A yang belum bayar" required/></p>
<p><label>URL Sukses Subscriber</label><input type="text" placeholder="Contoh: https://biznis.top (wajib diisi)" name="success" maxlength="200" class="form-control" required/></p>
<p><label>URL Jika Subscriber sudah terdaftar</label><input type="text" placeholder="Contoh: https://biznis.top" name="terdaftar" maxlength="250" class="form-control" required/></p>

<p><label>Saat email autoresponder berakhir, prospek dapat menerima email berikutnya yang ditambahkan?</label><select name="nextemail" id="exampleFormControlSelect1" class="form-control">
<option value="0">Tidak</option>
<option value="1">Ya</option>
</select>
</p>

<p><label>Aktifkan Captcha?</label><select name="cap" id="exampleFormControlSelect1" class="form-control">
<option value="0">Tidak</option>
<option value="1">Ya</option>
</select>
</p>

<p><label>Auto Pindah dari Grup (Jika anda pertama kali membuat grup, pilih None)</label><select name="unsubscribe" id="exampleFormControlSelect1" class="form-control">
<option value="0">None</option>
<?php
$query = mysqli_query($con,"SELECT id,nama FROM grup");
if (mysqli_num_rows($query) > 0) {
	while ($grup = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
		echo '<option value="'.$grup['id'].'">'.$grup['nama'].'</option>';
	}
}
?>
</select>
</p>

Field standar nama, email, dan hp. Anda dapat menambah field baru sejumlah 15 field.
<div id="dynamicInput"></div>
<input class="btn btn-secondary btn-border" type="button" value="Tambah Field Form" class="tombol" onClick="addInput('dynamicInput');">
<hr>
Pastikan ada kolom Nama, Email, HP pada Google Sheet
<p><label>URL Google Sheet</label><input type="text" placeholder="Contoh: https://docs.google.com/spreadsheets/d/e/2PACX-1vT-80vybcGh2kF9BwSL1AxcNotyXiL-UMytOHCNWCpTZTR8FioeNfvX317gLpYVPgGvGW8subl3_iL0/pub?gid=1590869017&single=true&output=csv (tidak wajib diisi)" name="link1" class="form-control" /></p>
Panduan intergrasi dengan google sheet, <a href="https://blog.biznis.top/2019/07/integrasi-dengan-google-sheet-form.html" target="_blank">KLIK DISINI</a> 
<hr>
<p><label>Script Form Opt dipasang pada</label><select name="membership" id="exampleFormControlSelect1" class="form-control">
<option value="0">Landing Page Elementor atau lainnya</option>
<option value="1">Aplikasi Membership BiznisTop</option>
<option value="2">Plugin Sejoli</option>
</select>
</p>
<hr>
<input class="btn btn-primary" type="submit" name="simpan" value="Simpan Grup"/>
</form>
</div>