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

Core_Auth::authorization('seo');

// Код формы
$iAdmin_Form_Id = 141;
$sAdminFormAction = '/admin/seo/index.php';

$sAdminFormQueryAction = '/admin/seo/query/index.php';

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

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

$sFormPath = $oAdmin_Form_Controller->getPath();

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

// Элементы меню
$oAdmin_Form_Entity_Menus->add(Core::factory('Admin_Form_Entity_Menu')
	->name(Core::_('Seo.characteristics'))
	->add(Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Seo.add'))
		->img('/admin/images/seo_add.gif')
		->href($oAdmin_Form_Controller->getAdminActionLoadHref($sFormPath, 'edit', NULL, 0, 0))
		->onclick($oAdmin_Form_Controller->getAdminActionLoadAjax($sFormPath, 'edit', NULL, 0, 0))
	)
	->add(Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Seo.request'))
		->img('/admin/images/seo_go.gif')
		->href($oAdmin_Form_Controller->getAdminActionLoadHref($sFormPath, 'define', NULL, 0, 0))
		->onclick($oAdmin_Form_Controller->getAdminActionLoadAjax($sFormPath, 'define', NULL, 0, 0))
	)
)
->add(Core::factory('Admin_Form_Entity_Menu')
	->name(Core::_('Seo.search_requests'))
	->add(Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Seo.management'))
		->img('/admin/images/query.gif')
		->href($oAdmin_Form_Controller->getAdminActionLoadHref($sAdminFormQueryAction, NULL, NULL, 0, 0))
		->onclick($oAdmin_Form_Controller->getAdminActionLoadAjax($sAdminFormQueryAction, NULL, NULL, 0, 0))
	)
	->add(Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Seo.get_position'))
		->img('/admin/images/query_go.gif')
		->href($oAdmin_Form_Controller->getAdminActionLoadHref($sAdminFormQueryAction, 'define_position', NULL, 0, 0))
		->onclick($oAdmin_Form_Controller->getAdminActionLoadAjax($sAdminFormQueryAction, 'define_position', NULL, 0, 0))
	)
)
->add(Core::factory('Admin_Form_Entity_Menu')
	->name(Core::_('Seo.report'))
	->add(Core::factory('Admin_Form_Entity_Menu')
		->name(Core::_('Seo.report_website'))
		->img('/admin/images/report.gif')
		->href($oAdmin_Form_Controller->getAdminActionLoadHref($sFormPath, 'report', NULL, 0, 0))
		->onclick($oAdmin_Form_Controller->getAdminActionLoadAjax($sFormPath, 'report', NULL, 0, 0))
	)
);

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

// Строка навигации
$oAdmin_Form_Entity_Breadcrumbs = new Admin_Form_Entity_Breadcrumbs();

// Элементы строки навигации
$oAdmin_Form_Entity_Breadcrumbs->add(Core::factory('Admin_Form_Entity_Breadcrumb')
	->name(Core::_('Seo.title'))
	->href($oAdmin_Form_Controller->getAdminLoadHref($sFormPath, NULL, NULL, ''))
	->onclick($oAdmin_Form_Controller->getAdminLoadAjax($sFormPath, NULL, NULL, ''))
);

// Действие редактирования
$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')
{
	$oSeo_Controller_Edit = new Seo_Controller_Edit(
		$oAdmin_Form_Action
	);

	$oSeo_Controller_Edit->addEntity($oAdmin_Form_Entity_Breadcrumbs);

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

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

if ($oAdmin_Form_Action && $oAdmin_Form_Controller->getAction() == 'define')
{
	$oSeo_Controller_Define = new Seo_Controller_Define(
		$oAdmin_Form_Action
	);

	$oAdmin_Form_Controller->addAction($oSeo_Controller_Define);
}

// Определение позиций
$oAdmin_Form_Action = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id)
	->Admin_Form_Actions
	->getByName('define_position');

if ($oAdmin_Form_Action && $oAdmin_Form_Controller->getAction() == 'define_position')
{
	$oSeo_Query_Position_Controller_Define = new Seo_Query_Position_Controller_Define(
		$oAdmin_Form_Action
	);

	$oAdmin_Form_Controller->addAction($oSeo_Query_Position_Controller_Define);
}

// Отчет по сайту
$oAdmin_Form_Action = Core_Entity::factory('Admin_Form', $iAdmin_Form_Id)
	->Admin_Form_Actions
	->getByName('report');

if ($oAdmin_Form_Action && $oAdmin_Form_Controller->getAction() == 'report')
{
	$oSeo_Controller_Report = new Seo_Controller_Report(
		$oAdmin_Form_Action
	);

	$oAdmin_Form_Entity_Breadcrumbs->add(Core::factory('Admin_Form_Entity_Breadcrumb')
		->name(Core::_('Seo.report_title', Core_Entity::factory('Site', CURRENT_SITE)->name))
		->href($oAdmin_Form_Controller->getAdminLoadHref($sFormPath, 'report', NULL, '0'))
		->onclick($oAdmin_Form_Controller->getAdminLoadAjax($sFormPath, 'report', NULL, '0'))
	);

	$oSeo_Controller_Report->addEntity($oAdmin_Form_Entity_Breadcrumbs);

	$oAdmin_Form_Controller->addAction($oSeo_Controller_Report);
}

// Действие "Применить"
$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);
}

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

// Ограничение по сайту
$oAdmin_Form_Dataset->addCondition(
	array('where' =>
		array('site_id', '=', CURRENT_SITE)
	)
);

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

$oAdmin_Form_Controller->execute();