<?php
require("session_check.php");
$plugin_table=$tablePreStr."plugins";
$name=get_args('path');
$opsition_value=get_args('opsition');
$valid_value=get_args('valid');
$autoorder_value=get_args('autoorder');
$type=get_args('type');
if(is_null($valid_value))$valid_value=0;
if(is_null($autoorder_value))$autoorder_value=0;
?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title></title>
	<script type="text/javascript" src="js/plugin.js"></script>
	<link rel="stylesheet" type="text/css" href="css/right.css">
<script>
function show_select(type)
{
	var plugin=plugin_Widget;
	switch(type)
	{
		case 1: plugin=plugin_App;break;
		case 2: plugin=plugin_App_Widget;break;
	}
	var tem="<select name='opsition'><option value='-1'>选择安装位置</option>";
	for(i=0;i<plugin.length;i++)
	{
		tem+="<option value='"+plugin[i].id+"'>"+plugin[i].name+"</option>";
	}
	tem+="</select>";
	document.getElementById('show_select').innerHTML=tem;
}
</script>
</head>

<body style="margin:auto">
	<?php
	if(!is_null($name) && !is_null($opsition_value)&&$opsition_value!=-1)
{
	$dom = new DOMDocument();
	$plugin_dir=dir(dirname(__file__)."/../plugins");
	chdir(dirname(__file__)."/../plugins");
	if(rename($name."/plugin.xml",$name."/_plugin.xml"))
	{
		$dom->load($name."/_plugin.xml");
		$plugin=$dom->getElementsByTagName("plugin")->item(0);
		$plugin_id=$plugin->getElementsByTagName("plugin_id")->item(0);
		$autoorder=$plugin->getElementsByTagName('autoorder')->item(0);
		$valid=$plugin->getElementsByTagName('valid')->item(0);
		if($plugin_id)
		{
			$plugin_id->nodeValue=$opsition_value;
		}
		else
		{
			$plugin_id=$dom->createElement("plugin_id");
			$plugin_id->nodeValue=$opsition_value;

		}
		if($autoorder)
		{
			$autoorder->nodeValue=$autoorder_value;
		}else
		{
			$autoorder=$dom->createElement("autoorder");
			$autoorder->nodeValue=$autoorder_value;
		}
		if($valid)
		{
			$valid->nodeValue=$valid_value;
		}
		else
		{
			$valid=$dom->createElement("valid");
			$valid->nodeValue=$valid_value;
		}
		$plugin->appendChild($plugin_id);
		$plugin->appendChild($autoorder);
		$plugin->appendChild($valid);

		$dom->formatOutput=true;
		$infos=$plugin->childNodes;
		foreach($infos as $info)
		{
			if($info->nodeName!="#text")
			{
				$tem=$info->nodeName;
				$$tem=$info->nodeValue;
			}
		}
		$dom->save($name."/_plugin.xml");
		//$valid=get_args('valid');
		//$autoorder=get_args('autoorder');
		if(isset($show))$type=$show;
		else $type=0;
		if(!isset($image))$image="";
		$description=short_check($description);
		$title=short_check($title);
		$dbo = new dbex;
		dbtarget('w',$dbServs);
		$sql="insert into $plugin_table(title,name,csspath,jspath,valid,callfunction,autoorder,type,inurl,plugin_id,image,reg_date,info) value('$title','$name','$csspath','$jspath','$valid_value','$callfunction','$autoorder_value','$type','$inurl','$opsition_value','$image',NOW(),'$description')";
		//echo $sql;
		$dbo->exeUpdate($sql);
		echo "<div style='color:green;text-align:center'><script>parent.right.install_end=true;</script>插件已经成功安装！</div>";
	}
}
else
{
?>
<form name="setplugin" method="post" action="?path=<?php echo $name?>">
<table width="100%" border="0">
  <tr>
	<td width=""><span id="show_select"><script>show_select(<?php echo $type?>)</script></span></td>
	<td width="">说明：安装位置指插件要在系统中显示的位置。</td>
  </tr>
  <tr>
	<td><input type='checkbox' id='autoorder' name='autoorder' value="1" />
	是否自由订制</td>
	<td>自由订制是指，此插件允许用户自己控制插件是否显示。</td>
  </tr>
  <tr>
	<td><input type='checkbox' id='valid' name='valid' value="1" />
	是否启用</td>
	<td>启用是指，插件是否生效。</td>
  </tr>
</table>
	<p style="text-align:center"><script>parent.right.install_submit="true";</script></p>
</form>
<?php
	}?>
</body>
</html>