-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpolls.php
182 lines (152 loc) · 5.1 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
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
<?php
/**
**********************
** BTManager v3.0.2 **
**********************
** http://www.btmanager.org/
** https://github.com/blackheart1/BTManager3.0.2
** http://demo.btmanager.org/index.php
** Licence Info: GPL
** Copyright (C) 2018
** Formerly Known As phpMyBitTorrent
** Created By Antonio Anzivino (aka DJ Echelon)
** And Joe Robertson (aka joeroberts/Black_Heart)
** Project Leaders: Black_Heart, Thor.
** File polls.php 2018-09-22 00:00:00 Thor
**
** CHANGES
**
** 2018-09-22 - Updated Masthead, Github, !defined('IN_BTM')
**/
if (defined('IN_BTM'))
{
require_once($_SERVER['DOCUMENT_ROOT'].'/security.php');
die ("Error 404 - Page Not Found");
}
else
{
define('IN_BTM', true);
}
require_once("common.php");
require_once("include/torrent_functions.php");
$user->set_lang('polls',$user->ulanguage);
$template = new Template();
set_site_var($user->lang['POLL_OVER_VIEW']);
$action = request_var('action', '');
$pollid = request_var('pollid', '0');
$returnto = strip_tags(request_var('returnto', ''));
if ($action == "delete")
{
if (!$pollid)
{
trigger_error('INVALID_ID', E_USER_ERROR);
}
if (confirm_box(true))
{
$db->sql_query( "DELETE FROM " . $db_prefix . "_pollanswers WHERE pollid = $pollid") or sqlerr();
$db->sql_query( "DELETE FROM " . $db_prefix . "_polls WHERE id = $pollid") or sqlerr();
if ($returnto == "main")
header("Location: $siteurl");
else
header("Location: $siteurl/polls.php?deleted=1");
die;
$template->assign_vars(array(
'S_SUCCESS' => true,
'S_FORWARD' => $siteurl . '/' . (($returnto == "main") ? 'index.php' : 'polls.php'),
'TITTLE_M' => $user->lang['SUCCESS'],
'MESSAGE' => $user->lang['POLL_REMOVED'],
));
echo $template->fetch('message_body.html');
close_out();
}
else
{
$hidden = build_hidden_fields(array(
'pollid' => $pollid,
'action' => 'delete',
'returnto' => $returnto,
));
confirm_box(false, $user->lang['POLL_DELETE'], $hidden, 'confirm_body.html', 'polls.php');
}
}
$rows = $db->sql_query("SELECT COUNT(*) as count FROM " . $db_prefix . "_polls") or sqlerr();
$row = $db->sql_fetchrow($rows);
$pollcount = $row['count'];
if ($pollcount == 0)
{
bterror($user->lang['ERROR_NO_POLLS'], $user->lang['BT_ERROR']);
}
$polls = $db->sql_query("SELECT * FROM " . $db_prefix . "_polls ORDER BY id DESC") or sqlerr();
function srt($a,$b)
{
if ($a[0] > $b[0]) return -1;
if ($a[0] < $b[0]) return 1;
return 0;
}
while ($poll = $db->sql_fetchrow( $polls))
{
$poll_out = array();
$poll_out['CAN_EDIT'] = false;
$o = array($poll['option0'],
$poll['option1'],
$poll['option2'],
$poll['option3'],
$poll['option4'],
$poll['option5'],
$poll['option6'],
$poll['option7'],
$poll['option8'],
$poll['option9']);
$key = array('OP_A',
'OP_B',
'OP_C',
'OP_D',
'OP_E',
'OP_F',
'OP_G',
'OP_H',
'OP_I',
'OP_J');
$poll_out['ADDED'] = gmdate("Y-m-d",strtotime($poll['added']));
$poll_out['TIME_ELAPS'] = get_elapsed_time(sql_timestamp_to_unix_timestamp($poll['added']));
$poll_out['POLL_ID'] = $poll['id'];
$poll_out['POLL_QUESTION'] = $poll['question'];
if (checkaccess('edit_polls'))
{
$poll_out['CAN_EDIT'] = true;
}
$pollanswers = $db->sql_query("SELECT selection FROM " . $db_prefix . "_pollanswers WHERE pollid=" . $poll['id'] . " AND selection < 20") or sqlerr();
$tvotes = $db->sql_numrows($pollanswers);
$poll_out['POLL_VOTES'] = number_format($tvotes);
$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 = $db->sql_fetchrow($pollanswers))
$vs[$pollanswer['selection']] += 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');
$i = 0;
while ($a = $os[$i])
{
if ($tvotes > 0)
$p = round($a[0] / $tvotes * 100);
else
$p = 0;
$poll_out[$key[$i]] = $a[1];
$poll_out[$key[$i] . '_IMG'] = ($p*2);
$poll_out[$key[$i] . '_ANSWERS'] = $p;
++$i;
}
//die(print_r($poll_out));
$template->assign_block_vars('poll_out',$poll_out);
}//POLLS_VIEW
$template->assign_vars(array(
'POLLS_VIEW' => true,));
echo $template->fetch('polloverview.html');
close_out();
?>