<?php
defined("BASEPATH") or exit("No direct access allowed");
?>
<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> Edit</li>
                      </ol>
                    </nav>

    
 <?php 

if (isset($_POST['ubah'])){
          
            $id = $_POST['id'] ;
            $p1 = mysqli_real_escape_string($con,$_POST['p1']);
            $p2 = mysqli_real_escape_string($con,$_POST['p2']);
            $p3 = mysqli_real_escape_string($con,$_POST['p3']);
            $p6 = mysqli_real_escape_string($con,$_POST['p6']);
            $p4 = mysqli_real_escape_string($con,$_POST['p4']);
            $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']);
			
			if (is_array($_POST['custom'])) {
			foreach ($_POST['custom'] as $custom) {
				$clear = special($custom);
				$dbcustom[txtonly($custom)] = $custom;			
				}		
			}

			$dbcustom = serialize($dbcustom);

            mysqli_query($con,"update grup set nama='$p1',diskripsi='$p2',success='$p3',unsub='$p6',terdaftar='$p4',custom='$dbcustom',nextemail='$nextemail',link1='$link1',cap='$cap',membership='$membership' where md5(id)='".$_GET['id']."'");
            
               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 Diubah
                </div> 
                ';
               
               echo "
               <div class='container'>
                 <form class='form-horizontal' role='form' action='index.php?page=listgrup' method='POST'>
                   <button type='submit' class='btn btn-primary'><span class='glyphicon glyphicon-log-out'></span> Kembali</button>
                 </form>
               </div>
               
               <script>
        	        swal('Good Job','berhasil mengubah data grup','success');
                </script>     
                
               " ;
             
}
?>
   
 <?php 
    
      $tampil=mysqli_fetch_row(mysqli_query($con,"select * from grup where md5(id)='".$_GET['id']."'"));
      
      

   ?>   

<div class="card-body">            

    
      <form action="" method="POST">
            <input type="hidden" name="id" value="<?php echo $tampil['id']; ?>">
      
      <form action="" method="POST">
        <p><label>Nama Grup</label><input type="text" name="p1" class="form-control" placeholder="Nama Grup" value="<?php echo $tampil[1]; ?>"></p>
        <p><label>Penjelasan Grup</label><input type="text" name="p2" class="form-control" placeholder="Penjelasan Grup" value="<?php echo $tampil[2]; ?>"></p>
        <p><label>URL Sukses</label><input type="text" name="p3" class="form-control" placeholder="Contoh: https://biznis.top/" value="<?php echo $tampil[4]; ?>"></p>
        <p><label>URL Jika Subscriber sudah terdaftar</label><input type="text" name="p4" class="form-control" placeholder="Contoh: https://biznis.top/" value="<?php echo $tampil[7]; ?>"></p>
        
        <p><label>Saat email autoresponder berakhir, prospek dapat menerima email berikutnya yang ditambahkan?</label>
        
         <?php  
            $result = mysqli_query($con,"SELECT * FROM grup where md5(id)='".$_GET['id']."' ORDER BY id");
            while($row = mysqli_fetch_assoc($result)){
                if($row['nextemail']==0) {
                    $ktw = 'Tidak';
                }else{
                    $ktw = 'Ya';
                }     
            echo "<select name='nextemail' class='form-control'>
            <option value=$row[nextemail]>$ktw</option>
            <option value='0'>Tidak</option>
            <option value='1'>Ya</option>
            </select> 
            ";
            } 
            ?>
         </p>
        
        <p><label>Aktifkan Captcha</label>
        
         <?php  
            $result = mysqli_query($con,"SELECT * FROM grup where md5(id)='".$_GET['id']."' ORDER BY id");
            while($row = mysqli_fetch_assoc($result)){
                if($row['cap']==0) {
                    $cap = 'Tidak';
                }else{
                    $cap = 'Ya';
                }     
            echo "<select name='cap' class='form-control'>
            <option value=$row[cap]>$cap</option>
            <option value='0'>Tidak</option>
            <option value='1'>Ya</option>
            </select> 
            ";
            } 
        ?>
        </p>

		<p><label>Pindah otomatis dari grup ini saat selesai Subscriber</label><select name="p6" class="form-control">
		<?php
		
		$query=mysqli_query($con,"select id,nama from grup");
        while($unsub=mysqli_fetch_array($query)){
			echo '<option  value="'.$unsub['id'].'"';
			if ($unsub['id'] == $tampil[5]) {  echo ' selected="selected"'; $i=1; }
			echo '>'.$unsub['nama'].'</option>';
		}
		echo '<option value="0"';
		if ($i==0) { echo ' selected="selected"'; }
		echo '>None</option></select></p>';
		
		
		
		$custom = unserialize($tampil[8]);
		$i = 0;
		if (is_array($custom)) {		
		foreach ($custom as $custom) {
			echo '<p><label>Custom Field '.$i.'</label><input type="text" name="custom[]" value="'.$custom.'"/></p>';
			$i++;
		}
		}
		echo '
		<script type="text/javascript">
			var counter = '.$i.';
			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>
		Field standar nama, email, dan hp. Anda dapat menambah field baru sejumlah 15 field.
		<div id="dynamicInput"></div>
		
		
        
		<p><input 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" name="link1" class="form-control" value="<?php echo $tampil[10]; ?>"></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>
        
         <?php  
            $result = mysqli_query($con,"SELECT * FROM grup where md5(id)='".$_GET['id']."' ORDER BY id");
            while($row = mysqli_fetch_assoc($result)){
                if($row['membership']==0) {
                    $ktw = '1).Landing Page Elementor atau lainnya';
                }elseif($row['membership']==1) {
                    $ktw='2).Aplikasi Membership BiznisTop';
                }else{
                    $ktw = '3).Plugin Sejoli';
                }     
            echo "<select name='membership' class='form-control'>
            <option value=$row[membership]>$ktw</option>
            <option value='0'>1).Landing Page Elementor atau lainnya </option>
            <option value='1'>2).Aplikasi Membership BiznisTop</option>
            <option value='2'>3).Plugin Sejoli</option>
            </select> 
            ";
            } 
            ?>
         </p>
         
        <div class="form-group">
          <div class  ="col-sm-4">
            <button type="submit" class="btn btn-primary" name="ubah"><span class="glyphicon glyphicon-pencil"></span> Ubah</button>
          </div>
        </div>
      </form>
    
</div>
    