<?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                                 */
/************************************************************************/
/* NSN News                                             */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright  2000-2005 by NukeScripts Network         */
/********************************************************/
defined('MAXIMUS') OR include_once("mainfile.php");

include_once("includes/counter.php");
include_once("modules/News/includes/functions.php");
$module_name = "News";
get_lang($module_name);

if (stristr($REQUEST_URI,"mainfile")) {
    redirect_url("modules.php?name=$module_name&file=read_article&sid=$sid");
} elseif (!isset($sid) && !isset($tid)) {
    redirect_url("index.php");
}

if ($save AND defined('USER_ALLOW')) {
    cookiedecode($user);
    $db->sql_query("UPDATE `".TABLE_USERS."` SET `umode`='$mode', `uorder`='$order', `thold`='$thold' WHERE `uid`='$cookie[0]'");
    getusrinfo($user);
    $info = base64_encode("$userinfo[user_id]:$userinfo[username]:$userinfo[user_password]:$userinfo[storynum]:$userinfo[umode]:$userinfo[uorder]:$userinfo[thold]:$userinfo[noscore]");
    @setcookie("user","$info",time()+$cookieusrtime);
}

if ($op == "Reply") {
    redirect_url("modules.php?name=$module_name&file=comments&op=Reply&pid=0&sid=$sid&mode=$mode&order=$order&thold=$thold");
}

$sql = "SELECT `catid`, `aid`, `time`, `title`, `hometext`, `bodytext`, `topic`, `informant`, `notes`, `acomm`, `haspoll`, `pollID`, `score`, `ratings` FROM `".TABLE_STORIES."` WHERE `sid`='$sid'";
if ( !($result = $db->sql_query($sql)) )
{ query_die(MODULE_ERROR, 'Could not SELECT stories WebSite', '', __LINE__, __FILE__, $sql);}
if ($numrows = $db->sql_numrows($result) != 1) {
    redirect_url("index.php");
    die();
}
$row   = $db->sql_fetchrow($result);
$catid     = $db->XMFnum($row['catid']);
$aid       = stripslashes($row['aid']);
$time      = stripslashes($row['time']);
$title     = stripslashes($row['title']);
$hometext  = stripslashes($row['hometext']);
$bodytext  = stripslashes($row['bodytext']);
$topic     = $db->XMFnum($row['topic']);
$informant = stripslashes($row['informant']);
$notes     = stripslashes($row['notes']);
$acomm     = $db->XMFnum($row['acomm']);
$haspoll   = $db->XMFnum($row['haspoll']);
$pollID    = $db->XMFnum($row['pollID']);
$score     = $db->XMFnum($row['score']);
$ratings   = $db->XMFnum($row['ratings']);
if ($aid == "") { redirect_url("modules.php?name=$module_name"); }
$sql1 = "UPDATE `".TABLE_STORIES."` SET `counter`=counter+1 WHERE `sid`='$sid' ";
if ( !($result = $db->sql_query($sql1)) )
{ query_die(MODULE_ERROR, 'Could not UPDATE stories WebSite', '', __LINE__, __FILE__, $sql1);}

$artpage = 1;
$pagetitle = "- $title";
$Theme_Sel = get_theme();
    echo "<html>\n";
    echo "<head>\n";
    require("themes/$Theme_Sel/theme.php");
    echo "<style type=\"text/css\">\n";
    echo "<!--\n";
    require("themes/$Theme_Sel/style/style.css");
    echo "-->\n";
    echo "</style>\n";
    echo "<title>$title</title>\n";
    echo "<base target='parent'>\n";
    echo "</head>\n";
    echo "<body>\n";
$artpage = 0;
formatTimestamp($time);
$title    = stripslashes($title);
$hometext = stripslashes($hometext);
$bodytext = stripslashes($bodytext);
$notes    = stripslashes($notes);
if($notes != "") { $notes = "<br /><br /><b><i>"._NOTE." $notes</i></b>"; } else { $notes = ""; }
if($bodytext == "") { $bodytext = "$hometext$notes"; } else { $bodytext = "$hometext<br /><br />$bodytext$notes"; }
if($informant == "") { $informant = $anonymous; }
getTopics($topic);
if($catid != 0) {
    $sql = "SELECT `title` FROM `".TABLE_STORIES_CAT."` WHERE `catid`='$catid'";
    if ( !($result = $db->sql_query($sql1)) )
{ query_die(MODULE_ERROR, 'Could not SELECT stories_cat WebSite', '', __LINE__, __FILE__, $sql1);}

    $row = $db->sql_fetchrow($result);
    $title1 = stripslashes($row['title']);
    $title = "<a href=\"modules.php?name=$module_name&amp;file=categories&amp;op=newindex&amp;catid=$catid\"><font class=\"storycat\">$title1</font></a>: $title";
}

echo "<table width=\"100%\" border=\"0\"><tr><td valign=\"top\" width=\"100%\">\n";
themearticle($aid, $informant, $datetime, $title, $bodytext, $topic, $topicname, $topicimage, $topictext);
echo "</td><td>&nbsp;</td><td valign=\"top\">\n";

echo "</body>\n";
echo "</html>\n";
die();
