<?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)  {

    OpenHeader(_BLOCKMGR);
    $sqlwb = "SELECT mid, title, custom_title, active, view, inmenu FROM ".TABLE_MODULES." WHERE active='1' ORDER BY title ASC";
    if ( !($resultwb = $db->sql_query($sqlwb)) )
{ query_die(GENERAL_ERROR, 'Could not obtain Admin modules BlocksManager', '', __LINE__, __FILE__, $sqlwb);}
    while( $row = $db->sql_fetchrow($resultwb)) {
    $mid = $db->XMFnum($row['mid']);
    $title = stripslashes($row['title']);
    $active = $db->XMFbin($row['active']);
    $view = $db->XMFnum($row['view']);
    $inmenu = $db->XMFbin($row['inmenu']);
    Max_OpenTable();
    $i=0;
    $sqlwb1 = "SELECT b.bid, b.bkey, b.title, b.url, m.bposition, m.weight, b.active, b.blanguage, b.blockfile, b.view FROM ".TABLE_BLOCKS." b, ".TABLE_BLOCKSMANAGER." m WHERE b.bid=m.bid AND m.title='$title' ORDER BY bposition, weight";
    if ( !($resultwb1 = $db->sql_query($sqlwb1)) )
{ query_die(GENERAL_ERROR, 'Could not obtain Admin modules BlocksManager', '', __LINE__, __FILE__, $sqlwb1);}
    $numblocks = $db->sql_numrows($resultwb1);

    if ($numblocks == 0) { $statustitle = "<img src='images/red_dot.gif'>";
    } else { $statustitle = "<img src='images/green_dot.gif'>";}

     echo "<table border='1' width=\"40%\"><tr><td width='1%'>$statustitle</td><td align=\"center\" bgcolor=\"$bgcolor2\">&nbsp;&nbsp;&nbsp;"._CONFIGBLOCKS.": <a href='".$admin_file.".php?op=BlocksManager&wb_name=$title'><b>$title</b></a>&nbsp;&nbsp;&nbsp;</td></tr></table>";

    if ($numblocks == 0) {
    echo "<table border=\"1\" width=\"100%\">\n<tr><td align=\"center\"><i>"._NOBLOCKSAFFECTED."</i> $title"
        ."</td></tr></table>";
	Max_CloseTable();
    } else {


    echo "<table border=\"1\" width=\"100%\">\n<tr>\n"
        ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._BLOCKMGR_TITLE."</b></td>\n"
        ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._BLOCKMGR_POSITION."</b></td>\n"
        ."<td align=\"center\" bgcolor=\"$bgcolor2\" colspan=\"2\"><b>"._BLOCKMGR_WEIGHT."</b></td>\n"
	."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._TYPE."</b></td>"
        ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._BLOCKMGR_STATUS."</b></td>\n"
        ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._BLOCKMGR_VIEW."</b></td>\n";
    if ($multilingual == 1) {
        echo "<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._BLOCKMGR_LANGUAGE."</b></td>\n";
    }
    echo "<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></tr>";



    while($row1 = $db->sql_fetchrow($resultwb1)) {
    $bid = $db->XMFnum($row1['bid']);
    $bkey = stripslashes($row1['bkey']);
    $title = stripslashes(check_html($row1['title'], "nohtml"));
    $url = stripslashes($row1['url']);
    $bposition = stripslashes($row1['bposition']);
    $weight = $db->XMFnum($row1['weight']);
    $active = $db->XMFbin($row1['active']);
    $blanguage = stripslashes($row1['blanguage']);
    $blockfile = stripslashes($row1['blockfile']);
    $view = $db->XMFnum($row1['view']);




        $weight1 = $weight - 1;
        $weight3 = $weight + 1;

        $res1 = $db->sql_query("SELECT bid FROM ".TABLE_BLOCKSMANAGER." WHERE title='$title' AND weight='$weight1' AND bposition='$bposition'");
	$row2 = $db->sql_fetchrow($res1);
	$con1 = $db->XMFnum($row2['bid']);

        $res2 = $db->sql_query("SELECT bid FROM ".TABLE_BLOCKSMANAGER." WHERE title='$title' AND weight='$weight3' AND bposition='$bposition'");
	$row3 = $db->sql_fetchrow($res2);
	$con2 = $db->XMFnum($row3['bid']);

        $wb_url = "".$admin_file.".php?op=BlocksManager_BlockPosition&amp;wb_name=$wb_name&amp;bid=$bid&amp;position=";
        $t_position = "<form action=\"".$admin_file.".php\" method=\"post\">\n";
        $t_position .= "<select name=\"bposition\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">\n";
       // if (!isset($wb_name)) { $wb_name = "admin"; }
        $t_position .= "<option value=\"".$wb_url."l\"";
        if ($bposition=="l") { $t_position .= " selected"; $xcolor = "green"; } $t_position .= ">"._BLOCKMGR_LEFT."</option>\n";
        $t_position .= "<option value=\"".$wb_url."c\"";
        if ($bposition=="c") { $t_position .= " selected"; $xcolor = "blue"; } $t_position .= ">"._BLOCKMGR_CENTERUP."</option>\n";
        $t_position .= "<option value=\"".$wb_url."d\"";
        if ($bposition=="d") { $t_position .= " selected"; $xcolor = "black"; } $t_position .= ">"._BLOCKMGR_CENTERDOWN."</option>\n";
        $t_position .= "<option value=\"".$wb_url."r\"";
	if ($bposition=="r") { $t_position .= " selected"; $xcolor = "red"; } $t_position .= ">"._BLOCKMGR_RIGHT."</option>\n";
        $t_position .= "</select>\n</form>\n";

	echo "<tr>\n"
            ."<td align=\"center\"><font color='$xcolor'>$title</font></td>\n"
            ."<td align=\"center\">$t_position</td>\n"
            ."<td align=\"center\"><font color='$xcolor'>$weight</font></td>\n"
            ."<td align=\"center\">\n";
        if ($con1) {
            echo"<a href=\"".$admin_file.".php?op=BlocksManager_BlockOrder&amp;wb_name=$wb_name&amp;weight=$weight&amp;bidori=$bid&amp;weightrep=$weight1&amp;bidrep=$con1\">"
               ."<img src=\"images/up.gif\" alt=\""._BLOCKMGR_BLOCKUP."\" title=\""._BLOCKMGR_BLOCKUP."\" border=\"0\" hspace=\"3\">"
               ."</a>\n";
        }
        if ($con2) {
            echo "<a href=\"".$admin_file.".php?op=BlocksManager_BlockOrder&amp;wb_name=$wb_name&amp;weight=$weight&amp;bidori=$bid&amp;weightrep=$weight3&amp;bidrep=$con2\">"
                ."<img src=\"images/down.gif\" alt=\""._BLOCKMGR_BLOCKDOWN."\" title=\""._BLOCKMGR_BLOCKDOWN."\" border=\"0\" hspace=\"3\">"
                ."</a>\n";
        }
        echo"</td>\n";
        if ($bkey == "") {
				if ($url == "") {
					$type = "HTML";
				} elseif ($url != "") {
					$type = "RSS/RDF";
				}
				if ($blockfile != "") {
					$type = _BLOCKFILE2;
				}
			} elseif ($bkey != "") {
				$type = _BLOCKSYSTEM;
			}
	echo "<td align=\"center\"><font color='$xcolor'>$type</font></td>";
        $block_act = $active;
        if ($active == 1) {
            $active = "<img src=\"images/active.gif\" alt=\""._ACTIVE."\" title=\""._ACTIVE."\" border=\"0\" width=\"16\" height=\"16\">";
	    $change = "<img src=\"images/inactive.gif\" alt=\""._DEACTIVATE."\" title=\""._DEACTIVATE."\" border=\"0\" width=\"16\" height=\"16\">";
	    $block_config = 0;
        } elseif ($active == 0) {
            $active = "<img src=\"images/inactive.gif\" alt=\""._INACTIVE."\" title=\""._INACTIVE."\" border=\"0\" width=\"16\" height=\"16\">";
	    $change = "<img src=\"images/active.gif\" alt=\""._ACTIVATE."\" title=\""._ACTIVATE."\" border=\"0\" width=\"16\" height=\"16\">";
	    $block_config = 1;
        }
        echo "<td align=\"center\">$active</td>\n";
	//

	$url3 = "".$admin_file.".php?op=BlocksManager_View&amp;wb_name=$wb_name&amp;bid=$bid&amp;view=";
	$t_view = "<form action=\"".$admin_file.".php\" method=\"post\">\n";
        $t_view .= "<select name=\"view\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">\n";
        if (!isset($wb_name)) { $wb_name = "admin"; }
        $t_view .= "<option value=\"".$url3."0\"";
        if ($view == 0) { $t_view .= " selected"; } $t_view .= ">"._MVALL."</option>\n";
        $t_view .= "<option value=\"".$url3."1\"";
        if ($view == 1) { $t_view .= " selected"; } $t_view .= ">"._MVUSERS."</option>\n";
        $t_view .= "<option value=\"".$url3."2\"";
        if ($view == 2) { $t_view .= " selected"; } $t_view .= ">"._MVADMIN."</option>\n";
        $t_view  .= "<option value=\"".$url3."3\"";
	if ($view == 3) { $t_view .= " selected"; } $t_view .= ">"._MVANON."</option>\n";
	$t_view  .= "<option value=\"".$url3."4\"";
	if ($view > 3) { $t_view .= " selected"; } $t_view .= ">"._MVGROUPS."</option>\n";
        $t_view .= "</select>\n</form>\n";
        echo "<td align=\"center\">$t_view</td>\n";
        if ($multilingual == 1) {
            if ($blanguage == "") {
                $blanguage = _ALL;
            } else {
                $blanguage = ucfirst($blanguage);
            }
            echo "<td align=\"center\"><font color='$xcolor'>$blanguage</font></td>\n";
        }
echo "<td align=\"center\"><font class=\"content\">&nbsp;<a href=\"".$admin_file.".php?op=BlocksManager_BlocksEdit&amp;page=BlocksManager_AllModules&amp;bid=$bid\"><img src=\"images/edit.gif\" alt=\""._EDIT."\" title=\""._EDIT."\" border=\"0\" width=\"17\" height=\"17\"></a>  <a href=\"".$admin_file.".php?op=BlocksManager_ChangeStatus&amp;bid=$bid&amp;active=$block_config&amp;wb_name=$wb_name\">$change</a>  ";
	if ($bkey == "") {
		echo "<a href=\"".$admin_file.".php?op=BlocksManager_DelBlock&amp;wb_name=$wb_name&amp;bid=$bid&amp;ok=0\"><img src=\"images/delete.gif\" alt=\""._DELETE."\" title=\""._DELETE."\" border=\"0\" width=\"17\" height=\"17\"></a>  ";
	} elseif ($bkey != "") {
		echo "<img src=\"images/delete_x.gif\" alt=\""._DELETE."\" title=\""._DELETE."\" border=\"0\" width=\"17\" height=\"17\"> ";
	}

include_once ("kernel/popup.php");

	if ($block_act == 0) {
	echo "<a href='".$admin_file.".php?op=BlocksManager_block_show&bid=$bid' onclick=\"NewsReadWindow(this.href,'SeeBlock','600','400','yes');return false;\"><img src=\"images/view.gif\" alt=\""._SHOW."\" title=\""._SHOW."\" border=\"0\" width=\"17\" height=\"17\"></a></font>&nbsp;</td></tr>";
	} else {
		echo "<img src=\"images/view_x.gif\" alt=\""._SHOW."\" title=\""._SHOW."\" border=\"0\" width=\"17\" height=\"17\"></font>&nbsp;</td></tr>";
}


        echo "</tr>\n";
        $wb_tabblocks[$i] = $bid;
        $i++;
    }
    echo "</table>\n";
    br('1');
Max_CloseTable();
br('1');

}}

    CloseFooter();



}
}else {
	echo "Access Denied";
}