<?php
define('IN_SMT',true);
define('CURSCRIPT','corp');
define('IN_MYMPS', true);

require_once dirname(__FILE__)."/include/global.php";
require_once dirname(__FILE__)."/data/config.php";

ifsiteopen();
require_once MYMPS_DATA."/config.db.php";
require_once MYMPS_INC."/db.class.php";
require_once MYMPS_SMARTY."/include.php";

$catid  	= isset($catid)  	? intval($catid)  : '';
$areaid 	= isset($areaid) 	? intval($areaid) : '';

$seo	 	= get_seoset();
$rewrite	= $seo['seo_force_yp'];

if($Catid && $rewrite == 'rewrite'){
	$detail=explode("-",$Catid);
	if($detail[0]){
		for($i=0;$i<count($detail) ;$i++ ){
			$_GET[$detail[$i]]=$$detail[$i]=str_replace(array('#@#','#!#'),array('-','/'),$detail[++$i]);	
		}
		extract($_GET);
	}
	$Catid = $detail = NULL;
}


if($catid && !$cur = $db -> getRow("SELECT parentid,corpname FROM `{$db_mymps}corp` WHERE corpid = '$catid'")) write_msg('当前商家分类不存在或者未被启用！');

$cate_limit 	= !empty($catid) 	? " AND b.catid IN(".get_corp_children($catid).") "  : "";
$area_limit 	= !empty($areaid) 	? " AND a.areaid = '$areaid' "	: "";
$level_limit	= " AND levelid > '1' AND if_corp = '1'";

$sql = empty($cate_limit) ? "SELECT a.* FROM `{$db_mymps}member` AS a WHERE 1 {$level_limit} {$cate_limit}{$area_limit} ORDER BY a.levelid DESC,a.jointime DESC" : "SELECT a.* FROM `{$db_mymps}member` AS a LEFT JOIN `{$db_mymps}member_category` AS b ON a.userid = b.userid WHERE 1 {$level_limit} {$cate_limit}{$area_limit} ORDER BY a.levelid DESC,a.jointime DESC";
$count_sql	= empty($cate_limit) ? "SELECT COUNT(a.id) FROM `{$db_mymps}member` AS a WHERE 1 {$level_limit}{$area_limit}" : "SELECT COUNT(b.id) FROM `{$db_mymps}member` AS a LEFT JOIN {$db_mymps}member_category AS b ON a.userid = b.userid WHERE 1  {$level_limit}{$cate_limit}{$area_limit}";

$rows_num 	= $db -> getOne($count_sql);
$param		= setParam(array('catid','areaid'),$rewrite,'corporation-');
if(is_array($res = page1($sql,$mymps_global['cfg_list_page_line']?$mymps_global['cfg_list_page_line']:10))){
	foreach($res as $key => $val){
		$arr['userid']		= $val['userid'];
		$arr['per_certify']	= $val['per_certify'];
		$arr['com_certify']	= $val['com_certify'];
		$arr['jointime']	= $val['jointime'];
		$arr['credits']		= $val['credits'];
		$arr['credit']		= $val['credit'];
		$arr['prelogo']		= $val['prelogo'];
		$arr['tname']		= HighLight($val['tname'] ? $val['tname'] : $val['userid'],$keywords);
		$arr['uri'] 		= Rewrite('store',array('uid'=>$val['id']));
		$arr['uri_comment'] = Rewrite('store',array('uid'=>$val['id'],'part'=>'comment'));
		$arr['uri_contactus'] = Rewrite('store',array('uid'=>$val['id'],'part'=>'contactus'));
		$arr['uri_album'] 	= Rewrite('store',array('uid'=>$val['id'],'part'=>'album'));
		$arr['address']		= $val['address'] ? $val['address'] : ($val['busway'] ? $val['busway'] : '暂无地址'); 
		$arr['levelid']		= $val['levelid'];
		$arr['tel']			= $val['tel'] ? $val['tel'] : '暂无电话';
		$member[]			= $arr;
	}
}

$ypcategory = get_corp_tree(0,'corp');
$area_list = cat_list('area',0,0,false,1);
$area_list	= array_merge(array('0'=>array('areaid'=>'','areaname'=>'不限地区')),$area_list);
if(is_array($area_list)){
	foreach($area_list as $areakey => $areaval){
		$area_list[$areakey]['uri'] = Rewrite('corp',array('catid'=>$catid,'areaid'=>$areaval['areaid']));
		$area_list[$areakey]['select'] = $areaval['areaid'] == $areaid ? '1' : 0;
	}
}

$loc 			= get_location('corp',$catid);
$page_title 	= $loc['page_title'];
$location		= $loc['location'];
$advertisement	= get_advertisement('other');
$adveritems		= $advertisement['items'];
$advertisement	= $advertisement['all'];
$hotmember		= mymps_get_member_list('','','',1,'','',2);

tpl_assign();
$smarty->assign('pageview',page2($rewrite));
$smarty->assign('member',$member);
$smarty->assign('area_list',$area_list);
$smarty->assign('ypcategory',$ypcategory);
$hotmember && $smarty->assign('hotmember',$hotmember);
//$smarty->assign('certifymember',mymps_get_member_list(10,1,'',1,1));
$smarty->assign('cur',$cur);
$smarty->assign('totalnum',$rows_num);
$smarty -> display(mymps_tpl(CURSCRIPT));

is_object($db) && $db->Close();
$ypcategory = $advertisement = $adveritems = $member = $area_list = $ypcategory = $loc = $page_title = $location = $seo = $rewrite = $_arr = $mymps_global = $rows_num = $db = $catid = $areaid = $rewrite = $sql = $timestamp =NULL;
?>