• [Mod] Keep Track Of What Each User Has Downloaded 4 0 5 1
Currently:  

Author Topic: [Mod] Keep Track Of What Each User Has Downloaded  (Read 231511 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« on: March 13, 2003, 01:03:06 AM »
Updated 03-15-2006 for 4images v1.7.2

Keep Track Of What Each User Has Downloaded
For each registered user, this mod maintains a list of the images they download and the date/time of the their last download.

Summary Description NOTE: This is NOT a download stats or counter mod

It has been said that necessity is the mother of invention. On my web site, I only allow downloads for registered users and I wanted to keep track of who was downloading what.

This mod lets you track what images have been downloaded by each registered user. It also enhances the "Edit Users" function in the admin control panel to let you query all users who downloaded anything before, after, or within a date range you enter by entering dates in both the before and after fields. You can also sort the returned list of users by the last download date in either ascending or descending order.

Once that query list is generated, clicking the "Edit" link next to a specific user will display the following in the "Edit User" HTML form:

1. A text area that holds the id numbers of the images they downloaded.
2. A search link to display those images in a new window.
3. The date and time of the user's last download.

The search link is also displayed in the member_profile.html template if you are logged in as a 4images administrator.

The database table 4images_users is modified to store the image id numbers for all downloads made by each user. It is also modified to store the date and time of the last download.  This code was heavily copied from the lightbox logic so it only took me 4 or 5 hours to research, code, test, document the installation procedure and write an installer to modify the database.  Your time to install this mod is approximately 15 minutes, you lucky bastard!  :wink:

Summary of files affected
[change] admin/users.php

[change] includes/functions.php
[change] includes/sessions.php
[change] includes/db_field_definitions.php

[change] lang/english/main.php
[change] lang/english/admin.php

[change] download.php
[change] member.php
[change] search.php

[change] templates/default/member_profile.html

[new]    4i_install_tud.php


admin/users.php:
Locate:
4images v1.7 - 1.7.1
Code: [Select]
  show_input_row($lang['field_lastaction'].$lang['date_desc'], "user_lastaction", $user_row['user_lastaction'], $textinput_size);4images v1.7.2
Code: [Select]
  show_date_input_row($lang['field_lastaction'].$lang['date_desc'], "user_lastaction", $user_row['user_lastaction'], $textinput_size);
Insert after:
Code: [Select]
  $user_row['download_lastaction'] = date("Y-m-d H:i", $user_row['download_lastaction']); // Mod: Track User Downloads
   $additional_user_fields['downloaded_image_ids'] = array("<a href=\"".ROOT_PATH."search.php?user_downloads=".$user_row['user_id']."\" target=\"_blank\">".$lang['downloaded_image_ids']."</a>", "textarea", 0); // Mod: Track User Downloads
Locate:
4images v1.7 - 1.7.1
Code: [Select]
  show_input_row($lang['field_lastaction_before'].$lang['date_format'], "lastactionbefore", "", $textinput_size);4images v1.7.2
Code: [Select]
  show_date_input_row($lang['field_lastaction_before'].$lang['date_format'], "lastactionbefore", "", $textinput_size);
Insert after:
Code: [Select]
  $user_row['download_lastaction'] = date("Y-m-d H:i", $user_row['download_lastaction']); // Mod: Track User Downloads
  show_input_row($lang['field_download_lastaction_after'].$lang['date_format'], "download_lastaction_after", "", $textinput_size); // Mod: Track User Downloads
  show_input_row($lang['field_download_lastaction_before'].$lang['date_format'], "download_lastaction_before", "", $textinput_size); // Mod: Track User Downloads
Locate:
Code: [Select]
  <option value="<?php echo get_user_table_field("""user_lastaction"); ?>"><?php echo $lang['field_lastaction']; ?></option>Insert after:
Code: [Select]
  <option value="<?php echo get_user_table_field("""download_lastaction"); ?>"><?php echo $lang['field_download_lastaction']; ?></option>Locate:
Code: [Select]
  $lastactionbefore = trim($HTTP_POST_VARS['lastactionbefore']);
  if ($lastactionbefore != "") {
    $condition .= " AND ".get_user_table_field("", "user_lastaction")." < UNIX_TIMESTAMP('$lastactionbefore')";
  }
Insert after:
Code: [Select]
  $download_lastaction_after = trim($HTTP_POST_VARS['download_lastaction_after']); // Mod: Track User Downloads
  if ($download_lastaction_after != "") { // Mod: Track User Downloads
    $condition .= " AND ".get_user_table_field("", "download_lastaction")." > UNIX_TIMESTAMP('$download_lastaction_after')"; // Mod: Track User Downloads
  } // Mod: Track User Downloads
  $download_lastaction_before = trim($HTTP_POST_VARS['download_lastaction_before']); // Mod: Track User Downloads
  if ($download_lastaction_before != "") { // Mod: Track User Downloads
    $condition .= " AND ".get_user_table_field("", "download_lastaction")." < UNIX_TIMESTAMP('$download_lastaction_before')"; // Mod: Track User Downloads
    $condition .= " AND ".get_user_table_field("", "download_lastaction")." > 0"; // Mod: Track User Downloads
  } // Mod: Track User Downloads
Locate:
Code: [Select]
    show_hidden_input("lastactionafter", $lastactionafter);
    show_hidden_input("lastactionbefore", $lastactionbefore);
Insert after:
Code: [Select]
    show_hidden_input("download_lastaction_after", $download_lastaction_after); // Mod: Track User Downloads
    show_hidden_input("download_lastaction_before", $download_lastaction_before); // Mod: Track User Downloads


Open includes/functions.php, at the very bottom and just before the closing:
Code: [Select]
?>Insert before:
Code: [Select]
// Mod: Track User Downloads BLOCK INSERT BEGIN
function add_to_downloaded_image_ids($id) {
  global $user_info, $site_db;
  $id = intval($id);
  if (!$id) {
    return false;
  }
  $downloaded_ids = $user_info['downloaded_image_ids'];
  $downloaded_array = explode(" ", $downloaded_ids);
  if (!in_array($id, $downloaded_array)) {
    $downloaded_ids .= " ".$id;
  }
  $user_info['downloaded_image_ids'] = trim($downloaded_ids);
  $user_info['download_lastaction'] = time();
  $sql = "UPDATE ".USERS_TABLE."
          SET download_lastaction = ".$user_info['download_lastaction'].", downloaded_image_ids = '".$user_info['downloaded_image_ids']."'
          WHERE user_id = ".$user_info['user_id'];
  return ($site_db->query($sql)) ? 1 : 0;
}
// Mod: Track User Downloads BLOCK INSERT END


Open includes/sessions.php, locate at the top:
Code: [Select]
$user_table_fields = array(
  "user_id" => "user_id",
  "user_level" => "user_level",
  "user_name" => "user_name",
  "user_password" => "user_password",
  "user_email" => "user_email",
  "user_showemail" => "user_showemail",
  "user_allowemails" => "user_allowemails",
  "user_invisible" => "user_invisible",
  "user_joindate" => "user_joindate",
  "user_activationkey" => "user_activationkey",
  "user_lastaction" => "user_lastaction",
  "user_location" => "user_location",
  "user_lastvisit" => "user_lastvisit",
  "user_comments" => "user_comments",
  "user_homepage" => "user_homepage",
  "user_icq" => "user_icq"
);
Add a comma at the end of the user_icq line and add a new line after:
Code: [Select]
$user_table_fields = array(
  "user_id" => "user_id",
  "user_level" => "user_level",
  "user_name" => "user_name",
  "user_password" => "user_password",
  "user_email" => "user_email",
  "user_showemail" => "user_showemail",
  "user_allowemails" => "user_allowemails",
  "user_invisible" => "user_invisible",
  "user_joindate" => "user_joindate",
  "user_activationkey" => "user_activationkey",
  "user_lastaction" => "user_lastaction",
  "user_location" => "user_location",
  "user_lastvisit" => "user_lastvisit",
  "user_comments" => "user_comments",
  "user_homepage" => "user_homepage",
  "user_icq" => "user_icq", // Mod: Track User Downloads (comma was added at end of line!)
  "download_lastaction" => "download_lastaction" // Mod: Track User Downloads
);


Open includes/db_field_definitions.php, locate:
Code: [Select]
// Example for additional user fields
//$additional_user_fields['user_adress'] = array($lang['user_adress'], "text", 1);
Insert after:
Code: [Select]
$additional_user_fields['downloaded_image_ids'] = array($lang['downloaded_image_ids'], "textarea", 0); // Mod: Track User Downloads
$additional_user_fields['download_lastaction'] = array($lang['download_lastaction'], "text", 0); // Mod: Track User Downloads


Open lang/english/main.php, at the very bottom and just before the closing:
Code: [Select]
?>Insert before:
Code: [Select]
$lang['downloaded_image_ids'] = "Downloaded Image IDs"; // Mod: Track User Downloads
$lang['download_lastaction'] = "Date Of Last Download"; // Mod: Track User Downloads
$lang['downloaded_images'] = "Downloaded Images"; // Mod: Track User Downloads


Open lang/english/admin.php
Locate:
Code: [Select]
$lang['field_lastaction'] = "Last activity";Insert after:
Code: [Select]
$lang['field_download_lastaction'] = "Last Download"; // Mod: Track User DownloadsLocate:
Code: [Select]
$lang['field_lastaction_before'] = "Last activity before";
$lang['field_lastaction_after'] = "Last activity after";
Insert after:
Code: [Select]
$lang['field_download_lastaction_before'] = "Last download before"; // Mod: Track User Downloads
$lang['field_download_lastaction_after'] = "Last download after"; // Mod: Track User Downloads


Open download.php, locate:
Code: [Select]
  if ($user_info['user_level'] != ADMIN) {
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_downloads = image_downloads + 1
            WHERE image_id = $image_id";
    $site_db->query($sql);
  }
Insert after:
Code: [Select]
  if ($user_info['user_level'] == USER) // Mod: Track User Downloads
    add_to_downloaded_image_ids($image_id); // Mod: Track User Downloads
OPTIONAL: If you want to track downloads from users AND administrators, change
Code: [Select]
  if ($user_info['user_level'] == USER) // Mod: Track User DownloadsTo
Code: [Select]
  if ($user_info['user_level'] >= USER) // Mod: Track User (and administrator) Downloads

Open member.php:
Locate:
Code: [Select]
      "lang_email" => $lang['email'],
      "lang_homepage" => $lang['homepage'],
      "lang_icq" => $lang['icq']
    ));
REPLACE with:
Code: [Select]
      "lang_email" => $lang['email'],
      "lang_homepage" => $lang['homepage'],
      "lang_icq" => $lang['icq'],
      "lang_download_lastaction" => $lang['download_lastaction'], // Mod: Track User Downloads
      "lang_user_downloads" => $lang['downloaded_images'], // Mod: Track User Downloads
      "url_user_downloads" => ($user_info['user_level'] == ADMIN) ? $site_sess->url(ROOT_PATH."search.php?user_downloads=".$user_row['user_id']) : "" // Mod: Track User Downloads
    ));


Open search.php:
Locate:
Code: [Select]
$search_id = array();Insert after:
Code: [Select]
// Mod: Track User Downloads BLOCK INSERT BEGIN
if (isset($HTTP_POST_VARS['user_downloads']) || isset($HTTP_GET_VARS['user_downloads'])) {
   $user_downloads = (isset($HTTP_POST_VARS['user_downloads'])) ? intval($HTTP_POST_VARS['user_downloads']) : intval($HTTP_GET_VARS['user_downloads']);
   if ($user_downloads != "" && $user_info['user_level'] == ADMIN) {
     $show_result = 1;
      $sql = "SELECT downloaded_image_ids
            FROM ".USERS_TABLE."
            WHERE ".get_user_table_field("", "user_id")." = $user_downloads";
     $user_downloads_info = $site_db->query_firstrow($sql);
     $user_downloads_ids = str_replace(" ", ",", trim($user_downloads_info['downloaded_image_ids']));
     $search_id['image_ids'] = $user_downloads_ids;
   }
}
// Mod: Track User Downloads BLOCK INSERT END


Open templates/default/member_profile.html:
Locate:
Code: [Select]
        <tr>
          <td class="row2"><b>{lang_icq}</b></td>
          <td class="row2">{if user_icq}<a href="http://wwp.icq.com/scripts/search.dll?to={user_icq}">{user_icq}</a> (<b>{user_icq_status}</b>){endif user_icq}</td>
        </tr>
Insert after:
Code: [Select]
              {if url_user_downloads}
        <tr>
          <td class="row1"><b>{lang_user_downloads}</b></td>
          <td class="row1"><a href="{url_user_downloads}">{lang_user_downloads}</a></td>
        </tr>
              {endif url_user_downloads}


4i_install_tud.php
Because the database must be modified, and it can be difficult to do correctly, I have written and tested an installer. Download the 4i_install_tud.zip file attached to this post. Extract the 4i_install_tud.php file and upload it to your web site. In a web browser, go to http://www.example.com/4images/4i_install_tud.php and follow the on-screen instructions.  Once your database is successfully updated, you should delete 4i_install_tud.php


Revisions:
*  Enhanced with V@no's add-on that provides a search link in both the admin Control Panel "Edit Users" and the member_profile.html template. Separately we both thought of adding the same feature but V@no beat me to it. Thank you. :)
*  Added "Last Download" to the "Order By" options list for admin CP "Edit Users".
* Attached the installer file to this post, just download it !
« Last Edit: July 19, 2006, 02:17:36 PM by V@no »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #1 on: March 13, 2003, 04:48:35 AM »
Exelent! Good job!

if I may, I'd like add little addon:
it will display a link for search downloaded images (only for admin) in user profile and in "edit user".

[EDITED]
Since this addon was included in original installation, no needed doublepost it. :D
[/EDITED]

The format to search is:
search.php?user_downloads=X
Where X is user ID
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #2 on: March 13, 2003, 05:53:49 AM »
Most excellent.  Great minds think alike huh?  

I was thinking about adding this very feature to the mod not more than 20 minutes after posting it!  Looks like you've saved me the trouble - thanks.

I'll definitely try it out tomorrow.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #3 on: March 14, 2003, 01:34:18 AM »
V@no's add-on has been included in the original instructions.

Also introduced is the ability to sort the user list by the "Last Download" date. This works regardless of whether or not you are editing users based on download date.  Users who have not downloaded anything are treated as having a ZERO download date and will show up at the end of the list if the "Order By" option is set to Descending.

Offline k4nth

  • Newbie
  • *
  • Posts: 28
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #4 on: March 14, 2003, 06:16:26 PM »
how can you make this work with 4images & pbpbb integrated site?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #5 on: March 14, 2003, 06:58:09 PM »
I have no idea since I do not use the "user integration" feature of 4images.  :wink:  If I understand correctly, with user integration, 4images uses the phpBB user table so this mod would need to be adjusted to use that table.

I really don't know what would be needed to make that work but that's were you should begin looking to identify code you need to change.

Offline ParaNike

  • Newbie
  • *
  • Posts: 26
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #6 on: March 27, 2003, 04:50:11 PM »
Can some one edit this mod so that it will work with the vbulletin integration?

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
download tracking in light box
« Reply #7 on: May 26, 2003, 10:07:24 PM »
:idea:   hey chris -

nice tracking module - one problem though ... it doesn't track lightbox selections (i.e. batch zips) - only single downloads ...

any thoughts?

thanx
bruce

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: download tracking in light box
« Reply #8 on: May 26, 2003, 10:33:25 PM »
Quote from: bgmurphy
it doesn't track lightbox selections (i.e. batch zips) - only single downloads ...

in /download.php find:
Code: [Select]
$sql = "SELECT cat_id, image_media_file, image_download_urlreplace with:
Code: [Select]
$sql = "SELECT cat_id, image_media_file, image_download_url, image_id
find next:
Code: [Select]
$file_added = 1;
add after:
Code: [Select]
if ($user_info['user_level'] == USER) // Mod: Track User Downloads
    add_to_downloaded_image_ids($image_row['image_id']); // Mod: Track User Downloads
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Re: download tracking in light box
« Reply #9 on: May 26, 2003, 11:58:08 PM »
v@no -

i replaced/added the code ... but it still didn't record my litebox download so ???

i modified the ----    == user to >= user  -- is that the prob?

thanx
bruce

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #10 on: May 27, 2003, 12:07:25 AM »
ops, sorry...I had typo...
replace
add_to_downloaded_image_ids($image_ros['image_id']);
with
add_to_downloaded_image_ids($image_row['image_id']);
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #11 on: May 27, 2003, 12:14:25 AM »
v@no -

which php module? .. and .. what should i do with the old code i did replace? - delete or ??

better yet .... can you repost the correct file changes procedures <grin> ?

bruce

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #12 on: May 27, 2003, 12:23:38 AM »
Quote from: bgmurphy
v@no -

which php module? .. and .. what should i do with the old code i did replace? - delete or ??
I thought I posted just for one file changes...:roll:

Quote from: bgmurphy
better yet .... can you repost the correct file changes procedures <grin> ?

bruce

I did already...:?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
[Mod] Keep Track Of What Each User Has Downloaded
« Reply #13 on: May 27, 2003, 12:46:22 AM »
v@no -

sorry - tired eyes .. and small type !!!!

i see what you modified now ... 3rd pass thru it ...

will get it corrected

thanx
bruce

Offline crazy4ke

  • Pre-Newbie
  • Posts: 7
    • View Profile
Help please....
« Reply #14 on: June 11, 2003, 01:04:02 AM »
I've followed all of these instructions and am getting the following:

Quote
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/casafeli/public_html/darkroom/includes/functions.php on line 128

Fatal error: Call to undefined function: get_php_version() in /home/casafeli/public_html/darkroom/global.php on line 248


At first I thought it was a trailing empty line at the end of the functions.php file but I've deleted it.