Messages
 
Inbox
- New Message
- Outbox"); if($logged[username] && $logged[level] == 5) echo ("
- New Sticky Message"); if($logged[username] && $logged[level] == 3) echo ("
- New Sticky Message"); break; case 'write': if (!$_POST[send]) { //the form hasnt been submitted yet.... echo ("
recipient
Message Subject
Message
"); } if ($_POST[to]) { //the form has been submitted. Now we have to make it secure and insert it into the database $subject = htmlspecialchars(addslashes("$_POST[subject]")); $message = htmlspecialchars(addslashes("$_POST[message]")); $to = htmlspecialchars(addslashes("$_POST[to]")); //the above lines remove html and add \ before all " $send = mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `unread` , `date` ) VALUES ('$subject', '$message', '$to', '$logged[username]', 'unread', NOW())"); echo ("Your message has been sent."); } break; case 'sticky': if (!$_POST[send]) { //the form hasnt been submitted yet.... echo ("
recipient
Message Subject
Message
"); } if ($_POST[to]) { //the form has been submitted. Now we have to make it secure and insert it into the database $subject = htmlspecialchars(addslashes("$_POST[subject]")); $message = htmlspecialchars(addslashes("$_POST[message]")); $to = htmlspecialchars(addslashes("$_POST[to]")); //the above lines remove html and add \ before all " $send = mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `from` , `unread` , `date` , `sticky` ) VALUES ('$subject', '$message', '$to', '$logged[username]', 'unread', NOW(), 1)"); echo ("Your message has been sent."); } break; case 'delete': if (!$_GET[msgid]) { echo ("Sorry, but this is an invalid message!"); } else { $getmsg = mysql_query("SELECT * from pmessages where id = '$_GET[msgid]'"); $msg = mysql_fetch_array($getmsg); //hmm..someones trying to delete someone elses messages! This keeps them from doing it if ($msg[touser] != $logged[username]) { echo ("This message was not sent to you!"); } elseif ($msg[sticky] != '1') { $delete = mysql_query("delete from pmessages where id = '$_GET[msgid]'"); echo "Your message has been deleted."; } else { echo "This Message Cannot Be Deleted."; } } break; case 'inbox': $get = mysql_query("SELECT * from pmessages where touser = '$logged[username]' order by id desc"); echo("
Subject From Date Delete
"); $nummessages = mysql_num_rows($get); if ($nummessages == 0) { echo ("You have 0 messages!"); } else { echo(""); while ($messages = mysql_fetch_array($get)) { //the above lines gets all the messages sent to you, and displays them with the newest ones on top echo (" "; } echo ""; echo ("
"); if ($messages[reply] == yes) { echo ("Reply to: "); } echo "
"; echo "$messages[title]
$messages[from] $messages[date]
"); } } } break; case 'view': //the url now should look like ?page=view&msgid=# if (!$_GET[msgid]) { //there isnt a &msgid=# in the url echo ("Invalid message!"); } else { //the url is fine..so we continue... $getmsg= mysql_query("SELECT * from pmessages where id = '$_GET[msgid]'"); $msg = mysql_fetch_array($getmsg); //the above lines get the message, and put the details into an array. if ($msg[touser] == $logged[username]) { //makes sure that this message was sent to the logged in member if (!$_POST[message]) { //the form has not been submitted, so we display the message and the form $markread = mysql_query("Update pmessages set unread = 'read' where id = '$_GET[msgid]'"); //this line marks the message as read. $msg[message] = nl2br(stripslashes("$msg[message]")); //removes slashes and converts new lines into line breaks. echo ("
$msg[title] -- From $messages[fromuser]
$msg[message]
Reply
"); } if ($_POST[message]) { //the form HAS been submitted, now we insert it into the database $message = htmlspecialchars(addslashes("$_POST[message]")); $do = mysql_query("INSERT INTO `pmessages` ( `title` , `message` , `touser` , `fromuser` , `unread` , `date`, `reply`) VALUES ('$msg[title]', '$message', '$msg[from]', '$logged[username]', 'unread', NOW(), 'yes')"); $newpmemail = mysql_query("SELECT * FROM users WHERE username= '$_POST[to]'"); echo ("Your message has been sent"); } } $getmsg= mysql_query("SELECT * from pmessages where id = '$_GET[msgid]'"); $msg = mysql_fetch_array($getmsg); //the above lines get the message, and put the details into an array. if ($msg[fromuser] == $logged[username]) { //makes sure that this message was sent to the logged in member if (!$_POST[message]) { //the form has not been submitted, so we display the message and the form //this line marks the message as read. $msg[message] = nl2br(stripslashes("$msg[message]")); //removes slashes and converts new lines into line breaks. } } else { //hmm..this message was NOT sent to the logged in user...so we won't display it. echo("Error
"); echo ("This message was sent incorrectly to you. It might be because the sender missed out capitals in your name. please send a message back to the sender saying you can't veiw the message because they spelt your name wrong."); } } break; case 'outbox': $get = mysql_query("SELECT * from pmessages where fromuser = '$logged[username]' order by id desc"); // gets the messages that you sent echo("
Subject To Date Read/Unread
"); $nummessages = mysql_num_rows($get); if ($nummessages == 0) { echo ("You have sent 0 messages!"); } else { echo(""); while ($messages = mysql_fetch_array($get)) { //the above lines gets all the messages sent to you, and displays them with the newest ones on top echo (" "); } echo ("
"); if ($messages[reply] == yes) { echo ("Reply to: "); } echo ("$messages[title] $messages[touser] $messages[date] $messages[unread]
"); } break; case 'multidelete': if(isset($_POST['delete_pms'])) { $delete_array = $_POST['messages']; //loop through each individual item in the array foreach($delete_array as $val) { $query = mysql_query("DELETE FROM pmessages WHERE id = '$val'"); } echo ("PM(s) deleted!"); echo ("You Will Be Redirected...
"); } else { if(isset($_POST['delete_all'])) { $query = mysql_query("DELETE FROM pmessages WHERE touser = '$logged[username]'"); echo ("Your Inbox Is Now Empty!)"; echo ("You Will Be Redirected..
"); } } break; } echo("

Inbox · New Message · Outbox"); if($logged[username] && $logged[level] == 5) echo (" · New Sticky Message"); if($logged[username] && $logged[level] == 3) echo (" · New Sticky Message"); } else { echo("You are not loged in. Please login to veiw the message system."); } ?>