

<?php 
session_start();
 if(!isset($_SESSION['email']))
  { $_SESSION['email'] = $_POST['email']; }
if(!isset($_SESSION['password'])) 
{ $_SESSION['password'] = $_POST['password']; } ?>
<html>
<head>
<title>The Science Network</title>

<link rel="stylesheet" type="text/css" href="style.css" />
</head>
	<body style="background-color:#E8E8E8">
    	<center>
    	<table width="768" height="519" border="0" style="background-color:#666666;">
  <tr>
    <td colspan="2"><img src="./logo2.gif" width="763" height="108" alt="logo"></td>
    </tr>
   <tr>
    <td colspan="2" valign="middle" style="background-color:#666;">
       
    </td>
    </tr>
   <tr>
    <td  width="585" height="379"  class="sidebar" style="background-color:#FFF; vertical-align:top; text-align:left">		        <br />
 	<?php
		

$db = mysql_connect("localhost","root","mysql");           /* start connection with database */

echo "<br>";
if (!$db)                                                       /* conditional statement */
{
die('Connection to Database down: '. mysql_error());            /* print if connection is not established */
}

mysql_select_db("ScientistNet", $db);   
?>                         
   	 <form method="POST" 
action="deleting.php" enctype="multipart/form-data">
   <?php
	$id = $_POST['mail'] ; 
	$sql =mysql_query("SELECT sender, recipient ,subject ,body, opened, timestamp ,fileName
FROM Mail 
WHERE id=$id"
) 
                     or die(mysql_error());

  $sqlopened =mysql_query("UPDATE Mail SET opened='T' 
  WHERE id=$id"
) 
                     or die(mysql_error());// change email status when it is read
	              
					
	
	$mail = mysql_fetch_assoc($sql);	
	
$sender= $mail['sender']; 
$sqlsender =mysql_query("SELECT name, email
FROM Scientist 
WHERE id=$sender"
) 
   or die(mysql_error());	// get sender info
   	$senderinfo = mysql_fetch_assoc($sqlsender);


$recipient= $mail['recipient'];
$sqlrecipient =mysql_query("SELECT name, email
FROM Scientist 
WHERE id=$recipient"
) 
   or die(mysql_error());	// get recipient info
   	$recipientinfo = mysql_fetch_assoc($sqlrecipient);
	echo $id;
			 
	?>
    
  <label for='sender'>From  :</label> 
  
  <?php 
  // dispaly sender
  echo $senderinfo['email'];
  ?>
  
  <br/>
  
   
  <label for='recipient'>To  :</label> 
 
 <?php
    // dispaly recipient
	
	
  echo $recipientinfo['email'];
   ?>
 
 <br/>
  <label for='subject'>Subject: </label>
  <?php
  // dispaly subject
   echo $mail['subject']; ?><br><br />
   
   <label for='time'>Date & Time: </label>
  <?php
  // dispaly subject
   echo $mail['timestamp']; ?><br><br /> 
   
   
  <label for='body'>Body:</label>
 <br> 
 <p> <?php 
 // dispaly body
 echo $mail['body']; ?>
 </p><br/>

<label for='uploaded_file'>Attachments</label><br /><br />
<?php
  // dispaly subject
  $fname =$mail['fileName'];
   echo "<a href='download.php'>$fname</a>";
   ?>
   <br><br /> 

<?php echo"<input type='hidden' name='mid' id='mid' value='$id' />"; ?>
<input type="submit" value="delete" name='delete'>
</form>


<form method="POST" action="newemail.php" enctype="multipart/form-data">
<?php echo"<input type='hidden' name='midf' id='midf' value='$id' />"; ?>


<input type="submit" value="Forward" name="forward">

</form>

<form method="POST" action="newemail.php" enctype="multipart/form-data">
<?php echo"<input type='hidden' name='midr' id='midr' value='$id' />"; ?>


<input type="submit" value="Reply" name="Reply">

</form>



     
    </td>
    <td width="173" align="center" valign="middle" class="sidebar" style="background-color:#CCC">
	<a href="./mail.php">Close</a>

    </td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle" style="background-color:#666; color:#FFF;">The Science Network, 2012&copy;</td>
    </tr>
</table>

	</body>
</html>
