9 Replies - 2551 Views - Last Post: 21 July 2009 - 07:55 PM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

simple PM system alert?

Posted 21 July 2009 - 12:34 PM

I'm currently using a PM system that i got from here, everything works fine.

but i would like to know how to set some sort of alert! when a user get's a new PM here are my scripts if needed.

http://www.dreaminco...mp;#entry708645

sendpm.php
<?php
session_start();
require("config.php");

$message = $_POST['forward2'];
 if (isset($_POST['submit']))
{
// if the form has been submitted, this inserts it into the Database 
  $to_user = $_POST['to_user'];
  $from_user = $_POST['from_user'];
  $message = $_POST['message'];
  mysql_query("INSERT INTO messages (to_user, message, from_user) VALUES ('$to_user', '$message', '$from_user')")or die(mysql_error());
  echo "PM succesfully sent!";
  echo '<br><br><strong>REDIRECTING</strong>.....<meta http-equiv="refresh" content="2;url=http://www.starcraftx.com/sendpm.php">.';
}
else
{
	// if the form has not been submitted, this will show the form
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">

<input type="hidden" name="from_user" maxlength="32" value = <?php echo $_SESSION['user']; ?>>

<tr><td background="myphpadmin/rusers/bg.gif">To User: </td>
<td background="myphpadmin/rusers/bg.gif"><input type="text" size="35" name="to_user" maxlength="32" value = "">
<script TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=listusers2.php;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>

<A HREF="listusers2.php"onclick="return popup(this, 'notes')">List of users</A>
</td></tr>

<tr><td bgcolor="#C0C0C0">Message: </td>
<td bgcolor="#C0C0C0"><TEXTAREA NAME="message" COLS=160 ROWS=10 WRAP=SOFT></TEXTAREA>
</td></tr>

<tr><td colspan="2" align="right" background="myphpadmin/rusers/bg.gif">
<input type="submit" name="submit" value="Send Message">
</td></tr>
</table>
</form>
<?php
}
?>



sentpm.pm
<?php
session_start();
require("config.php");

$user = $_SESSION['user'];
if (isset($_POST['delete'])) {
	$id = $_POST['id'];  
	mysql_query("UPDATE messages SET sent_deleted = 'yes' WHERE from_user = '$user' AND id = '$id'")or die(mysql_error());
	echo "Message succesfully deleted from your outbox.";
	echo '<br><br><strong>REDIRECTING</strong>.....<meta http-equiv="refresh" content="2;url=http://www.starcraftx.com/sentpm.php">.';
}
$user = $_SESSION['user'];
$sql = mysql_query("SELECT * FROM messages WHERE from_user = '$user' AND sent_deleted = 'no'")or die(mysql_error());

while($row = mysql_fetch_array( $sql ))
{
  echo "<table border=1>";
  echo "<tr><td background='images/smallx.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "<strong>Message ID</strong>#: ";
  echo $row['id'];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "<strong>To</strong>: ";
  echo $row['to_user'];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "<strong>From</strong>: ";
  echo $row['from_user'];
  echo "</td></tr>";

  echo "<tr><td bgcolor='#999999'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "<strong>Message</strong>: ";
  echo $row[message];
  echo "</td></tr>";
  echo "</br>";
?>

<br />
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">

<input type="hidden" name="id" maxlength="5" value = "<?php echo $row['id']; ?>">
<input type="submit" name="delete" value="Delete">

</table>
</form>

<?php
}
  echo "</table>";
  echo "</br>";
?>



inboxpm.php
<?php
session_start();
require("config.php");

$user = $_SESSION['user'];

if (isset($_POST['view_old'])) {
$user = $_SESSION['user'];
$query = mysql_query("SELECT * FROM messages WHERE to_user = '$user' AND deleted = 'no'")or die(mysql_error());
while($row2 = mysql_fetch_array($query))
{ 
  echo "<table border=1>";
  echo "<tr><td background='images/smallx.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "Message ID#: ";
  echo $row2['id'];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "To: ";
  echo $row2['to_user'];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "From: ";
  echo $row2['from_user'];
  echo " ";
  echo "</td></tr>";

  echo "<tr><td bgcolor='#999999'><font size='2' color='#000000' face='verdana'>";
  echo "Message: ";
  echo bb ($row2['message']);
  echo "</td></tr>";
  echo "</br>";
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2></td></tr>

<input type="hidden" name="id" maxlength="32" value = "<?php echo $row2['id']; ?>">
</td></tr>

<tr><td colspan="2" align="right">
<input type="submit" name="delete" value="Delete PM">
</td></tr>
</table>
</form>
<?php
}
}

if (isset($_POST['delete'])) {
$id = $_POST['id'];
$user = $_SESSION['user'];
$sql = mysql_query("UPDATE messages SET deleted = 'yes' WHERE id = '$id' AND to_user = '$user'")or die(mysql_error());
echo "Your message has been succesfully deleted.";
echo '<br><br><strong>REDIRECTING</strong>.....<meta http-equiv="refresh" content="2;url=http://www.starcraftx.com/inboxpm.php">.';
}

$sql = mysql_query("SELECT * FROM messages WHERE to_user = '$_SESSION[user]'")or die(mysql_error());
while($row = mysql_fetch_array($sql))
{ 
$user = $_SESSION['user'];
  echo "<table border=1>";
  echo "<tr><td background='images/smallx.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "Message ID#: ";
  echo $row[id];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "To: ";
  echo $row[to_user];
  echo "</td></tr>";

  echo "<tr><td background='myphpadmin/rusers/bg.gif'><font size='2' color='#FFFFFF' face='verdana'>";
  echo "From: ";
  echo $row[from_user];
  echo "</td></tr>";

  echo "<tr><td bgcolor='#999999'><font size='2' color='#000000' face='verdana'>";
  echo "Message: ";
  echo $row[message];
  echo "</td></tr>";

  echo "</br>";
  mysql_query("UPDATE messages SET read_yet = 'yes' WHERE to_user = '$user' AND id ='$row_id'")or die(mysql_error());
?>

<br>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">


<input type="hidden" name="id" maxlength="32" value = "<?php echo $row['id']; ?>">


<input type="submit" name="delete" value="Delete PM">


</table>
</form>

<?

}
echo "</table>";
?>


This post has been edited by dangmnx: 21 July 2009 - 12:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: simple PM system alert?

#2 indevelop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 09

Re: simple PM system alert?

Posted 21 July 2009 - 12:53 PM

You would have to use AJAX on the page where you want the user to be alerted.

Pick a framework, I recommend jquery, and have it poll the PHP script using an HTTP request to check whether a new message has arrived (at any interval you choose; 1 minute or 5 minutes, etc). When a new message arrives, the user can be alerted right on the page, without any redirects or page changes.
You can use any javascript ajax framework for this; not necessarily jquery.
Was This Post Helpful? 0
  • +
  • -

#3 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: simple PM system alert?

Posted 21 July 2009 - 01:11 PM

AJAX is not required if you just put a simple function call ...

function CheckForNewPm() {
// change this to select form the DB those messages that have NOT been read yet ... might need a extra field
$q = "SELECT COUNT(*) as new FROM messages WHERE to_user = '$user' AND deleted = 'no' AND read='false'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);

if ($v['new'] >0) { return true; } else { return false; }
}



and simply use it on a page you want to check on ...
maybe under a displayed username

echo $user . "<br/>";
if (CheckForNewPm()) {
echo "You have a new message!<br/>";
}



than everytime the page refreshes it checks for new messages ...

This post has been edited by RPGonzo: 21 July 2009 - 01:12 PM

Was This Post Helpful? 0
  • +
  • -

#4 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: simple PM system alert?

Posted 21 July 2009 - 01:28 PM

do i nsert that in each of my php file? or a specific one?

function CheckForNewPm() {
// change this to select form the DB those messages that have NOT been read yet ... might need a extra field
$q = "SELECT COUNT(*) as new FROM messages WHERE to_user = '$user' AND deleted = 'no' AND read='false'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);

if ($v['new'] >0) { return true; } else { return false; }
}





and i insert that under the user's name?
echo $user . "<br/>";
if (CheckForNewPm()) {
echo "You have a new message!<br/>";
}


Was This Post Helpful? 0
  • +
  • -

#5 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: simple PM system alert?

Posted 21 July 2009 - 01:30 PM

The function needs to be on each page you want the function available to you ... so if you want it available to use on every page maybe include it on something that is included on every page for ease of use ( like a header file or a session file )

I just used the users name as a example you put that

if (CheckForNewPm()) {
echo "You have a new message!<br/>";
}



wherever you want to display to the user they have a new PM ...
Was This Post Helpful? 0
  • +
  • -

#6 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: simple PM system alert?

Posted 21 July 2009 - 01:52 PM

i get a error

Quote

Fatal error: Call to undefined function checkfornewpm() in /home/dangmnne/public_html/index.php on line 83


when i insert this code.
<?php
include ('connect.php');
echo $user . "<br/>";
if (CheckForNewPm()) {
echo "You have a new message!<br/>";
}
?>

Was This Post Helpful? 0
  • +
  • -

#7 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 889
  • Joined: 08-August 08

Re: simple PM system alert?

Posted 21 July 2009 - 01:55 PM

have you included the actual function ?? naybe put it in your connect.
Was This Post Helpful? 0
  • +
  • -

#8 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: simple PM system alert?

Posted 21 July 2009 - 02:20 PM

Yes that is what your going to get if your trying to use the function before you included or declared it ... .. is the function in the connect.php file? and i ( for some strange odd reason ) like to make random letters caps so check the spelling CheckForNewPm lol
Was This Post Helpful? 0
  • +
  • -

#9 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: simple PM system alert?

Posted 21 July 2009 - 05:44 PM

okay;

its working but how can i fix this error that it gives me.

Quote

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dangmnne/public_html/login.php on line 29


<?php
include ('config.php');
function CheckForNewPm() {
// change this to select form the DB those messages that have NOT been read yet ... might need a extra field
$q = "SELECT COUNT(*) as new FROM messages WHERE to_user = '$user' AND deleted = 'no' AND read='false'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);

if ($v['new'] >0) { return true; } else { return false; }
}
echo $user . "<br/>";
if (CheckForNewPM()) {
echo "You have a new message!<br/>";
}
?>

Was This Post Helpful? 0
  • +
  • -

#10 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: simple PM system alert?

Posted 21 July 2009 - 07:55 PM

its this ...

$q = "SELECT COUNT(*) as new FROM messages WHERE to_user = '$user' AND deleted = 'no' AND read='false'";
$r = mysql_query($q);



the column read prob doesn't exist unless you created it ... in my PM system i have a column that is set to false when the user has not visited the PM yet .. as soon as they load it it switches the column to true ... really its a tinyint field either storing 1 = true or 0 = false

You can either remove that part or modify around it ... so change up the query to something that works for your database and that error should go away
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1