This repository has been archived by the owner on Dec 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pm.php
190 lines (178 loc) · 6.08 KB
/
pm.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
<?php
require_once('functions.php');
if ($login != true) {
redirect('failed.php?id=3');
} else {
$current_folder = 'inbox';
// INBOX
if ($get_action == 'inbox' || $get_action == '') {
title("Inbox");
page_header('Inbox');
?>
<p>Current Folder: <?php print $current_folder ?></p>
<p>Total Usage: <?php print pm_usage() ?> (Used/Maximum)</p>
<p><a href="?act=inbox&action=compose">Compose</a></p>
<form method="post" role="form" action="?action=change_folder">
Change Folder:
<div class="form-group">
<div class="col-sm-2">
<select name="folder" class="form-control">
<option value="inbox" selected="selected">Inbox</option>
<option value="outbox">Outbox</option>
<option value="drafts">Drafts</option>
<option value="sent">Sent</option>
<option value="trash">Trash</option>
<option value="spam">Spam</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Go!</button>
</div>
</form>
<?php
$results = $db->get_results("SELECT * FROM `personal_messages` WHERE `to_user_id` = $user_id ORDER BY `timestamp`");
if ($results) {
?>
<table class="table">
<tr>
<td>Number</td>
<td>From</td>
<td>Subject</td>
<td>Date</td>
<td>Options</td>
</tr>
<?php
$count = 1;
foreach ($results as $message) {
?>
<tr>
<td><?php print $count ?></td>
<td><?php print id2username($message->from_user_id) ?></td>
<td><?php print $message->subject ?></td>
<td><?php print timestamp2date($message->timestamp) ?></td>
<td><a href="?action=read&id=<?php print $message->id ?>">Read</a> | <a href="?action=reply&id=<?php print $message->id ?>">Reply</a> | <a href="?action=move&id=<?php print $message->id ?>">Move</a> | <a href="?action=delete&id=<?php print $message->id ?>">Delete</a></td>
</tr>
<?php
$count++;
};
} else {
?>
<h4>You have no messages</h4>
<?php
};
?>
</table>
<?php
};
// READ
if ($get_action == 'read') {
if ($get_id != '') {
$message = $db->get_row("SELECT * FROM `personal_messages` WHERE `id` = $get_id");
title($message->subject);
page_header($message->subject);
?>
<p><strong>Subject:</strong> <?php print $message->subject ?></p>
<p><strong>From:</strong> <?php print id2username($message->from_user_id) ?></p>
<p><strong>To:</strong> <?php print id2username($message->to_user_id) ?></p>
<p><strong>Date:</strong> <?php print timestamp2date($message->timestamp) ?></p>
<p><?php print $message->text ?></p>
<a href="?action=reply&id=<?php print $message->id ?>">Reply</a> | <a href="index.php?action=move&id=<?php print $message->id ?>">Move</a> | <a href="index.php?action=delete&id=<?php print $message->id ?>">Delete</a>
<?php
};
};
// REPLY
if ($get_action == 'reply') {
if ($get_id != '') {
$message = $db->get_row("SELECT * FROM `personal_messages` WHERE `id` = $get_id");
title($message->subject);
page_header('Reply to ' . $message->subject);
?>
<form method="post" role="form" action="?action=submit_reply">
<div class="form-group">
<label>To:</label>
<input type="text" class="form-control" name="to" value="<?php print id2username($message->from_user_id) ?>" /></p>
</div>
<div class="form-group">
<label>Subject:</label>
<input type="text" class="form-control" name="subject" value="RE: <?php print $message->subject ?>" /></p>
</div>
<div class="form-group">
<label>Body:</label>
<textarea name="body" class="form-control"><quote><?php print $message->text ?></quote></textarea>
</div>
<button type="submit" class="btn btn-lg btn-primary" name="submit">Send Message</button>
</form>
<?php
};
};
// SUBMIT REPLY
if ($get_action == 'submit_reply') {
$to_id = username2id($_POST['to']);
if ($to_id == -1) {
page_header("Username not found");
?>
Username not found
<?php
} else {
$subject = $_POST['subject'];
$body = $_POST['body'];
$db->query("INSERT INTO `personal_messages` (`subject`, `from_user_id`, `to_user_id`, `text`) VALUES ('$subject', '$user_id', '$to_id', '$body')");
page_header('Message Sent!');
?>
Message sent!
<?php
};
};
// COMPOSE MESSAGE
if ($get_action == 'compose') {
title("Compose New Message");
page_header('Compose New Message');
?>
<form method="post" action="?action=submit_reply">
<div class="form-group">
<label>To:</label>
<input type="text" class="form-control" name="to" value="" />
</div>
<div class="form-group">
<label>Subject:</label>
<input type="text" class="form-control" name="subject" value="" />
</div>
<div class="form-group">
<label>Body:</label>
<textarea name="body" class="form-control" rows="10" cols="50"></textarea>
</div>
<button type="submit" class="btn btn-lg btn-primary" name="submit">Send Message</button>
</form>
<?php
};
// DELETE MESSAGE
if ($get_action == 'delete') {
if ($get_id != '') {
page_header('Delete Message');
$message = $db->get_row("SELECT * FROM `personal_messages` WHERE `id` = $get_id");
?>
<h2>Are you sure you want to delete this message?</h2>
<p><strong>Subject:</strong> <?php print $message->subject ?></p>
<p><strong>From:</strong> <?php print id2username($message->from_user_id) ?></p>
<p><strong>To:</strong> <?php print id2username($message->to_user_id) ?></p>
<p><strong>Date:</strong> <?php print timestamp2date($message->timestamp) ?></p>
<p><strong>Message:</strong> <?php print $message->text ?></p>
<form action="?action=submit_delete&id=<?php print $message->id ?>" class="form" role="form" method="post">
<button type="submit" class="btn btn-lg btn-primary">Yes, delete this message</button>
<button type="button" class="btn btn-lg" onclick="history.go(-1)">No</button>
</form>
<?php
};
};
if ($get_action == 'submit_delete') {
$db->query("DELETE FROM `personal_messages` WHERE `id` = $get_id");
page_header('Message has been deleted');
?>
Message has been deleted.
<?php
};
if($get_action == 'change_folder') {
print '<center>not implemented yet</center>';
};
};
require_once('footer.php');
?>