/*********************************************
CPG-Dragonfly™ CMS
********************************************
Copyright © 2004 - 2007 by CPG Dev Team
http://dragonflycms.org
Dragonfly is released under the terms and conditions
of the GNU GPL version 2 or any later version
$Source: /cvs/modules/Web_Links/modules/Web_Links/rate.inc,v $
$Revision: 9.6 $
$Author: phoenix $
$Date: 2007/10/02 06:40:25 $
**********************************************/
if (!defined('CPG_NUKE')) { exit; }
function ratelink($lid, $ttitle) {
global $linksprefix, $db, $userinfo, $bgcolor2, $bgcolor3;
require_once('header.php');
menu(1);
echo '
';
OpenTable();
$displaytitle = ereg_replace ('_', ' ', $ttitle);
echo ''.$displaytitle.''
.'
'
.'- '._RATENOTE1.'
'
.'- '._RATENOTE2.'
'
.'- '._RATENOTE3.'
'
.'- '._RATENOTE4.'
'
.'- '._RATENOTE5.'
';
if (is_user()) {
echo '- '._YOUAREREGGED.'
- '._FEELFREE2ADD.'
';
} else {
echo '- '._YOUARENOTREGGED.'
- '._IFYOUWEREREG.'
';
}
echo '
';
echo '';
linkfooterchild($lid);
echo '
';
CloseTable();
}
function addrating() {
global $module_name, $linksprefix, $db, $userinfo, $anonymous, $weblinks_config;
$ratinglid = intval($_POST['ratinglid']);
$ratinguser = isset($_POST['ratinguser']) ? $_POST['ratinguser'] : '';
$rating = intval($_POST['rating']);
$ratingcomments = $_POST['ratingcomments'];
$anonwaitdays = $weblinks_config['anonwaitdays'];
$outsidewaitdays = $weblinks_config['outsidewaitdays'];
list($ttitle) = $db->sql_ufetchrow("SELECT title FROM ".$linksprefix."_links WHERE lid=$ratinglid");
$passtest = 'yes';
require_once('header.php');
completevoteheader();
if(is_user()) {
$ratinguser = $userinfo['username'];
} elseif ($ratinguser == 'outside') {
$ratinguser = 'outside';
} else {
$ratinguser = $anonymous;
}
/* Make sure only 1 anonymous from an IP in a single day. */
$ip = $userinfo['user_ip'];
/* Check if Rating is Null */
if ($rating == '--') {
$error = 'nullerror';
completevote($error);
$passtest = 'no';
}
/* Check if Link POSTER is voting (UNLESS Anonymous users allowed to post) */
if ($ratinguser != $anonymous && $ratinguser != 'outside') {
$result = $db->sql_query("SELECT submitter FROM ".$linksprefix."_links WHERE lid=$ratinglid");
while(list($ratinguserDB)= $db->sql_fetchrow($result)) {
if ($ratinguserDB==$ratinguser) {
$error = 'postervote';
completevote($error);
$passtest = 'no';
}
}
}
/* Check if REG user is trying to vote twice. */
if ($ratinguser != $anonymous && $ratinguser != 'outside') {
$result = $db->sql_query("SELECT ratinguser FROM ".$linksprefix."_votedata WHERE ratinglid=$ratinglid");
while(list($ratinguserDB)= $db->sql_fetchrow($result)) {
if ($ratinguserDB==$ratinguser) {
$error = 'regflood';
completevote($error);
$passtest = 'no';
}
}
}
/* Check if ANONYMOUS user is trying to vote more than once per day. */
if ($ratinguser==$anonymous){
$yesterdaytimestamp = (time()-(86400 * $anonwaitdays));
$ytsDB = Date('Y-m-d H:i:s', $yesterdaytimestamp);
$result = $db->sql_query("SELECT * FROM ".$linksprefix."_votedata WHERE ratinglid=$ratinglid AND ratinguser='"._ANONYMOUS."' AND ratinghostname = '$ip' AND TO_DAYS(NOW()) - TO_DAYS(ratingtimestamp) < $anonwaitdays");
$anonvotecount = $db->sql_numrows($result);
if ($anonvotecount >= 1) {
$error = 'anonflood';
completevote($error);
$passtest = 'no';
}
}
/* Check if OUTSIDE user is trying to vote more than once per day. */
if ($ratinguser=='outside'){
$yesterdaytimestamp = (time()-(86400 * $outsidewaitdays));
$ytsDB = Date('Y-m-d H:i:s', $yesterdaytimestamp);
$result = $db->sql_query("SELECT * FROM ".$linksprefix."_votedata WHERE ratinglid=$ratinglid AND ratinguser='outside' AND ratinghostname = '$ip' AND TO_DAYS(NOW()) - TO_DAYS(ratingtimestamp) < $outsidewaitdays");
$outsidevotecount = $db->sql_numrows($result);
if ($outsidevotecount >= 1) {
$error = 'outsideflood';
completevote($error);
$passtest = 'no';
}
}
/* Passed Tests */
if ($passtest == 'yes') {
$ratingcomments = Fix_Quotes($ratingcomments);
$ratinguser = Fix_Quotes($ratinguser);
/* All is well. Add to Line Item Rate to DB. */
$db->sql_query("INSERT INTO ".$linksprefix."_votedata (ratingdbid, ratinglid, ratinguser, rating, ratinghostname, ratingcomments, ratingtimestamp)values (NULL,'$ratinglid', '$ratinguser', '$rating', '$ip', '$ratingcomments', now())");
/* All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. */
/* NOTE: If weight is modified, ALL links need to be refreshed with new weight. */
/* Running a SQL statement with your modded calc for ALL links will accomplish this. */
$voteresult = $db->sql_query("select rating, ratinguser, ratingcomments FROM ".$linksprefix."_votedata WHERE ratinglid = $ratinglid");
$totalvotesDB = $db->sql_numrows($voteresult);
require("modules/$module_name/voteinclude.php");
$db->sql_query("UPDATE ".$linksprefix."_links SET linkratingsummary=$finalrating, totalvotes=$totalvotesDB, totalcomments=$truecomments WHERE lid = $ratinglid");
$error = 'none';
completevote($error);
}
completevotefooter($ratinglid, $ttitle, $ratinguser);
}
function outsidelinksetup($lid) {
global $module_name, $sitename, $nukeurl, $BASEHREF, $mainindex;
require_once('header.php');
menu(1);
echo '
';
OpenTable();
$promo1 = ''._RATETHISSITE.' @ '.$sitename.'';
$promo2 = '';
$promo3 = '';
echo ''._PROMOTEYOURSITE.'
'._PROMOTE01.'
1) '._TEXTLINK.'
'._PROMOTE02.'
'.$promo1.'
'._HTMLCODE1.'
'._THENUMBER.' "'.$lid.'" '._IDREFER.'
2) '._BUTTONLINK.'
'._PROMOTE03.'
'.$promo2.'
'._HTMLCODE2.'
3) '._REMOTEFORM.'
'._PROMOTE04.'
'.$promo3.'
'._HTMLCODE3.'
'._PROMOTE05.'
'.$sitename.' '._STAFF.'
';
CloseTable();
}