<?php
if(!defined('IN_MYMPS')) exit('FORBIDDEN');
runcron();
$cache = get_cache_config();
$smarty -> cache_lifetime    = $cache['site']['time'];
$smarty -> caching           = $cache['site']['open'];
unset($cache);

$tpl_index = get_tpl_index();
$tpl_index = $tpl_index['tpl_set'];

if (!$smarty->is_cached(mymps_tpl($tpl_index['banmian'] ? $tpl_index['banmian'] : 'simple','smarty'))){

	$seo = get_seoset();
	/*当前位置*/
	$loc					= get_location('index');
	$location				= $loc['location'];
	$page_title				= $loc['page_title'];
	unset($loc);
		
	/*首页广告*/
	$advertisement			= get_advertisement('index');//获得首页广告
	$adveritems				= $advertisement['items'];
	$advertisement['type']	= $advertisement['all'] ? (is_array($advertisement['type']) ? array_merge($advertisement['all']['type'],$advertisement['type']) : $advertisement['all']['type']) : $advertisement['type'];
	
	switch($tpl_index['banmian']){
		case 'classic':
				
			@include MYMPS_DATA.'/caches/plugin.php';
			$pluginsettings = $data;
			/*团购*/
			if($pluginsettings['group'] && $pluginsettings['group']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/group/include/functions.php';
				$groups = get_groups(3);
				$smarty -> assign('groupclass',get_group_class());
				$groups && $smarty -> assign('groups',$groups);
			}
			/*新闻*/
			if($pluginsettings['news'] && $pluginsettings['news']['disable'] != 1){
				$smarty->assign('news',mymps_get_news_list($tpl_index['news']));//取得网站最新新闻
			}
			/*商品*/
			if($pluginsettings['goods'] && $pluginsettings['goods']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/goods/include/functions.php';
				$smarty -> assign('goods',get_goods($tpl_index['goods'],1,''));
			}
			$data = $pluginsettings = NULL;
			
			/**************************/
			/*获得首页栏目版块分类循环*/
			/**************************/
			$index_cat			= get_categories_tree(0,'category');
			if(is_array($index_cat)){
				foreach($index_cat as $firstcatkey => $firstcatval){
					$incatids = NULL;
					$incatids = get_children($firstcatval['catid']);
					
					$query	= $db -> query("SELECT a.id,a.catid,a.userid,a.catid,a.title,a.ifred,a.html_path,a.ifbold,a.begintime,b.catname,b.dir_typename,b.html_dir FROM {$db_mymps}information AS a LEFT JOIN `{$db_mymps}category` AS b ON a.catid = b.catid WHERE $incatids AND a.info_level > '0' ORDER BY a.begintime DESC LIMIT 0,".$tpl_index['foreachinfo']);
					while($irow   = $db -> fetchRow($query)){
						$arr['id'] 	      = $irow['id'];
						$arr['title'] 	  = $irow['title'];
						$arr['begintime'] = $irow['begintime'];
						$arr['catname']	  = $irow['catname'];
						$arr['ifred']	  = $irow['ifred'];
						$arr['ifbold']	  = $irow['ifbold'];
						$arr['caturi']	  = Rewrite('category',array('dir_typename'=>$irow['dir_typename'],'catid'=>$irow['catid'],'html_dir'=>$irow['html_dir']));
						$arr['uri']		  = Rewrite('info',array('id'=>$irow['id'],'dir_typename'=>$irow['dir_typename'],'html_path'=>$irow['html_path']));
						$index_cat[$firstcatval['catid']]['information'][] = $arr;
					}
					
				}
				$query = NULL;
			}
			
			$mymps_global = array_merge($mymps_global,$seo);
			$cat = NULL;
			
			tpl_assign();
			$smarty->assign('announce',mymps_get_announce($tpl_index['announce']));
			$smarty->assign('faq',mymps_get_faq($tpl_index['faq']));
			$smarty->assign('count',$count);
			$smarty->assign('categories',$index_cat);

			$smarty->assign('cat',NULL);
		
		break;
		
		case 'simple':
		
			@include MYMPS_DATA.'/caches/plugin.php';
			$pluginsettings = $data;
			/*商品*/
			if($pluginsettings['goods'] && $pluginsettings['goods']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/goods/include/functions.php';
				$smarty -> assign('goods',get_goods($tpl_index['goods'],1,''));
			}
			/*团购*/
			if($pluginsettings['group'] && $pluginsettings['group']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/group/include/functions.php';
				$groups = get_groups(3);
				$smarty -> assign('groupclass',get_group_class());
				$groups && $smarty -> assign('groups',$groups);
			}

			$mymps_global = array_merge($mymps_global,$seo);
			$cat = NULL;
			
			$faquri['tel'] = Rewrite('about',array('part'=>'faq','id'=>'32','html_path'=>'/faq/32'.$seo['seo_htmlext']));//电话被冒用
			$faquri['del'] = Rewrite('about',array('part'=>'faq','id'=>'33','html_path'=>'/faq/33'.$seo['seo_htmlext']));//我要删除信息
			$faquri['upgrade'] = Rewrite('about',array('part'=>'faq','id'=>'24','html_path'=>'/faq/24'.$seo['seo_htmlext']));//我要推广信息
			$faquri['infonosee'] =  Rewrite('about',array('part'=>'faq','id'=>'34','html_path'=>'/faq/34'.$seo['seo_htmlext']));//信息不能显示
			$faquri['infofirst'] = Rewrite('about',array('part'=>'faq','id'=>'27','html_path'=>'/faq/27'.$seo['seo_htmlext']));//信息如何提前
			$faquri['certify'] = Rewrite('about',array('part'=>'faq','id'=>'22','html_path'=>'/faq/22'.$seo['seo_htmlext']));//我要认证
			
			tpl_assign();
			$smarty->assign('firstcats',get_smplist_cats($tpl_index['smp_cats']['first'],$tpl_index['showstyle']));//获得首页第一列分类循环
			$smarty->assign('secondcats',get_smplist_cats($tpl_index['smp_cats']['second'],$tpl_index['showstyle']));//获得首页第二列分类循环
			$smarty->assign('thirdcats',get_smplist_cats($tpl_index['smp_cats']['third'],$tpl_index['showstyle']));//获得首页第三列分类循环
			$smarty->assign('fourthcats',get_smplist_cats($tpl_index['smp_cats']['fourth'],$tpl_index['showstyle']));//获得首页第二列分类循环
			$smarty->assign('faquri',$faquri);
			//$smarty->assign('count',get_information_count());//发布信息数量统计
			$smarty->assign('cat',NULL);
		break;
		
		case 'portal':
		
			@include MYMPS_DATA.'/caches/plugin.php';
			$pluginsettings = $data;
			/*团购*/
			if($pluginsettings['group'] && $pluginsettings['group']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/group/include/functions.php';
				$groups = get_groups(3);
				$smarty -> assign('groupclass',get_group_class());
				$groups && $smarty -> assign('groups',$groups);
			}
			/*商品*/
			if($pluginsettings['goods'] && $pluginsettings['goods']['disable'] != 1){
				require_once MYMPS_ROOT.'/plugin/goods/include/functions.php';
				$smarty -> assign('goods',get_goods($tpl_index['goods'],1,''));
			}
			/*新闻*/
			if($pluginsettings['news'] && $pluginsettings['news']['disable'] != 1){
				$smarty->assign('news',mymps_get_news_list($tpl_index['news']));//取得网站最新新闻
			}
			$data = $pluginsettings = NULL;
			
			/*招聘信息开始*/
			$ids = '';
			$query = $db -> query("SELECT a.id,a.title,a.catid,a.ifred,a.ifbold,a.html_path,a.begintime FROM `{$db_mymps}information` AS a WHERE a.catid IN(".$tpl_index[portal][zhaopin].") AND a.info_level > '0' ORDER BY a.begintime DESC LIMIT 0,16");
			if($query){
				while($row = $db -> fetchRow($query)){
					$arr['id']        = $row['id'];
					$arr['title']     = $row['title'];
					$arr['ifred']     = $row['ifred'];
					$arr['ifbold']    = $row['ifbold'];
					$arr['begintime'] = $row['begintime'];
					$arr['uri']       = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
					$zhaopin[$row['id']]      = $arr;
					$ids .= $row['id'].',';
				}
			}
			$infoid = substr($ids,0,-1);
			if($infoid){
				$sql = "select infoid,name,value FROM {$db_mymps}info_extra WHERE infoid IN ($infoid) AND name = '".$tpl_index['portali']['company']."'";
				$res = $db->query($sql);
				while($row=$db->fetchrow($res)){
					$arr[$row['infoid']][$tpl_index['portali']['company']] = $row['value'];
				}
				foreach($zhaopin as $key => $info){
					$zhaopin[$key] = is_array($arr[$key]) ? array_merge($info,$arr[$key]) : $info;
				}
			}
			$arr = $row = $res = $query = $sql = '';
			/*招聘信息结束*/
			
			/*人才简历开始*/
			$arr = '';
			$query = $db -> query("SELECT a.id,a.title,a.catid,a.ifred,a.ifbold,a.html_path,a.contact_who FROM `{$db_mymps}information` AS a WHERE a.catid IN(".$tpl_index[portal][jianli].") AND a.info_level > '0' ORDER BY a.begintime DESC LIMIT 0,4");
			if($query){
				while($row = $db -> fetchRow($query)){
					$arr['id']        = $row['id'];
					$arr['title']     = $row['title'];
					$arr['ifred']     = $row['ifred'];
					$arr['ifbold']    = $row['ifbold'];
					$arr['contact_who']    = $row['contact_who'];
					$arr['uri']       = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
					$jianli[$row['id']]      = $arr;
				}
			}
			$arr = $row = $res = $query = $sql = '';
			/*人才简历结束*/
			
			/*二手房信息开始*/
			$ids = $arr = '';
			$query = $db -> query("SELECT a.id,a.catid,a.title,a.ifred,a.ifbold,a.html_path FROM `{$db_mymps}information` AS a WHERE a.catid IN(".$tpl_index[portal][ershoufang].") AND a.info_level > '0' ORDER BY a.begintime DESC LIMIT 0,12");
			if($query){
				while($row = $db -> fetchRow($query)){
					$arr['id']        = $row['id'];
					$arr['title']     = $row['title'];
					$arr['ifred']     = $row['ifred'];
					$arr['ifbold']    = $row['ifbold'];
					$arr['uri']       = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
					$esf[$row['id']]      = $arr;
					$ids .= $row['id'].',';
				}
			}		
			$infoid = substr($ids,0,-1);
			if($infoid){
				$sql = "SELECT infoid,name,value FROM {$db_mymps}info_extra WHERE infoid IN ($infoid) AND name = '".$tpl_index[portali][acreage]."' OR name = '".$tpl_index[portali][prices]."'";
				$res = $db->query($sql);
				while($row=$db->fetchrow($res)){
					$arr[$row['infoid']][$row['name']] = $row['value'];
				}
				foreach($esf as $key => $info){
					$esf[$key] = is_array($arr[$key]) ? array_merge($info,$arr[$key]) : $info;
				}
			}
			/*二手房信息结束*/
			
			/*出租房信息开始*/
			$ids = $arr = '';
			$query = $db -> query("SELECT a.id,a.catid,a.title,a.ifred,a.ifbold,a.html_path,a.img_path FROM `{$db_mymps}information` AS a WHERE a.catid IN (".$tpl_index[portal][zufang].") AND a.info_level > '0' AND a.img_path != '' ORDER BY a.begintime DESC LIMIT 0,6");
			if($query){
				while($row = $db -> fetchRow($query)){
					$arr['id']        = $row['id'];
					$arr['title']     = $row['title'];
					$arr['ifred']     = $row['ifred'];
					$arr['ifbold']    = $row['ifbold'];
					$arr['img_path']   = $row['img_path']?$row['img_path']:'/images/nophoto.gif';
					$arr['uri']       = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
					$czf[$row['id']]      = $arr;
					$ids .= $row['id'].',';
				}
			}
			$infoid = substr($ids,0,-1);
			if($infoid){
				$sql = "SELECT infoid,name,value FROM {$db_mymps}info_extra WHERE infoid IN ($infoid) AND name = '".$tpl_index[portali][mini_rent]."'";
				$res = $db->query($sql);
				while($row=$db->fetchrow($res)){
					$arr[$row['infoid']][$row['name']] = $row['value'];
				}
				foreach($czf as $key => $info){
					$czf[$key] = is_array($arr[$key]) ? array_merge($info,$arr[$key]) : $info;
				}
			}
			/*出租房信息结束*/

			/*二手市场开始*/
			//文字信息
			$arr = '';
			$query	 = $db -> query("SELECT a.id,a.title,a.catid,a.ifred,a.ifbold,a.begintime,a.html_path,b.catname FROM {$db_mymps}information AS a LEFT JOIN `{$db_mymps}category` AS b ON a.catid=b.catid WHERE a.catid IN(".$tpl_index[portal][ershou].") AND a.info_level > '0' ORDER BY a.begintime DESC LIMIT 0,12");
			while($row   = $db -> fetchRow($query)){
				$arr['id'] 	      = $row['id'];
				$arr['title'] 	  = $row['title'];
				$arr['begintime'] = $row['begintime'];
				$arr['catname']	  = $row['catname'];
				$arr['ifred']	  = $row['ifred'];
				$arr['ifbold']	  = $row['ifbold'];
				$arr['uri']		  = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
				$ershou[$row['id']] = $arr;
			}
			//图文信息
			$arr = '';
			$query = $db -> query("SELECT a.id,a.title,a.catid,a.html_path,a.img_path FROM `{$db_mymps}information` AS a WHERE a.catid IN(".$tpl_index[portal][ershou].") AND a.info_level > '0' AND img_path != '' ORDER BY a.begintime DESC LIMIT 0,8");
			if($query){
				while($row = $db -> fetchRow($query)){
					$arr['id']        = $row['id'];
					$arr['title']     = $row['title'];
					$arr['img_path']  = $row['img_path'];
					$arr['uri']       = Rewrite('info',array('id'=>$row['id'],'catid'=>$row['catid'],'html_path'=>$row['html_path']));
					$ershou_img[$row['id']]      = $arr;
				}
			}
			/*二手市场结束*/
			
			/*各模块发布和更多链接开始*/
			$tpl_index['portal']['ershou'] = explode(',',$tpl_index['portal']['ershou']);
			$tpl_index['portal']['ershou'] = $tpl_index['portal']['ershou'][count($tpl_index['portal']['ershou'])-1];
			$tpl_index['portal']['zhaopin'] = explode(',',$tpl_index['portal']['zhaopin']);
			$tpl_index['portal']['zhaopin'] = $tpl_index['portal']['zhaopin'][count($tpl_index['portal']['zhaopin'])-1];
			$tpl_index['portal']['jianli'] = explode(',',$tpl_index['portal']['jianli']);
			$tpl_index['portal']['jianli'] = $tpl_index['portal']['jianli'][count($tpl_index['portal']['jianli'])-1];
			$in = $tpl_index['portal']['ershou'].','.$tpl_index['portal']['zhaopin'].','.$tpl_index['portal']['ershoufang'].','.$tpl_index['portal']['jianli'].','.$tpl_index['portal']['zufang'];
			if($query = $db->query("SELECT catid,dir_typename,html_dir FROM `{$db_mymps}category` WHERE catid IN($in)")){
				while($row = $db->fetchRow($query)){
					$hd[$row['catid']]['dir_typename'] = $row['dir_typename'];
					$hd[$row['catid']]['html_dir'] = $row['html_dir'];
				}
			}
			$portaluri['postershou'] = $mymps_global['cfg_postfile'].'?catid='.$tpl_index['portal']['ershou'];
			$portaluri['moreershou'] = Rewrite('category',array('catid'=>$tpl_index['portal']['ershou'],'dir_typename'=>$hd[$tpl_index['portal']['ershou']]['dir_typename'],'html_dir'=>$hd[$tpl_index['portal']['ershou']]['html_dir']));
			$portaluri['catidershou'] = $tpl_index['portal']['ershou'];
			$portaluri['postzufang'] = $mymps_global['cfg_postfile'].'?catid='.$tpl_index['portal']['zufang'];
			$portaluri['morezufang'] = Rewrite('category',array('catid'=>$tpl_index['portal']['zufang'],'dir_typename'=>$hd[$tpl_index['portal']['zufang']]['dir_typename'],'html_dir'=>$hd[$tpl_index['portal']['zufang']]['html_dir']));
			$portaluri['catidzufang'] = $tpl_index['portal']['zufang'];
			$portaluri['postzhaopin'] = $mymps_global['cfg_postfile'].'?catid='.$tpl_index['portal']['zhaopin'];
			$portaluri['morezhaopin'] = Rewrite('category',array('catid'=>$tpl_index['portal']['zhaopin'],'dir_typename'=>$hd[$tpl_index['portal']['zhaopin']]['dir_typename'],'html_dir'=>$hd[$tpl_index['portal']['zhaopin']]['html_dir']));
			$portaluri['catidzhaopin'] = $tpl_index['portal']['zhaopin'];
			$portaluri['postershoufang'] = $mymps_global['cfg_postfile'].'?catid='.$tpl_index['portal']['ershoufang'];
			$portaluri['moreershoufang'] = Rewrite('category',array('catid'=>$tpl_index['portal']['ershoufang'],'dir_typename'=>$hd[$tpl_index['portal']['ershoufang']]['dir_typename'],'html_dir'=>$hd[$tpl_index['portal']['ershoufang']]['html_dir']));
			$portaluri['catidershoufang'] = $tpl_index['portal']['ershoufang'];
			$portaluri['postjianli'] = $mymps_global['cfg_postfile'].'?catid='.$tpl_index['portal']['jianli'];
			$portaluri['morejianli'] = Rewrite('category',array('catid'=>$tpl_index['portal']['jianli'],'dir_typename'=>$hd[$tpl_index['portal']['jianli']]['dir_typename'],'html_dir'=>$hd[$tpl_index['portal']['jianli']]['html_dir']));
			$portaluri['catidjianli'] = $tpl_index['portal']['jianli'];
			
			/*各模块发布和更多链接结束*/
			
			$mymps_global 	= array_merge($mymps_global,$seo);
			$categories 	= get_categories_tree(0,'category');
			$cat = $in = $hd = NULL;
			
			tpl_assign();
			$smarty->assign('ershou',$ershou);
			$smarty->assign('ershou_img',$ershou_img);
			$smarty->assign('esf',$esf);
			$smarty->assign('zhaopin',$zhaopin);
			$smarty->assign('jianli',$jianli);
			$smarty->assign('czf',$czf);
			//$smarty->assign('faq',mymps_get_faq($tpl_index['faq']));//网站帮助
			$smarty->assign('announce',mymps_get_announce($tpl_index['announce']));//网站公告
			$smarty->assign('ioption',$tpl_index['portali']);
			$smarty->assign('categories',$categories);
			$smarty->assign('portaluri',$portaluri);
			$smarty->assign('cat',NULL);
		break;
	}

$smarty->assign('lifebox',get_lifebox($tpl_index['lifebox']));//获得百宝箱
$smarty->assign('telephone',get_telephone($tpl_index['telephone']));//获得便民电话
$smarty->assign('index_topinfo',mymps_get_info_list($tpl_index['indextopinfo'],0,3));//取得首页置顶信息
$smarty->assign('shopclass',get_corp_tree(0,'corp'));//商家分类
$smarty->assign('members',$mymps_global['cfg_if_corp'] == 1 ? mymps_get_member_list('',0,'',1,'',2) : '');//首页火热店铺推荐显示的商家列表
$smarty->assign('focus',mymps_get_focus('index'));//首页焦点图
$smarty->assign('links',mymps_get_links());//取得首页友情链接

	
$category = $announce = $links = $advetisement = $adveritems = $page_title = $members = $news = $index_topinfo = $page_title = $irow = $count = $lifebox = $telephone =  $cat_list = $area_list = $index_cat = $cat = $portaluri = NULL;

}
?>