<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'manage':trim($action);

	$c=new cache();
	require_once(DIRCMS_ROOT.'include/list.class.php');
	$l=new dircmslist();
	switch($action)
	{
		case 'type':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				if(!$id)showmsg('请选择需要操作的企业类型!');
				foreach($id as $val)
				{
					switch($do)
					{
						case 'delete':
							$db->mysql_delete(DB_PRE.'member_type',intval($val));
							cache_delete('member_type'.$val.'.cache.php',DIRCMS_ROOT.'data/cache/');
							break;
						default:
							$db->update(DB_PRE.'member_type',array('type'=>$type[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
							break;
					}
				}
				$c->cache_member_type();
				showmsg($LANG['MANAGE_SUCEESS']);
			}
			function tree ($parentid=0)
			{
				global $db;
				static $flag=0;
				$r=$db->fetch_all("SELECT * FROM ".DB_PRE."member_type WHERE parentid=".intval($parentid));
				if($r)foreach($r as $_r)
				{
					echo '<tr>
			<td width="40" align="center"><input type="checkbox" name="id[]" value="'.$_r['id'].'" class="checkbox" /></td>
			<td width="80" align="center"><input type="text" size="6" name="orderby['.$_r['id'].']" value="'.$_r['orderby'].'" /></td>
			<td width="60" align="center">'.$_r['id'].'</td>
			<td width="240" align="center">'.str_repeat('&nbsp;',$_r['grade']*5).'└<input type="text" size="25" name="type['.$_r['id'].']" value="'.$_r['type'].'" /></td>
			<td width="100" align="center">'.$_r['grade'].'级企业类型</td>
			<td width="40" align="center"><a href="'.ADMIN_FILE.'?file=yellowpages&action=delete_type&id='.$_r['id'].'"><u>删除</u></a></td></tr>';
					tree($_r['id']);
				}
			}
			$r=cache_read('all_member_type.cache.php',DIRCMS_ROOT.'data/cache/');
			foreach($r as $_r)
			{
				if($_r['parentid']==0)$member_type[]=$_r;
			}
			include admin_tlp('yellowpages_type');			
			break;
		case 'add_type':
			if(isset($do_submit)) 
			{
				if(!$newmember_type['type'])showmsg('类型名称不能为空!');
				$type=explode("\r\n",$newmember_type['type']);
				$r=$db->fetch_one("SELECT grade FROM ".DB_PRE."member_type WHERE ".DB_PRE."member_type.id=".intval($newmember_type['parentid']));
				$newmember_type['grade']=$r['grade']+1;
				foreach($type as $val)
				{
					$newmember_type['type']=$val;
					$db->insert(DB_PRE."member_type",$newmember_type);
				}
				$c->cache_member_type();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=type');
			}
			require_once(DIRCMS_ROOT.'include/select.class.php');
			$s=new select();
			$select=$s->getSelect('newmember_type[parentid]','无（顶级企业类型）',DB_PRE.'member_type',true,'type');
			include admin_tlp('yellowpages_type_add');		
			break;
		case 'delete_type':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->mysql_delete(DB_PRE.'member_type',intval($id));
			$db->mysql_delete(DB_PRE.'member_type',intval($id),'parentid');
			$c->cache_member_type();
			cache_delete('member_type'.intval($id).'.cache.php',DIRCMS_ROOT.'data/cache/');
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=type');
			break;
		case 'manage':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if($do_submit)
			{
				switch($do)
				{
					case 'yellowpages_passed':
						if(!$id)showmsg('请选择需要审核的商家!');
						$sql=is_array($id)?"UPDATE ".DB_PRE."member SET iscompmayed=1 WHERE id in(".implode(',',$id).")":"UPDATE ".DB_PRE."member SET iscompmayed=1 WHERE id=".intval($id);
						$db->query($sql,true);
						$sql=is_array($id)?"UPDATE ".DB_PRE."member_cache SET iscompmayed=1 WHERE id in(".implode(',',$id).")":"UPDATE ".DB_PRE."member_cache SET iscompmayed=1 WHERE id=".intval($id);
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=manage');
						break;
					case 'yellowpages_unpassed':
						if(!$id)showmsg('请选择需要待审的商家!');
						$sql=is_array($id)?"UPDATE ".DB_PRE."member SET iscompmayed=0 WHERE id in(".implode(',',$id).")":"UPDATE ".DB_PRE."member SET iscompmayed=0 WHERE id=".intval($id);
						$db->query($sql,true);
						$sql=is_array($id)?"UPDATE ".DB_PRE."member_cache SET iscompmayed=0 WHERE id in(".implode(',',$id).")":"UPDATE ".DB_PRE."member_cache SET iscompmayed=0 WHERE id=".intval($id);
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=manage');
						break;
					case 'yellowpages_close':
						if(!$id)showmsg('请选择需要关闭的商家!');
						foreach($id as $val)
						{
							$db->update(DB_PRE.'member',array('modelid'=>1,'iscompmayed'=>0),'id='.intval($val));
							$db->update(DB_PRE.'member_cache',array('modelid'=>1,'iscompmayed'=>0),'id='.intval($val));
							$db->mysql_delete(DB_PRE.'corporatemember',intval($val),'userid');
							$db->insert(DB_PRE.'nomalmember',array('userid'=>intval($val)));
						}
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=manage');
						break;
				}
			}
			$k=trim($k);
			if(isset($status))
			{
				if($k)
				{
					$sql="SELECT a.*,b.* FROM ".DB_PRE."member_cache a LEFT JOIN ".DB_PRE."corporatemember b ON a.id=b.userid WHERE a.ispassed=1 AND (a.username='{$k}' OR b.companyname LIKE '%{$k}%') AND a.modelid=2 AND a.iscompmayed=".intval($status);
				}
				else
				{
					$sql="SELECT a.*,b.* FROM ".DB_PRE."member_cache a LEFT JOIN ".DB_PRE."corporatemember b ON a.id=b.userid WHERE a.ispassed=1 AND a.modelid=2 AND a.iscompmayed=".intval($status);
				}
			}
			else
			{
				if($k)
				{
					$sql="SELECT a.*,b.* FROM ".DB_PRE."member_cache a LEFT JOIN ".DB_PRE."corporatemember b ON a.id=b.userid WHERE a.ispassed=1 AND (a.username='{$k}' OR b.companyname LIKE '%{$k}%') AND a.modelid=2";
				}
				else
				{
					$sql="SELECT a.*,b.* FROM ".DB_PRE."member_cache a LEFT JOIN ".DB_PRE."corporatemember b ON a.id=b.userid WHERE a.ispassed=1 AND a.modelid=2";
				}
			}
			
			$data=$db->fetch_all($sql);
			$cururl=getcururl();
			$page=isset($page)?intval($page):1;
			$page=max(intval($page),1);
			$count=sizeof($data);
			$pagecount=ceil($count/15);
			$page=min($page,$pagecount);
			$data=array_slice($data,($page-1)*15,15);
			
			$_url=parse_url($cururl);
			$_query=preg_replace('/&page=[0-9]+/i','',$_url['query']);
			$firstpage=$_url['path'].'?'.$_query.'&page=1';
			$frontpage=$_url['path'].'?'.$_query.'&page='.max($page-1,1);
			$nextpage=$_url['path'].'?'.$_query.'&page='.min($page+1,$pagecount);
			$lastpage=$_url['path'].'?'.$_query.'&page='.$pagecount;
			$pagestring='当前'.$page.'/'.$pagecount.'页 <a href="'.$firstpage.'">首页</a> <a href="'.$frontpage.'">上一页</a> <a href="'.$nextpage.'">下一页</a> <a href="'.$lastpage.'">尾页</a>';
			include admin_tlp('yellowpages_manage');
			break;
		case 'guestbook':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if($do_submit)
			{
				switch($do)
				{
					case 'guestbook_delete':
						if(!$id)showmsg('请选择需要删除的企业留言!');
						$sql="DELETE FROM `".DB_PRE."member_comment` WHERE `".DB_PRE."member_comment`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=guestbook');
						break;
					case 'guestbook_lock':
						if(!$id)showmsg('请选择需要待审的企业留言!');
						$sql="UPDATE `".DB_PRE."member_comment` SET `".DB_PRE."member_comment`.`status`=0 WHERE `".DB_PRE."member_comment`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=guestbook');
						break;
					case 'guestbook_unlock':
						if(!$id)showmsg('请选择需要审核的企业留言!');
						$sql="UPDATE `".DB_PRE."member_comment` SET `".DB_PRE."member_comment`.`status`=1 WHERE `".DB_PRE."member_comment`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=guestbook');
						break;
				}
			}
			$where=1;
			if($timeid)
			{	
				$time = TIME; $timeid = TIME - $timeid*24*60*60; 
				$where.= " AND `addtime` >= '$timeid' AND `addtime` <= '$time'";
			}
			
			$where=isset($memberid)?$where." AND `memberid`=".intval($memberid):$where;
			$where=isset($status)?$where." AND `status`=".intval($status):$where;
			$where=!empty($k)?$where." AND `username` LIKE '%{$k}%' OR `content` LIKE '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'member_comment',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('yellowpages_guestbook');
			break;
		case 'guestbook_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->update(DB_PRE."member_comment",array('status'=>intval($status)),'id='.intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=guestbook');
			break;
		case 'news':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if($do_submit)
			{
				switch($do)
				{
					case 'news_delete':
						if(!$id)showmsg('请选择需要删除的企业新闻!');
						$sql="DELETE FROM `".DB_PRE."co_news` WHERE `".DB_PRE."co_news`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=news');
						break;
					case 'news_lock':
						if(!$id)showmsg('请选择需要待审的企业新闻!');
						$sql="UPDATE `".DB_PRE."co_news` SET `".DB_PRE."co_news`.`status`=0 WHERE `".DB_PRE."co_news`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=news');
						break;
					case 'news_unlock':
						if(!$id)showmsg('请选择需要审核的企业留言!');
						$sql="UPDATE `".DB_PRE."co_news` SET `".DB_PRE."co_news`.`status`=1 WHERE `".DB_PRE."co_news`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=news');
						break;
				}
			}
			$where=1;
			if($timeid)
			{	
				$time = TIME; $timeid = TIME - $timeid*24*60*60; 
				$where.= " AND `inputtime` >= '$timeid' AND `inputtime` <= '$time'";
			}
			
			$where=isset($userid)?$where." AND `userid`=".intval($userid):$where;
			$where=isset($status)?$where." AND `status`=".intval($status):$where;
			$where=!empty($k)?$where." AND `title` LIKE '%{$k}%' OR `description` LIKE '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'co_news',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('yellowpages_news');
			break;
		case 'news_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->update(DB_PRE."co_news",array('status'=>intval($status)),'id='.intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=news');
			break;
		case 'coupon':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if($do_submit)
			{
				switch($do)
				{
					case 'coupon_delete':
						if(!$id)showmsg('请选择需要删除的信息!');
						$sql="DELETE FROM `".DB_PRE."co_coupon` WHERE `".DB_PRE."co_coupon`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=coupon');
						break;
					case 'coupon_lock':
						if(!$id)showmsg('请选择需要待审的信息!');
						$sql="UPDATE `".DB_PRE."co_coupon` SET `".DB_PRE."co_coupon`.`status`=0 WHERE `".DB_PRE."co_coupon`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=coupon');
						break;
					case 'coupon_unlock':
						if(!$id)showmsg('请选择需要审核的信息!');
						$sql="UPDATE `".DB_PRE."co_coupon` SET `".DB_PRE."co_coupon`.`status`=1 WHERE `".DB_PRE."co_coupon`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=coupon');
						break;
				}
			}
			$where=1;
			if($timeid)
			{	
				$time = TIME; $timeid = TIME - $timeid*24*60*60; 
				$where.= " AND `inputtime` >= '$timeid' AND `inputtime` <= '$time'";
			}
			
			$where=isset($userid)?$where." AND `userid`=".intval($userid):$where;
			$where=isset($status)?$where." AND `status`=".intval($status):$where;
			$where=!empty($k)?$where." AND `title` LIKE '%{$k}%' OR `description` LIKE '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'co_coupon',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('yellowpages_coupon');
			break;
		case 'coupon_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->update(DB_PRE."co_coupon",array('status'=>intval($status)),'id='.intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=coupon');
			break;
		case 'product':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if($do_submit)
			{
				switch($do)
				{
					case 'product_delete':
						if(!$id)showmsg('请选择需要删除的信息!');
						$sql="DELETE FROM `".DB_PRE."co_product` WHERE `".DB_PRE."co_product`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=product');
						break;
					case 'product_lock':
						if(!$id)showmsg('请选择需要待审的信息!');
						$sql="UPDATE `".DB_PRE."co_product` SET `".DB_PRE."co_product`.`status`=0 WHERE `".DB_PRE."co_product`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=product');
						break;
					case 'product_unlock':
						if(!$id)showmsg('请选择需要审核的信息!');
						$sql="UPDATE `".DB_PRE."co_product` SET `".DB_PRE."co_product`.`status`=1 WHERE `".DB_PRE."co_product`.`id` in(".implode(',',$id).")";
						$db->query($sql,true);
						showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=product');
						break;
				}
			}
			$where=1;
			if($timeid)
			{	
				$time = TIME; $timeid = TIME - $timeid*24*60*60; 
				$where.= " AND `inputtime` >= '$timeid' AND `inputtime` <= '$time'";
			}
			
			$where=isset($userid)?$where." AND `userid`=".intval($userid):$where;
			$where=isset($status)?$where." AND `status`=".intval($status):$where;
			$where=!empty($k)?$where." AND `product` LIKE '%{$k}%' OR `description` LIKE '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'co_product',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('yellowpages_product');
			break;
		case 'product_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['yellowpages']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->update(DB_PRE."co_product",array('status'=>intval($status)),'id='.intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=product');
			break;
		case 'template':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['template']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$list=glob(TPL_ROOT.'comtmp/*');
			$files=glob(TPL_ROOT.'comtmp/*.*');
			$dirs=array_diff($list,$files);
			$r=array();
			foreach($dirs as $v)
			{
				if(basename($v)!='person')$r[]=basename($v);
			}
			include admin_tlp('yellowpages_template');
			break;
		case 'template_list':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['template']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$files=glob(TPL_ROOT.'comtmp/'.$tlp.'/*.html');
			$r=array();
			$i=0;
			foreach($files as $v)
			{
				$r[$i]['template']=basename($v,'.html');
				$r[$i]['updatetime']=date('Y-m-d H:i:s',filemtime($v));
				$i++;
			}
			include admin_tlp('yellowpages_template_list');
			break;
		case 'template_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['template']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			@unlink(TPL_ROOT.'comtmp/'.$path.'/'.$tlp.'.html');
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=template_list&tlp='.$path);
			break;
		case 'template_view':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['template']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$tmppath=DIRCMS_ROOT.'data/tmp/ctmp_'.trim($tlp).$_userid.'.html';
			$tmpurl='data/tmp/ctmp_'.trim($tlp).$_userid.'.html';
			$content=get_file_content(TPL_ROOT.'comtmp/'.$path.'/'.$tlp.'.html');
			$tmpcontent=str_replace('<base href="{{$DIRCMS[\'site_url\']}}" />','<base href="'.$DIRCMS['site_url'].'" />',$content);
			$tmpcontent=str_replace('<?php','&lt;?php',$tmpcontent);
			$tmpcontent=str_replace('?>','?&gt;',$tmpcontent);
			$tmpcontent=str_replace('{{$DIRCMS[\'site_url\']}}',$DIRCMS['site_url'],$tmpcontent);
			$tmpcontent=str_replace('{{$DIRCMS[site_url]}}',$DIRCMS['site_url'],$tmpcontent);
			$tmpcontent=preg_replace('/(\{\{dir:category[^\}]+\}\}.+?\{\{\/dir:category\}\})/ise',"'<a href=\"".ADMIN_FILE."?file=tag&action=edit_yp&tlp=".$tlp."&path=".$path."&content='.urlencode('\\1').'\" target=\"_blank\" style=\"width:70px; height:45px;background-color:#FFCC33\" title=\"修改标记\">修改标记</a>'",$tmpcontent);

			$tmpcontent=preg_replace('/\{\{dir:vote\s+action=\"[a-z]+\" id=([\$0-9a-z_]+)\}\}/i',"<a target=\"_blank\" href=\"".ADMIN_FILE."?file=other&action=vote_edit&id=\\1\" style=\"display:block;position:absolute;filter:Alpha(opacity=70);width:70px; line-height:25px;text-align:center;height:25px;color:#1b1b1b;background-color:#FFCC33;z-index:999\" title=\"修改投票\">修改投票</a>",$tmpcontent);

			$tmpcontent=preg_replace('/(\{\{dir:[^\}]+\}\}(.+?)\{\{\/dir:[^\{\}]+\}\})/ise',"'<a href=\"".ADMIN_FILE."?file=tag&action=edit_yp&tlp=".$tlp."&path=".$path."&content='.urlencode('\\1').'\" target=\"_blank\" style=\"display:block;position:absolute;filter:Alpha(opacity=70);width:70px; line-height:25px;text-align:center;height:25px;color:#1b1b1b;background-color:#FFCC33;z-index:999\" title=\"修改标记\">修改标记</a>'",$tmpcontent);
			$tmpcontent=preg_replace('/\{\{tlp\s+([a-z0-9_]+)\}\}/i',"<a href='".ADMIN_FILE."?file=template&action=view&id=\\1' title='模板的可视化视图' target='_blank'><font style='background-color:#FF8800'>{{tlp \\1}}</font></a>",$tmpcontent);
			$tmpcontent=preg_replace('/\{\{getTagname\(([0-9]+)\)\}\}/ie',"getTagname(\\1).' <a href=\"".ADMIN_FILE."?file=tag&action=edit_words&id=\\1\" target=\"_blank\"><font style=\"font-size:10px;font-weight:normal\">修改显示文字</font></a>'",$tmpcontent);
			if(!@file_put_contents($tmppath,$tmpcontent))
			{
				exit('<script language="javascript">{alert("请将您的data/tmp目录置为0777后再进行此操作!");history.back();}</script>');
			}
			include admin_tlp('yellowpages_template_view');
			break;
		case 'template_edit':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['template']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if(isset($do_submit)) 
			{
				@file_put_contents(TPL_ROOT.'comtmp/'.$path.'/'.$tlp.'.html',stripslashes($info['content']));
				@unlink($tmppath);
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=yellowpages&action=template_list&tlp='.$path);
			}
			if(!file_exists(TPL_ROOT.'comtmp/'.$path.'/'.$tlp.'.html'))showmsg('文件不存在!');
			$r['content']=get_file_content(TPL_ROOT.'comtmp/'.$path.'/'.$tlp.'.html');
			include admin_tlp('yellowpages_template_edit');
			break;
		case 'priv':
			if($do_submit)
			{
				cache_write('usepriv.cache.php',$usepriv,DIRCMS_ROOT.'company/cache/');
				cache_write('newspriv.cache.php',$newspriv,DIRCMS_ROOT.'company/cache/');
				cache_write('productpriv.cache.php',$productpriv,DIRCMS_ROOT.'company/cache/');
				cache_write('couponpriv.cache.php',$couponpriv,DIRCMS_ROOT.'company/cache/');
				cache_write('newscheckpriv.cache.php',$newscheckpriv,DIRCMS_ROOT.'company/cache/');
				cache_write('productcheckpriv.cache.php',$productcheckpriv,DIRCMS_ROOT.'company/cache/');
				cache_write('couponcheckpriv.cache.php',$couponcheckpriv,DIRCMS_ROOT.'company/cache/');
				cache_write('templatepriv.cache.php',$templatepriv,DIRCMS_ROOT.'company/cache/');
				showmsg($LANG['MANAGE_SUCEESS']);
			}
			$r=cache_read('membergrade.cache.php',DIRCMS_ROOT.'data/cache/');
			$usepriv=cache_read('usepriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$newspriv=cache_read('newspriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$productpriv=cache_read('productpriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$couponpriv=cache_read('couponpriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$newscheckpriv=cache_read('newscheckpriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$productcheckpriv=cache_read('productcheckpriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$couponcheckpriv=cache_read('couponcheckpriv.cache.php',DIRCMS_ROOT.'company/cache/');
			$templatepriv=cache_read('templatepriv.cache.php',DIRCMS_ROOT.'company/cache/');
			include admin_tlp('yellowpages_priv');
			break;
		case 'convert':
			$where=1;
			$k=trim(preg_replace('/[^a-z0-9_]+/i',' ',$k));
			$where=!empty($k)?$where." AND username LIKE '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'member_convert',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('yellowpages_convert');
			break;
		case 'passconvert':
			if(!$id)showmsg('请选择用户!');
			if(is_array($id))
			{
				foreach($id as $_id)
				{
					$_id=intval($_id);
					$r=cache_read('cache_membermodel'.$nowmodelid[$_id].'.cache.php',DIRCMS_ROOT.'data/cache_model/');	
					$db->mysql_delete(DB_PRE.$r['name'],$_id,'userid');
					$db->mysql_delete(DB_PRE.'member_convert',$_id,'userid');
					$r=cache_read('cache_membermodel'.$modelid[$_id].'.cache.php',DIRCMS_ROOT.'data/cache_model/');
					$template=$r['template'];
					$db->update(DB_PRE.'member',array('modelid'=>intval($modelid[$_id]),'template'=>$template),'id='.$_id);
					$db->update(DB_PRE.'member_cache',array('modelid'=>intval($modelid[$_id]),'template'=>$template),'id='.$_id);
					$db->insert(DB_PRE.$r['name'],array('userid'=>$_id));
				}
			}
			else
			{
				$_id=intval($id);
				$r=cache_read('cache_membermodel'.$nowmodelid.'.cache.php',DIRCMS_ROOT.'data/cache_model/');
				$db->mysql_delete(DB_PRE.$r['name'],$_id,'userid');
				$db->mysql_delete(DB_PRE.'member_convert',$_id,'userid');
				$r=cache_read('cache_membermodel'.$modelid.'.cache.php',DIRCMS_ROOT.'data/cache_model/');
				$template=$r['template'];
				$db->update(DB_PRE.'member',array('modelid'=>intval($modelid),'template'=>$template),'id='.$_id);	
				$db->update(DB_PRE.'member_cache',array('modelid'=>intval($modelid),'template'=>$template),'id='.$_id);	
				$db->insert(DB_PRE.$r['name'],array('userid'=>$_id));
			}
			showmsg($LANG['MANAGE_SUCEESS'],'?file=yellowpages&action=convert');
			break;
		case 'yellowpages_edit':
			include DIRCMS_ROOT.'include/member.class.php';
			$member=new member();
			$id=intval($id);
			if($id==ADMIN_FOUNDERS && $_userid!=ADMIN_FOUNDERS)showmsg('您无权修改网站创始人的黄页信息!');
			if(isset($do_submit))
			{
				$r=cache_read('cache_membermodel'.$modelid.'.cache.php',DIRCMS_ROOT.'data/cache_model/');
				$m_table=$r['name'];
				$db->update(DB_PRE.$m_table,$info,'userid='.intval($id));
				showmsg('黄页信息修改成功!',ADMIN_FILE.'?file=yellowpages&action=manage');
			}
			$data=$member->get($id);
			@extract($data);
			$r=cache_read('cache_membermodel'.$modelid.'.cache.php',DIRCMS_ROOT.'data/cache_model/');
			$m_table=$r['name'];
			$c=$db->fetch_one("SELECT a.*,b.* FROM ".DB_PRE."member a LEFT JOIN ".DB_PRE.$m_table." b ON a.id=b.userid WHERE a.id=".intval($id));
			require_once(DIRCMS_ROOT.'include/select.class.php');
			$s=new select();
			require_once(DIRCMS_ROOT.'include/form.class.php');	
			$f=new form('_m'.$modelid);
			$base_r=$f->get($c);
			include admin_tlp('yellowpages_edit');
			break;
	}
?>