<?php
	include str_replace('\\','/',dirname(__FILE__)).'/include/common.inc.php';
	@header("Cache-Control: no-cache, must-revalidate");
	session_start();
	(!$_userid || $_SESSION['is_admin']!=true) && exit('没有权限!');
	if(!$id || $id=='close')exit('');
	$id=trim($id);
	if(in_array($type,array('content','member')))
	{
		$r=cache_read('template.cache.php',TPL_ROOT.TPL_NAME.'/');
		$data='<div style="border:#afc7d8 1px solid;background-color:#edf0f6;line-height:20px;padding:5px"><a href="javascript:void(0);" onclick="javascript:poptemplate(\'close\');"><u>关闭</u></a><br />';
		if($r)foreach($r as $_r)
		{
			if(strtolower(substr($_r['template'],0,strlen($id)))==$id)
			{
				switch($type)
				{
					case 'content':
						$data.=$defaultv==$_r['template']?'[<font color="#FF0000">当前</font>] '.$_r['name'].'(<font color="#FF0000">'.$_r['template'].'.html</font>)<br />':'<a href="'.ADMIN_FILE.'?file=model&action=template&tlp='.$tlp.'&modelid='.$modelid.'&tlpname='.$_r['template'].'">[使用]</a> '.$_r['name'].'('.$_r['template'].'.html)<br />';
						break;
					case 'member':
						$data.=$defaultv==$_r['template']?'[<font color="#FF0000">当前</font>] '.$_r['name'].'(<font color="#FF0000">'.$_r['template'].'.html</font>)<br />':'<a href="'.ADMIN_FILE.'?file=membermodel&action=template&tlp='.$tlp.'&modelid='.$modelid.'&tlpname='.$_r['template'].'">[使用]</a> '.$_r['name'].'('.$_r['template'].'.html)<br />';
						break;					
				}
			}
		}
	}
	else
	{
		switch($type)
		{
			case 'area':
				$data='<div style="border:#afc7d8 1px solid;background-color:#edf0f6;line-height:20px;padding:5px"><a href="javascript:void(0);" onclick="javascript:poptemplate(\'close\');"><u>关闭</u></a><br /><a href="'.ADMIN_FILE.'?file=area&action=setparentid&id='.$modelid.'&parentid=0">一级</a><br />';
				$r=cache_read('all_area.cache.php',DIRCMS_ROOT.'data/cache/');
				foreach($r as $_r)
				{
					$data.=$_r['id']==$defaultv?$_r['area'].'<br />':'<a href="'.ADMIN_FILE.'?file=area&action=setparentid&id='.$modelid.'&parentid='.$_r['id'].'">'.$_r['area'].'</a><br />';
				}
				break;
			case 'member_type':
				$data='<div style="border:#afc7d8 1px solid;background-color:#edf0f6;line-height:20px;padding:5px"><a href="javascript:void(0);" onclick="javascript:poptemplate(\'close\');"><u>关闭</u></a><br /><a href="'.ADMIN_FILE.'?file=yellowpages&action=setparentid&id='.$modelid.'&parentid=0">一级</a><br />';
				$r=cache_read('member_type.cache.php',DIRCMS_ROOT.'data/cache/');
				foreach($r as $_r)
				{
					$data.=$_r['id']==$modelid?$_r['type'].'<br />':'<a href="'.ADMIN_FILE.'?file=yellowpages&action=setparentid&id='.$modelid.'&parentid='.$_r['id'].'">'.$_r['type'].'</a><br />';
				}
				break;
			case 'admin':
				$data='<div style="border:#afc7d8 1px solid;background-color:#edf0f6;line-height:20px;padding:5px"><a href="javascript:void(0);" onclick="javascript:poptemplate(\'close\');"><u>关闭</u></a><br />';
				$r=cache_read('role.cache.php',DIRCMS_ROOT.'data/cache/');
				foreach($r as $_r)
				{
					$data.=$_r['id']==$defaultv?$_r['name'].'<br />':'<a href="'.ADMIN_FILE.'?file=admin&action=setroleid&id='.$modelid.'&roleid='.$_r['id'].'">'.$_r['name'].'</a><br />';
				}
				break;
		}
	}
	$data.='</div>';
	exit($data);
?>