| 1 | <?php |
|---|
| 2 | // $Id: ratelink.php,v 1.5 2005/09/04 20:46:10 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------- // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | include "header.php"; |
|---|
| 28 | include_once XOOPS_ROOT_PATH."/class/module.errorhandler.php"; |
|---|
| 29 | $myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object |
|---|
| 30 | |
|---|
| 31 | if (!empty($_POST['submit'])) { |
|---|
| 32 | $eh = new ErrorHandler; //ErrorHandler object |
|---|
| 33 | if(empty($xoopsUser)){ |
|---|
| 34 | $ratinguser = 0; |
|---|
| 35 | }else{ |
|---|
| 36 | $ratinguser = $xoopsUser->getVar('uid'); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | //Make sure only 1 anonymous from an IP in a single day. |
|---|
| 40 | $anonwaitdays = 1; |
|---|
| 41 | $ip = getenv("REMOTE_ADDR"); |
|---|
| 42 | $lid = intval($_POST['lid']); |
|---|
| 43 | $cid = intval($_POST['cid']); |
|---|
| 44 | $rating = intval($_POST['rating']); |
|---|
| 45 | |
|---|
| 46 | // Check if Rating is Null |
|---|
| 47 | if ($rating=="--") { |
|---|
| 48 | redirect_header("ratelink.php?cid=".$cid."&lid=".$lid."",4,_MD_NORATING); |
|---|
| 49 | exit(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | // Check if Link POSTER is voting (UNLESS Anonymous users allowed to post) |
|---|
| 53 | if ($ratinguser != 0) { |
|---|
| 54 | $result=$xoopsDB->query("select submitter from ".$xoopsDB->prefix("mylinks_links")." where lid=$lid"); |
|---|
| 55 | while(list($ratinguserDB) = $xoopsDB->fetchRow($result)) { |
|---|
| 56 | if ($ratinguserDB == $ratinguser) { |
|---|
| 57 | redirect_header("index.php",4,_MD_CANTVOTEOWN); |
|---|
| 58 | exit(); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | // Check if REG user is trying to vote twice. |
|---|
| 63 | $result=$xoopsDB->query("select ratinguser from ".$xoopsDB->prefix("mylinks_votedata")." where lid=$lid"); |
|---|
| 64 | while(list($ratinguserDB) = $xoopsDB->fetchRow($result)) { |
|---|
| 65 | if ($ratinguserDB == $ratinguser) { |
|---|
| 66 | redirect_header("index.php",4,_MD_VOTEONCE2); |
|---|
| 67 | exit(); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | } else { |
|---|
| 72 | |
|---|
| 73 | // Check if ANONYMOUS user is trying to vote more than once per day. |
|---|
| 74 | $yesterday = (time()-(86400 * $anonwaitdays)); |
|---|
| 75 | $result=$xoopsDB->query("select count(*) FROM ".$xoopsDB->prefix("mylinks_votedata")." WHERE lid=$lid AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday"); |
|---|
| 76 | list($anonvotecount) = $xoopsDB->fetchRow($result); |
|---|
| 77 | if ($anonvotecount > 0) { |
|---|
| 78 | redirect_header("index.php",4,_MD_VOTEONCE2); |
|---|
| 79 | exit(); |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | if($rating > 10){ |
|---|
| 83 | $rating = 10; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | //All is well. Add to Line Item Rate to DB. |
|---|
| 87 | $newid = $xoopsDB->genId($xoopsDB->prefix("mylinks_votedata")."_ratingid_seq"); |
|---|
| 88 | $datetime = time(); |
|---|
| 89 | $sql = sprintf("INSERT INTO %s (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (%u, %u, %u, %u, '%s', %u)", $xoopsDB->prefix("mylinks_votedata"), $newid, $lid, $ratinguser, $rating, $ip, $datetime); |
|---|
| 90 | $xoopsDB->query($sql) or $eh->show("0013"); |
|---|
| 91 | |
|---|
| 92 | //All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
|---|
| 93 | updaterating($lid); |
|---|
| 94 | $ratemessage = _MD_VOTEAPPRE."<br />".sprintf(_MD_THANKURATE, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
|---|
| 95 | redirect_header("index.php",2,$ratemessage); |
|---|
| 96 | exit(); |
|---|
| 97 | |
|---|
| 98 | } else { |
|---|
| 99 | |
|---|
| 100 | $xoopsOption['template_main'] = 'mylinks_ratelink.html'; |
|---|
| 101 | include XOOPS_ROOT_PATH."/header.php"; |
|---|
| 102 | $lid = intval($_GET['lid']); |
|---|
| 103 | $cid = intval($_GET['cid']); |
|---|
| 104 | $result=$xoopsDB->query("select title from ".$xoopsDB->prefix("mylinks_links")." where lid=$lid"); |
|---|
| 105 | list($title) = $xoopsDB->fetchRow($result); |
|---|
| 106 | $xoopsTpl->assign('link', array('id' => $lid, 'cid' => $cid, 'title' => $myts->htmlSpecialChars($title))); |
|---|
| 107 | $xoopsTpl->assign('lang_voteonce', _MD_VOTEONCE); |
|---|
| 108 | $xoopsTpl->assign('lang_ratingscale', _MD_RATINGSCALE); |
|---|
| 109 | $xoopsTpl->assign('lang_beobjective', _MD_BEOBJECTIVE); |
|---|
| 110 | $xoopsTpl->assign('lang_donotvote', _MD_DONOTVOTE); |
|---|
| 111 | $xoopsTpl->assign('lang_rateit', _MD_RATEIT); |
|---|
| 112 | $xoopsTpl->assign('lang_cancel', _CANCEL); |
|---|
| 113 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 114 | } |
|---|
| 115 | ?> |
|---|