Jump to content

Creating Delete button while reading the message


CherieYuki

Recommended Posts

Hi, I'm doing a simple e-mail using localhost, while doing the rest, I realized I need a delete button for it. Is there a simple way to delete the message when the user opens the mail content?

 

This is the code I did for read_pm.php:

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>Read a PM</title>
    	<script type="text/javascript">
<!--
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
// -->
</script>
    	<style type="text/css">
	.auto-style2 {
		font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
		text-align: left;
	}
	.auto-style4 {
color: #FFFFFF;
}
	.auto-style1 {
		font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
	}
	</style>
    </head>
    <body onload="FP_preloadImgs(/*url*/'default/images/buttonD5.jpg',/*url*/'default/images/buttonD6.jpg',/*url*/'default/images/button51.jpg',/*url*/'default/images/button52.jpg')">
    	<div class="header">
        	<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a>
    </div>
        
        
<?php
//We check if the user is logged
if(isset($_SESSION['email']))
{
//We check if the ID of the discussion is defined
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
//We get the title and the narators of the discussion
$req1 = mysql_query('select title, user1, user2 from pm where id="'.$id.'" and id2="1"');
$dn1 = mysql_fetch_array($req1);
//We check if the discussion exists
if(mysql_num_rows($req1)==1)
{
//We check if the user have the right to read this discussion
if($dn1['user1']==$_SESSION['userid'] or $dn1['user2']==$_SESSION['userid'])
{
//The discussion will be placed in read messages
if($dn1['user1']==$_SESSION['userid'])
{
mysql_query('update pm set user1read="yes" where id="'.$id.'" and id2="1"');
$user_partic = 2;
}
else
{
mysql_query('update pm set user2read="yes" where id="'.$id.'" and id2="1"');
$user_partic = 1;
}
//We get the list of the messages
$req2 = mysql_query('select pm.timestamp, pm.message, users.id as userid, users.username from pm, users where pm.id="'.$id.'" and users.id=pm.user1 order by pm.id2');
//We check if the form has been sent
if(isset($_POST['message']) and $_POST['message']!='')
{
$message = $_POST['message'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
	$message = stripslashes($message);
}
//We protect the variables
$message = mysql_real_escape_string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8')));
//We send the message and we change the status of the discussion to unread for the recipient
if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "'.(intval(mysql_num_rows($req2))+1).'", "", "'.$_SESSION['userid'].'", "", "'.$message.'", "'.time().'", "", "")') and mysql_query('update pm set user'.$user_partic.'read="yes" where id="'.$id.'" and id2="1"'))
{
?>
<div class="message"><strong><span class="auto-style4">Your message has successfully been sent.</span></strong><br />
<a href="read_pm.php?id=<?php echo $id; ?>">Back to Message</a></div>
<?php
}
else
{
?>
<div class="message"><strong><span class="auto-style4">An error occurred while sending the message.</span></strong><br />
<a href="read_pm.php?id=<?php echo $id; ?>">Back to Message</a></div>
<?php
}
}
else
{
//We display the messages
?>
<div class="content">

<table class="messages_table">
<tr>
        <th class="auto-style2" style="height: 27px; width: 64px">Subject : <?php echo $dn1['title']; ?></th>
    </tr>
<?php
while($dn2 = mysql_fetch_array($req2))
{
?>
<tr>
    	<td class="auto-style2" style="height: 50px; width: 64px">
	<div class="auto-style2">Sent by: <a href="profile.php?id=<?php echo $dn2['userid']; ?>"><?php echo $dn2['username']; ?> 
		on <?php echo date('d/m/Y, g:i a' ,$dn2['timestamp']); ?></div>
    	<br>
    	
    	
    	
    	<?php echo $dn2['message']; ?></a><br></td>
    </tr>
<?php
}
//We display the reply form
?>
</table>
<br />
<div class="center">
    	<form action="read_pm.php?id=<?php echo $id; ?>" method="post">
    		 
<img id="img7" alt="Reply" fp-style="fp-btn: Braided Row 1; fp-font-style: Bold" fp-title="Reply" height="24" src="default/images/button53.jpg" style="border: 0" width="120" class="auto-style1" onmousedown="FP_swapImg(1,0,/*id*/'img7',/*url*/'default/images/button52.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img7',/*url*/'default/images/button53.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img7',/*url*/'default/images/button51.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img7',/*url*/'default/images/button51.jpg')"><br> <textarea rows="5" name="message" id="message" style="width: 311px"></textarea><br><br />
        <input type="submit" value="Send" />    
    		</form>
</div>
</div>
<?php
}
}
else
{
echo '<div class="message">You do not have the rights to access this page.</div>';
}
}
else
{
echo '<div class="message">This private message does not exists.</div>';
}
}
else
{
echo '<div class="message">The private message ID is not defined.</div>';
}
}
else
{
echo '<div class="message">You must be logged to access this page. Please register.</div>';
}
?>
	<div class="foot"><a href="list_pm.php">
		<img id="img1" alt="Back to Inbox" fp-style="fp-btn: Braided Row 3; fp-font-style: Bold" fp-title="Back to Inbox" height="24" onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'default/images/buttonD6.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img1',/*url*/'default/images/buttonD4.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img1',/*url*/'default/images/buttonD5.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'default/images/buttonD5.jpg')" src="default/images/buttonD4.jpg" style="border: 0" width="120"></a></div>
</body>
</html>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.