<?

/************************************************************************/
/* FlatNuke - Flat Text Based Content Management System                 */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2003-2004 by Simone Vellei                             */
/* http://flatnuke.sourceforge.net                                      */
/*                                                                      */
/* 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.       */
/************************************************************************/


if (eregi("section.php",$_SERVER['PHP_SELF']))
	{ Header("Location: ../../index.php");
	die();
	}

global $mesi,$fuso_orario;

$okmese=array(0,0,0,0,0,0,0,0,0,0,0,0);
$okanno=array();

// Security conversions
$year = getparam("year",PAR_GET,SAN_FLAT);
$month = getparam("month",PAR_GET,SAN_HTML);
$modname = getparam("mod", PAR_GET, SAN_FLAT);
if($year=="" AND $month==""){
	$my_modlist = "";
	$handle=opendir(get_fn_dir('news'));
	while ($file = readdir($handle)) {
		if (!( $file=="." or $file==".." )) {
		$my_modlist .= "$file ";
		}
	}
	closedir($handle);
	$my_modlist = explode(" ", $my_modlist);
	# vedo quali anni ci sono nelle news.
	for ($i=0; $i < sizeof($my_modlist)-1; $i++){
		$tmp=str_replace(".xml","",$my_modlist[$i]);
		$anno=date("Y",$tmp+(3600*$fuso_orario));
		$tmp=implode(":",$okanno);
		if(!stristr($tmp,$anno)){
			$okanno[count($okanno)]=$anno;
		}
	}
	echo "<ul>";
	if(count($okanno)>0) sort($okanno);
	for ($i=0; $i < count($okanno); $i++){
		if($okanno[$i]!="")
			echo "<li><a href=\"index.php?mod=".$modname."&amp;year=".($okanno[$i])."\">$okanno[$i]</a></li>";
	}
	echo "</ul>";

	$mymy_modlist = "";

	$myhandle = opendir('images/news');
	while ($myfile = readdir($myhandle)) {
		if (!($myfile == "." or $myfile == "..")) {
			$mymy_modlist.= "$myfile ";
		}
	}

	closedir($myhandle);
	$mymy_modlist = explode(" ", $mymy_modlist);
	sort($mymy_modlist);
	echo "<b>"._PERARGOMENTI.":</b><br />";
	for ($i=1; $i < sizeof($mymy_modlist); $i++) {
	$label=str_replace("_"," ", ereg_replace("\..*","",$mymy_modlist[$i]));
		echo "<div style=\"float:left; padding: 10px 10px 10px 10px; text-align:center\">";
		echo "<a href=\"index.php?mod=none_Search&amp;find=".$mymy_modlist[$i]."&amp;where=news\">";
		$w3c_title = _ARGOMENTO.": ".eregi_replace("\.png$|\.gif$|\.jpeg$|\.jpg$","",$mymy_modlist[$i]);
		echo "<img src=\"images/news/".$mymy_modlist[$i]."\" border=\"0\" alt=\"".$label."\" title=\"$w3c_title\" />";
		echo "<br />".$label."</a></div>";
		if($i%5==0) echo "<div style=\"clear:both\"></div>";
	}
	echo "<div style=\"clear:both\"></div>";
} else if($year!="" AND $month==""){
	$my_modlist = "";
	$handle=opendir(get_fn_dir('news'));
	while ($file = readdir($handle)) {
		if (!( $file=="." or $file==".." )) {
			$my_modlist .= "$file ";
		}
	}
	closedir($handle);
	$my_modlist = explode(" ", $my_modlist);
	# vedo quali mesi ci sono nelle news di quest'anno.
	for ($i=0; $i < sizeof($my_modlist)-1; $i++){
		$tmp=str_replace(".xml","",$my_modlist[$i]);
		$mese=date("m",$tmp+(3600*$fuso_orario));
		if ($mese<10)
			$mese=str_replace("0","",$mese);
		if(date("Y",$tmp+(3600*$fuso_orario))==$year){
			$ok[$mese-1]=1;
		}
	}

	echo "<ul>";
	for ($i=0; $i < 12; $i++){
		if($ok[$i]==1)
			echo "<li><a href=\"index.php?mod=".$modname."&amp;year=".$year."&amp;month=".($i+1)."\">$mesi[$i]</a></li>";
	}

	echo "</ul>";
	echo "<a href=\"javascript:history.back();\">&lt;&lt; "._INDIETRO."</a>";
} else {
	$my_modlist = "";
	$handle=opendir(get_fn_dir('news'));
	while ($file = readdir($handle)) {
		if (!( $file=="." or $file==".." )) {
			$my_modlist .= "$file ";
		}
	}
	closedir($handle);
	$my_modlist = explode(" ", $my_modlist);
	rsort($my_modlist);
	for ($i=0; $i < sizeof($my_modlist)-1; $i++){
		$tmp=str_replace(".xml","",$my_modlist[$i]);
		$mese=date("m",$tmp+(3600*$fuso_orario));
		$anno=date("Y",$tmp+(3600*$fuso_orario));
		if ($mese<10)
			$mese=str_replace("0","",$mese);
		if($mese==$month AND $anno==$year){
			$string=get_file('news/'.$my_modlist[$i]);
			$title=get_xml_element("fn:title",$string);
			$reads=get_xml_element("fn:reads",$string);
			$id=str_replace(".xml","",$my_modlist[$i]);
			echo "<img src=\"themes/$theme/images/read.png\" />&nbsp;<a href=\"index.php?mod=read&amp;id=$id\" alt=\"Read\">$title</a> (".
			date("d/m/Y - H:i",$id+(3600*$fuso_orario)).") "._LETTO." $reads "._VOLTE."<br />";
		}
	}
	echo "<br /><a href=\"javascript:history.back();\">&lt;&lt; "._INDIETRO."</a>";
}

?>
