function AdkViewDownload()
{
    global $sourcedir, $txt, $modSettings, $context, $user_info, $scripturl, $smcFunc, $boardurl, $memberContext;
    if (!empty($_REQUEST['down']) && is_numeric($_REQUEST['down'])) {
        $id_view = (int) $_REQUEST['down'];
    } else {
        fatal_lang_error('adkfatal_require_id_file', false);
    }
    //Get All information
    $sql = $smcFunc['db_query']('', '
		SELECT
		p.id_file, p.id_cat, 
	 	p.approved, p.views, p.title, p.id_member, m.real_name, p.date, p.description, p.main_image, p.id_topic, c.error,
	   	c.title AS CAT_TITLE, c.id_parent, p.totaldownloads,  p.lastdownload, m.avatar, c.id_parent, t.id_board,
			IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
			IFNULL(t.id_topic, p.id_topic) AS id_topic
		FROM ({db_prefix}adk_down_file as p,  {db_prefix}adk_down_cat AS c)
		LEFT JOIN {db_prefix}members AS m ON  (p.id_member = m.id_member)
		LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
		LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = p.id_topic)
		WHERE p.id_file = {int:id} AND p.id_cat = c.id_cat LIMIT 1', array('id' => $id_view));
    //If no query
    if ($smcFunc['db_num_rows']($sql) == 0) {
        fatal_lang_error('adkfatal_this_download_not_exist', false);
    }
    $row = $smcFunc['db_fetch_assoc']($sql);
    $smcFunc['db_free_result']($sql);
    if (!empty($row['error'])) {
        fatal_lang_error('adkfatal_this_download_not_exist', false);
    }
    //Verify if we can view
    verifyCatPermissions('view', $row['id_cat']);
    //It's not approved? (dissaproved :|)
    if ($row['approved'] == 0 && $user_info['id'] != $row['id_member'] && !allowedTo('adk_downloads_manage')) {
        fatal_lang_error('adkfatal_this_download_not_approved', false);
    }
    //$height and width
    $width = 75;
    $height = 75;
    $context['adkDownloadInformation'] = array('id_file' => $row['id_file'], 'id_cat' => $row['id_cat'], 'views' => $row['views'], 'file_title' => $row['title'], 'id_member' => $row['id_member'], 'member' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', 'date' => timeformat($row['date'], '%d/%m/%Y (%I:%M:%S %p)'), 'description' => parse_bbc($row['description']), 'cat' => '<a href="' . $scripturl . '?action=downloads;cat=' . $row['id_cat'] . '">' . $row['CAT_TITLE'] . '</a>', 'id_parent' => $row['id_parent'], 'totaldownloads' => $row['totaldownloads'], 'lastdownload' => empty($row['lastdownload']) ? $txt['adkdown_never'] : timeformat($row['lastdownload'], '%d/%m/%Y'), 'approved' => $row['approved'], 'image' => $row['main_image'], 'id_topic' => $row['id_topic'], 'id_board' => $row['id_board'], 'topic_exists' => checkTopicDownload($row['id_topic']), 'avatar' => $row['avatar'] == '' ? $row['id_attach'] > 0 ? '<img title="' . $row['real_name'] . '" style="vertical-align: middle;" width="' . $width . '" height="' . $height . '" src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" />' : '' : (stristr($row['avatar'], 'http://') ? '<img title="' . $row['real_name'] . '" style="vertical-align: middle;" width="' . $width . '" height="' . $height . '"src="' . $row['avatar'] . '" alt="" border="0" />' : '<img title="' . $row['real_name'] . '" style="vertical-align: middle;" width="' . $width . '" height="' . $height . '"src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar']) . '" alt="" border="0" />'));
    //Set the lintkree
    setLinktree('downloads', 'adkdown_downloads');
    CheckCatParent($row['id_parent']);
    setLinktree('downloads;cat=' . $row['id_cat'], $row['CAT_TITLE'], false, true);
    setLinktree('downloads;sa=view;down=' . $row['id_file'], $row['title'], false, true);
    $context['sub_template'] = 'adk_view_file';
    $context['page_title'] = $row['title'];
    //Views + 1 if i can
    if (empty($_SESSION['adk_download_view'][$id_view])) {
        $smcFunc['db_query']('', "UPDATE {db_prefix}adk_down_file\n\t\t\tSET views = views + 1 WHERE id_file = {int:id} LIMIT 1", array('id' => $id_view));
        $_SESSION['adk_download_view'][$id_view] = true;
    }
    //Load Attachments
    $context['load_attachments'] = getAttachments($id_view);
    //Please, load all info member.
    loadMemberData($context['adkDownloadInformation']['id_member'], false, 'profile');
    loadMemberContext($context['adkDownloadInformation']['id_member']);
    //Finaly, make my context string ;)
    $context['member'] = $memberContext[$context['adkDownloadInformation']['id_member']];
}
function CheckCatParent($id_cat)
{
    global $smcFunc, $scripturl, $context;
    /***
     * Load all links trees... when id_parent != 0
     ***/
    if ($id_cat != 0) {
        $sql = $smcFunc['db_query']('', '
			SELECT id_parent, title FROM {db_prefix}adk_down_cat
			WHERE id_cat = {int:cat}', array('cat' => $id_cat));
        $row = $smcFunc['db_fetch_assoc']($sql);
        $smcFunc['db_free_result']($sql);
        //Again?
        CheckCatParent($row['id_parent']);
        setLinktree('downloads;cat=' . $id_cat, $row['title'], false, true);
    }
}