Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * MCCodes Mailbox (V2)
- * Copyright (C) MCCodes
- * All rights reserved.
- * Author: Markku
- * File: mailbox.php
- */
- include 'globals.php';
- if ($ir['mailban']) {
- error('<span style="font-size:16px;font-weight:bold;color:red;">Error!</span><hr />
- You are currently banned from the mailbox for ' . $ir['mailban'] . ' days.<br />
- <strong>Reason:</strong> ' . $ir['mb_reason'] . ' ');
- $h->endpage();
- exit;
- }
- $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';
- echo '<hr />';
- echo '<table width="60%" cellspacing="1">';
- echo '<tr>';
- echo '<td style="width:25%;text-align:center;"><a href="mailbox.php?action=inbox">Inbox</a></td>';
- echo '<td style="width:25%;text-align:center;"><a href="mailbox.php?action=outbox">Outbox</a></td>';
- echo '<td style="width:25%;text-align:center;"><a href="mailbox.php?action=compose">Compose</a></td>';
- echo '<td style="width:25%;text-align:center;"><a href="mailbox.php?action=archive">Archive</a></td>';
- echo '</tr>';
- echo '</table>';
- echo '<hr />';
- if (!isset($_GET['action'])) {
- $_GET['action'] = 'inbox';
- }
- switch ($_GET['action']) {
- case 'inbox': inbox(); break;
- case 'outbox': outbox(); break;
- case 'compose': compose(); break;
- case 'delete': delete(); break;
- case 'send': send(); break;
- case 'clear_inbox': clear_inbox(); break;
- case 'clear_inbox_result': clear_inbox_result(); break;
- case 'archive': archive(); break;
- default: inbox(); break;
- }
- function inbox()
- {
- global $db, $ir, $c, $userid, $h;
- echo '<h3>Mailbox - Inbox</h3>';
- echo '<p>> <a href="mailbox.php?action=clear_inbox">Clear Inbox</a></p>';
- echo '<p>Only the last 25 messages you have received will be visible below.</p>';
- echo '<hr />';
- echo '<table width="95%" class="table" cellspacing="0">';
- echo '<tr>';
- echo '<th width="30%">Details</td>';
- echo '<th width="70%">Message</td>';
- echo '</tr>';
- $q = $db->query("SELECT `m`.*, `userid`, `username` FROM `mail` AS `m` LEFT JOIN `users` AS `u` ON `m`.`mail_from` = `u`.`userid` WHERE `m`.`mail_to` = $userid ORDER BY `mail_time` DESC LIMIT 25");
- while ($r = $db->fetch_row($q)) {
- $sent = date('F j, Y, g:i:s a', $r['mail_time']);
- $reply = '<a href="mailbox.php?action=compose&ID=' . $r['userid'] . '"><img src="icons/comment_add.png" alt="[Reply]" title="Reply to message" /></a>';
- $delete = '<a href="mailbox.php?action=delete&ID=' . $r['mail_id'] . '"><img src="icons/comment_delete.png" alt="[Delete]" title="Delete this message" /></a>';
- $report = '<a href="preport.php?ID=' . $r['userid'] . '&report=Fraudulent mail: ' . $fm . '"><img src="icons/bullet_error.png" alt="[Report]" title="Report this message" /></a>';
- echo '<tr><td style="border-right:1px solid #999;"><strong>From:</strong> ';
- if ($r['userid']) {
- echo "<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]";
- } else {
- echo "SYSTEM";
- }
- $fm = urlencode($r['mail_text']);
- echo '<br />';
- echo '<strong>Subject:</strong> ' . $r['mail_subject'] . '<br />';
- echo '<strong>Time:</strong> ' . $sent . '<br />';
- echo '' . $reply . ' ';
- echo '' . $delete . ' ';
- echo '' . $report . ' ';
- echo '</td>';
- echo '<td valign="top">' . $r['mail_text'] . '</td>';
- echo '</tr>';
- }
- $db->free_result($q);
- if ($ir['new_mail'] > 0) {
- $db->query("UPDATE `mail` SET `mail_read` = 1 WHERE `mail_to` = $userid");
- $db->query("UPDATE `users` SET `new_mail` = 0 WHERE `userid` = $userid");
- }
- echo '</table>';
- }
- function outbox()
- {
- global $db, $ir, $c, $userid, $h;
- echo '<h3>Mailbox - Outbox</h3>';
- echo '<p>Only the last 25 messages you have sent will be visible below.</p>';
- echo '<hr />';
- echo '<table width="95%" class="table" cellspacing="0">';
- echo '<tr>';
- echo '<th width="30%">Details</td>';
- echo '<th width="70%">Message</td>';
- echo '</tr>';
- $q = $db->query("SELECT `m`.*, `userid`, `username` FROM `mail` AS `m` LEFT JOIN `users` AS `u` ON `m`.`mail_to` = `u`.`userid` WHERE `m`.`mail_from` = $userid ORDER BY `mail_time` DESC LIMIT 25");
- while ($r = $db->fetch_row($q)) {
- $sent = date('F j, Y, g:i:s a', $r['mail_time']);
- echo '<tr>';
- echo '<td style="border-right:1px solid #999;">';
- echo '<strong>User:</strong> <a href="viewuser.php?u=' . $r['userid'] . '">' . $r['username'] . '</a> [' . $r['userid'] . '] <br />';
- echo '<strong>Subject:</strong> ' . $r['mail_subject'] . ' <br />';
- echo '<strong>Time:</strong> ' . $sent . ' <br />';
- echo '</td>';
- echo '<td valign="top">' . $r['mail_text'] . '</td>';
- echo '</tr>';
- }
- $db->free_result($q);
- echo '</table>';
- }
- function compose()
- {
- global $db, $ir, $c, $userid, $h;
- echo '<h3>Mailbox - Compose</h3>';
- echo '<form action="mailbox.php?action=send" method="post">
- <table width="55%" class="table" cellspacing="0">
- <tr><th style="text-align:center;">Select Contact</th></tr>
- <tr><td style="text-align:center;">';
- $q = $db->query("SELECT `c`.*, `username` FROM `contactlist` AS `c` INNER JOIN `users` AS `u` ON `c`.`cl_ADDED` = `u`.`userid` WHERE `c`.`cl_ADDER` = {$userid} ORDER BY u.`username` ASC");
- if ($db->num_rows($q) == 0) {
- echo 'You do not have any contacts!';
- } else {
- echo '<select name="user1" type="dropdown"><option value=""><select a contact...></option>';
- while ($r = $db->fetch_row($q)) {
- $esc_part = addslashes($r['username']);
- echo '<option value="' . $esc_part . '">' . $r['username'] . '</option>';
- }
- echo '</select>';
- }
- $db->free_result($q);
- $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';
- $user_exists = false;
- if ($_GET['ID']) {
- $un_query = $db->query("SELECT `username` FROM `users` WHERE `userid` = {$_GET['ID']}");
- if ($db->num_rows($un_query) > 0) {
- $user_exists = true;
- $user = $db->fetch_single($un_query);
- } else {
- $user = '';
- }
- $db->free_result($un_query);
- } else {
- $user = '';
- }
- $esc_user = addslashes($user);
- echo '</td>';
- echo '</tr>';
- echo '<tr><th style="border-top:1px solid #999;text-align:center;">Enter a Username</th></tr>';
- echo '<tr><td style="text-align:center;"><input type="text" name="user2" value="' . $esc_user . '" /></td></tr>';
- echo '<tr><th style="border-top:1px solid #999;text-align:center;">Enter a Subject</th></tr>';
- echo '<tr><td style="text-align:center;"><input type="text" name="subject" /></td></tr>';
- echo '<tr><th style="border-top:1px solid #999;text-align:center;">Enter a Message</th></tr>';
- echo '<tr><td style="text-align:center;"><textarea rows="4" cols="67" name="message"></textarea></td></tr>';
- echo '<tr><td style="text-align:center;"><input type="submit" value="Send Message" /></td></tr>';
- echo '</table></form>';
- if ($user_exists) {
- echo '<br />';
- echo '<table width="95%" class="table" cellspacing="0">';
- echo '<tr><th>Your last 5 mails to/from this person</th></tr>';
- $q = $db->query("SELECT `mail_time`, `mail_text`, `mail_from` FROM `mail` WHERE (`mail_from` = $userid AND `mail_to` = {$_GET['ID']}) OR (`mail_to` = $userid AND `mail_from` = {$_GET['ID']}) ORDER BY `mail_time` DESC LIMIT 5");
- while ($r = $db->fetch_row($q)) {
- $sender = ($_GET['ID'] == $r['mail_from']) ? $user : $ir['username'];
- echo '<tr>
- <td><strong>' . $sender . ':</strong> ' . $r['mail_text'] . '</td>
- </tr>';
- }
- $db->free_result($q);
- echo '</table>';
- echo '<hr />';
- echo '> <a href="mailbox.php">Go Back</a>';
- }
- }
- function send()
- {
- global $db, $ir, $c, $userid, $h;
- $subj = $db->escape(str_replace("\n", "<br />", strip_tags(stripslashes($_POST['subject']))));
- $msg = $db->escape(str_replace("\n", "<br />", strip_tags(stripslashes($_POST['message']))));
- if (empty($subj) || empty($msg)) {
- error('You must enter a subject and a message.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- } elseif ((strlen($msg) > 300) || (strlen($subj) > 50)) {
- error('Messages/Subjects are limited to 300/50 characters per time.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $_POST['user1'] = (isset($_POST['user1']) && preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['user1']) && ((strlen($_POST['user1']) < 32) && (strlen($_POST['user1']) >= 3))) ? $_POST['user1'] : '';
- $_POST['user2'] = (isset($_POST['user2']) && preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $_POST['user2']) && ((strlen($_POST['user2']) < 32) && (strlen($_POST['user2']) >= 3))) ? $_POST['user2'] : '';
- if ($_POST['user1'] && $_POST['user2']) {
- error('Please do not select a contact AND enter a username, only do one.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- if (empty($_POST['user1']) && empty($_POST['user2'])) {
- error('You must select a contact or enter a username.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $sendto = ($_POST['user1']) ? $_POST['user1'] : $_POST['user2'];
- $q = $db->query("SELECT `userid` FROM `users` WHERE `username` = '{$sendto}'");
- if ($db->num_rows($q) == 0) {
- $db->free_result($q);
- error('Sorry, that user does not exist.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $to = $db->fetch_single($q);
- $db->free_result($q);
- $db->query("INSERT INTO `mail` VALUES (NULL, 0, $userid, $to, " . time() . ", '$subj', '$msg')");
- $db->query("UPDATE `users` SET `new_mail` = `new_mail` + 1 WHERE `userid` = {$to}");
- success('Your message has been successfully sent!<br /> > <a href="mailbox.php">Go Back</a>');
- }
- function delete()
- {
- global $db, $ir, $c, $userid, $h;
- $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : '';
- if (empty($_GET['ID'])) {
- error('Sorry something went wrong there, Please go back and try again.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $q = $db->query("SELECT COUNT(`mail_id`) FROM `mail` WHERE `mail_id` = {$_GET['ID']} AND `mail_to` = {$userid}");
- if ($db->fetch_single($q) == 0) {
- $db->free_result($q);
- error('Sorry something went wrong there, Please go back and try again.<br /> > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $db->free_result($q);
- $db->query("DELETE FROM `mail` WHERE `mail_id` = {$_GET['ID']} AND `mail_to` = $userid");
- success('Your message has been deleted!<br /> > <a href="mailbox.php">Go Back</a>');
- }
- function clear_inbox()
- {
- global $ir, $c, $userid, $h;
- $delall_verf = request_csrf_code('clear_inbox');
- echo '<h3>Mailbox - Clear Inbox</h3>';
- general('This will clear all messages in your inbox, This cannot be undone, Are you sure you want to clear all?<hr />
- [<a href="mailbox.php?action=clear_inbox_result&verf=' . $delall_verf . '">Yes</a>] [<a href="mailbox.php">No</a>]');
- $h->endpage();
- exit;
- }
- function clear_inbox_result()
- {
- global $db, $ir, $c, $userid, $h;
- if (!isset($_GET['verf']) || !verify_csrf_code('clear_inbox', stripslashes($_GET['verf']))) {
- error('This action has been blocked for your security.<br />
- You should submit this action fast, to ensure that it is really you doing it.<br />
- > <a href="mailbox.php">Go Back</a>');
- $h->endpage();
- exit;
- }
- $m_c = $db->query("SELECT COUNT(`mail_id`) FROM `mail` WHERE `mail_to` = {$userid}");
- if ($db->fetch_single($m_c) == 0) {
- error('You have no mails in your inbox to delete.<br /> > <a href="mailbox.php">Go Back</a>');
- } else {
- $db->query("DELETE FROM `mail` WHERE `mail_to` = $userid");
- success(' ' . $db->affected_rows() . ' messages in your inbox have been deleted.<br /> > <a href="mailbox.php">Go Back</a>');
- }
- $db->free_result($m_c);
- }
- function archive()
- {
- global $ir, $c, $userid, $h;
- echo '<h3>Mailbox - Archive</h3>';
- general('This tool will allow you too download a history of your inbox/outbox.<hr />
- [<a href="dlarchive.php?a=inbox">Download Inbox</a>] [<a href="dlarchive.php?a=outbox">Download Outbox</a>]');
- $h->endpage();
- exit;
- }
- $h->endpage();
Advertisement
Add Comment
Please, Sign In to add comment