<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
if ($acces == 1) {
if($admintest && $adminsecu)  {

    $wb_name     = stripslashes(trim($wb_name));
    $leftpos   = "l";
    $rightpos  = "r";
    $centerpos = "c";
    $downpos   = "d";

    $result = $GLOBALS['db']->sql_query("SELECT `bid` FROM `".TABLE_BLOCKSMANAGER."` WHERE ( `bposition`='$leftpos' AND `title`='$wb_name' ) ORDER BY `weight` ASC");
    $weight = 0;
    while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
	$bid = $GLOBALS['db']->XMFnum($row['bid']);
	$weight++;
	$GLOBALS['db']->sql_query("UPDATE `".TABLE_BLOCKSMANAGER."` SET `weight`='$weight' WHERE ( `bid`='$bid' AND `title`='$wb_name' AND `bposition`='$leftpos' ) ");
    }
    $result2 = $GLOBALS['db']->sql_query("SELECT `bid` FROM `".TABLE_BLOCKSMANAGER."` WHERE ( `bposition`='$rightpos' AND `title`='$wb_name' ) ORDER BY `weight` ASC");
    $weight = 0;
    while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
	$bid = $GLOBALS['db']->XMFnum($row2['bid']);
	$weight++;
	$GLOBALS['db']->sql_query("UPDATE `".TABLE_BLOCKSMANAGER."` SET `weight`='$weight' WHERE ( `bid`='$bid' AND `title`='$wb_name' AND `bposition`='$rightpos' ) ");
    }
    $result3 = $GLOBALS['db']->sql_query("SELECT `bid` FROM `".TABLE_BLOCKSMANAGER."` WHERE ( `bposition`='$centerpos' AND `title`='$wb_name' ) ORDER BY `weight` ASC");
    $weight = 0;
    while ($row3 = $GLOBALS['db']->sql_fetchrow($result3)) {
	$bid = $GLOBALS['db']->XMFnum($row3['bid']);
	$weight++;
	$GLOBALS['db']->sql_query("UPDATE `".TABLE_BLOCKSMANAGER."` SET `weight`='$weight' WHERE ( `bid`='$bid' AND `title`='$wb_name' AND `bposition`='$centerpos' ) ");
    }
    $result4 = $GLOBALS['db']->sql_query("SELECT `bid` FROM `".TABLE_BLOCKSMANAGER."` WHERE ( `bposition`='$downpos' AND `title`='$wb_name' ) ORDER BY `weight` ASC");
    $weight = 0;
    while ($row4 = $GLOBALS['db']->sql_fetchrow($result4)) {
	$bid = $GLOBALS['db']->XMFnum($row4['bid']);
	$weight++;
	$GLOBALS['db']->sql_query("UPDATE `".TABLE_BLOCKSMANAGER."` SET `weight`='$weight' WHERE ( `bid`='$bid' AND `title`='$wb_name' AND `bposition`='$downpos' ) ");
    }
    $GLOBALS['db']->sql_query("OPTIMIZE TABLE `".TABLE_BLOCKSMANAGER."`");

redirect_url("".$admin_file.".php?op=BlocksManager&wb_name=$wb_name");
}
} else {
	echo "Access Denied";
}