-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php-func-forum_lib.php
More file actions
1340 lines (1029 loc) · 42.1 KB
/
functions.php-func-forum_lib.php
File metadata and controls
1340 lines (1029 loc) · 42.1 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
function pruefe_leserechte($th_id)
{
// Prüft anhand der th_id, ob der User im Forum lesen darf
global $u_level;
$query = "SELECT th_fo_id FROM thema WHERE th_id = " . intval($th_id);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
$fo_id = $fo['th_fo_id'];
$query = "SELECT fo_admin FROM forum WHERE fo_id = '$fo_id'";
$result = mysql_query($query);
list($admin_forum) = mysql_fetch_array($result);
$leserechte = false;
if ($u_level == "G")
if ($admin_forum == 0 || (($admin_forum & 8) == 8))
$leserechte = true;
if ($u_level == "U" || $u_level == "A" || $u_level == "M"
|| $u_level == "Z")
if ($admin_forum == 0 || (($admin_forum & 2) == 2))
$leserechte = true;
if ($u_level == "S" || $u_level == "C")
$leserechte = true;
return ($leserechte);
}
function hole_themen_id_anhand_posting_id($po_id)
{
// Prüft anhand der po_id ob gesperrt ist
$query = "SELECT po_th_id FROM posting WHERE po_id = " . intval($po_id);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
return ($fo['po_th_id']);
}
function pruefe_schreibrechte($th_id)
{
// Prüft anhand der th_id, ob der User ins Forum schreiben darf
global $u_level;
$query = "SELECT th_fo_id FROM thema WHERE th_id = " . intval($th_id);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
$fo_id = $fo['th_fo_id'];
$query = "SELECT fo_admin FROM forum WHERE fo_id = '$fo_id'";
$result = mysql_query($query);
list($admin_forum) = mysql_fetch_array($result);
$schreibrechte = false;
if ($u_level == "G")
if ((($admin_forum & 16) == 16))
$schreibrechte = true;
if ($u_level == "U" || $u_level == "A" || $u_level == "M"
|| $u_level == "Z")
if ($admin_forum == 0 || (($admin_forum & 4) == 4))
$schreibrechte = true;
if ($u_level == "S" || $u_level == "C")
$schreibrechte = true;
return ($schreibrechte);
}
function ist_thread_gesperrt($thread)
{
global $forum_thread_sperren;
// Prüft anhand der thread auf den man antworten will, gesperrt ist
$query = "SELECT po_threadts, po_ts, po_threadgesperrt FROM posting WHERE po_id = " . intval($thread);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
$threadgesperrt = false;
if ($fo['po_threadgesperrt'] == 'Y')
$threadgesperrt = true;
if ($forum_thread_sperren > 0) {
$abwann = mktime(0, 0, 0, date('m') - $forum_thread_sperren,
date('d') + 1, date('Y'));
// Alte Beiträge vor 4.12.2006 (ab hier erst protokoll des po_threadts)
if ($fo['po_threadts'] == 0) {
if ($fo['po_ts'] <= $abwann)
$threadgesperrt = true;
}
// Alle Beiträge nach/mit 4.12.2006
else {
if ($fo['po_threadts'] <= $abwann)
$threadgesperrt = true;
}
}
return ($threadgesperrt);
}
function ist_posting_gesperrt($po_id)
{
// Prüft anhand der po_id ob gesperrt ist
$query = "SELECT po_gesperrt FROM posting WHERE po_id = " . intval($po_id);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
$postinggesperrt = false;
if ($fo['po_gesperrt'] == 'Y')
$postinggesperrt = true;
return ($postinggesperrt);
}
function sperre_posting($po_id)
{
$query = "SELECT po_gesperrt FROM posting WHERE po_id = " . intval($po_id);
$result = mysql_query($query);
$fo = mysql_fetch_array($result);
if (ist_posting_gesperrt($po_id)) {
// Posting entsperren
$query = "UPDATE posting SET po_gesperrt = 'N' WHERE po_id = " . intval($po_id);
$result = mysql_query($query);
} else {
// Posting sperren
$query = "UPDATE posting SET po_gesperrt = 'Y' WHERE po_id = " . intval($po_id);
$result = mysql_query($query);
}
}
//User verlaesst Raum und geht ins Forum
//Austrittstext im Raum erzeugen, o_who auf 2 und o_raum auf -1 (community) setzen
function gehe_forum($u_id, $u_nick, $o_id, $o_raum)
{
global $conn, $t;
//Austrittstext im alten raum erzeugen
verlasse_chat($u_id, $u_nick, $o_raum);
system_msg("", 0, $u_id, "",
str_replace("%u_nick%", $u_nick, $t['betrete_forum1']));
//Daten in online-tabelle richten
$f['o_raum'] = -1; //-1 allgemein fuer community
$f['o_who'] = "2"; //2 -> Forum
schreibe_db("online", $f, $o_id, "o_id");
}
//Gelesene Postings des Users einlesen
function lese_gelesene_postings($u_id)
{
global $conn, $u_gelesene;
$sql = "select u_gelesene_postings from user
where u_id = $u_id";
$query = mysql_query($sql, $conn);
if (mysql_num_rows($query) > 0)
$gelesene = mysql_result($query, 0, "u_gelesene_postings");
$u_gelesene = unserialize($gelesene);
@mysql_free_result($query);
}
// markiert ein komplettes Thema als gelesen
function thema_alles_gelesen($th_id, $u_id)
{
global $conn, $u_gelesene;
$query = "SELECT po_id FROM posting WHERE po_th_id = " . intval($th_id);
$result = mysql_query($query);
if ($result && mysql_numrows($result) > 0) {
if (!$u_gelesene[$th_id])
$u_gelesene[$th_id][0] = array();
while ($a = mysql_fetch_array($result)) {
array_push($u_gelesene[$th_id], $a['po_id']);
//wenn schon gelesen, dann wieder raus
}
$u_gelesene[$th_id] = array_unique($u_gelesene[$th_id]);
$gelesene = serialize($u_gelesene);
$sql = "update user set u_gelesene_postings = '$gelesene' where u_id = $u_id";
mysql_query($sql, $conn);
}
}
// markiert einen Thread als gelesen
function thread_alles_gelesen($th_id, $thread_id, $u_id)
{
global $conn, $u_gelesene;
$query = "SELECT po_threadorder FROM posting WHERE po_id = " . intval($thread_id);
$result = mysql_query($query);
if ($result && mysql_numrows($result) == 1) {
if (!$u_gelesene[$th_id])
$u_gelesene[$th_id][0] = array();
// alle Postings sind im Vater in der Threadorder, dieses array, an die gelesenen anhängen
$a = mysql_fetch_array($result);
$b = explode(",", $a['po_threadorder']);
for ($i = 0; $i < count($b); $i++) {
array_push($u_gelesene[$th_id], $b[$i]);
}
//wenn schon gelesen, dann wieder raus
$u_gelesene[$th_id] = array_unique($u_gelesene[$th_id]);
// und zurückschreiben
$gelesene = serialize($u_gelesene);
$sql = "update user set u_gelesene_postings = '$gelesene' where u_id = $u_id";
mysql_query($sql, $conn);
}
}
//markiert ein posting fuer einen User als gelesen
function markiere_als_gelesen($po_id, $u_id, $th_id)
{
global $conn, $u_gelesene;
if (!$u_gelesene[$th_id])
$u_gelesene[$th_id][0] = $po_id;
else {
array_push($u_gelesene[$th_id], $po_id);
//wenn schon gelesen, dann wieder raus
$u_gelesene[$th_id] = array_unique($u_gelesene[$th_id]);
}
$gelesene = serialize($u_gelesene);
//schreiben nicht ueber schreibe_db, da sonst
//online-tabelle neu geschrieben wird -> hier unnoetig
//und unperformant
$sql = "update user set u_gelesene_postings = '$gelesene' where u_id = $u_id";
mysql_query($sql, $conn);
}
//gibt die ungelesenen Postings in einem Thema/Thread zurueck
//je nachdem, ob $arr_postings sich auf Thema oder Thread bezieht
function anzahl_ungelesene(&$arr_postings, $th_id)
{
global $u_gelesene;
//kein Posting in Gruppe --> keine ungelesenen
if (count($arr_postings) == 0)
return 0;
//kein Posting gelesen --> alle ungelesen
if (!$u_gelesene[$th_id])
return count($arr_postings);
// anzahl unterschied zwischen postings im Thread/thema und den gelesenen
//postings des users zurueckgeben
return count(array_diff($arr_postings, $u_gelesene[$th_id]));
}
function anzahl_ungelesene2(&$arr_postings, $th_id)
{
global $u_gelesene;
//kein Posting in Gruppe --> keine ungelesenen
if (count($arr_postings) == 0)
return 0;
//kein Posting gelesen --> alle ungelesen
if (!$u_gelesene[$th_id])
return count($arr_postings);
// anzahl unterschied zwischen postings im Thread/thema und den gelesenen
//postings des users zurueckgeben
$sql = "select po_id, po_u_id, po_threadorder
from posting
where po_vater_id = 0
and po_th_id = " . intval($th_id) . "
order by po_ts desc";
$query = mysql_query($sql);
$ungelesene = 0;
while ($posting = mysql_fetch_array($query, MYSQL_ASSOC)) {
if ($posting[po_threadorder] == "0") {
$anzreplys = 0;
$arr_postings = array($posting[po_id]);
} else {
$arr_postings = explode(",", $posting[po_threadorder]);
$anzreplys = count($arr_postings);
//Erstes Posting mit beruecksichtigen
$arr_postings[] = $posting[po_id];
}
$ungelesene += anzahl_ungelesene($arr_postings, $th_id);
}
return $ungelesene;
}
function anzahl_ungelesene3(&$arr_postings, $th_id)
{
global $u_gelesene;
//kein Posting in Gruppe --> keine ungelesenen
if (count($arr_postings) == 0)
return 0;
//kein Posting gelesen --> alle ungelesen
if (!$u_gelesene[$th_id])
return count($arr_postings);
// anzahl unterschied zwischen postings im Thread/thema und den gelesenen
//postings des users zurueckgeben
$arr = array_diff($arr_postings, $u_gelesene[$th_id]);
$diff = count($arr);
reset($arr);
while (list($key, $value) = each($arr)) {
# echo "Key: $key; Value: $value<br>\n";
$query = "SELECT * FROM posting WHERE po_id = " . intval($value);
$result = mysql_query($query);
$num = mysql_numrows($result);
#if ($num == 1) print "<font color=white>$th_id: ".$query." $num</font><BR>";
if ($num == 1) {
#checke_posting($value);
}
if ($num == 0)
$diff--;
}
return $diff;
}
//Prüft Usereingaben auf Vollständigkeit
// mode --> forum, thema, posting
function check_input($mode)
{
global $t;
$missing = "";
if ($mode == "forum") {
global $fo_name;
if (!$fo_name)
$missing = $t['missing_foname'];
} else if ($mode == "thema") {
global $th_name, $th_desc;
if (!$th_name)
$missing .= $t['missing_thname'];
if (!$th_desc)
$missing .= $t['missing_thdesc'];
} else if ($mode == "posting") {
global $po_titel, $po_text;
if (strlen(trim($po_titel)) <= 0)
$missing .= $t['missing_potitel'];
if (strlen(trim($po_text)) <= 0)
$missing .= $t['missing_potext'];
}
return $missing;
}
//neues Forum in Datenbank schreiben
function schreibe_forum()
{
global $fo_id, $fo_name, $fo_admin, $conn;
global $fo_gast, $fo_user;
$f['fo_name'] = $fo_name;
$f['fo_admin'] = $fo_gast + $fo_user + 1;
//groesste Order holen
$sql = "select max(fo_order) as maxorder from forum";
$query = mysql_query($sql, $conn);
$maxorder = mysql_result($query, 0, "maxorder");
@mysql_free_result($query);
if ($maxorder)
$maxorder++;
else $maxorder = 1;
$f['fo_order'] = $maxorder;
$fo_id = schreibe_db("forum", $f, "", "fo_id");
//Damit leeres Forum angezeigt wird, dummy-eintrag in Thema-Tabelle
$ff["th_fo_id"] = $fo_id;
$ff["th_name"] = "dummy-thema";
$ff["th_anzthreads"] = 0;
$ff["th_anzreplys"] = 0;
$ff["th_order"] = 0;
schreibe_db("thema", $ff, "", "th_id");
}
//Forum aendern
function aendere_forum()
{
global $fo_id, $fo_name, $fo_admin, $conn;
global $fo_gast, $fo_user;
$f['fo_name'] = $fo_name;
$f['fo_admin'] = $fo_gast + $fo_user + 1;
schreibe_db("forum", $f, $fo_id, "fo_id");
}
//Schiebt Forum in Darstellungsreihenfolge nach oben
function forum_up($fo_id, $fo_order)
{
global $conn;
if (!$fo_id)
return;
//forum über aktuellem Forum holen
$sql = "select fo_id, fo_order as prev_order
from forum
where fo_order < " . intval($fo_order) . "
order by fo_order desc
limit 1";
$query = mysql_query($sql, $conn);
$numrows = mysql_num_rows($query);
//ist Forum oberstes Forum?
if ($numrows == 1) {
$prev_order = mysql_result($query, 0, "prev_order");
$prev_id = mysql_result($query, 0, "fo_id");
@mysql_free_result($query);
//nein -> orders vertauschen
$f['fo_order'] = $fo_order;
schreibe_db("forum", $f, $prev_id, "fo_id");
$f['fo_order'] = $prev_order;
schreibe_db("forum", $f, $fo_id, "fo_id");
} else {
@mysql_free_result($query);
}
}
//Schiebt Forum in Darstellungsreihenfolge nach oben
function forum_down($fo_id, $fo_order)
{
global $conn;
if (!$fo_id)
return;
//forum über aktuellem Forum holen
$sql = "select fo_id, fo_order as next_order
from forum
where fo_order > " . intval($fo_order) . "
order by fo_order
limit 1";
$query = mysql_query($sql, $conn);
$numrows = mysql_num_rows($query);
//ist Thema schon letztes Thema?
if ($numrows == 1) {
$next_order = mysql_result($query, 0, "next_order");
$next_id = mysql_result($query, 0, "fo_id");
@mysql_free_result($query);
//nein -> orders vertauschen
$f['fo_order'] = $fo_order;
schreibe_db("forum", $f, $next_id, "fo_id");
$f['fo_order'] = $next_order;
schreibe_db("forum", $f, $fo_id, "fo_id");
} else {
@mysql_free_result($query);
}
}
//Komplettes Forum mit allen Themen und postings loeschen
function loesche_forum($fo_id)
{
global $conn;
if (!$fo_id)
return;
$fo_id = intval($fo_id);
$sql = "select fo_name from forum where fo_id=$fo_id";
$query = mysql_query($sql, $conn);
$fo_name = mysql_result($query, 0, "fo_name");
@mysql_free_result($query);
$sql = "select th_id from thema where th_fo_id=$fo_id";
$query = mysql_query($sql, $conn);
while ($thema = mysql_fetch_array($query, MYSQL_ASSOC)) {
$delsql = "delete from posting where po_th_id=$thema[th_id]";
mysql_query($delsql, $conn);
}
@mysql_free_result($query);
$sql = "delete from thema where th_fo_id=$fo_id";
mysql_query($sql, $conn);
$sql = "delete from forum where fo_id=$fo_id";
mysql_query($sql, $conn);
echo "<b>Forum $fo_name komplett gelöscht!</b><br>";
}
//Thema in Datenbank schreiben
function schreibe_thema($th_id = 0)
{
global $fo_id, $th_name, $th_desc, $conn, $th_forumwechsel, $th_verschiebe_nach;
//neues Thema
if ($th_id == 0) {
$f['th_fo_id'] = $fo_id;
$f['th_name'] = $th_name;
$f['th_desc'] = $th_desc;
$f['th_anzthreads'] = 0;
$f['th_anzreplys'] = 0;
//groesste Order holen
$sql = "select max(th_order) as maxorder from thema where th_fo_id=" . intval($fo_id);
$query = mysql_query($sql, $conn);
$maxorder = mysql_result($query, 0, "maxorder");
@mysql_free_result($query);
if ($maxorder)
$maxorder++;
else $maxorder = 1;
$f['th_order'] = $maxorder;
$th_id = schreibe_db("thema", $f, "", "th_id");
} else { //Thema editieren
if ($th_forumwechsel == "Y"
&& preg_match("/^([0-9])+$/i", $th_verschiebe_nach)) {
//groesste Order holen
$sql = "select max(th_order) as maxorder from thema where th_fo_id=" . intval($th_verschiebe_nach);
$query = mysql_query($sql, $conn);
$maxorder = mysql_result($query, 0, "maxorder");
@mysql_free_result($query);
if ($maxorder)
$maxorder++;
else $maxorder = 1;
$f['th_fo_id'] = $th_verschiebe_nach;
$f['th_order'] = $maxorder;
}
$f['th_name'] = $th_name;
$f['th_desc'] = $th_desc;
schreibe_db("thema", $f, $th_id, "th_id");
}
}
//Schiebt Thema in Darstellungsreihenfolge nach oben
function thema_up($th_id, $th_order, $fo_id)
{
global $conn;
if (!$th_id || !$fo_id)
return;
//thema über aktuellem Thema holen
$sql = "select th_id, th_order as prev_order
from thema
where th_fo_id = " . intval($fo_id) . "
and th_order < " . intval($th_order) . "
order by th_order desc
limit 1";
$query = mysql_query($sql, $conn);
$prev_order = mysql_result($query, 0, "prev_order");
$prev_id = mysql_result($query, 0, "th_id");
@mysql_free_result($query);
//ist Thema oberstes Thema?
if ($prev_order > 0) {
//nein -> orders vertauschen
$f['th_order'] = $th_order;
schreibe_db("thema", $f, $prev_id, "th_id");
$f['th_order'] = $prev_order;
schreibe_db("thema", $f, $th_id, "th_id");
}
}
//Schiebt Thema in Darstellungsreihenfolge nach unten
function thema_down($th_id, $th_order, $fo_id)
{
global $conn;
if (!$th_id || !$fo_id)
return;
//thema unter aktuellem Thema holen
$sql = "select th_id, th_order as next_order
from thema
where th_fo_id = " . intval($fo_id) . "
and th_order > " . intval($th_order) . "
order by th_order
limit 1";
$query = mysql_query($sql, $conn);
$numrows = mysql_num_rows($query);
//ist Thema schon letztes Thema?
if ($numrows == 1) {
$next_order = mysql_result($query, 0, "next_order");
$next_id = mysql_result($query, 0, "th_id");
@mysql_free_result($query);
//nein -> orders vertauschen
$f['th_order'] = $th_order;
schreibe_db("thema", $f, $next_id, "th_id");
$f['th_order'] = $next_order;
schreibe_db("thema", $f, $th_id, "th_id");
} else {
@mysql_free_result($query);
}
}
//Komplettes Thema mit allen Postings loeschen
function loesche_thema($th_id)
{
global $conn;
if (!$th_id)
return;
$th_id = intval($th_id);
$sql = "select th_name from thema where th_id=$th_id";
$query = mysql_query($sql, $conn);
$th_name = @mysql_result($query, 0, "th_name");
@mysql_free_result($query);
$delsql = "delete from posting where po_th_id=$th_id";
mysql_query($delsql, $conn);
$sql = "delete from thema where th_id=$th_id";
mysql_query($sql, $conn);
echo "<b>Thema $th_name komplett gelöscht!</b><br>";
}
//schreibt neues/editiertes Posting in Datenbank
function schreibe_posting()
{
global $conn, $th_id, $po_vater_id, $u_id, $po_id, $po_tiefe, $u_nick;
global $po_titel, $po_text, $thread, $mode, $user_id, $autor;
global $po_topposting, $po_threadgesperrt, $forum_admin, $t, $forum_aenderungsanzeige;
if ($mode == "edit") {
//muss autor neu gesetzt werden?
if ($forum_admin && $autor) {
$autor = intval($autor);
if (!preg_match("/[a-z]|[A-Z]/", $autor))
$sql = "select u_id from user where u_id=$autor";
else $sql = "select u_id from user where u_nick='$autor'";
$query = mysql_query($sql, $conn);
if (mysql_num_rows($query) > 0)
$u_id_neu = mysql_result($query, 0, "u_id");
if (!$u_id_neu)
echo "<b>Ein User mit dem Nick/der ID $autor existiert nicht!</b>";
else if ($u_id_neu != $user_id)
$f['po_u_id'] = $u_id_neu;
}
if ($forum_admin) {
$f['po_topposting'] = $po_topposting;
$f['po_threadgesperrt'] = $po_threadgesperrt;
}
$f['po_titel'] = htmlspecialchars($po_titel);
$f['po_text'] = htmlspecialchars(erzeuge_umbruch($po_text, 80));
if ($forum_aenderungsanzeige == "1") {
$append = $t['letzte_aenderung'];
$append = str_replace("%datum%", date("d.m.Y"), $append);
$append = str_replace("%uhrzeit%", date("H:i"), $append);
$append = str_replace("%user%", $u_nick, $append);
$f['po_text'] .= $append;
}
schreibe_db("posting", $f, $po_id, "po_id");
} else { //neues Posting
$f['po_th_id'] = $th_id;
$f['po_u_id'] = $u_id;
$f['po_vater_id'] = $po_vater_id;
$f['po_tiefe'] = $po_tiefe;
$f['po_titel'] = htmlspecialchars($po_titel);
$f['po_text'] = htmlspecialchars(erzeuge_umbruch($po_text, 80));
$f['po_ts'] = time();
$f['po_threadts'] = time();
if ($po_vater_id != 0)
$f['po_threadorder'] = 1;
else $f['po_threadorder'] = 0;
//Posting schreiben
$new_po_id = schreibe_db("posting", $f, "", "po_id");
//ist was schiefgelaufen?
if (!$new_po_id)
exit;
//falls reply muss po_threadorder des vaters neu geschrieben werden
if ($po_vater_id != 0) {
//po_threadorder des threadvaters neu schreiben
//dazu Tabelle posting locken
$sql = "LOCK TABLES posting WRITE";
@mysql_query($sql, $conn);
//alte Threadorder holen
$sql = "select po_threadorder from posting where po_id = " . intval($thread);
$query = mysql_query($sql, $conn);
$threadorder = mysql_result($query, 0, "po_threadorder");
@mysql_free_result($query);
//erste Antwort?
if ($threadorder == "0")
$threadorder = $new_po_id;
else {
//jetzt hab ich arbeit...
//rekursiv das unterste Posting dieses Teilbaums holen
$insert_po_id = hole_letzten($po_vater_id, $new_po_id);
//alte threadorder in feld aufsplitten
$threadorder_array = explode(",", $threadorder);
$threadorder_array_new = array();
$i = 0;
while (list($k, $v) = each($threadorder_array)) {
if ($v == $insert_po_id) {
$threadorder_array_new[$i] = $v;
$i++;
$threadorder_array_new[$i] = $new_po_id;
} else {
$threadorder_array_new[$i] = $v;
}
$i++;
}
$threadorder = implode(",", $threadorder_array_new);
}
//threadorder neu schreiben
$sql = "update posting
set po_threadorder = '$threadorder', po_threadts = "
. time()
. "
where po_id = $thread";
mysql_query($sql, $conn);
#print "neue threadorder: $threadorder<BR>";
//schliesslich noch die markierung des letzten in der Ebene entfernen
$sql = "update posting
set po_threadorder = '0'
where po_threadorder = '1'
and po_id <> $new_po_id
and po_vater_id = " . intval($po_vater_id);
mysql_query($sql, $conn);
//Tabellen wieder freigeben
$sql = "UNLOCK TABLES";
@mysql_query($sql, $conn);
} else {
//Thread neu setzen
$thread = $new_po_id;
}
//th_postings muss neu geschrieben werden
//anz_threads und anz_replys im Thema setzen
//erst Tabelle thema sperren
$sql = "LOCK TABLES thema WRITE";
@mysql_query($sql, $conn);
//altes th_postings und anz_threads und anz_replys holen
$sql = "select th_postings, th_anzthreads, th_anzreplys from thema where th_id = " . intval($th_id);
$query = mysql_query($sql, $conn);
$postings = mysql_result($query, 0, "th_postings");
$anzthreads = mysql_result($query, 0, "th_anzthreads");
$anzreplys = mysql_result($query, 0, "th_anzreplys");
if (!$postings) //erstes Posting in diesem Thema
$postings = $new_po_id;
else { //schon postings da
$postings_array = explode(",", $postings);
$postings_array[] = $new_po_id;
$postings = implode(",", $postings_array);
}
if ($po_vater_id == 0) {
//neuer Thread
$anzthreads++;
} else {
//neue Antwort
$anzreplys++;
}
//schreiben
$sql = "update thema
set th_postings = '$postings',
th_anzthreads = $anzthreads,
th_anzreplys = $anzreplys
where th_id = " . intval($th_id);
mysql_query($sql, $conn);
//Tabellen wieder freigeben
$sql = "UNLOCK TABLES";
@mysql_query($sql, $conn);
}
if (!isset($new_po_id))
$new_po_id = 0;
return $new_po_id;
}
//holt ausgehend von root_id das letzte Posting
//im Teilbaum unterhalb der root_id
function hole_letzten($root_id, $new_po_id)
{
global $conn;
$sql = "select po_id
from posting
where po_vater_id = " . intval($root_id) . "
and po_id <> " . intval($new_po_id) . "
order by po_ts desc
limit 1";
$query = mysql_query($sql, $conn);
$anzahl = mysql_num_rows($query);
if ($anzahl > 0)
$new_root_id = mysql_result($query, 0, "po_id");
@mysql_free_result($query);
if ($anzahl > 0) {
//es geht noch tiefer...
$retval = hole_letzten($new_root_id, $new_po_id);
} else {
$retval = $root_id;
}
return $retval;
}
//loescht das Posting und alle Antworten darauf
function loesche_posting()
{
global $conn, $th_id, $po_id, $thread;
global $arr_delete;
global $farbe_tabellenrahmen, $farbe_tabelle_kopf2, $punkte_pro_posting, $t, $farbe_text;
$arr_delete = array();
//tabelle posting und thema locken
$sql = "LOCK TABLES posting, thema WRITE";
@mysql_query($sql, $conn);
//rekursiv alle zu loeschenden postings in feld einlesen
$arr_delete[] = $po_id;
hole_alle_unter($po_id);
//po_threadorder neu schreiben
//nur relevant, wenn posting nicht erster im Thread
//ansonsten wird es eh geloescht
if ($po_id != $thread) {
$sql = "select po_threadorder, po_ts from posting where po_id=" . intval($thread);
$query = mysql_query($sql, $conn);
$threadorder = mysql_result($query, 0, "po_threadorder");
$new_ts = mysql_result($query, 0, "po_ts");
//in array einlesen und zu loeschende rausschmeissen
$arr_new_threadorder = explode(",", $threadorder);
$arr_new_threadorder = array_diff($arr_new_threadorder, $arr_delete);
if (count($arr_new_threadorder) == 0) {
$arr_new_threadorder[0] = 0;
} else {
// beim löschen eines Postings wird hier die letzte änderung aller postings gesucht, damit
// der thread_ts wieder stimmt
$new_ts = '0000000000';
$new_threadorder = implode(",", $arr_new_threadorder);
$arr_new_threadorder = explode(",", $new_threadorder);
for ($i = 0; $i < count($arr_new_threadorder); $i++) {
$sql = "select po_ts from posting where po_id = " . intval($arr_new_threadorder[$i]);
$query = mysql_query($sql, $conn);
$ts = mysql_result($query, 0, "po_ts");
if ($ts > $new_ts)
$new_ts = $ts;
}
}
$new_threadorder = implode(",", $arr_new_threadorder);
$sql = "update posting
set po_threadorder = '$new_threadorder', po_threadts = $new_ts
where po_id = $thread";
mysql_query($sql, $conn);
//eventuell letztes Posting auf ebene neu markieren
$sql = "select po_vater_id, po_threadorder from posting where po_id = " . intval($po_id);
$query = mysql_query($sql, $conn);
$threadorder = mysql_result($query, 0, "po_threadorder");
$vater_id = mysql_result($query, 0, "po_vater_id");
//falls letztes posting, dann neu setzen
if ($threadorder == "1") {
$sql = "select po_id from posting
where po_vater_id = $vater_id
and po_id <> " . intval($po_id) . "
order by po_ts desc
limit 1";
$query = mysql_query($sql, $conn);
if (mysql_num_rows($query) > 0) {
$po_id_update = mysql_result($query, 0, "po_id");
$sql = "update posting
set po_threadorder = '1'
where po_id = $po_id_update";
mysql_query($sql, $conn);
}
}
}
//eintragungen in Thema neu schreiben
$sql = "select th_anzthreads, th_anzreplys, th_postings from thema where th_id=" . intval($th_id);
$query = mysql_query($sql, $conn);
$postings = mysql_result($query, 0, "th_postings");
$anzthreads = mysql_result($query, 0, "th_anzthreads");
$anzreplys = mysql_result($query, 0, "th_anzreplys");
//in array einlesen und zu loeschende rausschmeissen
$arr_new_postings = explode(",", $postings);
$arr_new_postings = array_diff($arr_new_postings, $arr_delete);
$new_postings = implode(",", $arr_new_postings);
//th_anzthreads und th_anzreplys neu schreiben