<?php

@require_once './mainfile.php';
if ( ! defined( '_MAINFILE_' ) ) { exit( '!! ACCESS DENIED !!' ); }

/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: archive.php,v 1.9.2.4 2004/06/12 16:54:44 ajvwaay Exp $




######################################################################
# myPHP-NUKE: Web Portal System: Archive add-on
# ==--=========================================
#
# This module is to view your news items archived by month, year
# in cronological order.
#
# 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.
#
# Original version:
# [11-may-2001] Kenneth Lee - http://www.nexgear.com/
#
# INSTALLATION:
#
# Simply place this file in your root myPHPNuke install.
# Point a link to http://www.youresite.com/archive.php
# It will automatically scan all your news to generate archive links
#
######################################################################
# Version modifie
# [14-mai-2001] Pascal Le Boustouller - webmaster@i-annonces.net
######################################################################

//include("extention.inc");
//include("dbconf.$phpEx");
//if (!isset($mainfile)) { include("mainfile.php"); }
include("header.php");
OpenTable();
echo "<div id='archive'>\n";

# articles per page
$nb_affichage = 20;



$count = 0;
$altbg = 0;
$fromyear = "0000";
$frommonth = "00";
$lastyear = "0000";
$lastmonth = "00";

if (!isset( $op ))
{
    $op = null;
}

switch($op) {
    case "get":
        $fromyear = $year;
        $frommonth = $month;
    break;
}


$indexresult=mysql_query("SELECT time FROM " . $mpnTables['stories'] . " ORDER by time DESC");
if(!$indexresult) {
    echo mysql_errno(). ": ".mysql_error(). "<br>"; exit();
} else {

    if (!isset($debut)) { $debut=0; }


    if ($fromyear != "0000") {
        print ("<P><B>" . translate("Articles for") . " ");
        switch($frommonth) {
            case "01": echo translate("January"); break;
            case "02": echo translate("February"); break;
            case "03": echo translate("March"); break;
            case "04": echo translate("April"); break;
            case "05": echo translate("May"); break;
            case "06": echo translate("June"); break;
            case "07": echo translate("July"); break;
            case "08": echo translate("August"); break;
            case "09": echo translate("September"); break;
            case "10": echo translate("October"); break;
            case "11": echo translate("November"); break;
            case "12": echo translate("December"); break;
        }
        print (" $fromyear</B><P>");
    
        print ("<table width=\"100%\" border=0 cellpadding=2 cellspacing=2 bgcolor=$bgcolor3>
              <tr bgcolor=$bgcolor2><TD width=\"110\">" . translate("Topics") . "</TD><td>" . translate("Articles") . "</td><td align=center width=\"50\">" . translate("Actions") . "</td><td align=center width=\"30\">" . translate("Views") . "</td><td align=center width=\"80\">" . translate("Posted") . "</td></tr>");
    
    
        $current_month = (int)$HTTP_GET_VARS['month'];
        $current_year  = (int)$HTTP_GET_VARS['year'];
    
        $results = mysql_query("SELECT COUNT(*) FROM " . $mpnTables['stories'] . " WHERE time > '$current_year-$current_month-01 00:00:00' and time < '$current_year-$current_month-31 23:59:59'");
        $nbe=mysql_result($results, 0);
    //        mysql_close;
    
        $top=1;
        $result = mysql_query("SELECT sid, catid, aid, title, time, counter, topic, informant FROM " . $mpnTables['stories'] . " WHERE time > '$current_year-$current_month-01 00:00:00' and time < '$current_year-$current_month-31 23:59:59' ORDER by time DESC LIMIT $debut,$nb_affichage");
        if(!$result) {
            echo mysql_errno(). ": ".mysql_error(). "<br>"; exit();
        }
    
    
        while (list($s_sid, $catid, $aid, $title, $timee, $counter, $topic, $informant) = mysql_fetch_row($result)) {
        
            $printP = "<a href=\"print.php?sid=$s_sid\"><img src=\"images/print.gif\" border=0 Alt=\"" . translate("Printer Friendly Page") . "\" width=15 height=11></a>";
            $sendF = "<a href=\"friend.php?op=FriendSend&sid=$s_sid\"><img src=\"images/friend.gif\" border=0 Alt=\"" . translate("Send this Story to a Friend") . "\" width=15 height=11></a>";
            $sid = $s_sid;
            if ($topic != 0) {
                $resultm = mysql_query("select topicname from " . $mpnTables['topics'] . " where topicid='$topic'");
                list($title1) = mysql_fetch_row($resultm);
                $title = "<a href=\"search.php?query=&topic=$topic\">$title1</a></TD><TD><a href=\"article.php?sid=$sid\">$title</a>";
            } else {
                $title = "&nbsp;</TD><TD><a href=\"article.php?sid=$sid\">$title</a>";
            }
            if ($altbg==0) {
                print ("<tr bgcolor=$bgcolor1>");
                $altbg=1;
            } else {
                print ("<tr>");
                $altbg=0;
            }
            print ("<td>$title</td><td align=center>$printP&nbsp;$sendF</td><td align=center>$counter</td><td align=center>");
            echo strftime(translate("datestring4"),strtotime($timee)). "</td></tr>\n";
            $count ++;
        }
        print ("</table><P>" . sprintf(translate("There are %s article(s) in total"), $nbe));
    }//$fromyear != 0000
} 

//mysql_close;

if ($top==1)
{
    echo "<P>";

    if ($debut != 0)
    {

        echo "&lt;&lt; <a href=\"archive.php?op=get&year=$current_year&month=$current_month&debut=";
        $resultat = ($debut-$nb_affichage);
        if ($resultat < 0)
        {
            $resultat = 0;
        }
        echo "$resultat\">" . translate("Previous") . "</a> &lt;&lt; ";
    }

    if (($debut+$nb_affichage) < $nbe)
    {
        echo "&gt;&gt; <a href=\"archive.php?op=get&year=$current_year&month=$current_month&debut=";
        $final =($debut+$nb_affichage);
        if ($final >= $nbe)
        {
            $final=($nbe - $nb_affichage);
        }
        echo "$final\">" . translate("Next") . "</a> &gt;&gt;";

    }
}

//start of index
print ("<b>" . translate("Month index") ."</b>\n<P>");
while (list($time) = mysql_fetch_row($indexresult)) {
    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, $datetime);
    if (($lastyear!=$datetime[1]) OR ($lastmonth!=$datetime[2]))
    {
        $lastmonth = $datetime[2];
        $lastyear = $datetime[1];
        print ("<DD><li><a href=\"archive.php?op=get&year=$lastyear&month=$lastmonth\">");
        switch($lastmonth) {
            case "01": echo translate("January"); break;
            case "02": echo translate("February"); break;
            case "03": echo translate("March"); break;
            case "04": echo translate("April"); break;
            case "05": echo translate("May"); break;
            case "06": echo translate("June"); break;
            case "07": echo translate("July"); break;
            case "08": echo translate("August"); break;
            case "09": echo translate("September"); break;
            case "10": echo translate("October"); break;
            case "11": echo translate("November"); break;
            case "12": echo translate("December"); break;
        }
        $results = mysql_query("SELECT COUNT(*) FROM " . $mpnTables['stories'] . " WHERE time > '$lastyear-$lastmonth-01 00:00:00' and time < '$lastyear-$lastmonth-31 23:59:59'");
        $nbb=mysql_result($results, 0);

        print (" $lastyear</a> ($nbb " . translate("Articles") . ")<br>");


    }
}
//end of index


echo "</div>";
        CloseTable();
include("footer.php");
?>
