<?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 random headline MAXIMUS directly...');

global $multilingual, $currentlang, $tipath, $cookie;

$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]"; }

if ($multilingual == 1) {
    $querylang = "AND (`alanguage`='$currentlang' OR `alanguage`='')"; /* the OR is needed to display stories who are posted to ALL languages */
} else {
    $querylang = "";
}

$numrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_TOPICS."`"));
if ($numrows > 1) {
    $sql = "SELECT `topicid` FROM `".TABLE_TOPICS."`";
    if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain _topics', '', __LINE__, __FILE__, $sql);}
    while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
	$topicid = $GLOBALS['db']->XMFnum($row['topicid']);
	$topic_array .= "$topicid-";
    }
    $r_topic = explode("-",$topic_array);
    mt_srand((double)microtime()*1000000);
    $numrows = $numrows-1;
    $topic = mt_rand(0, $numrows);
    $topic = $r_topic[$topic];
} else {
    $topic = 1;
}
$sql2 = "SELECT `topicimage`, `topictext` FROM `".TABLE_TOPICS."` WHERE `topicid`='$topic'";
if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(CORE_ERROR, 'Could not obtain _topics', '', __LINE__, __FILE__, $sql2);}
$row2 = $GLOBALS['db']->sql_fetchrow($result2);
$topicimage = stripslashes($row2['topicimage']);
$topictext  = stripslashes($row2['topictext']);
$content = "<br /><center><a href=\"modules.php?name=News&amp;new_topic=$topic\"><img src=\"$tipath$topicimage\" border=\"0\" alt=\"$topictext\" title=\"$topictext\" /></a><br />[ <a href=\"modules.php?name=Search&amp;topic=$topic\">$topictext</a> ]</center><br />";
$content .= "<table border=\"0\" width=\"100%\">";
$sql3 = "SELECT `sid`, `title` FROM `".TABLE_STORIES."` WHERE `topic`='$topic' $querylang ORDER BY `sid` DESC LIMIT 0,9";
if ( !($result3 = $GLOBALS['db']->sql_query($sql3)) )
{ query_die(CORE_ERROR, 'Could not obtain _stories', '', __LINE__, __FILE__, $sql3);}
while ($row3 = $GLOBALS['db']->sql_fetchrow($result3)) {
$sid   = $GLOBALS['db']->XMFnum($row3['sid']);
$title = stripslashes($row3['title']);
    $content .= "<tr><td valign=\"top\"><strong><big>&middot;</big></strong></td><td><a href=\"modules.php?name=News&amp;file=article&amp;sid=$sid$r_options\">$title</a></td></tr>";
}
$content .= "</table>";