/
functions-community.php
1378 lines (1185 loc) · 54.2 KB
/
functions-community.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
require_once("functions.php-func-sms.php");
function suche_vaterposting($poid)
{
// Diese Funktion sucht das Vaterposting des übergebenen Postings
$query = "SELECT po_vater_id FROM posting WHERE po_id = '" . intval($poid) . "'";
$result = mysql_query($query);
list($vp) = mysql_fetch_array($result);
return ($vp);
}
function suche_threadord($poid)
{
// Diese Funktion sucht die Threadorder des Vaterpostings
$query = "SELECT po_threadorder FROM posting WHERE po_id = '" . intval($poid) . "'";
$result = mysql_query($query);
list($to) = mysql_fetch_array($result);
return ($to);
}
function mail_neu($u_id, $u_nick, $id, $nachricht = "OLM")
{
// Hat der User neue Chat-Mail?
// $u_id ist die ID des des Users
// $nachricht ist die Art, wie die Nachricht verschickt wird (E-Mail, Chat-Mail, OLM)
global $system_farbe, $conn, $dbase, $communityfeatures, $t, $http_host, $webmaster, $chat;
// Fenstername
$fenster = str_replace("+", "", $u_nick);
$fenster = str_replace("-", "", $fenster);
$fenster = str_replace("ä", "", $fenster);
$fenster = str_replace("ö", "", $fenster);
$fenster = str_replace("ü", "", $fenster);
$fenster = str_replace("Ä", "", $fenster);
$fenster = str_replace("Ö", "", $fenster);
$fenster = str_replace("Ü", "", $fenster);
$fenster = str_replace("ß", "", $fenster);
$query = "SELECT mail.*,date_format(m_zeit,'%d.%m.%y um %H:%i') as zeit,u_nick "
. "FROM mail LEFT JOIN user on m_von_uid=u_id "
. "WHERE m_an_uid=$u_id AND m_status='neu' "
. "order by m_zeit desc";
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) > 0) {
// Sonderfall OLM: "Sie haben neue Mail..." ausgeben.
if ($nachricht == "OLM") {
$ur1 = "mail.php?http_host=$http_host&id=$id&aktion=";
$url = "HREF=\"$ur1\" TARGET=\"640_$fenster\" onclick=\"window.open('$ur1','640_$fenster','resizable=yes,scrollbars=yes,width=780,height=580'); return(false);\"";
system_msg("", 0, $u_id, $system_farbe,
str_replace("%link%", $url, $t['mail1']));
}
while ($row = mysql_fetch_object($result)) {
// Nachricht verschicken
switch ($nachricht) {
case "OLM":
$txt = str_replace("%zeit%", $row->zeit, $t['mail2']);
if ($row->u_nick != "NULL" && $row->u_nick != "") {
$txt = str_replace("%nick%", $row->u_nick, $txt);
} else {
$txt = str_replace("%nick%", $chat, $txt);
}
system_msg("", 0, $u_id, $system_farbe,
str_replace("%betreff%", $row->m_betreff, $txt));
break;
case "E-Mail":
// Mail als verschickt markieren
unset($f);
$f['m_status'] = "neu/verschickt";
$f['m_zeit'] = $row->m_zeit;
schreibe_db("mail", $f, $row->m_id, "m_id");
// E-Mail an u_id versenden
email_versende($row->m_von_uid, $u_id,
$t['mail3'] . $row->m_text, $row->m_betreff);
break;
case "SMS":
// Mail als verschickt markieren
unset($f);
$f['m_status'] = "neu/verschickt";
$f['m_zeit'] = $row->m_zeit;
schreibe_db("mail", $f, $row->m_id, "m_id");
$txt = str_replace("%zeit%", $row->zeit, $t['mail2']);
if ($row->u_nick != "NULL" && $row->u_nick != "") {
$txt = str_replace("%nick%", $row->u_nick, $txt);
} else {
$txt = str_replace("%nick%", $chat, $txt);
}
sms_sende($u_id, $u_id,
str_replace("%betreff%", $row->m_betreff, $txt));
break;
}
}
}
@mysql_free_result($result);
}
function profil_neu($u_id, $u_nick, $id)
{
// Hat der User sein Profil ausgefüllt?
// Falls nein, wird einer Erinnerung ausgegeben
// $u_id ist die ID des des Users
global $system_farbe, $dbase, $conn, $communityfeatures, $t, $http_host;
$fenster = str_replace("+", "", $u_nick);
$fenster = str_replace("-", "", $fenster);
$fenster = str_replace("ä", "", $fenster);
$fenster = str_replace("ö", "", $fenster);
$fenster = str_replace("ü", "", $fenster);
$fenster = str_replace("Ä", "", $fenster);
$fenster = str_replace("Ö", "", $fenster);
$fenster = str_replace("Ü", "", $fenster);
$fenster = str_replace("ß", "", $fenster);
$query = "SELECT ui_id FROM userinfo WHERE ui_userid=$u_id";
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) == 0) {
$ur1 = "profil.php?http_host=$http_host&id=$id&aktion=neu";
$url = "HREF=\"$ur1\" TARGET=\"640_$fenster\" onclick=\"neuesFenster2('$ur1'); return(false);\"";
system_msg("", 0, $u_id, $system_farbe,
str_replace("%link%", $url, $t['profil1']));
}
@mysql_free_result($result);
}
function autoselect($name, $voreinstellung, $tabelle, $feld)
{
// Erzeugt Select-Feld aus der Datenbank
// $name=Name der Auswahl
// $voreinstellung=Voreinstellung der Auswahl
// $tabelle=Name der Tabelle in der Datenbank
// $feld=Name des Felds
global $system_farbe, $conn, $dbase, $communityfeatures, $t, $http_host;
$query = "SHOW COLUMNS FROM $tabelle like '" . mysql_real_escape_string($feld) . "'";
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) != 0) {
$txt = substr(mysql_result($result, 0, "Type"), 4, -1);
$felder = explode(",", $txt);
echo "<SELECT NAME=\"$name\">\n";
while (list($key, $set_name) = each($felder)) {
$set_name = substr($set_name, 1, -1);
if ($set_name == $voreinstellung) {
echo "<OPTION SELECTED VALUE=$set_name>$set_name\n";
} else {
echo "<OPTION VALUE=$set_name>$set_name\n";
}
}
echo "</SELECT>\n";
}
mysql_free_result($result);
}
function punkte($anzahl, $o_id, $u_id = 0, $text = "", $sofort = FALSE)
{
// Addiert/Subtrahiert $anzahl Punkte auf das Punktekonto des Users $o_id/$u_id
// Dieser User muss online sein, die punkte werden in der Tabelle online addiert
// Falls $text Zeichen enthält, wird der Text mit einem Standardtext ausgegeben
global $t, $o_punkte, $dbase, $communityfeatures, $conn, $punkte_gruppe;
// In die Datenbank schreiben
if ($anzahl > 0 || $anzahl < 0) {
if ($u_id != 0) {
$where = "WHERE o_user=$u_id";
} else {
$where = "WHERE o_id=$o_id";
}
$query = "UPDATE online set o_punkte=o_punkte+" . intval($anzahl) . " " . $where;
mysql_query($query, $conn);
}
// Meldung an User ausgeben
if (strlen($text) > 0) {
if ($anzahl > 0) {
// Gutschrift
$text = str_replace("%text%", $text, $t['punkte1']);
$text = str_replace("%punkte%", $anzahl, $text);
} else {
// Abzug
$text = str_replace("%text%", $text, $t['punkte2']);
$text = str_replace("%punkte%", $anzahl * (-1), $text);
}
if ($u_id != 0)
system_msg("", 0, $u_id,
(isset($system_farbe) ? $system_farbe : ""), $text);
}
// Optional Punkte sofort in Userdaten übertragen
if ($sofort && $o_id) {
// Tabellen online+user exklusiv locken
$query = "LOCK TABLES online WRITE, user WRITE";
$result = mysql_query($query, $conn);
// Aktuelle Punkte auf Punkte in Usertabelle addieren
$result = mysql_query(
"select o_punkte,o_user FROM online WHERE o_id=" . intval($o_id), $conn);
if ($result && mysql_num_rows($result) == 1) {
$row = mysql_fetch_object($result);
$u_id = $row->o_user;
// es können maximal die punkte abgezogen werden, die man auch hat
$result2 = mysql_query(
"select u_punkte_gesamt, u_punkte_jahr, u_punkte_monat FROM user WHERE u_id=$u_id",
$conn);
if ($result2 && mysql_num_rows($result2) == 1) {
$row2 = mysql_fetch_object($result2);
$p_gesamt = $row2->u_punkte_gesamt + $row->o_punkte;
$p_jahr = $row2->u_punkte_jahr + $row->o_punkte;
$p_monat = $row2->u_punkte_monat + $row->o_punkte;
if ($p_gesamt < 0)
$p_gesamt = 0;
if ($p_jahr < 0)
$p_jahr = 0;
if ($p_monat < 0)
$p_monat = 0;
}
$query = "update user set " . "u_punkte_monat=$p_monat, "
. "u_punkte_jahr=$p_jahr, " . "u_punkte_gesamt=$p_gesamt "
. "where u_id=$u_id";
$result2 = mysql_query($query, $conn);
$result = mysql_query(
"UPDATE online set o_punkte=0 WHERE o_id=" . intval($o_id), $conn);
}
@mysql_free_result($result);
// Gruppe neu berechnen
unset($f);
$f['u_punkte_gruppe'] = 0;
$result = mysql_query(
"select u_punkte_gesamt FROM user WHERE u_id=$u_id", $conn);
if ($result && mysql_num_rows($result) == 1) {
$u_punkte_gesamt = mysql_result($result, 0, 0);
foreach ($punkte_gruppe as $key => $value) {
if ($u_punkte_gesamt < $value) {
break;
} else {
$f['u_punkte_gruppe'] = dechex($key);
}
}
}
schreibe_db("user", $f, $u_id, "u_id");
// Lock freigeben
$query = "UNLOCK TABLES";
$result = mysql_query($query, $conn);
}
}
function punkte_offline($anzahl, $u_id)
{
// Addiert/Subtrahiert $anzahl Punkte auf das Punktekonto des Users $u_id
// Die Punkte werden direkt in die user-tabelle geschrieben
// Optional wird Info-Text als Ergebnis zurückgeliefert
global $t, $dbase, $communityfeatures, $conn, $punkte_gruppe;
// In die Datenbank schreiben
// Tabellen online+user exklusiv locken
$query = "LOCK TABLES online WRITE, user WRITE";
$result = mysql_query($query, $conn);
// Aktuelle Punkte auf Punkte in Usertabelle addieren
if ($u_id && ($anzahl > 0 || $anzahl < 0)) {
// es können maximal die punkte abgezogen werden, die man auch hat
$result2 = mysql_query(
"select u_punkte_gesamt, u_punkte_jahr, u_punkte_monat FROM user WHERE u_id=$u_id",
$conn);
if ($result2 && mysql_num_rows($result2) == 1) {
$row2 = mysql_fetch_object($result2);
$p_gesamt = $row2->u_punkte_gesamt + $anzahl;
$p_jahr = $row2->u_punkte_jahr + $anzahl;
$p_monat = $row2->u_punkte_monat + $anzahl;
if ($p_gesamt < 0)
$p_gesamt = 0;
if ($p_jahr < 0)
$p_jahr = 0;
if ($p_monat < 0)
$p_monat = 0;
}
$query = "update user set " . "u_login=u_login, "
. "u_punkte_monat=$p_monat, " . "u_punkte_jahr=$p_jahr, "
. "u_punkte_gesamt=$p_gesamt " . "where u_id=$u_id";
$result = mysql_query($query, $conn);
}
// Gruppe neu berechnen
unset($f);
$f['u_punkte_gruppe'] = 0;
$result = mysql_query(
"select u_punkte_gesamt,u_nick FROM user WHERE u_id=$u_id", $conn);
if ($result && mysql_num_rows($result) == 1) {
$u_punkte_gesamt = mysql_result($result, 0, "u_punkte_gesamt");
$u_nick = mysql_result($result, 0, "u_nick");
foreach ($punkte_gruppe as $key => $value) {
if ($u_punkte_gesamt < $value) {
break;
} else {
$f['u_punkte_gruppe'] = dechex($key);
}
}
}
schreibe_db("user", $f, $u_id, "u_id");
// Lock freigeben
$query = "UNLOCK TABLES";
$result = mysql_query($query, $conn);
// Meldung an User ausgeben
if ($anzahl > 0) {
// Gutschrift
$text = str_replace("%user%", $u_nick, $t['punkte21']);
$text = str_replace("%punkte%", $anzahl, $text);
} else {
// Abzug
$text = str_replace("%user%", $u_nick, $t['punkte22']);
$text = str_replace("%punkte%", $anzahl * (-1), $text);
}
return ($text);
}
function aktion(
$typ,
$an_u_id,
$u_nick,
$id = "",
$suche_was = "",
$inhalt = "")
{
// Programmierbare Aktionen für User $an_u_id von User $u_nick
// Verschickt eine Nachricht (Aktion) zum Login, Raumwechsel, Sofort oder alle 5 Minuten aus (a_wann)
// Die Aktion ist Mail (Chatintern), E-Mail an die Adresse des Users oder eine Online-Message (a_wie)
// Die betroffene Chat-Funktion (zb. Freund-Login/Logout, Mailempfang) wird als Text definiert (a_was)
// Pro Funktion kann ein Infotext hinterlegt werden (a_text)
// typ = "Sofort/Offline", "Sofort/Online", "Login", "Alle 5 Minuten"
// Die Session-ID $id kann optional übergeben werden
// Mit der Angabe von $suche_was kann die Suche auf ein a_was eingeschränkt werden
// Für "Sofort/Offline" und "Sofort/Online" muss der Inhalt in $inhalt übergeben werden
global $u_id, $t, $dbase, $communityfeatures, $conn;
if ($communityfeatures) {
// Einstellungen aus DB in Array a_was merken und dabei SETs auflösen
// Mögliche a_wann: Sofort/Offline, Sofort/Online, Login, Alle 5 Minuten
$query = "SELECT a_was,a_wie from aktion " . "WHERE a_user=$an_u_id "
. "AND a_wann='$typ' ";
if ($suche_was != "")
$query .= "AND a_was='$suche_was'";
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_object($result)) {
$wie = explode(",", $row->a_wie);
foreach ($wie as $a_wie) {
$a_was[$row->a_was][$a_wie] = TRUE;
}
}
}
@mysql_free_result($result);
switch ($typ) {
case "Sofort/Offline":
case "Sofort/Online":
if ($suche_was != "" && isset($a_was)
&& is_array($a_was[$suche_was])) {
foreach ($a_was[$suche_was] as $wie => $was) {
aktion_sende($suche_was, $wie, $inhalt, $an_u_id,
$u_id, $u_nick, $id);
}
}
break;
case "Alle 5 Minuten":
// Aktionen ausführen
if (isset($a_was["Freunde"]["OLM"]))
freunde_online($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Freunde"]["Chat-Mail"]))
freunde_online($an_u_id, $u_nick, $id, "Chat-Mail");
if (isset($a_was["Freunde"]["E-Mail"]))
freunde_online($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Freunde"]["SMS"]))
freunde_online($an_u_id, $u_nick, $id, "SMS");
if (isset($a_was["Neue Mail"]["OLM"]))
mail_neu($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Neue Mail"]["E-Mail"]))
mail_neu($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Neue Mail"]["SMS"]))
mail_neu($an_u_id, $u_nick, $id, "SMS");
if (isset($a_was["Antwort auf eigenes Posting"]["OLM"]))
postings_neu($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Antwort auf eigenes Posting"]["Chat-Mail"]))
postings_neu($an_u_id, $u_nick, $id, "Chat-Mail");
if (isset($a_was["Antwort auf eigenes Posting"]["E-Mail"]))
postings_neu($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Antwort auf eigenes Posting"]["SMS"]))
postings_neu($an_u_id, $u_nick, $id, "SMS");
// Merken, wann zuletzt die Aktionen ausgeführt wurden
$query = "UPDATE online SET o_aktion=" . time()
. " where o_user=$an_u_id";
$result = mysql_query($query, $conn);
break;
case "Login":
default:
// Aktionen ausführen
if (isset($a_was["Freunde"]["OLM"]))
freunde_online($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Freunde"]["Chat-Mail"]))
freunde_online($an_u_id, $u_nick, $id, "Chat-Mail");
if (isset($a_was["Freunde"]["E-Mail"]))
freunde_online($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Freunde"]["SMS"]))
freunde_online($an_u_id, $u_nick, $id, "SMS");
if (isset($a_was["Neue Mail"]["OLM"]))
mail_neu($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Neue Mail"]["E-Mail"]))
mail_neu($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Neue Mail"]["SMS"]))
mail_neu($an_u_id, $u_nick, $id, "SMS");
if (isset($a_was["Antwort auf eigenes Posting"]["OLM"]))
postings_neu($an_u_id, $u_nick, $id, "OLM");
if (isset($a_was["Antwort auf eigenes Posting"]["Chat-Mail"]))
postings_neu($an_u_id, $u_nick, $id, "Chat-Mail");
if (isset($a_was["Antwort auf eigenes Posting"]["E-Mail"]))
postings_neu($an_u_id, $u_nick, $id, "E-Mail");
if (isset($a_was["Antwort auf eigenes Posting"]["SMS"]))
postings_neu($an_u_id, $u_nick, $id, "SMS");
}
}
}
;
function aktion_sende(
$a_was,
$a_wie,
$inhalt,
$an_u_id,
$von_u_id,
$u_nick,
$id = "")
{
// Versendet eine Nachricht an User $an_u_id von $von_u_id/$u_nick
// Der Inhalt der Nachricht wird in $inhalt übergeben
// Die Session-ID $id kann optional übergeben werden
// Die Aktion ist Mail (Chatintern), E-Mail an die Adresse des Users oder eine Online-Message (a_wie)
// Die betroffene Chat-Funktion (zb. Freund-Login/Logout, Mailempfang) wird als Text definiert (a_was)
global $system_farbe, $dbase, $communityfeatures, $t;
$userlink = user($von_u_id, 0, True, False, " ", "", "", False, False,
31);
switch ($a_wie) {
case "OLM":
// Nachricht erzeugen
switch ($a_was) {
case "Freunde":
// Nachricht von Login/Logoff erzeugen
if ($inhalt['aktion'] == "Login" && $inhalt['raum']) {
$txt = str_replace("%u_name%", $userlink,
$t['freunde1']);
$txt = str_replace("%raum%", $inhalt['raum'], $txt);
} elseif ($inhalt['aktion'] == "Login") {
$txt = str_replace("%u_name%", $userlink,
$t['freunde5']);
} else {
$txt = str_replace("%u_name%", $u_nick, $t['freunde2']);
}
if ($inhalt['f_text'])
$txt .= " (" . $inhalt['f_text'] . ")";
system_msg("", 0, $an_u_id, $system_farbe, $txt);
break;
case "Neue Mail":
// Nachricht erzeugen
$txt = str_replace("%nick%", $u_nick, $t['mail7']);
$txt = str_replace("%betreff%", $inhalt['m_betreff'], $txt);
// Nachricht versenden
system_msg("", 0, $an_u_id, $system_farbe, $txt);
break;
case "Antwort auf eigenes Posting":
$text = str_replace("%po_titel%", $inhalt['po_titel'],
$t['msg_new_posting_olm']);
$text = str_replace("%po_ts%", $inhalt['po_ts'], $text);
$text = str_replace("%forum%", $inhalt['forum'], $text);
$text = str_replace("%thema%", $inhalt['thema'], $text);
$text = str_replace("%user_from_nick%",
$inhalt['user_from_nick'], $text);
$text = str_replace("%po_titel_antwort%",
$inhalt['po_titel_antwort'], $text);
$text = str_replace("%po_ts_antwort%",
$inhalt['po_ts_antwort'], $text);
system_msg("", 0, $an_u_id, $system_farbe, $text);
break;
}
break;
case "Chat-Mail":
// Nachricht erzeugen
switch ($a_was) {
case "Freunde":
// Nachricht von Login/Logoff erzeugen
if ($inhalt['aktion'] == "Login" && $inhalt[raum]) {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde3']);
$betreff = str_replace("%raum%", $inhalt['raum'],
$betreff);
} elseif ($inhalt[aktion] == "Login") {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde6']);
} else {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde4']);
}
if ($inhalt['f_text']) {
$txt = $t['mail9'] . $betreff . " ("
. $inhalt['f_text'] . ")";
} else {
$txt = $t['mail9'] . $betreff;
}
// Mail-Absender ist MainChat
$von_u_id = 0;
mail_sende($von_u_id, $an_u_id, $txt, $betreff);
break;
case "Neue Mail":
// Eine neue Chat-Mail kann keine Chat-Mail auslösen
break;
case "Antwort auf eigenes Posting":
$betreff = str_replace("%po_titel%", $inhalt['po_titel'],
$t['betreff_new_posting']);
$text = str_replace("%po_titel%", $inhalt['po_titel'],
$t['msg_new_posting_chatmail']);
$text = str_replace("%po_ts%", $inhalt['po_ts'], $text);
$text = str_replace("%forum%", $inhalt['forum'], $text);
$text = str_replace("%thema%", $inhalt['thema'], $text);
$text = str_replace("%user_from_nick%",
$inhalt['user_from_nick'], $text);
$text = str_replace("%po_titel_antwort%",
$inhalt['po_titel_antwort'], $text);
$text = str_replace("%po_ts_antwort%",
$inhalt['po_ts_antwort'], $text);
$text = str_replace("%baum%", $inhalt['baum'], $text);
mail_sende($von_u_id, $an_u_id, $text, $betreff);
break;
}
break;
case "E-Mail":
// Nachricht erzeugen
switch ($a_was) {
case "Freunde":
// Nachricht von Login/Logoff erzeugen
if ($inhalt['aktion'] == "Login" && $inhalt['raum']) {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde3']);
$betreff = str_replace("%raum%", $inhalt['raum'],
$betreff);
} elseif ($inhalt['aktion'] == "Login") {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde6']);
} else {
$betreff = str_replace("%u_name%", $u_nick,
$t['freunde4']);
}
if ($inhalt['f_text']) {
$txt = $t['mail8'] . $betreff . " ("
. $inhalt['f_text'] . ")";
} else {
$txt = $t['mail8'] . $betreff;
}
email_versende($von_u_id, $an_u_id, $txt, $betreff);
break;
case "Neue Mail":
// Mail als verschickt markieren
unset($f);
$f['m_status'] = "neu/verschickt";
schreibe_db("mail", $f, $inhalt['m_id'], "m_id");
// Nachricht versenden
email_versende($inhalt['m_von_uid'], $inhalt['m_an_uid'],
$t['mail3'] . $inhalt['m_text'], $inhalt['m_betreff']);
break;
case "Antwort auf eigenes Posting":
$betreff = str_replace("%po_titel%", $inhalt['po_titel'],
$t['betreff_new_posting']);
$text = str_replace("%po_titel%", $inhalt['po_titel'],
$t['msg_new_posting_email']);
$text = str_replace("%po_ts%", $inhalt['po_ts'], $text);
$text = str_replace("%forum%", $inhalt['forum'], $text);
$text = str_replace("%thema%", $inhalt['thema'], $text);
$text = str_replace("%user_from_nick%",
$inhalt['user_from_nick'], $text);
$text = str_replace("%po_titel_antwort%",
$inhalt['po_titel_antwort'], $text);
$text = str_replace("%po_ts_antwort%",
$inhalt['po_ts_antwort'], $text);
$text = str_replace("%baum%", $inhalt['baum'], $text);
email_versende($von_u_id, $an_u_id, $text, $betreff);
break;
}
break;
case "SMS":
// Nachricht erzeugen
switch ($a_was) {
case "Freunde":
// Nachricht von Login/Logoff erzeugen
if ($inhalt['aktion'] == "Login" && $inhalt['raum']) {
$txt = str_replace("%u_name%", $u_nick, $t['freunde1']);
$txt = str_replace("%raum%", $inhalt['raum'], $txt);
} elseif ($inhalt['aktion'] == "Login") {
$txt = str_replace("%u_name%", $u_nick, $t['freunde5']);
} else {
$txt = str_replace("%u_name%", $u_nick, $t['freunde2']);
}
if ($inhalt['f_text'])
$txt .= " (" . $inhalt['f_text'] . ")";
sms_sende($an_u_id, $an_u_id, $txt);
break;
case "Neue Mail":
// Mail als verschickt markieren
unset($f);
$f['m_status'] = "neu/verschickt";
schreibe_db("mail", $f, $inhalt['m_id'], "m_id");
// Nachricht erzeugen
$txt = str_replace("%nick%", $u_nick, $t['mail7']);
$txt = str_replace("%betreff%", $inhalt['m_betreff'], $txt);
// Nachricht versenden
sms_sende($an_u_id, $an_u_id, $txt);
break;
case "Antwort auf eigenes Posting":
$text = str_replace("%po_titel%", $inhalt['po_titel'],
$t['msg_new_posting_sms']);
$text = str_replace("%po_ts%", $inhalt['po_ts'], $text);
$text = str_replace("%forum%", $inhalt['forum'], $text);
$text = str_replace("%thema%", $inhalt['thema'], $text);
system_msg("", 0, $an_u_id, $system_farbe, $text);
sms_sende($an_u_id, $an_u_id, $text);
break;
}
break;
}
}
function mail_sende($von, $an, $text, $betreff = "")
{
// Verschickt Mail von ID $von an ID $an mit Text $text
global $t;
global $u_nick;
$mailversand_ok = true;
$fehlermeldung = "";
// User die die Mailbox zu haben, bekommen keine Aktionen per Mainchat
$query = "SELECT m_id FROM mail WHERE m_von_uid=" . intval($an) . " AND m_an_uid=" . intval($an) . " and m_betreff = 'MAILBOX IST ZU' and m_status != 'geloescht'";
$result = mysql_query($query);
$num = mysql_numrows($result);
if ($num >= 1) {
$mailversand_ok = false;
$fehlermeldung = $t['chat_msg105'];
}
// Gesperrte User bekommen keine Chatmail Aktionen mehr
$query = "SELECT u_id FROM user WHERE u_id=" . intval($an) . " AND u_level='Z'";
$result = mysql_query($query);
$num = mysql_numrows($result);
if ($num >= 1) {
$mailversand_ok = false;
$fehlermeldung = "User ist gesperrt, und kann deswegen keine Chatmail empfangen";
}
// mailbombing schutz!
$query = "SELECT m_id,now()-m_zeit as zeit FROM mail WHERE m_von_uid = " . intval($von) . " AND m_an_uid = '" . intval($an) . " order by m_id desc limit 0,1";
// system_msg("",0,$von,$system_farbe,"DEBUG: $query");
$result = mysql_query($query);
if (mysql_numrows($result) == 1) {
$a = mysql_fetch_array($result);
$zeit = $a['zeit'];
} else {
$zeit = 999;
}
if ($zeit < 30) {
$mailversand_ok = false;
$fehlermeldung = $t['chat_msg104'];
}
if ($mailversand_ok == true) {
$f['m_von_uid'] = $von;
$f['m_an_uid'] = $an;
$f['m_status'] = "neu";
$f['m_text'] = chat_parse($text);
if ($betreff) {
$f['m_betreff'] = $betreff;
} else {
// Betreff aus Text übernehmen und kürzen
$f['m_betreff'] = $text;
if (strlen($f['m_betreff']) > 5) {
$f['m_betreff'] = substr($f['m_betreff'], 0, 30);
$f['m_betreff'] = substr($f['m_betreff'], 0,
strrpos($f['m_betreff'], " ") + 1);
}
;
}
;
$f['m_id'] = schreibe_db("mail", $f, "", "m_id");
// Nachricht über neue E-Mail sofort erzeugen
if (ist_online($an)) {
aktion("Sofort/Online", $an, $u_nick, "", "Neue Mail", $f);
} else {
aktion("Sofort/Offline", $an, $u_nick, "", "Neue Mail", $f);
}
;
}
if (!isset($f['m_id']))
$f['m_id'] = "";
$ret = array($f['m_id'], $fehlermeldung);
return ($ret);
}
function email_versende(
$von_user_id,
$an_user_id,
$text,
$betreff,
$an_u_email = FALSE)
{
// Versendet "echte" E-Mail an User mit an_user_id
// Falls an_u_email=TRUE wird Mail an u_email Adressen verschickt,
// sonst an u_adminemail (interne Adresse)
global $chat, $dbase, $conn, $t, $http_host;
// Umwandlung der Entities rückgängig machen, Slashes und Tags entfernen
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$text = str_replace("<ID>", "", $text);
$text = str_replace("<HTTP_HOST>", $http_host, $text);
$text = strip_tags(strtr($text, $trans));
$betreff = strip_tags(strtr($betreff, $trans));
// Absender ermitteln
$query = "SELECT u_email,u_nick from user WHERE u_id=" . intval($von_user_id);
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) == 1) {
$abrow = mysql_fetch_object($result);
}
@mysql_free_result($result);
// Empfänger ermitteln und E-Mail versenden, Footer steht in $t[mail4]
$query = "SELECT u_adminemail,u_email,u_name,u_nick from user WHERE u_id=" . intval($an_user_id);
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) == 1) {
$row = mysql_fetch_object($result);
// Empfänger
if ($an_u_email && $row->u_email) {
$adresse = $row->u_email;
} else {
$adresse = $row->u_adminemail;
}
// Absender
if ($abrow->u_email == "") {
$absender = $chat . " <" . $adresse . ">";
} else {
$absender = $abrow->u_nick . " <" . $abrow->u_email . ">";
}
mail($adresse, $betreff, str_replace("%user%", $row->u_nick, $text)
. $t['mail4'], "From: $absender\nReply-To: $absender\n");
@mysql_free_result($result);
return (TRUE);
} else {
@mysql_free_result($result);
return (FALSE);
}
}
function freunde_online($u_id, $u_nick, $id, $nachricht = "OLM")
{
// Sind Freunde des Users online?
// $u_id ist die ID des des Users
// $nachricht ist die Art, wie die Nachricht verschickt wird (E-Mail, Chat-Mail, OLM)
global $conn, $system_farbe, $dbase, $communityfeatures, $t, $http_host, $webmaster, $o_js, $whotext;
$query = "SELECT f_id,f_text,f_userid,f_freundid,f_zeit FROM freunde WHERE f_userid=" . intval($u_id) . " AND f_status = 'bestaetigt' "
. "UNION "
. "SELECT f_id,f_text,f_userid,f_freundid,f_zeit FROM freunde WHERE f_freundid=" . intval($u_id) . " AND f_status = 'bestaetigt' "
. "ORDER BY f_zeit desc ";
$result = mysql_query($query, $conn);
if ($result && mysql_num_rows($result) > 0) {
$txt = "";
$i = 0;
while ($row = mysql_fetch_object($result)) {
// User aus DB lesen
if ($row->f_userid != $u_id) {
$query = "SELECT u_nick,u_id,u_level,u_punkte_gesamt,u_punkte_gruppe,o_id,"
. "date_format(u_login,'%d.%m.%y %H:%i') as login, "
. "UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(o_login) AS online "
. "from user, online " . "WHERE o_user=u_id "
. "AND u_id=$row->f_userid ";
} elseif ($row->f_freundid != $u_id) {
$query = "SELECT u_nick,u_id,u_level,u_punkte_gesamt,u_punkte_gruppe,o_id,"
. "date_format(u_login,'%d.%m.%y %H:%i') as login, "
. "UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(o_login) AS online "
. "from user,online " . "WHERE o_user=u_id "
. "AND u_id=$row->f_freundid ";
}
// system_msg("",0,$u_id,$system_farbe,"DEBUG: $nachricht, $query");
$result2 = mysql_query($query, $conn);
if ($result2 && mysql_num_rows($result2) > 0) {
// Nachricht erzeugen
$row2 = mysql_fetch_object($result2);
switch ($nachricht) {
case "OLM":
// Onlinenachricht an u_id versenden
if ($i > 0)
$txt .= "<BR>";
$q2 = "SELECT r_name,o_id,o_who,"
. "UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(o_login) AS online_zeit "
. "FROM online left join raum on r_id=o_raum WHERE o_user=$row2->u_id ";
$r2 = mysql_query($q2);
if ($r2 && mysql_num_rows($r2) > 0) {
$r = mysql_fetch_object($r2);
if ($r->o_who == 0) {
$raum = $t['chat_msg67'] . " <b>" . $r->r_name
. "</b>";
} else {
$raum = "<b>[" . $whotext[$r->o_who] . "]</b>";
}
}
@mysql_free_result($r2);
$weiterer = $t['chat_msg90'];
$weiterer = str_replace("%u_name%",
user($row2->u_id, $row2, TRUE, TRUE, " ",
$row2->online, "", FALSE), $weiterer);
$weiterer = str_replace("%raum%", $raum, $weiterer);
$txt .= $weiterer;
if ($row->f_text)
$txt .= " (" . $row->f_text . ")";
break;
case "Chat-Mail":
// Chat-Mail an u_id versenden
if ($i > 0)
$txt .= "\n\n";
$txt .= str_replace("%u_name%", $row2->u_nick,
$t['chat_msg91']);
$txt = str_replace("%online%",
gmdate("H:i:s", $row2->online), $txt);
if ($row->f_text)
$txt .= " (" . $row->f_text . ")";
break;
case "E-Mail":
// E-Mail an u_id versenden
if ($i > 0)
$txt .= "\n\n";
$txt .= str_replace("%u_name%", $row2->u_nick,
$t['chat_msg91']);
$txt = str_replace("%online%",
gmdate("H:i:s", $row2->online), $txt);
if ($row->f_text)
$txt .= " (" . $row->f_text . ")";
break;
case "SMS":
// SMS an u_id versenden
if ($i > 0)
$txt .= "\n\n";
$txt .= str_replace("%u_name%", $row2->u_nick,
$t['chat_msg91']);
$txt = str_replace("%online%",
gmdate("H:i:s", $row2->online), $txt);
if ($row->f_text)
$txt .= " (" . $row->f_text . ")";
break;
}
$i++;
}
}
// Nachricht versenden
if ($i != 0) {
switch ($nachricht) {
case "OLM":
system_msg("", 0, $u_id, $system_farbe, $txt);
break;
case "Chat-Mail":
$betreff = str_replace("%anzahl%", $i, $t['mail6']);
mail_sende(0, $u_id,
str_replace("%user%", $u_nick, $t['mail5']) . $txt,
$betreff);
break;
case "E-Mail":
$betreff = str_replace("%anzahl%", $i, $t['mail6']);
email_versende("", $u_id, $t['mail5'] . $txt, $betreff);
break;
case "SMS":
$betreff = str_replace("%anzahl%", $i, $t['mail6']);
$smstext = $betreff . " "
. str_replace("%user%", $u_nick, $t['mail5']) . $txt;
$smstext = str_replace("\n", " ", $smstext);
sms_sende($u_id, $u_id, $smstext);
// mail("martin@huskie.de","test","test");
break;
}
}
}
@mysql_free_result($result);
}
//prüft ob neue Antworten auf eigene Postings
//vorhanden sind und benachrichtigt entsprechend
function postings_neu($an_u_id, $u_nick, $id, $nachricht)
{
global $conn, $t, $system_farbe;
//schon gelesene Postings des Users holen
$sql = "select u_gelesene_postings from user where u_id = " . intval($an_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);
//alle eigenen Postings des Users mit allen Antworten