 <?php
/**
 * $Source: /home/cvs/nukescripts/modules/AvantGo/index.php,v $
 * $Revision: 1.0.0-1 $
 * $Author: cyril $
 * $Date: 2006/09/10 14:46:04 $
 * Fix ligne 34 zorteil  - Bug 163
 */
/************************************************************************/
/* 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");

 $module_name = "AvantGo";
 get_lang($module_name);

 function avtgo() {
 	global $sitename, $slogan, $module_name, $site_logo;
 	header("Content-Type: text/html");
 	echo "<html>\n"
 	."<head>\n"
 	."<title>$sitename - AvantGo</title>\n"
 	."<meta name=\"HandheldFriendly\" content=\"True\">\n"
 	."</head>\n"
 	."<body>\n\n\n"
 	."<div align=\"center\">\n";
 	$sql = "SELECT `sid`, `title`, `time` FROM `".TABLE_STORIES."` ORDER BY `sid` DESC LIMIT 10";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(MODULE_ERROR, 'Could not obtain stories', '', __LINE__, __FILE__, $sql);}
 	if (!$result) {
 		echo "An error occured";
 	} else {
 		echo "\t<a href=\"index.php\"><img src=\"images/$site_logo\" alt=\"$slogan\" title=\"$slogan\" border=\"0\" /></a><br /><br />\r\n"
 		."\t<table border=\"0\" align=\"center\">\r\n"
 		."\t\t<tr>\r\n"
 		."\t\t\t<td bgcolor=\"#efefef\">"._TITLE."</td>\r\n"
 		."\t\t\t<td bgcolor=\"#efefef\">"._DATE."</td>\r\n"
 		."\t\t</tr>\r\n";
 		for ($m=0; $m < $GLOBALS['db']->sql_numrows($result); $m++) {
 			$row = $GLOBALS['db']->sql_fetchrow($result);
 			$sid = $GLOBALS['db']->XMFnum($row['sid']);
 			$title = stripslashes(check_html($row['title'], "nohtml"));
 			$time  = stripslashes($row['time']);
 			echo "\t\t<tr>\r\n"
 			."\t\t\t<td><a href=\"modules.php?name=$module_name&amp;op=ReadStory&amp;sid=$sid\">$title</a></td>\r\n"
 			."\t\t\t<td>$time</td>\r\n"
 			."\t\t</tr>\r\n";
 		}
 		echo"\t</table>\r\n";
 	}
 	echo "</body>\n"
 	."</html>";
 	include_once ("includes/counter.php");
 	die();
 }

 function ReadStory($sid) {
 	global $site_logo, $nukeurl, $sitename, $datetime, $module_name;
 	$sid = $GLOBALS['db']->XMFnum($sid);
 	$sql = "SELECT `sid` FROM `".TABLE_STORIES."` WHERE `sid`='$sid'";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(MODULE_ERROR, 'Could not obtain stories', '', __LINE__, __FILE__, $sql);}
	$num = $GLOBALS['db']->sql_numrows($result);
 	if ($num == 0) {
 		redirect_url("modules.php?name=$module_name");
 		die();
 	}
 	$sid = $GLOBALS['db']->XMFnum(trim($sid));
 	$sql1 = "SELECT `title`, `time`, `hometext`, `bodytext`, `topic`, `notes` FROM `".TABLE_STORIES."` WHERE `sid`='$sid'";
	if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(MODULE_ERROR, 'Could not obtain stories', '', __LINE__, __FILE__, $sql1);}
	$row1 = $GLOBALS['db']->sql_fetchrow($result1);
 	$title = stripslashes($row1['title']);
 	$time = stripslashes($row1['time']);
 	$hometext = stripslashes($row1['hometext']);
 	$bodytext = stripslashes($row1['bodytext']);
 	$topic = $GLOBALS['db']->XMFnum($row1['topic']);
 	$notes = stripslashes($row1['notes']);
 	$sql2 = "SELECT `topictext` FROM `".TABLE_TOPICS."` WHERE `topicid`='$topic'";
	if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(MODULE_ERROR, 'Could not obtain stories', '', __LINE__, __FILE__, $sql2);}
	$row2 = $GLOBALS['db']->sql_fetchrow($result2);
 	$topictext = stripslashes($row2['topictext']);
 	formatTimestamp($time);
 	echo "
    <html>
    <head>
    <title>$sitename - $title</title>
    <meta name=\"HandheldFriendly\" content=\"True\">
    </head>
    <body bgcolor=\"#ffffff\" text=\"#000000\">
    <table border=\"0\" align=\"center\"><tr><td>
    <table border=\"0\" width=\"640\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#000000\"><tr><td>
    <table border=\"0\" width=\"640\" cellpadding=\"20\" cellspacing=\"1\" bgcolor=\"#ffffff\"><tr><td>
    <center>
    <img src=\"images/$site_logo\" border=\"0\" alt=\"\"><br /><br />
    <font class=\"content\">
    <b>$title</b></font><br />
    <font class=tiny><b>"._PDATE."</b> $datetime<br /><b>"._PTOPIC."</b> $topictext</font><br /><br />
    </center>
    <font class=\"content\">
    $hometext<br /><br />
    $bodytext<br /><br />
    $notes<br /><br />
    </font>
    </td></tr></table></td></tr></table>
    <br /><br /><center>
    <font class=\"content\">
    "._COMESFROM." $sitename<br />
    <a href=\"$nukeurl\">$nukeurl</a><br /><br />
    "._THEURL."<br />
    <a href=\"$nukeurl/modules.php?name=News&file=article&sid=$sid\">$nukeurl/modules.php?name=News&file=article&sid=$sid</a>
    </font>
    </td></tr></table>
    </body>
    </html>
    ";
$GLOBALS['db']->sql_freeresult($result);
$GLOBALS['db']->sql_freeresult($result1);
 }

 switch($op) {

 	case "ReadStory":
 	ReadStory($sid);
 	break;

 	default:
 	avtgo();
 	break;
 }