<?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 (!stristr(htmlentities($_SERVER['SCRIPT_NAME']), "plan.php")) {
    Header("Location: index.php");
    die();
}
defined('MAXIMUS') OR include_once("mainfile.php");

$name = "Plan";
/********  CONFIGURATION   ****************/
// $mapforum  -> 1 activate / 0 deactivate
// $maptopics -> 1 activate / 0 deactivate
//$mapforum = 1;
//$maptopics = 1;
/******************************************/

$index = 1;

function ViewPlan($firstimg,$titre,$title,$url,$secondimg,$brconfig,$tab,$bold,$italik,$target) {
global $currentlang;
$currentlang = $GLOBALS['db']->XMFlang($currentlang);
if ($bold) { $bl1 = "<b>"; $bl2 = "</b>"; } else {$bl1 =  $bl2 = "";}
if ($italik) { $it1 = "<i>"; $it2 = "</i>"; } else { $it1 = $it2 = "";}
if ($target) { $targ = "target=\"new\"";  } else { $targ = ""; }

if ($tab) {
for ($h=0; $h < $tab; $h++) {
echo "&nbsp;";
} }
if ($currentlang=="english" AND $title) {
if ($firstimg) { echo "<img src=\"images/blocks/$firstimg\" alt=\"$title\" title=\"$title\" /> "; }
if ($url ) { echo "<a href=\"$url\">$title</a>"; } else { echo "$title"; }
if ($secondimg) { echo " <img src=\"images/blocks/$secondimg\" alt=\"\" /> "; }
if ($brconfig) {
for ($i=0; $i < $brconfig; $i++) {
br('1');
}
}
br('1');
}
elseif ($currentlang!="english" AND $titre) {
if ($firstimg) { echo "<img src=\"images/blocks/$firstimg\" alt=\"$titre\" title=\"$titre\"> "; }
if ($url ) { echo "<a href=\"$url\">$titre</a>"; } else { echo "$titre"; }
if ($secondimg) { echo " <img src=\"images/blocks/$secondimg\" alt=\"\" /> "; }
if ($brconfig) {
for ($i=0; $i < $brconfig; $i++) {
br('1');
}
}
br('1');
}
}

function Map() {
global $prefix ;
echo "<blockquote>";
$sql = "select `firstimg`, `titre`, `title`, `url`, `secondimg`, `brconfig`, `tab`, `bold`, `italik`, `target` FROM `".TABLE_PLAN."` WHERE `actif`='1' ORDER BY `id` ";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain plan config', '', __LINE__, __FILE__, $sql);}
while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
$firstimg  = stripslashes($row['firstimg']);
$titre     = stripslashes($row['titre']);
$title     = stripslashes($row['title']);
$url       = stripslashes($row['url']);
$secondimg = stripslashes($row['secondimg']);
$brconfig  = $GLOBALS['db']->XMFnum($row['brconfig']);
$tab       = $GLOBALS['db']->XMFnum($row['tab']);
$bold      = $GLOBALS['db']->XMFbin($row['bold']);
$italik    = $GLOBALS['db']->XMFbin($row['italik']);
$target    = $GLOBALS['db']->XMFbin($row['target']);

if ( ($view == 0) || ($view == 1 AND defined('USER_ALLOW') || defined('ADMIN_ALLOW')) || ($view == 1 AND !defined('USER_ALLOW') AND !defined('ADMIN_ALLOW')) || ($view == 2 AND defined('ADMIN_ALLOW'))  ||  ($view > 3 AND in_groups($groups) || defined('ADMIN_ALLOW')) ){
ViewPlan($firstimg,$titre,$title,$url,$secondimg,$brconfig,$tab,$bold,$italik,$target);
}
}
echo "</blockquote>";
$GLOBALS['db']->sql_freeresult($result);
br('3');
}

if ( MAXADV_MAPFORUM == 0 ) {
function MapForum() {
global $prefix, $sitename  ;
$sql = "select `cat_id`, `cat_title`, `cat_order` FROM `".$prefix."_bbcategories` ORDER BY `cat_order` ";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain mapforum config', '', __LINE__, __FILE__, $sql);}
echo "<blockquote>"
    ."<b><font size='3'>"._FORUMS." $sitename</font></b>"
    ."<blockquote>";
while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
$cat_id    = $GLOBALS['db']->XMFnum($row['cat_id']);
$cat_title = stripslashes($row['cat_title']);
$cat_order = $GLOBALS['db']->XMFnum($row['cat_order']);
echo "<img src=\"images/arrow2.gif\" alt=\"$cat_title\" title=\"$cat_title\" /> <a href=\"modules.php?name=Forums&amp;file=index&amp;c=$cat_id\">$cat_title</a>";
br('2');
$sql1 = "select `forum_name`, `forum_posts` FROM `".$prefix."_bbforums` WHERE `cat_id`='$cat_id' ORDER BY `forum_order`";
if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(CORE_ERROR, 'Could not obtain mapforum config', '', __LINE__, __FILE__, $sql1);}
while ($row1 = $GLOBALS['db']->sql_fetchrow($result1)) {
$forum_name  = stripslashes($row1['forum_name']);
$forum_posts = $GLOBALS['db']->XMFnum($row1['forum_posts']);
echo "&nbsp;&nbsp;&nbsp;<img src=\"images/blocks/arrow.png\" alt=\"$forum_name\" title=\"$forum_name\" /> <a href=\"modules.php?name=Forums&amp;file=viewforum&amp;f=$cat_id\">$forum_name</a> <font size=\"1\">( $forum_posts Posts )</font>";
br('1');
}
br('2');
}
br('2');
echo "</blockquote></blockquote>";
}
}

if ( MAXADV_MAPTOPICS == 0 ) {
function MapTopics() {
global $sitename ;
$sql = "select `topicid`, `topictext` FROM `".TABLE_TOPICS."` ORDER BY `topictext` ";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain maptopics config', '', __LINE__, __FILE__, $sql);}
echo "<blockquote>"
    ."<b><font size=\"3\">"._TOPICS." $sitename</font></b>"
    ."<blockquote>";
while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
$topicid   = $GLOBALS['db']->XMFnum($row['topicid']);
$topictext = stripslashes($row['topictext']);
$sql1 = "SELECT `sid` FROM `".TABLE_STORIES."` WHERE `topic`='$topicid' ";
if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(CORE_ERROR, 'Could not obtain mapforum config', '', __LINE__, __FILE__, $sql1);}
$numarticles = $GLOBALS['db']->sql_numrows($result1);

if ($numarticles > 1) {
$nbarticles = ""._ARTICLES."";
} else {
$nbarticles = ""._ARTICLE."";
}
echo "<img src=\"images/arrow2.gif\" alt=\"$topictext\" title=\"$topictext\" /> <a href=\"modules.php?name=News&amp;new_topics=$topicid\">$topictext</a> ( $numarticles $nbarticles )";
br('1');
}
br('2');
echo "</blockquote></blockquote>";
}
}


incoh( 'Plan', 'html', "".CACHE_VPLAN."", '1' );

echo "<center><font size='4'>"._MAPWEBSITE."</font></center>";
br('2');
Map();

if ( MAXADV_MAPFORUM == 0 ) {
	if ( is_active('Forums') ) {
		MapForum();
	}
}

if ( MAXADV_MAPTOPICS == 0 ) {
	if ( is_active('Topics') ) {
		MapTopics();
	}
}

incof( 'Plan', 'html', "".CACHE_VPLAN."", '1' );