-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdl_list.php
162 lines (136 loc) Β· 3.66 KB
/
dl_list.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
<?php
define('IN_FORUM', true);
define('BB_SCRIPT', 'dl_list');
define('BB_ROOT', './');
require(BB_ROOT .'common.php');
$forum_id = isset($_REQUEST[POST_FORUM_URL]) ? (int) $_REQUEST[POST_FORUM_URL] : 0;
$topic_id = isset($_REQUEST[POST_TOPIC_URL]) ? (int) $_REQUEST[POST_TOPIC_URL] : 0;
$mode = isset($_REQUEST['mode']) ? (string) $_REQUEST['mode'] : '';
$confirmed = isset($_POST['confirm']);
// Get new DL-status
if ($mode == 'set_dl_status' || $mode == 'set_topics_dl_status')
{
if (isset($_POST['dl_set_will']))
{
$new_dl_status = DL_STATUS_WILL;
$dl_key = 'dlw';
}
elseif (isset($_POST['dl_set_down']))
{
$new_dl_status = DL_STATUS_DOWN;
$dl_key = 'dld';
}
elseif (isset($_POST['dl_set_complete']))
{
$new_dl_status = DL_STATUS_COMPLETE;
$dl_key = 'dlc';
}
elseif (isset($_POST['dl_set_cancel']))
{
$new_dl_status = DL_STATUS_CANCEL;
$dl_key = 'dla';
}
else
{
bb_die('Invalid download status');
}
}
// Define redirect URL
$full_url = isset($_POST['full_url']) ? str_replace('&', '&', htmlspecialchars($_POST['full_url'])) : '';
if (isset($_POST['redirect_type']) && $_POST['redirect_type'] == 'search')
{
$redirect_type = "search.php";
$redirect = ($full_url) ? $full_url : "$dl_key=1";
}
else
{
$redirect_type = (!$topic_id) ? "viewforum.php" : "viewtopic.php";
$redirect = ($full_url) ? $full_url : ((!$topic_id) ? POST_FORUM_URL ."=$forum_id" : POST_TOPIC_URL ."=$topic_id");
}
// Start session management
$user->session_start();
set_die_append_msg();
// Check if user logged in
if (!$userdata['session_logged_in'])
{
redirect(LOGIN_URL . "?redirect=$redirect_type&$redirect");
}
// Check if user did not confirm
if (isset($_POST['cancel']) && $_POST['cancel'])
{
redirect("$redirect_type?$redirect");
}
// Delete DL-list
if ($mode == 'dl_delete' && $topic_id)
{
if (!IS_ADMIN)
{
$sql = "SELECT forum_id FROM ". BB_TOPICS ." WHERE topic_id = $topic_id LIMIT 1";
if (!$row = DB()->sql_fetchrow(DB()->sql_query($sql)))
{
bb_die('Could not obtain forum_id for this topic');
}
$is_auth = auth(AUTH_ALL, $row['forum_id'], $userdata);
if (!$is_auth['auth_mod'])
{
bb_die($lang['NOT_MODERATOR']);
}
}
if (!$confirmed)
{
$hidden_fields = array(
't' => $topic_id,
'mode' => 'dl_delete',
);
print_confirmation(array(
'QUESTION' => $lang['DL_LIST_DEL_CONFIRM'],
'FORM_ACTION' => 'dl_list.php',
'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
));
}
clear_dl_list($topic_id);
redirect("$redirect_type?$redirect");
}
// Update DL status
$req_topics_ary = $topics_ary = array();
// Get topics selected by user
if ($mode == 'set_topics_dl_status')
{
if (!isset($_POST['dl_topics_id_list']) || !is_array($_POST['dl_topics_id_list']))
{
bb_die($lang['NONE_SELECTED']);
}
foreach ($_POST['dl_topics_id_list'] as $topic_id)
{
$req_topics_ary[] = (int) $topic_id;
}
}
elseif ($mode == 'set_dl_status')
{
$req_topics_ary[] = (int) $topic_id;
}
// Get existing topics
if ($req_topics_sql = join(',', $req_topics_ary))
{
$sql = "SELECT topic_id FROM ". BB_TOPICS ." WHERE topic_id IN($req_topics_sql)";
foreach (DB()->fetch_rowset($sql) as $row)
{
$topics_ary[] = $row['topic_id'];
}
}
if ($topics_ary && ($mode == 'set_dl_status' || $mode == 'set_topics_dl_status'))
{
$new_dlstatus_ary = array();
foreach ($topics_ary as $topic_id)
{
$new_dlstatus_ary[] = array(
'user_id' => (int) $user->id,
'topic_id' => (int) $topic_id,
'user_status' => (int) $new_dl_status,
);
}
$new_dlstatus_sql = DB()->build_array('MULTI_INSERT', $new_dlstatus_ary);
DB()->query("REPLACE INTO ". BB_BT_DLSTATUS ." $new_dlstatus_sql");
redirect("$redirect_type?$redirect");
}
redirect("index.php");