Browse code

Initial uplad w/ php7 fixes

Rainer Volkrodt authored on 2016/03/12 15:54:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
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
+$pollquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_poll WHERE poll_end IS NULL OR poll_end = '0000-00-00 00:00:00' ORDER BY poll_id DESC LIMIT 1");
28
+if($pollquery) $currentpoll = dbassoc($pollquery);
29
+
30
+if(isset($_POST['cast_vote'])) {
31
+	$poll = isset($_POST['poll_id']) && isNumber($_POST['poll_id']) ? $_POST['poll_id'] : false;
32
+	$opt = isset($_POST['opt']) && isNumber($_POST['opt']) ? $_POST['opt'] : false;
33
+	if(!$poll || !$opt) accessDenied( ); // could only be a hack attempt.
34
+	$voted = dbquery("SELECT vote_id FROM ".TABLEPREFIX."fanfiction_poll_votes WHERE vote_poll = '".$currentpoll['poll_id']."' AND vote_user = '".USERUID."'");
35
+	list($voter) = dbrow($voted);
36
+        if(!$voter) $cast = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_poll_votes(`vote_user`, `vote_opt`, `vote_poll`) VALUES('".USERUID."', '$opt', '$poll')");
37
+	if(!empty($cast)) $content .= write_message(_VOTECAST);
38
+	else $content .= write_message(_ALREADYVOTED);
39
+}
40
+
41
+if(!$currentpoll) $content = "<div style='text-align: center;'>"._NOPOLL."</div>";
42
+else  {
43
+	   $pollopts = explode("|#|", $currentpoll['poll_opts']);
44
+	   $content .= "<div id='poll_question'>".$currentpoll['poll_question']."</div><br />";
45
+	   if(isMEMBER) {
46
+		$voted = dbquery("SELECT vote_id FROM ".TABLEPREFIX."fanfiction_poll_votes WHERE vote_poll = '".$currentpoll['poll_id']."' AND vote_user = '".USERUID."'");
47
+		list($voter) = dbrow($voted);
48
+           }
49
+	   if(empty($voter) && isMEMBER) {
50
+		$content .= "<form name='poll' id='poll' method='POST' action='".$_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] ? "?".$_SERVER['QUERY_STRING']  : "")."'>
51
+			<input type='hidden' name='poll_id' value='".$currentpoll['poll_id']."'>";
52
+		   $x = 1;
53
+		   foreach($pollopts as $opt) {
54
+		       $content .= "<input type='radio' name='opt' value='$x'> $opt<br />";
55
+		       $x++;
56
+		   }
57
+		   $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>";
58
+		$content .= write_message("<br /><a href='"._BASEDIR."blocks/poll/pollarchive.php?poll=".$currentpoll['poll_id']."'>"._POLLRESULTS."</a><br /><br />");
59
+
60
+	  }
61
+	  else { 
62
+		$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");
63
+
64
+		if(isset($blocks['poll']['bar']) && file_exists($blocks['poll']['bar'])) $bar = $blocks['poll']['bar'];
65
+		else $bar = "blocks/poll/bar.jpg";
66
+		$totalvotes = 0;
67
+		while($optvotes = dbassoc($votes)) {
68
+			$results[$optvotes['vote_opt']] = $optvotes['count'];
69
+			 $totalvotes = $optvotes['count'] ? $optvotes['count'] + $totalvotes : $totalvotes;
70
+		}
71
+		foreach($pollopts as $num => $opt) {
72
+			unset($percent);
73
+			if(!empty($results[($num + 1)])) $percent = floor(($results[($num + 1)] / $totalvotes) * 100);
74
+			else $percent = 0;
75
+			$content .= "<div>$opt <br /> <img src='$bar' alt='".strip_tags($opt)."' height='12' width='".$percent."' class='poll'> $percent%</div>";	
76
+		}
77
+	  }
78
+}
79
+	$content .= "<div style='text-align: center;'><a href='"._BASEDIR."blocks/poll/pollarchive.php'>"._POLLARCHIVE."</a></div>";
80
+?>
0 81
\ No newline at end of file