<?php
/**
* FILE_NAME : newsc.php
*
* @copyright Copyright (c) www.shuangyulin.com
* @author 双鱼林设计
* @package 新闻内容页
* @subpackage
* @version QQ:287307421或 254540457
*/

require_once './include/common.inc.php';

/*--  对一些系统变量赋值  --*/
$template->assign("css_root",$css_root);
$template->assign("siteurl",$_CFG['siteurl']);
$template->assign("sitename",$_CFG['sitename']);

/*--  初始化 url 传值  --*/
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 1;

 

/*--  查询文章信息  --*/
$sql = $allsin = '';
$page = $cates = array();

$sql = "SELECT a.aid,a.catid,a.title,a.username,a.dateline,a.viewnum,c.aid,c.content FROM {$dbprefix}articles a LEFT JOIN {$dbprefix}articlecontent c ON a.aid = c.aid WHERE id = $id"; 
$query = $DB->query($sql);
if (!$query) {
	showmessage("您查看的页面不存在，2秒后返回");
}
while ($row = $DB->fetch_array($query)) {
	$row['dateline'] = formatdate($_CFG['format_type'],$row['dateline']);
	$article = $row;
}


/*--  查询出本分类下最热门10条文章  --*/
$sql = "SELECT aid,title FROM {$dbprefix}articles ORDER BY viewnum DESC LIMIT 10"; 
$query = $DB->query($sql);
while ($row = $DB->fetch_array($query)) {
	$row['title'] = cutstr($row['title'],22);//11个字符
	$row['sysurl'] = "newsc.php?id=".$row['aid'];
	$artlist[] = $row;
}

/*--  查询本分类的自定义模板信息  --*/
$sql = "SELECT catid,name,covertemplate,template FROM {$dbprefix}articlecategories WHERE catid =".$article['catid'];
$query = $DB->query($sql);
while ($row = $DB->fetch_array($query)) {
	$cateurl = "news.php?id=".$row['catid'];
	$cate = $row;
}

/*--  更新这篇文章的点击数  --*/
$sql = "UPDATE {$dbprefix}articles SET viewnum = '".($article['viewnum']+1)."' WHERE aid = $id";
$DB->query($sql);

/*--  当该分类的自定义模板为空，使用默认模板  --*/
$pagetpl = '';
if (!$cate['template'] && !$cate['covertemplate']) {	
	$pagetpl = "newsc.html";	
} elseif ($cate['covertemplate']) {
	$pagetpl = $cate['covertemplate'];
} elseif ($cate['template']) {
	$pagetpl = $cate['template'];
}

require_once 'header.php';

/*--  右侧头部名称  --*/
$template->assign("pagename",$cate['name']);
/*--  右侧头部链接  --*/
$template->assign("pageurl",$cateurl);

/*--  右侧文章内容  --*/
$template->assign("title",$article['title']);
$template->assign("username",$article['username']);
$template->assign("dateline",$article['dateline']);
$template->assign("viewnum",$article['viewnum']);
$template->assign("content",$article['content']);

/*--  对左边栏的热门文章赋值  --*/
$template->assign("artlist",$artlist);

$template->display($pagetpl);

require_once 'footer.php';
?>