Back to vBulletin 3.0 Add-Ons

Who Downloaded This Attachment - for Gold
Mod Version: 1.00, by Mr Blunt

This modification is in the archives.
vB Version: 3.0.0 Rating: (0 vote - 0 average) Installs: 12
Released: 05 Apr 2004 Last Update: Never Downloads: 3
Not Supported  

// **********************************************
// **********************************************
// Hack to track Who Downloaded attachments
// Old vb2 hack modified to vbulletin 3.0 Gold
// Credit to TWTCommish for the original vb2 hack
// index.php?t=36900
// **********************************************
// **********************************************
4 new templates
2 modified templates
1 modified php file
1 new php file

This hack allows admins, supermods, and mods to see who downloads each file. If you want to allow other groups, just add/subtract them from whodownloaded.php on the top line as desired.

Although I rewrote and tested this myself, and it works like a charm now, I'm not offering support for this. I'm just a Joe Average. This is an old old hack. I just had to change some words like "gettemplate" to "fetch_template" and "dooutput" to "print_output" and one instance of "post" changed to "attachment". Also had to modify table structures and of course figure out where to put everything. I'm fairly certain that this is up-to-snuff but don't take my word for it.

It doesn't track IP's or how many times a user may have downloaded. It just brings up a popup window with the usernames that have downloaded this atachment. Who knows, maybe someone else will build upon this.

Forgive me if I posted this in the wrong place or if it shouldn't be here at all.
Mods, feel free to do what you wish with this.
Just trying to give a little back to those who have taught me.

// **********************************************
// create a new template - whodownloads
// **********************************************
Code:
<html>
<head>
<title>Who Downloaded This?</title>
$headinclude
<script language="JavaScript">self.focus();</script>
</head>
<body>
<table cellpadding="10" cellspacing="0" border="0" width="100%"><tr><td>
<table cellpadding="4" cellspacing="$stylevar[cellspacing]" border="0" width="100%">
	<tr>
		<td class="tcat" width="100%"><b>Total Downloads: $total</b></td>
	</tr>
	<tr>
		<td class="alt1" width="100%"><b>User</b></td>
	</tr>
$whodownloadsbit
	<tr id="cat">
		<td class="thead" width="100%" align="center"><a href="javascript:window.close();">Close Window</a></td>
	</tr>
</table>
</td></tr></table>
</body>
</html>

// **********************************************
// **********************************************
// create a new template - whodownloadsbit
// **********************************************
Code:
<tr>
		<td class="thead"><a href="member.php?s=$session[sessionhash]&action=getinfo&userid=$download[userid]" target="_blank">$download[username]</a></td>
</tr>

// **********************************************
// **********************************************
// create a new template - whodownloads_error
// **********************************************
Code:
<tr>
		<td class="thead">No downloads found.</td>
</tr>

// **********************************************
// **********************************************
// create a new template - whodownloads_error_nop
// **********************************************
Code:
<tr>
		<td class="thead">Sorry, no Permisson.</td>
</tr>

// **********************************************
// **********************************************
// Find this in template - headinclude
// **********************************************
Code:
<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<if condition="$show['popups']"><script type="text/javascript" src="clientscript/vbulletin_menu.js"></script></if>
// **********************************************
// Change it to this
// **********************************************
Code:
<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<if condition="$show['popups']"><script type="text/javascript" src="clientscript/vbulletin_menu.js"></script></if>
<script language="JavaScript">
	<!-- START HIDE
function whodownloaded(attachmentid)
{
	window.open
	("whodownloaded.php?s=$session[sessionhash]&attachmentid=" + attachmentid, "whodownloaded", "toolbar=no, scrollbars=yes, resizable=no, width=240, height=300, top=50, left=50");
}
  -->
</script>

// **********************************************
// **********************************************
// Find this in template - postbit_attachment
// **********************************************
Code:
<tr>
	<td><img class="inlineimg" src="$stylevar[imgdir_attach]/$attachment[attachmentextension].gif" alt="<phrase 1="$attachment[attachmentextension]">$vbphrase[file_type_x]</phrase>" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="attachment.php?$session[sessionurl]attachmentid=$attachment[attachmentid]" target="_blank">$attachment[filename]</a> ($attachment[filesize], <phrase 1="$attachment[counter]">$vbphrase[x_views]</phrase></td>
</tr>
// **********************************************
// Change it to this
// **********************************************
Code:
<tr>
	<td><img class="inlineimg" src="$stylevar[imgdir_attach]/$attachment[attachmentextension].gif" alt="<phrase 1="$attachment[attachmentextension]">$vbphrase[file_type_x]</phrase>" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="attachment.php?$session[sessionurl]attachmentid=$attachment[attachmentid]" target="_blank">$attachment[filename]</a> ($attachment[filesize], <phrase 1="$attachment[counter]">$vbphrase[x_views], </phrase></td>
	<td><a href="javascript:whodownloaded($attachment[attachmentid])">Who Downloaded This?</a>)</td>
</tr>

// **********************************************
// **********************************************
// create a new php file - whodownloaded.php
// place it in the main forum (upload) directory
// (same directory that has attachment.php)
// **********************************************
Code:
<?php
require("./global.php");
if (($bbuserinfo[usergroupid] == 6 OR $bbuserinfo[usergroupid] == 5 OR $bbuserinfo[usergroupid] == 7) AND $attachmentid)
{
	$downloads = $DB_site->query("SELECT u.userid, u.username FROM user u WHERE u.downloads LIKE \"$attachmentid%\" OR u.downloads LIKE \"%$attachmentid%\" OR u.downloads LIKE \"%$attachmentid\" ORDER BY u.username ASC");
	$total     = $DB_site->query_first("SELECT counter FROM attachment WHERE attachmentid = $attachmentid");
	$total     = $total[counter];
	if (!$DB_site->num_rows($downloads))
	{
		eval("\$whodownloadsbit .= \"".fetch_template("whodownloads_error",1,0)."\";");
	}
	else
	{
		while ($download = $DB_site->fetch_array($downloads))
		{
			eval("\$whodownloadsbit .= \"".fetch_template("whodownloadsbit",1,0)."\";");
		}
	}
}
else
{
	eval("\$whodownloadsbit .= \"".fetch_template("whodownloads_error_nop",1,0)."\";");
}
eval('print_output("' . fetch_template('whodownloads') . '");');
?>

// **********************************************
// **********************************************
// Find this in attachment.php
// **********************************************
Code:
			// or doing it once an hour
			$DB_site->shutdown_query("
				INSERT INTO " . TABLE_PREFIX . "attachmentviews (attachmentid)
				VALUES ($attachmentid)
			");
		}
	}
// **********************************************
// Change it to this
// **********************************************
Code:
			// or doing it once an hour
			$DB_site->shutdown_query("
				INSERT INTO " . TABLE_PREFIX . "attachmentviews (attachmentid)
				VALUES ($attachmentid)
			");
		}
	}
	// here's the who downloaded hack
	$dl    = $DB_site->query_first("SELECT downloads FROM user WHERE userid = $bbuserinfo[userid]");
	$comma = ($dl[downloads]) ? ',' : '';
	$DB_site->query("
		UPDATE user
		SET downloads = '$dl[downloads]$comma$attachmentid'
		WHERE userid = $bbuserinfo[userid]
	");

// **********************************************
// **********************************************
// Run this SQL Query from Admincp
// **********************************************
Code:
ALTER TABLE user ADD COLUMN downloads TEXT NOT NULL;
If you had this installed previously, like for vb2, then don't rerun the query.
The query didn't change so I'D SUSPECT the old and new data is compatible.

And make sure you have completely removed the old vb2 hack beforehand or I suspect this would create a conflict.

Download

No files for download.

Similar Mods

Who Downloaded This Attachment vBulletin 3.5 Add-ons
Most Downloaded Attachment vBulletin 2.x Full Releases

vblts.ru supports vBulletin®, 2022-2024