<?php
$kernel = & singleton('kernel');
/* ID Информационной системы */
$InformationSystem_id = to_int($GLOBALS['LA']['InformationSystemID']);
/* Количество записей на страницу */
$items_on_page = to_int($GLOBALS['LA']['ItemsOnPage']);
$GLOBALS['LA_InformationSystem'] = & singleton('InformationSystem');
if ($items_on_page !== true)
{
$items_on_page = to_int($items_on_page);
}
$property = to_array($property);
/* Текстовая информация для указания номера страницы, например "страница" */
if (isset($GLOBALS['LA']['page']))
{
$property['page'] = to_str($GLOBALS['LA']['page']);
}
else
{
$property['page'] = 'страница';
}
/* Разделитель в заголовке страницы */
if (isset($GLOBALS['LA']['separator']))
{
$property['separator'] = to_str($GLOBALS['LA']['separator']);
}
else
{
$property['separator'] = ' / ';
}
$GLOBALS['InformationResult'] = array();
// Если указание на страницу - не прерываем определение
if (ereg ("^part-([0-9]*)$", end($GLOBALS['URL_ARRAY']), $regs) && to_int($regs[1]) > 0)
{
/* Страница умножается на кол-во элементов, выводимых на страницу */
$break_if_path_not_found = false;
$GLOBALS['part_ii'] = $regs[1];
}
else
{
$break_if_path_not_found = true;
$GLOBALS['part_ii'] = 1;
}
/* получаем для пути ассоциативный массив с id группы и id/url элемента для данной инфосистемы */
$GLOBALS['INFSYS_result'] = $GLOBALS['LA_InformationSystem']->GetInformationFromPath($InformationSystem_id, '', $break_if_path_not_found);
/* Если путь существует */
if ($GLOBALS['INFSYS_result'])
{
$template_id = 0;
$template_property_id = 111;
$group_id = $GLOBALS['INFSYS_result']['group'];
while (!$template_id) {
$row = $InformationSystem->GetPropertysGroup($group_id, $InformationSystem_id);
if (sizeof($row))
foreach ($row as $key => $property_row)
if ($property_row['information_propertys_groups_id'] == $template_property_id) {
$template_id = $property_row['information_propertys_groups_value_value'];
break;
}
if ($template_id)
break;
else {
$row2 = $InformationSystem->GetInformationGroup($group_id);
if ($row2)
$group_id = $row2['information_groups_parent_id'];
else
break;
}
}
if ($template_id)
$kernel->set_current_page_data_template($template_id);
/* получаем массив с деревом от текущей группы до корня */
$GLOBALS['LA_InformationSystem']->GetInformationGroupsForXml($GLOBALS['INFSYS_result']['group'], $InformationSystem_id);
$group_path='';
$mas_information_groups_for_xml=$GLOBALS['LA_InformationSystem']->get_mas_information_groups_for_xml();
/* получаем данные о группе */
$group_result=$GLOBALS['LA_InformationSystem']->SelectInformationGroups($GLOBALS['INFSYS_result']['group'], $InformationSystem_id);
$row_group=mysql_fetch_assoc($group_result);
/* получаем данные из seo - полей для групп */
$seo_title = trim($row_group['information_groups_seo_title']);
$seo_description = trim($row_group['information_groups_seo_description']);
$seo_keywords = trim($row_group['information_groups_seo_keywords']);
/* цикл по массиву с деревом для формирования пути по группам */
for($i = count($mas_information_groups_for_xml)-1; $i >= 0; $i--)
{
/* seo_title для группы пустое, то в заголовок подставляем название */
if (trim($mas_information_groups_for_xml[$i]['information_groups_seo_title'])=='')
{
$group_path.=$property['separator'].$mas_information_groups_for_xml[$i]['information_groups_name'];
}
else
{
$group_path.=$property['separator'].$mas_information_groups_for_xml[$i]['information_groups_seo_title'];
}
}
/* определяем название информационной системы */
$row = $GLOBALS['LA_InformationSystem']->GetInformationSystem($InformationSystem_id);
/* имя информационной системы */
$InformationSystem_name = $row['information_systems_name'];
/* Если вывод информационного элемента */
if ($GLOBALS['INFSYS_result']['item'])
{
/* определяем id информационного элемента */
$item_id = $GLOBALS['LA_InformationSystem']->GetIdInformationItem($GLOBALS['INFSYS_result']['item'], $GLOBALS['INFSYS_result']['group'], $InformationSystem_id);
$GLOBALS['InformationResult']['item_id'] = $item_id;
/* получаем данные об элементе */
$row_item = $GLOBALS['LA_InformationSystem']->GetInformationSystemItem($item_id);
if (class_exists('SiteUsers'))
{
$SiteUsers = & singleton('SiteUsers');
$site_user_id = $SiteUsers->GetCurrentSiteUser();
}
else
{
$site_user_id = 0;
}
if ($GLOBALS['LA_InformationSystem']->GetAccessItem($site_user_id, $row_item['information_items_id'], $row_item))
{
/* проверяем если seo_title непустой, то в заголовок страницы подставляем его */
if (trim($row_item['information_items_seo_title']) != '')
{
$item_name = $property['separator'].trim($row_item['information_items_seo_title']);
}
else
{
/* имя элемента */
$item_name = $property['separator'].$row_item['information_items_name'];
}
}
}
else
{
/* Вывод информационной группы */
/* Определяем номер страницы для показа */
$end_array_item = end($GLOBALS['URL_ARRAY']);
$page = to_str($end_array_item);
if (ereg ("^page-([0-9]*)$", $page, $regs) && to_int($regs[1]) > 0)
{
/* Страница умножается на кол-во элементов, выводимых на страницу */
$items_begin = ($regs[1] - 1) * $items_on_page;
/* Если показываем группу, а не элемент, то указываем страницу (страница N), если она не первая */
$page_number = "{$property['separator']}{$property['page']} {$regs[1]}";
}
else
{
$items_begin = 0;
}
/* Массив, возвращаемый методом */
$GLOBALS['InformationResult']['items_begin'] = $items_begin;
}
if (isset($GLOBALS['INFSYS_result']['tag_name']))
{
$tag_name = "Метка: {$GLOBALS['INFSYS_result']['tag_name']} {$property['separator']}";
}
/* формируем заголовок страницы */
$new_title = to_str($tag_name) . $InformationSystem_name . $group_path . to_str($item_name) . to_str($page_number);
}
else
{
// Элемент/группа не найдены, возвращаем 404 ошибку.
ShowHeader404();
if (to_str($_SERVER['REQUEST_URI']) != '/')
{
header('Location: /');
}
// Прекращаем выполнение
exit();
}
if (!empty($new_title))
{
/* отображаем группу, если не существует данных об элементе и родительская группа не является корнем */
if (!isset($row_item) && $GLOBALS['INFSYS_result']['group'] != 0 || !empty($tag_name) || !empty($page_number))
{
/* Заголовок для группы задан */
if (!empty($seo_title))
{
$kernel->set_title($seo_title);
}
else
{
$kernel->set_title($new_title);
}
/* Описание для группы задано */
if (!empty($seo_description))
{
$kernel->set_description($seo_description);
}
else
{
$kernel->set_description($new_title);
}
/* Ключевые слова для группы заданы */
if (!empty($seo_keywords))
{
$kernel->set_keywords($seo_keywords);
}
else
{
$kernel->set_keywords($new_title);
}
}
elseif (isset($row_item)) /* отображаем элемент */
{
if (!empty($row_item['information_items_seo_description']))
{
$kernel->set_title(trim($row_item['information_items_seo_title']));
}
else
{
$kernel->set_title($new_title);
}
/* Описание для элемента задано */
if (!empty($row_item['information_items_seo_description']))
{
$kernel->set_description(trim($row_item['information_items_seo_description']));
}
else
{
$kernel->set_description($new_title);
}
/* Ключевые слова для элемента заданы */
if (!empty($row_item['information_items_seo_keywords']))
{
$kernel->set_keywords(trim($row_item['information_items_seo_keywords']));
}
else
{
$kernel->set_keywords($new_title);
}
}
}
$GLOBALS['InformationResult']['items_on_page'] = $items_on_page;
?>