-
Notifications
You must be signed in to change notification settings - Fork 29
/
polls.php
150 lines (121 loc) · 5.89 KB
/
polls.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
<?php
/*
// +--------------------------------------------------------------------------+
// | Project: TBDevYSE - TBDev Yuna Scatari Edition |
// +--------------------------------------------------------------------------+
// | This file is part of TBDevYSE. TBDevYSE is based on TBDev, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | TBDevYSE 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, or |
// | (at your option) any later version. |
// | |
// | TBDevYSE is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with TBDevYSE; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
$action = $_GET["action"];
$pollid = $_GET["pollid"];
$returnto = $_GET["returnto"];
if ($action == "delete")
{
if (get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], "Permission denied.");
if (!is_valid_id($pollid))
stderr($tracker_lang['error'], "Invalid ID.");
$sure = $_GET["sure"];
if (!$sure)
stderr("Óäàëèòü îïðîñ","Âû äåéñòâèòåëüíî õîòèòå óäàëèòü îïðîñ? Íàæìèòå\n" .
"<a href=?action=delete&pollid=$pollid&returnto=$returnto&sure=1>ñþäà</a> åñëè âû óâåðåíû.");
sql_query("DELETE FROM pollanswers WHERE pollid = $pollid") or sqlerr(__FILE__, __LINE__);
sql_query("DELETE FROM polls WHERE id = $pollid") or sqlerr(__FILE__, __LINE__);
if ($returnto == "main")
header("Location: $DEFAULTBASEURL");
else
header("Location: $DEFAULTBASEURL/polls.php?deleted=1");
die;
}
$rows = sql_query("SELECT COUNT(*) FROM polls") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_row($rows);
$pollcount = $row[0];
if ($pollcount == 0)
stderr("Èçâèíèåò", "Íåò îïðîñîâ!");
$polls = sql_query("SELECT * FROM polls ORDER BY id DESC LIMIT 1," . ($pollcount - 1 )) or sqlerr(__FILE__, __LINE__);
stdhead("Ïðîøëûå îïðîñû");
print("<h1>Ïðîøëûå îïðîñû</h1>");
function srt($a,$b)
{
if ($a[0] > $b[0]) return -1;
if ($a[0] < $b[0]) return 1;
return 0;
}
while ($poll = mysql_fetch_assoc($polls))
{
$o = array($poll["option0"], $poll["option1"], $poll["option2"], $poll["option3"], $poll["option4"],
$poll["option5"], $poll["option6"], $poll["option7"], $poll["option8"], $poll["option9"],
$poll["option10"], $poll["option11"], $poll["option12"], $poll["option13"], $poll["option14"],
$poll["option15"], $poll["option16"], $poll["option17"], $poll["option18"], $poll["option19"]);
print("<p><table width=750 border=1 cellspacing=0 cellpadding=10><tr><td align=center>\n");
print("<p class=sub>");
$added = date("Y-m-d",strtotime($poll['added'])) . " GMT (" . (get_elapsed_time(sql_timestamp_to_unix_timestamp($poll["added"]))) . " íàçàä)";
print("$added");
if (get_user_class() >= UC_ADMINISTRATOR)
{
print(" - [<a href=makepoll.php?action=edit&pollid=$poll[id]><b>Ðåäàêòèðîâàòü</b></a>]\n");
print(" - [<a href=?action=delete&pollid=$poll[id]><b>Óäàëèòü</b></a>]\n");
}
print("<a name=$poll[id]>");
print("</p>\n");
print("<table class=main border=1 cellspacing=0 cellpadding=5><tr><td class=text>\n");
print("<p align=center><b>" . $poll["question"] . "</b></p>");
$pollanswers = sql_query("SELECT selection FROM pollanswers WHERE pollid=" . $poll["id"] . " AND selection < 20") or sqlerr(__FILE__, __LINE__);
$tvotes = mysql_num_rows($pollanswers);
$vs = array(); // count for each option ([0]..[19])
$os = array(); // votes and options: array(array(123, "Option 1"), array(45, "Option 2"))
// Count votes
while ($pollanswer = mysql_fetch_row($pollanswers))
$vs[$pollanswer[0]] += 1;
reset($o);
for ($i = 0; $i < count($o); ++$i)
if ($o[$i])
$os[$i] = array($vs[$i], $o[$i]);
// now os is an array like this:
if ($poll["sort"] == "yes")
usort($os, srt);
print("<table width=100% class=main border=0 cellspacing=0 cellpadding=0>\n");
$i = 0;
while ($a = $os[$i])
{
if ($tvotes > 0)
$p = round($a[0] / $tvotes * 100);
else
$p = 0;
if ($i % 2)
$c = "";
else
$c = " bgcolor=#ECE9D8";
print("<tr><td class=embedded$c>" . $a[1] . " </td><td class=embedded$c>" .
"<img src=pic/bar_left.gif><img src=pic/bar.gif height=9 width=" . ($p * 3) . "><img src=pic/bar_right.gif> $p%</td></tr>\n");
++$i;
}
print("</table>\n");
$tvotes = number_format($tvotes);
print("<p align=center>Ãîëîñîâ: $tvotes</p>\n");
print("</td></tr></table>\n");
print("</td></tr></table></p>\n");
}
stdfoot();
?>