<?php
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']) && isset($_REQUEST['uid']) && !empty($_REQUEST['uid'])):
$error = false;
include '../config.php';
function sanitize_input($data) { //filter value function
    global $db;

    return mysqli_real_escape_string($db->link, htmlspecialchars(stripslashes(trim($data))));
}
$evp_options_sql = "SELECT option_name, option_value FROM evp_options";
$evp_options_read = $db->select($evp_options_sql);
if ($evp_options_read) {
    $evp_options_check = mysqli_num_rows($evp_options_read);
    if ($evp_options_check > 0) {
        while ($row = $evp_options_read->fetch_assoc()) {
            $option_name[$row['option_name']] = $row['option_value'];
        }
        $evp_options_read->free();
        $a_url = $option_name['app_url'];
        $s_path = $option_name['script_path'];
        $site_title = $option_name['site_title'];
    }
}
	$del_email = sanitize_input($_REQUEST['email']);
	$user_id = sanitize_input($_REQUEST['uid']);
	$find_user_sql = "SELECT c_user_id, email_add, sent, c_name, list_name FROM evp_send_email_list 
						INNER JOIN evp_campaign_list  
						WHERE evp_campaign_list.c_name = evp_send_email_list.list_name and 
						evp_campaign_list.c_user_id = '$user_id' AND
						evp_campaign_list.c_unsub = 'true' AND
						evp_send_email_list.email_add = '$del_email' AND
						evp_send_email_list.sent = 'true'";
	$find_user_sql_read = $db->select($find_user_sql);
	if($find_user_sql_read->num_rows > 0 ){
	$delete_user_sql = "DELETE evp_send_email_list FROM evp_send_email_list 
				INNER JOIN evp_campaign_list  
				WHERE evp_campaign_list.c_name = evp_send_email_list.list_name and 
				evp_campaign_list.c_user_id = '$user_id' and
				evp_send_email_list.email_add = '$del_email' and
				evp_send_email_list.sent = 'true'";
	$delete_user_sql_read = $db->select($delete_user_sql);
	$error = false;
	} else {
	$error = true;
	}	
?>
<?php if($error == false) { ?>
<h2><?php _e('Your email address has been successfully removed from our list');?>!</h2>
<? } else { ?>
<h2><?php _e('Sorry, Your email address do not exists in our system');?>!</h2>
<?php } ?>
<?php 
else:
	 header("location: ../");
endif;
?>