<?php
require_once('../../system/configuration.php');
require(PATH_SYSTEM.'core.php');
try 
{
	$vhost = new vhost();
	
	$_SESSION['user']->userCheckAccess(LEVEL_CUSTOMER);
	$_SESSION['hosting']->userCheckAccess();
	
	$_SESSION['template']->loadJS('vhosts.js');
	
	if ( $_SESSION['hosting']->information_hosting->offer_virtualhosts_number == 0 ) $base_tpl = 'error/not_in_offer';
	else {
		// VHosts specific menu
		$vhosts_menu = array();
		$vhosts_menu['hosting/domainnames.xhtml'] = 'mnu_list_vhosts';
		$vhosts_menu['hosting/domainnames-add.xhtml'] = "mnu_add_vhost";
		$_SESSION['template']->addMenu('vhosts', $vhosts_menu);
		
		if ( isset($_GET['action']) and $_GET['action'] == 'add') {
			$base_tpl = 'hosting/vhosts/add';
		} else {
			$base_tpl = 'hosting/vhosts/list';
			$pages_count = $vhost->userCountTotalPages();
			$_SESSION['template']->getWords(array('pages_count' => $pages_count));
		}
	}
	$_SESSION['template']->loadTemplate('_contentbegin');
	$_SESSION['template']->loadTemplate($base_tpl);
	$_SESSION['template']->loadTemplate('_contentend');
	$_SESSION['template']->getWords(array('sql' => $_SESSION['database']->executed_req));
	$_SESSION['template']->parseTemplate();
} catch (myException $error) {
	$error->displayErrorMessage();
}
