*

Recent

Author Topic: [v1] User messages  (Read 8912 times)

Danny

  • Newbie
  • *
  • Posts: 41
  • Force: +5/-0
[v1] User messages
« on: January 14, 2009, 06:30:49 PM »
Dylan requested a user messages system. Therefore i coded one, though i'll be building a user list with profile page so the user can actual be contacted via linked from the profile, i will do that tomorrow.

Create a new file called "messages.php" in your "pages" directory.
Add to the file "messages.php":
Code: [Select]
<?php
if(!isset($suserid)){
echo '<div class="error">Please login.</div>';
exit;
}
echo 
' <table align="center">
<tr>
<td class="content4"><a href="'
.$domain.'/index.php?action=messages&case=compose">Compose</a></td>
<td class="content4"><a href="'
.$domain.'/index.php?action=messages&case=deleteall">Delete All</a></td>

</tr>
</table>'
;
switch(
$_GET['case']){
default:
inbox();
break;

case 'compose':
compose();
break;


case 'reply':
reply();
break;

case 'read':
read();
break;


case 'delete':
delete();
break;

case 'deleteall':
deleteall();
break;
}
function 
inbox(){
global $db$domain$userid;

$w $db->query("SELECT * FROM dd_messages WHERE to_userid='{$userid}' ORDER BY datesent DESC");
echo '<h2>Messages</h2>
<table width="100%" border="0" align="center">
<tr>
<th class="header3">#</th>
<th class="header3">Details</th>
<th class="header3">Status</th>
<th class="header3">Options</th>
</tr>
'
;
while($iw $db->fetch_row($w)){
if($iw['status'] == 0){
$status '<font color="green">Unread</font>';
}else{
$status '<font color="red">Read</font>';
}
$gr $db->fetch_row($db->query("SELECT userid, username FROM dd_users WHERE userid='{$iw['from_userid']}'"));
echo ' <tr>
<td class="content3"><div align="center">'
.$iw['ID'].'</div></td>
<td class="content3"><small>
Subject: '
.$iw['subject'].'<br />
Date: '
.date('d/m/Y'$iw['datesent']).'<br />
From: '
.$gr['username'].'<br />
</small></td>
<td class="content3"><div align="center">'
.$status.'</div></td>
<td class="content3" align="center">
<div align="center">
[<a href="'
.$domain.'/index.php?action=messages&case=delete&ID='.$iw['ID'].'">Delete</a> -
 <a href="'
.$domain.'/index.php?action=messages&case=read&ID='.$iw['ID'].'">Read</a>]</div></td>
</tr>'
;
}
echo '</table>

<br />
<div align="center">
<a href="'
.$domain.'/index.php?action=messages&case=deleteall">Delete All</a>
</div>'
;

}
function 
read(){
global $db$domain$template$userid;

$ID abs((int) $_GET['ID']);
$ir $db->query("SELECT * FROM dd_messages WHERE to_userid='{$userid}' AND ID='{$ID}'");

$or $db->fetch_row($ir);
if(!$db->num_rows($ir)){
echo 'Either you do not own that message or it does not exist.';
include ('templates/'.$template.'/footer.php');
exit;
}
$db->query("UPDATE dd_messages SET status='1' WHERE ID='$ID'");
$ud $db->fetch_row($db->query("SELECT username, userid FROM dd_users WHERE userid='{$or['from_userid']}'"));
$message str_replace('\n''<br />'$or['content']);
echo '<table width="95%" border="0" align="center">
<tr>
<td class="header5" width="30%">Message From:</td>
<td class="content5">'
.$ud['username'].'</td>
</tr>
<tr>
<td class="header5">Subject Details</td>
<td class="content5">'
.$or['subject'].'<br /><small>'.date('d/m/Y'$or['datesent']).'</small></td>
</tr>
<tr>
<td class="header5" colspan="2"><div align="center">Message</div></td>
</tr>
<tr>
<td class="content5" colspan="2" valign="top">'
.$message.'</td>
</tr>
</table>
<div align="center"><b>Quick Reply:</b><br>

<form action="'
.$domain.'/index.php?action=messages&case=reply&amp;ID='.$or['from_userid'].'" method="post">
<textarea cols="50" rows="6" name="message"></textarea><br><input name="submit" value="Send" type="submit">
<input name="to" value="'
.$or['from_userid'].'" type="hidden">
<input size="37" name="subject" value="[No Subject]" type="hidden">

</form> </div>
<br />
<b>Your Conversation with '
.$ud['username'].'.</b><br />
<table width="90%" border="0" align="center">
<tr>
<th class="header5">From/Date</th>
<th class="header5">Message</th>
</tr>'
;
$tt $db->query("SELECT m.*,u1.username as MSender from dd_messages m left join dd_users u1 on m.from_userid=u1.userid WHERE (m.from_userid=$userid AND m.to_userid={$ud['userid']}) OR (m.to_userid=$userid AND m.from_userid={$ud['userid']}) ORDER BY m.ID DESC LIMIT 5") or die(mysql_error());

while($row mysql_fetch_array($tt)){
$op $db->fetch_row($db->query("select username from dd_users where userid='{$row['from_userid']}'"));
echo ' <tr align="center">

<td>'
.$op['username'].'
<br /><small>On: '
.date('d/m/Y'$row['datesent']).'</small></td>
<td>'
.$row['content'].'</td>
</tr>'
;

}
echo'</table>';
}
function 
reply(){
global 
$userid$domain$db;
$to abs((int) $_POST['to']);
$message stripslashes(mysql_real_escape_string($_POST['message']));
$subject stripslashes(mysql_real_escape_string($_POST['subject']));
if(!
$to || !$message){ exit; }
$date time();
$db->query("INSERT INTO dd_messages SET
from_userid='
{$userid}',
to_userid='
{$to}',
subject='
{$subject}',
content = '
$message',
status = '0',
datesent='
$date'");
echo 'Message sent.';
}

function 
compose(){
global 
$userid$domain$db$template;
if(isset(
$_POST['submit'])){
$to abs((int) $_POST['to']);
$message stripslashes(mysql_real_escape_string($_POST['message']));
$subject stripslashes(mysql_real_escape_string($_POST['subject']));
if(!
$to || !$message){ exit; }
$date time();
$db->query("INSERT INTO dd_messages SET
from_userid='
{$userid}',
to_userid='
{$to}',
subject='
{$subject}',
content = '
$message',
status = '0',
datesent='
{$date}'");

echo 'Message sent.';
include ('templates/'.$template.'/footer.php');
exit;
}
if(
$to == ''){
$to '';
}else{
$to $ID;
}


echo 
'
<form action="'
.$domain.'/index.php?action=messages&case=compose" method="POST">
<table width="95%" border="0" align="center">
<tr>
<td class="header5" width="30%">To (Userid#):</td>
<td class="content5" width="30%"><input type="text" name="to" value="'
.$to.'" size="35"></td>
</tr>
<tr>
<td class="header5" width="30%">Subject:</td>
<td class="content5" width="30%"><input type="text" name="subject" value="[No Subject]" size="35"></td>
</tr>
<tr>
<td colspan="2" class="header5" align="center">Message</td>
</tr>
<tr>
<td colspan="2" class="content5">
<textarea cols="65" rows="6" name="message"></textarea>
</td>

</tr>
<tr>
<td colspan="2" align="center" class="content5"><input type="submit" name="submit" value="Send"></td>
</tr>

</table>
</form> '
;
}
function 
delete(){
$ID abs((int) $_GET['ID']);
global 
$db$userid;

$db->query("DELETE FROM dd_messages WHERE ID='$ID' AND to_userid='$userid'");
echo 'Deleted.';

}
function 
deleteall(){
global $db$userid;
$db->query("DELETE FROM dd_messages WHERE to_userid='$userid'");
}
$pgname 'Messages';
?>


Open the "index.php" in the main directory.
Find:
Code: [Select]
case 'newest':
include ('pages/newest.php');
break;


Add After:
Code: [Select]
case 'messages':
include ('pages/messages.php');
break;

Open the myaccount.php file via in the page file.
Find:
Code: [Select]
<td class=\'content5\' style=\'padding:3px;\'><a href=\''.$url2.'\'>Change Password</a></td>
Add after that:
Code: [Select]
<td class="content5" style="padding:3px;"><a href="'.$domain.'/index.php?action=messages">Messages</a></td>


Run the query in your mysql database:

Code: [Select]
CREATE TABLE IF NOT EXISTS `dd_messages` (
  `ID` int(11) NOT NULL auto_increment,
  `from_userid` int(11) NOT NULL,
  `to_userid` int(11) NOT NULL,
  `subject` varchar(250) NOT NULL,
  `content` longtext NOT NULL,
  `status` int(11) NOT NULL default '0',
  `datesent` varchar(250) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;


There you go, should work fine any problems, please post here!

Danny.

EDIT: Fixed --- "please login" bug fixed.
« Last Edit: January 27, 2009, 06:19:38 AM by Danny »

DylanParrin

  • Newbie
  • *
  • Posts: 7
  • Force: +0/-0
Re: [v1] User messages
« Reply #1 on: January 15, 2009, 10:07:51 AM »
OMG Thank you so much! This is awesome! And very fast reply! Wow!

Thannnks! :D

-D!

DylanParrin

  • Newbie
  • *
  • Posts: 7
  • Force: +0/-0
Re: [v1] User messages
« Reply #2 on: January 15, 2009, 10:11:04 AM »
i'll be building a user list with profile page so the user can actual be contacted via linked from the profile, i will do that tomorrow.

Wow! That is awesome... I caaan't wait! :D

DylanParrin

  • Newbie
  • *
  • Posts: 7
  • Force: +0/-0
Re: [v1] User messages
« Reply #3 on: January 16, 2009, 11:36:16 AM »
i'll be building a user list with profile page so the user can actual be contacted via linked from the profile, i will do that tomorrow.

Wow! That is awesome... I caaan't wait! :D
Are you adding it today :D?

Danny

  • Newbie
  • *
  • Posts: 41
  • Force: +5/-0
Re: [v1] User messages
« Reply #4 on: January 17, 2009, 07:04:18 PM »
 :P sorry about that, had a few other commercial products to take care of, i will build it soon.

EDIT: userlist done, http://freearcadescript.net/forums/index.php?topic=6.0
« Last Edit: January 17, 2009, 07:49:55 PM by Danny »

DylanParrin

  • Newbie
  • *
  • Posts: 7
  • Force: +0/-0
Re: [v1] User messages
« Reply #5 on: January 22, 2009, 11:37:55 AM »
:P sorry about that, had a few other commercial products to take care of, i will build it soon.

EDIT: userlist done, http://freearcadescript.net/forums/index.php?topic=6.0
Have you done it yet? I'm trying to get my site up by the end of the month...

maverick

  • Newbie
  • *
  • Posts: 34
  • Force: +0/-1
Re: [v1] User messages
« Reply #6 on: January 27, 2009, 02:35:08 AM »
Quote
Please login.

When i try to when i click  Message User

Danny

  • Newbie
  • *
  • Posts: 41
  • Force: +5/-0
Re: [v1] User messages
« Reply #7 on: January 27, 2009, 06:20:11 AM »
Bug has been fixed, reupload the messages.php file with the one up there.