<?php
require_once ('header.php');

foreach ($catearr as $k=>$vl){
	$sql="select * from {$tablepre}category where category_status=1 and category_parentid=".$vl['category_id']." order by category_order asc";
    $cate2arr=$db->get_all($sql);
    $catearr[$k]['category_two']=$cate2arr; //二级分类
    
	$msql="select m.*,cm.category_id,cm.hits_num,cm.down_num,cm.fav_num,pic.thumbnail_path 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(select category_id from {$tablepre}category 
	       where category_parentid=".$vl['category_id'].") and m.msg_status=1 and m.msg_starttime<='".$getnow."' and m.msg_endtime>='".$getnow."'  
		   GROUP BY cm.msg_id,cm.category_id order by m.msg_id desc,pic.attach_id asc limit ".$index_cate_num.""; 
    $msgarr = $db->get_all($msql);
	
	if (!empty($msgarr)){
		$catearr[$k]['message']=$msgarr;
	}else{
		//为空时的默认数据
		$nullarr[0]=array(msg_id=>1,
                          msg_title => '飞天下载系统FTDMS X2.0版',
                          msg_titlecolor => '#FF0000',
                          msg_content => '<div align="center"><img src="/upload/201910/demo2.png" alt=""></div>',
                          msg_keyword => '下载系统,ftdms,飞天',
                          msg_demourl => 'http://www.ftdms.cn/default.php',
                          msg_order => 18,
                          msg_downurl => 'http://www.ftdms.cn/default.php',
                          msg_integral => 0,
                          msg_poster => 1,
                          msg_createtime => '2019-10-01 14:38:21',
                          msg_starttime => '2019-10-01 00:00:00',
                          msg_endtime => '2029-10-01 00:00:00',
                          msg_status => 1,
                          msg_tuijian => 1,
                          msg_isad => 1,
                          category_id => 8,
                          hits_num => 27,
                          down_num => 10004,
                          fav_num => 169,
                          thumbnail_path => '/upload/201910/imgsmall/demo2.png'
		);
		$nullarr[1]=array(msg_id=>1,
                          msg_title => '飞天素材网后台管理框架模板iframe版',
                          //msg_titlecolor => '#FF0000',
                          msg_content => '<div align="center"><img src="/upload/201910/demo.png" alt=""></div>',
                          msg_keyword => '下载系统,ftdms,飞天',
                          msg_demourl => 'http://www.ftsucai.com/view-12-341.html',
                          msg_order => 18,
                          msg_downurl => 'http://www.ftsucai.com/view-12-341.html',
                          msg_integral => 0,
                          msg_poster => 1,
                          msg_createtime => '2019-10-01 14:38:21',
                          msg_starttime => '2019-10-01 00:00:00',
                          msg_endtime => '2029-10-01 00:00:00',
                          msg_status => 1,
                          msg_tuijian => 1,
                          msg_isad => 0,
                          category_id => 8,
                          hits_num => 27,
                          down_num => 10004,
                          fav_num => 169,
                          thumbnail_path => '/upload/201910/imgsmall/demo.png'
		);
		$nullarr[2]=array(msg_id=>1,
                          msg_title => '飞天素材网后台管理框架模板单页版',
                          //msg_titlecolor => '#FF0000',
                          msg_content => '<div align="center"><img src="/upload/201910/demo4.png" alt=""></div>',
                          msg_keyword => '下载系统,ftdms,飞天',
                          msg_demourl => 'http://www.ftsucai.com/view-12-389.html',
                          msg_order => 18,
                          msg_downurl => 'http://www.ftsucai.com/view-12-389.html',
                          msg_integral => 0,
                          msg_poster => 1,
                          msg_createtime => '2019-10-01 14:38:21',
                          msg_starttime => '2019-10-01 00:00:00',
                          msg_endtime => '2029-10-01 00:00:00',
                          msg_status => 1,
                          msg_tuijian => 0,
                          msg_isad => 0,
                          category_id => 8,
                          hits_num => 27,
                          down_num => 10004,
                          fav_num => 169,
                          thumbnail_path => '/upload/201910/imgsmall/demo4.png'
		);
		$nullarr[3]=array(msg_id=>1,
                          msg_title => '飞天下载系统手机版',
                          //msg_titlecolor => '#FF0000',
                          msg_content => '<div align="center"><img src="/upload/201910/loadpage.jpg" alt=""></div>',
                          msg_keyword => '下载系统,ftdms,飞天',
                          msg_demourl => 'http://www.ftdms.cn/default.php',
                          msg_order => 18,
                          msg_downurl => 'http://www.ftdms.cn/default.php',
                          msg_integral => 0,
                          msg_poster => 1,
                          msg_createtime => '2019-10-01 14:38:21',
                          msg_starttime => '2019-10-01 00:00:00',
                          msg_endtime => '2029-10-01 00:00:00',
                          msg_status => 1,
                          msg_tuijian => 0,
                          msg_isad => 0,
                          category_id => 8,
                          hits_num => 27,
                          down_num => 10004,
                          fav_num => 169,
                          thumbnail_path => '/upload/201910/imgsmall/loadpage.jpg'
		);
	    $catearr[$k]['message']=$nullarr;
	}

}

include($template->getfile('index'));
?>