-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakepoll.php
179 lines (156 loc) · 5.91 KB
/
makepoll.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
<?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 makepoll.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");
$template = new Template();
$user->set_lang('makepoll',$user->ulanguage);
set_site_var($user->lang['POLL_MANAGER']);
function is_valid_id($id)
{
return is_numeric($id) && ($id > 0) && (floor($id) == $id);
}
$timestamp = time();
$timeout = $timestamp - $timeoutseconds = 300;
$action = request_var("action", '', true);
$pollid = request_var('pollid', 0);
$question = request_var("question", '', true);
$option0 = request_var("option0", '', true);
$option1 = request_var("option1", '', true);
$option2 = request_var("option2", '', true);
$option3 = request_var("option3", '', true);
$option4 = request_var("option4", '', true);
$option5 = request_var("option5", '', true);
$option6 = request_var("option6", '', true);
$option7 = request_var("option7", '', true);
$option8 = request_var("option8", '', true);
$option9 = request_var("option9", '', true);
$sort = request_var("sort", '', true);
$returnto = request_var("returnto", '', true);
$template->assign_vars(array(
'HEADER' => $user->lang['MAKE_POLL'],
));
if ($action == "edit")
{
if (!is_valid_id($pollid))
bterror(sprintf($user->lang['INVALID_POLL_ID'], $pollid), $user->lang['BT_ERROR']);
$res = $db->sql_query("SELECT * FROM " . $db_prefix . "_polls WHERE id = $pollid") or sqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) == 0)
bterror(sprintf($user->lang['NO_POLL_FOUND'], $pollid), $user->lang['BT_ERROR']);
$poll = $db->sql_fetchrow($res);
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$sql_ary = array("question" => $question,
"option0" => $option0,
"option1" => $option1,
"option2" => $option2,
"option3" => $option3,
"option4" => $option4,
"option5" => $option5,
"option6" => $option6,
"option7" => $option7,
"option8" => $option8,
"option9" => $option9,
"sort" => $sort,);
if ($question == '' || $option0 == '' || $option1 == '')
bterror($user->lang['MISSING_FORM_DATA'], $user->lang['BT_ERROR']);
if ($pollid)
{
$sql = "UPDATE " . $db_prefix . "_polls SET " . $db->sql_build_array('UPDATE', $sql_ary) . "WHERE id = $pollid";
$message = 'POLL_EDITED';
}
else
{
$sql_ary += array("added" => gmdate("Y-m-d H:i:s", time()));
$sql = "INSERT INTO " . $db_prefix . "_polls " . $db->sql_build_array('INSERT', $sql_ary);
$message = 'POLL_TAKEN';
}
$db->sql_query($sql);
if ($pollid)
$link = "$siteurl/polls.php#$pollid";
else
$link = "$siteurl";
trigger_error($user->lang[$message] . back_link($link));
die;
}
if ($pollid)
$template->assign_vars(array(
'HEADER' => $user->lang['EDIT_POLL'],
'HIDDEN' => build_hidden_fields(array(
'pollid' => $pollid,
'action' => 'edit',
'returnto' => $returnto)),
));
else
{
// Warn if Current Poll is less than 3 Days Old
$res = $db->sql_query("SELECT question,added FROM " . $db_prefix . "_polls ORDER BY added DESC LIMIT 1") or sqlerr();
$arr = $db->sql_fetchrow($res);
if ($arr)
{
$hours = floor((strtotime(gmdate("Y-m-d H:i:s", time())) - sql_timestamp_to_unix_timestamp($arr["added"])) / 3600);
$days = floor($hours / 24);
if ($days < 3)
{
$hours -= $days * 24;
if ($days)
{
$t = $days . ' ' . $user->lang['DAY' . ($days > 1 ? "S" : "")];
}
else
{
$t = $hours . ' ' . $user->lang['HOUR' . ($hours > 1 ? "S" : "")];
}
$template->assign_vars(array(
'S_NOTICE' => true,
'S_ERROR' => true,
'L_MESSAGE' => $user->lang['WARNING'],
'S_ERROR_MESS' => sprintf($user->lang['NEW_POLL_NOTICE'],$arr['question'],$t),
));
}
}
}
$template->assign_vars(array(
'P_QUESTION' => $poll['question'],
'P_OPTIONA' => $poll['option0'],
'P_OPTIONB' => $poll['option1'],
'P_OPTIONC' => $poll['option2'],
'P_OPTIOND' => $poll['option3'],
'P_OPTIONE' => $poll['option4'],
'P_OPTIONF' => $poll['option5'],
'P_OPTIONG' => $poll['option6'],
'P_OPTIONH' => $poll['option7'],
'P_OPTIONI' => $poll['option8'],
'P_SORT' => $poll["sort"] == "no" ? false : true,
'P_SUBMIT' => $user->lang['SUBMIT'],
));
echo $template->fetch('managepolls.html');
close_out();
?>