<?php

include('config.php');
include('fungsi.php');

if(is_numeric($_GET['id']) && isset($_GET['code'])) {
	$id = $_GET['id'];	
	$bid = $_GET['code'];
	$query = mysqli_query($con,"SELECT * FROM gtm,prospek WHERE gtm.id_member=prospek.ID and gtm.id='$id' LIMIT 0,1");
	$check = mysqli_fetch_array($query,MYSQLI_ASSOC);
	$code = md5($check['id'].'||'.$check['id_grup']);
	$grup = $check['id_grup'];
	if ($code == $_GET['code']) {
		mysqli_query($con,"DELETE FROM gtm WHERE id='$id'");
		mysqli_query($con,"UPDATE grup SET jmlunsub=jmlunsub+1 WHERE id='$grup'");
		mysqli_query($con,"UPDATE broadcast SET unsub=unsub+1 WHERE ID='$bid'");
		
		$email = $check['email'];
		$pesan = 'Prosfek anda dengan email '.$email.' baru saja UNSUB dari grup "' .$grup.'"';
		mysqli_query($con,"insert into pesan1 values(NULL, '$pesan','3', NOW())");
		
		$query = mysqli_query($con,"SELECT * FROM akunn WHERE id=1");
	        $check = mysqli_fetch_array($query,MYSQLI_NUM);
	        if (isset($check[0])) {
				$urlhost =$check[4];
    	        $emailhost = $check[5];
    	        $passhost = $check[6];
	            $namao = $check[10];
	            $port = $check[11];
	            $emailapi = $check[12];
    	        $keyapi = $check[13];
    	        $hp = $check[7];
    	        $smsaktif = $check[14];
    	        $telegram_id = $check[16];
    	        $secret_token = $check[17];
	        }
	   $message_text = $pesan;
                sendMessage($telegram_id, $message_text, $secret_token);     
	        
		echo '<center>Terima kasih, anda sudah dihapus dari grup ini </center>';		
	}
}