-
Notifications
You must be signed in to change notification settings - Fork 29
/
message.php
829 lines (767 loc) · 41.8 KB
/
message.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
<?
/*
// +--------------------------------------------------------------------------+
// | Project: TBDevYSE - TBDev Yuna Scatari Edition |
// +--------------------------------------------------------------------------+
// | This file is part of TBDevYSE. TBDevYSE is based on TBDev, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | TBDevYSE 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. |
// | |
// | TBDevYSE 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 TBDevYSE; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();
parked();
// Define constants
define('PM_DELETED',0); // Message was deleted
define('PM_INBOX',1); // Message located in Inbox for reciever
define('PM_SENTBOX',-1); // GET value for sent box
// Determine action
$action = (string) $_GET['action'];
if (!$action)
{
$action = (string) $_POST['action'];
if (!$action)
{
$action = 'viewmailbox';
}
}
// íà÷àëî ïðîñìîòð ïî÷òîâîãî ÿùèêà
if ($action == "viewmailbox") {
// Get Mailbox Number
$mailbox = (int) $_GET['box'];
if (!$mailbox)
{
$mailbox = PM_INBOX;
}
if ($mailbox == PM_INBOX)
{
$mailbox_name = $tracker_lang['inbox'];
}
else
{
$mailbox_name = $tracker_lang['outbox'];
}
// Start Page
stdhead($mailbox_name); ?>
<script language="Javascript" type="text/javascript">
var checkflag = "false";
var marked_row = new Array;
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
}
}
</script>
<!--<script language="javascript" type="text/javascript" src="js/functions.js"></script>-->
<H1><?=$mailbox_name?></H1>
<DIV align="right"><FORM action="message.php" method="get">
<INPUT type="hidden" name="action" value="viewmailbox"><?=$tracker_lang['go_to'];?>: <SELECT name="box">
<OPTION value="1"<?=($mailbox == PM_INBOX ? " selected" : "")?>><?=$tracker_lang['inbox'];?></OPTION>
<OPTION value="-1"<?=($mailbox == PM_SENTBOX ? " selected" : "")?>><?=$tracker_lang['outbox'];?></OPTION>
</SELECT> <INPUT type="submit" value="<?=$tracker_lang['go_go_go'];?>"></FORM>
</DIV>
<TABLE border="0" cellpadding="4" cellspacing="0" width="100%">
<FORM action="message.php" method="post" name="form1">
<INPUT type="hidden" name="action" value="moveordel">
<TR>
<TD width="2%" class="colhead"> </TD>
<TD width="51%" class="colhead"><?=$tracker_lang['subject'];?></TD>
<?
if ($mailbox == PM_INBOX )
print ("<TD width=\"35%\" class=\"colhead\">".$tracker_lang['sender']."</TD>");
else
print ("<TD width=\"35%\" class=\"colhead\">".$tracker_lang['receiver']."</TD>");
?>
<TD width="10%" class="colhead"><?=$tracker_lang['date'];?></TD>
<TD width="2%" class="colhead"><INPUT type="checkbox" title="<?=$tracker_lang['mark_all'];?>" value="<?=$tracker_lang['mark_all'];?>" onClick="this.value=check(document.form1.elements);"></TD>
</TR>
<? if ($mailbox != PM_SENTBOX) {
$res = sql_query("SELECT m.*, u.username AS sender_username, s.id AS sfid, r.id AS rfid FROM messages m LEFT JOIN users u ON m.sender = u.id LEFT JOIN friends r ON r.userid = {$CURUSER["id"]} AND r.friendid = m.receiver LEFT JOIN friends s ON s.userid = {$CURUSER["id"]} AND s.friendid = m.sender WHERE receiver=" . sqlesc($CURUSER['id']) . " AND location=" . sqlesc($mailbox) . " ORDER BY id DESC") or sqlerr(__FILE__,__LINE__);
} else {
$res = sql_query("SELECT m.*, u.username AS receiver_username, s.id AS sfid, r.id AS rfid FROM messages m LEFT JOIN users u ON m.receiver = u.id LEFT JOIN friends r ON r.userid = {$CURUSER["id"]} AND r.friendid = m.receiver LEFT JOIN friends s ON s.userid = {$CURUSER["id"]} AND s.friendid = m.sender WHERE sender=" . sqlesc($CURUSER['id']) . " AND saved='yes' ORDER BY id DESC") or sqlerr(__FILE__,__LINE__);
}
if (mysql_num_rows($res) == 0) {
echo("<TD colspan=\"6\" align=\"center\">".$tracker_lang['no_messages'].".</TD>\n");
}
else
{
while ($row = mysql_fetch_assoc($res))
{
// Get Sender Username
if ($row['sender'] != 0) {
$username = "<A href=\"userdetails.php?id=" . $row['sender'] . "\">" . $row["sender_username"] . "</A>";
$id = $row['sender'];
$friend = $row['sfid'];
if ($friend && $CURUSER['id'] != $row['sender']) {
$username .= " <a href=friends.php?action=delete&type=friend&targetid=$id>[óäàëèòü èç äðóçåé]</a>";
}
elseif ($CURUSER['id'] != $row['sender']) {
$username .= " <a href=friends.php?action=add&type=friend&targetid=$id>[äîáàâèòü â äðóçüÿ]</a>";
}
}
else {
$username = $tracker_lang['from_system'];
}
// Get Receiver Username
if ($row['receiver'] != 0) {
$receiver = "<A href=\"userdetails.php?id=" . $row['receiver'] . "\">" . $row["receiver_username"] . "</A>";
$id_r = $row['receiver'];
$friend = $row['rfid'];
if ($friend && $CURUSER['id'] != $row['receiver']) {
$receiver .= " <a href=friends.php?action=delete&type=friend&targetid=$id_r>[óäàëèòü èç äðóçåé]</a>";
}
elseif ($CURUSER['id'] != $row['receiver']) {
$receiver .= " <a href=friends.php?action=add&type=friend&targetid=$id_r>[äîáàâèòü â äðóçüÿ]</a>";
}
}
else {
$receiver = $tracker_lang['from_system'];
}
$subject = htmlspecialchars_uni($row['subject']);
if (strlen($subject) <= 0) {
$subject = $tracker_lang['no_subject'];
}
if ($row['unread'] == 'yes' && $mailbox != PM_SENTBOX) {
echo("<TR>\n<TD ><IMG src=\"pic/pn_inboxnew.gif\" alt=\"".$tracker_lang['mail_unread']."\"></TD>\n");
}
else {
echo("<TR>\n<TD><IMG src=\"pic/pn_inbox.gif\" alt=\"".$tracker_lang['mail_read']."\"></TD>\n");
}
echo("<TD><A href=\"message.php?action=viewmessage&id=" . $row['id'] . "\">" . $subject . "</A></TD>\n");
if ($mailbox != PM_SENTBOX) {
echo("<TD>$username</TD>\n");
}
else {
echo("<TD>$receiver</TD>\n");
}
echo("<TD nowrap>" . display_date_time(strtotime($row['added']), $CURUSER["tzoffset"]) . "</TD>\n");
echo("<TD><INPUT type=\"checkbox\" name=\"messages[]\" title=\"".$tracker_lang['mark']."\" value=\"" . $row['id'] . "\" id=\"checkbox_tbl_" . $row['id'] . "\"></TD>\n</TR>\n");
}
}
?>
<tr class="colhead">
<td colspan="6" align="right" class="colhead">
<input type="hidden" name="box" value="<?=$mailbox?>">
<input type="submit" name="delete" title="<?=$tracker_lang['delete_marked_messages'];?>" value="<?=$tracker_lang['delete'];?>" onClick="return confirm('<?=$tracker_lang['sure_mark_delete'];?>')">
<input type="submit" name="markread" title="<?=$tracker_lang['mark_as_read'];?>" value="<?=$tracker_lang['mark_read'];?>" onClick="return confirm('<?=$tracker_lang['sure_mark_read'];?>')"></form>
</td>
</tr>
</form>
</table>
<div align="left"><img src="pic/pn_inboxnew.gif" alt="Íåïðî÷èòàííûå" /> <?=$tracker_lang['mail_unread_desc'];?><br />
<img src="pic/pn_inbox.gif" alt="Ïðî÷èòàííûå" /> <?=$tracker_lang['mail_read_desc'];?></div>
<?
stdfoot();
}
// êîíåö ïðîñìîòð ïî÷òîâîãî ÿùèêà
// íà÷àëî ïðîñìîòð òåëà ñîîáùåíèÿ
if ($action == "viewmessage") {
$pm_id = (int) $_GET['id'];
if (!$pm_id)
{
stderr($tracker_lang['error'], "Ó âàñ íåò ïðàâ äëÿ ïðîñìîòðà ýòîãî ñîîáùåíèÿ.");
}
// Get the message
$res = sql_query('SELECT * FROM messages WHERE id=' . sqlesc($pm_id) . ' AND (receiver=' . sqlesc($CURUSER['id']) . ' OR (sender=' . sqlesc($CURUSER['id']). ' AND saved=\'yes\')) LIMIT 1') or sqlerr(__FILE__,__LINE__);
if (mysql_num_rows($res) == 0)
{
stderr($tracker_lang['error'],"Òàêîãî ñîîáùåíèÿ íå ñóùåñòâóåò.");
}
// Prepare for displaying message
$message = mysql_fetch_assoc($res);
if ($message['sender'] == $CURUSER['id'])
{
// Display to
$res2 = sql_query("SELECT username FROM users WHERE id=" . sqlesc($message['receiver'])) or sqlerr(__FILE__,__LINE__);
$sender = mysql_fetch_array($res2);
$sender = "<A href=\"userdetails.php?id=" . $message['receiver'] . "\">" . $sender[0] . "</A>";
$reply = "";
$from = "Êîìó";
}
else
{
$from = "Îò êîãî";
if ($message['sender'] == 0)
{
$sender = "Ñèñòåìíîå";
$reply = "";
}
else
{
$res2 = sql_query("SELECT username FROM users WHERE id=" . sqlesc($message['sender'])) or sqlerr(__FILE__,__LINE__);
$sender = mysql_fetch_array($res2);
$sender = "<A href=\"userdetails.php?id=" . $message['sender'] . "\">" . $sender[0] . "</A>";
$reply = " [ <A href=\"message.php?action=sendmessage&receiver=" . $message['sender'] . "&replyto=" . $pm_id . "\">Îòâåòèòü</A> ]";
}
}
$body = format_comment($message['msg']);
$added = display_date_time(strtotime($message['added']), $CURUSER['tzoffset']);
if (get_user_class() >= UC_MODERATOR && $message['sender'] == $CURUSER['id'])
{
$unread = ($message['unread'] == 'yes' ? "<SPAN style=\"color: #FF0000;\"><b>(Íîâîå)</b></A>" : "");
}
else
{
$unread = "";
}
$subject = htmlspecialchars_uni($message['subject']);
if (strlen($subject) <= 0)
{
$subject = "Áåç òåìû";
}
// Mark message unread
sql_query("UPDATE messages SET unread='no' WHERE id=" . sqlesc($pm_id) . " AND receiver=" . sqlesc($CURUSER['id']) . " LIMIT 1");
// Display message
stdhead("Ëè÷íîå Ñîîáùåíèå (Òåìà: $subject)"); ?>
<TABLE width="660" border="0" cellpadding="4" cellspacing="0">
<TR><TD class="colhead" colspan="2">Òåìà: <?=$subject?></TD></TR>
<TR>
<TD width="50%" class="colhead"><?=$from?></TD>
<TD width="50%" class="colhead">Äàòà îòïðàâêè</TD>
</TR>
<TR>
<TD><?=$sender?></TD>
<TD><?=$added?> <?=$unread?></TD>
</TR>
<TR>
<TD colspan="2"><?=$body?></TD>
</TR>
<TR>
<TD align="right" colspan=2>[ <A href="message.php?action=deletemessage&id=<?=$pm_id?>">Óäàëèòü</A> ]<?=$reply?> [ <A href="message.php?action=forward&id=<?=$pm_id?>">Ïåðåñëàòü</A> ]</TD>
</TR>
</TABLE><?
stdfoot();
}
// êîíåö ïðîñìîòð òåëà ñîîáùåíèÿ
// íà÷àëî ïðîñìîòð ïîñûëêà ñîîáùåíèÿ
if ($action == "sendmessage") {
$receiver = $_GET["receiver"];
if (!is_valid_id($receiver))
stderr($tracker_lang['error'], "Íåâåðíîå ID ïîëó÷àòåëÿ");
$replyto = $_GET["replyto"];
if ($replyto && !is_valid_id($replyto))
stderr($tracker_lang['error'], "Íåâåðíîå ID ñîîáùåíèÿ");
$auto = $_GET["auto"];
$std = $_GET["std"];
if (($auto || $std ) && get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
$res = sql_query("SELECT * FROM users WHERE id=$receiver") or die(mysql_error());
$user = mysql_fetch_assoc($res);
if (!$user)
stderr($tracker_lang['error'], "Ïîëüçîâàòåëÿ ñ òàêèì ID íå ñóùåñòâóåò.");
if ($auto)
$body = $pm_std_reply[$auto];
if ($std)
$body = $pm_template[$std][1];
if ($replyto) {
$res = sql_query("SELECT * FROM messages WHERE id=$replyto") or sqlerr(__FILE__, __LINE__);
$msga = mysql_fetch_assoc($res);
if ($msga["receiver"] != $CURUSER["id"])
stderr($tracker_lang['error'], "Âû ïûòàåòåñü îòâåòèòü íå íà ñâîå ñîîáùåíèå!");
$res = sql_query("SELECT username FROM users WHERE id=" . $msga["sender"]) or sqlerr(__FILE__, __LINE__);
$usra = mysql_fetch_assoc($res);
$body .= "\n\n\n-------- $usra[username] ïèñàë(à): --------\n".htmlspecialchars_uni($msga['msg'])."\n";
// Change
$subject = "Re: " . htmlspecialchars_uni($msga['subject']);
// End of Change
}
stdhead("Îòñûëêà ñîîáùåíèé", false);
?>
<table class=main border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>
<form name=message method=post action=message.php>
<input type=hidden name=action value=takemessage>
<table class=message cellspacing=0 cellpadding=5>
<tr><td colspan=2 class=colhead>Ñîîáùåíèå äëÿ <a class=altlink_white href=userdetails.php?id=<?=$receiver?>><?=$user["username"]?></a></td></tr>
<TR>
<TD colspan="2"><B>Òåìà: </B>
<INPUT name="subject" type="text" size="60" value="<?=$subject?>" maxlength="255"></TD>
</TR>
<tr><td<?=$replyto?" colspan=2":""?>>
<?
textbbcode("message","msg","$body");
?>
</td></tr>
<tr>
<? if ($replyto) { ?>
<td align=center><input type=checkbox name='delete' value='yes' <?=$CURUSER['deletepms'] == 'yes'?"checked":""?>>Óäàëèòü ñîîáùåíèå ïîñëå îòâåòà
<input type=hidden name=origmsg value=<?=$replyto?>></td>
<? } ?>
<td align=center><input type=checkbox name='save' value='yes' <?=$CURUSER['savepms'] == 'yes'?"checked":""?>>Ñîõðàíèòü ñîîáùåíèå â îòïðàâëåííûõ</td></tr>
<tr><td<?=$replyto?" colspan=2":""?> align=center><input type=submit value="Ïîñëàòü!" class=btn></td></tr>
</table>
<input type=hidden name=receiver value=<?=$receiver?>>
</form>
</div></td></tr></table>
<?
stdfoot();
}
// êîíåö ïîñûëêà ñîîáùåíèÿ
// íà÷àëî ïðèåì ïîñëàííîãî ñîîáùåíèÿ
if ($action == 'takemessage') {
$receiver = $_POST["receiver"];
$origmsg = $_POST["origmsg"];
$save = $_POST["save"];
$returnto = $_POST["returnto"];
if (!is_valid_id($receiver) || ($origmsg && !is_valid_id($origmsg)))
stderr($tracker_lang['error'],"Íåâåðíûé ID");
$msg = trim($_POST["msg"]);
if (!$msg)
stderr($tracker_lang['error'],"Ïîæàëóéñòà ââåäèòå ñîîáùåíèå!");
$subject = trim($_POST['subject']);
if (!$subject)
stderr($tracker_lang['error'],"Ïîæàëóéñòà ââåäèòå òåìó ñîîáùåíèÿ!");
// Change
$save = ($save == 'yes') ? "yes" : "no";
// End of Change
$res = sql_query("SELECT email, acceptpms, notifs, parked, UNIX_TIMESTAMP(last_access) as la FROM users WHERE id=$receiver") or sqlerr(__FILE__, __LINE__);
$user = mysql_fetch_assoc($res);
if (!$user)
stderr($tracker_lang['error'], "Íåò ïîëüçîâàòåëÿ ñ òàêèì ID $receiver.");
//Make sure recipient wants this message
if ($user["parked"] == "yes")
stderr($tracker_lang['error'], "Ýòîò àêêàóíò ïðèïàðêîâàí.");
if (get_user_class() < UC_MODERATOR)
{
if ($user["acceptpms"] == "yes")
{
$res2 = sql_query("SELECT * FROM blocks WHERE userid=$receiver AND blockid=" . $CURUSER["id"]) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res2) == 1)
sttderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü äîáàâèë âàñ â ÷åðíûé ñïèñîê.");
}
elseif ($user["acceptpms"] == "friends")
{
$res2 = sql_query("SELECT * FROM friends WHERE userid=$receiver AND friendid=" . $CURUSER["id"]) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res2) != 1)
stderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü ïðèíèìàåò ñîîáùåíèå òîëüêî èç ñïèñêà ñâîèõ äðóçåé");
}
elseif ($user["acceptpms"] == "no")
stderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü íå ïðèíèìàåò ñîîáùåíèÿ.");
}
sql_query("INSERT INTO messages (poster, sender, receiver, added, msg, subject, saved, location) VALUES(" . $CURUSER["id"] . ", " . $CURUSER["id"] . ",
$receiver, '" . get_date_time() . "', " . sqlesc($msg) . ", " . sqlesc($subject) . ", " . sqlesc($save) . ", 1)") or sqlerr(__FILE__, __LINE__);
$sended_id = mysql_insert_id();
if (strpos($user['notifs'], '[pm]') !== false) {
$username = $CURUSER["username"];
$usremail = $user["email"];
$body = <<<EOD
$username ïîñëàë âàì ëè÷íîå ñîîáùåíèå!
Ïðîéäèòå ïî ññûëêå íèæå, ÷òîáû åãî ïðî÷èòàòü.
$DEFAULTBASEURL/message.php?action=viewmessage&id=$sended_id
--
$SITENAME
EOD;
$subj = "Âû ïîëó÷èëè íîâîå ËÑ îò $username!";
sent_mail($usremail, $SITENAME, $SITEEMAIL, $subj, $body, false);
}
$delete = $_POST["delete"];
if ($origmsg)
{
if ($delete == "yes")
{
// Make sure receiver of $origmsg is current user
$res = sql_query("SELECT * FROM messages WHERE id=$origmsg") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 1)
{
$arr = mysql_fetch_assoc($res);
if ($arr["receiver"] != $CURUSER["id"])
stderr($tracker_lang['error'],"Âû ïûòàåòåñü óäàëèòü íå ñâîå ñîîáùåíèå!");
if ($arr["saved"] == "no")
sql_query("DELETE FROM messages WHERE id=$origmsg") or sqlerr(__FILE__, __LINE__);
elseif ($arr["saved"] == "yes")
sql_query("UPDATE messages SET unread = 'no', location = '0' WHERE id=$origmsg") or sqlerr(__FILE__, __LINE__);
}
}
if (!$returnto)
$returnto = "$DEFAULTBASEURL/message.php";
}
if ($returnto) {
header("Location: $returnto");
die;
}
else {
header ("Refresh: 2; url=message.php");
stderr($tracker_lang['success'] , "Ñîîáùåíèå áûëî óñïåøíî îòïðàâëåíî!");
}
}
// êîíåö ïðèåì ïîñëàííîãî ñîîáùåíèÿ
//íà÷àëî ìàññîâàÿ ðàññûëêà
if ($action == 'mass_pm') {
if (get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
$n_pms = intval($_POST['n_pms']);
$pmees = $_POST['pmees'];
$auto = $_POST['auto'];
if ($auto)
$body=$mm_template[$auto][1];
stdhead("Îòñûëêà ñîîáùåíèé", false);
?>
<table class=main border=0 cellspacing=0 cellpadding=0>
<tr><td class=embedded><div align=center>
<form method=post action=<?=htmlspecialchars_uni($_SERVER['PHP_SELF']);?> name=message>
<input type=hidden name=action value=takemass_pm>
<? if ($_SERVER["HTTP_REFERER"]) { ?>
<input type=hidden name=returnto value="<?=htmlspecialchars_uni($_SERVER["HTTP_REFERER"]);?>">
<? } ?>
<table border=1 cellspacing=0 cellpadding=5>
<tr><td class=colhead colspan=2>Ìàññîâàÿ ðàññûëêà äëÿ <?=$n_pms?> ïîëüçîâàòå<?=($n_pms>1?"ëåé":"ëÿ")?></td></tr>
<TR>
<TD colspan="2"><B>Òåìà: </B>
<INPUT name="subject" type="text" size="60" maxlength="255"></TD>
</TR>
<tr><td colspan="2"><div align="center">
<?=textbbcode("message","msg","$body");?>
</div></td></tr>
<tr><td colspan="2"><div align="center"><b>Êîììåíòàðèé: </b>
<input name="comment" type="text" size="70">
</div></td></tr>
<tr><td><div align="center"><b>Îò: </b>
<?=$CURUSER['username']?>
<input name="sender" type="radio" value="self" checked>
Ñèñòåìíîå
<input name="sender" type="radio" value="system">
</div></td>
<td><div align="center"><b>Take snapshot:</b> <input name="snap" type="checkbox" value="1">
</div></td></tr>
<tr><td colspan="2" align=center><input type=submit value="Ïîñëàòü!" class=btn>
</td></tr></table>
<input type=hidden name=pmees value="<?=$pmees?>">
<input type=hidden name=n_pms value=<?=$n_pms?>>
</form><br /><br />
</div>
</td>
</tr>
</table>
<?
stdfoot();
}
//êîíåö ìàññîâàÿ ðàññûëêà
//íà÷àëî ïðèåì ñîîáùåíèé èç ìàññîâîé ðàññûëêè
if ($action == 'takemass_pm') {
if (get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
$msg = trim($_POST["msg"]);
if (!$msg)
stderr($tracker_lang['error'],"Ïîæàëóéñòà ââåäèòå ñîîáùåíèå.");
$sender_id = ($_POST['sender'] == 'system' ? 0 : $CURUSER['id']);
$from_is = unesc($_POST['pmees']);
// Change
$subject = trim($_POST['subject']);
$query = "INSERT INTO messages (sender, receiver, added, msg, subject, location, poster) ". "SELECT $sender_id, u.id, '" . get_date_time(time()) . "', " .
sqlesc($msg) . ", " . sqlesc($subject) . ", 1, $sender_id " . $from_is;
// End of Change
sql_query($query) or sqlerr(__FILE__, __LINE__);
$n = mysql_affected_rows();
$n_pms = $_POST['n_pms'];
$comment = $_POST['comment'];
$snapshot = $_POST['snap'];
// add a custom text or stats snapshot to comments in profile
if ($comment || $snapshot)
{
$res = sql_query("SELECT u.id, u.uploaded, u.downloaded, u.modcomment ".$from_is) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$l = 0;
while ($user = mysql_fetch_array($res))
{
unset($new);
$old = $user['modcomment'];
if ($comment)
$new = $comment;
if ($snapshot)
{
$new .= ($new?"\n":"") . "MMed, " . date("Y-m-d") . ", " .
"UL: " . mksize($user['uploaded']) . ", " .
"DL: " . mksize($user['downloaded']) . ", " .
"r: " . (($user['downloaded'] > 0)?($user['uploaded']/$user['downloaded']) : 0) . " - " .
($_POST['sender'] == "system"?"System":$CURUSER['username']);
}
$new .= $old?("\n".$old):$old;
sql_query("UPDATE users SET modcomment = " . sqlesc($new) . " WHERE id = " . $user['id']) or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows())
$l++;
}
}
}
header ("Refresh: 3; url=message.php");
stderr($tracker_lang['success'], (($n_pms > 1) ? "$n ñîîáùåíèé èç $n_pms áûëî" : "Ñîîáùåíèå áûëî")." óñïåøíî îòïðàâëåíî!" . ($l ? " $l êîììåíòàðèé(åâ) â ïðîôèëå " . (($l>1) ? "áûëè" : " áûë") . " îáíîâëåí!" : ""));
}
//êîíåö ïðèåì ñîîáùåíèé èç ìàññîâîé ðàññûëêè
//íà÷àëî ïåðåìåùåíèå, ïîìå÷àíèå êàê ïðî÷èòàííîãî
if ($action == "moveordel") {
$pm_id = (int) $_POST['id'];
$pm_box = (int) $_POST['box'];
$pm_messages = $_POST['messages'];
if ($_POST['move']) {
if ($pm_id) {
// Move a single message
@sql_query("UPDATE messages SET location=" . sqlesc($pm_box) . ", saved = 'yes' WHERE id=" . sqlesc($pm_id) . " AND receiver=" . $CURUSER['id'] . " LIMIT 1");
}
else {
// Move multiple messages
@sql_query("UPDATE messages SET location=" . sqlesc($pm_box) . ", saved = 'yes' WHERE id IN (" . implode(", ", array_map("sqlesc", array_map("intval", $pm_messages))) . ') AND receiver=' . $CURUSER['id']);
}
// Check if messages were moved
if (@mysql_affected_rows() == 0) {
stderr($tracker_lang['error'], "Íå âîçìîæíî ïåðåìåñòèòü ñîîáùåíèÿ!");
}
header("Location: message.php?action=viewmailbox&box=" . $pm_box);
exit();
}
elseif ($_POST['delete']) {
if ($pm_id) {
// Delete a single message
$res = sql_query("SELECT * FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
$message = mysql_fetch_assoc($res);
if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no') {
sql_query("DELETE FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED) {
sql_query("DELETE FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes') {
sql_query("UPDATE messages SET location=0 WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED) {
sql_query("UPDATE messages SET saved='no' WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
} else {
// Delete multiple messages
if (is_array($pm_messages))
foreach ($pm_messages as $id) {
$res = sql_query("SELECT * FROM messages WHERE id=" . sqlesc((int) $id));
$message = mysql_fetch_assoc($res);
if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no') {
sql_query("DELETE FROM messages WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED) {
sql_query("DELETE FROM messages WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes') {
sql_query("UPDATE messages SET location = " . PM_DELETED . ", unread = 'no' WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED) {
sql_query("UPDATE messages SET saved='no' WHERE id=" . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
}
}
}
// Check if messages were moved
if (@mysql_affected_rows() == 0) {
stderr($tracker_lang['error'],"Ñîîáùåíèå íå ìîæåò áûòü óäàëåíî!");
}
else {
header("Location: message.php?action=viewmailbox&box=" . $pm_box);
exit();
}
}
elseif ($_POST["markread"]) {
//ïîìå÷àåì îäíî ñîîáùåíèå
if ($pm_id) {
sql_query("UPDATE messages SET unread='no' WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
//ïîìå÷àåì ìíîæåñòâî ñîîáùåíèé
else {
if (is_array($pm_messages))
foreach ($pm_messages as $id) {
$res = sql_query("SELECT * FROM messages WHERE id=" . sqlesc((int) $id));
$message = mysql_fetch_assoc($res);
sql_query("UPDATE messages SET unread='no' WHERE id = " . sqlesc((int) $id)) or sqlerr(__FILE__,__LINE__);
}
}
// Ïðîâåðÿåì, áûëè ëè ïîìå÷åíû ñîîáùåíèÿ
if (@mysql_affected_rows() == 0) {
stderr($tracker_lang['error'], "Ñîîáùåíèå íå ìîæåò áûòü ïîìå÷åíî êàê ïðî÷èòàííîå! ");
}
else {
header("Location: message.php?action=viewmailbox&box=" . $pm_box);
exit();
}
}
stderr($tracker_lang['error'],"Íåò äåéñòâèÿ.");
}
//êîíåö ïåðåìåùåíèå, ïîìå÷àíèå êàê ïðî÷èòàííîãî
//íà÷àëî ïåðåñûëêà
if ($action == "forward") {
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// Display form
$pm_id = (int) $_GET['id'];
// Get the message
$res = sql_query('SELECT * FROM messages WHERE id=' . sqlesc($pm_id) . ' AND (receiver=' . sqlesc($CURUSER['id']) . ' OR sender=' . sqlesc($CURUSER['id']) . ') LIMIT 1') or sqlerr(__FILE__,__LINE__);
if (!$res) {
stderr($tracker_lang['error'], "Ó âàñ íåò ðàçðåøåíèÿ ïåðåñûëàòü ýòî ñîîáùåíèå.");
}
if (mysql_num_rows($res) == 0) {
stderr($tracker_lang['error'], "Ó âàñ íåò ðàçðåøåíèÿ ïåðåñûëàòü ýòî ñîîáùåíèå.");
}
$message = mysql_fetch_assoc($res);
// Prepare variables
$subject = "Fwd: " . htmlspecialchars_uni($message['subject']);
$from = $message['sender'];
$orig = $message['receiver'];
$res = sql_query("SELECT username FROM users WHERE id=" . sqlesc($orig) . " OR id=" . sqlesc($from)) or sqlerr(__FILE__,__LINE__);
$orig2 = mysql_fetch_assoc($res);
$orig_name = "<A href=\"userdetails.php?id=" . $from . "\">" . $orig2['username'] . "</A>";
if ($from == 0) {
$from_name = "Ñèñòåìíîå";
$from2['username'] = "Ñèñòåìíîå";
}
else {
$from2 = mysql_fetch_array($res);
$from_name = "<A href=\"userdetails.php?id=" . $from . "\">" . $from2['username'] . "</A>";
}
$body = "-------- Îðèãèíàëüíîå ñîîáùåíèå îò " . $from2['username'] . ": --------<BR>" . format_comment($message['msg']);
stdhead($subject);?>
<FORM action="message.php" method="post">
<INPUT type="hidden" name="action" value="forward">
<INPUT type="hidden" name="id" value="<?=$pm_id?>">
<TABLE border="0" cellpadding="4" cellspacing="0">
<TR><TD class="colhead" colspan="2"><?=$subject?></TD></TR>
<TR>
<TD>Êîìó:</TD>
<TD><INPUT type="text" name="to" value="Ââåäèòå èìÿ" size="83"></TD>
</TR>
<TR>
<TD>Îðèãèíàëüíûé<BR>îòïðàâèòåëü:</TD>
<TD><?=$orig_name?></TD>
</TR>
<TR>
<TD>Îò:</TD>
<TD><?=$from_name?></TD>
</TR>
<TR>
<TD>Òåìà:</TD>
<TD><INPUT type="text" name="subject" value="<?=$subject?>" size="83"></TD>
</TR>
<TR>
<TD>Ñîîáùåíèå:</TD>
<TD><TEXTAREA name="msg" cols="80" rows="8"></TEXTAREA><BR><?=$body?></TD>
</TR>
<TR>
<TD colspan="2" align="center">Ñîõðàíèòü ñîîáùåíèå <INPUT type="checkbox" name="save" value="1"<?=$CURUSER['savepms'] == 'yes'?" checked":""?>> <INPUT type="submit" value="Ïåðåñëàòü"></TD>
</TR>
</TABLE>
</FORM><?
stdfoot();
}
else {
// Forward the message
$pm_id = (int) $_POST['id'];
// Get the message
$res = sql_query('SELECT * FROM messages WHERE id=' . sqlesc($pm_id) . ' AND (receiver=' . sqlesc($CURUSER['id']) . ' OR sender=' . sqlesc($CURUSER['id']) . ') LIMIT 1') or sqlerr(__FILE__,__LINE__);
if (!$res) {
stderr($tracker_lang['error'], "Ó âàñ íåò ðàçðåøåíèÿ ïåðåñûëàòü ýòî ñîîáùåíèå.");
}
if (mysql_num_rows($res) == 0) {
stderr($tracker_lang['error'], "Ó âàñ íåò ðàçðåøåíèÿ ïåðåñûëàòü ýòî ñîîáùåíèå.");
}
$message = mysql_fetch_assoc($res);
$subject = (string) $_POST['subject'];
$username = strip_tags($_POST['to']);
// Try finding a user with specified name
$res = sql_query("SELECT id FROM users WHERE LOWER(username)=LOWER(" . sqlesc($username) . ") LIMIT 1");
if (!$res) {
stderr($tracker_lang['error'], "Ïîëüçîâàòåëÿ, ñ òàêèì èìåíåì íå ñóùåñòâóåò.");
}
if (mysql_num_rows($res) == 0) {
stderr($tracker_lang['error'], "Ïîëüçîâàòåëÿ, ñ òàêèì èìåíåì íå ñóùåñòâóåò.");
}
$to = mysql_fetch_array($res);
$to = $to[0];
// Get Orignal sender's username
if ($message['sender'] == 0) {
$from = "Ñèñòåìíîå";
}
else {
$res = sql_query("SELECT * FROM users WHERE id=" . sqlesc($message['sender'])) or sqlerr(__FILE__,__LINE__);
$from = mysql_fetch_assoc($res);
$from = $from['username'];
}
$body = (string) $_POST['msg'];
$body .= "\n-------- Îðèãèíàëüíîå ñîîáùåíèå îò " . $from . ": --------\n" . $message['msg'];
$save = (int) $_POST['save'];
if ($save) {
$save = 'yes';
}
else {
$save = 'no';
}
//Make sure recipient wants this message
if (get_user_class() < UC_MODERATOR) {
if ($from["acceptpms"] == "yes") {
$res2 = sql_query("SELECT * FROM blocks WHERE userid=$to AND blockid=" . $CURUSER["id"]) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res2) == 1)
stderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü äîáàâèë âàñ â ÷åðíûé ñïèñîê.");
}
elseif ($from["acceptpms"] == "friends") {
$res2 = sql_query("SELECT * FROM friends WHERE userid=$to AND friendid=" . $CURUSER["id"]) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res2) != 1)
stderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü ïðèíèìàåò ñîîáùåíèå òîëüêî èç ñïèñêà ñâîèõ äðóçåé.");
}
elseif ($from["acceptpms"] == "no")
stderr("Îòêëîíåíî", "Ýòîò ïîëüçîâàòåëü íå ïðèíèìàåò ñîîáùåíèÿ.");
}
sql_query("INSERT INTO messages (poster, sender, receiver, added, subject, msg, location, saved) VALUES(" . $CURUSER["id"] . ", " . $CURUSER["id"] . ", $to, '" . get_date_time() . "', " . sqlesc($subject) . "," . sqlesc($body) . ", " . sqlesc(PM_INBOX) . ", " . sqlesc($save) . ")") or sqlerr(__FILE__, __LINE__);
stderr("Óäà÷íî", "ËÑ ïåðåñëàíî.");
}
}
//êîíåö ïåðåñûëêà
//íà÷àëî óäàëåíèå ñîîáùåíèÿ
if ($action == "deletemessage") {
$pm_id = (int) $_GET['id'];
// Delete message
$res = sql_query("SELECT * FROM messages WHERE id=" . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
if (!$res) {
stderr($tracker_lang['error'],"Ñîîáùåíèÿ ñ òàêèì ID íå ñóùåñòâóåò.");
}
if (mysql_num_rows($res) == 0) {
stderr($tracker_lang['error'],"Ñîîáùåíèÿ ñ òàêèì ID íå ñóùåñòâóåò.");
}
$message = mysql_fetch_assoc($res);
if ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'no') {
$res2 = sql_query("DELETE FROM messages WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] == PM_DELETED) {
$res2 = sql_query("DELETE FROM messages WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['receiver'] == $CURUSER['id'] && $message['saved'] == 'yes') {
$res2 = sql_query("UPDATE messages SET location = " . PM_DELETED . ", unread = 'no' WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
elseif ($message['sender'] == $CURUSER['id'] && $message['location'] != PM_DELETED) {
$res2 = sql_query("UPDATE messages SET saved = 'no' WHERE id = " . sqlesc($pm_id)) or sqlerr(__FILE__,__LINE__);
}
if (!$res2) {
stderr($tracker_lang['error'],"Íåâîçìîæíî óäàëèòü ñîîáùåíèå.");
}
if (mysql_affected_rows() == 0) {
stderr($tracker_lang['error'],"Íåâîçìîæíî óäàëèòü ñîîáùåíèå.");
}
else {
header("Location: message.php?action=viewmailbox&id=" . $message['location']);
exit();
}
}
//êîíåö óäàëåíèå ñîîáùåíèÿ
?>