4images Forum & Community
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 15, 2018, 01:14:15 PM

Login with username, password and session length
Search:     Advanced search
Togle to toolbar
Translate this page with =>
Translate this page >
* Home Help Search Login Register
 
+  4images Forum & Community
|-+  4images Modifications / Modifikationen
| |-+  Mods & Plugins (Releases & Support) (Moderators: mawenzi, Rembrandt)
| | |-+  [Mod] Keep Track Of What Each User Has Downloaded
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3 4 5 ... 12 » »» Print
Current Topic Rating: *****
Author Topic: [Mod] Keep Track Of What Each User Has Downloaded  (Read 171716 times)
Chris
4images Moderator
4images Guru
*****
Offline Offline

Posts: 4487

Thank You
-Given: 0
-Receive: 31

Did u ever stop to think and then forget to start?


View Profile
« 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
1
  show_input_row($lang['field_lastaction'].$lang['date_desc'], "user_lastaction", $user_row['user_lastaction'], $textinput_size);
4images v1.7.2
1
  show_date_input_row($lang['field_lastaction'].$lang['date_desc'], "user_lastaction", $user_row['user_lastaction'], $textinput_size);

Insert after:
1
2
  $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
1
  show_input_row($lang['field_lastaction_before'].$lang['date_format'], "lastactionbefore", "", $textinput_size);
4images v1.7.2
1
  show_date_input_row($lang['field_lastaction_before'].$lang['date_format'], "lastactionbefore", "", $textinput_size);

Insert after:
1
2
3
  $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:
1
  <option value="<?php echo get_user_table_field("""user_lastaction"); ?>"><?php echo $lang['field_lastaction']; ?></option>
Insert after:
1
  <option value="<?php echo get_user_table_field("""download_lastaction"); ?>"><?php echo $lang['field_download_lastaction']; ?></option>
Locate:
1
2
3
4
  $lastactionbefore = trim($HTTP_POST_VARS['lastactionbefore']);
  if ($lastactionbefore != "") {
    $condition .= " AND ".get_user_table_field("", "user_lastaction")." < UNIX_TIMESTAMP('$lastactionbefore')";
  }
Insert after:
1
2
3
4
5
6
7
8
9
  $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:
1
2
    show_hidden_input("lastactionafter", $lastactionafter);
    show_hidden_input("lastactionbefore", $lastactionbefore);
Insert after:
1
2
    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:
Insert before:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$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:
1
2
// Example for additional user fields
//$additional_user_fields['user_adress'] = array($lang['user_adress'], "text", 1);
Insert after:
1
2
$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:
Insert before:
1
2
3
$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:
1
$lang['field_lastaction'] = "Last activity";
Insert after:
1
$lang['field_download_lastaction'] = "Last Download"; // Mod: Track User Downloads
Locate:
1
2
$lang['field_lastaction_before'] = "Last activity before";
$lang['field_lastaction_after'] = "Last activity after";
Insert after:
1
2
$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:
1
2
3
4
5
6
  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:
1
2
  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
1
  if ($user_info['user_level'] == USER) // Mod: Track User Downloads
To
1
  if ($user_info['user_level'] >= USER) // Mod: Track User (and administrator) Downloads


Open member.php:
Locate:
1
2
3
4
      "lang_email" => $lang['email'],
      "lang_homepage" => $lang['homepage'],
      "lang_icq" => $lang['icq']
    ));
REPLACE with:
1
2
3
4
5
6
7
      "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:
1
$search_id = array();
Insert after:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 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:
1
2
3
4
        <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:
1
2
3
4
5
6
              {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. Smile
*  Added "Last Download" to the "Order By" options list for admin CP "Edit Users".
* Attached the installer file to this post, just download it !

* 4i_install_tud.zip (1.62 KB - downloaded 1538 times.)
* 4i_install_tud_fixed.zip (1.6 KB - downloaded 842 times.)
« Last Edit: July 19, 2006, 02:17:36 PM by V@no » Logged

V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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. Very Happy
[/EDITED]

The format to search is:
search.php?user_downloads=X
Where X is user ID
Logged

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)
Chris
4images Moderator
4images Guru
*****
Offline Offline

Posts: 4487

Thank You
-Given: 0
-Receive: 31

Did u ever stop to think and then forget to start?


View Profile
« 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.
Logged

Chris
4images Moderator
4images Guru
*****
Offline Offline

Posts: 4487

Thank You
-Given: 0
-Receive: 31

Did u ever stop to think and then forget to start?


View Profile
« 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.
Logged

k4nth
Newbie
*
Offline Offline

Posts: 28

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #4 on: March 14, 2003, 06:16:26 PM »

how can you make this work with 4images & pbpbb integrated site?
Logged
Chris
4images Moderator
4images Guru
*****
Offline Offline

Posts: 4487

Thank You
-Given: 0
-Receive: 31

Did u ever stop to think and then forget to start?


View Profile
« 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.
Logged

ParaNike
Newbie
*
Offline Offline

Posts: 26

Thank You
-Given: 0
-Receive: 0


View Profile
« 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?
Logged
bgmurphy
Full Member
***
Offline Offline

Posts: 113

Thank You
-Given: 0
-Receive: 0


View Profile
« 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
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« Reply #8 on: May 26, 2003, 10:33:25 PM »

Quote from: bgmurphy   [Expand]
it doesn't track lightbox selections (i.e. batch zips) - only single downloads ...

in /download.php find:
1
$sql = "SELECT cat_id, image_media_file, image_download_url
replace with:
1
$sql = "SELECT cat_id, image_media_file, image_download_url, image_id

find next:
1
$file_added = 1;

add after:
1
2
if ($user_info['user_level'] == USER) // Mod: Track User Downloads
    add_to_downloaded_image_ids($image_row['image_id']); // Mod: Track User Downloads
Logged

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)
bgmurphy
Full Member
***
Offline Offline

Posts: 113

Thank You
-Given: 0
-Receive: 0


View Profile
« 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
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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']);
Logged

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)
bgmurphy
Full Member
***
Offline Offline

Posts: 113

Thank You
-Given: 0
-Receive: 0


View Profile
« 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
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« Reply #12 on: May 27, 2003, 12:23:38 AM »

Quote from: bgmurphy   [Expand]
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...Rolling Eyes

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

bruce

I did already...Confused
Logged

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)
bgmurphy
Full Member
***
Offline Offline

Posts: 113

Thank You
-Given: 0
-Receive: 0


View Profile
« 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
Logged
crazy4ke
Pre-Newbie

Offline Offline

Posts: 7

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #14 on: June 11, 2003, 01:04:02 AM »

I've followed all of these instructions and am getting the following:

Quote  [Expand]
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.
Logged
Pages: [1] 2 3 4 5 ... 12 » »» Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.24 seconds with 19 queries.
Post your comments here