| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,81 @@ |
| 1 |
+<?php |
|
| 2 |
+// ---------------------------------------------------------------------- |
|
| 3 |
+// Copyright (c) 2007 by Tammy Keefer |
|
| 4 |
+// http://efiction.hugosnebula.com |
|
| 5 |
+// ---------------------------------------------------------------------- |
|
| 6 |
+// LICENSE |
|
| 7 |
+// |
|
| 8 |
+// This program is free software; you can redistribute it and/or |
|
| 9 |
+// modify it under the terms of the GNU General Public License (GPL) |
|
| 10 |
+// as published by the Free Software Foundation; either version 2 |
|
| 11 |
+// of the License, or (at your option) any later version. |
|
| 12 |
+// |
|
| 13 |
+// This program is distributed in the hope that it will be useful, |
|
| 14 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 16 |
+// GNU General Public License for more details. |
|
| 17 |
+// |
|
| 18 |
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|
| 19 |
+// ---------------------------------------------------------------------- |
|
| 20 |
+if(!defined("_CHARSET")) exit( );
|
|
| 21 |
+ |
|
| 22 |
+global $language; |
|
| 23 |
+ |
|
| 24 |
+if(file_exists(_BASEDIR."blocks/poll/{$language}.php")) include_once(_BASEDIR."blocks/poll/{$language}.php");
|
|
| 25 |
+else include_once(_BASEDIR."blocks/poll/en.php"); |
|
| 26 |
+$content = ""; |
|
| 27 |
+$pollopts = array(); |
|
| 28 |
+$pollquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_poll WHERE poll_end IS NULL OR poll_end = 0 ORDER BY poll_id DESC LIMIT 1");
|
|
| 29 |
+if($pollquery) $currentpoll = dbassoc($pollquery); |
|
| 30 |
+ |
|
| 31 |
+if(isset($_POST['cast_vote'])) {
|
|
| 32 |
+ $poll = isset($_POST['poll_id']) && isNumber($_POST['poll_id']) ? $_POST['poll_id'] : false; |
|
| 33 |
+ $opt = isset($_POST['opt']) && isNumber($_POST['opt']) ? $_POST['opt'] : false; |
|
| 34 |
+ if(!$poll || !$opt) accessDenied( ); // could only be a hack attempt. |
|
| 35 |
+ $voted = dbquery("SELECT vote_id FROM ".TABLEPREFIX."fanfiction_poll_votes WHERE vote_poll = '".$currentpoll['poll_id']."' AND vote_user = '".USERUID."'");
|
|
| 36 |
+ list($voter) = dbrow($voted); |
|
| 37 |
+ if(!$voter) $cast = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_poll_votes(`vote_user`, `vote_opt`, `vote_poll`) VALUES('".USERUID."', '$opt', '$poll')");
|
|
| 38 |
+ if(!empty($cast)) $content .= write_message(_VOTECAST); |
|
| 39 |
+ else $content .= write_message(_ALREADYVOTED); |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+if(!$currentpoll) $content = "<div style='text-align: center;'>"._NOPOLL."</div>"; |
|
| 43 |
+else {
|
|
| 44 |
+ $pollopts = explode("|#|", $currentpoll['poll_opts']);
|
|
| 45 |
+ $content .= "<div id='poll_question'>".$currentpoll['poll_question']."</div><br />"; |
|
| 46 |
+ if(isMEMBER) {
|
|
| 47 |
+ $voted = dbquery("SELECT vote_id FROM ".TABLEPREFIX."fanfiction_poll_votes WHERE vote_poll = '".$currentpoll['poll_id']."' AND vote_user = '".USERUID."'");
|
|
| 48 |
+ list($voter) = dbrow($voted); |
|
| 49 |
+ } |
|
| 50 |
+ if(empty($voter) && isMEMBER) {
|
|
| 51 |
+ $content .= "<form name='poll' id='poll' method='POST' action='".$_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] ? "?".$_SERVER['QUERY_STRING'] : "")."'> |
|
| 52 |
+ <input type='hidden' name='poll_id' value='".$currentpoll['poll_id']."'>"; |
|
| 53 |
+ $x = 1; |
|
| 54 |
+ foreach($pollopts as $opt) {
|
|
| 55 |
+ $content .= "<input type='radio' name='opt' value='$x'> $opt<br />"; |
|
| 56 |
+ $x++; |
|
| 57 |
+ } |
|
| 58 |
+ $content .= "<div style='text-align: center;'><input type='submit' id='cast_vote' name='cast_vote' value='"._VOTE."' class='button' style='font-size: 11px;'></div></form>"; |
|
| 59 |
+ $content .= write_message("<br /><a href='"._BASEDIR."blocks/poll/pollarchive.php?poll=".$currentpoll['poll_id']."'>"._POLLRESULTS."</a><br /><br />");
|
|
| 60 |
+ |
|
| 61 |
+ } |
|
| 62 |
+ else {
|
|
| 63 |
+ $votes = dbquery("SELECT COUNT(vote_opt) as count, vote_opt FROM ".TABLEPREFIX."fanfiction_poll_votes WHERE vote_poll = '".$currentpoll['poll_id']."' GROUP BY vote_opt ORDER BY vote_opt");
|
|
| 64 |
+ |
|
| 65 |
+ if(isset($blocks['poll']['bar']) && file_exists($blocks['poll']['bar'])) $bar = $blocks['poll']['bar']; |
|
| 66 |
+ else $bar = "blocks/poll/bar.jpg"; |
|
| 67 |
+ $totalvotes = 0; |
|
| 68 |
+ while($optvotes = dbassoc($votes)) {
|
|
| 69 |
+ $results[$optvotes['vote_opt']] = $optvotes['count']; |
|
| 70 |
+ $totalvotes = $optvotes['count'] ? $optvotes['count'] + $totalvotes : $totalvotes; |
|
| 71 |
+ } |
|
| 72 |
+ foreach($pollopts as $num => $opt) {
|
|
| 73 |
+ unset($percent); |
|
| 74 |
+ if(!empty($results[($num + 1)])) $percent = floor(($results[($num + 1)] / $totalvotes) * 100); |
|
| 75 |
+ else $percent = 0; |
|
| 76 |
+ $content .= "<div>$opt <br /> <img src='$bar' alt='".strip_tags($opt)."' height='12' width='".$percent."' class='poll'> $percent%</div>"; |
|
| 77 |
+ } |
|
| 78 |
+ } |
|
| 79 |
+} |
|
| 80 |
+ $content .= "<div style='text-align: center;'><a href='"._BASEDIR."blocks/poll/pollarchive.php'>"._POLLARCHIVE."</a></div>"; |
|
| 81 |
+?> |
|
| 0 | 82 |
\ No newline at end of file |