<?php
/* $Id: overview.inc.php,v 1.9 2003/11/21 21:25:36 leyeti Exp $ */

// adding file revision into global array
if(function_exists("revisionInit")) revisionInit("\$Revision: 1.9 $", __FILE__);

// =============================================================
// Get NEWS for overview
// =============================================================

//include for check_and_autoarchive() : Auto archive if out of date
include(ROOTPATH."/modules/news/inc/news_func.inc.php");

function getnews() {
    global $smarty, $conn, $myEnv;

	check_and_autoarchive();
	
  	
    $sql = "SELECT t1.*, t2.channelname, t3.username FROM mgw_news_channels t2, mgw_news t1 LEFT JOIN mgw_users t3 ON t1.owner = t3.id WHERE t1.isactive= '1' AND t1.channelid = t2.id ORDER BY t1.lu_date DESC";

    if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
    $i=0;
    while (($row = $res->FetchRow()) && $i++ < (isset($_SESSION["MGW"]->settings["overview_news"]) ? $_SESSION["MGW"]->settings["overview_news"] : 5)){
	$sql_read = "SELECT userid FROM mgw_news_consult WHERE userid='".$_SESSION["MGW"]->userid."' AND newsid='".$row["id"]."'";
	if(!$res_read = $conn->Execute($sql_read)) exit(showSQLerror($sql_read, $conn->ErrorMsg(), __LINE__, __FILE__));
	$row_read = $res_read->FetchRow();
	$news_list = array("datum" => date($_SESSION["MGW"]->settings["datefmt"],$res->UnixTimeStamp($row["lu_date"])),
			   "subject" => $row["headline"],
			   "autor" => $row["username"],
			   "channel" => $row["channelname"],
			   "newsid"=> $row["id"],
			   "not_read"=> (isset($_SESSION["MGW"]->userid) && $row_read["userid"]!=$_SESSION["MGW"]->userid) ? "1" : "");
	$smarty->append("nl" , $news_list);
    }
	$smarty->assign("backurl",urlencode(ROOTURL."modules/overview/index.php?".SID));
    return $smarty->fetch("file:".ROOTPATH."/modules/news/templates/default/".$myEnv["output"]."/news_overview.tpl");
}
?>
