<?php
/**
 * Online shop.
 *
 * @package HostCMS
 * @version 6.x
 * @author Hostmake LLC
 * @copyright © 2005-2013 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 */
require_once('../../../../../../bootstrap.php');

Core_Auth::authorization('shop');

// Код формы
$iAdmin_Form_Id = 61;
$sAdminFormAction = '/admin/shop/country/location/city/area/index.php';

$oAdmin_Form = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id);

$oShopCountryLocationCity = Core_Entity::factory('Shop_Country_Location_City', Core_Array::getGet('shop_city_id', 0));

$oShopCountryLocation = $oShopCountryLocationCity->Shop_Country_Location;

$oShopCountry = $oShopCountryLocation->Shop_Country;

// Контроллер формы
$oAdmin_Form_Controller = new Admin_Form_Controller($oAdmin_Form);
$oAdmin_Form_Controller
	->setUp()
	->path($sAdminFormAction)
	->title($pageTitle = Core::_('Shop_Country_Location_City_Area.show_city_area_title', $oShopCountryLocationCity->name))
	->pageTitle($pageTitle);

// Меню формы
$oAdmin_Form_Entity_Menus = new Admin_Form_Entity_Menus();

// Элементы меню
$oAdmin_Form_Entity_Menus->add(
	Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Shop_Country_Location_City_Area.show_city_area_link'))
		->add(
			Core::factory('Admin_Form_Entity_Menu')
				->name(Core::_('Shop_Country_Location_City_Area.show_city_area_link_add'))
				->img('/admin/images/city_area_add.gif')
				->href(
					$oAdmin_Form_Controller->getAdminActionLoadHref($oAdmin_Form_Controller->getPath(), 'edit', NULL, 0, 0)
				)
				->onclick(
					$oAdmin_Form_Controller->getAdminActionLoadAjax($oAdmin_Form_Controller->getPath(), 'edit', NULL, 0, 0)
				)
		)
);

// Добавляем все меню контроллеру
$oAdmin_Form_Controller->addEntity($oAdmin_Form_Entity_Menus);

// Представитель класса хлебных крошек
$oAdmin_Form_Entity_Breadcrumbs = new Admin_Form_Entity_Breadcrumbs();

// Создаем первую хлебную крошку
$oFirstBreadCrumb = Core::factory('Admin_Form_Entity_Breadcrumb')
	->name(Core::_('Shop.menu'))
	->href
	(
		$oAdmin_Form_Controller->getAdminLoadHref($sShopFormPath = '/admin/shop/index.php', NULL, NULL, '')
	)
	->onclick
	(
		$oAdmin_Form_Controller->getAdminLoadAjax($sShopFormPath, NULL, NULL, '')
	);

$oAdmin_Form_Entity_Breadcrumbs->add
(
	$oFirstBreadCrumb
);

// Добавляем вторую крошку на страны
$oAdmin_Form_Entity_Breadcrumbs->add(
	Core::factory('Admin_Form_Entity_Breadcrumb')
		->name(Core::_('Shop_Country.show_country_link'))
		->href
		(
			$oAdmin_Form_Controller->getAdminLoadHref($prevFormPath = '/admin/shop/country/index.php', NULL, NULL, '')
		)
		->onclick
		(
			$oAdmin_Form_Controller->getAdminLoadAjax($prevFormPath, NULL, NULL, '')
		)
);

// Добавляем вторую крошку на местоположения
$oAdmin_Form_Entity_Breadcrumbs->add(
	Core::factory('Admin_Form_Entity_Breadcrumb')
		->name(Core::_('Shop_Country_Location.show_location_title', $oShopCountry->name))
		->href
		(
			$oAdmin_Form_Controller->getAdminLoadHref($prevFormPath = '/admin/shop/country/location/index.php', NULL, NULL, $sAdditionalParam = '&shop_country_id=' . $oShopCountry->id)
		)
		->onclick
		(
			$oAdmin_Form_Controller->getAdminLoadAjax($prevFormPath, NULL, NULL, $sAdditionalParam)
		)
);

// Добавляем третью крошку на города
$oAdmin_Form_Entity_Breadcrumbs->add(
	Core::factory('Admin_Form_Entity_Breadcrumb')
		->name(Core::_('Shop_Country_Location_City.show_city_title', $oShopCountryLocation->name))
		->href
		(
			$oAdmin_Form_Controller->getAdminLoadHref($prevFormPath = '/admin/shop/country/location/city/index.php', NULL, NULL, $sAdditionalParam = "&shop_location_id=" . $oShopCountryLocation->id)
		)
		->onclick
		(
			$oAdmin_Form_Controller->getAdminLoadAjax($prevFormPath, NULL, NULL, $sAdditionalParam)
		)
);

// Добавляем четвертую крошку на текущую форму
$oAdmin_Form_Entity_Breadcrumbs->add(
	Core::factory('Admin_Form_Entity_Breadcrumb')
		->name($pageTitle)
		->href
		(
			$oAdmin_Form_Controller->getAdminLoadHref($oAdmin_Form_Controller->getPath(), NULL, NULL, $sAdditionalParam = "&shop_city_id=" . $oShopCountryLocationCity->id)
		)
		->onclick
		(
			$oAdmin_Form_Controller->getAdminLoadAjax($oAdmin_Form_Controller->getPath(), NULL, NULL, $sAdditionalParam)
		)
);

$oAdmin_Form_Controller->addEntity($oAdmin_Form_Entity_Breadcrumbs);

// Действие редактирования
$oAdmin_Form_Action = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id)
	->Admin_Form_Actions
	->getByName('edit');

if ($oAdmin_Form_Action && $oAdmin_Form_Controller->getAction() == 'edit')
{
	$ShopCountryLocationCityArea_Controller_Edit = new Shop_Country_Location_City_Area_Controller_Edit
	(
		$oAdmin_Form_Action
	);

	// Хлебные крошки для контроллера редактирования
	$ShopCountryLocationCityArea_Controller_Edit
		->addEntity
		(
			$oAdmin_Form_Entity_Breadcrumbs
		);

	// Добавляем типовой контроллер редактирования контроллеру формы
	$oAdmin_Form_Controller->addAction($ShopCountryLocationCityArea_Controller_Edit);
}

// Действие "Применить"
$oAdminFormActionApply = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id)
	->Admin_Form_Actions
	->getByName('apply');

if ($oAdminFormActionApply && $oAdmin_Form_Controller->getAction() == 'apply')
{
	$oControllerApply = new Admin_Form_Action_Controller_Type_Apply
	(
		$oAdminFormActionApply
	);

	// Добавляем контроллер редактирования контроллеру формы
	$oAdmin_Form_Controller->addAction($oControllerApply);
}

// Действие "Копировать"
$oAdminFormActionCopy = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id)
	->Admin_Form_Actions
	->getByName('copy');

if ($oAdminFormActionCopy && $oAdmin_Form_Controller->getAction() == 'copy')
{
	$oControllerCopy = new Admin_Form_Action_Controller_Type_Copy(
		$oAdminFormActionCopy
	);

	// Добавляем типовой контроллер редактирования контроллеру формы
	$oAdmin_Form_Controller->addAction($oControllerCopy);
}

// Источник данных 0
$oAdmin_Form_Dataset = new Admin_Form_Dataset_Entity
(
	Core_Entity::factory('Shop_Country_Location_City_Area')
);

$oAdmin_Form_Dataset->addCondition(
	array('where' =>
		array('shop_country_location_city_id', '=', $oShopCountryLocationCity->id)
	)
);

// Добавляем источник данных контроллеру формы
$oAdmin_Form_Controller->addDataset
(
	$oAdmin_Form_Dataset
);

// Показ формы
$oAdmin_Form_Controller->execute();