/
index.php
416 lines (401 loc) · 19.4 KB
/
index.php
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
/* Additional security & Abstraction layer conversion */
/* 2003 chatserv */
/* http://www.nukefixes.com -- http://www.nukeresources.com */
/************************************************************************/
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- "._SURVEYS."";
if (isset($pollID)) {
$pollID = intval($pollID);
}
if(!isset($pollID)) {
include ('header.php');
pollList();
include ('footer.php');
} elseif(isset($forwarder)) {
pollCollector($pollID, $voteID, $forwarder);
} elseif($op == "results" && $pollID > 0) {
include ("header.php");
OpenTable();
echo "<center><font class=\"title\"><b>"._CURRENTPOLLRESULTS."</b></font></center>";
CloseTable();
echo "<br>";
echo "<table border='0' width='100%'><tr><td width='70%' valign='top'>";
OpenTable();
pollResults($pollID);
CloseTable();
echo "</td><td> </td><td width='30%' valign='top'>";
OpenTable();
echo "<b>"._LAST5POLLS." $sitename</b><br><br>";
if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
$result = $db->sql_query("SELECT pollID, pollTitle, voters FROM ".$prefix."_poll_desc where artid='0' order by timeStamp DESC limit 1,5");
while ($row = $db->sql_fetchrow($result)) {
$plid = intval($row['pollID']);
$pltitle = stripslashes(check_html($row['pollTitle'], "nohtml"));
$plvoters = intval($row['voters']);
if ($pollID == $plid) {
echo "<img src='images/arrow.gif' border='0'> $pltitle ($plvoters "._LVOTES.")<br><br>";
} else {
echo "<img src='images/arrow.gif' border='0'> <a href='modules.php?name=$module_name&op=results&pollID=$plid$r_options'>$pltitle</a> ($plvoters "._LVOTES.")<br><br>";
}
}
echo "<a href='modules.php?name=$module_name'><b>"._MOREPOLLS."</b></a>";
CloseTable();
echo "</td></tr></table>";
cookiedecode($user);
if (($pollcomm) AND ($mode != "nocomments")) {
echo "<br><br>";
include("modules/Surveys/comments.php");
}
include ("footer.php");
} elseif($voteID > 0) {
pollCollector($pollID, $voteID);
} elseif($pollID != pollLatest()) {
include ('header.php');
OpenTable();
echo "<center><font class=\"option\"><b>"._SURVEY."</b></font></center>";
CloseTable();
echo "<br><br>";
echo "<table border=\"0\" align=\"center\"><tr><td>";
pollMain($pollID);
echo "</td></tr></table>";
include ('footer.php');
} else {
include ('header.php');
OpenTable();
echo "<center><font class=\"option\"><b>"._CURRENTSURVEY."</b></font></center>";
CloseTable();
echo "<br><br><table border=\"0\" align=\"center\"><tr><td>";
pollNewest();
echo "</td></tr></table>";
include ('footer.php');
}
/*********************************************************/
/* Functions */
/*********************************************************/
function pollMain($pollID) {
global $boxTitle, $boxContent, $pollcomm, $user, $cookie, $prefix, $dbi, $module_name, $db;
$pollID = intval($pollID);
if(!isset($pollID))
$pollID = 1;
if(!isset($url))
$url = sprintf("modules.php?name=$module_name&op=results&pollID=%d", $pollID);
$boxContent .= "<form action=\"modules.php?name=$module_name\" method=\"post\">";
$boxContent .= "<input type=\"hidden\" name=\"pollID\" value=\"".$pollID."\">";
$boxContent .= "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">";
$result_a = $db->sql_query("SELECT pollTitle, voters FROM ".$prefix."_poll_desc WHERE pollID='$pollID'");
list($pollTitle, $voters) = $db->sql_fetchrow($result_a);
$boxTitle = _SURVEY;
$boxContent .= "<font class=\"content\"><b>$pollTitle</b></font><br><br>\n";
$boxContent .= "<table border=\"0\" width=\"100%\">";
for($i = 1; $i <= 12; $i++) {
$result = sql_query("SELECT pollID, optionText, optionCount, voteID FROM ".$prefix."_poll_data WHERE pollID='$pollID' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result, $dbi);
if(is_object($object)) {
$optionText = $object->optionText;
if($optionText != "") {
$boxContent .= "<tr><td valign=\"top\"><input type=\"radio\" name=\"voteID\" value=\"".$i."\"></td><td width=\"100%\"><font class=\"content\">$optionText</font></td></tr>\n";
}
}
}
$boxContent .= "</table><br><center><font class=\"content\"><input type=\"submit\" value=\""._VOTE."\"></font><br>";
if (is_user($user)) {
cookiedecode($user);
}
for($i = 0; $i < 12; $i++) {
$result2 = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE pollID='$pollID' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result2, $dbi);
$optionCount = $object->optionCount;
$sum = (int)$sum+$optionCount;
}
$boxContent .= "<br><font class=\"content\"><a href=\"modules.php?name=$module_name&op=results&pollID=$pollID&mode=$cookie[4]&order=$cookie[5]&thold=$cookie[6]\"><b>"._RESULTS."</b></a><br><a href=\"modules.php?name=$module_name\"><b>"._POLLS."</b></a><br>";
if ($pollcomm) {
list($numcom) = $db->sql_fetchrow($db->sql_query("select count(*) from ".$prefix."_pollcomments where pollID='$pollID'"));
$boxContent .= "<br>"._VOTES.": <b>$sum</b> <br> "._PCOMMENTS." <b>$numcom</b>\n\n";
} else {
$boxContent .= "<br>"._VOTES." <b>$sum</b>\n\n";
}
$boxContent .= "</font></center></form>\n\n";
themesidebox($boxTitle, $boxContent);
}
function pollLatest() {
global $prefix, $multilingual, $currentlang, $db;
if ($multilingual == 1) {
$querylang = "WHERE planguage='$currentlang' AND artid='0'";
} else {
$querylang = "WHERE artid='0'";
}
$pollID = $db->sql_fetchrow($db->sql_query("SELECT pollID FROM ".$prefix."_poll_desc $querylang ORDER BY pollID DESC LIMIT 1"));
return($pollID[0]);
}
function pollNewest() {
$pollID = pollLatest();
pollMain($pollID);
}
function pollCollector($pollID, $voteID, $forwarder) {
global $HTTP_COOKIE_VARS, $prefix, $db;
/* Fix for lamers that like to cheat on polls */
if (empty($ip)) {
$ip = $_SERVER["REMOTE_ADDR"];
}
$pollID = intval($pollID);
$voteID = intval($voteID);
$past = time()-1800;
$db->sql_query("DELETE FROM ".$prefix."_poll_check WHERE time < '$past'");
$row = $db->sql_fetchrow($db->sql_query("SELECT ip FROM ".$prefix."_poll_check WHERE (ip='$ip') AND (pollID='$pollID')"));
$ips = $row['ip'];
$ctime = time();
if ($ip == $ips) {
$voteValid = 0;
} else {
$db->sql_query("INSERT INTO ".$prefix."_poll_check (ip, time, pollID) VALUES ('$ip', '$ctime', '$pollID')");
$voteValid = "1";
}
/* Fix end */
/* update database if the vote is valid */
if($voteValid>0) {
$db->sql_query("UPDATE ".$prefix."_poll_data SET optionCount=optionCount+1 WHERE pollID='$pollID' AND voteID='$voteID'");
if ($voteID != "") {
$db->sql_query("UPDATE ".$prefix."_poll_desc SET voters=voters+1 WHERE pollID='$pollID'");
update_points(8);
}
Header("Location: $forwarder");
} else {
Header("Location: $forwarder");
}
/* a lot of browsers can't handle it if there's an empty page */
echo "<html><head></head><body></body></html>";
}
function pollList() {
global $user, $cookie, $prefix, $multilingual, $currentlang, $admin, $dbi, $module_name, $db;
if (isset($cookie[4])) { $r_options .= "&mode=$cookie[4]"; }
if (isset($cookie[5])) { $r_options .= "&order=$cookie[5]"; }
if (isset($cookie[6])) { $r_options .= "&thold=$cookie[6]"; }
if ($multilingual == 1) {
$querylang = "WHERE planguage='$currentlang' AND artid='0'";
} else {
$querylang = "WHERE artid='0'";
}
$result = sql_query("SELECT pollID, pollTitle, timeStamp, voters FROM ".$prefix."_poll_desc $querylang ORDER BY timeStamp DESC", $dbi);
$counter = 0;
OpenTable();
OpenTable();
echo "<center><font class=\"title\"><b>"._PASTSURVEYS."</b></font></center>";
CloseTable();
echo "<table border=\"0\" cellpadding=\"8\"><tr><td>";
while($object = sql_fetch_object($result, $dbi)) {
$resultArray[$counter] = array($object->pollID, $object->pollTitle, $object->timeStamp, $object->voters);
$counter++;
}
for ($count = 0; $count < count($resultArray); $count++) {
$id = $resultArray[$count][0];
$id = intval($id);
$i = intval($i);
$pollTitle = $resultArray[$count][1];
$voters = $resultArray[$count][3];
for($i = 0; $i < 12; $i++) {
$result2 = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE pollID='$id' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result2, $dbi);
$optionCount = $object->optionCount;
$sum = (int)$sum+$optionCount;
}
echo "<strong><big>·</big></strong> <a href=\"modules.php?name=$module_name&pollID=$id\">$pollTitle</a> ";
if (is_admin($admin)) {
$editing = " - <a href=\"admin.php?op=polledit&pollID=$id\">Edit</a>";
} else {
$editing = "";
}
echo "(<a href=\"modules.php?name=$module_name&op=results&pollID=$id$r_options\">"._RESULTS."</a> - $sum "._LVOTES."$editing)<br>\n";
$sum = 0;
}
echo "</td></tr></table>"
."<br>";
OpenTable();
echo "<center><font class=\"title\"><b>"._SURVEYSATTACHED."</b></font></center>";
CloseTable();
echo "<table border=\"0\" cellpadding=\"8\"><tr><td>";
if ($multilingual == 1) {
$querylang = "WHERE planguage='$currentlang' AND artid!='0'";
} else {
$querylang = "WHERE artid!='0'";
}
$counter = 0;
$result3 = sql_query("SELECT pollID, pollTitle, timeStamp, voters FROM ".$prefix."_poll_desc $querylang ORDER BY timeStamp DESC", $dbi);
while($object = sql_fetch_object($result3, $dbi)) {
$resultArray2[$counter] = array($object->pollID, $object->pollTitle, $object->timeStamp, $object->voters);
$counter++;
}
for ($count = 0; $count < count($resultArray2); $count++) {
$id = $resultArray2[$count][0];
$id = intval($id);
$i = intval($i);
$pollTitle = $resultArray2[$count][1];
$voters = $resultArray2[$count][3];
for($i = 0; $i < 12; $i++) {
$result4 = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE pollID='$id' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result4, $dbi);
$optionCount = $object->optionCount;
$sum = (int)$sum+$optionCount;
}
echo "<strong><big>·</big></strong> <a href=\"modules.php?name=$module_name&pollID=$id\">$pollTitle</a> ";
if (is_admin($admin)) {
$editing = " - <a href=\"admin.php?op=polledit&pollID=$id\">Edit</a>";
} else {
$editing = "";
}
$res = $db->sql_query("select sid, title from ".$prefix."_stories where pollID='$id'");
list($sid, $title) = $db->sql_fetchrow($res);
$sid = intval($sid);
$title = stripslashes(check_html($title, "nohtml"));
echo "(<a href=\"modules.php?name=$module_name&op=results&pollID=$id$r_options\">"._RESULTS."</a> - $sum "._LVOTES."$editing)<br>\n"
.""._ATTACHEDTOARTICLE." <a href=\"modules.php?name=News&file=article&sid=$sid$r_options\">$title</a><br><br>\n";
$sum = "";
}
echo "</td></tr></table>";
CloseTable();
}
function pollResults($pollID) {
global $resultTableBgColor, $resultBarFile, $Default_Theme, $user, $cookie, $prefix, $dbi, $admin, $module_name, $db;
if(!isset($pollID)) $pollID = 1;
$pollID = intval($pollID);
$result = $db->sql_query("SELECT pollID, pollTitle, timeStamp, artid FROM ".$prefix."_poll_desc WHERE pollID='$pollID'");
$holdtitle = $db->sql_fetchrow($result);
echo "<b>$holdtitle[1]</b><br><br>";
$i = intval($i);
for($i = 0; $i < 12; $i++) {
$result2 = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE pollID='$pollID' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result2, $dbi);
$optionCount = $object->optionCount;
$sum = (int)$sum+$optionCount;
}
echo "<table border=\"0\">";
/* cycle through all options */
for($i = 1; $i <= 12; $i++) {
/* select next vote option */
$result3 = sql_query("SELECT pollID, optionText, optionCount, voteID FROM ".$prefix."_poll_data WHERE pollID='$pollID' AND voteID='$i'", $dbi);
$object = sql_fetch_object($result3, $dbi);
if(is_object($object)) {
$optionText = $object->optionText;
$optionCount = $object->optionCount;
if($optionText != "") {
echo "<tr><td>";
echo "$optionText";
echo "</td>";
if($sum) {
$percent = 100 * $optionCount / $sum;
} else {
$percent = 0;
}
echo "<td>";
$percentInt = (int)$percent * 4 * 1;
$percent2 = (int)$percent;
if(is_user($user)) {
if($cookie[9]=="") $cookie[9]=$Default_Theme;
if(!$file=@opendir("themes/$cookie[9]")) {
$ThemeSel = $Default_Theme;
} else {
$ThemeSel = $cookie[9];
}
} else {
$ThemeSel = $Default_Theme;
}
if (file_exists("themes/$ThemeSel/images/survey_leftbar.gif") AND file_exists("themes/$ThemeSel/images/survey_mainbar.gif") AND file_exists("themes/$ThemeSel/images/survey_rightbar.gif")) {
$l_size = getimagesize("themes/$ThemeSel/images/survey_leftbar.gif");
$m_size = getimagesize("themes/$ThemeSel/images/survey_mainbar.gif");
$r_size = getimagesize("themes/$ThemeSel/images/survey_rightbar.gif");
$leftbar = "survey_leftbar.gif";
$mainbar = "survey_mainbar.gif";
$rightbar = "survey_rightbar.gif";
} else {
$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
$leftbar = "leftbar.gif";
$mainbar = "mainbar.gif";
$rightbar = "rightbar.gif";
}
if (file_exists("themes/$ThemeSel/images/survey_mainbar_d.gif")) {
$m1_size = getimagesize("themes/$ThemeSel/images/survey_mainbar_d.gif");
$mainbar_d = "survey_mainbar_d.gif";
if ($percent2 > 0 AND $percent2 <= 23) {
$salto = "<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"$percentInt\">";
} elseif ($percent2 > 24 AND $percent2 < 50) {
$a = $percentInt - 100;
$salto = "<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"$a\">";
} elseif ($percent2 > 49 AND $percent2 < 75) {
$a = $percentInt - 200;
$salto = "<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"$a\">";
} elseif ($percent2 > 74 AND $percent2 <= 100) {
$a = $percentInt - 300;
$salto = "<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"70\">"
."<img src=\"themes/$ThemeSel/images/$mainbar_d\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m1_size[1]\" width=\"30\">"
."<img src=\"themes/$ThemeSel/images/$mainbar\" alt=\"$percent2 %\" title=\"$percent2 %\" height=\"$m_size[1]\" width=\"$a\">";
}
}
if ($percent > 0) {
echo "<img src=\"themes/$ThemeSel/images/$leftbar\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"$percent2 %\" title=\"$percent2 %\">";
if (file_exists("themes/$ThemeSel/images/survey_mainbar_d.gif")) {
echo "$salto";
} else {
echo "<img src=\"themes/$ThemeSel/images/$mainbar\" height=\"$m_size[1]\" width=\"$percentInt\" alt=\"$percent2 %\" title=\"$percent2 %\">";
}
echo "<img src=\"themes/$ThemeSel/images/$rightbar\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"$percent2 %\" title=\"$percent2 %\">";
} else {
echo "<img src=\"themes/$ThemeSel/images/$leftbar\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"$percent2 %\" title=\"$percent2 %\">";
if (!file_exists("themes/$ThemeSel/images/survey_mainbar_d.gif")) {
echo "<img src=\"themes/$ThemeSel/images/$mainbar\" height=\"$m_size[1]\" width=\"$m_size[0]\" alt=\"$percent2 %\" title=\"$percent2 %\">";
}
echo "<img src=\"themes/$ThemeSel/images/$rightbar\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"$percent2 %\" title=\"$percent2 %\">";
}
printf(" %.2f%% (%s)", $percent, $optionCount);
echo "</td></tr>";
}
}
}
echo "</table><br>";
echo "<center><font class=\"content\">";
echo "<b>"._TOTALVOTES." $sum</b><br>";
echo "<br><br>";
$booth = $pollID;
$booth = intval($booth);
if ($holdtitle[3] > 0) {
$article = "<br><br>"._GOBACK."</font></center>";
} else {
$article = "</font></center>";
}
echo "[ <a href=\"modules.php?name=$module_name&pollID=$booth\">"._VOTING."</a> | "
."<a href=\"modules.php?name=$module_name\">"._OTHERPOLLS."</a> ] $article";
if (is_admin($admin)) {
echo "<br><center>[ <a href=\"admin.php?op=create\">"._ADD."</a> | <a href=\"admin.php?op=polledit&pollID=$pollID\">"._EDIT."</a> ]</center>";
}
return(1);
}
?>