<?php
 defined("BASEPATH") or exit("No direct access allowed");
 $query1 = mysqli_query($con,"select count(*) from grup order by tgl_bikin desc");
   $statusbc1 = mysqli_fetch_array($query1,MYSQLI_NUM);
   $jml1 = $statusbc1[0];
   
if (isset($_GET['hapus']) && is_numeric($_GET['hapus'])) {
		$hapus = $_GET['hapus'];
		
		mysqli_query($con,"DELETE FROM grup WHERE id=$hapus");
		mysqli_query($con,"DELETE FROM gtm WHERE id_grup=$hapus");
		mysqli_query($con,"DELETE FROM bc WHERE grup_target=$hapus");
		mysqli_query($con,"DELETE FROM champ WHERE grup=$hapus");
		
		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 Grup dengan id '.$hapus.' Telah Dihapus
            </div>
            
            <script>
        	        swal("Good Job","berhasil menghapus data grup","success");
                </script>     
		';
		
	}
      
if (isset($_POST['reset'])){
    $grup = $_POST['grup'];
    mysqli_query($con,"UPDATE gtm SET customdata='' WHERE id_grup=$grup");
    mysqli_query($con,"UPDATE grup SET custom='' WHERE id=$grup");
    echo '<script>
        	        swal("Good Job","Berhasil Reset","success");
                </script>
    ';
}

if (isset($_POST['aktif'])){
    $grup = $_POST['grup'];
    mysqli_query($con,"UPDATE champ SET stschamp=1 WHERE grup=$grup");
    echo '<script>
        	        swal("Good Job","Berhasil Diaktifkan","success");
                </script>
    ';
}

if (isset($_POST['nonaktif'])){
    $grup = $_POST['grup'];
    mysqli_query($con,"UPDATE champ SET stschamp=0 WHERE grup=$grup");
    echo '<script>
        	        swal("Good Job","Berhasil Non Diaktifkan","success");
                </script>
    ';
}

if( isset( $_REQUEST['aksi'] )){
		$aksi = $_REQUEST['aksi'];
		switch($aksi){
			case 'baru':
				include 'newgrup.php';
				break;
			case 'edit':
				include 'editgrup.php';
				break;
			case 'hapus':
				include 'hapusproduk.php';
				break;
			case 'form':
				include 'editform.php';
				break;
			case 'viral':
				include 'editviral.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="#"><i class="far fa-file"></i> Grup</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. Buat Grup baru klik +Grup. <br>
            2. Script Form Opt akan tampil setelah anda membuat pesan auto. <a href="index.php?page=pesanauto">KLIK DISINI</a><br>
            3. Saat menghapus pastikan memang betul2 anda menghapus karena akan terhapus juga data Broadcast, Auto Pesan dan Grup Member. <br>
            4. Untuk pengguna plugin elementor pada CMS wordpress dapat menggunakan script <a href="https://blog.biznis.top/2019/05/script-form-responsive-untuk-elementor.html" target="_blank">INI</a> untuk mempercantik tampilan form.<br>
            5. Jika anda menggunakan WP Affiliasi dari CB dan sudah diintegrasikan dengan Auto BiznisTop, silahkan download Plugin Wordpress Auto BiznisTop dan instal kemudian lakukan setting.<br>
            6. Jika klik Tombol Reset Custom Field maka nama Field Custom dan datanya hilang dan tidak bisa dikembalikan.<br>
            7. Script Form Opt support pada layanan Sejoli, Plugin Prokemsuite, Plugin Woowa Premium dan plugin Wuoymembership.<br>
            8. Disarankan agar jumlah prospek/subscriber dalam grup mengikuti jumlah batas pengiriman email dari pihak hosting.
            </div>
            </div>
        </div> 
            
            <!-- /.box-header -->
            
                
				<form class="form-horizontal" role="form" action="index.php?page=listgrup&aksi=baru" method="POST">
				<button class="btn btn-secondary">
				<span class="btn-label">
					<i class="fa fa-plus"></i>
				</span>
				Grup
				</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>Nama / No.Grup</th>
                            <th>Keterangan Grup</th>
                            <th>Tgl.Create</th>
                            <th>Jml.Prospek <br>Subs/Unsub</th>
                            <th>Jml.Email <br>Auto/Broacast</th>
                            <th>Script Form Opt (Pasang di web/blog) / URL untuk Plugin Auto BiznisTop di Wordpress / URL Form Default</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Action</th>
							<th>Nama Grup</th>
                            <th>Keterangan Grup</th>
                            <th>Tgl.Create</th>
                            <th>Jml.Prospek <br>Subs/Unsub</th>
                            <th>Jml.Email <br>Auto/Broacast</th>
                            <th>Script Form Opt (Pasang di web/blog) / URL untuk Plugin Auto BiznisTop di Wordpress / URL Form Default</th>
                        </tr>
                    </tfoot>
                    <tbody>
                       <?php
                            
                            $qu=mysqli_query($con,"select * from grup order by id desc");
                            while($data=mysqli_fetch_row($qu)){
                                
                                $eid= md5($data[0]);
                                
                                $q1 = mysqli_query($con,"SELECT count(id) FROM gtm where id_grup=$data[0]");
                                   $s1 = mysqli_fetch_array($q1,MYSQLI_NUM);
                                   $jml1 = $s1[0];
                                   
                                $q2 = mysqli_query($con,"SELECT count(ID) FROM champ where grup=$data[0]");
                                   $s2 = mysqli_fetch_array($q2,MYSQLI_NUM);
                                   $jml2 = $s2[0];
                                   
                                $q3 = mysqli_query($con,"SELECT count(ID) FROM bc where grup_target=$data[0]");
                                   $s3 = mysqli_fetch_array($q3,MYSQLI_NUM);
                                   $jml3 = $s3[0];
                                   
                                $ceksts = mysqli_query($con,"SELECT stschamp FROM champ where grup=$data[0]");
                                   $s4 = mysqli_fetch_array($ceksts,MYSQLI_NUM);
                                   $stschamp = $s4[0];    
                                IF(isset($stschamp)){
                                    $stschamp = $stschamp;
                                }   
                                
                                IF($data[20]==0){
                                  $action = $weburl.'/subs.php';
                                }elseIF($data[20]==1){
                                  $action = $weburl.'/subs2.php';  
                                }elseIF($data[20]==2){
                                  $action = $weburl.'/subs.php';  
                                }    
								                            
                                echo "
                                <tr>
                                    <td>   
									<a type='button' class='btn btn-icon btn-round btn-default' href='index.php?page=listgrup&aksi=edit&id=$eid' >EDIT</a>
									
									<a type='button' class='btn btn-icon btn-round btn-default' onclick='return konfirmasi()' href='?page=listgrup&hapus=$data[0]'>DEL</a>
									
									</td>
                                    <td>
                                        $data[1] ($data[0])
                                    </td>
                                    <td>
                                        $data[2] 
                                    </td>
                                    <td>
                                        $data[3] 
                                    </td>
                                    <td>
                                        $jml1 / $data[6] 
                                    </td>
                                    <td>
                                        $jml2 / $jml3 
                                    </td>
                                    <td>
                                    ";
									
										$query = mysqli_query($con,"SELECT count(*) FROM champ WHERE grup=$data[0]");
										$check = mysqli_fetch_array($query,MYSQLI_NUM);
										if ($check[0] > 0) {
											$query = mysqli_query($con,"SELECT * FROM grup WHERE id=$data[0] LIMIT 0,1");
											$grup = mysqli_fetch_array($query,MYSQLI_ASSOC);
											echo '
											<div style="background:#5ab4dd;padding:10px;border:1px solid #000000">
											&lt;form id="keform'.$data[0].'" action="'.$action.'" method="post"&gt;
												&lt;p&gt;&lt;label&gt;Nama&lt;/label&gt;&lt;input type="text" name="name" required/&gt;&lt;/p&gt;
												&lt;p&gt;&lt;label&gt;Email&lt;/label&gt;&lt;input type="email" name="email" required/&gt;&lt;/p&gt;
												&lt;p&gt;&lt;label&gt;HP/WA&lt;/label&gt;&lt;input type="number" name="hp" required/&gt;&lt;/p&gt;';
												$custom = unserialize($grup['custom']);
												if (is_array($custom)) {
													foreach ($custom as $custom)             {
										echo '&lt;p&gt;&lt;label&gt;'.$custom.'&lt;/label&gt;&lt;input type="text" name="custom['.txtonly($custom).']"/&gt;&lt;/p&gt;';
													}
												}
												
										echo ' &lt;input type="hidden" name="grup" value="'.$data[0].'"/&gt;
												&lt;p&gt;
										     ';
										
										IF($data[14]==1){
										    
										echo ' &lt;img src=&quot;'.$weburl.'/login/Captcha.php&quot; alt=&quot;gambar&quot; height=&quot;100%&quot; width=&quot;45%&quot;/&gt; &lt;br&gt;
                                        &lt;input name=&quot;nilaiCaptcha&quot; value=&quot;&quot; maxlength=&quot;6&quot; placeholder=&quot;Ketik kode Captcha&quot; required/&gt;
                                             ';
										}		
										
										echo  ' &lt;br&gt;&lt;input type="submit" class="tombol" value="Subscribe"/&gt;&lt;/p&gt;
											&lt;/form&gt;
											</div>';
											
										If(!empty($custom)){	
											echo '
											 <form action="" <form action="" method="post">
										<input type="hidden" name="grup" value="'.$data[0].'">	 
											<input type="submit" name="reset" value="Reset Custom Field"/>
											</form>
											
											';
										}
											
											echo '
											<div style="background:#d4bf4c;padding:10px;border:1px solid #000000">
											'.$weburl.'/kirim1.php?grup='.$data[0].'&ver='.$lisensi.'
											</div>
											';
											
    										IF($stschamp==1){
    										    echo '
    										    
    										    <div style="background:#20f5c0;padding:10px;border:1px solid #000000">
											'.$weburl.'/form/'.$data[0].'
											</div>
											
											<div style="background:#2c97f5;padding:10px;border:1px solid #000000">
											'.$weburl.'/webhookelementor/'.$data[0].'
											</div>
											
                								<form action="" <form action="" method="post">
            										<input type="hidden" name="grup" value="'.$data[0].'">	 
            											<input type="submit" name="nonaktif" value="Non Aktifkan Pesan Auto"/>
        											</form>
        											
        										<a type="submit" class="btn btn-icon btn-round btn-default" href="index.php?page=listgrup&aksi=form&id='.$data[0].'">Setting Form Default</a>
        										
        										<a type="submit" class="btn btn-icon btn-round btn-default" href="index.php?page=listgrup&aksi=viral&id='.$data[0].'">Setting Viralkan</a>
        										
    										    ';
    										}else{    
    										    echo '
                								<form action="" <form action="" method="post">
            										<input type="hidden" name="grup" value="'.$data[0].'">	 
            											<input type="submit" name="aktif" value="Aktifkan Pesan Auto"/>
        											</form>
    										    ';
    										}	
											
										} else {
											echo 'Script Form Opt tidak tampil karena anda belum membuat pesan auto, 
											silahkan buat <a href="index.php?page=pesanauto"><b>KLIK DISINI</b></a>';
										}
								echo "		
                                    </td>   
                                </tr>
                                ";
                            }
                       ?>
                    </tbody>
                </table>
                </div>
                
 </div>
            <!-- /.box-body -->
        


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