Location: PHPKode > projects > Alumni Tracking Database > AlumniDB1.01/outbox.php
<?php

session_start();
header("Cache-control: private"); // IE 6 Fix.
include ("Includes/connect.php");
include ('Includes/config.php');

$nodata = true;

/* this block checks to see if the user has already logged in */
if($_SESSION["login1"] != true)
{
	session_unset();
	session_destroy();
	echo('<script>window.location = "login.php"</script>');
}
if($_SESSION["guest"] == "yes")
{
	session_unset();
	session_destroy();
	echo('<script>window.location = "login.php"</script>');
}
unset($_SESSION['msg']);
unset($_SESSION['msg2']);
unset($_SESSION['msg3']);
unset($_SESSION['msg4']);
unset($_SESSION['msg5']);

//DELETE THE MESSAGES SELECTED
if(isset($_POST["deleteSelected"]))
{}
$data = $conn->query("SELECT * FROM MESSAGEOUTBOX WHERE MESSAGEOUTBOX.username = '".$_SESSION["username"]."'");
while($row = $data->fetchRow())
{
	if(isset($_POST["checkbox".$row["messageID"]]))
	{
		$query = "DELETE FROM MESSAGEOUTBOX WHERE MESSAGEOUTBOX.messageID = '".$row["messageID"]."'";
		$conn->query($query);
	}
}


//GET THE MESSAGE IF CLICKED		
if(isset($_GET["message"]))
{
	$query = "UPDATE MESSAGEOUTBOX SET MESSAGEOUTBOX.unread = 1 WHERE messageID = '".$_GET['message']."'";
	$conn->query($query);
	
	$nodata = false;
	$data = $conn->query("SELECT * FROM MESSAGEOUTBOX WHERE MESSAGEOUTBOX.sender = '".$_SESSION["username"]."' AND messageID = '".$_GET["message"]."'");
	$row = $data->fetchRow();
	$data2 = $conn->query("SELECT firstname, lastname FROM USER WHERE USER.username = '".$row["sender"]."'");
	$row2 = $data2->fetchRow();
	$data3 = $conn->query("SELECT firstname, lastname FROM USER WHERE USER.username = '".$row["username"]."'");
	$row3 = $data3->fetchRow();
	
	$from = $row["sender"];
	$fromFname = $row2["firstname"];
	$fromLname = $row2["lastname"];
	$to = $row["username"];
	echo $row['username'];
	$toFname = $row3["firstname"];
	$toLname = $row3["lastname"];
	$subject = $row["subject"];
	$message = $row["message"];
	$messageID2 = $row["messageID"];
}

//IF JUST DELETE WAS PUSHED
if(isset($_POST["deleteThis"]))
{
	//$messageID = $_GET["message"];
	$query = "DELETE FROM MESSAGEOUTBOX WHERE MESSAGEOUTBOX.messageID = '".$_POST["messageID"]."'";
	$conn->query($query);
}

//GET THE MAIL
	//Grab the data from the database
		$data = $conn->query("SELECT * FROM MESSAGEOUTBOX WHERE MESSAGEOUTBOX.sender = '".$_SESSION["username"]."' ORDER BY MESSAGEOUTBOX.date_sent DESC");
	//Fill the data
		while($row = $data->fetchRow())
		{
			$data2 = $conn->query("SELECT * FROM USER WHERE USER.username = '".$row["username"]."'");
			$row2 = $data2->fetchRow();
			$fname = $row2["firstname"];
			$lname = $row2["lastname"];

			$messageID = $row["messageID"];
						
				$mailListing .= "<tr bgcolor='#CCCCCC' >				
									<td align='center'><input type=checkbox name='checkbox$messageID' value=''></td>
									<td align='left'>".'&nbsp;&nbsp;'.$row['username'].' ('.$row2['firstname'].' '.$row2['lastname'].')'."</td>
									<td align='left'><A HREF='outbox.php?message=$messageID' style='font-weight:normal'>".'&nbsp;&nbsp;'.$row['subject']."</A></td>	
									<td align='left'>".'&nbsp;'.$row['date_sent']."</td>
									<td></td>	
								</tr>";
		}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>Message - Outbox</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<!--includes stylessheets that sets the font for the webpage-->
	<link rel="stylesheet" type="text/css" href="styles/main.css">
	<link rel="stylesheet" type="text/css" href="styles/tab.css">
	<link rel="stylesheet" type="text/css" href="styles/headers.css">
</head>
<body class="section-2">
	<form method="post" name="alumni" action="outbox.php">
	<div id="centercontent">
		<ul id="formmenu">
			<li id="nav-1"><a href="inbox.php">Inbox</a></li>
			<li id="nav-2"><a href="outbox.php">Outbox</a></li>
			<li id="nav-3"><a href="compose.php">Compose</a></li>
		</ul>
		<div id="contents">
			<h2><strong>Message Outbox</strong></h2>
			<div class="errormessage"><?=$_SESSION["login2error"]?></div>
			<div class="systemmessage"><?=$_SESSION["msg"]?></div>
			<form name='formresult' action='inbox.php' method='POST'>
			<table width="700" border="0" cellspacing="0" cellpadding="0" align="center">			
					<th class="admin" width="15"><div align="center">--</div></th>
					<th class="admin" width="125"><div align="left">To&nbsp;&nbsp;&nbsp;</div></th>
					<th class="admin" width="460"><div align="left">Subject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></th>
					<th class="admin" width="100"><div align="left">Date&nbsp;&nbsp;&nbsp;</div></th>
					<?=$mailListing?>			
			</table><br>
				<input type="submit" value="Delete Selected" name="deleteSelected">
			<? if($nodata == false) { ?>
				<br><br><hr><br><br>
				<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" align="CENTER">
				<td bgcolor="#FFFFFF"><div id="forminput">
					<div id="formrow">
						<div class="item">
							From:&nbsp;&nbsp;
								<span style='font-weight:normal'><?=$from?>&nbsp;(<?=$fromFname?>&nbsp;<?=$fromLname?>)</span>
							<br><br>To:&nbsp;&nbsp;
								<span style='font-weight:normal'><?=$to?>&nbsp;(<?=$toFname?>&nbsp;<?=$toLname?>)</span>
							<br><br>Subject:&nbsp;&nbsp;
								<span style='font-weight:normal'><?=$subject?></span>
							<br><br>
							<span style='font-weight:normal'>
								<?=$message?>
							</span>
							<input type="hidden" name="messageID" value="<?=$messageID2?>">			
						</div>
					</div>
					</td>
					</table><br>
					<div id="submitarea">
						<input type="submit" NAME="close" value="Close">
						&nbsp;&nbsp;
						<input type="submit" NAME="deleteThis" value="Delete">
						<br><br>
						* indicates a required field					
					</div>
				</div>
			<? } ?>
			</form>
		</div>
	</div>
	</form>
<div id="topcontent"><?include ("Includes/north.php");?></div>
<div id="leftcontent"><?include ("Includes/west.php");?></div>	
<div id="rightcontent"><?include ("Includes/east.php");?></div>
<div id="bottomcontent"><?include ("Includes/south.php");?></div>
</body>
</html>
Return current item: Alumni Tracking Database