function download()
{
global $vbulletin, $db, $attach;
if (!$vbulletin->GPC['thumb'])
{ //not thumbnail view
if (empty($attach))
{ //vb3.x
$attachmentinfo = $db->query_first_slave("
SELECT attachmentid, attachment.userid, filesize, thread.forumid
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = attachment.postid)
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (post.threadid = thread.threadid)
WHERE " . ($vbulletin->GPC['postid'] ? "attachment.postid = " . $vbulletin->GPC['postid'] : "attachmentid = " . $vbulletin->GPC['attachmentid'])
);
}
else if (array_pop(explode('_', strtolower(get_class($attach)))) == 'post')
{ //vb4.x
$attachmentinfo = $db->query_first_slave("
SELECT a.attachmentid, fd.userid, fd.filesize, thread.forumid
FROM " . TABLE_PREFIX . "attachment AS a
INNER JOIN " . TABLE_PREFIX . "filedata AS fd ON (a.filedataid = fd.filedataid)
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = a.contentid)
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (post.threadid = thread.threadid)
WHERE a.attachmentid = " . intval($attach->attachmentid)
);
}
if ($attachmentinfo)
{ //only forum attachments
VBCREDITS::action('download', $vbulletin->userinfo['userid'], $attachmentinfo['attachmentid'], false, array('forumid' => $$attachmentinfo['forumid'], 'multiplier' => $attachmentinfo['filesize'], 'ownerid' => $attachmentinfo['userid']));
}
}
}