<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Обработчик добавления сайта с макетом.
 * 
 * Файл: /admin/site/action/add_site_with_template.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */

$site = & singleton ('site');

$SiteTemplate = & singleton ('SiteTemplate');
$aXmlTemplatesTmp = $SiteTemplate->GetTemplateXml();

if (!$aXmlTemplatesTmp)
{
	show_error_message(sprintf($GLOBALS['MSG_site']['write_error'], $SiteTemplate->GetTemplateFilePath()));
}

$sTemplatesUrlServer = $SiteTemplate->GetTemplatesUrlServer();

$form_params = array();

$form_params['title'] = "Выбор макета сайта";

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/site/site.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'AddSiteWithTemplate';

$admin_forms_fields = new admin_forms_fields();

$form_params['path_array'][] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/site/site.php', '', 42, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/site/site.php', '', 42, 'load_data'),
'name' => $GLOBALS['MSG_site']['site_link_sites']);

$admin_forms_fields->admin_forms_fields($form_params);

$kernel = & singleton('kernel');

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

if (isset($aXmlTemplatesTmp) && is_array($aXmlTemplatesTmp) && count($aXmlTemplatesTmp) > 0)
{
	// Шаблон выбран, установлено selected
	$selected = false;

	// цикл по дереву group
	foreach ($aXmlTemplatesTmp['groups'][0]['value']['group'] as $iKeyGroup => $aValueGroup)
	{
		// если в группе есть шаблоны
		if (isset($aValueGroup['value']['templates'][0]['value']['template']))
		{
			// цикл по дереву template
			foreach ($aValueGroup['value']['templates'][0]['value']['template'] as $iKeyTemplate => $aValueTemplate)
			{
				// Пропускаем шаблон "Корпорация"
				if ($aValueTemplate['arg']['id'] == 2782)
				{
					continue ;
				}
				
				$small_width = $aValueTemplate['value']['template_preview']['0']['arg']['width'];
				$small_height = 200 + 40;

				ob_start();
				// Вывод информации о шаблоне
				?><div class="site_template_block">
				<div class="bord_img" style="width: <?php echo $small_width?>px; height:<?php echo $small_height?>px;">
					<div class="tl"></div>
					<div class="t"></div>
					<div class="tr"></div>
					<div class="r"></div>
					<div class="br"></div>
					<div class="b"></div>
					<div class="bl"></div>
					<div class="l"></div>
					
					<a href="<?php echo $sTemplatesUrlServer.$aValueTemplate['value']['template_full_preview']['0']['value']?>" target="_blank">
					<img src="<?php echo $sTemplatesUrlServer.$aValueTemplate['value']['template_preview']['0']['value']?>"
					width="<?php echo $small_width?>" />
					</a>
					
					<div class="bottom">
						<input style="float: left" type="radio" <?php if(!$selected) {echo 'checked="checked"';} ?> name="template_id" id="template_<?php echo $aValueTemplate['arg']['id']?>" value="<?php echo $aValueTemplate['arg']['id']?>" /> 

						<label for="template_<?php echo $aValueTemplate['arg']['id']?>" style="margin-left: 5px; float: left">
							<b><?php echo $aValueTemplate['value']['template_name']['0']['value']?></b>
							<br />
							<span><?php echo $aValueGroup['value']['group_name'][0]['value']?></span>
						</label>
					</div>
				</div>
				</div><?php
				
				$value = ob_get_clean();
				
				$param = array();
				$param['tab_id'] = $tab_id;
				$param['name'] = "site_template_{$aValueTemplate['arg']['id']}";
				$param['type'] = 15;
				$param['value'] = $value;
				$admin_forms_fields->AddField($param);

				$selected = true;
			}
		}
	}
}

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

// Кнопка "Сохранить".
/*$param = array();
$param['name'] = 'save_site';
$param['caption'] = $GLOBALS['MSG_site']['site_save'];
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'button';
$admin_forms_fields->AddButton($param);*/

// Кнопка "Далее".
$param = array();
$param['name'] = 'add_site_with_template';
$param['caption'] = 'Далее';
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($param);

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