forked from mlangill/biotorrents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forummanage.php
374 lines (298 loc) · 11.4 KB
/
forummanage.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
<?php
ob_start("ob_gzhandler");
require_once "include/bittorrent.php";
require_once "include/html_functions.php";
require_once "include/user_functions.php";
dbconn();
loggedinorreturn();
if( (get_user_class() < UC_MODERATOR) || ($CURUSER['id'] !== '1')) //sysop id check
stderr("Error", "Permission denied.");
$action = isset($_GET['action']) ? $_GET['action'] : ''; //if not goto default!
switch($action) {
case 'edit':
editForum();
break;
case 'takeedit':
takeeditForum();
break;
case 'delete':
deleteForum();
break;
case 'takedelete':
takedeleteForum();
break;
case 'add':
addForum();
break;
case 'takeadd':
takeaddForum();
break;
default:
showForums();
}
function showForums() {
stdhead("Forum Management Tools");
echo '<span class="btn"><a href="forummanage.php?action=add">Add New</a></span><br /><br />';
begin_main_frame();
echo '<table width="700" border="0" align="center" cellpadding="2" cellspacing="0">';
echo "<tr><td class='colhead' align='left'>Name</td><td class='colhead'>Topics</td><td class='colhead'>Posts</td><td class='colhead'>Read</td><td class='colhead'>Write</td><td class='colhead'>Create Topic</td><td class='colhead'>Modify</td></tr>";
$result = mysql_query ("SELECT * FROM forums ORDER BY sort ASC");
if ( mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)){
echo "<tr><td><a href='forums.php?action=viewforum&forumid=".$row["id"]."'><b>".htmlentities($row["name"], ENT_QUOTES)."</b></a><br />".htmlentities($row["description"], ENT_QUOTES)."</td>";
echo "<td>".$row["topiccount"]."</td><td>".$row["postcount"]."</td><td>minimal " . get_user_class_name($row["minclassread"]) . "</td><td>minimal " . get_user_class_name($row["minclasswrite"]) . "</td><td>minimal " . get_user_class_name($row["minclasscreate"]) . "</td><td align='center' style=\"white-space: nowrap;\"><b><a href=\"?action=edit&id=".$row["id"]."\">EDIT</a> | <a href=\"forummanage.php?action=delete&id=".$row["id"]."\"><font color='red'>DELETE</font></a></b></td></tr>";
}
}
else
{print "<tr><td>Sorry, no records were found!</td></tr>";}
echo "</table>";
end_main_frame();
stdfoot();
}
function addForum() {
global $CURUSER;
stdhead("Add Forum");
echo '<span class="btn"><a href="forummanage.php">Cancel</a></span><br /><br />';
begin_main_frame();
?>
<form method='post' action="forummanage.php?action=takeadd">
<table width="600" border="0" cellspacing="0" cellpadding="3" align="center">
<tr align="center">
<td colspan="2" class='colhead'>Make New Forum</td>
</tr>
<tr>
<td><b>Forum Name</b></td>
<td><input name="name" type="text" size="20" maxlength="60" /></td>
</tr>
<tr>
<td><b>Forum Description</b></td>
<td><input name="desc" type="text" size="30" maxlength="200" /></td>
</tr>
<tr>
<td><b>Minimum Read Permission</b></td>
<td><select name="readclass">
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value='$i'" . ($CURUSER["class"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n");
?>
</select>
</td>
</tr>
<tr>
<td><b>Minimum Write Permission</b></td>
<td><select name='writeclass'>
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value='$i'" . ($CURUSER["class"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n");
?>
</select></td>
</tr>
<tr>
<td><b>Minimun Create Topic Permission</b></td>
<td><select name='createclass'>
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value='$i'" . ($CURUSER["class"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n");
?>
</select></td>
</tr>
<tr>
<td><b>Forum Rank</b></td>
<td><select name="sort">
<?php
$res = mysql_query ("SELECT sort FROM forums");
$nr = mysql_num_rows($res);
$maxclass = $nr + 1;
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value='$i'>$i </option>\n");
?>
</select>
</td>
</tr>
<tr align="center">
<td colspan="2">
<!--<input type="hidden" name="action" value="takeadd" /> -->
<input type="submit" name="Submit" value="Make Forum" class="btn" /></td>
</tr>
</table>
</form>
<?php
// end_frame();
end_main_frame();
stdfoot();
}
function editForum() {
stdhead("Edit Forum");
$id = isset($_GET["id"]) ? (int)$_GET["id"] : stderr("Error", "Not Found");
echo '<span class="btn"><a href="forummanage.php">Cancel</a></span><br /><br />';
begin_frame("Edit Forum");
$result = mysql_query ("SELECT * FROM forums where id = '$id'");
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)){
?>
<form method="post" action="forummanage.php?action=takeedit">
<table width="600" border="0" cellspacing="0" cellpadding="3" align="center">
<tr align="center">
<td colspan="2" class='colhead'>Edit Forum: <?php echo htmlentities($row["name"], ENT_QUOTES);?></td>
</tr>
<tr>
<td><b>Forum Name</b></td>
<td><input name="name" type="text" size="30" maxlength="60" value="<?php echo htmlentities($row["name"], ENT_QUOTES);?>" /></td>
</tr>
<tr>
<td><b>Forum Description</b></td>
<td><input name="desc" type="text" size="30" maxlength="200" value="<?php echo htmlentities($row["description"], ENT_QUOTES);?>" /></td>
</tr>
<tr>
<td><b>Minimun Read Permission</b></td>
<td><select name='readclass'>
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
if( get_user_class_name($i) != "" )
print("<option value='$i'" . ($row["minclassread"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>");
?>
</select>
</td>
</tr>
<tr>
<td><b>Minimal Post Rank</b></td>
<td><select name='writeclass'>
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
if( get_user_class_name($i) != "" )
print("<option value='$i'" . ($row["minclasswrite"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i)."</option>");
?>
</select></td>
</tr>
<tr>
<td><b>Minimal Create Topic Rank</b></td>
<td><select name='createclass'>
<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
if( get_user_class_name($i) != "" )
print("<option value='$i'" . ($row["minclasscreate"] == $i ? " selected='selected'" : "") . ">" . get_user_class_name($i)."</option>");
?>
</select></td>
</tr>
<tr>
<td><b>Forum Rank</b></td>
<td><select name='sort'>
<?php
$res = mysql_query ("SELECT sort FROM forums");
$nr = mysql_num_rows($res);
$maxclass = $nr + 1;
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value='$i'" . ($row["sort"] == $i ? " selected='selected'" : "") . ">$i</option>");
?>
</select>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input type="submit" name="Submit" value="Edit Forum" class="btn" />
</td>
</tr>
</table>
</form>
<?php
}
}
else
{print "Sorry, no records were found!";}
// end_frame();
end_main_frame();
stdfoot();
}
function takeaddForum() {
if (!$_POST['name'] && !$_POST['desc']) { header("Location: forummanage.php"); die();}
@mysql_query("INSERT INTO forums
(sort, name, description, minclassread, minclasswrite, minclasscreate) VALUES(" .
sqlesc($_POST['sort']) . ", " .
sqlesc($_POST['name']). ", " .
sqlesc($_POST['desc']). ", " .
sqlesc($_POST['readclass']) . ", " .
sqlesc($_POST['writeclass']) . ", " .
sqlesc($_POST['createclass']) . ")");
if(mysql_affected_rows() === 1)
stderr("Success", "Forum Added. <a href='forummanage.php'>Return to Forum Management</a>");
else
stderr("Error", "There was an error. <a href='forummanage.php'>Return to Forum Management</a>");
die();
}
function takeeditForum() {
if (!$_POST['name'] && !$_POST['desc'] && !$_POST['id']) { header("Location: forummanage.php"); die();}
@mysql_query("UPDATE forums SET sort = " .
sqlesc($_POST['sort']) . ", name = " .
sqlesc($_POST['name']). ", description = " .
sqlesc($_POST['desc']). ", minclassread = " .
sqlesc($_POST['readclass']) . ", minclasswrite = " .
sqlesc($_POST['writeclass']) . ", minclasscreate = " .
sqlesc($_POST['createclass']) . " where id = ".
sqlesc($_POST['id'])."");
if(mysql_affected_rows() === 1)
stderr("Success", "Forum Edited. <a href='forummanage.php'>Return to Forum Management</a>");
else
stderr("Error", "There was an error. <a href='forummanage.php'>Return to Forum Management</a>");
die();
}
function deleteForum() {
$id = isset($_GET['id']) ? (int)$_GET['id'] : stderr("Error", "No fecking id!");
$res = @mysql_query("SELECT id FROM topics WHERE forumid=$id");
if (mysql_num_rows($res) >= 1) {
stdhead();
forum_select($id);
stdfoot();
exit();
}
else
stderr("Warning", "You are about to delete a forum, there is no UNDELETE!! <a href='forummanage.php?action=takedelete&id=$id'>Continue?</a>");
}
function takedeleteForum() {
$id = isset($_GET['id']) ? (int)$_GET['id'] : stderr("Error", "No fecking id!");
if(!isset($_POST['deleteall'])) {
$res = @mysql_query("SELECT id FROM topics WHERE forumid=$id");
if (mysql_num_rows($res) == 0)
@mysql_query("DELETE FROM forums WHERE id=$id");
(mysql_affected_rows() > 0) ?
stderr("Success", "Forum deleted return to <a href='forummanage.php'>Forum Management</a>") : stderr("Error", "Something bad happened!");
}
else
{
$forumid = (isset($_POST['forumid']) && ctype_digit($_POST['forumid'])) ? (int)$_POST['forumid'] : atserr("Error", "Nowhere to move to baby!");
$res = @mysql_query("SELECT id FROM topics WHERE forumid=$id");
if (mysql_num_rows($res) == 0)
stderr("Error", "There are no topics in this forum!");
while($row = mysql_fetch_assoc($res))
$tid[] = $row['id'];
@mysql_query("UPDATE topics SET forumid=$forumid WHERE id IN (".join(',' , $tid).")");
if(mysql_affected_rows() > 0)
@mysql_query("DELETE FROM forums WHERE id=$id");
(mysql_affected_rows() > 0) ?
stderr("Success", "Forum deleted return to <a href='forummanage.php'>Forum Management</a>") : stderr("Error", "Something bad happened!");
}
}
function forum_select($currentforum = 0)
{
print("<p align='center'><form method='post' action='forummanage.php?action=takedelete&id=$currentforum' name='jump'>\n");
print("<input type='hidden' name='deleteall' value='true' />\n");
print("Select Forum to move topics to: ");
print("<select name='forumid'>\n");
$res = mysql_query("SELECT * FROM forums ORDER BY name") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
{
if ($arr["id"] == $currentforum)
continue;
print("<option value='" . $arr["id"] . ($currentforum == $arr["id"] ? "' selected='selected'>" : "'>") . $arr["name"] . "</option>\n");
}
print("</select>\n");
print("<input type='submit' value='Move To...' class='btn' />\n");
print("</form>\n</p>");
}
?>