AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2563 lines
66 KiB

8 years ago
<?php
/**
7 years ago
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
8 years ago
*
*/
7 years ago
/**
* Класс работы с рубриками
*/
class AVE_Rubric
8 years ago
{
7 years ago
/**
* Количество рубрик на странице
*
* @public int
*/
public $_limit = 30;
8 years ago
7 years ago
function get_rubric_fields_group($rubric_id)
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
ORDER BY
group_position ASC
");
8 years ago
7 years ago
$groups = array();
8 years ago
7 years ago
while($row = $sql->FetchRow())
{
array_push($groups, $row);
}
8 years ago
7 years ago
return $groups;
8 years ago
}
7 years ago
/**
* Вывод списка рубрик
*
*/
function rubricList()
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubrics = array();
$num = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_rubrics")->GetCell();
8 years ago
7 years ago
$page_limit = $this->_limit;
$pages = ceil($num / $page_limit);
$set_start = get_current_page() * $page_limit - $page_limit;
if ($num > $page_limit)
{
$page_nav = " <a class=\"pnav\" href=\"index.php?do=rubs&page={s}&cp=" . SESSION . "\">{t}</a> ";
$page_nav = get_pagination($pages, 'page', $page_nav);
$AVE_Template->assign('page_nav', $page_nav);
}
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
rub.*,
7 years ago
(SELECT 1 FROM " . PREFIX . "_documents WHERE rubric_id = rub.Id LIMIT 1) AS doc_count,
7 years ago
(SELECT count(*) FROM " . PREFIX . "_rubric_fields AS fld WHERE fld.rubric_id = rub.Id) AS fld_count,
(SELECT count(*) FROM " . PREFIX . "_rubric_templates AS tmpls WHERE tmpls.rubric_id = rub.Id) AS tmpls_count
FROM
" . PREFIX . "_rubrics AS rub
GROUP BY rub.Id
ORDER BY rub.rubric_position
LIMIT " . $set_start . "," . $page_limit
);
8 years ago
7 years ago
while ($row = $sql->FetchRow())
array_push($rubrics, $row);
8 years ago
7 years ago
$AVE_Template->assign('rubrics', $rubrics);
}
/**
* создание рубрики
*
*/
function rubricNew()
{
global $AVE_DB, $AVE_Template;
switch ($_REQUEST['sub'])
{
case '':
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/rubnew.tpl'));
break;
case 'save':
$errors = array();
8 years ago
7 years ago
if (empty($_POST['rubric_title']))
8 years ago
{
7 years ago
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_NO_NAME'));
8 years ago
}
else
{
7 years ago
$name_exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
rubric_title = '" . $_POST['rubric_title'] . "'
7 years ago
LIMIT 1
")->NumRows();
8 years ago
7 years ago
if ($name_exist) array_push($errors, $AVE_Template->get_config_vars('RUBRIK_NAME_EXIST'));
8 years ago
7 years ago
if (! empty($_POST['rubric_alias']))
7 years ago
{
if (preg_match(TRANSLIT_URL ? '/[^\%HYa-z0-9\/_-]+/' : '/[^\%HYa-zа-яА-Яёїєі0-9\/_-]+/u', $_POST['rubric_alias']))
{
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_PREFIX_BAD_CHAR'));
}
else
{
$prefix_exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
rubric_alias = '" . $_POST['rubric_alias'] . "'
7 years ago
LIMIT 1
")->NumRows();
if ($prefix_exist) array_push($errors, $AVE_Template->get_config_vars('RUBRIK_PREFIX_EXIST'));
}
}
if (!empty($errors))
{
$AVE_Template->assign('errors', $errors);
$AVE_Template->assign('templates', get_all_templates());
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/rubnew.tpl'));
}
else
8 years ago
{
7 years ago
$position = (int)$AVE_DB->Query("
7 years ago
SELECT
MAX(rubric_position)
FROM
" . PREFIX . "_rubrics
7 years ago
")->GetCell() + 1;
8 years ago
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubrics
8 years ago
SET
7 years ago
rubric_title = '" . $_POST['rubric_title'] . "',
rubric_alias = '" . $_POST['rubric_alias'] . "',
rubric_template_id = '" . intval($_POST['rubric_template_id']) . "',
rubric_author_id = '" . $_SESSION['user_id'] . "',
rubric_created = '" . time() . "',
7 years ago
rubric_position = '" . $position . "',
rubric_changed = '" . time() . "',
rubric_changed_fields = '" . time() . "'
8 years ago
");
7 years ago
$iid = $AVE_DB->InsertId();
// Выставляем всем право на просмотр рубрики, админу - все права
$sql_user = $AVE_DB->Query("
SELECT
grp.*,
COUNT(usr.Id) AS UserCount
FROM
" . PREFIX . "_user_groups AS grp
LEFT JOIN
" . PREFIX . "_users AS usr
ON usr.user_group = grp.user_group
GROUP BY grp.user_group
");
while ($row = $sql_user->FetchRow())
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_permissions
7 years ago
SET
rubric_id = '" . $iid . "',
user_group_id = '" . $row->user_group . "',
rubric_permission = '". (($row->user_group == 1) ? "alles|docread|new|newnow|editown|editall|delrev" : "docread")."'
");
}
// Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('RUBRIK_LOG_NEW_RUBRIC') . ' - ' . stripslashes(htmlspecialchars($_POST['rubric_title'], ENT_QUOTES)) . ' (id: '.$iid.')');
8 years ago
7 years ago
header('Location:index.php?do=rubs&action=edit&Id=' . $iid . '&cp=' . SESSION);
exit;
}
8 years ago
}
7 years ago
break;
}
8 years ago
}
7 years ago
7 years ago
/**
* Запись настроек рубрики
*
*/
function quickSave()
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
if (check_permission_acp('rubric_edit'))
8 years ago
{
7 years ago
foreach ($_POST['rubric_title'] as $rubric_id => $rubric_title)
8 years ago
{
7 years ago
if (! empty($rubric_title))
8 years ago
{
7 years ago
$set_rubric_title = '';
$set_rubric_alias = '';
8 years ago
7 years ago
$name_exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
7 years ago
WHERE
rubric_title = '" . $rubric_title . "'
AND
Id != '" . $rubric_id . "'
LIMIT 1
")->NumRows();
if (!$name_exist)
8 years ago
{
7 years ago
$set_rubric_title = "rubric_title = '" . $rubric_title . "',";
}
if (isset($_POST['rubric_alias'][$rubric_id]) && $_POST['rubric_alias'][$rubric_id] != '')
{
$pattern = TRANSLIT_URL ? '/[^\%HYa-z0-9\/_-]+/' : '/[^\%HYa-zа-яА-Яёїєі0-9\/_-]+/u';
7 years ago
if (! (preg_match($pattern, $_POST['rubric_alias'][$rubric_id])))
8 years ago
{
7 years ago
$prefix_exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
7 years ago
WHERE
rubric_alias = '" . $_POST['rubric_alias'][$rubric_id] . "'
AND
Id != '" . $rubric_id . "'
LIMIT 1
")->NumRows();
7 years ago
if (! $prefix_exist)
7 years ago
{
$set_rubric_alias = "rubric_alias = '" . trim(preg_replace($pattern, '', $_POST['rubric_alias'][$rubric_id]), '/') . "',";
}
8 years ago
}
}
7 years ago
else
{
$set_rubric_alias = "rubric_alias = '',";
}
8 years ago
7 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
7 years ago
SET
" . $set_rubric_title . "
" . $set_rubric_alias . "
rubric_meta_gen = '" . (isset($_POST['rubric_meta_gen'][$rubric_id]) ? $_POST['rubric_meta_gen'][$rubric_id] : '0') . "',
rubric_alias_history = '" . (isset($_POST['rubric_alias_history'][$rubric_id]) ? $_POST['rubric_alias_history'][$rubric_id] : '0') . "',
rubric_template_id = '" . (int)$_POST['rubric_template_id'][$rubric_id] . "',
7 years ago
rubric_docs_active = '" . (isset($_POST['rubric_docs_active'][$rubric_id]) ? $_POST['rubric_docs_active'][$rubric_id] : '0') . "',
rubric_changed = '".time()."',
rubric_changed_fields = '".time()."'
7 years ago
WHERE
Id = '" . $rubric_id . "'
");
}
8 years ago
}
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_REP_QUICKSAVE_T');
$header = $AVE_Template->get_config_vars('RUBRIK_REP_QUICKSAVE_H');
$theme = 'accept';
8 years ago
7 years ago
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_QUICKSAVE'));
8 years ago
7 years ago
if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] = 'run')
{
7 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
7 years ago
}
else
{
7 years ago
$page = !empty($_REQUEST['page']) ? '&page=' . $_REQUEST['page'] : '' ;
header('Location:index.php?do=rubs' . $page . '&cp=' . SESSION);
}
7 years ago
exit;
8 years ago
}
}
7 years ago
7 years ago
/**
* Копирование рубрики
*
*/
function rubricCopy()
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubric_id = (int)$_REQUEST['Id'];
8 years ago
7 years ago
$errors = array();
if (empty($_REQUEST['rubric_title']))
8 years ago
{
7 years ago
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_NO_NAME'));
8 years ago
}
else
{
7 years ago
$name_exist = $AVE_DB->Query("
8 years ago
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
rubric_title = '" . $_POST['rubric_title'] . "'
8 years ago
LIMIT 1
")->NumRows();
7 years ago
if ($name_exist)
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_NAME_EXIST'));
8 years ago
}
7 years ago
if (! empty($_POST['rubric_alias']))
7 years ago
{
if (preg_match(TRANSLIT_URL ? '/[^\%HYa-z0-9\/-]+/' : '/[^\%HYa-zа-яёїєі0-9\/_-]+/', $_POST['rubric_alias']))
{
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_PREFIX_BAD_CHAR'));
}
else
{
$prefix_exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
rubric_alias = '" . $_POST['rubric_alias'] . "'
7 years ago
LIMIT 1
")->NumRows();
8 years ago
7 years ago
if ($prefix_exist)
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_PREFIX_EXIST'));
7 years ago
}
}
8 years ago
7 years ago
$row = $AVE_DB->Query("
SELECT *
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $rubric_id . "'
7 years ago
")->FetchRow();
8 years ago
7 years ago
if (! $row)
array_push($errors, $AVE_Template->get_config_vars('RUBRIK_NO_RUBRIK'));
7 years ago
7 years ago
if (! empty($errors))
8 years ago
{
7 years ago
$AVE_Template->assign('errors', $errors);
8 years ago
}
7 years ago
else
8 years ago
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubrics
8 years ago
SET
7 years ago
rubric_title = '" . $_POST['rubric_title'] . "',
rubric_alias = '" . $_POST['rubric_alias'] . "',
rubric_template = '" . addslashes($row->rubric_template) . "',
rubric_template_id = '" . addslashes($row->rubric_template_id) . "',
rubric_author_id = '" . (int)$_SESSION['user_id'] . "',
rubric_created = '" . time() . "',
rubric_teaser_template = '" . addslashes($row->rubric_teaser_template) . "',
rubric_header_template = '" . addslashes($row->rubric_header_template) . "',
rubric_footer_template = '" . addslashes($row->rubric_footer_template) . "',
rubric_admin_teaser_template = '" . addslashes($row->rubric_admin_teaser_template) . "',
rubric_changed = '" . time() . "',
rubric_changed_fields = '" . time() . "'
8 years ago
");
7 years ago
7 years ago
$iid = $AVE_DB->InsertId();
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
user_group_id,
rubric_permission
7 years ago
FROM
" . PREFIX . "_rubric_permissions
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
");
7 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_permissions
7 years ago
SET
rubric_id = '" . $iid . "',
user_group_id = '" . (int)$row->user_group_id . "',
rubric_permission = '" . addslashes($row->rubric_permission) . "'
");
}
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
rubric_field_title,
rubric_field_alias,
rubric_field_type,
rubric_field_position,
rubric_field_default,
rubric_field_template,
rubric_field_template_request,
rubric_field_description
7 years ago
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
ORDER BY rubric_field_position ASC
");
7 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_fields
7 years ago
SET
rubric_id = '" . $iid . "',
rubric_field_title = '" . addslashes($row->rubric_field_title) . "',
rubric_field_alias = '" . addslashes($row->rubric_field_alias) . "',
rubric_field_type = '" . addslashes($row->rubric_field_type) . "',
rubric_field_position = '" . (int)$row->rubric_field_position . "',
rubric_field_default = '" . addslashes($row->rubric_field_default) . "',
rubric_field_template = '" . addslashes($row->rubric_field_template) . "',
rubric_field_template_request = '" . addslashes($row->rubric_field_template_request) . "',
rubric_field_description = '" . addslashes($row->rubric_field_description) . "'
");
}
8 years ago
7 years ago
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_COPY') . ' - ' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)) . ' (id: '.$rubric_id.')');
8 years ago
7 years ago
echo '<script>window.opener.location.reload();window.close();</script>';
}
8 years ago
}
7 years ago
7 years ago
/**
* Удаление рубрики
*
*/
function rubricDelete()
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubric_id = (int)$_REQUEST['Id'];
8 years ago
7 years ago
if ($rubric_id <= 1)
{
header('Location:index.php?do=rubs&cp=' . SESSION);
exit;
}
8 years ago
7 years ago
$rubric_not_empty = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_documents
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
LIMIT 1
")->GetCell();
8 years ago
7 years ago
if (!$rubric_not_empty)
{
$AVE_DB->Query("
7 years ago
DELETE FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $rubric_id . "'
7 years ago
");
7 years ago
7 years ago
$AVE_DB->Query("
7 years ago
DELETE FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
");
7 years ago
7 years ago
$AVE_DB->Query("
7 years ago
DELETE FROM
" . PREFIX . "_rubric_permissions
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
");
7 years ago
$AVE_DB->Query("
DELETE FROM
" . PREFIX . "_rubric_templates
WHERE
rubric_id = '" . $rubric_id . "'
");
// Удалить КЕШ
$AVE_DB->clearCache('rub_' . $rubric_id);
// Удалить файлы шаблонов
$this->clearTemplates($rubric_id);
7 years ago
// Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('RUBRIK_LOG_DEL_RUBRIC') . ' - ' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)) . ' (id: '.$rubric_id.')');
}
8 years ago
7 years ago
header('Location:index.php?do=rubs&cp=' . SESSION);
exit;
}
7 years ago
7 years ago
/**
* Вывод списка полей рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricFieldShow($rubric_id = 0, $ajax)
{
global $AVE_DB, $AVE_Template;
7 years ago
if (check_permission_acp('rubric_edit'))
8 years ago
{
7 years ago
// Поля
$sql = $AVE_DB->Query("
SELECT
7 years ago
a.*,
b.group_title,
b.group_description,
b.group_position
7 years ago
FROM
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubric_fields_group AS b
ON a.rubric_field_group = b.Id
WHERE
a.rubric_id = '" . $rubric_id . "'
ORDER BY
b.group_position ASC, a.rubric_field_position ASC
");
8 years ago
7 years ago
$fields_list = array();
8 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$group_id = ($row->rubric_field_group) ? $row->rubric_field_group : 0;
$fields_list[$group_id]['group_position'] = ($row->group_position) ? $row->group_position : 100;
$fields_list[$group_id]['group_title'] = $row->group_title;
$fields_list[$group_id]['group_description'] = $row->group_description;
$fields_list[$group_id]['fields'][$row->Id]['Id'] = $row->Id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_id'] = $row->rubric_id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_group'] = $row->rubric_field_group;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_alias'] = $row->rubric_field_alias;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_title'] = $row->rubric_field_title;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_type'] = $row->rubric_field_type;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_numeric'] = $row->rubric_field_numeric;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_default'] = $row->rubric_field_default;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_search'] = $row->rubric_field_search;
}
8 years ago
7 years ago
$fields_list = msort($fields_list, 'group_position');
8 years ago
7 years ago
$AVE_Template->assign('groups_count', count($fields_list));
$AVE_Template->assign('fields_list', $fields_list);
8 years ago
7 years ago
// Группы полей
$fields_groups = array();
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT *
7 years ago
FROM
" . PREFIX . "_rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
ORDER BY
group_position ASC
7 years ago
");
8 years ago
7 years ago
while ($row = $sql->FetchRow())
array_push($fields_groups, $row);
8 years ago
7 years ago
$AVE_Template->assign('fields_groups', $fields_groups);
8 years ago
7 years ago
// Права
$groups = array();
8 years ago
7 years ago
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_user_groups");
8 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$row->doall = ($row->user_group == 1) ? ' disabled="disabled" checked="checked"' : '';
$row->doall_h = ($row->user_group == 1) ? 1 : '';
8 years ago
7 years ago
$rubric_permission = $AVE_DB->Query("
7 years ago
SELECT
rubric_permission
FROM
" . PREFIX . "_rubric_permissions
WHERE
user_group_id = '" . $row->user_group . "'
AND
rubric_id = '" . $rubric_id . "'
7 years ago
")->GetCell();
8 years ago
7 years ago
$row->permissions = @explode('|', $rubric_permission);
8 years ago
7 years ago
array_push($groups,$row);
}
8 years ago
7 years ago
$sql = $AVE_DB->Query("
7 years ago
SELECT
rubric_title,
rubric_linked_rubric,
rubric_description
FROM
" . PREFIX . "_rubrics
WHERE
id = '" . $rubric_id . "'
7 years ago
LIMIT 1
");
8 years ago
7 years ago
$rubrik = $sql->FetchRow();
8 years ago
7 years ago
$rubrik->rubric_linked_rubric = ($rubrik->rubric_linked_rubric != '0')
? unserialize($rubrik->rubric_linked_rubric)
: array();
8 years ago
7 years ago
$AVE_Template->assign('rubric', $rubrik);
$AVE_Template->assign('groups', $groups);
$AVE_Template->assign('fields', get_field_type());
$AVE_Template->assign('rubs', $this->rubricShow());
if (isAjax())
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/fields.tpl'));
else
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/fields_list.tpl'));
8 years ago
}
else
{
7 years ago
header('Location:index.php?do=rubs&cp=' . SESSION);
exit;
8 years ago
}
}
7 years ago
/**
* Вывод списка полей рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricRulesShow($rubric_id = 0)
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
if (check_permission_acp('rubric_edit'))
{
// Права
$groups = array();
7 years ago
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_user_groups
");
7 years ago
while ($row = $sql->FetchRow())
{
$row->doall = ($row->user_group == 1) ? ' disabled="disabled" checked="checked"' : '';
$row->doall_h = ($row->user_group == 1) ? 1 : '';
$rubric_permission = $AVE_DB->Query("
7 years ago
SELECT
rubric_permission
FROM
" . PREFIX . "_rubric_permissions
WHERE
user_group_id = '" . $row->user_group . "'
AND
rubric_id = '" . $rubric_id . "'
7 years ago
")->GetCell();
$row->permissions = @explode('|', $rubric_permission);
array_push($groups,$row);
}
$sql = $AVE_DB->Query("
7 years ago
SELECT
rubric_title,
rubric_linked_rubric,
rubric_description
FROM
" . PREFIX . "_rubrics
WHERE
id = '" . $rubric_id . "'
7 years ago
LIMIT 1
");
$rubric = $sql->FetchRow();
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign('groups', $groups);
if (isAjax())
{
}
else
{
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/rules.tpl'));
}
}
else
8 years ago
{
7 years ago
header('Location:index.php?do=rubs&cp=' . SESSION);
exit;
8 years ago
}
}
7 years ago
/**
* Вывод списка рубрик
*
* @param int $rubric_id идентификатор текущей рубрики
*/
function rubricShow($RubLink=null)
8 years ago
{
7 years ago
global $AVE_DB;
8 years ago
7 years ago
if ($RubLink !== null)
{
7 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
7 years ago
SET
rubric_linked_rubric = '" . serialize($_REQUEST['rubric_linked']) . "'
WHERE
Id = '" . (int)$_REQUEST['Id'] . "'
");
7 years ago
7 years ago
header('Location:index.php?do=rubs&action=edit&Id=' . (int)$_REQUEST['Id'] . '&cp=' . SESSION);
exit;
8 years ago
}
else
{
7 years ago
$rubs = array();
7 years ago
7 years ago
$sql = $AVE_DB->Query("
7 years ago
SELECT
rubric_title,
Id
FROM
" . PREFIX . "_rubrics
ORDER BY
rubric_position ASC
7 years ago
");
while ($row = $sql->FetchRow())
7 years ago
array_push($rubs, $row);
7 years ago
return $rubs;
8 years ago
}
7 years ago
}
8 years ago
7 years ago
/**
* Создание нового поля рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricFieldNew($rubric_id = 0, $ajax)
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
if (! empty($_POST['title_new']))
7 years ago
{
$position = (int)$AVE_DB->Query("
7 years ago
SELECT
MAX(rubric_field_position)
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
")->GetCell() + 1;
8 years ago
7 years ago
if ($_POST['rub_type_new'] == 'dropdown')
{
$rubric_field_default = trim($_POST['default_value']);
$rubric_field_default = preg_split('/\s*,\s*/', $rubric_field_default);
$rubric_field_default = implode(',', $rubric_field_default);
}
else
{
$rubric_field_default = $_POST['default_value'];
}
8 years ago
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_fields
8 years ago
SET
7 years ago
rubric_id = '" . $rubric_id . "',
rubric_field_group = '" . (($_POST['group_new'] != '') ? (int)$_POST['group_new'] : '0') . "',
rubric_field_title = '" . $_POST['title_new'] . "',
rubric_field_type = '" . $_POST['rub_type_new'] . "',
rubric_field_position = '" . $position . "',
rubric_field_default = '" . $rubric_field_default . "',
rubric_field_numeric = '" . (($_POST['rubric_field_numeric'] == 1) ? $_POST['rubric_field_numeric'] : '0') . "',
rubric_field_search = '" . (($_POST['rubric_field_search'] == 1) ? $_POST['rubric_field_search'] : '0') . "'
8 years ago
");
7 years ago
$UpdateRubricField = $AVE_DB->InsertId();
$sql = $AVE_DB->Query("
7 years ago
SELECT
Id
FROM
" . PREFIX . "_documents
WHERE
rubric_id = '" . $rubric_id . "'
7 years ago
");
while ($row = $sql->FetchRow())
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_document_fields
7 years ago
SET
rubric_field_id = '" . $UpdateRubricField . "',
document_id = '" . $row->Id . "'
");
}
7 years ago
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . $rubric_id . "'
");
7 years ago
// Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('RUBRIK_LOG_NEW_FIELD').' (' . stripslashes(htmlspecialchars($_POST['title_new'], ENT_QUOTES)) . ') '. stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)). ' (id: '.$rubric_id.')');
7 years ago
}
else
{
if (! isAjax())
{
7 years ago
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
7 years ago
}
else
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_EMPTY_MESSAGE');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'error';
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
8 years ago
exit;
7 years ago
}
8 years ago
7 years ago
if (! isAjax())
{
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
}
else
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_FILD_SAVED');
8 years ago
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
7 years ago
$theme = 'accept';
8 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
7 years ago
exit;
8 years ago
}
7 years ago
/**
* Редактирование кода для рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricCodeEdit($rubric_id = 0)
{
global $AVE_DB, $AVE_Template;
switch ($_REQUEST['sub']) {
case '':
$code = $AVE_DB->Query("
SELECT
rubric_code_start,
rubric_code_end,
rubric_start_code
FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $rubric_id . "'
")->FetchRow();
$AVE_Template->assign('code', $code);
$AVE_Template->assign('rubric_title', $this->rubricNameByIdGet($rubric_id)->rubric_title);
$AVE_Template->assign('formaction', 'index.php?do=rubs&action=code&sub=save&Id=' . $rubric_id . '&cp=' . SESSION);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/code.tpl'));
break;
case 'save':
$sql = $AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
7 years ago
rubric_start_code = '" . $_POST['rubric_start_code'] . "',
rubric_code_start = '" . $_POST['rubric_code_start'] . "',
rubric_code_end = '" . $_POST['rubric_code_end'] . "',
rubric_changed = '" . time() . "'
7 years ago
WHERE
Id = '" . $rubric_id . "'
");
8 years ago
7 years ago
// Очищаем кэш рубрики
$AVE_DB->clearCache('rub_' . $rubric_id);
8 years ago
7 years ago
if ($sql->_result === false)
{
$message = $AVE_Template->get_config_vars('RUBRIK_CODE_SAVED_ERR');
$header = $AVE_Template->get_config_vars('RUBRIK_CODE_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('RUBRIK_CODE_SAVED');
$header = $AVE_Template->get_config_vars('RUBRIK_CODE_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIK_CODE_UPDATE') . " (" . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)) . ") (id: $rubric_id)");
}
8 years ago
7 years ago
if (isAjax())
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
else
header('Location:index.php?do=rubs&action=code&Id=' . $rubric_id . '&cp=' . SESSION);
7 years ago
7 years ago
exit;
}
}
8 years ago
7 years ago
/**
* Редактирование кода для рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricCode($rubric_id = 0)
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$sql = $AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
7 years ago
rubric_start_code = '" . $_POST['rubric_start_code'] . "',
rubric_code_start = '" . $_POST['rubric_code_start'] . "',
rubric_code_end = '" . $_POST['rubric_code_end'] . "',
rubric_changed = '" . time() . "'
7 years ago
WHERE
Id = '" . $rubric_id . "'
");
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
if ($sql->_result === false)
{
$message = $AVE_Template->get_config_vars('RUBRIK_CODE_SAVED_ERR');
$header = $AVE_Template->get_config_vars('RUBRIK_CODE_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('RUBRIK_CODE_SAVED');
$header = $AVE_Template->get_config_vars('RUBRIK_CODE_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIK_CODE_UPDATE') . " (" . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)) . ") (id: $rubric_id)");
}
if (isAjax())
{
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
else
{
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
}
exit;
}
/**
* Редактирование описания рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricDesc($rubric_id = 0)
{
global $AVE_DB;
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
7 years ago
SET
7 years ago
rubric_description = '" . $_POST['rubric_description'] . "'
7 years ago
WHERE
Id = '" . $rubric_id . "'
");
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
exit;
}
/**
* Управление полями рубрики
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricFieldSave($rubric_id = 0)
{
global $AVE_DB, $AVE_Template;
foreach ($_POST['title'] as $id => $title)
{
7 years ago
if (! empty($title))
7 years ago
{
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
7 years ago
SET
7 years ago
rubric_field_title = '" . $title . "',
rubric_field_numeric = '" . $_POST['rubric_field_numeric'][$id] . "',
rubric_field_search = '" . $_POST['rubric_field_search'][$id] . "'
7 years ago
WHERE
Id = '" . $id . "'
");
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_FIELD_EDIT') . ' (' . stripslashes($title) . ') '.$AVE_Template->get_config_vars('RUBRIK_REPORT_RUB').' (' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ') (Id:' . $rubric_id . ')');
}
}
foreach ($_POST['del'] as $id => $Del)
{
7 years ago
if (! empty($Del))
7 years ago
{
$AVE_DB->Query("
7 years ago
DELETE FROM
" . PREFIX . "_rubric_fields
WHERE
Id = '" . $id . "'
AND
rubric_id = '" . $rubric_id . "'
7 years ago
");
7 years ago
7 years ago
$AVE_DB->Query("
7 years ago
DELETE FROM
" . PREFIX . "_document_fields
WHERE
rubric_field_id = '" . $id . "'
7 years ago
");
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_FIELD_DEL') . ' (' . stripslashes($_POST['title'][$id]) . ') '.$AVE_Template->get_config_vars('RUBRIK_REPORT_RUB').' (' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ') (Id:' . $rubric_id . ')');
}
}
7 years ago
// Очищаем кэш шаблона документов рубрики
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed = '" . time() . "',
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . $rubric_id . "'
");
7 years ago
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_FILDS_SAVED');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIK_FILDS_REPORT') . ' (' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ') (Id:' . $rubric_id . ')');
7 years ago
if (isAjax())
7 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
7 years ago
else
{
7 years ago
$AVE_Template->assign('message', $message);
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
}
7 years ago
7 years ago
exit;
}
/**
* Сортировка полей рубрики
*
* @param array $sorted последовательность id полей
*/
function rubricFieldsSort()
{
global $AVE_DB, $AVE_Template;
foreach ($_REQUEST['sort'] as $position => $field_id)
{
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
7 years ago
SET
rubric_field_position = '" . (int)$position . "'
WHERE
Id = '" . (int)$field_id . "'
");
}
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_SORTE_FIELDS'));
7 years ago
if (isAjax())
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_SORTED');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'accept';
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
}
/**
* Сортировка рубрик
*
* @param array $sorted последовательность id полей
*/
function rubricsSort()
{
global $AVE_DB, $AVE_Template;
foreach ($_REQUEST['sort'] as $position => $rub_id)
{
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
8 years ago
SET
7 years ago
rubric_position = '" . (int)$position . "'
8 years ago
WHERE
7 years ago
Id = '" . (int)$rub_id . "'
8 years ago
");
7 years ago
}
8 years ago
7 years ago
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_SORTE'));
7 years ago
if (isAjax())
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIK_SORTED');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'accept';
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
}
/**
* Вывод шаблона рубрики
*
* @param int $show
* @param int $extern
*/
function rubricTemplateShow($show = '', $extern = '0')
{
global $AVE_DB, $AVE_Template;
if ($extern == 1)
$fetchId = (isset($_REQUEST['rubric_id']) && is_numeric($_REQUEST['rubric_id'])) ? $_REQUEST['rubric_id'] : 0;
else
$fetchId = (isset($_REQUEST['Id']) && is_numeric($_REQUEST['Id'])) ? $_REQUEST['Id'] : 0;
$rubric = $AVE_DB->Query("
SELECT
rubric_title,
rubric_template,
rubric_header_template,
rubric_footer_template,
rubric_teaser_template,
rubric_admin_teaser_template,
rubric_description
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $fetchId . "'
")->FetchRow();
7 years ago
// Поля
$sql = $AVE_DB->Query("
SELECT
7 years ago
a.*,
b.group_title,
b.group_description,
b.group_position
7 years ago
FROM
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubric_fields_group AS b
ON a.rubric_field_group = b.Id
WHERE
a.rubric_id = '" . $fetchId . "'
ORDER BY
b.group_position ASC, a.rubric_field_position ASC
");
$fields_list = array();
$drop_down_fields = array();
while ($row = $sql->FetchRow())
{
$group_id = ($row->rubric_field_group) ? $row->rubric_field_group : 0;
if ($row->rubric_field_type == 'drop_down' || $row->rubric_field_type == 'drop_down_key')
array_push($drop_down_fields, $row->Id);
$fields_list[$group_id]['group_position'] = ($row->group_position) ? $row->group_position : 100;
$fields_list[$group_id]['group_title'] = $row->group_title;
$fields_list[$group_id]['group_description'] = $row->group_description;
$fields_list[$group_id]['fields'][$row->Id]['Id'] = $row->Id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_id'] = $row->rubric_id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_group'] = $row->rubric_field_group;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_alias'] = $row->rubric_field_alias;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_title'] = $row->rubric_field_title;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_type'] = $row->rubric_field_type;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_numeric'] = $row->rubric_field_numeric;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_default'] = $row->rubric_field_default;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_search'] = $row->rubric_field_search;
}
$fields_list = msort($fields_list, 'group_position');
$AVE_Template->assign('groups_count', count($fields_list));
$AVE_Template->assign('fields_list', $fields_list);
$AVE_Template->assign('field_array', get_field_type());
if ($show == 1 )
$rubric->rubric_template = stripslashes($_POST['rubric_template']);
if ($extern == 1)
{
$AVE_Template->assign('ddid', implode(',', $drop_down_fields));
}
else
{
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign('formaction', 'index.php?do=rubs&action=template&sub=save&Id=' . $fetchId . '&cp=' . SESSION);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/form.tpl'));
}
}
/**
* Редактирование шаблона рубрики
*
* @param string $data
*/
function rubricTemplateSave($Rtemplate, $Htemplate = '', $Ttemplate = '', $Atemplate = '', $Ftemplate = '')
{
global $AVE_DB, $AVE_Template;
$rubric_id = (int)$_REQUEST['Id'];
$sql = $AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
7 years ago
rubric_template = '" . ($Rtemplate) . "',
rubric_header_template = '" . $Htemplate . "',
rubric_footer_template = '" . $Ftemplate . "',
rubric_teaser_template = '" . $Ttemplate . "',
rubric_admin_teaser_template = '" . $Atemplate . "',
rubric_changed = '" . time() . "'
7 years ago
WHERE
Id = '" . $rubric_id . "'
");
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
if ($sql === false)
{
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_TPL_ERR');
$header = $AVE_Template->get_config_vars('RUBRIK_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_TPL');
$header = $AVE_Template->get_config_vars('RUBRIC_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_TEMPL_RUB') . ' (' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ') (Id:' . $rubric_id . ')');
}
if (isAjax())
{
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
else
{
$AVE_Template->assign('message', $message);
header('Location:index.php?do=rubs&cp=' . SESSION);
}
7 years ago
exit;
7 years ago
}
/**
* Управление правами доступа к документам рубрик
*
* @param int $rubric_id идентификатор рубрики
*/
function rubricPermissionSave($rubric_id = 0)
{
global $AVE_DB, $AVE_Template;
if (check_permission_acp('rubric_perms') && is_numeric($rubric_id) && $rubric_id > 0)
{
foreach ($_POST['user_group'] as $key => $user_group_id)
{
$exist = $AVE_DB->Query("
SELECT 1
7 years ago
FROM
" . PREFIX . "_rubric_permissions
WHERE
user_group_id = '" . $user_group_id . "'
AND
rubric_id = '" . $rubric_id . "'
7 years ago
LIMIT 1
")->NumRows();
$rubric_permission = @implode('|', $_POST['perm'][$key]);
7 years ago
7 years ago
if ($exist)
{
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_permissions
SET
rubric_permission = '" . $rubric_permission . "'
WHERE
user_group_id = '" . $user_group_id . "'
AND
rubric_id = '" . $rubric_id . "'
7 years ago
");
}
else
{
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_permissions
7 years ago
SET
rubric_id = '" . $rubric_id . "',
user_group_id = '" . $user_group_id . "',
rubric_permission = '" . $rubric_permission . "'
");
}
8 years ago
}
7 years ago
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed = '" . time() . "'
WHERE
7 years ago
Id = '" . $rubric_id . "'
7 years ago
");
$AVE_DB->clearCache('rub_' . $rubric_id);
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_PERMS');
$header = $AVE_Template->get_config_vars('RUBRIC_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIK_REPORT_PERMISION') . ' (' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ') (Id:' . $rubric_id . ')');
if (isAjax())
8 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
7 years ago
else
7 years ago
header('Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION);
7 years ago
exit;
7 years ago
}
8 years ago
}
7 years ago
/**
* Получить наименование и URL-префикс Рубрики по идентификатору
*
* @param int $rubric_id идентификатор Рубрики
* @return object наименование Рубрики
*/
function rubricNameByIdGet($rubric_id = 0)
{
global $AVE_DB;
8 years ago
7 years ago
static $rubrics = array();
7 years ago
if (! isset($rubrics[$rubric_id]))
7 years ago
{
$rubrics[$rubric_id] = $AVE_DB->Query("
SELECT
rubric_title,
rubric_alias,
rubric_description
7 years ago
FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $rubric_id . "'
7 years ago
LIMIT 1
")->FetchRow();
}
return $rubrics[$rubric_id];
8 years ago
}
7 years ago
/**
* Формирование прав доступа Групп пользователей на все Рубрики
*
*/
function rubricPermissionFetch()
{
global $AVE_DB, $AVE_Document, $AVE_Template;
$items = array();
$sql = $AVE_DB->Query("
SELECT
Id,
rubric_title,
rubric_docs_active
FROM
" . PREFIX . "_rubrics
ORDER
BY rubric_position
");
while ($row = $sql->FetchRow())
{
$AVE_Document->documentPermissionFetch($row->Id);
if (defined('UGROUP') && UGROUP == 1) $row->Show = 1;
elseif (isset($_SESSION[$row->Id . '_editown']) && $_SESSION[$row->Id . '_editown'] == 1) $row->Show = 1;
elseif (isset($_SESSION[$row->Id . '_editall']) && $_SESSION[$row->Id . '_editall'] == 1) $row->Show = 1;
elseif (isset($_SESSION[$row->Id . '_new']) && $_SESSION[$row->Id . '_new'] == 1) $row->Show = 1;
elseif (isset($_SESSION[$row->Id . '_newnow']) && $_SESSION[$row->Id . '_newnow'] == 1) $row->Show = 1;
elseif (isset($_SESSION[$row->Id . '_alles']) && $_SESSION[$row->Id . '_alles'] == 1) $row->Show = 1;
array_push($items, $row);
}
$AVE_Template->assign('rubrics', $items);
8 years ago
}
7 years ago
/**
* Получить
*/
function rubricAliasAdd()
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
a.rubric_title,
b.rubric_field_title,
b.rubric_field_alias
FROM
" . PREFIX . "_rubrics AS a
JOIN
" . PREFIX . "_rubric_fields AS b
WHERE
a.Id = '" . $_REQUEST['rubric_id'] . "'
AND
b.Id = '" . $_REQUEST['field_id'] . "'
")->FetchAssocArray();
$AVE_Template->assign($sql);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/alias.tpl'));
}
8 years ago
7 years ago
7 years ago
function rubricAliasCheck($rubric_id, $field_id, $value)
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
7 years ago
7 years ago
$errors = array();
7 years ago
7 years ago
if (! intval($rubric_id)>0)
7 years ago
$errors[] = $AVE_Template->get_config_vars('RUBRIK_ALIAS_RUBID');
7 years ago
if (! intval($field_id)>0)
7 years ago
$errors[] = $AVE_Template->get_config_vars('RUBRIK_ALIAS_FIELDID');
7 years ago
if (! preg_match('/^[A-Za-z][[:word:]]{0,19}$/', $value))
7 years ago
$errors[] = $AVE_Template->get_config_vars('RUBRIK_ALIAS_MATCH');
//Проверяем есть такой алиас уже
$res = $AVE_DB->Query("
7 years ago
SELECT
COUNT(*)
7 years ago
FROM
" . PREFIX . "_rubric_fields
WHERE
Id <> " . intval($field_id) . "
AND rubric_id = " . intval($rubric_id) . "
AND rubric_field_alias = '" . addslashes($value) . "'
")->GetCell();
7 years ago
if ($res > 0)
7 years ago
$errors[] = $AVE_Template->get_config_vars('RUBRIK_ALIAS_MATCH');
if (empty($errors))
8 years ago
{
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
8 years ago
SET
7 years ago
rubric_field_alias = '" . addslashes($value) . "'
8 years ago
WHERE
7 years ago
Id = '" . intval($field_id) . "'
7 years ago
AND
rubric_id = '" . intval($rubric_id) . "'
8 years ago
");
7 years ago
7 years ago
$AVE_Template->assign('success', true);
}
else
{
$AVE_Template->assign('errors', $errors);
}
8 years ago
7 years ago
$sql = $AVE_DB->Query("
7 years ago
SELECT
a.rubric_title,
b.rubric_field_title,
b.rubric_field_alias
FROM
" . PREFIX . "_rubrics AS a
JOIN
" . PREFIX . "_rubric_fields AS b
WHERE
a.Id = '" . $_REQUEST['rubric_id'] . "'
AND
b.Id = '" . $_REQUEST['field_id'] . "'
")->FetchAssocArray();
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
");
7 years ago
$AVE_Template->assign($sql);
7 years ago
7 years ago
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/alias.tpl'));
}
7 years ago
function rubricFieldTemplate()
{
7 years ago
global $AVE_DB, $AVE_Template;
$field = $AVE_DB->Query("
7 years ago
SELECT
a.rubric_title,
b.rubric_field_default,
b.rubric_field_title,
b.rubric_field_template,
b.rubric_field_template_request,
b.rubric_field_description
FROM
" . PREFIX . "_rubrics AS a
JOIN
" . PREFIX . "_rubric_fields AS b
WHERE
a.Id = '" . $_REQUEST['rubric_id'] . "'
AND
b.Id = '" . $_REQUEST['field_id'] . "'
")->FetchAssocArray();
7 years ago
$AVE_Template->assign($field);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/field_template.tpl'));
}
7 years ago
function rubricFieldTemplateSave($id, $rubric_id)
{
7 years ago
global $AVE_DB, $AVE_Template;
$sql = $AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
7 years ago
SET
rubric_field_default = '" . $_POST['rubric_field_default'] . "',
rubric_field_template = '" . $_POST['rubric_field_template'] . "',
rubric_field_template_request = '" . $_POST['rubric_field_template_request'] . "',
rubric_field_description = '" . $_POST['rubric_field_description'] . "'
WHERE
Id = '" . $id . "'
");
7 years ago
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
");
$AVE_DB->clearCache('rub_' . $rubric_id);
if ($sql === false)
7 years ago
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_FLDTPL_ERR');
$header = $AVE_Template->get_config_vars('RUBRIK_ERROR');
$theme = 'error';
7 years ago
if (isAjax() && ! $_REQUEST['save'])
7 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
7 years ago
else
7 years ago
$this->rubricFieldTemplate();
7 years ago
exit;
7 years ago
}
else
{
7 years ago
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_FLDTPL');
$header = $AVE_Template->get_config_vars('RUBRIC_SUCCESS');
$theme = 'accept';
7 years ago
if (isAjax())
{
7 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
exit;
}
8 years ago
}
}
7 years ago
7 years ago
function rubricFieldChange($field_id, $rubric_id)
{
global $AVE_DB, $AVE_Template;
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
")->FetchAssocArray();
$AVE_Template->assign('rf', $sql);
$AVE_Template->assign('fields', get_field_type());
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/change.tpl'));
}
7 years ago
7 years ago
function rubricFieldChangeSave($field_id, $rubric_id)
{
global $AVE_DB, $AVE_Template;
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
7 years ago
SET
7 years ago
rubric_field_type = '" . trim($_POST['rubric_field_type']) . "'
7 years ago
WHERE
Id = '" . $field_id . "'
AND
rubric_id = '" . $rubric_id . "'
");
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
")->FetchAssocArray();
8 years ago
7 years ago
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
");
7 years ago
$AVE_Template->assign('rf', $sql);
$AVE_Template->assign('fields', get_field_type());
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/change.tpl'));
}
8 years ago
7 years ago
function rubricFieldsGroups($rubric_id)
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
ORDER BY
group_position
");
$groups = array();
7 years ago
while ($row = $sql->FetchRow())
7 years ago
array_push($groups, $row);
$AVE_Template->assign('rubric', $this->rubricNameByIdGet($rubric_id));
$AVE_Template->assign('groups', $groups);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/fields_groups.tpl'));
8 years ago
}
7 years ago
/**
* Сортировка групп полей рубрики
*
* @param array $sorted последовательность id полей
*/
function rubricFieldsGroupsSort()
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
foreach ($_REQUEST['sort'] as $position => $group_id)
{
$position++;
7 years ago
7 years ago
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubric_fields_group
SET
group_position = '" . (int)$position . "'
WHERE
Id = '" . (int)$group_id . "'
");
}
8 years ago
7 years ago
if (isAjax())
{
$message = $AVE_Template->get_config_vars('RUBRIK_SORTED');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'accept';
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
7 years ago
exit;
7 years ago
}
8 years ago
}
7 years ago
function rubricNewGroupFields($rubric_id)
{
global $AVE_DB;
$position = $AVE_DB->Query("
SELECT
MAX(group_position)
FROM
" . PREFIX . "_rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
")->GetCell();
$position++;
8 years ago
$AVE_DB->Query("
7 years ago
INSERT
" . PREFIX . "_rubric_fields_group
8 years ago
SET
7 years ago
rubric_id = '" . $rubric_id . "',
group_position = '" . $position . "',
group_title= '" . $_REQUEST['group_title'] . "'
8 years ago
");
7 years ago
header('Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION);
exit;
8 years ago
}
7 years ago
function rubricEditGroupFields($rubric_id)
{
global $AVE_DB;
foreach($_REQUEST['group_title'] as $k => $v)
{
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubric_fields_group
SET
group_title= '" . $v . "'
WHERE
Id = '" . $k . "'
");
}
8 years ago
7 years ago
header('Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION);
exit;
8 years ago
}
7 years ago
7 years ago
function rubricDelGroupFields($Id, $rubric_id)
{
global $AVE_DB;
8 years ago
7 years ago
$AVE_DB->Query("
DELETE FROM
" . PREFIX . "_rubric_fields_group
WHERE
Id = '" . $Id . "'
");
8 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
8 years ago
SET
7 years ago
rubric_field_group = '0'
8 years ago
WHERE
7 years ago
rubric_field_group = '" . $Id . "'
AND
rubric_id = '" . $rubric_id . "'
8 years ago
");
7 years ago
header('Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION);
exit;
}
8 years ago
7 years ago
function rubricFieldGroupChange($field_id, $rubric_id)
{
8 years ago
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
")->FetchAssocArray();
8 years ago
7 years ago
$AVE_Template->assign('rf', $sql);
$AVE_Template->assign('groups', $this->get_rubric_fields_group($rubric_id));
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/groups.tpl'));
8 years ago
}
7 years ago
7 years ago
function rubricFieldGroupChangeSave($field_id, $rubric_id)
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubric_fields
7 years ago
SET
7 years ago
rubric_field_group = '" . trim($_POST['rubric_field_group']) . "'
7 years ago
WHERE
Id = '" . $field_id . "'
AND
rubric_id = '" . $rubric_id . "'
");
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
")->FetchAssocArray();
8 years ago
7 years ago
$AVE_Template->assign('rf', $sql);
$AVE_Template->assign('groups', $this->get_rubric_fields_group($rubric_id));
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/groups.tpl'));
8 years ago
}
7 years ago
7 years ago
// Список дополнительных шаблон для данной рубрики
function tmplsList()
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$templates = array();
8 years ago
7 years ago
$num = $AVE_DB->Query("
SELECT
COUNT(*)
FROM
" . PREFIX . "_rubric_templates
WHERE
rubric_id = '" . $_REQUEST['Id'] . "'
")->GetCell();
8 years ago
7 years ago
$page_limit = $this->_limit;
8 years ago
7 years ago
$pages = ceil($num / $page_limit);
8 years ago
7 years ago
$set_start = get_current_page() * $page_limit - $page_limit;
8 years ago
7 years ago
if ($num > $page_limit)
8 years ago
{
7 years ago
$page_nav = " <a class=\"pnav\" href=\"index.php?do=rubs&action=tmpls&page={s}&cp=" . SESSION . "\">{t}</a> ";
$page_nav = get_pagination($pages, 'page', $page_nav);
$AVE_Template->assign('page_nav', $page_nav);
8 years ago
}
7 years ago
$sql = $AVE_DB->Query("
SELECT
rub.*,
rubrics.rubric_title,
7 years ago
(SELECT 1 FROM " . PREFIX . "_documents WHERE rubric_id = rub.rubric_id AND rubric_tmpl_id = rub.id LIMIT 1) AS doc_count
7 years ago
FROM
" . PREFIX . "_rubric_templates AS rub
LEFT JOIN
" . PREFIX . "_rubrics AS rubrics
ON rubrics.Id = rub.rubric_id
WHERE
rub.rubric_id = '" . (int)$_REQUEST['Id'] . "'
GROUP
BY rub.id
ORDER
BY rub.id
LIMIT
" . $set_start . "," . $page_limit
);
8 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$row->author_id = get_username_by_id($row->author_id);
array_push($templates, $row);
}
8 years ago
7 years ago
$rubric = $this->rubricNameByIdGet((int)$_REQUEST['Id']);
8 years ago
7 years ago
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign('templates', $templates);
8 years ago
}
7 years ago
/**
* Вывод шаблона рубрики
*
* @param int $show
* @param int $extern
*/
function tmplsEdit()
8 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$tmpls_id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? $_REQUEST['id'] : 0;
$rubric_id = (int)$_REQUEST['rubric_id'];
8 years ago
7 years ago
if ($tmpls_id)
{
$template = $AVE_DB->Query("
SELECT
title,
template
FROM
" . PREFIX . "_rubric_templates
WHERE
id = '" . $tmpls_id . "'
")
->FetchRow();
}
8 years ago
7 years ago
if ($_REQUEST['action'] == 'tmpls_from')
{
$template = $AVE_DB->Query("
SELECT
rubric_title as title,
rubric_template as template
FROM
" . PREFIX . "_rubrics
WHERE
Id = '" . $rubric_id . "'
")
->FetchRow();
}
8 years ago
7 years ago
if ($_REQUEST['action'] == 'tmpls_copy')
{
$template = $AVE_DB->Query("
SELECT
title,
template
FROM
" . PREFIX . "_rubric_templates
WHERE
id = '" . $_REQUEST['tmpls_id'] . "'
")
->FetchRow();
}
8 years ago
7 years ago
// Поля
8 years ago
$sql = $AVE_DB->Query("
SELECT
7 years ago
a.*,
b.group_title,
b.group_description,
b.group_position
8 years ago
FROM
7 years ago
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubric_fields_group AS b
ON a.rubric_field_group = b.Id
8 years ago
WHERE
7 years ago
a.rubric_id = '" . $rubric_id . "'
ORDER BY
b.group_position ASC, a.rubric_field_position ASC
");
8 years ago
7 years ago
$fields_list = array();
$drop_down_fields = array();
8 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$group_id = ($row->rubric_field_group) ? $row->rubric_field_group : 0;
8 years ago
7 years ago
if ($row->rubric_field_type == 'drop_down' || $row->rubric_field_type == 'drop_down_key')
array_push($drop_down_fields, $row->Id);
8 years ago
7 years ago
$fields_list[$group_id]['group_position'] = ($row->group_position) ? $row->group_position : 100;
$fields_list[$group_id]['group_title'] = $row->group_title;
$fields_list[$group_id]['group_description'] = $row->group_description;
$fields_list[$group_id]['fields'][$row->Id]['Id'] = $row->Id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_id'] = $row->rubric_id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_group'] = $row->rubric_field_group;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_alias'] = $row->rubric_field_alias;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_title'] = $row->rubric_field_title;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_type'] = $row->rubric_field_type;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_numeric'] = $row->rubric_field_numeric;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_default'] = $row->rubric_field_default;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_search'] = $row->rubric_field_search;
}
8 years ago
7 years ago
$fields_list = msort($fields_list, 'group_position');
8 years ago
7 years ago
$AVE_Template->assign('groups_count', count($fields_list));
$AVE_Template->assign('fields_list', $fields_list);
8 years ago
7 years ago
$AVE_Template->assign('field_array', get_field_type());
8 years ago
7 years ago
$rubric = $this->rubricNameByIdGet($rubric_id);
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign('template', $template);
$AVE_Template->assign('formaction', 'index.php?do=rubs&action=tmpls_edit&sub=save&id=' . $tmpls_id . '&rubric_id=' . $_REQUEST['rubric_id'] . '&cp=' . SESSION);
$AVE_Template->assign('content', $AVE_Template->fetch('rubs/tmpls_form.tpl'));
8 years ago
}
7 years ago
/**
* Редактирование шаблона рубрики
*
* @param string $data
*/
function tmplsSave($template = '', $title = '')
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$tmpls_id = (int)$_REQUEST['id'];
$rubric_id = (int)$_REQUEST['rubric_id'];
8 years ago
7 years ago
if ($tmpls_id)
{
$sql = $AVE_DB->Query("
UPDATE
" . PREFIX . "_rubric_templates
SET
title = '" . $title . "',
template = '" . $template . "'
WHERE
id = '" . $tmpls_id . "'
");
}
else
{
$sql = $AVE_DB->Query("
INSERT INTO
" . PREFIX . "_rubric_templates
SET
title = '" . $title . "',
template = '" . $template . "',
rubric_id = '" . $rubric_id . "',
author_id = '" . UID . "',
created = '" . time() . "'
");
8 years ago
7 years ago
$tmpls_id = $AVE_DB->InsertId();
}
8 years ago
7 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed = '" . time() . "'
7 years ago
WHERE
7 years ago
Id = '" . intval($rubric_id) . "'
7 years ago
");
8 years ago
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
if ($sql === false)
{
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_TPL_ERR');
$header = $AVE_Template->get_config_vars('RUBRIK_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('RUBRIC_SAVED_TPL');
$header = $AVE_Template->get_config_vars('RUBRIC_SUCCESS');
$theme = 'accept';
reportLog($AVE_Template->get_config_vars('RUBRIC_TEMPL_REPORT') . ' ' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title)) . ' (Id шаблона:' . $tmpls_id . ')');
8 years ago
}
7 years ago
if (isAjax())
{
8 years ago
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
7 years ago
else
{
$AVE_Template->assign('message', $message);
header('Location:index.php?do=rubs&action=tmpls&Id='.$rubric_id.'&cp=' . SESSION);
}
7 years ago
exit;
8 years ago
}
7 years ago
function tmplsDelete()
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubric_id = (int)$_REQUEST['rubric_id'];
$tmpls_id = (int)$_REQUEST['tmpls_id'];
8 years ago
7 years ago
$rubric_not_empty = $AVE_DB->Query("
SELECT 1
FROM " . PREFIX . "_documents
WHERE
rubric_id = '" . $rubric_id . "'
AND
rubric_tmpl_id = '" . $tmpls_id . "'
LIMIT 1
")->GetCell();
8 years ago
7 years ago
if (! $rubric_not_empty)
{
$AVE_DB->Query("
DELETE
FROM
" . PREFIX . "_rubric_templates
WHERE
id = '" . $tmpls_id . "'
AND
rubric_id = '" . $rubric_id . "'
");
8 years ago
7 years ago
$AVE_DB->Query("
7 years ago
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed = '" . time() . "'
7 years ago
WHERE
7 years ago
Id = '" . intval($rubric_id) . "'
7 years ago
");
8 years ago
7 years ago
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
// Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('RUBRIC_TMPLS_LOG_DEL') . ' - ' . stripslashes(htmlspecialchars($this->rubricNameByIdGet($rubric_id)->rubric_title, ENT_QUOTES)) . ' (Id шаблона: '.$rubric_id.')');
}
8 years ago
7 years ago
header('Location:index.php?do=rubs&action=tmpls&Id='.$rubric_id.'&cp=' . SESSION);
exit;
8 years ago
}
7 years ago
function _get_fields_type($type = null)
8 years ago
{
7 years ago
static $fields;
8 years ago
7 years ago
if (is_array($fields))
return $fields;
8 years ago
7 years ago
$arr = get_defined_functions();
8 years ago
7 years ago
$fields = array();
$field = array();
8 years ago
7 years ago
foreach ($arr['user'] as $v)
{
if (trim(substr($v, 0, strlen('get_field_'))) == 'get_field_')
{
$d = '';
8 years ago
7 years ago
$name = @$v('', 'name', '', '', 0, $d);
8 years ago
7 years ago
$id = substr($v, strlen('get_field_'));
8 years ago
7 years ago
if ($name != false && is_string($name))
$fields[] = array('id' => $id,'name' => (isset($fields_vars[$name])
? $fields_vars[$name]
: $name));
8 years ago
7 years ago
if (! empty($type) && $id == $type)
$field = array('id' => $id,'name' => (isset($fields_vars[$name])
? $fields_vars[$name]
: $name));
}
}
8 years ago
7 years ago
$fields = msort($fields, array('name'));
8 years ago
7 years ago
return (! empty($type)) ? $field : $fields;
}
8 years ago
7 years ago
function ShowFields()
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubric_id = (int)$_REQUEST['Id'];
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
rubric_field_type
FROM
" . PREFIX . "_rubric_fields
WHERE
rubric_id = '".$rubric_id."'
GROUP BY
rubric_field_type
");
8 years ago
7 years ago
$enable = array();
8 years ago
7 years ago
while ($row = $sql->FetchArray())
$enable[] = $row['rubric_field_type'];
8 years ago
7 years ago
$fields = $this->_get_fields_type();
8 years ago
7 years ago
foreach ($fields as $field)
{
$exists[$field['id']]['adm'] = file_exists(BASE_DIR . '/fields/' . $field['id'] . '/tpl/field.tpl');
$exists[$field['id']]['doc'] = file_exists(BASE_DIR . '/fields/' . $field['id'] . '/tpl/field-doc.tpl');
$exists[$field['id']]['req'] = file_exists(BASE_DIR . '/fields/' . $field['id'] . '/tpl/field-req.tpl');
}
8 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
rubric_title,
rubric_linked_rubric,
rubric_description
FROM
" . PREFIX . "_rubrics
WHERE
id = '" . $rubric_id . "'
LIMIT 1
");
8 years ago
7 years ago
$rubric = $sql->FetchRow();
8 years ago
7 years ago
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign("enable", $enable);
$AVE_Template->assign("exists", $exists);
$AVE_Template->assign("fields", $fields);
$AVE_Template->assign("content", $AVE_Template->fetch('rubs/_fields_list.tpl'));
8 years ago
}
7 years ago
function ShowFieldsByType($fld)
{
global $AVE_DB, $AVE_Template;
8 years ago
7 years ago
$rubric_id = (int)$_REQUEST['rubric_id'];
8 years ago
7 years ago
$sql = $AVE_DB->Query("
8 years ago
SELECT
7 years ago
a.Id,
a.rubric_id,
a.rubric_field_type,
a.rubric_field_title,
b.rubric_title
8 years ago
FROM
7 years ago
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubrics AS b
ON a.rubric_id = b.Id
8 years ago
WHERE
7 years ago
a.rubric_field_type = '" . $fld ."'
AND
a.rubric_id = '".$rubric_id."'
ORDER BY
a.rubric_id
");
8 years ago
7 years ago
$rubrics = array();
while ($row = $sql->FetchRow())
{
$rubrics[$row->rubric_id]['rubric_id'] = $row->rubric_id;
$rubrics[$row->rubric_id]['rubric_title'] = $row->rubric_title;
$rubrics[$row->rubric_id]['rubric_field_type'] = $row->rubric_field_type;
$rubrics[$row->rubric_id]['fields'][$row->Id]['id'] = $row->Id;
$rubrics[$row->rubric_id]['fields'][$row->Id]['title'] = $row->rubric_field_title;
$rubrics[$row->rubric_id]['fields'][$row->Id]['adm_tpl'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $row->Id . '.tpl');
$rubrics[$row->rubric_id]['fields'][$row->Id]['doc_tpl'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $row->Id . '.tpl');
$rubrics[$row->rubric_id]['fields'][$row->Id]['req_tpl'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $row->Id . '.tpl');
$rubrics[$row->rubric_id]['fields'][$row->Id]['adm_main'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field.tpl');
$rubrics[$row->rubric_id]['fields'][$row->Id]['doc_main'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field-doc.tpl');
$rubrics[$row->rubric_id]['fields'][$row->Id]['req_main'] = file_exists(BASE_DIR . '/fields/' . $fld . '/tpl/field-req.tpl');
}
$sql = $AVE_DB->Query("
8 years ago
SELECT
7 years ago
rubric_title,
rubric_linked_rubric,
rubric_description
8 years ago
FROM
" . PREFIX . "_rubrics
WHERE
7 years ago
id = '" . $rubric_id . "'
LIMIT 1
");
8 years ago
7 years ago
$rubric = $sql->FetchRow();
8 years ago
7 years ago
$AVE_Template->assign('rubric', $rubric);
$AVE_Template->assign('main', $this->_get_fields_type($fld));
$AVE_Template->assign("rubrics", $rubrics);
$AVE_Template->assign("content", $AVE_Template->fetch('rubs/_field_list.tpl'));
8 years ago
}
7 years ago
function EditFieldTpl($id = '', $fld, $type)
{
global $AVE_DB, $AVE_Template, $_fm_dir;
8 years ago
7 years ago
switch ($type)
{
case 'adm':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $id . '.tpl';
$source = BASE_DIR . '/fields/' . $fld . '/tpl/field.tpl';
break;
case 'doc':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $id . '.tpl';
$source = BASE_DIR . '/fields/' . $fld . '/tpl/field-doc.tpl';
break;
case 'req':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $id . '.tpl';
$source = BASE_DIR . '/fields/' . $fld . '/tpl/field-req.tpl';
break;
}
8 years ago
7 years ago
if (empty($id))
$file = $source;
8 years ago
7 years ago
if (file_exists($file))
$code_text = file_get_contents($file);
else
$code_text = file_get_contents($source);
8 years ago
$sql = $AVE_DB->Query("
7 years ago
SELECT
a.rubric_field_title,
b.rubric_title
FROM
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubrics AS b
ON a.rubric_id = b.Id
8 years ago
WHERE
7 years ago
a.rubric_field_type = '" . $fld ."'
AND
a.Id = '" . $id ."'
")->FetchAssocArray();
8 years ago
7 years ago
$params =
array(
'id' => $id,
'fld' => $fld,
'type' => $type,
'func' => (file_exists($file) ? 'edit' : 'new'),
'field' => $sql,
);
$AVE_Template->assign('main', $this->_get_fields_type($fld));
$AVE_Template->assign('params', $params);
$AVE_Template->assign('code_text', $code_text);
$AVE_Template->assign("content", $AVE_Template->fetch('rubs/_field_code.tpl'));
8 years ago
}
7 years ago
/**
* Сохранение шаблона
*
*/
function SaveFieldTpl($id = '', $fld, $type, $func)
8 years ago
{
7 years ago
global $AVE_DB;
7 years ago
switch ($type)
{
case 'adm':
$file = (! empty($id))
? BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $id . '.tpl'
: BASE_DIR . '/fields/' . $fld . '/tpl/field.tpl';
break;
case 'doc':
$file = (! empty($id))
? BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $id . '.tpl'
: BASE_DIR . '/fields/' . $fld . '/tpl/field-doc.tpl';
break;
case 'req':
$file = (! empty($id))
? BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $id . '.tpl'
: BASE_DIR . '/fields/' . $fld . '/tpl/field-req.tpl';
break;
}
$data = stripcslashes($_REQUEST['code_text']);
@file_put_contents($file, $data);
chmod($file, 0644);
7 years ago
$rubric_id = (int)$_REQUEST['rubric_id'];
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
");
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
$message = 'Шаблон успешнно сохранен';
$header = 'Выполнено';
8 years ago
$theme = 'accept';
7 years ago
echo json_encode(
array(
'message' => $message,
'header' => $header,
'theme' => $theme)
);
8 years ago
exit;
}
7 years ago
/**
* Удаление шаблона поля
*
*/
function DeleteFieldTpl($id, $fld, $type, $func)
{
7 years ago
global $AVE_DB;
7 years ago
switch ($type)
{
case 'adm':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $id . '.tpl';
break;
8 years ago
7 years ago
case 'doc':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $id . '.tpl';
break;
8 years ago
7 years ago
case 'req':
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $id . '.tpl';
break;
}
8 years ago
7 years ago
@unlink($file);
8 years ago
7 years ago
$rubric_id = $AVE_DB->Query("SELECT rubric_id FROM " . PREFIX . "_rubric_fields WHERE Id = '".$id."'")->GetCell();
$AVE_DB->Query("
UPDATE
" . PREFIX . "_rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
");
$AVE_DB->clearCache('rub_' . $rubric_id);
7 years ago
header('Location:' . get_referer_link());
exit;
8 years ago
}
7 years ago
function clearTemplates($rubric_id)
{
}
8 years ago
}
7 years ago
?>