<?php
define('IN_PHPMPS', true);
require dirname(__FILE__) . '/include/common.inc.php';
$nolook=1;
$act = $_REQUEST['act'] ? $_REQUEST['act'] : 'list';
switch($act){
 case 'list':
    $res = $db->query("select * from {$table}type where module='article'");
	$type = array();
	while($row = $db->fetchrow($res)) {
		$row['url'] = url_rewrite('article', array('iid'=>$row['typeid'],'act'=>'list'));
		$type[] = $row;
	}
	$typeid  = !empty($_REQUEST['typeid']) ? intval($_REQUEST['typeid']) : '';
	$typewhere = $typeid ? " AND typeid = '$typeid' " : '';

	$page = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;
	$size = !empty($_CFG['pagesize']) && intval($_CFG['pagesize']) > 0 ? intval($_CFG['page_size']) : 20;

	$count = $db->getOne("SELECT COUNT(*) FROM {$table}article WHERE 1 ".$typewhere. $areaid_sql);
	$max_page = ($count> 0) ? ceil($count / $size) : 1;
	if($page>$max_page)$page = $max_page;
	$pager['search'] = array('typeid' => $typeid);
	$pager = page('article', $typeid, '', $count, $size, $page);

	$sql = "SELECT * FROM {$table}article WHERE 1 " .$typewhere.$areaid_sql." ORDER BY is_pro desc,listorder desc,id DESC LIMIT $pager[start],$pager[size]";
	$res = $db->query($sql);
	$articles = array();
	while($row = $db->fetchRow($res)) {
		$row['title']    = $row['is_pro']==1 ? '<span class="bor_1 f12">荐</span>'.$row['title'] : $row['title'];
		$row['addtime']  = mdate($row['addtime']);
		$row['thumbs']      = !empty($row['thumb']) ? PHPMPS_PATH.$row['thumb'] : $CFG['com_thumbs'];
		$row['description'] = !empty($row['description']) ? str_replace("&nbsp;","",strip_tags($row['description']))."..." : '';
		$row['url']      = url_rewrite('article',array('aid'=>$row['id'],'act'=>'view'));
		$articles[]      = $row;
	}
    
	$cat_info = $db->getOne("SELECT typename FROM {$table}type WHERE typeid = '$typeid'");
	$art_cat       = !empty($cat_info) ? $cat_info : '分类';
	$page_id = 'article_list';

    $seo['title'] = '资讯列表_'.$CFG['webname'];
    include tpl('article_list');
	break;
//View
  case 'view':
	$id = intval($_REQUEST['id']);
	$typeid = intval($_REQUEST['typeid']);
	if(empty($id))  showmsg('缺少参数！');
	$article = $db->getRow("SELECT * FROM {$table}article WHERE id='$id'");
	if(empty($article))showmsg('不存在此文章', 'index.php');
	extract($article);
	$addtime = date('Y-m-d H:i', $addtime);
	//$com_info = com_info("comname",$comid);
	//$com_url = url_rewrite('com',array('act'=>'view','comid'=>$comid));
	
	$db->query("UPDATE {$table}article SET click=click+1 WHERE id='$id'");

    $seo['title']   = $title."_".$CFG['webname'];
    include tpl('article_view');
	break;
}
?>