<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * This class provides PLESK domain support
 *
 * @package    OSB
 * @subpackage Plugins/Plesk
 * @category   Plugins
 * @author     Deon George
 * @copyright  (c) 2010 Deon George
 * @license    http://dev.leenooks.net/license.html
 */
class Plesk_Domain extends Plesk {
	private $_loaded = FALSE;

	// @todo Get these default "templates" values out of the DB
	private $_template = array(
		'gen_info'=>array(),
		'hosting'=>array(),
		'limits'=>array(),
		'user'=>array(),
	);

	/**
	 * Get a Client Configuration
	 */
	public function cmd_getdomain(Model_Service $so) {
		$items = array_keys($this->_template);

                $domain = $this->packet->add_node('domain');
		$get = $domain->add_node('get');
		$filter = $get->add_node('filter');
                $filter->add_node('domain-name',strtolower($so->plugin()->name()));
		$dataset = $get->add_node('dataset');
		foreach ($items as $k)
			$dataset->add_node($k);

		$result = $this->server_command($this->xml);

		if ($result->domain->get->result->status->value() != 'ok')
			throw new Kohana_Exception('Unable to get PLESK Domain data');
 
		foreach ($items as $k)
			foreach ($result->get($k) as $a=>$b)
				$this->_object[$k] = $this->collapse($b);

		$this->_loaded = TRUE;

		return $this;
	}

	public function loaded() {
		return $this->_loaded;
	}
}
?>
