Location: PHPKode > projects > Gsys > messages/message_functions.php
<?PHP
//Filename : message_functions.php
//Description : Functions for working on messages
//Author :  darc
//Last modified :  2006.12.20

    include '../includes/db.php';
    include '../includes/auth.php';

switch($_GET["cat"])
{
//will check your messages to see if the user has any
 case "check_messages" :
 {
$sql = "SELECT * FROM messages INNER JOIN brothers ON brothers.pin_num = messages.from_pin WHERE to_pin = '$_SESSION[pin_num]' ORDER BY date_sent DESC";
$result = mysql_query($sql,$connection) or die(mysql_error);

$sql2 = "UPDATE messages SET messages.read = '1' WHERE messages.read = '0' && to_pin = '$_SESSION[pin_num]'";
$result2 = mysql_query($sql2,$connection) or die(mysql_error);

         echo "
		<html>
		<head><title>Check Messages</title>
		<link href=\"../includes/index.css\" rel=\"stylesheet\" type=\"text/css\"></head>
		<body class=\"body\">
<br />
<table width=\"810\" height=\"626\" border=\"0\" align=\"center\" cellpadding=\"15\">
  <tr> 
    <td height=\"128\" colspan=\"2\"><img src=\"../images/eg_banner.gif\" width=\"810\" height=\"172\"></td>
  </tr>
  <tr> 
    <td width=\"27%\" height=\"488\" valign=\"top\">"; include '../includes/nav.inc'; echo "</td>
    <td width=\"53%\" align=\"center\" valign=\"top\">";

echo "<table border=\"1\" cellpadding=\"4\">

		<tr>
		<td align=\"center\"><strong>Date Sent</strong></td>
		<td><strong>Title</strong></td>
		<td><strong>Message</strong></td>
		<td><strong>Sent By</strong></td>
		<td><strong>Delete Message</strong></td>
		</tr>";

//START LOOP
		while ($row =mysql_fetch_array($result))
		{
			$msg_id = $row['msg_id'];
			$date_time = $row['date_sent'];
	                $sent_by = $row['username'];
	                $title = $row['title'];
	                $message = $row['body'];

	         echo "<tr><td align=\"center\">";
	         echo($date_time); 
	         echo "</td><td>";
	         echo($title);
	         echo "</td><td>";
	         echo($message);
	         echo "</td><td>";
	         echo($sent_by);
	         echo "</td><td valign=\"center\">";
	        
?>
<center>
<form method="post" action="message_functions.php?cat=delete_message">
<input type="hidden" name="msg_id" value="<?php echo $msg_id; ?>">
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Delete">
</form>
		</center>	
<?php
	         echo "</td></tr>";
		}
		
		echo "
		</table>
	</td>
</tr>
</table>
		</body>
		</html>";
         break;
     }

case "do_send_message":

{
    	$message = $_POST['message'];
  	 $sender_pin = $_POST['sender_pin'];
  	 $to_pin = $_POST['member_pin'];
         $message = $_POST['message'];
         $title = $_POST['title'];

  $sql = "INSERT INTO `messages` (`msg_id` , `to_pin` , `from_pin` , `date_sent` , `title` , `body` , `read`) VALUES ('', '$to_pin', '$sender_pin', NOW(), '$title', '$message', '0')";
  $result = mysql_query($sql,$connection) or die(mysql_error());
  
          echo "	<html>
		<head><title>Message Sent Successfully</title>
		<link href=\"../includes/index.css\" rel=\"stylesheet\" type=\"text/css\"></head>
		<body class=\"body\">
<br />
<table width=\"810\" height=\"626\" border=\"0\" align=\"center\" cellpadding=\"15\">
  <tr> 
    <td height=\"128\" colspan=\"2\"><img src=\"../images/eg_banner.gif\" width=\"810\" height=\"172\"></td>
  </tr>
  <tr> 
    <td width=\"27%\" height=\"488\" valign=\"top\">"; include '../includes/nav.inc'; echo "</td>
    <td width=\"53%\" align=\"center\">Message sent successfully!<br>   </td>
  </tr>
</table></body></html>";
          break;
     }
  
 case "delete_message" :
    {
        $mess_num = $_POST['msg_id'];
        $sql = "DELETE FROM messages WHERE msg_id = '$mess_num'";
        $result = mysql_query($sql,$connection) or die(mysql_error());
    
        echo "	<html>
		<head><title>Message Deleted Successfully</title>
		<link href=\"../includes/index.css\" rel=\"stylesheet\" type=\"text/css\"></head>
		<body class=\"body\">
<br />
<table width=\"810\" height=\"626\" border=\"0\" align=\"center\" cellpadding=\"15\">
  <tr> 
    <td height=\"128\" colspan=\"2\"><img src=\"../images/eg_banner.gif\" width=\"810\" height=\"172\"></td>
  </tr>
  <tr> 
    <td width=\"27%\" height=\"488\" valign=\"top\">"; include '../includes/nav.inc'; echo "</td>
    <td width=\"53%\" align=\"center\">Message deleted successfully!<br>   </td>
  </tr>
</table></body></html>";
        return;
    }
  
}  
?> 
  
Return current item: Gsys