forked from joeroberts234/phpMyBitTorrent
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathforums.php
More file actions
1461 lines (1321 loc) · 68.9 KB
/
forums.php
File metadata and controls
1461 lines (1321 loc) · 68.9 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
/*
*----------------------------phpMyBitTorrent V 2.0.5---------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*-------------- Created By Antonio Anzivino (aka DJ Echelon) --------------*
*------------- http://www.p2pmania.it -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*------------- http://www.bittorrent.com -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*-- This program is free software; you can redistribute it and/or modify --*
*-- it under the terms of the GNU General Public License as published by --*
*-- the Free Software Foundation; either version 2 of the License, or --*
*-- (at your option) any later version. --*
*-- --*
*-- This program is distributed in the hope that it will be useful, --*
*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*
*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*
*-- GNU General Public License for more details. --*
*-- --*
*-- You should have received a copy of the GNU General Public License --*
*-- along with this program; if not, write to the Free Software --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --*
*-- --*
*------------------------------------------------------------------------------*
*------ ©2010 phpMyBitTorrent Development Team ------*
*----------- http://phpmybittorrent.com -----------*
*------------------------------------------------------------------------------*
*----------------- Sunday, September 14, 2008 9:05 PM ---------------------*
*/
if (defined('IN_PMBT'))die ("You can't include this file");
define("IN_PMBT",true);
include("header.php");
include_once("include/forum_config.php");
include_once'themes/'.$theme.'/forums/main.php';
if(!$user->ulanguage == '' && file_exists('language/forum/'.$user->ulanguage.'.php'))include'language/forum/'.$user->ulanguage.'.php';
elseif (file_exists('language/forum/'.$language.'.php'))include_once'language/forum/'.$language.'.php';
else
include_once'language/forum/english.php';
$themedir = "" . $siteurl . "/themes/" . $theme . "/forums/";
if ($user->forumbanned) {
OpenErrTable(_bt_notice);
echo _btf_banned;
CloseErrTable();
include'footer.php';
}else{
if ($FORUMS)
{
//define the clickable smilies
$submit = (isset($_POST['post'])) ? true : false;
$preview = (isset($_POST['preview'])) ? true : false;
$save = (isset($_POST['save'])) ? true : false;
$load = (isset($_POST['load'])) ? true : false;
$delete = (isset($_POST['delete'])) ? true : false;
$cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
$action = ($delete && !$preview && !$refresh && $submit) ? 'reply' : request_var('action', '');
if($refresh)$action = 'reply';
include'include/textarea.php';
echo"<script type=\"text/javascript\" src=\"bbcode.js\"></script>";
function CutName ($vTxt, $Car) {
while(strlen($vTxt) > $Car) {
return substr($vTxt, 0, $Car) . "...";
} return $vTxt;
}
function is_valid_id($id)
{
return is_numeric($id) && ($id > 0) && (floor($id) == $id);
}
function is_booked_marcked($id){
global $db, $db_prefix, $user;
$sql = "SELECT COUNT(`forum_id`) FROM`".$db_prefix."_forums_watch` WHERE `forum_id`='".$id."' AND `user_id`='".$user->id."';";
$arr = $db->sql_query($sql);
$res = $db->sql_fetchrow($arr);
return ($res[0]>=1) ? true : false;
}
function get_topic_title($id){
global $db, $db_prefix;
$sql = "SELECT `subject` FROM `".$db_prefix."_forum_topics` WHERE `id`='".$id."' LIMIT 1;";
$arr = $db->sql_query($sql);
while ($res = $db->sql_fetchrow($arr)) {
return $res['subject'];
}
}
function get_row_count($table, $suffix = "")
{
global $db, $db_prefix;
if ($suffix)
$suffix = " $suffix";
($r = $db->sql_query("SELECT COUNT(*) FROM $table$suffix")) or die(mysql_error());
($a = $db->sql_fetchrow($r)) or die(mysql_error());
return $a[0];
}
// Mark all forums as read
function catch_up(){
global $db, $db_prefix, $user;
$res = $db->sql_query("SELECT id, lastpost FROM ".$db_prefix."_forum_topics") or forumsqlerr(__FILE__, __LINE__);
while ($arr = $db->sql_fetchrow($res)) {
$topicid = $arr["id"];
$postid = $arr["lastpost"];
$r = $db->sql_query("SELECT id,lastpostread FROM ".$db_prefix."_forum_readposts WHERE userid=".$user->id." AND topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($r) == 0){
$db->sql_query("INSERT INTO ".$db_prefix."_forum_readposts (userid, topicid, lastpostread) VALUES(".$user->id.", $topicid, $postid)") or forumsqlerr(__FILE__, __LINE__);
}else{
$a = $db->sql_fetchrow($r);
if ($a["lastpostread"] < $postid)
$db->sql_query("UPDATE ".$db_prefix."_forum_readposts SET lastpostread=$postid WHERE id=" . $a["id"]) or forumsqlerr(__FILE__, __LINE__);
}
}
}
// Returns the minimum read/write class levels of a forum
function get_forum_access_levels($forumid){
global $db, $db_prefix;
$res = $db->sql_query("SELECT minclassread, minclasswrite, moderator FROM ".$db_prefix."_forum_forums WHERE id=$forumid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) != 1)
return false;
$arr = $db->sql_fetchrow($res);
return array("read" => $arr["minclassread"], "write" => $arr["minclasswrite"], "moder" => $arr['moderator']);
}
// Returns the forum ID of a topic, or false on error
function get_topic_forum($topicid) {
global $db, $db_prefix;
$res = $db->sql_query("SELECT forumid FROM ".$db_prefix."_forum_topics WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) != 1)
return false;
$arr = $db->sql_fetchrow($res);
return $arr[0];
}
// Returns the ID of the last post of a forum
function update_topic_last_post($topicid) {
global $db, $db_prefix;
$res = $db->sql_query("SELECT id FROM ".$db_prefix."_forum_posts WHERE topicid=$topicid ORDER BY id DESC LIMIT 1") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or die("No post found");
$postid = $arr[0];
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET lastpost=$postid WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
}
function get_forum_last_post($forumid) {
global $db, $db_prefix;
$res = $db->sql_query("SELECT lastpost FROM ".$db_prefix."_forum_topics WHERE forumid=$forumid ORDER BY lastpost DESC LIMIT 1") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
$postid = $arr[0];
if ($postid)
return $postid;
else
return 0;
}
function encodehtml($s, $linebreaks = true)
{
$s = str_replace(array("<",">","\""), array("<",">","""), str_replace("&", "&", $s));
if ($linebreaks)
$s = nl2br($s);
return $s;
}
//Top forum posts
//Action: New topic
if ($action == "newtopic") {
$forumid = $_GET["forumid"];
if (!is_valid_id($forumid)){
OpenErrTable(_bt_notice);
echo _btf_invalid_id;
CloseErrTable();
include'footer.php';
}
forumheader(_btf_cnt);
insert_compose_frame($forumid);
include'footer.php';
}
///////////////////////////////////////////////////////// Action: POST
if ($action == "post") {
$forumid = $_POST["forumid"];
$topicid = $_POST["topicid"];
if (!is_valid_id($forumid) && !is_valid_id($topicid)){
OpenErrTable(_bt_notice);
echo _btf_invalid_id_post;
CloseErrTable();
include'footer.php';
}
$newtopic = $forumid > 0;
$subject = $_POST["subject"];
if ($newtopic) {
if (!$subject)
showerror(_bterror, _btf_must_enter_subject);
$subject = trim($subject);
if (!$subject OR $subject == "")
showerror(_bterror, _btf_must_enter_subject);
if (strlen($subject) > $max_subject_length)showerror(_bterror, "Subject is limited to $max_subject_length characters.");
}else{
$forumid = get_topic_forum($topicid) or die("Bad topic ID");
}
$attachment_data = (isset($_POST['attachment_data'])) ? $_POST['attachment_data'] : array();
////// Make sure sure user has write access in forum
$arr = get_forum_access_levels($forumid) or die("Bad forum ID");
if (!$arr["write"] == "0" AND !in_array($user->group,explode(" ", $arr["write"])) AND !in_array($user->id,explode(" ", $arr["moder"])) AND !$user->admin)
showerror(_bterror, "<p><i>You are not permitted to post in this forum.</i></p>\n");
$body = trim($_POST["body"]);
if (!$body)
showerror(_bterror, "No body text.");
if (strlen($body) > $max_post_length)showerror(_bterror, "Post's are limited to $max_post_length characters.");
$userid = $user->id;
if ($newtopic) { //Create topic
$subject2 = $db->sql_escape(stripslashes($subject));
$subject = $db->sql_escape(stripslashes($subject));
$db->sql_query("INSERT INTO ".$db_prefix."_forum_topics (userid, subject, forumid) VALUES ('".$userid."', '".$subject."', '".$forumid."')") or forumsqlerr(__FILE__, __LINE__);
$topicid = $db->sql_nextid() or die("No topic ID returned");
$mesg = '/notice *[color='.getusercolor($user->group).']'.$user->name.'[/color] Posted Thread [url='.$siteurl.'/forums.php?action=viewtopic&topicid='.$topicid.']'.$subject2.'[/url]*';
if($shout_new_topic)$db->sql_query("INSERT INTO ".$db_prefix."_shouts (user, text, posted) VALUES ('".$user->id."', '".$mesg."', NOW());");
}else{
//Make sure topic exists and is unlocked
$res = $db->sql_query("SELECT * FROM ".$db_prefix."_forum_topics WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or die("Topic id n/a");
if ($arr["locked"] == 'yes' AND !checkaccess("modforum"))
showerror("Topic Locked", "Topic is loced you can not post to it");
//Get forum ID
$forumid = $arr["forumid"];
$topic_owner = $arr["user_id"];
}
//Insert the new post
$body = $db->sql_escape(stripslashes($body));
$db->sql_query("INSERT INTO ".$db_prefix."_forum_posts (topicid, userid, added, body) VALUES($topicid, $userid, NOW(), '".$body."')") or forumsqlerr(__FILE__, __LINE__);
$postid = $db->sql_nextid() or die("Post id n/a");
$mesg = '/notice *[color='.getusercolor($user->group).']'.$user->name.'[/color] replied to the thread [url='.$siteurl.'/forums.php?action=viewtopic&topicid='.$topicid.'&page=last#'.$postid.']'.$arr["subject"].'[/url]*';
if($shout_new_post && !$newtopic)$db->sql_query("INSERT INTO ".$db_prefix."_shouts (user, text, posted) VALUES ('".$user->id."', '".$mesg."', NOW());");
if(sizeof($attachment_data)){
$i=0;
foreach($attachment_data as $data => $val)
{
$attach_sql = array(
'post_msg_id' => $postid,
'topic_id' => $topicid,
'is_orphan' => 0,
'poster_id' => $user->id,
'attach_comment' => $attachment_data[$data]['attach_comment'],
);
$sql = 'UPDATE torrent_attachments SET ' . $db->sql_build_array('UPDATE', $attach_sql) . '
WHERE attach_id = ' . $attachment_data[$data]['attach_id'] . '
AND is_orphan = 1
AND poster_id = ' . $user->id;
$db->sql_query($sql);
$i++;
}
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET `topic_attachment` = topic_attachment + " . $i . " WHERE `id` = " . $topicid . " LIMIT 1");
$db->sql_query("UPDATE ".$db_prefix."_forum_posts SET `post_attachment` = post_attachment + " . $i . " WHERE `id` = " . $postid . " LIMIT 1");
}
if($allow_bookmarks)
{
$res = $db->sql_query("SELECT COUNT(user_id) FROM ".$db_prefix."_bookmarks WHERE topic_id=$topicid AND user_id <> ".$user->id ." LIMIT 1") or forumsqlerr(__FILE__, __LINE__);
$res2 = $db->sql_query("SELECT * FROM ".$db_prefix."_bookmarks WHERE topic_id=$topicid ") or forumsqlerr(__FILE__, __LINE__);
list ($count) = $db->sql_fetchrow($res);
$db->sql_freeresult($res);
if ($count > 0)
{
$arr = $db->sql_fetchrow($res2);
$booksend = str_replace(array("**username**","**owner**","**thread**","**posts**","**lastposter**","**formlink**","**removebook**"),array(username_is($arr['user_id']),username_is($topic_owner),get_topic_title($topicid),get_row_count("".$db_prefix."_forum_posts", " WHERE topicid='$topicid'"),username_is($userid),$siteurl."/forums.php?action=viewtopic&topicid=$topicid&page=last","[url=".$siteurl."/forums.php?action=viewtopic&do=removebook&topicid=$topicid&page=last]Here[/url]"),$bookmes);
$db->sql_query("INSERT INTO ".$db_prefix."_private_messages (sender, recipient, subject, text, sent) VALUES ('0','".$arr['user_id']."','New Forum Post','".addslashes($booksend)."',NOW());");
$db->sql_freeresult($res2);
}
if($book)$db->sql_query("INSERT INTO ".$db_prefix."_bookmarks (topic_id, user_id) VALUES ( ".$topicid.", ".$user->id.")");
}
//Update topic last post
update_topic_last_post($topicid);
//All done, redirect user to the post
$headerstr = "Location: $siteurl/forums.php?action=viewtopic&topicid=$topicid&page=last";
if ($newtopic)
header($headerstr);
else
header("$headerstr#$postid");
die;
}
///////////////////////////////////////////////////////// Action: VIEW TOPIC
if ($action == "viewtopic") {
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid))
die;
$userid = $user->id;
//------ Get topic info
$res = $db->sql_query("SELECT * FROM ".$db_prefix."_forum_topics WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or showerror("Forum error", "Topic not found");
$locked = ($arr["locked"] == 'yes');
$subject = stripslashes($arr["subject"]);
$sticky = $arr["sticky"] == "yes";
$forumid = $arr["forumid"];
$is_moder = get_forum_access_levels($forumid);
echo $is_moder["minclassread"];
if(!in_array($user->group,explode(" ", $is_moder["read"])))showerror(_bterror,"You do Not have access to this Section");
// Update Topic Views
$viewsq = $db->sql_query("SELECT views FROM ".$db_prefix."_forum_topics WHERE id=$topicid");
$viewsa = $db->sql_fetchrow($viewsq);
$views = $viewsa[0];
$new_views = $views+1;
$uviews = $db->sql_query("UPDATE ".$db_prefix."_forum_topics SET views = $new_views WHERE id=$topicid");
// End
//------ Get forum
$res = $db->sql_query("SELECT * FROM ".$db_prefix."_forum_forums WHERE id=$forumid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or showerror("Forum error", "Forum is empty");
$forum = stripslashes($arr["name"]);
//------ Get post count
$res = $db->sql_query("SELECT COUNT(*) FROM ".$db_prefix."_forum_posts WHERE topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
$postcount = $arr[0];
//------ Make page menu
$pagemenu = "<br><small>\n";
$perpage = $postsper_page;
$pages = floor($postcount / $perpage);
if ($pages * $perpage != $postcount)
++$pages;
if ($page == "last")
$page = $pages;
else {
if($page < 1)
$page = 1;
elseif ($page > $pages)
$page = $pages;
}
$offset = $page * $perpage - $perpage;
//
if ($page == 1)
$pagemenu .= "<b><< Prev</b>";
else
$pagemenu .= "<a href=forums.php?action=viewtopic&topicid=$topicid&page=" . ($page - 1) .
"><b><< Prev</b></a>";
//
$pagemenu .= " ";
for ($i = 1; $i <= $pages; ++$i) {
if ($i == $page)
$pagemenu .= "<b>$i</b>\n";
else
$pagemenu .= "<a href=forums.php?action=viewtopic&topicid=$topicid&page=$i><b>$i</b></a>\n";
}
//
$pagemenu .= " ";
if ($page == $pages)
$pagemenu .= "<b>Next >></b><br><br>\n";
else
$pagemenu .= "<a href=forums.php?action=viewtopic&topicid=$topicid&page=" . ($page + 1) .
"><b>Next >></b></a><br><br>\n";
//Get topic posts
$res = $db->sql_query("SELECT * FROM ".$db_prefix."_forum_posts WHERE topicid=$topicid ORDER BY id LIMIT $offset,$perpage") or forumsqlerr(__FILE__, __LINE__);
stdhead("View Topic: $subject");
forum_table("$forum > $subject", 'center');
forumheader("<a href=forums.php?action=viewforum&forumid=$forumid>$forum</a> > $subject");
print ("<table align=center cellpadding=0 cellspacing=5 width=100% border=0 ><tr><td>");
if (!$locked){
print ("<div align='right'><a href=forums.php?action=reply&topicid=$topicid><img src=" . $themedir . "$button_reply border=0></a></div>");
}else{
print ("<div align='right'><img src=" . $themedir . "button_locked.gif border=0 alt=Locked></div>");
}
print ("</td></tr></table>");
//------ Print table of posts
$pc = $db->sql_numrows($res);
$pn = 0;
$r = $db->sql_query("SELECT lastpostread FROM ".$db_prefix."_forum_readposts WHERE userid=" . $user->id . " AND topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
$a = $db->sql_fetchrow($r);
$lpr = $a[0];
if (!$lpr)
$db->sql_query("INSERT INTO ".$db_prefix."_forum_readposts (userid, topicid) VALUES($userid, $topicid)") or forumsqlerr(__FILE__, __LINE__);
while ($arr = $db->sql_fetchrow($res)) {
++$pn;
$post_attachment = $arr['post_attachment'];
$postid = $arr["id"];
$posterid = $arr["userid"];
$added = $arr["added"] . " GMT (" . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . " ago)";
//---- Get poster details
$res4 = $db->sql_query("SELECT COUNT(*) FROM ".$db_prefix."_forum_posts WHERE userid=$posterid") or forumsqlerr();
$arr33 = $db->sql_fetchrow($res4);
$forumposts = $arr33[0];
$res2 = $db->sql_query("SELECT * FROM ".$db_prefix."_users WHERE id=$posterid") or forumsqlerr(__FILE__, __LINE__);
$arr2 = $db->sql_fetchrow($res2);
$postername = $arr2["username"];
if($post_attachment >= 1)
{
$ata_box = '';
$sql_atta = 'SELECT `attach_id`, `real_filename`, `attach_comment`, `extension`, `filesize`, `download_count` FROM `torrent_attachments`'
. ' WHERE `post_msg_id` = \'' . $postid . '\' AND `poster_id` = \'' . $posterid . '\' LIMIT 0, 30 ';
$res_atta = $db->sql_query($sql_atta)or forumsqlerr();
while(list ($attach_id, $real_filename, $attach_comment, $extension, $filesize, $download_count) = $db->sql_fetchrow($res_atta)){
$ata_box .= "<dd> <dl class=\"file\">\n";
$ata_box .= "<dt><img src=\"images/upload_icons/" . $extension . ".gif\" alt=\"\" title=\"\" width=\"7\" height=\"10\"> <a class=\"postlink\" href=\"./file.php?id=" . $attach_id . "\">" . $real_filename . "</a></dt>\n";
$ata_box .= "<dd><em>" . $attach_comment . "</em></dd> <dd>(" . mksize($filesize) . ") ". (($download_count > 0)? $download_count ." Down loads" : "Not downloaded yet")."</dd>\n";
$ata_box .= "</dl>\n";
$ata_box .= "</dd>\n";
}
$db->sql_freeresult($res_atta);
}
if ($postername == "") {
$by = "Deluser";
$title = "Deleted Account";
$privacylevel = "strong";
$usersignature = " ";
$userdownloaded = "0";
$useruploaded = "0";
$avatar = "";
$nposts = "-";
$tposts = "-";
}else{
$avatar = "avatars/".htmlspecialchars($arr2["avatar"]);
$userdownloaded = mksize($arr2["downloaded"]);
$useruploaded = mksize($arr2["uploaded"]);
$privacylevel = $arr2["privacy"];
$usersignature = stripslashes(format_comment($arr2["signature"]));
if ($arr2["downloaded"] > 0) {
$userratio = number_format($arr2["uploaded"] / $arr2["downloaded"], 2);
}else
if ($arr2["uploaded"] > 0)
$userratio = "Inf.";
else
$userratio = "---";
if(!$arr2["country"]){
$usercountry = "unknown";
}else{
$res4 = $db->sql_query("SELECT name,flagpic FROM ".$db_prefix."_countries WHERE id=$arr2[country] LIMIT 1") or forumsqlerr();
$arr4 = $db->sql_fetchrow($res4);
$usercountry = $arr4["name"];
}
$title = strip_tags($arr2["title"]);
$donated = $arr2['donated'];
$by = "<a href=user.php?op=profile&id=$posterid><font color=\"".getusercolor(getlevel_name($posterid))."\">" . $postername . "</font></a>" . ($donated > 0 ? "<img src=".$siteurl."/images/donator.gif height=\"16\" width=\"16\" alt='Donated'>" : "") . "";
}
if (!$avatar)
$avatar = $siteurl ."/images/default_avatar.gif";
print("<a name=$postid>\n");
if ($pn == $pc) {
print("<a name=last>\n");
if ($postid > $lpr)
$db->sql_query("UPDATE ".$db_prefix."_forum_readposts SET lastpostread=$postid WHERE userid=$userid AND topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
}
//working here
print("<table align=center cellpadding=3 cellspacing=0 width=100% border=1 class=\"ftopictable1\"><tr><td width=150 align=center>$by<td with=100% align=left><small>Posted at $added </small></tr></table>");
print("<table align=center cellpadding=3 cellspacing=0 class=\"ftopictable2\" width=100% border=1>\n");
$body = format_comment($arr["body"], false, true);
parse_smiles($body);
if($CENSORWORDS) {//bad word censor
$query = "SELECT * FROM ".$db_prefix."_censor";
$result = $db->sql_query($query);
while ($row = $db->sql_fetchrow($result)) {
$body = str_replace($row['word'], $row['censor'], $body);
}
}//censor end
if (is_valid_id($arr['editedby'])) {
$res2 = $db->sql_query("SELECT username FROM ".$db_prefix."_users WHERE id=$arr[editedby]");
if ($db->sql_numrows($res2) == 1) {
$arr2 = $db->sql_fetchrow($res2);
//edited by comment out if needed
$body .= "<br><br><font size=1 class=small><i>Last edited by <a href=user.php?op=profile&id=$arr[editedby]><font color=\"".getusercolor(getlevel_name($arr['editedby']))."\">" . $arr2['username'] . "</font></a> on $arr[editedat]</i></font><br>\n";
$body .= "\n";
}
}
$quote = htmlspecialchars($arr["body"]);
$postcount1 = $db->sql_query("SELECT COUNT(".$db_prefix."_forum_posts.userid) FROM ".$db_prefix."_forum_posts WHERE id=$posterid") or forumsqlerr();
while($row = $db->sql_fetchrow($postcount1)) {
if ($privacylevel == "strong" && !$user->admin){//hide stats, but not from staff
$useruploaded = "---";
$userdownloaded = "---";
$userratio = "---";
$nposts = "-";
$tposts = "-";
}
print ("<tr valign=top><td width=150 align=left><center><i>$title</i></center><br><center><a href=user.php?op=profile&id=$posterid>".gen_avatar($posterid)."</a></center><br>Uploaded: $useruploaded<br>Downloaded: $userdownloaded<br>Posts: ".(($forumposts > 0)? "<a class=\"pocount\" title=\"View users Posts\" href=forums.php?action=search&search_id=".$posterid.">".$forumposts."</a>" : $posterid) ."<br><br>Ratio: $userratio<br>Location: $usercountry<br><br></td>");
print ("<td class=fcomment>$body<br>");
if($post_attachment >= 1){
echo "<br><br><br><br><dl class=\"attachbox\">\n";
echo "<dt>Attachments</dt>\n";
echo $ata_box;
echo "</dl><br clear=\"all\" />\n";
}
if (!$usersignature){
print("<br><br></td></tr>\n");
}else{
print("<br><br>---------------<br>$usersignature</td></tr>\n");
}
}
print("</table>\n");
print("<table align=center cellpadding=3 cellspacing=0 class=\"ftopictable3\" width=100% border=1 ><tr><td width=150 align=center><nobr> <a href=pm.php?op=send&to=$posterid><img src=".$themedir."$icon_pm border=0></a> </nobr><td with=100%>");
print ("<div style='float: left;'><a href=report.php?forumid=$topicid&forumpost=$postid><img src=".$themedir."$p_report border='0' alt='Report This Post'></a> <a href='javascript:scroll(0,0);'><img src=".$themedir."p_up.gif border='0' alt='Go to the top of the page'></a></div><div align=right>");
//define buttons and who can use them
if ($user->id == $posterid || $user->admin || in_array($user->group,explode(" ", $is_moder["write"]))){
print ("<a href='forums.php?action=editpost&postid=$postid'&topic=$topicid><img src=".$themedir."$p_edit border='0' ></a> ");
}
if ($user->admin || in_array($user->group,explode(" ", $is_moder["write"]))){
print ("<a href='forums.php?action=deletepost&postid=$postid&sure=0'><img src=".$themedir."$p_delete border='0' ></a> ");
}
if (!$locked){
print ("<a onclick=\"comment_smile('[quote=".htmlspecialchars(username_is($posterid))."]". str_replace(array("\r\n", "\n", "\r","'"),array('<br>','<br>','<br>','·'),$quote) ."[/quote]',Form.body)\"><img src=".$themedir."$p_quote border='0' ></a> ");
print ("<a href='forums.php?action=reply&topicid=$topicid'><img src=".$themedir."$p_reply border='0' ></a>");
}
print(" </div></td></tr></table>");
print("</p>\n");// post seperate·
}
//-------- end posts table ---------//
print($pagemenu);
//quick reply
if (!$locked || in_array($user->id,explode(" ", $is_moder["moder"]))){
print ("<table align=center cellpadding=3 cellspacing=0 style='border-collapse: collapse' bordercolor=646262 width=100% border=1 class = ftableback><TR><TD><BR><CENTER><B>POST REPLY</B></CENTER><BR>");
$newtopic = false;
print("<a name=\"bottom\"></a>");
print("<form name=Form method=post action=?action=post>\n");
if ($newtopic)
print("<input type=hidden name=forumid value=$id>\n");
else
print("<input type=hidden name=topicid value=$topicid>\n");
print("<center><table border=0 cellspacing=0 cellpadding=0>");
if ($newtopic)
print("<tr><td class=alt2>Subject</td><td class=alt1 align=left style='padding: 0px'><input type=text size=100 maxlength=$max_subject_length name=subject style='border: 0px; height: 19px'></td></tr>\n");
echo " <select id=fontselect
onchange=fontformat(Form,this.options[this.selectedIndex].value,'font',body)>
<option value=0>FONT</option>
<option value=arial><font face=\"arial\">Arial</font></option>
<option value=comic sans ms>Comic</option>
<option value=courier new>Courier New</option>
<option value=tahoma>Tahoma</option>
<option value=times new roman>Times New Roman</option>
<option value=verdana>Verdana</option>
</select>
<select id=sizeselect onchange=fontformat(Form,this.options[this.selectedIndex].value,'size',body)>
<option value=0>Size</option>
<option value=1>Thery Small</option>
<option value=2>Small</option>
<option value=3>Normal</option>
<option value=4>Large</option>
<option value=5>X-Large</option>
</select>
<select id=colorselect
onchange=fontformat(Form,this.options[this.selectedIndex].value,'color',body)>
<option value=0>COLOR</option>
<option value=skyblue style=color:skyblue>sky blue</option>
<option value=royalblue style=color:royalblue>royal blue</option>
<option value=blue style=color:blue>blue</option>
<option value=darkblue style=color:darkblue>dark-blue</option>
<option value=orange style=color:orange>orange</option>
<option value=orangered style=color:orangered>orange-red</option>
<option value=crimson style=color:crimson>crimson</option>
<option value=red style=color:red>red</option>
<option value=firebrick style=color:firebrick>firebrick</option>
<option value=darkred style=color:darkred>dark red</option>
<option value=green style=color:green>green</option>
<option value=limegreen style=color:limegreen>limegreen</option>
<option value=seagreen style=color:seagreen>sea-green</option>
<option value=deeppink style=color:deeppink>deeppink</option>
<option value=tomato style=color:tomato>tomato</option>
<option value=coral style=color:coral>coral</option>
<option value=purple style=color:purple>purple</option>
<option value=indigo style=color:indigo>indigo</option>
<option value=burlywood style=color:burlywood>burlywood</option>
<option value=sandybrown style=color:sandybrown>sandy brown</option>
<option value=sienna style=color:sienna>sienna</option>
<option value=chocolate style=color:chocolate>chocolate</option>
<option value=teal style=color:teal>teal</option>
<option value=silver style=color:silver>silver</option>
</select>
<br /><a href=bbcode.php target=\"_blank\">BBcode help</a><br /><br />";
print("<tr><td>");
quickbb();
quicktags();
?><script language=javascript>
function PopMoreSmiles(form,text) {
link='moresmiles.php?form='+form+'&text='+text;
newWin=window.open(link,'moresmile','height=500,width=600,resizable=no,scrollbars=yes');
if (window.focus) {
newWin.focus()
}
}</script><?php echo "<center><a href=\"javascript: PopMoreSmiles('Form','body')\">More Smiles</a></center>";
print("</td><td width=10> </td><td align=left><textarea name=body cols=60 rows=10></textarea></td>\n");
print("<td> </td></tr>\n");
print("<tr><td colspan=3 align=center><br>");
echo "<input name=\"book\" value=\"yes\" type=\"checkbox\">Notify me when a reply is posted<br />";
echo("<input type=image class=btn src=".$themedir."$button_reply border=0></td></tr>\n");
print("</table></form></center>\n");
//forum_table_close();
print ("</TD></TR></TABLE>");
}else{
print ("<CENTER><img src=".$themedir."button_locked.gif alt=Locked></CENTER>");
}
//end quick reply
if ($locked)
print("<p>This topic is locked; no new posts are allowed.</p>\n");
else {
$arr = get_forum_access_levels($forumid) or die;
if (!$arr["write"] == "0" AND !in_array($user->group,explode(" ", $arr["write"])))
print("<p><i>You are not permitted to post in this forum2.</i></p>\n");
else
$maypost = true;
}
//insert page numbers and quick jump
// insert_quick_jump_menu($forumid);
// MODERATOR OPTIONS
if ($user->admin OR in_array($user->group,explode(" ", $arr["moder"]))) {
forum_table_close();
forum_table("Moderator Options");
$res = $db->sql_query("SELECT id,name,minclasswrite FROM ".$db_prefix."_forum_forums ORDER BY name") or forumsqlerr(__FILE__, __LINE__);
print("<table border=0 cellspacing=0 cellpadding=0>\n");
print("<form method=post action=forums.php?action=renametopic>\n");
print("<input type=hidden name=topicid value=$topicid>\n");
print("<input type=hidden name=returnto value=".$HTTP_SERVER_VARS["REQUEST_URI"].">\n");
print("<tr><td class=embedded align=right>"._btf_renametopic."</td><td class=embedded><input type=text name=subject size=60 maxlength=$max_subject_length value=\"" . stripslashes(htmlspecialchars($subject)) . "\">\n");
print("<input type=submit value='Apply'></td></tr>");
print("</form>\n");
print("<form method=post action=forums.php?action=movetopic&topicid=$topicid>\n");
print("<tr><td class=embedded align=right>"._btf_movethread."</td><td class=embedded><select name=forumid>");
while ($arr = $db->sql_fetchrow($res))
if ($arr["id"] != $forumid && in_array($user->group,explode(" ", $arr["minclasswrite"])))
print("<option value=" . $arr["id"] . ">" . $arr["name"] . "\n");
print("</select> <input type=submit value="._bt_aply."></form></td></tr>\n");
print("</table>\n");
//
print("<table width=100%><tr><td align=center>\n");
if ($locked)
print("Locked: <a href=forums.php?action=unlocktopic&forumid=$forumid&topicid=$topicid&page=$page title='Unlock'><img src=". $themedir ."topic_unlock.gif border=0 alt=UnLock Topic></a>\n");
else
print("Locked: <a href=forums.php?action=locktopic&forumid=$forumid&topicid=$topicid&page=$page title='Lock'><img src=". $themedir ."topic_lock.gif border=0 alt=Lock Topic></a>\n");
print("Delete Entire Topic: <a href=forums.php?action=deletetopic&topicid=$topicid&sure=0 title='Delete'><img src=". $themedir ."$topic_delete border=0 alt=Delete Topic></a>\n");
if ($sticky)
print("Sticky: <a href=forums.php?action=unsetsticky&forumid=$forumid&topicid=$topicid&page=$page title='UnStick'><img src=". $themedir ."folder_sticky_new.gif border=0 alt=UnStick Topic></a>\n");
else
print("Sticky: <a href=forums.php?action=setsticky&forumid=$forumid&topicid=$topicid&page=$page title='Stick'><img src=". $themedir ."folder_sticky.gif border=0 alt=Stick Topic></a>\n");
print("</td></tr></table>\n");
//
}
forum_table_close();
stdfoot();
include'footer.php';
die;
}
/////////////////////////////////////////////////////////Action: Remove bookmark
if (isset($do) AND $do == "removebook") {
if(!isset($topicid) OR $topicid == "" OR !is_numeric($topicid))showerror("Delete BookMark","No Topic is set please check your link");
if (!isset($sure) OR !$sure == "1")
showerror("Delete BookMark", "Sanity check: You are about to Remove your bookmark for ".get_topic_title($topicid).". Click <a href=forums.php?do=removebook&topicid=$topicid&sure=1>here</a> if you are sure.");
$db->sql_query("DELETE FROM ".$db_prefix."_bookmarks WHERE topic_id=$topicid AND user_id=".$user->id."") or forumsqlerr(__FILE__, __LINE__);
header("Location: $siteurl/forums.php");
die;
}
///////////////////////////////////////////////////////// Action: REPLY
if ($action == "reply") {
$topicid = request_var('topicid', '');
if (!is_valid_id($topicid))
die;
$body = request_var('body', '');
stdhead("Post reply");
forum_table("Post reply");
insert_compose_frame($topicid, false,$body);
forum_table_close();
stdfoot();
include'footer.php';
die;
}
///////////////////////////////////////////////////////// Action: MOVE TOPIC
if ($action == "movetopic") {
$forumid = $_POST["forumid"];
$topicid = $_GET["topicid"];
if (!is_valid_id($forumid) || !is_valid_id($topicid) || !$user->admin)
die;
// Make sure topic and forum is valid
$res = @$db->sql_query("SELECT minclasswrite FROM ".$db_prefix."_forum_forums WHERE id=$forumid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) != 1)
showerror(_bterror, "Forum not found.");
$arr = $db->sql_fetchrow($res);
if (10 < $arr[0])
die;
$res = @$db->sql_query("SELECT subject,forumid FROM ".$db_prefix."_forum_topics WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) != 1)
showerror(_bterror, "Topic not found.");
$arr = $db->sql_fetchrow($res);
if ($arr["forumid"] != $forumid)
@$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET forumid=$forumid, moved='yes' WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
// Redirect to forum page
header("Location: $siteurl/forums.php?action=viewforum&forumid=$forumid");
die;
}
///////////////////////////////////////////////////////// Action: DELETE TOPIC
if ($action == "deletetopic") {
$topicid = $_GET["topicid"];
if (!is_valid_id($topicid) || !$user->admin)
die;
$sure = $_GET["sure"];
if (!$sure == "1")
showerror("Delete topic", "Sanity check: You are about to delete a topic. Click <a href=forums.php?action=deletetopic&topicid=$topicid&sure=1>here</a> if you are sure.");
$db->sql_query("DELETE FROM ".$db_prefix."_forum_topics WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
$db->sql_query("DELETE FROM ".$db_prefix."_forum_posts WHERE topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
$db->sql_query("DELETE FROM ".$db_prefix."_bookmarks WHERE topic_id=$topicid") or forumsqlerr(__FILE__, __LINE__);
header("Location: $SITEURL/forums.php");
die;
}
///////////////////////////////////////////////////////// Action: EDIT TOPIC
if ($action == "editpost") {
//$postid = $HTTP_GET_VARS["postid"];
if (!is_valid_id($postid))
die;
$res = $db->sql_query("SELECT * FROM ".$db_prefix."_forum_posts WHERE id=$postid") or forumsqlerr(__FILE__, __LINE__);
if ($db->sql_numrows($res) != 1)
showerror(_bterror, "No post with ID $postid.");
$arr = $db->sql_fetchrow($res);
if ($user->id != $arr["userid"] && !$user->admin)
showerror(_bterror, "Denied!");
if ($take == '1') {
//$body = $HTTP_POST_VARS['body'];
if ($body == "")
showerror(_bterror, "Body cannot be empty!");
$body = $db->sql_escape(stripslashes($body));
//$editedat = $db->sql_escape(get_date_time());
$db->sql_query("UPDATE ".$db_prefix."_forum_posts SET body='".$body."', editedat=NOW(), editedby=".$user->id." WHERE id='".$postid."'") or forumsqlerr(__FILE__, __LINE__);
//$returnto = $returnto"];$topicid
if ($returnto != ""){
header("Location: $returnto");
die;
}
else
showerror("Success", "Post was edited successfully.");
}
stdhead();
forum_table("Edit Post");
print("<form name=Form method=post action=?action=editpost&postid=$postid>\n");
print("<input type=hidden name=take value=\"1\">\n");
print("<input type=hidden name=returnto value=\"$siteurl/forums.php?action=viewtopic&topicid=" . $arr["topicid"] . "\">\n");
print("<center><table border=0 cellspacing=0 cellpadding=5>\n");
print("<tr><td>\n");
quicktags();
print("</td><td style='padding: 0px'><textarea name=body cols=50 rows=20 >" . stripslashes(htmlspecialchars($arr["body"])) . "</textarea></td></tr>\n");
print("<tr><td align=center colspan=2><input type=submit value='Submit Changes' class=btn></td></tr>\n");
print("</table></center>\n");
print("</form>\n");
forum_table_close();
stdfoot();
include'footer.php';
die;
}
///////////////////////////////////////////////////////// Action: DELETE POST
if ($action == "deletepost") {
$postid = $_GET["postid"];
$sure = $_GET["sure"];
$res = $db->sql_query("SELECT userid FROM ".$db_prefix."_forum_posts WHERE id=$postid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
if ($arr['userid'] != $user->id AND !checkaccess("modforum"))showerror(_bterror, "Can't delete post access denied.\n");
if(!is_valid_id($postid))showerror(_bterror, _btiderror);
//SURE?
if ($sure == "0") {
showerror("Delete post", "Sanity check: You are about to delete a post. Click <a href=forums.php?action=deletepost&postid=$postid&sure=1>here</a> if you are sure.");
}
//------- Get topic id
$res = $db->sql_query("SELECT topicid FROM ".$db_prefix."_forum_posts WHERE id=$postid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or showerror(_bterror, "Post not found");
$topicid = $arr[0];
$res = $db->sql_query("SELECT userid FROM ".$db_prefix."_forum_posts WHERE id=$postid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
if (!$arr['userid'] == $user->id)
showerror(_bterror, "Can't delete post; it is the only post of the topic. You should <a href=forums.php?action=deletetopic&topicid=$topicid&sure=1>delete the topic</a> instead.\n");
//------- We can not delete the post if it is the only one of the topic
$res = $db->sql_query("SELECT COUNT(*) FROM ".$db_prefix."_forum_posts WHERE topicid=$topicid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
if ($arr[0] < 2)
showerror(_bterror, "Can't delete post; it is the only post of the topic. You should <a href=forums.php?action=deletetopic&topicid=$topicid&sure=1>delete the topic</a> instead.\n");
//------- Delete post
$db->sql_query("DELETE FROM ".$db_prefix."_forum_posts WHERE id=$postid") or forumsqlerr(__FILE__, __LINE__);
//------- Update topic
update_topic_last_post($topicid);
header("Location: $SITEURL/forums.php?action=viewtopic&topicid=$topicid");
die;
}
///////////////////////////////////////////////////////// Action: LOCK TOPIC
if ($action == "locktopic") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || !$user->admin)
die;
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET locked='yes' WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
header("Location: $siteurl/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: UNLOCK TOPIC
if ($action == "unlocktopic") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || !$user->admin)
die;
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET locked='no' WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
header("Location: $siteurl/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: STICK TOPIC
if ($action == "setsticky") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
$error = array();
$moder = get_forum_access_levels($forumid);
if (!is_valid_id($topicid))$error[] = "No Forum ID";
if(!in_array($user->id,explode(" ", $moder["moder"]))){
if(!$user->admin)
$error[] = "You do not have Mod rights here";
}
if (count($error) > 0)
bterror($error,_btupload);
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET sticky='yes' WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
header("Location: $siteurl/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: UNSTICK TOPIC
if ($action == "unsetsticky") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
$moder = get_forum_access_levels($forumid);
$error = array();
if (!is_valid_id($topicid))$error[] = "No Forum ID";
if(!in_array($user->id,explode(" ", $moder["moder"]))){
if(!$user->admin)
$error[] = "You do not have Mod rights here sample1";
}
if (count($error) > 0)
bterror($error,_btupload);
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET sticky='no' WHERE id=$topicid") or forumsqlerr(__FILE__, __LINE__);
header("Location: $siteurl/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: RENAME TOPIC
if ($action == 'renametopic') {
if (!$user->admin)
die;
$topicid = $HTTP_POST_VARS['topicid'];
if (!is_valid_id($topicid))
die;
$subject = $HTTP_POST_VARS['subject'];
if ($subject == '')
showerror('Error', 'You must enter a new title!');
$subject = $db->sql_escape(stripslashes($subject));
$db->sql_query("UPDATE ".$db_prefix."_forum_topics SET subject='$subject' WHERE id=$topicid") or forumsqlerr();
$returnto = $HTTP_POST_VARS['returnto'];
if ($returnto)
header("Location: $returnto");
die;
}
///////////////////////////////////////////////////////// Action: Watch FORUM
if ($action == "watchforum") {
$forumid = $_GET["forumid"];
if (!is_valid_id($forumid))
die;
$res = $db->sql_query("SELECT name, minclassread FROM ".$db_prefix."_forum_forums WHERE id=$forumid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or die;
$can_read = explode(" ", $arr["minclassread"]);
$forumname = $arr["name"];
if (!$arr["minclassread"] == "0" AND !in_array($user->group,$can_read))
die("Not permitted");
stdhead("Forum : $forumname");
$sql = "INSERT INTO `".$db_prefix."_forums_watch` (`forum_id`, `user_id`, `notify_status`) VALUES ('" . $forumid . "', '" . $user->id . "', '1');";
$db->sql_query($sql);
echo "<meta http-equiv=\"refresh\" content=\"5;url=./forums.php?action=viewforum&forumid=" . $forumid."\">";
OpenMessTable('Information');
echo 'You have subscribed to be notified of new posts in this forum ' . $forumname . '.<br>';
echo '<a href=forums.php?action=viewforum&forumid=' . $forumid . '>Return to the forum last visited</a>';
CloseMessTable();
insert_quick_jump_menu($forumid);
forum_table_close();
stdfoot();
include'footer.php';
die;
}
///////////////////////////////////////////////////////// Action: VIEW FORUM
if ($action == "viewforum") {
$forumid = $_GET["forumid"];
if (!is_valid_id($forumid))
die;
$page = $_GET["page"];
$userid = $user->id;
//------ Get forum name
$res = $db->sql_query("SELECT name, minclassread FROM ".$db_prefix."_forum_forums WHERE id=$forumid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res) or die;
$can_read = explode(" ", $arr["minclassread"]);
$forumname = $arr["name"];
if (!$arr["minclassread"] == "0" AND !in_array($user->group,$can_read))
die("Not permitted");
//------ Get topic count
$perpage = $topics_per_page;
$res = $db->sql_query("SELECT COUNT(*) FROM ".$db_prefix."_forum_topics WHERE forumid=$forumid") or forumsqlerr(__FILE__, __LINE__);
$arr = $db->sql_fetchrow($res);
$num = $arr[0];
if ($page == 0)
$page = 1;
$first = ($page * $perpage) - $perpage + 1;
$last = $first + $perpage - 1;
if ($last > $num)
$last = $num;
$pages = floor($num / $perpage);
if ($perpage * $pages < $num)
++$pages;
//------ Build menu
$menu = "<p align=center><b>\n";
$lastspace = false;
for ($i = 1; $i <= $pages; ++$i) {
if ($i == $page)
$menu .= "<font class=gray>$i</font>\n";
elseif ($i > 3 && ($i < $pages - 2) && ($page - $i > 3 || $i - $page > 3)) {
if ($lastspace)
continue;
$menu .= "... \n";
$lastspace = true;
}
else {
$menu .= "<a href=forums.php?action=viewforum&forumid=$forumid&page=$i>$i</a>\n";
$lastspace = false;
}
if ($i < $pages)
$menu .= "</b>|<b>\n";
}
$menu .= "<br />\n";
if ($page == 1)
$menu .= "<font class=gray><< Prev</font>";
else
$menu .= "<a href=forums.php?action=viewforum&forumid=$forumid&page=" . ($page - 1) . "><< Prev</a>";
$menu .= " ";