<?php
session_start();
require_once "init.php";


/**
 * @$type  输入的资源类型 0文件路径，1已经读出来的字符串
 * 这个类暂时先放在这里。
 */

class xml {
	var $xml;
	/*
	*构造函数初始化 $xml
	*构造SimpleXMLElement 对象
	*/
	function __construct($source, $type = 0) {
		if ($type == 1) {
			$this->xml = simplexml_load_string($source);
		} else {
			$this->xml = simplexml_load_file($source);
		}	
	}
	//获取某个节点
	function getNode($name) {
		return $this->xml->$name;
	}
	//获取某个节点属性值
	function getNodeAttr($name,$attr) {
		return $this->xml->$name[$attr];
	}
	//根据xpath来查找
	function xpathSearch($sear) {
		return $this->xml->xpath('//'.$sear);
	}
	//或取某个节点下的所有子
	function getChildren($name) {
		return $this->xml->$name->children();
	}
}

$pass_name = $_GET["name"];
$pass_type = $_GET["type"];
if($pass_type == "vhost")
{
	$param['ftpname'] = $pass_name;
	$param['action']   = "gethostinfo";
	$param['category'] = "vhost";
}
else if($pass_type == "domain")
{
	$param['domain'] = $pass_name;
	$param['action']   = "getdomaininfo";
	$param['category'] = "domain";
}
else if($pass_type == "email")
{
	$param['domain'] = $pass_name;
	$param['action']   = "getmailinfo";
	$param['category'] = "email";
}
else if($pass_type == "database")
{
	
	$param['dbname'] = $pass_name;
	$param['action']   = "getdbinfo";
	$param['category'] = "database";
}
else
{
	echo "无效参数";die();
}

$api = new API();
$api->Execute($param);

if($api->getValue('returncode')==200) {
	$xml_parser = new xml($api->xmlresp,1);
} elseif ($api->getValue('returncode')==300) {
	$fial = $api->getValue('failreason');
	echo "<script>alert('".$fial."');history.back();</script>";
} else {
	echo "<script>alert('未知错误，请稍后再尝试');history.back();</script>";
}

$products = $xml_parser->getChildren("products");
print_r($products);
?>
