<?php
/**
* This file processes the rules that were selected 
* in rulesIndex.php for logged in users.
* @author Samuel Tran <stran2005@users.sourceforge.net>
* @author Nicolas Peyrussie <peyrouz@users.sourceforge.net>
* @version 04-03-07
* @package MailZu
*
* Copyright (C) 2005 - 2007 MailZu
* License: GPL, see LICENSE
*/
/**
* Include Template class
*/
include_once('lib/Template.class.php');
/**
* Include Quarantine functions 
*/
include_once('lib/Quarantine.lib.php');
/**
* Include common output functions
*/
include_once('templates/common.template.php');
/**
* Include quarantine-specific output functions
*/
include_once('templates/quarantine.template.php');

if (!Auth::is_logged_in()) {
    Auth::print_login_msg();	// Check if user is logged in
}
//Turn off all error reporting, useless for users
error_reporting(0);

$db = new DBEngine();

$t = new Template(translate('Rules Processing'));

$t->printHTMLHeader();
$t->printWelcome();
$t->startMain();

// Break table into 2 columns, put quick links on left side and all other tables on the right
startQuickLinksCol();
showQuickLinks();		// Print out My Quick Links
startDataDisplayCol();
global $conf;
$action = CmnFns::get_action();
$content_type = CmnFns::get_ctype();
$query_string = CmnFns::get_query_string();
$wblist_rule_array = CmnFns::getGlobalVar('wblist_rule_array', POST);

switch ( $_SESSION['sessionNav'] ) {
	case 'My rules':
		$referral = 'rulesIndex.php';
		break;
	case 'Site Rules':
		$referral = 'rulesAdmin.php';
		break;
}

// If no message was selected and the action is not "Delete All"
if ( ! isset($wblist_rule_array))
 	printNoMesgWarning();

elseif ( isset( $action ) ) {

	switch ( $action ) {
		case translate('Delete'):
			foreach ($wblist_rule_array AS $row) {
				list( $from, $to, $rule ) = explode( "_", $row );
				$db->wbdelete($rule,$to,$from);
			}
			CmnFns::redirect_js($referral . '?' . $query_string);
			break;
		default:
			CmnFns::do_error_box(translate('Unknown action type'), '', false);
	}

}

endDataDisplayCol();
$t->endMain();
$t->printHTMLFooter();
?>