<?php
// +-------------------------------------------------------------+
// | HiveMail™ version 1.3.1
// +-------------------------------------------------------------+
// | HIVEMAIL™ IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than Hivemail or if you have otherwise received
// | this software from someone who is not a representative of
// | this organization you are involved in an illegal activity.
// +-------------------------------------------------------------+
// | $RCSfile: rules.rearrange.php,v $ - $Revision: 1.11 $
// | $Date: 2004/07/21 02:49:32 $ - $Author: tubedogg $
// +-------------------------------------------------------------+

error_reporting(E_ALL & ~E_NOTICE);
$templatesused = 'redirect_rules';
require_once('./global.php');

// ############################################################################
$ruleid = getinfo('rule', $ruleid, true);

// ############################################################################
// Get the rules
$rules = $DB_site->query("
	SELECT *
	FROM hive_rule
	WHERE userid = $hiveuser[userid]
	ORDER BY display
");
$oldrule = array();
while ($thisrule = $DB_site->fetch_array($rules)) {
	// Either this is the moving rule and we're moving it up, or the old rule is our man and we move it down
	if (!empty($oldrule) and (($oldrule['ruleid'] == $ruleid and $move == 'down') or ($thisrule['ruleid'] == $ruleid and $move == 'up'))) {
		// Swap this rule's display order with the previous one
		$DB_site->query("
			UPDATE hive_rule
			SET display = $thisrule[display]
			WHERE ruleid = $oldrule[ruleid]
		");
		$DB_site->query("
			UPDATE hive_rule
			SET display = $oldrule[display]
			WHERE ruleid = $thisrule[ruleid]
		");
		break;
	}
	$oldrule = $thisrule;
}

eval(makeredirect("redirect_rules", "rules.list.php"));

?>