<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.5 www.bcoos.net 2006-08 GPL
//v1.4 www.exoops.info 2006/03 GPL
// $Id: archive.php,v 1.3 2003/03/19 07:01:09 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once("header.php");
$bcoosConfig['title'] .= " - "._NW_NEWSARCHIVES;
include_once(XOOPS_ROOT_PATH."/header.php");
include_once("class/class.newsstory.php");
$count     = 0;
$altbg     = 0;
$fromyear  = "0000";
$frommonth = "00";
$lastyear  = "0000";
$lastmonth = "00";
switch($_GET['op']) {
case "get":
	$fromyear  = intval($year);
	$frommonth = intval($month);
	break;
}
$useroffset = "0";
if ($xoopsUser) {
	$timezone = $xoopsUser->timezone();
	if (isset($timezone)) {
		$useroffset = $xoopsUser->timezone();
		} else {
			$useroffset = $bcoosConfig['default_TZ'];
		}
}
OpenTable();
echo '<table border="0" width="100%"><tr><td>';
$result=$db->query("SELECT published FROM ".$db->prefix("stories")." WHERE published>0 AND published<=".time()." ORDER BY published DESC");
if (!$result) {
	echo $db->errno(). ": ".$db->error(). "<br />";
	CloseTable();
	include_once(XOOPS_ROOT_PATH."/footer.php");
	exit();
	} else {
	echo "<b>"._NW_NEWSARCHIVES."</b><br /><br />";
	while (list($time) = $db->fetchRow($result)) {
		$datetime[1]  = date("Y", $time);
		$datetime[2]  = date("m", $time);
		if (($lastyear != $datetime[1]) || ($lastmonth != $datetime[2])) {
			$lastyear  = $datetime[1];
			$lastmonth = $datetime[2];
			echo "<img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."size.gif' border='0' alt='' align='middle' />&nbsp;<a href='archive.php?op=get&amp;year=".$lastyear."&amp;month=".$lastmonth."'>";
			switch($lastmonth) {
				case "01":
					print _NW_JANUARY;
					break;
				case "02":
					print _NW_FEBRUARY;
					break;
				case "03":
					print _NW_MARCH;
					break;
				case "04":
					print _NW_APRIL;
					break;
				case "05":
					print _NW_MAY;
					break;
				case "06":
					print _NW_JUNE;
					break;
				case "07":
					print _NW_JULY;
					break;
				case "08":
					print _NW_AUGUST;
					break;
				case "09":
					print _NW_SEPTEMBER;
					break;
				case "10":
					print _NW_OCTOBER;
					break;
				case "11":
					print _NW_NOVEMBER;
					break;
				case "12":
					print _NW_DECEMBER;
					break;
			}
			echo ", $lastyear</a><br />";
		}
	}
}
print ("</td></tr></table>");
if ($fromyear != "0000") {
	print ("<br />");
	print ("<table border='0' width='100%'><tr><td>");
	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0' class='bg3'>";
	echo "<tr align='center' class='bg2'><td align='left'>&nbsp;<b>"._NW_ARTICLES." ( ";
	switch($frommonth) {
		case "01":
			print _NW_JANUARY;
			break;
		case "02":
			print _NW_FEBRUARY;
			break;
		case "03":
			print _NW_MARCH;
			break;
		case "04":
			print _NW_APRIL;
			break;
		case "05":
			print _NW_MAY;
			break;
		case "06":
			print _NW_JUNE;
			break;
		case "07":
			print _NW_JULY;
			break;
		case "08":
			print _NW_AUGUST;
			break;
		case "09":
			print _NW_SEPTEMBER;
			break;
		case "10":
			print _NW_OCTOBER;
			break;
		case "11":
			print _NW_NOVEMBER;
			break;
		case "12":
			print _NW_DECEMBER;
			break;
	}
	echo "
		 $fromyear )</b></td>
		<td align='center'><b>"._NW_ACTIONS."</b></td>
		<td><b>"._NW_VIEWS."</b></td>
		<td><b>"._NW_COMMENTS."</b></td>
		<td><b>"._DATE."</b></td>
		</tr>";
	// must adjust the selected time to server timestamp
	$timeoffset = $useroffset - $bcoosConfig['server_TZ'];
	$monthstart = mktime(0-$timeoffset,0,0,$frommonth,1,$fromyear);
	$monthend   = mktime(23-$timeoffset,59,59,$frommonth+1,0,$fromyear);
	$monthend   = ($monthend > time()) ? time() : $monthend;
	$sql = "SELECT * FROM ".$db->prefix("stories")." WHERE published > $monthstart and published < $monthend ORDER by published DESC";
	//echo $sql;
	$result = $db->query($sql);
	while ($myrow = $db->fetchArray($result)) {
		$article    = new NewsStory($myrow);
		$printP     = "<a href='print.php?storyid=".$article->storyid()."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."print.gif' border='0' alt='"._NW_PRINTERFRIENDLY."' width='15' height='11' /></a>&nbsp;";
		$sendF      = "<a target='_top' href='mailto:?subject=".rawurlencode(sprintf(_NW_INTARTICLE, $bcoosConfig['title']))."&body=".rawurlencode(sprintf(_NW_INTARTFOUND, $bcoosConfig['title']).":\r\n".XOOPS_URL."/modules/".$xoopsModule->dirname()."/article.php?storyid=".$article->storyid())."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."email.gif' border='0' alt='"._NW_SENDSTORY."' width='15' height='11' /></a>";
		$storytitle = $article->title();
		$storytopic = $article->topic_title();
		$storytitle = "<a href='index.php?storytopic=".$article->topicid()."'>".$storytopic."</a>: <a href='article.php?storyid=".$article->storyid()."'>".$storytitle."</a>";
		if ($altbg==0) {
			echo "<tr align='right' class='bg1'>";
			$altbg = 1;
			} else {
				echo "<tr align='right'>";
				$altbg=0;
			}
		$sql = $db->query("SELECT COUNT(*) FROM ".$db->prefix("comments")." WHERE item_id='".$article->storyid()."'");
		$comments = $db->fetchRow($sql);
		echo "
			<td align='left'>&nbsp;<a href='article.php?storyid=".$article->storyid()."'>".$storytitle."</td>
			<td align='center'>$printP $sendF</td>
			<td align='center'>".$article->counter()."</td>
			<td align='center'>".intval($comments[0])."</td>
			<td align='left'>".formatTimestamp($article->published(), "s", $useroffset)."</td>
			</tr>";
		$count ++;
	}
echo "</table></td></tr></table>";
printf(_NW_THEREAREINTOTAL, $count);
}
CloseTable();
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
