<?php
require("session_check.php");
require("proxy/proxy.php");
//语言包引入
$u_langpackage=new uilp;
$er_langpackage=new errorlp;
$serv_url=list_substitue("tpl");
$is_show=0;
$tpl_list=array();
$error_str='';

if($serv_content=@file_get_contents($serv_url)){
	if(preg_match("/error\_\d/",$serv_content)){
		$error_str=$er_langpackage->{"er_".$serv_content};//代理程序返回错误
	}else{
		$serv_tpl_array=explode(",",$serv_content);
		foreach($serv_tpl_array as $val){
			if(!empty($val)){
				$tpl_list[]=$val;
			}
		}
		$is_show=1;
	}
}else{
	$error_str=$u_langpackage->u_get_false;
	}
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/right.css">
</head>
<script type='text/javascript'>
	
	function change_dir_state(dir,state){
		if(state==0){
			document.getElementById('dir_value_'+dir).value=document.getElementById('def_dir_'+dir).innerHTML;
		}else{
			document.getElementById('def_dir_'+dir).innerHTML=document.getElementById('dir_value_'+dir).value;
		}
			document.getElementById('def_dir_'+dir).style.display='';
			document.getElementById('new_dir_'+dir).style.display='none';		
	}
	
	function show_change(dir){
		document.getElementById('def_dir_'+dir).style.display='none';
		document.getElementById('new_dir_'+dir).style.display='';		
	}
	
	function download(tpl_name){
		document.getElementById('action').style.display='';
		document.getElementById('action').style.top=document.body.clientHeight/2-150+"px";
		document.getElementById('action').style.left=document.body.clientWidth/2-150+"px";
		var setup_dir=document.getElementById('dir_value_'+tpl_name).value;
		window.location.href='download_tpl.action.php?tpl_name='+tpl_name+"&setup_dir="+setup_dir;
	}
	
</script>
<body>
<div id='action' style='display:none;' class='ajax_window'>
	<div style='background-color:white;width:220px;height:50px'>
		<div style='margin-left:25px;width:220px'>
			<div style='margin-top:15px;width:220px'><img src='images/loading.gif' style='float:left' />正在编译，请稍等...</div>
		</div>
	</div>
</div>
<div class="container">
	<div class="rs_head"><?php echo $u_langpackage->u_new_list;?></div>
</div>
<?php if($is_show==1){?>
	<table class="main">
		<tr>
			<th><?php echo $u_langpackage->u_tpl_name;?></th>
			<th><?php echo $u_langpackage->u_dir_pos;?></th>
			<th><?php echo $u_langpackage->u_ctrl;?></th>
		</tr>
	<?php
	foreach($tpl_list as $rs){
	?>
		<tr>
			<td width="50%"><?php echo $rs;?></td>
			<td width="*">templates/
				<span id='def_dir_<?php echo $rs;?>'><?php echo $rs;?></span>
				<span id='new_dir_<?php echo $rs;?>' style='display:none'>
					<input type='text' id='dir_value_<?php echo $rs;?>' value='<?php echo $rs;?>' style='width:80px' />
					<input type='button' class='top_button' onclick='change_dir_state("<?php echo $rs;?>",1);' value='<?php echo $u_langpackage->u_sure;?>' />
					<input type='button' class='top_button' onclick='change_dir_state("<?php echo $rs;?>",0);' value='<?php echo $u_langpackage->u_cancel;?>' />
				</span>
			</td>
			<td width="15%">
				&nbsp|&nbsp
				<a href='javascript:download("<?php echo $rs;?>");' onclick='return confirm("<?php echo $u_langpackage->u_ask_download;?>")'><?php echo $u_langpackage->u_download;?></a> &nbsp|&nbsp 
				<a href='javascript:show_change("<?php echo $rs;?>");'><?php echo $u_langpackage->u_change_dir;?></a>&nbsp|
			</td>
		</tr>
	<?php }?>
	</table>
	
<?php }else{?>

	<table class="main main_left">
		<tr>
			<td><?php echo $error_str;?></td>
		</tr>
	</table>

<?php }?>
	
	<div class="container">
		<div class="rs_head"><?php echo $u_langpackage->u_prompt_inf;?></div>
	</div>
	<table class="main main_left">
		<tr>
			<td><?php echo $u_langpackage->u_tpl_prompt_1;?></td>
		</tr>
		<tr>
			<td><?php echo $u_langpackage->u_tpl_prompt_2;?></td>
		</tr>
	</table>

</body>
</html>