<?php
header('Content-Type: text/html; Charset=utf-8');
require_once('header.php');
include_once("classes/pageclass.php");

$cateid=intval($_GET["cateid"]);
$cid=intval($_GET["cid"]);

$page=intval($_GET["page"]);
if ($page==0) $page=1;

if ($cid>0){
   $fn="list-c";
   $tagsql  = "select * from {$tablepre}category where category_status=1 and category_id=".$cid."";
   $sql     = "select * from {$tablepre}category where category_status=1 and category_id=".$cid." order by category_order asc";
   $plink['cid']=$cid;
   $wznav=get_msgcate($cid);
   if ($html_flag==1){
      $map_nav = '<a href=list-'.$wznav['cate1_id'].'.html>'.$wznav['cate1_name'].'</a><span>></span>'.$wznav['cate2_name'];
   }else{
      $map_nav = '<a href=list.php?cateid='.$wznav['cate1_id'].'>'.$wznav['cate1_name'].'</a><span>></span>'.$wznav['cate2_name'];
   }
   $list_title=$wznav['cate2_name'].'_'.$wznav['cate1_name'];

   $category_id=$wznav['cate1_id'];
   $list_keywords=$wznav['cate2_name'].','.$wznav['cate1_name'];
   $list_desc='专业提供海量的'.$wznav['cate1_name'].'资源下载,并可在线预览运行效果.';
   
   location_to_murl("list.php?cid=".$cid);
}else{
   $fn="list";
   $tagsql  = "select * from {$tablepre}category where category_status=1 and category_id=".$cateid."";
   $sql     = "select * from {$tablepre}category where category_status=1 and category_parentid=".$cateid." order by category_order asc";
   $plink['cateid']=$cateid;
   $wznav=get_msgcate($cateid);
   $map_nav = $wznav['cate2_name'];
   $list_title=$wznav['cate2_name'];

   $category_id=$cateid;
   $list_keywords=$wznav['cate2_name'];
   $list_desc='专业提供海量的'.$wznav['cate2_name'].'资源下载,并可在线预览运行效果.';
   
   location_to_murl("list.php?cateid=".$cateid);
}


//$list_title=$wznav['cate2_name'];

$rscate  = $db->get_all($sql);
foreach ($rscate as $k=>$v){
    $catelist[$k]=$v['category_id'];
}
$idstr=implode(",",$catelist);

$tagarr  = $db->get_row($tagsql);

$taglist = explode(",",$tagarr['category_desc']);
$taglist = array_slice($taglist,0,12);

//GROUP BY cm.msg_id,cm.category_id
$str = "select m.*,cm.category_id,cm.hits_num,cm.down_num,cm.fav_num,pic.thumbnail_path,
        (select category_parentid from {$tablepre}category where category_id=cm.category_id) as category_parentid
        from {$tablepre}message m 
        inner join {$tablepre}categorymng cm on cm.msg_id=m.msg_id
	    inner join {$tablepre}attachmng pic ON pic.msg_id = m.msg_id
	    where pic.index_box=1 and cm.category_id in(".$idstr.") and m.msg_status=1 and m.msg_starttime<='".$getnow."' and m.msg_endtime>='".$getnow."' 
		GROUP BY cm.msg_id order by m.msg_order DESC,m.msg_id DESC,pic.attach_id asc"; 

$rs     = $db->query($str,true);
$myrow  = $rs->fetchAll();
$numrows = count($myrow); 

//$p->setvar(array("cateid" => $cateid, "kw" => $kw)); 
if ($html_flag==1){

	$p       = new html_page;
	$p->setvar($plink); 
	$p->set($site_num,$numrows,$psize,$fn); 
	$rsx=$db->query($str." limit ".$p->limit(),true);

}else{

	$p       = new desk_page;
	$p->setvar($plink); 
	$p->set($site_num,$numrows,$psize); 
	$rsx=$db->query($str." limit ".$p->limit(),true);

}

if ($numrows!=0){
	 $i=0;
	 $ListArray = array();
	 while ($myrow = $rsx->fetch()) {
		 $ListArray[$i]['msg_id']=$myrow['msg_id'];
		 $ListArray[$i]['msg_title']=$myrow['msg_title'];
		 $ListArray[$i]['category_parentid']=$myrow['category_parentid'];
		 $ListArray[$i]['category_id']=$myrow['category_id'];
		 $ListArray[$i]['msg_demourl']=$myrow['msg_demourl'];		 
		 $ListArray[$i]['msg_downurl']=$myrow['msg_downurl'];
		 $ListArray[$i]['msg_integral']=$myrow['msg_integral'];
		 $ListArray[$i]['msg_poster']=$myrow['msg_poster'];
		 $ListArray[$i]['msg_url']=$myrow['msg_url'];
		 $ListArray[$i]['thumbnail_path']=$myrow['thumbnail_path'];
		 $ListArray[$i]['hits_num']=$myrow['hits_num'];
		 $ListArray[$i]['msg_starttime']=$myrow['msg_starttime'];
		 $ListArray[$i]['msg_endtime']=$myrow['msg_endtime'];
		 $ListArray[$i]['fav_num']=$myrow['fav_num'];
		 $ListArray[$i]['msg_isad']=$myrow['msg_isad'];
		 $ListArray[$i]['msg_tuijian']=$myrow['msg_tuijian'];
		 $ListArray[$i]['msg_createtime']=dateFormat($myrow['msg_createtime'],'Y-m-d');
		 $i++;
	 }
}

$pager=$p->output(1);
include($template->getfile('list'));
?>