Location: PHPKode > scripts > PHPwebmail > phpwebmail/history.php
<?php
/*          
PHPwebmail is a webmail client written in php.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License   
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/ 

   session_start();
   require("not_registered.php");

	if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
		@mysql_select_db("phpwebmail");
		$sql_query = "SELECT textmode FROM prefs WHERE user='$name'";
		$result = mysql_query($sql_query);
		        // catch SQL errors
		        if (mysql_errno()) echo ("ERROR ".mysql_error());
		$row = mysql_fetch_row($result);
		$textmode = $row[0];
		mysql_close($db_link);
	} // if db_link ends
?>
<html>
<head> 
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
</head>
<body bgcolor="<?php echo $bg_color_main; ?>" text="<?php echo $fg_color; ?>" link="<?php echo $link_color; ?>" vlink="<?php echo $link_color; ?>" alink="<?php echo $alink_color; ?>">
<font face="arial" size=2>

<?php
// main entry point

if (!isset($action)) $action="";
if ($action == "really") {
// delete all
      if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
	@mysql_select_db("phpwebmail");
	$sql_query = "DELETE FROM history WHERE user='$name'";
	$result = mysql_query($sql_query);
        // catch SQL errors
        if (mysql_errno()) echo ("ERROR ".mysql_error());
      } // if db_link ends
}

if ($action == "all") {
// ask before deleting all
?>
	<h3>Really delete all sent messages?</h3>
	<font face="arial" size=2><b><a href="history.php?<?php SID ?>&action=really"><?php if ($textmode) echo "yes"; else echo "<img src=images/_yes.gif border=0 alt=yes>"; ?></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="javascript:history.back()"><?php if ($textmode) echo "no"; else echo "<img src=images/_no.gif border=0 alt=no>"; ?></a></b>
<?php		  
} else if (!empty($nr) && empty($del)) {
// show the message
      if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
	@mysql_select_db("phpwebmail");
	$sql_query = "SELECT  mailto, cc, bcc, subject, body, attachment, date FROM history WHERE user='$name' AND nr=".$nr;
	$result = mysql_query($sql_query);
        // catch SQL errors
        if (mysql_errno()) echo ("ERROR ".mysql_error());
	$row = mysql_fetch_row($result);
	$the_to = strip_tags(htmlspecialchars($row[0]));
	$the_cc = strip_tags(htmlspecialchars($row[1]));
	$the_bcc = strip_tags(htmlspecialchars($row[2]));
	$the_subject = $row[3];
	$the_body = strip_tags(htmlspecialchars($row[4]));
	$the_attachment = $row[5];
	$the_date = date("D, d M Y H:i",$row[6]);
	echo "<H3>View a previously sent message:</h3><br>";  
      	echo "<font face=\"courier,fixed\" size=2><B>Date: &nbsp;&nbsp;&nbsp;".$the_date."<BR>
		To: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$the_to."<BR>
		Cc: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>".$the_cc."<b><BR>
		Bcc: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>".$the_bcc."<b><BR>
		Subject: ".$the_subject."</B><BR>
      		<BR>\n".nl2br($the_body)."<BR>";
	if (!empty($the_attachment)) {
	    echo "<b>";
	    if ($textmode) echo "Attachment: "; else echo "<img src=\"images/attach.gif\"> ";
	    echo "$the_attachment</b><BR><BR>";
	}   		
        mysql_close($db_link);
	echo "<br><a href=\"send_mail.php?".SID."&subject=".urlencode($the_subject)."&body=".urlencode($the_body)."\"\"><font face=\"arial\" size=2><b>Resend this message</b></a><br><br><a href=\"history.php?".SID."\"><font face=\"arial\" size=2><b>Back to list</b></a>";
      } // if db_link ends
} else { 
//show the table
?>
	<h3>Messages you have sent with PHPwebmail:</h3>
	<table border=1><TR ALIGN="TOP">
	<TD align="left"><font face="arial" size=2><b>To</TD>
	<TD align="left"><font face="arial" size=2><b>Subject</b> <i>(Click to read)</TD>
	<TD align="left"><font face="arial" size=2><b>Date/Time</TD>
	<TD align="left"><font face="arial" size=2><b><a href="history.php?<?php SID ?>&action=all">
	    <?php if ($textmode) echo "delete all"; else echo "<img src=images/_del_all.gif border=0 alt=\"delete all\">"; ?>
	</a></TD>
	<TR>
<?php
      // get everything from the database
      if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
	@mysql_select_db("phpwebmail");
	if ($del == "yes") {
		$sql_query = "DELETE FROM history WHERE nr='$nr'";
		$result = mysql_query($sql_query);
	        // catch SQL errors
 	        if (mysql_errno()) echo ("ERROR ".mysql_error());
	} // if del ends
	$sql_query = "SELECT nr, mailto, subject, date FROM history WHERE user='$name' ORDER BY nr DESC";
	$result = mysql_query($sql_query);
        // catch SQL errors
        if (mysql_errno()) echo ("ERROR ".mysql_error());
	while ($row = mysql_fetch_row($result)) {
	  $the_nr = $row[0];
	  $the_to = $row[1];
	  $the_subject = $row[2];
	  if (empty($the_subject)) $the_subject="(no subject)";
	  $the_date = date("D, d M Y H:i",$row[3]);

	  echo "<TR><TD><font face=\"arial\" size=2>$the_to</TD><TD><font face=\"arial\" size=2><a href=\"history.php?".SID."&nr=$the_nr\">$the_subject</a></TD><TD><font face=\"arial\" size=2>$the_date</TD><TD align=\"center\"><font face=\"arial\" size=2><a href=\"history.php?".SID."&nr=$the_nr&del=yes\">";
	  if ($textmode) echo "delete"; else echo "<img src=\"images/_del_this.gif\" border=0 alt=\"delete\">";
	  echo "</a></TD></TR>";
	} // while ends
        mysql_close($db_link);
      } // if db_link ends
      echo "</TABLE>";
} // else ends
?>

</BODY></HTML>
Return current item: PHPwebmail