CREATE TABLE `bb_history` (
  `id` mediumint(9) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `topics_id` int(11) NOT NULL,
  `forums_id` int(11) NOT NULL,
  `time` int(11) NOT NULL,
  `torrent_up` bigint(20) unsigned NOT NULL default '0',
  `torrent_all_down` bigint(20) unsigned NOT NULL default '0',
  `torrent_down` bigint(20) unsigned NOT NULL default '0',
  `torrent_bonus` bigint(20) unsigned NOT NULL default '0',
  `torrent_ratio` bigint(20) unsigned NOT NULL default '0',
  `torrent_time` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

download.php


for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++)
{
    $auth_pages[$i]['post_id'] = intval($auth_pages[$i]['post_id']);
 
    if ($auth_pages[$i]['post_id'] != 0)
    {
        $sql = 'SELECT forum_id, topic_id
            FROM ' . BB_POSTS . '
            WHERE post_id = ' . (int) $auth_pages[$i]['post_id'];
 
        if ( !($result = DB()->sql_query($sql)) )
        {
            message_die(GENERAL_ERROR, 'Could not query post information', '', __LINE__, __FILE__, $sql);
        }
 
        $row = DB()->sql_fetchrow($result);
 
        $forum_id = $row['forum_id'];
        $topics_id = $row['topic_id'];
        $is_auth = array();
        $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
 
        if ($is_auth['auth_download'])
        {
            $authorised = TRUE;
        }
        if(!$history = DB()->fetch_rowset("SELECT topics_id FROM bb_history WHERE topics_id = $topics_id")){
            DB()->query("INSERT INTO bb_history
                (id, user_id, topics_id, forums_id, time)
            VALUES
                ('', '".$userdata['user_id']."', '".$topics_id."', '".$forum_id."', '". TIMENOW ."')");
        }
    }
}