-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathforums.php
More file actions
3497 lines (2810 loc) · 131 KB
/
forums.php
File metadata and controls
3497 lines (2810 loc) · 131 KB
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
**************************
** FreeTSP Version: 1.0 **
**************************
** http://www.freetsp.info
** https://github.com/Krypto/FreeTSP
** Licence Info: GPL
** Copyright (C) 2010 FreeTSP v1.0
** A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
** Project Leaders: Krypto, Fireknight.
**/
//-- Bleach Forums Improved and Optimized for TBDEV.NET by Alex2005 --//
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'function_main.php');
require_once(FUNC_DIR.'function_user.php');
require_once(FUNC_DIR.'function_vfunctions.php');
require_once(FUNC_DIR.'function_torrenttable.php');
require_once(FUNC_DIR.'function_bbcode.php');
db_connect(true);
logged_in();
parked();
//-- Configs Start --//
//-- The Max Class, ie: UC_CODER - Is Able To Delete, Edit The Forum Etc... --//
define('MAX_CLASS', UC_MANAGER);
//-- Set's The Max File Size In php.ini, No Need To Change --//
ini_set("upload_max_filesize", $maxfilesize);
//-- Set's The Root Path, Change Only If You Know What You Are Doing --//
//define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
//-- The Extensions That Are Allowed To Be Uploaded By The Users --//
//-- Note: You Need To Have The Pics In The $image_dir Folder, ie zip.gif, rar.gif --//
$allowed_file_extensions = array('rar',
'zip');
//-- Just A Check, So That The Default URL, Wont Have A Ending Backslash (to Double Backslash The Links), No Need To Edit Or Delete --//
$site_url_rev = strrev($site_url);
if ($site_url_rev[0] == '/')
{
$site_url_rev[0] = '';
$site_url = strrev($site_url_rev);
}
//-- Configs End --//
$action = (isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"]) ? $_POST["action"] : ''));
if (!function_exists('highlight'))
{
function highlight ($search, $subject, $hlstart = '<span style="color : #ff0000; font-weight:bold;">', $hlend = '</span>')
{
$srchlen = strlen($search); //-- Length Of Searched String --//
if ($srchlen == 0)
{
return $subject;
}
$find = $subject;
while ($find = stristr($find, $search)) //-- Find $search Text In $subject -case Insensitive --//
{
$srchtxt = substr($find, 0, $srchlen); //-- Get New Search Text --//
$find = substr($find, $srchlen);
$subject = str_replace($srchtxt, $hlstart.$srchtxt.$hlend, $subject); //-- Highlight Found Case Insensitive Search Text --//
}
return $subject;
}
}
function catch_up ($id = 0)
{
global $CURUSER, $posts_read_expiry;
$userid = (int) $CURUSER['id'];
$res = sql_query("SELECT t.id, t.lastpost, r.id AS r_id, r.lastpostread
FROM topics AS t
LEFT JOIN posts AS p ON p.id = t.lastpost
LEFT JOIN readposts AS r ON r.userid=".sqlesc($userid)." AND r.topicid=t.id
WHERE p.added > ".sqlesc(get_date_time(gmtime() - $posts_read_expiry)).(!empty($id) ?
AND t.id '.(is_array($id) ? 'IN ('.implode(', ', $id).')' : '= '.sqlesc($id)) : '')) or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
{
$postid = (int) $arr['lastpost'];
if (!is_valid_id($arr['r_id']))
{
sql_query("INSERT INTO readposts (userid, topicid, lastpostread)
VALUES($userid, ".(int) $arr['id'].", $postid)") or sqlerr(__FILE__, __LINE__);
}
else
{
if ($arr['lastpostread'] < $postid)
{
sql_query("UPDATE readposts
SET lastpostread = $postid
WHERE id = ".$arr['r_id']) or sqlerr(__FILE__, __LINE__);
}
}
}
mysql_free_result($res);
}
//-- Begin Cached Online Users --//
function forum_stats ()
{
//-- Active Users In Forums --//
global $forum_width, $CURUSER, $image_dir, $site_url;
$forum3 = "";
$files = CACHE_DIR."forum.txt";
$expire = 30; //-- 30 Seconds --//
if (file_exists($files) && filemtime($files) > (time() - $expire))
{
$forum3 = unserialize(file_get_contents($files));
}
else
{
$dt = sqlesc(get_date_time(gmtime() - 180));
$forum1 = sql_query("SELECT id, username, class, warned, donor
FROM users
WHERE forum_access >= $dt
ORDER BY class DESC") or sqlerr(__FILE__, __LINE__);
while ($forum2 = mysql_fetch_assoc($forum1))
{
$forum3[] = $forum2;
}
$OUTPUT = serialize($forum3);
$fp = fopen($files, "w");
fputs($fp, $OUTPUT);
fclose($fp);
} //-- End Else --//
$forumusers = "";
if (is_array($forum3))
{
foreach ($forum3
AS
$arr)
{
if ($forumusers)
{
$forumusers .= ",\n";
}
$forumusers .= "".format_username($arr)."";
}
}
if (!$forumusers)
{
$forumusers = "There are Currently No Active Members in the Forum";
}
$topic_post_res = sql_query("SELECT SUM(topiccount) AS topics, SUM(postcount) AS posts
FROM forums");
$topic_post_arr = mysql_fetch_assoc($topic_post_res);
?>
<br />
<table border='0' width='<?php echo $forum_width; ?>' cellspacing='0' cellpadding='5'>
<tr>
<td class='colhead' align='center'>Now Active in Forums:</td>
</tr>
<tr>
<td class='text'><?php echo $forumusers; ?></td>
</tr>
<tr>
<td class='colhead' align='center'><h2>Our Members Wrote <span style='font-weight:bold;'><?php echo number_format($topic_post_arr['posts']); ?></span> Posts in <span style='font-weight:bold;'><?php echo number_format($topic_post_arr['topics']); ?></span> Threads</h2>
</td>
</tr>
</table>
<?php
}
function show_forums ($forid)
{
global $CURUSER, $image_dir, $posts_read_expiry, $site_url;
$forums_res = sql_query("SELECT f.id, f.name, f.description, f.postcount, f.topiccount, f.minclassread, p.added, p.topicid, p.userid, p.id AS pid, u.username, t.subject, t.lastpost, r.lastpostread
FROM forums AS f
LEFT JOIN posts AS p ON p.id = (SELECT MAX(lastpost) FROM topics WHERE forumid = f.id)
LEFT JOIN users AS u ON u.id = p.userid
LEFT JOIN topics AS t ON t.id = p.topicid
LEFT JOIN readposts AS r ON r.userid = ".sqlesc($CURUSER['id'])." AND r.topicid = p.topicid
WHERE f.forid = $forid
ORDER BY sort ASC") or sqlerr(__FILE__, __LINE__);
while ($forums_arr = mysql_fetch_assoc($forums_res))
{
if ($CURUSER['class'] < $forums_arr["minclassread"])
{
continue;
}
$forumid = (int) $forums_arr["id"];
$lastpostid = (int) $forums_arr['lastpost'];
if (is_valid_id($forums_arr['pid']))
{
$lastpost = "<div style='white-space: nowrap;'>".$forums_arr["added"]."<br />by <a class='altlink_user' href='$site_url/userdetails.php?id=".(int) $forums_arr["userid"]."'><span style='font-weight:bold;'>".htmlspecialchars($forums_arr['username'])."</span></a><br />in <a href='forums.php?action=viewtopic&topicid=".(int) $forums_arr["topicid"]."&page=p$lastpostid#$lastpostid'><span style='font-weight:bold;'>".htmlspecialchars($forums_arr['subject'])."</span></a></div>";
$img = 'unlocked'.((($forums_arr['added'] > (get_date_time(gmtime() - $posts_read_expiry))) ? ((int) $forums_arr['pid'] > $forums_arr['lastpostread']) : 0) ? 'new' : '');
}
else
{
$lastpost = "N/A";
$img = "unlocked";
}
?>
<tr>
<td align='left'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='embedded' style='padding-right: 5px'><img src="<?php echo $image_dir.$img; ?>.png" width='32' height='32' border='0' alt='No New Posts' title='No New Posts' /></td>
<td class='embedded'>
<a href='forums.php?action=viewforum&forumid=<?php echo $forumid; ?>'><span style='font-weight:bold;'><?php echo htmlspecialchars($forums_arr["name"]); ?></span></a><?php
/*
if ($CURUSER['class'] >= UC_ADMINISTRATOR)
{
?> <span style='font-size: xx-small;'>[<a class='altlink' href='forums.php?action=editforum&forumid=<?php echo $forumid; ?>'>Edit</a>][<a class='altlink' href='forums.php?action=deleteforum&forumid=<?php echo $forumid; ?>'>Delete</a>]</span><?php
}
*/
if (!empty($forums_arr["description"]))
{
?><br /><?php echo htmlspecialchars($forums_arr["description"]);
}
?></td>
</tr>
</table>
</td>
<td align='center'><?php echo number_format($forums_arr["topiccount"]); ?></td>
<td align='center'><?php echo number_format($forums_arr["postcount"]); ?></td>
<td align='left'><?php echo $lastpost; ?></td>
</tr>
<?php
}
}
//--Returns the Minimum Read/Write Class Levels of a Forum --//
function get_forum_access_levels ($forumid)
{
global $CURUSER, $site_url, $image_dir;
$res = sql_query("SELECT minclassread, minclasswrite, minclasscreate
FROM forums
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
{
return false;
}
$arr = mysql_fetch_assoc($res);
return array("read" => $arr["minclassread"],
"write" => $arr["minclasswrite"],
"create" => $arr["minclasscreate"]);
}
//-- Returns The Forum Id Of A Topic, Or False On Error --//
function get_topic_forum ($topicid)
{
global $CURUSER, $image_dir, $posts_read_expiry, $site_url;
$res = sql_query("SELECT forumid
FROM topics
WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
{
return false;
}
$arr = mysql_fetch_assoc($res);
return (int) $arr['forumid'];
}
//-- Returns The Id Of The Last Post Of A Forum --//
function update_topic_last_post ($topicid)
{
$res = sql_query("SELECT MAX(id) AS id
FROM posts
WHERE topicid = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die ("No Post Found!");
sql_query("UPDATE topics
SET lastpost = {$arr['id']}
WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
//-- Update Forum Post/Topic Count --//
$forums = sql_query("SELECT id
FROM forums");
while ($forum = mysql_fetch_assoc($forums))
{
$postcount = 0;
$topiccount = 0;
$topics = sql_query("SELECT id
FROM topics
WHERE forumid = $forum[id]");
while ($topic = mysql_fetch_assoc($topics))
{
$res = sql_query("SELECT COUNT(*)
FROM posts
WHERE topicid = $topic[id]");
$arr = mysql_fetch_row($res);
$postcount += $arr[0];
++$topiccount;
}
sql_query("UPDATE forums
SET postcount = $postcount, topiccount = $topiccount
WHERE id = $forum[id]");
}
}
function get_forum_last_post ($forumid)
{
$res = sql_query("SELECT MAX(lastpost) AS lastpost
FROM topics
WHERE forumid = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res);
$postid = (int) $arr['lastpost'];
return (is_valid_id($postid) ? $postid : 0);
}
//-- Inserts a Quick Jump Menu --//
function insert_quick_jump_menu ($currentforum = 0)
{
global $CURUSER;
?>
<div style='text-align:center;'>
<form method='get' action='forums.php' name='jump'>
<input type="hidden" name="action" value="viewforum" />
<?php print("<span style='font-weight:bold;'>Quick jump:</span>"); ?>
<select name='forumid' onchange="if(this.options[this.selectedIndex].value != -1){ forms['jump'].submit() }">
<?php
$res = sql_query("SELECT id, name, minclassread
FROM forums
ORDER BY name") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
{
if ($CURUSER['class'] >= $arr["minclassread"])
{
echo "<option value='".$arr["id"].($currentforum == $arr["id"] ? "' selected='selected'" : "'").'>'.$arr["name"]."</option>";
}
}
?>
</select>
<input type='submit' class='btn' value='Go!' />
</form>
</div>
<br />
<?php
}
//-- Inserts a Compose Frame --//
function insert_compose_frame ($id, $newtopic = true, $quote = false, $attachment = false)
{
global $maxsubjectlength, $CURUSER, $maxfilesize, $image_dir, $use_attachment_mod, $site_url, $image_dir;
if ($newtopic)
{
$res = sql_query("SELECT name
FROM forums
WHERE id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("Bad Forum ID!");
?><h3>New Topic in <a href='forums.php?action=viewforum&forumid=<?php echo $id; ?>'><?php echo htmlspecialchars($arr["name"]); ?></a> forum</h3>
<?php
}
else
{
$res = sql_query("SELECT t.forumid, t.subject, t.locked, f.minclassread
FROM topics AS t
LEFT JOIN forums AS f ON f.id = t.forumid
WHERE t.id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die ("Forum Error, Topic Not Found!");
if ($CURUSER['class'] < $arr['minclassread'])
{
error_message("warn", "Sorry", "You are Not Allowed in Here!");
end_table();
exit();
}
if ($arr['locked'] == 'yes' && $CURUSER['class'] < UC_MODERATOR)
{
error_message("warn", "Sorry", "The Topic is Locked!");
end_table();
exit();
}
?><h3 align="center">Reply to Topic: <a href='forums.php?action=viewtopic&topicid=<?php echo $id; ?>'><?php echo htmlspecialchars($arr["subject"]); ?></a></h3>
<?php
}
if ($quote)
{
$postid = (int) $_GET["postid"];
if (!is_valid_id($postid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT posts.*, users.username
FROM posts
JOIN users ON posts.userid = users.id
WHERE posts.id = $postid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
{
error_message("error", "Error", "No Post with that ID!");
}
$arr = mysql_fetch_assoc($res);
}
begin_frame("Compose", true);
?>
<form method='post' name='compose' action='forums.php' enctype='multipart/form-data'>
<input type='hidden' name='action' value='post' />
<input type='hidden' name='<?php echo ($newtopic ? 'forumid' : 'topicid'); ?>' value='<?php echo $id; ?>' />
<?php
begin_table(true);
if ($newtopic)
{
?>
<tr>
<td class='rowhead' width='10%'>Subject</td>
<td align='left'>
<input type='text' name='subject' size='100' maxlength='<?php echo $maxsubjectlength; ?>' style='border: 0px; height: 19px' />
</td>
</tr>
<?php
}
?>
<tr>
<td class='rowhead' width='10%'>Body</td>
<td class='rowhead'>
<?php
$qbody = ($quote ? "[quote=".htmlspecialchars($arr["username"])."]".htmlspecialchars(unesc($arr["body"]))."[/quote]" : '');
if (function_exists('textbbcode'))
{
echo("".textbbcode("compose", "body", $qbody)."");
}
else
{
?>
<textarea name='body' rows='7' cols='5' style='width:99%'><?php echo $qbody; ?></textarea><?php
}
echo("</td></tr>");
if ($use_attachment_mod && $attachment)
{
?>
<tr>
<td colspan='2'>
<fieldset class='fieldset'>
<legend>Add Attachment</legend>
<input type='checkbox' name='uploadattachment' value='yes' />
<input type='file' name='file' size='60' />
<div class='error'>Allowed Files: rar, zip<br />Size Limit <?php echo mksize($maxfilesize); ?></div>
</fieldset>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan='2' align='center'>
<input type='submit' class='btn' value='Submit' />
</td>
</tr>
<?php
end_table();
?>
</form>
<p align='center'><a href='<?php echo $site_url; ?>/smilies.php' target='_blank'>Smilies</a></p><?php
end_frame();
//-- Get Last 10 Posts If This Is A Reply --//
if (!$newtopic)
{
$postres = sql_query("SELECT p.id, p.added, p.body, u.id AS uid, u.username, u.avatar
FROM posts AS p
LEFT JOIN users AS u ON u.id = p.userid
WHERE p.topicid = ".sqlesc($id).
ORDER BY p.id DESC
LIMIT 10") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($postres) > 0)
{
?>
<br />
<?php
begin_frame("Last 10 Posts, in Reverse Order");
while ($post = mysql_fetch_assoc($postres))
{
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($post["avatar"]) : '');
if (empty($avatar))
{
$avatar = $image_dir."default_avatar.gif";
}
?>
<p class='sub'>#<?php echo $post["id"]; ?> by <?php echo (!empty($post["username"]) ? $post["username"] : "unknown[{$post['uid']}]"); ?> at <?php echo $post["added"]; ?> GMT</p><?php
begin_table(true);
?>
<tr>
<td class='rowhead' align='center' width='100' height='100' style='padding: 0px' valign="top"><img src="<?php echo $avatar; ?>" width='125' height='125' border='0' alt='Avatar' title='Avatar' /></td>
<td class='comment' valign='top'><?php echo format_comment($post["body"]); ?></td>
</tr>
<?php
end_table();
}
end_frame();
}
}
insert_quick_jump_menu();
}
if ($action == 'updatetopic' && $CURUSER['class'] >= UC_MODERATOR)
{
$topicid = (isset($_GET['topicid']) ? (int) $_GET['topicid'] : (isset($_POST['topicid']) ? (int) $_POST['topicid'] : 0));
if (!is_valid_id($topicid))
{
error_message("error", "Error", "Invalid Topic ID!");
}
$topic_res = sql_query('SELECT t.sticky, t.locked, t.subject, t.forumid, f.minclasswrite,
(SELECT COUNT(id) FROM posts WHERE topicid = t.id) AS post_count
FROM topics AS t
LEFT JOIN forums AS f ON f.id = t.forumid
WHERE t.id = '.sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($topic_res) == 0)
{
error_message("error", "Error", "No Topic with that ID!");
}
$topic_arr = mysql_fetch_assoc($topic_res);
if ($CURUSER['class'] < (int) $topic_arr['minclasswrite'])
{
error_message("error", "Error", "You are Not Allowed to Edit this Topic.");
}
$forumid = (int) $topic_arr['forumid'];
$subject = $topic_arr['subject'];
if ((isset($_GET['delete']) ? $_GET['delete'] : (isset($_POST['delete']) ? $_POST['delete'] : '')) == 'yes')
{
if ((isset($_GET['sure']) ? $_GET['sure'] : (isset($_POST['sure']) ? $_POST['sure'] : '')) != 'yes')
{
error_message("error", "Sanity Check", "<a href='forums.php?action=$action&topicid=$topicid&delete=yes&sure=yes'>You are about to Delete this Topic. Click here to Confirm!</a>");
}
write_log("Topic <span style='font-weight:bold;'>".$subject."</span> was Deleted by <a class='altlink_user' href='$site_url/userdetails.php?id=".$CURUSER['id']."'>".$CURUSER['username']."</a>.");
if ($use_attachment_mod)
{
$res = sql_query("SELECT attachments.filename
FROM posts
LEFT JOIN attachments ON attachments.postid = posts.id
WHERE posts.topicid = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
{
if (!empty($arr['filename']) && is_file($attachment_dir."/".$arr['filename']))
{
unlink($attachment_dir."/".$arr['filename']);
}
}
}
sql_query("DELETE posts, topics ".($use_attachment_mod ? ", attachments, attachmentdownloads " : "").($use_poll_mod ? ", postpolls, postpollanswers " : "").
FROM topics
LEFT JOIN posts ON posts.topicid = topics.id ".($use_attachment_mod ?
LEFT JOIN attachments ON attachments.postid = posts.id
LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id " : "").($use_poll_mod ?
LEFT JOIN postpolls ON postpolls.id = topics.pollid
LEFT JOIN postpollanswers ON postpollanswers.pollid = postpolls.id " : "").
WHERE topics.id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
header('Location: '.$_SERVER['PHP_SELF'].'?action=viewforum&forumid='.$forumid);
exit();
}
$returnto = $_SERVER['PHP_SELF'].'?action=viewtopic&topicid='.$topicid;
$updateset = array();
$locked = ($_POST['locked'] == 'yes' ? 'yes' : 'no');
if ($locked != $topic_arr['locked'])
{
$updateset[] = 'locked = '.sqlesc($locked);
}
$sticky = ($_POST['sticky'] == 'yes' ? 'yes' : 'no');
if ($sticky != $topic_arr['sticky'])
{
$updateset[] = 'sticky = '.sqlesc($sticky);
}
$new_subject = $_POST['subject'];
if ($new_subject != $subject)
{
if (empty($new_subject))
{
error_message("error", "Error", "Topic Name Cannot be Empty.");
}
$updateset[] = 'subject = '.sqlesc($new_subject);
}
$new_forumid = (int) $_POST['new_forumid'];
if (!is_valid_id($new_forumid))
{
error_message("error", "Error", "Invalid Forum ID!");
}
if ($new_forumid != $forumid)
{
$post_count = (int) $topic_arr['post_count'];
$res = sql_query("SELECT minclasswrite
FROM forums
WHERE id = ".sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
{
error_message("error", "Error", "Forum Not Found!");
}
$arr = mysql_fetch_assoc($res);
if ($CURUSER['class'] < (int) $arr['minclasswrite'])
{
error_message("error", "Error", "You are Not Allowed to Move this Topic into the Selected Forum.");
}
$updateset[] = 'forumid = '.sqlesc($new_forumid);
sql_query("UPDATE forums
SET topiccount = topiccount - 1, postcount = postcount - ".sqlesc($post_count).
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE forums
SET topiccount = topiccount + 1, postcount = postcount + ".sqlesc($post_count).
WHERE id = ".sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
$returnto = $_SERVER['PHP_SELF'].'?action=viewforum&forumid='.$new_forumid;
}
if (sizeof($updateset) > 0)
{
sql_query("UPDATE topics
SET ".implode(', ', $updateset).
WHERE id = ".sqlesc($topicid));
}
header('Location: '.$returnto);
exit();
}
else if ($action == "editforum" && $CURUSER['class'] == MAX_CLASS) //-- Action: Edit Forum --//
{
$forumid = (int) $_GET["forumid"];
if (!is_valid_id($forumid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT name, description, minclassread, minclasswrite, minclasscreate
FROM forums
WHERE id = $forumid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
{
error_message("error", "Error", "No Forum Found with that ID!");
}
$forum = mysql_fetch_assoc($res);
site_header("Edit Forum");
begin_frame("Edit Forum", "center");
print("<form method='post' action='forums.php?action=updateforum&forumid=$forumid'>\n");
begin_table();
print("<tr>
<td class='rowhead'>Forum name</td>
<td align='left' style='padding: 0px'>
<input type='text' name='name' size='60' maxlength='$maxsubjectlength' value=\"".htmlspecialchars($forum['name'])."\" style='border: 0px; height: 19px' />
</td>
</tr>\n
<tr>
<td class='rowhead'>Description</td>
<td align='left' style='padding: 0px'>
<textarea name='description' cols='68' rows='3' style='border: 0px'>".htmlspecialchars($forum['description'])."</textarea>
</td>
</tr>\n
<tr>
<td class='rowhead'></td>
<td align='left' style='padding: 0px'> Minimum <select name='readclass'>");
for ($i = 0;
$i <= MAX_CLASS;
++$i)
{
print("<option value='$i'".($i == $forum['minclassread'] ? " selected='selected'" : "").">".get_user_class_name($i)."</option>\n");
}
print("</select> Class Required to View<br />\n Minimum <select name='writeclass'>");
for ($i = 0;
$i <= MAX_CLASS;
++$i)
{
print("<option value='$i'".($i == $forum['minclasswrite'] ? " selected='selected'" : "").">".get_user_class_name($i)."</option>\n");
}
print("</select> Class Required to Post<br />\n Minimum <select name='createclass'>");
for ($i = 0;
$i <= MAX_CLASS;
++$i)
{
print("<option value='$i'".($i == $forum['minclasscreate'] ? " selected='selected'" : "").">".get_user_class_name($i)."</option>\n");
}
print("</select> Class Required to Create Topics</td></tr>\n
<tr>
<td colspan='2' align='center'>
<input type='submit' class='btn' value='Submit' />
</td>
</tr>\n");
end_table();
print("</form><br />");
end_frame();
site_footer();
exit();
}
else if ($action == "updateforum" && $CURUSER['class'] == MAX_CLASS) //-- Action: Update Forum --//
{
$forumid = (int) $_GET["forumid"];
if (!is_valid_id($forumid))
{
error_message('error', 'Error', 'Invalid ID!');
}
$res = sql_query('SELECT id
FROM forums
WHERE id = '.sqlesc($forumid));
if (mysql_num_rows($res) == 0)
{
error_message('error', 'Error', 'No Forum with that ID!');
}
$name = $_POST['name'];
$description = $_POST['description'];
if (empty($name))
{
error_message('error', 'Error', 'You Must Specify a Name for the Forum.');
}
if (empty($description))
{
error_message('error', 'Error', 'You Must Provide a Description for the Forum.');
}
sql_query("UPDATE forums
SET name = ".sqlesc($name).", description = ".sqlesc($description).", minclassread = ".sqlesc((int) $_POST['readclass']).", minclasswrite = ".sqlesc((int) $_POST['writeclass']).", minclasscreate = ".sqlesc((int) $_POST['createclass']).
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
else if ($action == 'deleteforum' && $CURUSER['class'] == MAX_CLASS) //-- Action: Delete Forum --//
{
$forumid = (int) $_GET['forumid'];
if (!is_valid_id($forumid))
{
error_message('error', 'Error', 'Invalid ID!');
}
$confirmed = (int) $_GET['confirmed'];
if (!$confirmed)
{
$rt = sql_query("SELECT topics.id, forums.name
FROM topics
LEFT JOIN forums ON forums.id=topics.forumid
WHERE topics.forumid = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$topics = mysql_num_rows($rt);
$posts = 0;
if ($topics > 0)
{
while ($topic = mysql_fetch_assoc($rt))
{
$ids[] = $topic['id'];
$forum = $topic['name'];
}
$rp = sql_query("SELECT COUNT(id)
FROM posts
WHERE topicid IN (".join(', ', $ids).")");
foreach ($ids
AS
$id)
{
if ($a = mysql_fetch_row($rp))
{
$posts += $a[0];
}
}
}
if ($use_attachment_mod || $use_poll_mod)
{
$res = sql_query("SELECT ".($use_attachment_mod ?
COUNT(attachments.id) AS attachments " : "").($use_poll_mod ? ($use_attachment_mod ? ', ' : '').
COUNT(postpolls.id) AS polls " : "").
FROM topics
LEFT JOIN posts ON topics.id=posts.topicid ".($use_attachment_mod ?
LEFT JOIN attachments ON attachments.postid = posts.id " : "").($use_poll_mod ?
LEFT JOIN postpolls ON postpolls.id=topics.pollid " : "").
WHERE topics.forumid=".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
($use_attachment_mod ? $attachments = 0 : NULL);
($use_poll_mod ? $polls = 0 : NULL);
if ($arr = mysql_fetch_assoc($res))
{
($use_attachment_mod ? $attachments = $arr['attachments'] : NULL);
($use_poll_mod ? $polls = $arr['polls'] : NULL);
}
}
error_message("warn", "** WARNING! **", "Deleting this Forum with id=$forumid (".$forum.") will also Delete ".$posts." Post".($posts != 1 ? 's' : '').($use_attachment_mod ? ", ".$attachments." attachment".($attachments != 1 ? 's' : '') : "").($use_poll_mod ? " AND ".($polls - $attachments)." poll".(($polls - $attachments) != 1 ? 's' : '') : "")." in ".$topics." topic".($topics != 1 ? 's' : '').".[<a href='forums.php?action=deleteforum&forumid=$forumid&confirmed=1'>ACCEPT</a>] [<a href='forums.php?action=viewforum&forumid=$forumid'>CANCEL</a>]");
}
$rt = sql_query("SELECT topics.id ".($use_attachment_mod ? ", attachments.filename " : "").
FROM topics
LEFT JOIN posts ON topics.id = posts.topicid ".($use_attachment_mod ?
LEFT JOIN attachments ON attachments.postid = posts.id " : "").
WHERE topics.forumid = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$topics = mysql_num_rows($rt);
if ($topics == 0)
{
sql_query("DELETE
FROM forums
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
else
{
while ($topic = mysql_fetch_assoc($rt))
{
$tids[] = $topic['id'];
if ($use_attachment_mod && !empty($topic['filename']))
{
$filename = $attachment_dir."/".$topic['filename'];
if (is_file($filename))
{
unlink($filename);
}
}
}
}
sql_query("DELETE posts.*, topics.*, forums.* ".($use_attachment_mod ? ", attachments.*, attachmentdownloads.* " : "").($use_poll_mod ? ", postpolls.*, postpollanswers.* " : "").
FROM posts ".($use_attachment_mod ?
LEFT JOIN attachments ON attachments.postid = posts.id
LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id " : "").
LEFT JOIN topics ON topics.id = posts.topicid
LEFT JOIN forums ON forums.id = topics.forumid ".($use_poll_mod ?
LEFT JOIN postpolls ON postpolls.id = topics.pollid
LEFT JOIN postpollanswers ON postpollanswers.pollid = postpolls.id " : "").
WHERE posts.topicid IN (".join(', ', $tids).")") or sqlerr(__FILE__, __LINE__);
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
else if ($action == "newtopic") //-- Action: New Topic --//
{
$forumid = (int) $_GET["forumid"];
if (!is_valid_id($forumid))
{
error_message("error", "Error", "Invalid ID!");
}
site_header("New Topic");
insert_compose_frame($forumid, true, false, true);
site_footer();
exit();
}
else if ($action == "post") //-- Action: Post --//
{
$forumid = (isset($_POST['forumid']) ? (int) $_POST['forumid'] : NULL);
if (isset($forumid) && !is_valid_id($forumid))
{
error_message("error", "Error", "Invalid Forum ID!");