<?php
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///Script PHP/MYSQL of management of classifieds ads developed by Script PAG
///Script PAG all rights reserved. Use under license. http://www.script-pag.com
///////////////////////////////////////////////////////////////////////////////////////////

############################################################

require_once __DIR__.'/includes_adm/all_fns_adm.php';

///////////////////////////////////
//Check if an admin is connected
//////////////////////////////////
	
if(!empty($_SESSION['valid_admin']))
$valid_admin = $_SESSION['valid_admin'];

if(!check_valid_all())
redirect('index.php');

///////////////////////////////////
//Validation of type
//////////////////////////////////
	
if(!empty($_GET['type']))
{
	if($_GET['type'] >= 1 && $_GET['type'] <= 2)
	$type = (int) $_GET['type'];
	
	else redirect('index.php');
}
else redirect('index.php');

///////////////////////////////////
//Initializing variable $error
//////////////////////////////////

$error = '';

///////////////////////////////////
//Validation of data
//////////////////////////////////

if($type == 1 && isset($_POST['email']))
{
	if(empty($_POST['email']) || !valid_email($_POST['email']))
	$error = 1;
	
	elseif(!get_email_ban($_POST['email']))
	$error = 2;
}

///////////////////////////////////
//Remove email blacklisted and including html functions
//////////////////////////////////

if($type == 1 && !empty($_POST['email']) && empty($error))
{
	delete_email_ban($_POST['email']);
	create_cache_blacklist();
	
	$error = 'succes';
}

///////////////////////////////////
//Remove email blacklisted and including html functions
//////////////////////////////////

if($type == 2 && isset($_POST['keywords']))
{
	create_cache_blacklist_keywords($_POST['keywords']);
	
	$error = 'succes';
}

///////////////////////////////////
//Close database connexion
//////////////////////////////////

$conn = null;

///////////////////////////////////
//Display view
//////////////////////////////////

$view = array();
$view[] = 'template_adm/tpl_blacklist_adm.php';

require_once __DIR__.'/template_adm/tpl_layout_adm.php';