Customizing SMF > Tips and Tricks
Tracking User Activity
Masterd:
I know that. I'm just sarcastic.
studiowi33:
How do u get this to work in 2.0 Gold?
I get a "Fatal error: Call to undefined function db_query() in /home/theozcc1/public_html/tracker.php on line 294".
Thanks for looking.
Doctor Deejay:
--- Quote from: studiowi33 on July 02, 2011, 02:49:56 PM ---How do u get this to work in 2.0 Gold?
I get a "Fatal error: Call to undefined function db_query() in /home/theozcc1/public_html/tracker.php on line 294".
Thanks for looking.
--- End quote ---
This should work:
--- Code: ---<?php
/*
$Id: tracker.php,v 1.29 2006/02/21 14:11:48 bobbitt Exp $
Written by Mike Bobbitt for Army.ca
*/
// Place this script in the same directory as SSI.php, or set the path below
if (file_exists(dirname(__FILE__).'/SSI.php')) {
$ssifile = dirname(__FILE__).'/SSI.php';
} else {
$ssifile = "/var/www/html/forums/SSI.php";
}
// Are we running on Army.ca or standalone?
if (preg_match("/army.ca$/i", $_SERVER["HTTP_HOST"])) {
$armyca = 1;
} else {
$armyca = 0;
}
if ($armyca) {
include_once "/var/www/html/includes/header.php";
} else {
require ($ssifile);
// Set this to restrict access. Currently only admins are allowed.
$isstaff = $user_info['is_admin'];
}
// Make sure we have a DB prefix at least
if (!isset ($db_prefix)) {
$db_prefix = "`smf`.smf_";
}
// Database tables
// These are all default values, and should not need to be changed.
$db_member_table = "members";
$db_log_topics_table = "log_topics";
$db_message_table = "messages";
$db_topics_table = "topics";
$db_boards_table = "boards";
$db_log_boards_table = "log_boards";
$db_log_errors_table = "log_errors";
$db_log_notify_table = "log_notify";
$db_log_online_table = "log_online";
$db_log_actions_table = "log_actions";
// Make sure table name includes database name
$db_member_table = "$db_prefix$db_member_table";
$db_log_topics_table = "$db_prefix$db_log_topics_table";
$db_message_table = "$db_prefix$db_message_table";
$db_topics_table = "$db_prefix$db_topics_table";
$db_boards_table = "$db_prefix$db_boards_table";
$db_log_boards_table = "$db_prefix$db_log_boards_table";
$db_log_errors_table = "$db_prefix$db_log_errors_table";
$db_log_notify_table = "$db_prefix$db_log_notify_table";
$db_log_online_table = "$db_prefix$db_log_online_table";
$db_log_actions_table = "$db_prefix$db_log_actions_table";
if (!$isstaff) {
echo "ERROR: You are not Army.ca Staff.";
if ($armyca) {
include "$include_dir/footer.php";
}
exit (1);
}
// download variables
if (isset ($_REQUEST["function"])) {
$function = $_REQUEST["function"];
}
if (isset ($_REQUEST["u"])) {
$u = $_REQUEST["u"];
}
if (isset ($_REQUEST["user"])) {
$user = $_REQUEST["user"];
}
echo "<h1>User Tracker</h1>\n";
echo "This script tracks the recent actions of all users in The Watch List.<br /><br />\n";
// Warning group IDs (primary)
$watchlist = "23";
// Show "lookup user" form
if (!$function) {
echo<<<HTML
<div class="highlight">Track User</div><br /><br />
<form>
Username, Display Name or User ID #: <input type="text" name="user" />
<input type="hidden" name="function" value="trackuser" />
<br />
<input type="submit" value="Track User">
</form>
<br />
HTML;
}
if ($function == "trackuser") {
// it's a userid, not a username
if (preg_match("/^\d+$/", $user)) {
$u = $user;
} else {
// Generate query
$result = mysql_query("SELECT $db_member_table.`ID_MEMBER` FROM $db_member_table WHERE $db_member_table.`memberName` = \"$user\" OR $db_member_table.`realName` = \"$user\"", __FILE__, __LINE__);
$res = mysql_fetch_array($result);
$u = $res[0];
}
if (!$u) {
echo<<<HTML
<br />
<br />
WARNING: User $user not found. Please search again.
<br />
<br />
HTML;
} else {
$function = "track";
}
}
// Track a user
if ($function == "track") {
// Get username again
$result = mysql_query("SELECT $db_member_table.`realName` FROM $db_member_table WHERE $db_member_table.`ID_MEMBER` = \"$u\"", __FILE__, __LINE__);
$res = mysql_fetch_array($result);
$realName = $res[0];
mysql_free_result($result);
echo "Tracking <a href=\"$scripturl?action=profile;u=$u\">$realName</a>...<br />\n";
echo "<br />Jump to: <a href=\"#boards\">Boards</a> || <a href=\"#topics\">Topics</a> || <a href=\"#monitor\">Monitored Topics</a> || <a href=\"#admin\">Admin Actions</a> || <a href=\"#errors\">Errors</a>";
echo "<a name=\"boards\"><h2>Current Action</h2></a>";
// Get the user's current action
$result = mysql_query("SELECT * FROM $db_log_online_table WHERE $db_log_online_table.`ID_MEMBER` = \"$u\" ORDER BY $db_log_online_table.`logTime` DESC LIMIT 1", __FILE__, __LINE__);
echo "<table>";
while ($res = mysql_fetch_array($result)) {
echo "<tr><td>";
// Decode current action
global $sourcedir;
include_once ("$sourcedir/Who.php");
echo determineActions($res['url']);
echo "</td><td>";
if ($res['logTime']) {
echo $res['logTime'];
}
echo "</td></tr>\n";
}
echo "</table>";
mysql_free_result($result);
echo "<a name=\"boards\"><h2>Recent Boards</h2></a>";
// Get the user's board log
$result = mysql_query("SELECT * FROM $db_log_boards_table WHERE $db_log_boards_table.`ID_MEMBER` = \"$u\"", __FILE__, __LINE__);
echo "<table>";
while ($res = mysql_fetch_array($result)) {
// Get the board title
$result2 = mysql_query("SELECT $db_boards_table.`name` FROM $db_boards_table WHERE $db_boards_table.`ID_BOARD` = \"$res[ID_BOARD]\"", __FILE__, __LINE__);
$res2 = mysql_fetch_array($result2);
$name = $res2[0];
mysql_free_result($result2);
echo "<tr><td><a href=\"$scripturl/board,$res[ID_BOARD].0.html\">$name</a></td><td>";
if ($res['logTime']) {
echo date("Y/m/d H:i:s", $res['logTime']);
}
echo "</td></tr>\n";
}
echo "</table>";
mysql_free_result($result);
echo "<a name=\"topics\"><h2>Recent Topics</h2></a>";
// Get the user's topic log
$result = mysql_query("SELECT * FROM $db_log_topics_table WHERE $db_log_topics_table.`ID_MEMBER` = \"$u\" ORDER BY $db_log_topics_table.`ID_TOPIC` DESC", __FILE__, __LINE__);
echo "<table>";
while ($res = mysql_fetch_array($result)) {
// Get the topic title
$result2 = mysql_query("SELECT $db_message_table.`subject` FROM $db_message_table WHERE $db_message_table.`ID_TOPIC` = \"$res[ID_TOPIC]\"", __FILE__, __LINE__);
$res2 = mysql_fetch_array($result2);
$subject = $res2[0];
mysql_free_result($result2);
echo "<tr><td><a href=\"$scripturl/topic,$res[ID_TOPIC].0.html\">$subject</a></td><td>";
if ($res['logTime']) {
echo date("Y/m/d H:i:s", $res['logTime']);
}
echo "</td></tr>\n";
}
echo "</table>";
mysql_free_result($result);
echo "<a name=\"monitor\"><h2>Monitored Topics/Boards</h2></a>";
// Get the user's notifications list
$result = mysql_query("SELECT * FROM $db_log_notify_table WHERE $db_log_notify_table.`ID_MEMBER` = \"$u\"", __FILE__, __LINE__);
while ($res = mysql_fetch_array($result)) {
// Get the topic title
if ($res[ID_TOPIC]) {
$result2 = mysql_query("SELECT $db_message_table.`subject` FROM $db_message_table WHERE $db_message_table.`ID_TOPIC` = \"$res[ID_TOPIC]\"", __FILE__, __LINE__);
$res2 = mysql_fetch_array($result2);
$subject = $res2[0];
if (!$subject) {
$subject = "Not a valid topic.";
}
mysql_free_result($result2);
echo "<a href=\"$scripturl/topic,$res[ID_TOPIC].0.html\">$subject</a><br />\n";
}
if ($res[ID_BOARD]) {
// Get the board title
$result2 = mysql_query("SELECT $db_boards_table.`name` FROM $db_boards_table WHERE $db_boards_table.`ID_BOARD` = \"$res[ID_BOARD]\"", __FILE__, __LINE__);
$res2 = mysql_fetch_array($result2);
$subject = $res2[0];
mysql_free_result($result2);
echo "<a href=\"$scripturl/board,$res[ID_BOARD].0.html\">$subject</a><br />\n";
}
}
mysql_free_result($result);
echo "<a name=\"admin\"><h2>Admin Actions</h2></a>";
// Get the user's admin actions log
$result = mysql_query("SELECT * FROM $db_log_actions_table WHERE $db_log_actions_table.`ID_MEMBER` = \"$u\" ORDER BY $db_log_actions_table.`logTime` ASC", __FILE__, __LINE__);
echo<<<HTML
<table>
<tr>
<th>Datestamp</th><th>Action</th><th>Details</th><th>IP Address</th>
</tr>
HTML;
while ($res = mysql_fetch_array($result)) {
echo "<tr><td>";
echo date("Y/m/d H:i:s", $res['logTime'])."</td><td>";
echo $res['action']."</td><td>";
include_once ("$sourcedir/Who.php");
echo determineActions($res['extra'])."</td><td>";
echo $res['ip']."</td><td>";
echo "</tr>";
}
mysql_free_result($result);
echo "</table>";
echo "<a name=\"errors\"><h2>Recent Errors</h2></a>";
// Get the user's error log
$result = mysql_query("SELECT * FROM $db_log_errors_table WHERE $db_log_errors_table.`ID_MEMBER` = \"$u\" ORDER BY $db_log_errors_table.`logTime` DESC", __FILE__, __LINE__);
echo "<table>";
while ($res = mysql_fetch_array($result)) {
echo "<tr><td>$res[message]</td><td>";
echo date("Y/m/d H:i:s", $res[logTime]);
echo "</td></tr>\n";
}
echo "</table>";
mysql_free_result($result);
if ($armyca) {
include_once "$include_dir/footer.php";
}
exit (0);
}
// Get list of users in The Watch List
if ($armyca) {
$result = mysql_query("SELECT * FROM $db_member_table WHERE $db_member_table.`additionalGroups` LIKE \"%$watchlist%\"", __FILE__, __LINE__);
echo "Select the user you want to track:<br /><br />\n";
while ($res = mysql_fetch_array($result)) {
echo "<a href=\"$scripturl?action=profile;u=$res[ID_MEMBER]\"><img align=\"middle\" src=\"http://army.ca/forums/Themes/Armyca/images/icons/profile_sm.gif\" border=\"0\"></a> <a href=\"?function=track;u=$res[ID_MEMBER]\">$res[realName]</a><br />\n";
}
mysql_free_result($result);
include "$include_dir/footer.php";
}
?>
--- End code ---
studiowi33:
thanks Doc, but(!)...
It doesn't show who's online (like it used to,) so i imputted my own user ID and got these:
--- Code: ---User Tracker
This script tracks the recent actions of all users in The Watch List.
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 131
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 132
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 134
Tracking ...
Jump to: Boards || Topics || Monitored Topics || Admin Actions || Errors
Current Action
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 143
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 147
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 163
Recent Boards
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 168
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 172
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 186
Recent Topics
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 191
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 195
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 209
Monitored Topics/Boards
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 214
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 216
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 239
Admin Actions
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 244
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 253
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 262
Datestamp Action Details IP Address
Recent Errors
Warning: Wrong parameter count for mysql_query() in /home/theozcc1/public_html/Ztracker.php on line 268
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 272
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/theozcc1/public_html/Ztracker.php on line 278
--- End code ---
I appreciate the effort Doc, just isn't working :(
EDIT: After reverting to the original tracker.php file, this is the contents of line 289...
--- Code: ---$result = db_query("SELECT $db_member_table.realName, $db_member_table.ID_MEMBER FROM $db_log_online_table, $db_member_table WHERE $db_log_online_table.ID_MEMBER = $db_member_table.ID_MEMBER ORDER BY $db_log_online_table.`logTime` DESC", __FILE__, __LINE__);
--- End code ---
I can't see any online users to track and before upgrading to 2.0, I was able to simply click on the name. It kinda works now, but I have to manually enter a User ID into the "Track User" form.
(Sorry if I'm dense about this, it's a great feature.)
Uploaded with ImageShack.us
Martine M:
Thanks for the script I installed it, will let you know how it works.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version