<?php
require("session_check.php");
require("proxy/proxy.php");
//语言包引入
$t_langpackage=new toollp;
$er_langpackage=new errorlp;
$xmlDom=new DomDocument;
$serv_url=list_substitue("tools");
$client_url="toolsBox/tool.xml";
$is_show=0;
$serv_content=@file_get_contents($serv_url);//取得代理返回数据

if($serv_content){
	if(preg_match("/error\_\d/",$serv_content)){
		$error_str=$er_langpackage->{"er_".$serv_content};//代理程序返回错误
	}else{
		$client_content=file_get_contents($client_url);
		preg_match_all("/<tool_item id=\"\w+\">/",$client_content,$is_setup);//取得本地已经安装的工具

		foreach($is_setup[0] as $val){
			$val=str_replace("\"","\\\"",$val);
			$serv_content=preg_replace("/".$val."[\s\S]*<\/tool_item>[^<]/","",$serv_content);//检测已有的工具组件
		}
		
		if(!preg_match("/<tool_item id=\"\w*\">([\s\S]*)<\/tool_item>/",$serv_content)){//是否有可以下载的组件
			$error_str=$t_langpackage->t_download_none;
		}else{
			$is_show=1;
			$xmlDom->loadXML($serv_content);//取得本地没有的可以下载的工具组件
			$tool_item=$xmlDom->getElementsByTagName('tool_item');
		}
	}
}else{
	$error_str=$t_langpackage->t_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 download_action(tool_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";
		window.location.href="download_tool.action.php?id="+tool_name;
	}
</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' /><?php echo $t_langpackage->t_loading;?></div>
		</div>
	</div>
</div>
<div class="container">
	<div class="rs_head"><?php echo $t_langpackage->t_list;?></div>
</div>
<?php if($is_show==1){?>
	<table class="main">
		<tr>
			<th><?php echo $t_langpackage->t_name;?></th>
			<th><?php echo $t_langpackage->t_code_num;?></th>
			<th><?php echo $t_langpackage->t_time;?></th>
			<th><?php echo $t_langpackage->t_author;?></th>
			<th><?php echo $t_langpackage->t_ctrl;?></th>
		</tr>
	<?php
	foreach($tool_item as $rs){
	?>
		<tr>
			<td><?php echo $rs->getElementsByTagName('toolName')->item(0)->nodeValue;?></td>
			<td><?php echo $rs->getAttribute("id");?></td>
			<td><?php echo $rs->getElementsByTagName('date')->item(0)->nodeValue;?></td>
			<td><?php echo $rs->getElementsByTagName('author')->item(0)->nodeValue;?></td>
			<td><a href='javascript:download_action("<?php echo $rs->getAttribute("id");?>");' onclick='return confirm("<?php echo $t_langpackage->t_ask_download;?>")'><?php echo $t_langpackage->t_download;?></a></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 $t_langpackage->t_tip_inf;?></div>
	</div>
	<table class="main main_left">
		<tr>
			<td><?php echo $t_langpackage->t_download_pro_1;?></td>
		</tr>
		<tr>
			<td><?php echo $t_langpackage->t_download_pro_2;?></td>
		</tr>
		<tr>
			<td><?php echo $t_langpackage->t_download_pro_3;?></td>
		</tr>		
	</table>

</body>
</html>