PDA

View Full Version : Chat Log


pets.ca
03-07-2005, 07:01 PM
Hi there,

I require the ability to keep a log of all chat activity on my board. I plan to have a single chat room only. Is there a way to dump all activity (time/date stamped) to a text file?

thanks

dave

wacnstac
03-07-2005, 11:52 PM
This would be useful to me as well.

Zero Tolerance
03-08-2005, 05:38 PM
It may be created for a future version, thats not a promise.

- Zero Tolerance

sv1cec
03-09-2005, 09:10 AM
It may be created for a future version, thats not a promise.

- Zero Tolerance
If I may, add this code at the end of your admin_vbchat.php file, before the ?> :


// ###################### Do View Messages ########################
if ($_GET['do'] == "viewmessages" )
{
$file="vbchat_store";
globalize($_REQUEST, array(
'sid' => INT,
'perpage' => INT,
'page' => INT,
'orderby' => STR,
));
print_cp_header("vBChat System");

$perpage=20;

if ($page < 1)
{
$page = 1;
}
$startat = ($page - 1) * $perpage;

$counter=$DB_site->query_first("SELECT COUNT(*) AS messages FROM " . TABLE_PREFIX . "{$file} AS message");

if ($counter['messages']==0 or $counter['messages']=='')
{
$url='admin_vbchat.php';
$wait=5;
print_cp_message("No Chat Messages to Show.", $url, $wait);
}

$totalpages = ceil($counter['messages'] / $perpage);

$Get_Chat_MSG = $DB_site->query("select m.*,u.*,t.username AS tusername, t.userid AS tuserid from ".TABLE_PREFIX."{$file} m
left join ".TABLE_PREFIX."user u on (u.userid = m.s_postby)
left join ".TABLE_PREFIX."user t on (t.userid = m.s_foruser)
order by m.s_postime LIMIT $startat, $perpage");

if ($DB_site->num_rows($Get_Chat_MSG))
{

if ($page != 1)
{
$prv = $page - 1;
$firstpage = "<input type=\"button\" class=\"button\" value=\"&laquo; " . $vbphrase['first_page'] . "\" tabindex=\"1\" onclick=\"window.location='admin_vbchat.php?$session[sessionurl]do=viewmessages&perpage=$perpage&orderby=$orderby&file=$file&page=1'\">";
$prevpage = "<input type=\"button\" class=\"button\" value=\"&lt; " . $vbphrase['prev_page'] . "\" tabindex=\"1\" onclick=\"window.location='admin_vbchat.php?$session[sessionurl]do=viewmessages&perpage=$perpage&orderby=$orderby&file=$file&page=$prv'\">";
}

if ($page != $totalpages)
{
$nxt = $page + 1;
$nextpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['next_page'] . " &gt;\" tabindex=\"1\" onclick=\"window.location='admin_vbchat.php?$session[sessionurl]do=viewmessages&perpage=$perpage&orderby=$orderby&file=$file&page=$nxt'\">";
$lastpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['last_page'] . " &raquo;\" tabindex=\"1\" onclick=\"window.location='admin_vbchat.php?$session[sessionurl]do=viewmessages&perpage=$perpage&orderby=$orderby&file=$file&page=$totalpages'\">";
}

$aa=($page-1)*$perpage+1;
if ($page<$totalpages)
{
$bb=$page*$perpage;
}
else
{
$bb=$counter['messages'];
}
$cc=$counter['messages'];

print_form_header('', '');

print_table_header("View vBChat Messages<br>Page $page of $totalpages<br>Messages $aa to $bb of $cc",14);

$header = array();

$header[] = "<b>ID</b>";
$header[] = "<b>Poster Name</b>";
$header[] = "<b>Message</b>";
$header[] = "<b>Date/Time</b>";
$header[] = "<b>To User</b>";

print_cells_row($header, 1);

while($message=$DB_site->fetch_array($Get_Chat_MSG))
{

$cell = array();

// $message[date] = vbdate ( $vboptions['dateformat'], $message[s_postime] ) ;
$message[time] = vbdate ( $vboptions['timeformat'], $message[s_postime] ) ;
$message[date]=date("d-m-Y");

if($message['s_foruser']=="0")
{
$touser='All';
}
else
{
$touser=$message[tusername];
}

$cell[] = "<font size='-1'>$message[sid]</font>";
$cell[] = "<font size='-1'>$message[username]<br>$message[userid]</font>";
$cell[] = "<font size='-1'>$message[s_message]</font>";
$cell[] = "<font size='-1'>$message[date]<br>$message[time]</font>";
$cell[] = "<font size='-1'>$touser<br>$message[tuserid]</font>";

print_cells_row($cell);

}
print_table_footer(5, "$firstpage $prevpage &nbsp; $nextpage $lastpage");
}
}


Then edit your admincp/index.php file and find:


construct_nav_option ( 'Chat Prune Options', 'admin_vbchat.php?do=prune', '<br />' ) ;


Right below that, add:


construct_nav_option ( 'Chat Log', 'admin_vbchat.php?do=viewmessages', '<br />' ) ;


Let me know if that works.

Of course, you should not have the prune chat option active, or else the messages will be deleted.

AzHousePro
03-20-2005, 07:09 AM
Looks like it works to me. Nice job.

How hard would it be to code something that dumped the entire log to a text file on the server?

Mike

Deaths
03-20-2005, 10:23 AM
Why dump it to a .txt file, if it's already in the DB?

AzHousePro
03-20-2005, 04:25 PM
Just thought it would be nice to dump the log to a text file every once in a while and purge the database.

Mike

sv1cec
03-24-2005, 02:39 AM
That, Sir, I have no idea how to do it.

Diana Notacat
04-17-2005, 01:57 AM
This was brilliantly useful!

Is it possible to make some modifications to this to allowing viewing logs for the created rooms as well? Perhaps a menu to "view Logs for X room"?

Deaths
04-17-2005, 05:57 AM
Would you want it to be an actual file on your server, which is updated at regular bases, or do you just want to be able to download the .txt file?

sv1cec
04-17-2005, 11:32 AM
This was brilliantly useful!

Is it possible to make some modifications to this to allowing viewing logs for the created rooms as well? Perhaps a menu to "view Logs for X room"?
If there is need I could modify the code for you, to show logs per room. It works as it is for me, my board's chat is not that much used, so the users are pretty happy with the Main Room only.

As it is now, the log shows all messages, from all rooms.

Rgds

Diana Notacat
04-17-2005, 10:56 PM
Displaying for specific rooms is definetly a need! I use multiple rooms for roleplay plus private discussions outside of the main room!

I don't need logs saved as a text file, though if I could download/save them I'd actually preffer them in a html that also display the fonts/colors.

An also uncessary wish would be to display logs with/without the PMs incase I wanted to quick copy logs to display elsewhere; like a community event, planning, ect without comprimising the privacy of PMs!

sv1cec
04-18-2005, 11:57 AM
The problem is that the various chat rooms are stored in the database as numbers, in a way that does not allow consistency. This is at least my understanding on how things work, maybe Zero can shed some more light on this one. Let's take this example:

Your main room is number 0.
The admin creates a permanent room, this gets number 1.
A user creates another room (temporary), which gets number 2.

In the database, messages are all stored in the same table, with a column indicating which room each message was posted in.

So let's assume there are people in every one of the rooms above and they are discussing. Then the users from room 2 log out and soon after that, the room is deleted. Then, the admin decides that he no longer wants room 1 and he deletes that too. And soon after that another user creates a new temporary room, which now gets number 1. People start posting new messages in this new temporary room. Guess what happens?

Messages from the old permanent room, which had number 1 and messages from the new temporary room 1, get mixed up and if you ask for the log, they will show together. This is a byproduct of how the program handles rooms and messages. In order to have proper logs per chat room, the chatrooms should have a unique index, as they are created, which never gets given to another chatroom. And every message stored in the database would be characterized by that index, so that at any time, you can ask for the log of that room, and the program would get the messages, based on that index.

As you understand, this would require a lot of changes in the existing code, and the only one responsible for deciding if this should be done or not, is ZT.

As for logs not showing the Personal Messages, that's easy to do, you just change the query which generates the log, from this:


$Get_Chat_MSG = $DB_site->query("select m.*,u.*,t.username AS tusername, t.userid AS tuserid from ".TABLE_PREFIX."{$file} m
left join ".TABLE_PREFIX."user u on (u.userid = m.s_postby)
left join ".TABLE_PREFIX."user t on (t.userid = m.s_foruser)
order by m.s_postime DESC LIMIT $startat, $perpage");


to something like this:


$Get_Chat_MSG = $DB_site->query("select m.*,u.*,t.username AS tusername, t.userid AS tuserid from ".TABLE_PREFIX."{$file} m
left join ".TABLE_PREFIX."user u on (u.userid = m.s_postby)
left join ".TABLE_PREFIX."user t on (t.userid = m.s_foruser)
where s_foruser='0' order by m.s_postime DESC LIMIT $startat, $perpage");


That will give you a reverse-sorted (newer messages first) log, containing only the messages which were public (to all users).

Rgds

TimBrown
07-08-2005, 05:10 AM
Great mod!

If the log gets too big, how is it deleted? Will that be a problem?

Tulsa
07-31-2005, 03:41 PM
Love the mod but while I can see the first page of the log, it won't seem to allow me to view the rest of the pages.