Tracking User Activity

Started by Mike Bobbitt, May 24, 2005, 12:47:14 PM

Previous topic - Next topic

Mike Bobbitt

Hi Eyesman,

No config page for it unfortunately, but you will want to change the group ID listed in the PHP file to match the group you want to monitor:

// Warning group IDs (primary)
$watchlist = "23";

Eyesman

Hi Mike,

If I understand correctly I have to change it every time I need to track a user?

Thanx!

Mike Bobbitt

No, you just change the watch list group to the group ID you want to use, then add users to that group (as a secondary membership) and they will appear on the list.

Jeet Chowdhury

i got this error,

Fatal error: Call to undefined function db_query() in /home/mobtalk/public_html/tracker.php on line 110

Arantor

Quote from: Jeet Chowdhury on January 28, 2011, 03:34:45 AM
i got this error,

Fatal error: Call to undefined function db_query() in /home/mobtalk/public_html/tracker.php on line 110

You're using 2.0. This does not work on 2.0 and will need to be rewritten to work on 2.0.
Holder of controversial views, all of which my own.


Jeet Chowdhury

ok thank you arantor for the answer. :)

Masterd

This is working with the SMF 2.0.

Arantor

Then why is it calling 1.1.x functions?
Holder of controversial views, all of which my own.


Masterd

Then he downloaded the wrong file.

Since when $smcFunc is SMF 1.1.x function?

Arantor

It isn't, never has been. $func is the equivalent in SMF 1.1.x, for some things and db_query() for others.
Holder of controversial views, all of which my own.


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.
SMF 2.0.2

Robert.

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.
This should work:
<?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";
}
?>

studiowi33

#313
thanks Doc, but(!)...

It doesn't show who's online (like it used to,) so i imputted my own user ID and got these:
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


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...

$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__);

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
SMF 2.0.2

Martine M

Thanks for the script I installed it, will let you know how it works.
Running SMF 2.09 - Diego Andrés Theme Elegant Mind - TP 1.0 - Main Forum language English - Browser Firefox 33


Justin se

nice script.
i'll install it later to my website...

Martine M

Running SMF 2.09 - Diego Andrés Theme Elegant Mind - TP 1.0 - Main Forum language English - Browser Firefox 33


tacosfitnessblog


Astarta

The mod is great! Thank you for your work!
I've tested it with 2.0.2 and it works like a charm!
I've only one question still...
Is it possible to log topic's views only it certain board?
I've looked on tvl_log function (in Sources/TopicViewLog.php), but I do not see the way to accomplish this task. I know the board ID, but how to use it...
with best regards,
Astarta

http://rat.ru/forum/index.php

kasparh

i'm givingv a try on my forum, and it works great doing the job, but i have this error displayed



any idea ?

sorry for the link on imagebam, but i can't attach files

Advertisement: