<?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                                 */
/************************************************************************/
defined('MAXIMUS') or die ('Access denied block modules MAXIMUS directly...');

$block_name = "Modules";
get_blang("$block_name");

$content = "";

if (defined('ADMIN_ALLOW')) {
	$block_retention   = CACHE_BL_MODULES;
	$block_name_cache = "BlocModulesAdmin";
	$extension        = "php";
} elseif (defined('USER_ALLOW')) {
	$block_retention   = CACHE_BL_MODULES;
	$block_name_cache = "BlocModulesUser";
	$extension        = "html";
} else {
	$block_retention   = CACHE_BL_MODULES;
	$block_name_cache = "BlocModules";
	$extension        = "html";
}


if ( $content = opencacheb ( "".$block_name_cache."", "".$extension."", "".$block_retention."" ) ) {
 } else {

	$content .= "<div class='vertical'><a href='index.php'>"._HOME."</a><br /></div>\n";

    $sql = "SELECT `title`, `custom_title`, `view`, `groups` FROM `".TABLE_MODULES."` WHERE (`active`='1' AND `inmenu`='1' AND `install`='1') ORDER BY `custom_title` ASC";
    $a = 0; $dummy = 0;
    if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain _modules', '', __LINE__, __FILE__, $sql);}
    while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
	$m_title      = stripslashes($row['title']);
	$custom_title = stripslashes($row['custom_title']);
	$view         = $GLOBALS['db']->XMFnum($row['view']);
	$groups       = $GLOBALS['db']->XMFnum($row['groups']);

	if ( ($view == 0) || ($view == 1 AND (defined('USER_ALLOW') OR defined('ADMIN_ALLOW'))) || ($view == 2 AND defined('ADMIN_ALLOW')) || ($view == 3) || ($view > 3 AND in_groups($groups)) ) {
	$content .= "<div class='vertical'><a href=\"modules.php?name=$m_title\">$custom_title</a></div>\n";
	}

    }

    $GLOBALS['db']->sql_freeresult($result);
    /* If you're Admin you and only you can see Inactive modules and test it */
    /* If you copied a new module is the /modules/ directory, yuo can instll it by your administration */

    if (defined('ADMIN_ALLOW')) {
	$content .= ""._INVISIBLEMODULES."<br />";
	$content .= "<br /><center><b>"._INVISIBLEMODULES."</b><br /> ";
	$content .= "<font class='tiny'>"._ACTIVEBUTNOTSEE."</font></center><br /> ";
	$sql1 = "SELECT `title`, `custom_title` FROM `".TABLE_MODULES."` WHERE (`active`='1' AND `inmenu`='0' AND `install`='1') ORDER BY `custom_title` ASC";
        $a = 0; $dummy = 0;
	if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(CORE_ERROR, 'Could not obtain _modules', '', __LINE__, __FILE__, $sql1);}
	while ($row1 = $GLOBALS['db']->sql_fetchrow($result1)) {
	    $mn_title     = stripslashes($row1['title']);
	    $custom_title = stripslashes($row1['custom_title']);

	    if ($custom_title != "") {
		$content .= "<div class='vertical'><a href=\"modules.php?name=$mn_title\">$custom_title</a></div>\n";
		$dummy = 1;
	    } else {
		$a = 1;
	    }
	}
	if ($a == 1 AND $dummy != 1) {
    	    $content .= "<i>"._NONE."</i><br />\n";
	}
	$GLOBALS['db']->sql_freeresult($result1);

// not active
	$content .= "<br /><center><b>"._NOACTIVEMODULES."</b><br />";
	$content .= "<font class='tiny'>"._FORADMINTESTS."</font></center><br />";
	$sql2 = "SELECT `title`, `custom_title` FROM `".TABLE_MODULES."` WHERE `active`='0' AND `install`='1' ORDER BY `custom_title` ASC";
        $a = 0; $dummy = 0;
	if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(CORE_ERROR, 'Could not obtain _modules', '', __LINE__, __FILE__, $sql2);}
	while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
	    $mnna_title     = stripslashes($row2['title']);
	    $customna_title = stripslashes($row2['custom_title']);

	    if ($customna_title != "") {
		$content .= "<div class='vertical'><a href=\"modules.php?name=$mnna_title\">$customna_title</a></div>\n";
		$dummy = 1;
	    } else {
		$a = 1;
	    }
	}
	if ($a == 1 AND $dummy != 1) {
    	    $content .= "<i>"._NONE."</i><br />\n";
	}
	$GLOBALS['db']->sql_freeresult($result2);

// not intall
 	$content .= "<br /><center><b>"._NOINSTALLMODULES."</b><br /></center>";
	$content .= "<font class='tiny'>"._FORADMINTESTS."</font></center><br />";
	$sql3 = "SELECT `title`, `custom_title` FROM `".TABLE_MODULES."` WHERE (`install`='0' AND `install`='0') ORDER BY `custom_title` ASC";
        $a = 0; $dummy = 0;
	if ( !($result3 = $GLOBALS['db']->sql_query($sql3)) )
{ query_die(CORE_ERROR, 'Could not obtain _modules', '', __LINE__, __FILE__, $sql3);}
	while ($row3 = $GLOBALS['db']->sql_fetchrow($result3)) {
	    $mnot_title      = stripslashes($row3['title']);
	    $customnot_title = stripslashes($row3['custom_title']);

	    if ($customnot_title != "") {
		$content .= "<div class='vertical'><a href=\"\">$customnot_title</a></div>\n";
		$dummy = 2;
	    } else {
		$a = 2;
	    }
	}
	if ($a == 2 AND $dummy != 2) {
    	    $content .= "<i>"._NONE."</i><br />\n";
	}
 	echo "</div>";
	$GLOBALS['db']->sql_freeresult($result3);
    }
closecacheb ( "".$content."", "".$block_name_cache."", "".$extension."", "".$block_retention."" );
}