include("ncnsession.inc.php");
include("memconfig.inc.php");
include("ncnlib.inc.php");
include("article.inc.php");
if (!($artid>0)):
ProblemMess("Sorry, the article id is missing for some reason",3);
endif;
if ($referpg==""):
$referpg = getenv("HTTP_REFERER");
if (ereg("artview.php",$referpg)):
$referpg = "";
endif;
endif;
if ($xmode=="rate"):
#-- Process a rating
if (!($vote>0)):
$xmessage .= "You didn't choose a rating
";
else:
#-- Pick up old vote again, to be sure nobody cheats or votes twice
$res = mysql_db_query("$dbname","select * from recvotes where memno='$curmemno' and votetype='article' and itemid=$artid");
if ($res<=0):
echo "\n";
endif;
if (mysql_numrows($res)>0):
#-- They did vote before
$row = mysql_fetch_array($res);
$oldvoteid = $row['voteid'];
$oldvote = $row['vote'];
$oldvotedate = substr($row['oldvotedate'],0,10);
else:
$oldvote = "";
$oldvoteid = 0;
$oldvotedate = "0000-00-00";
endif;
if ($oldvote==""):
#-- This is a new rating
$recfields = "(voteid,memno,votetype,votedate,vote,itemid)";
$recvalues = "(0,'$curmemno','article',now(),$vote,$artid)";
$res = mysql_db_query("$dbname","insert into recvotes $recfields values $recvalues");
if ($res<=0):
echo "\n";
$xmessage .= "There was a database error in saving your rating
";
else:
$res = mysql_db_query("$dbname","update articles set votes=votes+1,totrate=totrate+$vote where artid=$artid");
if ($res<=0):
echo "\n";
$xmessage .= "There was a database error in updating the article with your rating
";
else:
$xmessage .= "Your rating of $vote was recorded
";
endif;
endif;
else:
#-- We're updating an existing rating
$res = mysql_db_query("$dbname","update recvotes set vote=$vote,votedate=now() where memno='$curmemno' and voteid=$oldvoteid");
if ($res<=0):
echo "\n";
$xmessage .= "There was a database error in updating your rating
";
else:
$ratechange = $vote-$oldvote;
$res = mysql_db_query("$dbname","update articles set totrate=totrate+$ratechange where artid=$artid");
if ($res<=0):
echo "\n";
$xmessage .= "There was a database error in updating the article with your rating
";
else:
$xmessage .= "Your changed rating was recorded
";
endif;
endif;
endif;
endif;
elseif ($xmode=="comment"):
#-- Adding a comment
$newcomment = str_replace("\r","",$newcomment);
$newcomment = str_replace("\n","
",$newcomment);
$newcomment = urlencode(stripslashes($newcomment));
$recfields = "(comid,rectype,itemid,memno,comdate,comment)";
$recvalues = "(0,'article',$artid,'$curmemno',now(),'$newcomment')";
$res = mysql_db_query("$dbname","insert into reccomments $recfields values $recvalues");
if ($res<=0):
echo "\n";
$xmessage .= "There was a database error when saving your comment
";
endif;
endif;
$res = mysql_db_query("$dbname","select * from articles where artid=$artid");
if ($res<=0):
echo "\n";
endif;
if (mysql_numrows($res)<=0):
ProblemMess("Article not found",3);
endif;
$row = mysql_fetch_array($res);
$i = 0;
while ($i Article","View Article","artview.php?artid=$artid");
?>
Article