<?php
define('CURSCRIPT', 'article');
require_once './engine/common.inc.php';
require_once './engine/attachment.func.php';
require_once './clientdata/cache/cache_navigation.php';
require_once './engine/gateweicode.func.php';
$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*5;
$rpp=5;
$floor=($curpage==1)?2:(($curpage-1)*$rpp+2);
$q = $db->query("SELECT a.* , b.* , c.userid FROM g_article_content b , g_articles a left join g_members c ON a.uid = c.uid  WHERE a.aid=$aid and a.aid = b.aid LIMIT 1");
	if(!$allarticle=$db->fetch_array($q)){
			showmsg("文章不存在或未通过审核");
	};
	$view=++$allarticle['view'];
	$categoryid=$allarticle['categoryid'];
	$pid= $allarticle['pid'];
	$displayway=$articlecategory[$categoryid]['displayway'];
	//如果是直接显示，调整导航
	if(!$displayway){
	$maincategory=$subcategory=array();
	$maincategory[$categoryid]['categorytitle']=$articlecategory[$categoryid]['categorytitle'];
	$q=$db->query("SELECT aid , articletitle FROM g_articles where categoryid=$categoryid order by ord desc");
	while($article=$db->fetch_array($q)){
			$subcategory[$article['aid']]=$article['articletitle'];
		}
	}


$siteheadtitle=implode(' ',array($allarticle['articletitle'],$articlecategory[$categoryid]['categorytitle'],$sitename,$sitekeywords));
	$q = $db->query("UPDATE g_articles SET view = $view WHERE aid =$aid LIMIT 1");
	$aq = $db->query("SELECT * FROM g_attachments WHERE bid=$aid and typeid=1");
	while($q_attach=$db->fetch_array($aq)){
			$q_attach['icon']=attachtype(fileext($q_attach['storename'])."\t".$q_attach['type']);
			$allattachs[$q_attach['fid']]=$q_attach;
		}
	$totalrecord=$db->result($db->query("SELECT count(*) FROM g_replys WHERE typeid = 1 and bid = $aid"),0);
	$rq=$db->query("SELECT a.*,b.uid,b.userid,b.userface,b.gid,b.postcount,b.registertime FROM g_replys a left join g_members b ON a.reply_uid=b.uid WHERE a.typeid = 1 and a.bid = $aid limit $startrecord,$rpp");
	while($q_reply=$db->fetch_array($rq)){
		$q_reply=ismemberexist($q_reply);
		$replys[]=$q_reply;
		$raq = $db->query("SELECT * FROM g_attachments WHERE bid = {$q_reply['rid']} and typeid=4");
	while($q_attachs=$db->fetch_array($raq)){
			$q_attachs['icon']=attachtype(fileext($q_attachs['storename'])."\t".$q_attachs['type']);
			$replyattachs[$q_reply['rid']][$q_attachs['fid']]=$q_attachs;
		}
	}
$message=gateweicode($allarticle['content']);
  foreach($replys as $key => $val){
	$rrrid=$val['rid'];
	$replys[$key]['content']=gateweicode($val['content']);
	$replys[$key]['ip']=$val['ip1'].'.'.$val['ip2'].'.*.*';//此处设置调整显示ip显示的位数
	$replys[$key]['floor']=$floor;
	$floor++;
}

if(!empty($allattachs)){
		foreach($allattachs as $key => $val){
				if(!in_array($key,$displayattachs)){
				$downattachs[$key]=$val;
			}
		}
	}

if(!empty($replyattachs)){
		foreach($replyattachs as $keys => $vals){
			foreach($vals as $key => $val){
				if(!in_array($key,$displayattachs)){
				$replydownattachs[$keys][$key]=$val;
				}
			}
		}
	}

$multipage=multi($totalrecord, 5, $curpage, "viewarticle.php?aid=".$aid);
include($templatedir."viewarticle.tpl.php");


