<?php
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Модуль typograph.
 *
 * Файл: /admin/typograph/typograph.php
 *
 * @author Hostmake LLC
 * @version 5.x
 */
// Подключаем основные классы.
require_once('../../main_classes.php');

$admin = new Admin();

// Проверка авторизации пользователя.
$admin->admin_session_valid('typograph');

$kernel = & singleton('kernel');

// Инсталляция всех модулей ядра.
$kernel->LoadModules(!isset($_REQUEST['JsHttpRequest']));

// Инициализация CURRENT_SITE и констант.
$admin->admin_init();

if (!isset($_REQUEST['JsHttpRequest']))
{
	do_html_header_admin($GLOBALS['MSG_typograph']['form_title']);
}

$admin_forms = & singleton('admin_forms');

$typograph = & singleton('typograph');

// Типографирование
ob_start();

if (isset($_REQUEST['typograph']))
{
	$content = $typograph->ProcessTypographic(to_str($_REQUEST['typograph']), isset($_REQUEST['use_trailing_punctuation']));
}
else
{
	$content = '';
}

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/typograph/typograph.php';
$form_params['title'] = $GLOBALS['MSG_typograph']['form_title'];

$admin_forms_fields = new admin_forms_fields($form_params);

ob_start();
show_message($GLOBALS['MSG_typograph']['form_warning']);
$text1 = ob_get_clean();

// Параметры.
$tab_id = $admin_forms_fields->AddTab('');

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'text';
$param['caption'] = $text1;
$param['type'] = 8; // Поле ввода.

$admin_forms_fields->AddField($param);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'typograph';
$param['caption'] = $GLOBALS['MSG_typograph']['form_text'];
$param['type'] = 5; // Поле ввода.
$param['value'] = $content;
$param['attributes']['rows'] = 15;

$admin_forms_fields->AddField($param);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'use_trailing_punctuation';
$param['caption'] = $GLOBALS['MSG_typograph']['use_trailing_punctuation'];
$param['type'] = 1; // Флажок.
$param['value'] = isset($_REQUEST['use_trailing_punctuation']);

$admin_forms_fields->AddField($param);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

if (isset($_REQUEST['typograph']))
{
	// Оттипографированный текст
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'typograph_result';
	$param['type'] = 15; // Поле ввода.
	$param['value'] = '<div class="typograph_result">'.$content.'</div>';

	$admin_forms_fields->AddField($param);
}

// Кнопка "Типографировать".
$param = array();
$param['name'] = 'exec_typograph';
$param['caption'] = $GLOBALS['MSG_typograph']['exec_typograph'];
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '/admin/typograph/typograph.php', '', this, 0)";
$param['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($param);

// Отображение формы.
$admin_forms_fields->ShowForm();

$form_html = ob_get_clean();

if (!isset($_REQUEST['JsHttpRequest']))
{
	?><div id="id_content"><?php echo $form_html?></div><?php
}
else
{
	$JsHttpRequest = new JsHttpRequest('UTF-8');

	$GLOBALS['_RESULT'] = array(
	'error' => '',
	'form_html' => $form_html,
	'title' => $GLOBALS['MSG_typograph']['form_title']);

	echo $JsHttpRequest->LOADER;
}

if (!isset($_REQUEST['JsHttpRequest']))
{
	do_html_footer_admin();
}
?>