190 lines
6 KiB
PHP
190 lines
6 KiB
PHP
<?php
|
|
// Require core components
|
|
require_once __DIR__ . '/../startup.php';
|
|
|
|
// Initialise Markdown parser
|
|
$parser = new Parsedown();
|
|
|
|
print desHeader($flashii->loggedIn() ? 'Messages' : 'Login to view');
|
|
|
|
if($flashii->loggedIn()) {
|
|
print '<div class="messageFoldersContainer">';
|
|
|
|
print '<a href="/m/inbox" class="messagesFolder" id="inbox">';
|
|
print 'Inbox';
|
|
print '</a>';
|
|
|
|
print '<a href="/m/sent" class="messagesFolder" id="sent">';
|
|
print 'Sent';
|
|
print '</a>';
|
|
|
|
print '<a href="/m/compose" class="messagesFolder" id="newmsg">';
|
|
print 'Compose';
|
|
print '</a>';
|
|
|
|
print '</div>';
|
|
|
|
print '<div class="content messages">';
|
|
|
|
switch(@$_GET['i']) {
|
|
case 'compose':
|
|
print '<div class="head">Compose Message</div>';
|
|
print '<div class="private-message"><form method="post" action="/sys/sendmessage">';
|
|
print '<div class="private-message-receiver">';
|
|
print '<div><abbr title="Usernames separated by commas (,)">To</abbr>: <input name="to-users" /></div>';
|
|
print '<div>Subject: <input name="subject" /></div>';
|
|
print '</div>';
|
|
print 'GOOD MESSAGING SYSTEM 10/10';
|
|
print '</form></div>';
|
|
break;
|
|
case 'read':
|
|
if(!isset($_GET['id']) || empty($_GET['id'])) {
|
|
print 'No ID specified';
|
|
break;
|
|
}
|
|
|
|
$id = $_GET['id'];
|
|
|
|
if((!is_numeric($id)) || (!preg_match('/[0-9]+/', $id))) {
|
|
print 'Invalid ID specified.';
|
|
break;
|
|
}
|
|
|
|
$msgQuery = $database->prepare("SELECT * FROM `flashii_messages` WHERE `id` = ?");
|
|
$msgQuery->bind_param('s', $id);
|
|
$msgQuery->execute();
|
|
$msgResult = $msgQuery->get_result();
|
|
$msgArray = $msgResult->fetch_array(MYSQLI_ASSOC);
|
|
$msgQuery->close();
|
|
|
|
if(!in_array($_SESSION['uid'], unserialize($msgArray['toUsers']))) {
|
|
print 'You are not authorised to read this message.';
|
|
break;
|
|
}
|
|
|
|
print '<div class="head">';
|
|
print $msgArray['title'];
|
|
print '</div>';
|
|
print '» From <a href="/u/';
|
|
print $msgArray['fromUser'];
|
|
print '" target="_blank" style="color: inherit; text-decoration: none; font-weight: 700; ';
|
|
print $flashii->getRankdata($flashii->getUserdata($msgArray['fromUser'])['userrole'])['style'];
|
|
print '">';
|
|
print $flashii->getUserdata($msgArray['fromUser'])['username'];
|
|
print '</a> on ';
|
|
print date($fwSettings['dateFormat'], $msgArray['date']);
|
|
print '<div class="private-message markdown">';
|
|
print $parser->text($msgArray['content']);
|
|
print '</div>';
|
|
break;
|
|
case 'sent':
|
|
$msgQuery = $database->query("SELECT * FROM `flashii_messages`");
|
|
$msgArray = $msgQuery->fetch_all(MYSQLI_ASSOC);
|
|
$inboxArr = [];
|
|
|
|
foreach($msgArray as $key => $value) {
|
|
if($value['fromUser'] == $_SESSION['uid'])
|
|
$inboxArr[$key] = $value;
|
|
}
|
|
?>
|
|
<table class="msg-inbox">
|
|
<thead>
|
|
<tr>
|
|
<td>To</td>
|
|
<td>Subject</td>
|
|
<td>Sent</td>
|
|
</tr>
|
|
<thead>
|
|
<tbody>
|
|
<?php
|
|
if(!empty($inboxArr)) {
|
|
foreach($inboxArr as $msg) {
|
|
print '<tr><td style="font-weight: 700;">';
|
|
foreach(unserialize($msg['toUsers']) as $user) {
|
|
print '<a href="/u/';
|
|
print $user;
|
|
print '" target="_blank" style="';
|
|
print $flashii->getRankdata($flashii->getUserdata($user)['userrole'])['style'];
|
|
print 'color: inherit; text-decoration: none; height: 100%; width: 100%; display: inline-block;">';
|
|
print $flashii->getUserdata($user)['username'];
|
|
print '</a>';
|
|
}
|
|
print '</td><td><a href="/m/read/';
|
|
print $msg['id'];
|
|
print '" class="default" style="height: 100%; width: 100%; display: block;">';
|
|
print $msg['title'];
|
|
print '</a></td><td>';
|
|
print date($fwSettings['dateFormat'], $msg['date']);
|
|
print '</td></tr>';
|
|
}
|
|
} else {
|
|
print '<tr><td colspan="3">You have no sent messages.</td></tr>';
|
|
}
|
|
?>
|
|
<tbody>
|
|
</table>
|
|
<?php
|
|
break;
|
|
case 'inbox':
|
|
default:
|
|
$msgQuery = $database->query("SELECT * FROM `flashii_messages`");
|
|
$msgArray = $msgQuery->fetch_all(MYSQLI_ASSOC);
|
|
$inboxArr = [];
|
|
|
|
foreach($msgArray as $key => $value) {
|
|
if(in_array($_SESSION['uid'], unserialize($value['toUsers'])) && (empty($msg['deletedBy']) || !in_array($_SESSION['uid'], unserialize($value['deletedBy']))))
|
|
$inboxArr[$key] = $value;
|
|
}
|
|
?>
|
|
<table class="msg-inbox">
|
|
<thead>
|
|
<tr>
|
|
<td>From</td>
|
|
<td>Subject</td>
|
|
<td>Received</td>
|
|
</tr>
|
|
<thead>
|
|
<tbody>
|
|
<?php
|
|
if(!empty($inboxArr)) {
|
|
foreach($inboxArr as $msg) {
|
|
print '<tr';
|
|
if(empty($msg['readBy']) || !in_array($_SESSION['uid'], unserialize($msg['readBy']))) {
|
|
print ' style="background: #C2AFFE; font-weight: 700;"';
|
|
}
|
|
print '><td style="';
|
|
print $flashii->getRankdata($flashii->getUserdata($msg['fromUser'])['userrole'])['style'];
|
|
print ' font-weight: 700;">';
|
|
print '<a href="/u/';
|
|
print $msg['fromUser'];
|
|
print '" target="_blank" style="color: inherit; text-decoration: none; height: 100%; width: 100%; display: block;">';
|
|
print $flashii->getUserdata($msg['fromUser'])['username'];
|
|
print '</a></td><td><a href="/m/read/';
|
|
print $msg['id'];
|
|
print '" class="default" style="height: 100%; width: 100%; display: block;">';
|
|
print $msg['title'];
|
|
print '</a></td><td>';
|
|
print date($fwSettings['dateFormat'], $msg['date']);
|
|
print '</td></tr>';
|
|
}
|
|
} else {
|
|
print '<tr><td colspan="3">You have no recieved messages.</td></tr>';
|
|
}
|
|
?>
|
|
<tbody>
|
|
</table>
|
|
<?php
|
|
break;
|
|
print '</div>';
|
|
}
|
|
} else {
|
|
?>
|
|
<div class="content standalone" style="padding: 20px;">
|
|
<h1>Login to view this page!</h1>
|
|
If you actually are logged in something went wrong and you should report this to <a href="/u/2" target="_blank" class="default">Flashwave</a>.<br />
|
|
If you aren't logged in please log in or create an account if you don't have one.
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
print desFooter();
|