<?php
/*============================*\
|| ###########################||
|| # vBulletin PHPFORCE增强包#||
|| # -------------------------||
|| # http://www.phpforce.cn  #||
|| ###########################||
\*============================*/

$phrasegroups = array('postbit');
// pre-cache templates used by all actions
$globaltemplates = array(
	'whodownloadsbit',
	'whodownloads',

);

require("./global.php");


$attachmentid = $vbulletin->input->clean_gpc('r', 'attachmentid', TYPE_UINT);

if ($attachmentid AND ($vbulletin->userinfo['permissions']['hack_joey_permissions'] & $vbulletin->bf_ugp_hack_joey_permissions['canviewdu']))
{
	$whodowns = $db->query_first("
		SELECT counter, whodown
		FROM " . TABLE_PREFIX . "attachment
		WHERE attachmentid = $attachmentid
	");
	$downsuser = ereg_replace("(^\,|\,$)|[^0-9\,]", "", implode(",",array_unique(explode(",",$whodowns['whodown']))));
	$downloads = $db->query_read("
		SELECT userid, username
		FROM " . TABLE_PREFIX . "user
		WHERE userid IN (0".$downsuser.")
		ORDER BY username ASC
	");

		$dnum = 0;
	if ($db->num_rows($downloads))
	{
		while ($download = $db->fetch_array($downloads))
		{
			$dnum++; 
			eval('$whodownloadsbit .= "' . fetch_template('whodownloadsbit') . '";');
		}
	}
	if($downsuser!=$whodowns['whodown'] && $attachmentid){
			$db->query_write("
				UPDATE " . TABLE_PREFIX . "attachment SET
				 whodown = '$downsuser'
				WHERE attachmentid = $attachmentid
			");
	}	
}
else
{
		print_no_permission();

}

eval('print_output("' . fetch_template('whodownloads') . '");');

/*========================================*\
|| ########################################
|| Downloaded: Fri Jan 30th 2009 14:59:49
|| ########################################
\*========================================*/
?>