| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
require_once('../includes/config/settings.php'); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
function __autoload($class) { |
|---|
| 30 |
global $SETTINGS; |
|---|
| 31 |
if (is_file($SETTINGS['fspath'] . 'classes/pages/' . $class . '.php')) { |
|---|
| 32 |
require_once($SETTINGS['fspath'] . 'classes/pages/' . $class . '.php'); |
|---|
| 33 |
} elseif (is_file($SETTINGS['fspath'] . 'classes/misc/' . $class . '.php')) { |
|---|
| 34 |
require_once($SETTINGS['fspath'] . 'classes/misc/' . $class . '.php'); |
|---|
| 35 |
} else { die('Class ' . $class . ' not found.'); } |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
$WARNINGS = Array(); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
require_once($SETTINGS['fspath'] . 'includes/config/version.php'); |
|---|
| 43 |
|
|---|
| 44 |
require_once($SETTINGS['fspath'] . 'includes/config/bots.php'); |
|---|
| 45 |
|
|---|
| 46 |
$F = new Format(); |
|---|
| 47 |
require($SETTINGS['fspath'] . 'includes/lang/' . $SETTINGS['language'] . '.php'); |
|---|
| 48 |
|
|---|
| 49 |
$C = new Connection(); |
|---|
| 50 |
Member::session(); |
|---|
| 51 |
if (isset($_SESSION['lang']) && $_SESSION['lang'] != '') { |
|---|
| 52 |
include($SETTINGS['fspath'] . 'includes/lang/' . $_SESSION['lang'] . '.php'); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
require($SETTINGS['fspath'] . 'includes/input.php'); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
$_pref = '../'; |
|---|
| 59 |
$html = Page::start(); |
|---|
| 60 |
|
|---|
| 61 |
switch (isset($INPUT['showresults'])) { |
|---|
| 62 |
|
|---|
| 63 |
case 'yes': |
|---|
| 64 |
|
|---|
| 65 |
if (Member::checkRights('Pollvote', 'r')) { |
|---|
| 66 |
|
|---|
| 67 |
// get poll info |
|---|
| 68 |
$q = $C->prepare('SELECT topictitle FROM ' . $SETTINGS['dbtableprefix'] . 'topics WHERE poll=:id'); |
|---|
| 69 |
$q->bindParam(':id', $INPUT['id'], PDO::PARAM_INT, 12); |
|---|
| 70 |
$s = $q->execute(); |
|---|
| 71 |
$row_q = $q->fetchAll(); |
|---|
| 72 |
$q = NULL;; |
|---|
| 73 |
$q2 = $C->prepare('SELECT * FROM ' . $SETTINGS['dbtableprefix'] . 'polls WHERE pollid=:id'); |
|---|
| 74 |
$q2->bindParam(':id', $INPUT['id'], PDO::PARAM_INT, 12); |
|---|
| 75 |
$s2 = $q2->execute(); |
|---|
| 76 |
if ($s && $s2) { |
|---|
| 77 |
$row_title = $row_q[0]['topictitle']; |
|---|
| 78 |
$row = $q2->fetchObject(); |
|---|
| 79 |
$q2 = NULL;; |
|---|
| 80 |
|
|---|
| 81 |
$html->body->addChild('h2', $row_title); |
|---|
| 82 |
$div = $html->body->addChild('div', $LANG['Results'] . ':'); |
|---|
| 83 |
$div->addAttribute('class', 'pollheaders'); |
|---|
| 84 |
|
|---|
| 85 |
$table = new Table('poll'); |
|---|
| 86 |
$pollchoices = split("\n", $row->pollchoices); |
|---|
| 87 |
$pollvotes = split("\n", $row->pollvotes); |
|---|
| 88 |
|
|---|
| 89 |
$i = 0; |
|---|
| 90 |
while ($pollvotes[$i] != '') { |
|---|
| 91 |
$totalpollvotes = $totalpollvotes + $pollvotes[$i]; |
|---|
| 92 |
$i++; |
|---|
| 93 |
} |
|---|
| 94 |
$i = 0; |
|---|
| 95 |
while ($pollchoices[$i]) { |
|---|
| 96 |
if ($totalpollvotes > 0) { |
|---|
| 97 |
|
|---|
| 98 |
$percentage = round($pollvotes[$i] * 100 / $totalpollvotes, 0); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
$table->addRow(Array($pollchoices[$i], '<td valign="middle"><img src="../images/pollbar.png" width="' . $percentage . '" height="16" alt="' . $percentage . '%" /></td>', '<td align="right">' . $percentage . '%</td>', '<td align="right">(' . $pollvotes[$i] . ' ' . $word_votes . ')</td>')); |
|---|
| 102 |
$i++; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
$div = $html->body->addChild('div'); |
|---|
| 106 |
$div->addAttribute('class', 'pollbody'); |
|---|
| 107 |
$div->addElement($table->get()); |
|---|
| 108 |
$div = $html->body->addChild('div'); |
|---|
| 109 |
$div->addAttribute('class', 'pollbottom'); |
|---|
| 110 |
$div = $html->body->addChild('div'); |
|---|
| 111 |
$div->addAttribute('align', 'center'); |
|---|
| 112 |
$a = $div->addChild('a', $LANG['Close_Window']); |
|---|
| 113 |
$a->addAttribute('href', 'javascript:self.close()'); |
|---|
| 114 |
} else { |
|---|
| 115 |
$q2->closeCursor(); |
|---|
| 116 |
$div = $html->body->addChild('div', $LANG['error_id']); |
|---|
| 117 |
$div->addAttribute('class', 'message'); |
|---|
| 118 |
} |
|---|
| 119 |
} else { |
|---|
| 120 |
$div = $html->body->addChild('div', $LANG['error_permission_denied']); |
|---|
| 121 |
$div->addAttribute('class', 'message'); |
|---|
| 122 |
} |
|---|
| 123 |
break; |
|---|
| 124 |
|
|---|
| 125 |
default: |
|---|
| 126 |
|
|---|
| 127 |
if (Member::checkRights('Pollvote', 'w') && isset($_SESSION['memberid']) && $_SESSION['memberid'] > 0) { |
|---|
| 128 |
|
|---|
| 129 |
$q = $C->prepare('SELECT t.closed, p.pollid, p.pollchoices, p.pollvotes, p.pollvoters FROM ' . $SETTINGS['dbtableprefix'] . 'polls AS p INNER JOIN ' . $SETTINGS['dbtableprefix'] . 'topics AS t ON t.poll = p.pollid WHERE p.pollid = :id'); |
|---|
| 130 |
$q->bindParam(':id', $INPUT['poll'], PDO::PARAM_INT, 12); |
|---|
| 131 |
if ($q->execute()) { |
|---|
| 132 |
$row = $q->fetchObject(); |
|---|
| 133 |
$q = NULL; |
|---|
| 134 |
|
|---|
| 135 |
if ($row->closed == 0) { |
|---|
| 136 |
|
|---|
| 137 |
$pollvoters = split("\n", $row->pollvoters); |
|---|
| 138 |
$i = 0; $voted = 0; |
|---|
| 139 |
while ($pollvoters[$i] != '') { |
|---|
| 140 |
if ($_SESSION['memberid'] == $pollvoters[$i]) { |
|---|
| 141 |
$voted = 1; |
|---|
| 142 |
} |
|---|
| 143 |
$i++; |
|---|
| 144 |
} |
|---|
| 145 |
if ($voted === 0) { |
|---|
| 146 |
|
|---|
| 147 |
$pollvotes = split("\n", $row->pollvotes); |
|---|
| 148 |
$pollvotes[$INPUT['vote']]++; |
|---|
| 149 |
$row->pollvotes = implode("\n", $pollvotes); |
|---|
| 150 |
$row->pollvoters .= $_SESSION['memberid'] . "\n"; |
|---|
| 151 |
|
|---|
| 152 |
$q = $C->prepare('UPDATE ' . $SETTINGS['dbtableprefix'] . 'polls SET pollvotes=:votes, pollvoters=:voters WHERE pollid=:id'); |
|---|
| 153 |
$q->bindParam(':votes', $row->pollvotes, PDO::PARAM_STR); |
|---|
| 154 |
$q->bindParam(':voters', $row->pollvoters, PDO::PARAM_STR); |
|---|
| 155 |
$q->bindParam(':id', $INPUT['poll'], PDO::PARAM_INT, 12); |
|---|
| 156 |
$q->execute(); |
|---|
| 157 |
$q = NULL; |
|---|
| 158 |
|
|---|
| 159 |
$C = NULL; |
|---|
| 160 |
session_write_close(); |
|---|
| 161 |
session_start(); |
|---|
| 162 |
|
|---|
| 163 |
header('Location: ' . $SETTINGS['webpath'] . $F->link('topic') . 'id=' . $INPUT['topic'] . '&page=' . $INPUT['page'] . '&' . strip_tags(SID)); |
|---|
| 164 |
|
|---|
| 165 |
$div = $html->body->addChild('div', str_replace(Array('%topic%', '%page%'), Array($INPUT['topic'], $INPUT['page']), $LANG['voting_successful'])); |
|---|
| 166 |
$div->addAttribute('class', 'message'); |
|---|
| 167 |
} else { |
|---|
| 168 |
|
|---|
| 169 |
$div = $html->body->addChild('div', $LANG['error_already_voted']); |
|---|
| 170 |
$div->addAttribute('class', 'message'); |
|---|
| 171 |
} |
|---|
| 172 |
} else { |
|---|
| 173 |
|
|---|
| 174 |
$div = $html->body->addChild('div', $LANG['error_topic_closed']); |
|---|
| 175 |
$div->addAttribute('class', 'message'); |
|---|
| 176 |
} |
|---|
| 177 |
} else { |
|---|
| 178 |
|
|---|
| 179 |
$q->closeCursor(); |
|---|
| 180 |
$div = $html->body->addChild('div', $LANG['error_id']); |
|---|
| 181 |
$div->addAttribute('class', 'message'); |
|---|
| 182 |
} |
|---|
| 183 |
} else { |
|---|
| 184 |
|
|---|
| 185 |
$div = $html->body->addChild('div', $LANG['error_permission_denied']); |
|---|
| 186 |
$div->addAttribute('class', 'message'); |
|---|
| 187 |
} |
|---|
| 188 |
break; |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
Page::send($html); |
|---|
| 193 |
|
|---|
| 194 |
?> |
|---|