<?php
defined('IN_TS') or die('Access Denied.');

$attachid=intval($_GET['id']);
$strattach = $new['attach']->find('attach',array(
                                                'attachid'=>$attachid,
                                                ));

if ($strattach == '') {
	header ( "HTTP/1.1 404 Not Found" );
	header ( "Status: 404 Not Found" );
	$title = '404';
	include pubTemplate ( "404" );
	exit ();
}

$arrattachuser = aac ( 'user' )->getSimpleUser ( $strattach ['userid'] );


//是否关注
if($TS_USER['userid'] != '' && $TS_USER['userid'] != $arrattachuser['userid']){
	$userid=$arrattachuser['userid'];
	$followNum = $db->once_num_rows("select * from ".dbprefix."user_follow where userid='".$TS_USER['userid']."' and userid_follow='$userid'");
	if($followNum > '0'){
		$arrattachuser['isfollow'] = true;
	}else{
		$arrattachuser['isfollow'] = false;
	}
}else{
	$arrattachuser['isfollow'] = false;
}

// 是否审核
if ($strattach ['isaudit'] == 1 && $TS_USER['isadmin']==0 && $TS_USER['userid']!=$strattach['userid']) {
	tsNotice ( '内容审核中...' );
}

$file_dir = "uploadfile/attach/".$strattach['attachurl'];
$filemd5=md5_file($file_dir);
if($filemd5)
{
	
}else
{
	$filemd5="File_Erro!";
	
}

// 获取评论
$page = isset ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1;
$url = tsUrl ( 'attach', 'show', array (
		'id' => $attachid,
		'page' => '' 
) );
$lstart = $page * 10 - 10;

$arrComments = $new ['attach']->findAll ( 'attach_comment', array (
		'attachid' => $attachid 
), 'addtime desc', null, $lstart . ',10' );

foreach ( $arrComments as $key => $item ) {
	$arrComment [] = $item;
	$arrComment[$key]['content'] = tsDecode($item['content']);
	$arrComment [$key] ['user'] = aac ( 'user' )->getSimpleUser ( $item ['userid'] );
}

$commentNum = $new ['attach']->findCount ( 'attach_comment', array (
		'attachid' => $attachid 
) );

$pageUrl = pagination ( $commentNum, 10, $page, $url );

// 标签
//$strattach ['tags'] = aac ( 'tag' )->getObjTagByObjid ( 'attach', 'attachid', $strattach ['attachid'] );
$title = $strattach['attachname'];
include template ( "show" );
