<?php
/***************************************************************************
* feedNews.php
*
* begin : October 2006
* version : 25 October 2006
* copyright : (C) 2006 grandolini.net
*
* Feed news to the site through an XMLHTTP response script
*
***************************************************************************/
session_start();
require('private/Host.inc');
require('common/db/MySql.php');
$dbh=db_connect(array($host,$user,$password));
$dbs=db_select_db(array($db_main));
#
if(!isset($_SESSION[last_news]) || $_SESSION[last_news]<=0) { $_SESSION[last_news]=999999; }
$IP=$_SERVER[REMOTE_ADDR];
$sth=db_query("SELECT * FROM online WHERE ip='$IP'");
if($sth[1]>0)
{
$row=db_fetch($sth[0]);
$USER_ID =$row[0][user];
$USER_PRIV =$row[0][privil];
}
$query="SELECT * FROM g_news WHERE news_skin='".$_SESSION[misc][skin]."' AND ";
if($USER_PRIV<80) { $query.='news_publish=1'; } else { $query.='news_publish>=1'; }
$query.=" AND news_date<='".date('Y-m-d')."' AND (news_exp>='".date('Y-m-d')."' OR LEFT(news_exp,4)='0000') "; $reset=$query;
switch($_GET[act])
{
case 'prev':
$_SESSION[last_news]++;
$query.="AND RRN>='$_SESSION[last_news]' ORDER BY news_date ASC LIMIT 1";
$reset.="AND RRN>0 ORDER BY news_date ASC LIMIT 1";
break;
case 'next':
default:
$_SESSION[last_news]--;
$query.="AND RRN<='$_SESSION[last_news]' ORDER BY RRN DESC,news_date DESC LIMIT 1";
$reset.="AND RRN<999999 ORDER BY RRN DESC,news_date DESC LIMIT 1";
}
#
$sth=db_query($query);
if($sth[1]==0)
{
$sth=db_query($reset);
# $debug=$query; # debug
}
if($sth[1]>0)
{
$rows=db_fetch($sth[0]);
$date=date('j M Y',strtotime($rows[0][news_date]));
$news=str_replace(' ',' ',$rows[0][news_msg]);
}
else
{
$rows[0][RRN]=-1;
$rows[0][news_date]='';
$news='No news available in the database!';
$date='';
}
$_SESSION[last_news]=$rows[0][RRN];
# $news=$debug; # debug
#
# if($_SESSION[misc][location]=='l') { for($i=0;$i<6000;$i++) { $tmp=file('skins/phpCAMALEO/import/english.txt'); } } # debug, loop to see the wait animation
#
header("Cache-Control: no-cache, must-revalidate");
header('Expires: Fri, 31 Dec 1999 23:59:59 GMT');
header('Content-type: text/xml');
echo '<sitenews>'
.'<RRN>'.$rows[0][RRN].'</RRN>'
.'<news>'
.htmlspecialchars($date).'|'
.htmlspecialchars($news).'|'
.htmlspecialchars($rows[0][news_link]).'|'
.htmlspecialchars($rows[0][news_target])
.'</news>'
.'</sitenews>';
?>