-
Notifications
You must be signed in to change notification settings - Fork 50
/
mailbox.php
executable file
·218 lines (199 loc) · 6.95 KB
/
mailbox.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
<?php
session_start();
require "global_func.php";
if ($_SESSION['loggedin'] == 0)
{
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is =
mysql_query(
"SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
$c) or die(mysql_error());
$ir = mysql_fetch_array($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
if ($ir['mailban'])
{
die(
"<font color=red><h3>! ERROR</h3>
You have been mail banned for {$ir['mailban']} days.<br />
<br />
<b>Reason: {$ir['mb_reason']}</font></b>");
}
$_GET['ID'] = abs((int) $_GET['ID']);
print
"<table width=75% border=2><tr><td><a href='mailbox.php?action=inbox'>Inbox</a></td> <td><a href='mailbox.php?action=outbox'>Sent Messages</a></td> <td><a href='mailbox.php?action=compose'>Compose Message</a></td> <td><a href='mailbox.php?action=delall'>Delete All Messages</a></td> <td><a href='mailbox.php?action=archive'>Archive Messages</a></td></tr> </table><br />";
switch ($_GET['action'])
{
case 'inbox':
mail_inbox();
break;
case 'outbox':
mail_outbox();
break;
case 'compose':
mail_compose();
break;
case 'delete':
mail_delete();
break;
case 'send':
mail_send();
break;
case 'delall':
mail_delall();
break;
case 'delall2':
mail_delall2();
break;
case 'archive':
mail_archive();
break;
default:
mail_inbox();
break;
}
function mail_inbox()
{
global $ir, $c, $userid, $h;
print
"Only the last 25 messages sent to you are visible.<br />
<table width=75% border=2><tr style='background:gray'><th>From</th><th>Subject/Message</th></tr>";
$q =
mysql_query(
"SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_to=$userid ORDER BY mail_time DESC LIMIT 25",
$c);
while ($r = mysql_fetch_array($q))
{
$sent = date('F j, Y, g:i:s a', $r['mail_time']);
print "<tr><td>";
if ($r['userid'])
{
print
"<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]";
}
else
{
print "SYSTEM";
}
$fm = urlencode($r['mail_text']);
print
"</td>\n<td>{$r['mail_subject']}</td></tr><tr><td>Sent at: $sent<br /><a href='mailbox.php?action=compose&ID={$r['userid']}'>Reply</a><br />
<a href='mailbox.php?action=delete&ID={$r['mail_id']}'>Delete</a> <br />
<a href='preport.php?ID={$r['userid']}&report=Fradulent mail: {$fm}'>Report</a></td><td>{$r['mail_text']}</td></tr>";
}
mysql_query("UPDATE mail SET mail_read=1 WHERE mail_to=$userid", $c);
}
function mail_outbox()
{
global $ir, $c, $userid, $h;
print
"Only the last 25 messages you have sent are visible.<br />
<table width=75% border=2><tr style='background:gray'><th>To</th><th>Subject/Message</th></tr>";
$q =
mysql_query(
"SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_to=u.userid WHERE m.mail_from=$userid ORDER BY mail_time DESC LIMIT 25",
$c);
while ($r = mysql_fetch_array($q))
{
$sent = date('F j, Y, g:i:s a', $r['mail_time']);
print
"<tr><td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td><td>{$r['mail_subject']}</td></tr><tr><td>Sent at: $sent<br /></td><td>{$r['mail_text']}</td></tr>";
}
}
function mail_compose()
{
global $ir, $c, $userid, $h;
print
"<form action='mailbox.php?action=send' method='post'>
<table width=75% border=2> <tr>
<td>ID to send to:</td> <td><input type='text' name='userid' value='{$_GET['ID']}' /></td></tr><tr>
<td>Subject:</td> <td><input type='text' name='subject' /></td></tr><tr>
<td>Message:</td>
<td><textarea rows=5 cols=40 name='message'></textarea></td></tr><tr> <td colspan=2><input type='submit' value='Send' /></td></tr></table></form>";
if ($_GET['ID'])
{
print
"<br /><table width=75% border=2><tr><td colspan=2><b>Your last 5 mails to/from this person:</b></td></tr>";
$q =
mysql_query(
"SELECT m.*,u1.username as sender from mail m left join users u1 on m.mail_from=u1.userid WHERE (m.mail_from=$userid AND m.mail_to={$_GET['ID']}) OR (m.mail_to=$userid AND m.mail_from={$_GET['ID']}) ORDER BY m.mail_time DESC LIMIT 5",
$c);
while ($r = mysql_fetch_array($q))
{
$sent = date('F j, Y, g:i:s a', $r['mail_time']);
print
"<tr><td>$sent</td> <td><b>{$r['sender']} wrote:</b> {$r['mail_text']}</td></tr>";
}
print "</table>";
}
}
function mail_send()
{
global $ir, $c, $userid, $h;
$subj =
mysql_real_escape_string(
str_replace(array("\n"), array("<br />"),
htmlentities(
stripslashes(strip_tags($_POST['subject'])),
ENT_QUOTES, 'ISO-8859-1')), $c);
$msg =
mysql_real_escape_string(
str_replace(array("\n"), array("<br />"),
htmlentities(
stripslashes(strip_tags($_POST['message'])),
ENT_QUOTES, 'ISO-8859-1')), $c);
$to = (int) $_POST['userid'];
mysql_query(
"INSERT INTO mail VALUES(NULL,0,$userid,$to," . time()
. ",'$subj','$msg')", $c) or die(mysql_error());
print "Message sent.<br />
<a href='mailbox.php'>> Back</a>";
}
function mail_delete()
{
global $ir, $c, $userid, $h;
mysql_query(
"DELETE FROM mail WHERE mail_id={$_GET['ID']} AND mail_to=$userid",
$c);
print "Message deleted.<br />
<a href='mailbox.php'>> Back</a>";
}
function mail_delall()
{
global $ir, $c, $userid, $h;
print
"This will delete all the messages in your inbox.<br />
There is <b>NO</b> undo, so be sure.<br />
<a href='mailbox.php?action=delall2'>> Yes, delete all messages</a><br />
<a href='mailbox.php'>> No, go back</a>";
}
function mail_delall2()
{
global $ir, $c, $userid, $h;
mysql_query("DELETE FROM mail WHERE mail_to='$userid'", $c);
print
"All " . mysql_affected_rows($c)
. " mails in your inbox were deleted.<br />
<a href='mailbox.php'>> Back</a>";
}
function mail_archive()
{
global $ir, $c, $userid, $h;
print
"This tool will download an archive of all your messages.<br />
<a href='dlarchive.php?a=inbox'>> Download Inbox</a><br />
<a href='dlarchive.php?a=outbox'>> Download Outbox</a>";
}
$h->endpage();