Hello everyone,
Please help me on this one, How do i embed sound notifications for new messages in a chat room...
Here's my index file...
<?php
if(!session_start()){
session_start();
}
//echo $_SESSION['username'];
$link = mysql_connect("localhost", "root")or die("cannot connect");
mysql_select_db("chat")or die("cannot select Database");
if($_REQUEST['action']=="login"){
$_SESSION['username']=$_REQUEST['user'];
$_SESSION['old_messages']=array('0');
}
if($_REQUEST['action']=="logout"){
if(session_start){
session_destroy();
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Chat</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php if($_SESSION['username']!=NULL && $_REQUEST['action']!="logout"){ ?>
<div align="right">
<a href="index.php?action=logout">(Logout)</a>
</div>
<form action="panel.php" method="Post" target="panel">
<input type="hidden" name="receiver_id" value="1">
<table align="center" width="324px" style="background-color: #73cff5;" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="50%" align="left"><img src="/images/top-left.jpg" width="16"><br><br></td>
<td width="50%" align="right"><img src="/images/top-right.jpg" width="16"><br><br></td>
</tr>
<tr>
<td align="center" colspan="2">
<iframe id="panel" name="panel" src="panel.php" height="360" width="312"
marginheight="0" marginwidth="0" frameborder="0" scrolling="auto">
Your Browser does not support inline frames please switch to a different browser
or update your current browser.</iframe>
<td>
</tr>
<tr>
<td align="center" colspan="2">
<textarea id="message" name="message" style="width: 312px;height: 60px;"></textarea>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input type="hidden" name="action" value="post_message">
<input type="hidden" name="username" value="<?php echo $_SESSION['username']; ?>">
<input type="submit" value="Send" >
</td>
</tr>
<tr align="center">
<td width="50%" align="left"><img src="/images/bottom-left.jpg" width="16"></td>
<td width="50%" align="right"><img src="/images/bottom-right.jpg" width="16"></td>
</tr>
</table>
</form>
<?php } else {?>
<br><br>
<form action="index.php" method="post">
<table align="center" valign="center" width="324px" style="background-color: #73cff5;" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="50%" align="left"><img src="/images/top-left.jpg" width="16"><br><br></td>
<td width="50%" align="right"><img src="/images/top-right.jpg" width="16"><br><br></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="text" name="user" value="Enter username here" style="color: #999999;">
<input type="hidden" name="action" value="login">
<input type="submit" value="Send">
</td>
</tr>
<tr align="center">
<td width="50%" align="left"><br><img src="/images/bottom-left.jpg" width="16"></td>
<td width="50%" align="right"><br><img src="/images/bottom-right.jpg" width="16"></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>
and here's my messages file; to retrieve and store messages from MySQL
<?php
if(!session_start()){
session_start();
}
//echo $_SESSION['username'];
$link = mysql_connect("localhost", "root")or die("cannot connect");
mysql_select_db("chat")or die("cannot select Database");
if($_POST['action']=="post_message" && $_REQUEST['message']!=NULL){
mysql_query("INSERT INTO messages VALUES(NULL , CURTIME() , CURDATE(), '$_REQUEST[username]', '$_POST[message]')");
}
if($_REQUEST['action']=="delete"){
mysql_query("DELETE FROM messages WHERE id = $_REQUEST[id]");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="10">
<link rel="stylesheet" type="text/css" href="/style.css">
<script type="text/javascript">
function directTo(userId){
window.parent.document.getElementById('message').value = userId+">>";
}
</script>
<style type="text/css">
b{
color:#000000;
}
body{
background-color: #FFFFFF;
}
.deleteButton{
color: #FFFFFF;
background-color: #FF0000;
padding-left: 2px;
padding-right: 2px;
line-height:14px;
}
.deleteButton:hover{
color: #FFFFFF;
background-color: #999999;
}
</style>
</head>
<body>
<?php
$result = mysql_query ("SELECT * FROM messages WHERE date = CURDATE() ORDER BY time DESC");
$i=1;
$count=0;
while($message = mysql_fetch_array($result)){
//Set message background color to null
$message_color="";
//Set avatar to default if user has image set avatar to user image
$avatar="default";
if($message['image']==1){
$avatar=$message['sender_id'];
}
//Check if message is new
$new_messages{$i}=$message['id'];
if(!in_array($message['id'], $_SESSION['old_messages']) && $_SESSION['username'] != $message['name']) {
if($count==0 && $i==1){
echo "<EMBED SRC=\"chord.wav\" HIDDEN=\"TRUE\" AUTOSTART=\"TRUE\" width=\"10\" height=\"5\"></EMBED>";
$message_color="background-color: yellow;";
$count=1;
}
}
?>
<table width="296 " style="font:normal 10pt verdana;border-bottom: dotted 1px #A0A0A0;<?php echo $message_color; ?>">
<tr>
<td rowspan="2" height="80" width="64" valign="top">
<a href="javascript: directTo('<?php echo $message['name']; ?>')" style="display: block;background-color: #FFFFFF;border: solid 1px #CFCED2;width: 68px; height: 68px;">
<img src="images/<?php echo $message['name']; ?>.jpg" style="border: solid 4px #FFFFFF;width: 60px; height: 60px;">
</a>
</td>
<td align="left" colspan="2">
<b><?php echo $message['name']; ?></b><br>
<?php echo $message['message']; ?>
</td>
</tr><tr>
<td style="font-size: 8pt;color: B0B0B0;" align="right">
<?php //echo get_login_status($message['activity_log']); ?></td>
<td style="font-size: 8pt;color: B0B0B0;" align="right"><?php echo $message['time']; ?><br>
<?php if($_SESSION['username'] == $message['name']){
echo "<a class=\"deleteButton\" href=\"panel.php?action=delete&id=".$message['id']."\">Delete</a>";
} ?></td>
</tr>
</table>
<?php
$i++;
} ?>
<?php
$_SESSION['old_messages']=$new_messages;
?>
</body>
</html>