<?php
include("inc.top.php");
$ord='';
$search='';

$t->set_file("content","member.area.emailbanlist.html");
$t->set_file("addtoban","member.area.addtobanlist.html");
$t->set_file("menu","member.area.view_emailbanlist.html");
$t->set_file("emailrow","member.area.emailban_row.html");

get_logged_info();
$member_id=$q->f("id");
echo $error;


	if ($_GET['add'] != '') {
		$t->parse("email_content","addtoban");
		$query = "SELECT  id,name FROM campaigns WHERE member_id='".$q->f("id")."'";
		$q->query($query);
		while ( $q->next_record()) {
			$select .= "<option value='".$q->f("id")."'>".$q->f("name")."</option>";
		}
		$t->set_var("select_campaign",$select);
		if ($error == '1' ) $t->set_var("email_content","<p align='center'>The email and campaign you entered already are on the ban list <br>"); 
		if ($error == '2' ) $t->set_var("email_content","<p align='center'>The email and campaign you entered must not be empty <br>"); 
		}
		else {
		
			if ($_GET['search_name'] != '') $search = " AND email LIKE '%".$_GET['search_name']."%'";
			if ($_GET['name'] == 'up') $ord=' ORDER BY name ASC';
			if ($_GET['name'] == 'down') $ord=' ORDER BY name DESC';
			if ($_GET['email'] == 'up') $ord=' ORDER BY email ASC';
			if ($_GET['email'] == 'down') $ord=' ORDER BY email DESC';
			if ($_GET['campaign'] == 'up') $ord=' ORDER BY campaign ASC';
			if ($_GET['campaign'] == 'down') $ord=' ORDER BY campaign DESC';
			if ($_GET['date_added'] == 'up') $ord=' ORDER BY date_added ASC';
			if ($_GET['date_added'] == 'down') $ord=' ORDER BY date_added DESC';
			if ($ord == '') $ord = ' ORDER BY date_added DESC';
			$t->parse("email_content","menu",true);
			$query = " SELECT banlist.id,banlist.name,campaigns.name as nume_camp,email,campaign,date_added,ban FROM banlist,campaigns WHERE campaigns.id=campaign AND banlist.member_id = '".$member_id."'".$search.$ord;
			
			$q->query($query);
			while ($q->next_record()) {
				$t->set_var("name",$q->f("name"));
				$t->set_var("email",$q->f("email"));
				$t->set_var("campaign",$q->f("nume_camp"));
				$t->set_var("date_added",$q->f("date_added"));
				$t->set_var("ban","<a href='unban.php?id={id}'>unban</a> ");
				$t->set_var("id",$q->f("id"));
				$t->parse("email_ban_row","emailrow",true);
				}
			}
			
			$t->set_file("menu_html", "member.area.menu.html");
			
			$t->parse("menu", "menu_html");
	
	$t->pparse("out", "content");	
		
//include("inc.bottom.php");
?>