<?php
if(!defined('R_P')) exit('Access Denied');
$id = intval($_GET['id']);
$cid = 0;
$_output = qbase::get_object('content', $channelid, $id)->get();
if (empty($_output)) qbase::showmsg("没有找到您要找的" . $channeltitle, $skin , toPath($channelid));
$cid = $_output['cid'];

$_category_info = getCidInfo( $channelid, $cid);
if(empty($_category_info)) qbase::purviewCheckDie("提交了错误参数");

$iif = !( $_category_info['pur_browse'] || $_category_info['html'] || $_output['pay']);
$_output['url']  = qbase::GetHtmlDirType($_output['channelid'], $_output['id'], $_category_info['ciddir'], $_output['dateline'],$_output['filename'],$_output['ver'],$iif);
$_output['edit_time'] = qbase::formatTime('Y-m-d H点', $_output['edit_time']);

if(($_category_info['pur_browse'] || $_output['pay']) && !qbase::is_admin())
{//权限检测
	require( R_P.'/include/class.userpay.php');
	$pay_purview = array(
		'id' => $id,
		'cid' => $cid,
		'point'        => $_output['requirepoint'],
		'read_purview' => $_output['read_purview'],
		'pay_type'     => $_output['pay_type'],
		'read_last'    => $_output['read_last'],
	);
	$purview = new userpay($channelid, $pay_purview, trim(urldecode($_GET['param'])));
	$_output['paid'] = $purview->checkSureLink('view');
	$_output['paid']++;
	if($_output['paid'] != 2) qbase::purviewCheckDie("此文档属收费内容，需支付后才能继续查看");
}


$downurls = array();
$user_info = qbase::get_object('login')->checkSession();
$hash = qbase::array2string(
	array(
		't'=>$_SERVER['REQUEST_TIME'],
		'p'=>qbase::get_ip(),
		'u'=>$user_info['uid']
	)	
);
$md5 = strtoupper(substr(md5($hash . $_SET['passport_key']), 0, 15));
$encodeHash = urlencode(base64_encode($hash));
$encodeHashLink = "hash={$encodeHash}&md5={$md5}";
if($_output['type'] == 1){
	if(false === ($server_config = cache::get('sys_server'))){
		$server_config = qbase::get_object('server')->cache();
	}
	$temp = qdb::queryfirst("select id, pid, serverid from ".TABLEPRE."downloads_{$channelid}  where id='$id'");
	if(!empty($temp)){
		$sids = explode(",", $temp['serverid']);
		foreach($sids as $sid){
			$sid = intval($sid);
			if($sid > 0 && isset($server_config[$sid]) && $server_config[$sid]['server_islock'] == 0){
				$downurls[] = array(
					'id'=>$id,
					'pid'=>$temp['pid'],
					'name'=>$server_config[$sid]['server_name'],
					'sid'=>$sid
				);
			}
		}
	}
}else{
	$downurls = qbase::get_object('content', $channelid, $id)->get_s();
	foreach($downurls as &$val){
		$val['name'] = $val['url_name'];
	}
	unset($val);
}
if( !is_array($downurls)) qbase::purviewCheckDie("数据不存在，请联系管理员");


$showphp = '';
if($_output['showphp']){
	$showphp = $_output['showphp'];
}elseif($info['showmessage']){
	$showphp = $info['showmessage'];
}else{
	$showphp = qbase::GetCidSkin(2);
}

include qbase::template($skin .'/download/showdown');
?>