<?php
/**
* @package phpBB-WAP
* @copyright (c) phpBB Group
* @Оптимизация под WAP: Гутник Игорь ( чел ).
* @简体中文：中文phpBB-WAP团队
* @license http://opensource.org/licenses/gpl-license.php
**/

/**
* 这是一款自由软件, 您可以在 Free Software Foundation 发布的
* GNU General Public License 的条款下重新发布或修改; 您可以
* 选择目前 version 2 这个版本（亦可以选择任何更新的版本，由
* 你喜欢）作为新的牌照.
**/

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
}

$rule_id = ( isset($_GET['r']) ) ? abs(intval($_GET['r'])) : '';
$crid = ( isset($_GET['crid']) ) ? abs(intval($_GET['crid'])) : '';

if( $is_rules_auth )
{
	$rn = '';
	if ( $rule_id && $mode == 'delrule' )
	{
		$sql = "SELECT * FROM " . RULES_TABLE . " WHERE rule_id = $rule_id";
		if( !($result = $db->sql_query($sql)) )
		{
			trigger_error('Could not obtain rules information.', E_USER_WARNING);
		}
		$r = $db->sql_fetchrow($result);
		$rn = $r['rule_name'];
		$cr = $r['rule_cat_id'];
		$rule_base_id = $r['rule_id'];
		$page_title = '删除规则';
	}
	elseif ( $crid && $mode == 'delcat' )
	{
		$sql = "SELECT * FROM " . RULES_CAT_TABLE . " WHERE cat_r_id = $crid";
		if( !($result = $db->sql_query($sql)) )
		{
			trigger_error('Could not obtain rules cat information.', E_USER_WARNING);
		}
		$crid = $db->sql_fetchrow($result);
		$cridn = $crid['cat_r_name'];
		$crid_base = $crid['cat_r_id'];
		$page_title = '删除规则分类';
	}
	else
	{
		redirect(append_sid('rules.php', true));
	}

	if ( isset($_POST['cancel']) )
	{
		redirect(append_sid('rules.php', true));
	}

	$confirm = ( isset($_POST['confirm']) ) ? ( ( $_POST['confirm'] ) ? true : false ) : false;
	
	if( !$confirm )
	{
		page_header($page_title);
		
		$template->set_filenames(array(
			'confirm' => 'confirm_body.tpl')
		);

		$lang_confirm_rule = '请确认是否删除规则：' . $rn;
		$lang_confirm_cat = '请确认是否删除规则分类：' . $cridn;
		$s_confirm = ( $mode == 'delrule' ) ? append_sid("rules.php?mode=delrule&amp;r=$rule_base_id") : append_sid("rules.php?mode=delcat&amp;crid=$crid_base");

		$template->assign_vars(array(
			'MESSAGE_TITLE' 	=> '删除',
			'MESSAGE_TEXT'		=> ( $mode == 'delrule' ) ? $lang_confirm_rule : $lang_confirm_cat,
			'L_YES' 			=> '是',
			'L_NO' 				=> '否',
			'S_CONFIRM_ACTION' 	=> $s_confirm)
		);

		$template->pparse('confirm');

		page_footer();
		exit;
	}

	if ( $rule_base_id && $mode == 'delrule' )
	{
		$sql = "DELETE FROM " . RULES_TABLE . "
			WHERE rule_id = $rule_base_id";
		if( $db->sql_query($sql) )
		{
			trigger_error('Error delete rule', E_USER_WARNING);
		}
		redirect(append_sid("rules.php?crid=$cr", 1));
	}
	elseif ( $crid_base && $mode == 'delcat' )
	{
		$sql = 'DELETE FROM ' . RULES_CAT_TABLE . "
			WHERE cat_r_id = $crid_base";
			
		if( $db->sql_query($sql) )
		{
			trigger_error('Error delete rules cat', E_USER_WARNING);
		}
		
		$sql = "DELETE FROM " . RULES_TABLE . "
			WHERE rule_cat_id = $crid_base";
			
		if( !$db->sql_query($sql) )
		{
			trigger_error('Error delete rules', E_USER_WARNING);
		}
		
		redirect(append_sid('rules.php', true));
	}
	else
	{
		redirect(append_sid('rules.php', true));
	}
}
else
{
	redirect(append_sid('rules.php', true));
}
?>