<?php
/**
 * $Source: /home/cvs/nukescripts/blocks/blocks-Old_Articles.php,v $
 * $Revision: 1.0.0a $
 * $Author: cyril $
 * $Date: 2007/02/01 11:20:01 $
 * Bug 208 fix Piermin
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2007                                            */
/* http://www.php-maximus.org                                           */
/* 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 old articles MAXIMUS directly...');

if ( $content = opencacheb ( 'OLDArticles', 'html' , "".CACHE_BL_OLDARTICLES."", '1' ) ) {
} else {

global $locale, $oldnum, $cookie, $categories, $cat, $multilingual, $currentlang, $new_topic, $user_news;

$new_topic    = addslashes( $new_topic ) ;
$multilingual = addslashes( $multilingual ) ;
$currentlang  = addslashes( $currentlang ) ;
$cat          = addslashes( $cat ) ;
$user_news    = $GLOBALS['db']->XMFnum( $user_news );
$cookie[3]    = $GLOBALS['db']->XMFnum( $cookie[3] );

if ( isset($cookie[3]) AND $user_news == 1) {
	$storynum = $cookie[3];
} else {
	if (is_file('modules/News/includes/functions.php')) {
		include_once('modules/News/includes/functions.php');
	$neconfig = ne_get_configs();
	$storynum = $GLOBALS['db']->XMFnum( $neconfig['homenumber'] );
	} else {
	$storynum = 0;
	}
}

if ( empty($oldnum) ) { $storynum = 10; }

if ($multilingual == 1) {
    if ($categories == 1) {
    	$querylang = "where `catid`='$cat' AND (`alanguage`='$currentlang' OR `alanguage`='')";
    } else {
    	$querylang = "where (`alanguage`='$currentlang' OR `alanguage`='')";
	if ($new_topic != 0) {
	    $querylang .= " AND `topic`='$new_topic'";
	}
    }
} else {
    if ($categories == 1) {
   	$querylang = "where `catid`='$cat'";
    } else {
	$querylang = "";
	if ($new_topic != 0) {
	    $querylang = "WHERE `topic`='$new_topic'";
	}
    }
}

$boxstuff = "<table border=\"0\" width=\"100%\">";
$boxTitle = _PASTARTICLES;
$sql = "SELECT `sid`, `title`, `time`, `comments` FROM `".TABLE_STORIES."` $querylang ORDER BY `time` DESC LIMIT $storynum, $oldnum";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(BLOCK_ERROR, 'Could not obtain _stories', '', __LINE__, __FILE__, $sql);}
$vari = 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]"; }

while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
    $sid      = $GLOBALS['db']->XMFnum($row['sid']);
    $title    = stripslashes($row['title']);
    $time     = stripslashes($row['time']);
    $comments = stripslashes($row['comments']);
    $see      = 1;
    setlocale(LC_TIME, $locale);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime2);
    $datetime2 = strftime(""._DATESTRING2."", mktime($datetime2[4],$datetime2[5],$datetime2[6],$datetime2[2],$datetime2[3],$datetime2[1]));
    $datetime2 = ucfirst($datetime2);
    if ($articlecomm == 1) {
	$comments = "($comments)";
    } else {
	$comments = "";
    }
    if($time2==$datetime2) {
        $boxstuff .= "<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> $comments</td></tr>\n";
    } else {
        if($a=="") {
    	    $boxstuff .= "<tr><td colspan=\"2\"><b>$datetime2</b></td></tr><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> $comments</td></tr>\n";
	    $time2 = $datetime2;
	    $a = 1;
	} else {
	    $boxstuff .= "<tr><td colspan=\"2\"><b>$datetime2</b></td></tr><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> $comments</td></tr>\n";
	    $time2 = $datetime2;
	}
    }
    $vari++;
    if ($vari==$oldnum) {
	if (isset($cookie[3])) {
	    $storynum = $cookie[3];
	} else {
	    $storynum = $storyhome;
	}
	$min = $oldnum + $storynum;
	$dummy = 1;
    }
}

if ($dummy == 1 AND is_active('Stories_Archive')) {
    $boxstuff .= "</table><br /><a href=\"modules.php?name=Stories_Archive\"><b>"._OLDERARTICLES."</b></a>\n";
} else {
    $boxstuff .= "</table>";
}

if ($see == 1) {
    $content = $boxstuff;
}

closecacheb ( "".$content."", 'OLDArticles', 'html' , "".CACHE_BL_OLDARTICLES."", '1' );
}