<?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 Header("Location: ../../index.php");

$tipath = "images/topics/";
$module_name = "Topics";
get_lang($module_name);
$index = 1;
$pagetitle = "- "._ACTIVETOPICS."";

incoh( 'Topics', 'html',  "".CACHE_VTOPICS."", '1' );
Max_OpenTable();
$sql = "SELECT `topicid`, `topicname`, `topicimage`, `topictext` FROM `".TABLE_TOPICS."` ORDER BY `topictext`";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain topics modules', '', __LINE__, __FILE__, $sql);}
if ($GLOBALS['db']->sql_numrows($result) > 0) {
	$r_options = "";
	if (isset($cookie[4])) { $r_options .= "&amp;mode=$cookie[4]"; }
	if (isset($cookie[5])) { $r_options .= "&amp;order=$cookie[5]"; }
	if (isset($cookie[6])) { $r_options .= "&amp;thold=$cookie[6]"; }
	echo "<center><font class='title'><b>"._ACTIVETOPICS."</b></font><br />\n"
	."<font class=\"content\">"._CLICK2LIST."</font><br /><br />\n"
	."<form action=\"modules.php?name=Search\" method=\"post\">"
	."<input type=\"text\" name=\"query\" size=\"30\" />&nbsp;&nbsp;"
	."<input type=\"submit\" value=\""._SEARCH."\" />"
	."</form></center>";
	br('2');
	while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
		$topicid    = $GLOBALS['db']->XMFnum($row['topicid']);
		$topicname  = stripslashes($row['topicname']);
		$topicimage = stripslashes($row['topicimage']);
		$topictext  = stripslashes(check_html($row['topictext'], "nohtml"));
		$ThemeSel   = get_theme();
		if (@file_exists("themes/$ThemeSel/images/topics/$topicimage")) {
			$t_image = "themes/$ThemeSel/images/topics/$topicimage";
		} else {
			$t_image = "$tipath$topicimage";
		}
		$sql1 = "SELECT `counter` FROM `".TABLE_STORIES."` WHERE `topic`='$topicid'";
		if ( !($res = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stories modules', '', __LINE__, __FILE__, $sql1);}
		$numrows = $GLOBALS['db']->sql_numrows($res);
		$reads = 0;
		while ($counting = $GLOBALS['db']->sql_fetchrow($res)) {
			$ccounter = $GLOBALS['db']->XMFnum($counting['counter']);
			$reads = $reads+$ccounter;
		}
		title($topictext);
		echo "<a name=\"$topicid\"></a>";
		echo "<table border=\"1\" width=\"100%\" align=\"center\" cellpadding=\"2\">\n"
		."<tr><td valign=\"top\" width='25%'><a name=\"$topicid\"></a>\n"
		."<a href=\"modules.php?name=News&amp;new_topic=$topicid\"><img src=\"$t_image\" border=\"0\" alt=\"$topictext\" title=\"$topictext\" hspace='5' vspace='5' /></a><br /><br />\n"
		."<font class=\"content\">\n"
		."<big><strong>&middot;</strong></big>&nbsp;<b>"._TOPIC.":</b> $topictext<br />\n"
		."<big><strong>&middot;</strong></big>&nbsp;<b>"._TOTNEWS.":</b> $numrows<br />\n"
		."<big><strong>&middot;</strong></big>&nbsp;<b>"._TOTREADS.":</b> $reads</font>\n"
		."</td>\n"
		."<td valign=\"top\">";
		$sql2 = "SELECT `sid`, `catid`, `title` FROM `".TABLE_STORIES."` WHERE `topic`='$topicid' ORDER BY `sid` DESC LIMIT 0,10";
		if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stories modules', '', __LINE__, __FILE__, $sql2);}
		$num = $GLOBALS['db']->sql_numrows($result2);
		if ($num != 0) {
			while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
				$sid   = $GLOBALS['db']->XMFnum($row2['sid']);
				$catid = $GLOBALS['db']->XMFnum($row2['catid']);
				$title = stripslashes(check_html($row2['title'], "nohtml"));
	$sql3 = "SELECT `title` FROM `".TABLE_STORIES_CAT."` WHERE `catid`='$catid'";
	if ( !($result3 = $GLOBALS['db']->sql_query($sql3)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stories_cat modules', '', __LINE__, __FILE__, $sql3);}
	$row3 = $GLOBALS['db']->sql_fetchrow($result3);
				$rtitle = stripslashes(check_html($row3['title'], "nohtml"));
				if ($catid == 0) {
					$cat_link = "";
				} else {
					$cat_link = "<a href='modules.php?name=News&amp;file=categories&amp;op=newindex&amp;catid=$catid'><b>$rtitle</b></a>: ";
				}
				echo "<img src='modules/$module_name/images/arrow.gif' border='0' alt='' title='' />&nbsp;&nbsp;$cat_link<a href='modules.php?name=News&amp;file=article&amp;sid=$sid$r_options'>$title</a><br />";
			}
			if ($num == 10) {
				echo "<div align='right'><big><strong>&middot;</strong></big>&nbsp;<a href='modules.php?name=News&amp;new_topic=$topicid'><b>"._MORE." --></b></a>&nbsp;&nbsp;</div>";
			}
		} else {
			echo "<i>"._NONEWSYET."</i>";
		}
		echo "</td></tr></table>";
		br('2');
	}
}
Max_CloseTable();
incof( 'Topics', 'html',  "".CACHE_VTOPICS."", '1'  );