2017-06-24 00:58:56 +03:00
< ? php
/**
2018-03-12 23:35:55 +03:00
* AVE . cms
*
* @ package AVE . cms
* @ version 3. x
* @ filesource
* @ copyright © 2007 - 2014 AVE . cms , http :// www . ave - cms . ru
2017-06-24 00:58:56 +03:00
*
*/
2018-03-12 23:35:55 +03:00
/**
* Класс работы с рубриками
*/
class AVE_Rubric
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
/**
* Количество рубрик на странице
*
* @ public int
*/
public $_limit = 30 ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
function get_rubric_fields_group ( $rubric_id )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
*
FROM
" . PREFIX . " _rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
ORDER BY
group_position ASC
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$groups = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
array_push ( $groups , $row );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
return $groups ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Вывод списка рубрик
*
*/
function rubricList ()
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubrics = array ();
$num = $AVE_DB -> Query ( " SELECT COUNT(*) FROM " . PREFIX . " _rubrics " ) -> GetCell ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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 );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
rub .* ,
2018-05-19 20:30:18 +03:00
( SELECT 1 FROM " . PREFIX . " _documents WHERE rubric_id = rub . Id LIMIT 1 ) AS doc_count ,
2018-03-12 23:35:55 +03:00
( 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
);
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
array_push ( $rubrics , $row );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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 ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( empty ( $_POST [ 'rubric_title' ]))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_NO_NAME' ));
2017-06-24 00:58:56 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$name_exist = $AVE_DB -> Query ( "
SELECT 1
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
rubric_title = '" . $_POST[' rubric_title '] . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" )->NumRows();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $name_exist ) array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_NAME_EXIST' ));
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( ! empty ( $_POST [ 'rubric_alias' ]))
2018-03-12 23:35:55 +03:00
{
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
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
rubric_alias = '" . $_POST[' rubric_alias '] . "'
2018-03-12 23:35:55 +03:00
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
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$position = ( int ) $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
SELECT
MAX ( rubric_position )
FROM
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
" )->GetCell() + 1;
2017-06-24 00:58:56 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubrics
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
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() . "' ,
2018-05-16 23:14:07 +03:00
rubric_position = '" . $position . "' ,
rubric_changed = '" . time() . "' ,
rubric_changed_fields = '" . time() . "'
2017-06-24 00:58:56 +03:00
" );
2018-03-12 23:35:55 +03:00
$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 ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubric_permissions
2018-03-12 23:35:55 +03:00
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 . ')' );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=edit&Id=' . $iid . '&cp=' . SESSION );
exit ;
}
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
break ;
}
2017-06-24 00:58:56 +03:00
}
2018-03-26 10:33:20 +03:00
2018-03-12 23:35:55 +03:00
/**
* Запись настроек рубрики
*
*/
function quickSave ()
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
if ( check_permission_acp ( 'rubric_edit' ))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
foreach ( $_POST [ 'rubric_title' ] as $rubric_id => $rubric_title )
2017-06-24 00:58:56 +03:00
{
2018-05-16 23:14:07 +03:00
if ( ! empty ( $rubric_title ))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$set_rubric_title = '' ;
$set_rubric_alias = '' ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$name_exist = $AVE_DB -> Query ( "
SELECT 1
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
WHERE
rubric_title = '" . $rubric_title . "'
AND
Id != '" . $rubric_id . "'
LIMIT 1
" )->NumRows();
if ( ! $name_exist )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$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' ;
2018-05-16 23:14:07 +03:00
if ( ! ( preg_match ( $pattern , $_POST [ 'rubric_alias' ][ $rubric_id ])))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$prefix_exist = $AVE_DB -> Query ( "
SELECT 1
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
WHERE
rubric_alias = '" . $_POST[' rubric_alias '][$rubric_id] . "'
AND
Id != '" . $rubric_id . "'
LIMIT 1
" )->NumRows();
2018-05-16 23:14:07 +03:00
if ( ! $prefix_exist )
2018-03-12 23:35:55 +03:00
{
$set_rubric_alias = " rubric_alias = ' " . trim ( preg_replace ( $pattern , '' , $_POST [ 'rubric_alias' ][ $rubric_id ]), '/' ) . " ', " ;
}
2017-06-24 00:58:56 +03:00
}
}
2018-03-12 23:35:55 +03:00
else
{
$set_rubric_alias = " rubric_alias = '', " ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
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] . "' ,
2018-05-16 23:14:07 +03:00
rubric_docs_active = '" . (isset($_POST[' rubric_docs_active '][$rubric_id]) ? $_POST[' rubric_docs_active '][$rubric_id] : ' 0 ') . "' ,
rubric_changed = '".time()."' ,
rubric_changed_fields = '".time()."'
2018-03-12 23:35:55 +03:00
WHERE
Id = '" . $rubric_id . "'
" );
}
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$message = $AVE_Template -> get_config_vars ( 'RUBRIK_REP_QUICKSAVE_T' );
$header = $AVE_Template -> get_config_vars ( 'RUBRIK_REP_QUICKSAVE_H' );
$theme = 'accept' ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIK_REPORT_QUICKSAVE' ));
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( isset ( $_REQUEST [ 'ajax' ]) && $_REQUEST [ 'ajax' ] = 'run' )
{
2018-03-12 23:35:55 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
2018-05-16 23:14:07 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$page = ! empty ( $_REQUEST [ 'page' ]) ? '&page=' . $_REQUEST [ 'page' ] : '' ;
header ( 'Location:index.php?do=rubs' . $page . '&cp=' . SESSION );
}
2018-05-16 23:14:07 +03:00
exit ;
2017-06-24 00:58:56 +03:00
}
}
2018-03-26 10:33:20 +03:00
2018-03-12 23:35:55 +03:00
/**
* Копирование рубрики
*
*/
function rubricCopy ()
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_id = ( int ) $_REQUEST [ 'Id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$errors = array ();
if ( empty ( $_REQUEST [ 'rubric_title' ]))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_NO_NAME' ));
2017-06-24 00:58:56 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$name_exist = $AVE_DB -> Query ( "
2017-06-24 00:58:56 +03:00
SELECT 1
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
rubric_title = '" . $_POST[' rubric_title '] . "'
2017-06-24 00:58:56 +03:00
LIMIT 1
" )->NumRows();
2018-05-16 23:14:07 +03:00
if ( $name_exist )
array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_NAME_EXIST' ));
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
if ( ! empty ( $_POST [ 'rubric_alias' ]))
2018-03-12 23:35:55 +03:00
{
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
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
rubric_alias = '" . $_POST[' rubric_alias '] . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" )->NumRows();
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( $prefix_exist )
array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_PREFIX_EXIST' ));
2018-03-12 23:35:55 +03:00
}
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$row = $AVE_DB -> Query ( "
SELECT *
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
Id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" )->FetchRow();
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( ! $row )
array_push ( $errors , $AVE_Template -> get_config_vars ( 'RUBRIK_NO_RUBRIK' ));
2018-03-12 23:35:55 +03:00
2018-05-16 23:14:07 +03:00
if ( ! empty ( $errors ))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'errors' , $errors );
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
else
2017-06-24 00:58:56 +03:00
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubrics
2017-06-24 00:58:56 +03:00
SET
2018-05-16 23:14:07 +03:00
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() . "'
2017-06-24 00:58:56 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$iid = $AVE_DB -> InsertId ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
user_group_id ,
rubric_permission
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubric_permissions
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubric_permissions
2018-03-12 23:35:55 +03:00
SET
rubric_id = '" . $iid . "' ,
user_group_id = '" . (int)$row->user_group_id . "' ,
rubric_permission = '" . addslashes($row->rubric_permission) . "'
" );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
ORDER BY rubric_field_position ASC
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
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) . "'
" );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIK_REPORT_COPY' ) . ' - ' . stripslashes ( htmlspecialchars ( $this -> rubricNameByIdGet ( $rubric_id ) -> rubric_title , ENT_QUOTES )) . ' (id: ' . $rubric_id . ')' );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
echo '<script>window.opener.location.reload();window.close();</script>' ;
}
2017-06-24 00:58:56 +03:00
}
2018-03-26 10:33:20 +03:00
2018-03-12 23:35:55 +03:00
/**
* Удаление рубрики
*
*/
function rubricDelete ()
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_id = ( int ) $_REQUEST [ 'Id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $rubric_id <= 1 )
{
header ( 'Location:index.php?do=rubs&cp=' . SESSION );
exit ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_not_empty = $AVE_DB -> Query ( "
SELECT 1
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _documents
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" )->GetCell();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( ! $rubric_not_empty )
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
DELETE FROM
" . PREFIX . " _rubrics
WHERE
Id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
DELETE FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
DELETE FROM
" . PREFIX . " _rubric_permissions
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
2018-05-16 23:14:07 +03:00
$AVE_DB -> Query ( "
DELETE FROM
" . PREFIX . " _rubric_templates
WHERE
rubric_id = '" . $rubric_id . "'
" );
// Удалить КЕШ
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
// Удалить файлы шаблонов
$this -> clearTemplates ( $rubric_id );
2018-03-12 23:35:55 +03:00
// Сохраняем системное сообщение в журнал
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIK_LOG_DEL_RUBRIC' ) . ' - ' . stripslashes ( htmlspecialchars ( $this -> rubricNameByIdGet ( $rubric_id ) -> rubric_title , ENT_QUOTES )) . ' (id: ' . $rubric_id . ')' );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&cp=' . SESSION );
exit ;
}
2018-03-26 10:33:20 +03:00
2018-03-12 23:35:55 +03:00
/**
* Вывод списка полей рубрики
*
* @ param int $rubric_id идентификатор рубрики
*/
function rubricFieldShow ( $rubric_id = 0 , $ajax )
{
global $AVE_DB , $AVE_Template ;
2018-03-26 10:33:20 +03:00
if ( check_permission_acp ( 'rubric_edit' ))
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
// Поля
$sql = $AVE_DB -> Query ( "
SELECT
2018-03-26 10:33:20 +03:00
a .* ,
b . group_title ,
b . group_description ,
b . group_position
2018-03-12 23:35:55 +03:00
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
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields_list = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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 ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields_list = msort ( $fields_list , 'group_position' );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'groups_count' , count ( $fields_list ));
$AVE_Template -> assign ( 'fields_list' , $fields_list );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
// Группы полей
$fields_groups = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT *
2018-03-26 10:33:20 +03:00
FROM
" . PREFIX . " _rubric_fields_group
WHERE
rubric_id = '" . $rubric_id . "'
ORDER BY
group_position ASC
2018-03-12 23:35:55 +03:00
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
array_push ( $fields_groups , $row );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'fields_groups' , $fields_groups );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
// Права
$groups = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( " SELECT * FROM " . PREFIX . " _user_groups " );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
$row -> doall = ( $row -> user_group == 1 ) ? ' disabled="disabled" checked="checked"' : '' ;
$row -> doall_h = ( $row -> user_group == 1 ) ? 1 : '' ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_permission = $AVE_DB -> Query ( "
2018-03-26 10:33:20 +03:00
SELECT
rubric_permission
FROM
" . PREFIX . " _rubric_permissions
WHERE
user_group_id = '" . $row->user_group . "'
AND
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" )->GetCell();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$row -> permissions = @ explode ( '|' , $rubric_permission );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
array_push ( $groups , $row );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
2018-03-26 10:33:20 +03:00
SELECT
rubric_title ,
rubric_linked_rubric ,
rubric_description
FROM
" . PREFIX . " _rubrics
WHERE
id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubrik = $sql -> FetchRow ();
2017-06-24 00:58:56 +03:00
2018-03-26 10:33:20 +03:00
$rubrik -> rubric_linked_rubric = ( $rubrik -> rubric_linked_rubric != '0' )
? unserialize ( $rubrik -> rubric_linked_rubric )
: array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
}
2018-03-12 23:35:55 +03:00
/**
* Вывод списка полей рубрики
*
* @ param int $rubric_id идентификатор рубрики
*/
function rubricRulesShow ( $rubric_id = 0 )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( check_permission_acp ( 'rubric_edit' ))
{
// Права
$groups = array ();
2018-05-16 23:14:07 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
*
FROM
" . PREFIX . " _user_groups
" );
2018-03-12 23:35:55 +03:00
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 ( "
2018-05-16 23:14:07 +03:00
SELECT
rubric_permission
FROM
" . PREFIX . " _rubric_permissions
WHERE
user_group_id = '" . $row->user_group . "'
AND
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" )->GetCell();
$row -> permissions = @ explode ( '|' , $rubric_permission );
array_push ( $groups , $row );
}
$sql = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
SELECT
rubric_title ,
rubric_linked_rubric ,
rubric_description
FROM
" . PREFIX . " _rubrics
WHERE
id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
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
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
}
2018-03-12 23:35:55 +03:00
/**
* Вывод списка рубрик
*
* @ param int $rubric_id идентификатор текущей рубрики
*/
function rubricShow ( $RubLink = null )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB ;
2017-06-24 00:58:56 +03:00
2018-03-26 10:33:20 +03:00
if ( $RubLink !== null )
{
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-03-26 10:33:20 +03:00
UPDATE
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
SET
rubric_linked_rubric = '" . serialize($_REQUEST[' rubric_linked ']) . "'
WHERE
Id = '" . (int)$_REQUEST[' Id '] . "'
" );
2018-03-26 10:33:20 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=edit&Id=' . ( int ) $_REQUEST [ 'Id' ] . '&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$rubs = array ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
2018-03-26 10:33:20 +03:00
SELECT
rubric_title ,
Id
FROM
" . PREFIX . " _rubrics
ORDER BY
rubric_position ASC
2018-03-12 23:35:55 +03:00
" );
while ( $row = $sql -> FetchRow ())
2018-03-26 10:33:20 +03:00
array_push ( $rubs , $row );
2018-03-12 23:35:55 +03:00
return $rubs ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
/**
* Создание нового поля рубрики
*
* @ param int $rubric_id идентификатор рубрики
*/
function rubricFieldNew ( $rubric_id = 0 , $ajax )
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( ! empty ( $_POST [ 'title_new' ]))
2018-03-12 23:35:55 +03:00
{
$position = ( int ) $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
SELECT
MAX ( rubric_field_position )
FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" )->GetCell() + 1;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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' ];
}
2017-06-24 00:58:56 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubric_fields
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
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 ') . "'
2017-06-24 00:58:56 +03:00
" );
2018-03-12 23:35:55 +03:00
$UpdateRubricField = $AVE_DB -> InsertId ();
$sql = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
SELECT
Id
FROM
" . PREFIX . " _documents
WHERE
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
while ( $row = $sql -> FetchRow ())
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _document_fields
2018-03-12 23:35:55 +03:00
SET
rubric_field_id = '" . $UpdateRubricField . "' ,
document_id = '" . $row->Id . "'
" );
}
2018-05-16 23:14:07 +03:00
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . $rubric_id . "'
" );
2018-03-12 23:35:55 +03:00
// Сохраняем системное сообщение в журнал
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 . ')' );
2018-05-16 23:14:07 +03:00
}
else
{
if ( ! isAjax ())
{
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION );
2018-05-16 23:14:07 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$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 ));
}
2017-06-24 00:58:56 +03:00
exit ;
2018-05-16 23:14:07 +03:00
}
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
if ( ! isAjax ())
{
header ( 'Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION );
}
else
{
2018-03-12 23:35:55 +03:00
$message = $AVE_Template -> get_config_vars ( 'RUBRIK_FILD_SAVED' );
2017-06-24 00:58:56 +03:00
$header = $AVE_Template -> get_config_vars ( 'RUBRIK_FILDS_SUCCESS' );
2018-03-12 23:35:55 +03:00
$theme = 'accept' ;
2017-06-24 00:58:56 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
}
2018-05-16 23:14:07 +03:00
exit ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Редактирование кода для рубрики
*
* @ 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
2018-05-16 23:14:07 +03:00
rubric_start_code = '" . $_POST[' rubric_start_code '] . "' ,
rubric_code_start = '" . $_POST[' rubric_code_start '] . "' ,
rubric_code_end = '" . $_POST[' rubric_code_end '] . "' ,
rubric_changed = '" . time() . "'
2018-03-12 23:35:55 +03:00
WHERE
Id = '" . $rubric_id . "'
" );
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
// Очищаем кэш рубрики
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2017-06-24 00:58:56 +03:00
2020-07-30 16:49:44 +03:00
if ( $sql !== true )
2018-03-12 23:35:55 +03:00
{
$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 ) " );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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 );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
exit ;
}
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
/**
* Редактирование кода для рубрики
*
* @ param int $rubric_id идентификатор рубрики
*/
function rubricCode ( $rubric_id = 0 )
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
2018-05-16 23:14:07 +03:00
rubric_start_code = '" . $_POST[' rubric_start_code '] . "' ,
rubric_code_start = '" . $_POST[' rubric_code_start '] . "' ,
rubric_code_end = '" . $_POST[' rubric_code_end '] . "' ,
rubric_changed = '" . time() . "'
2018-03-12 23:35:55 +03:00
WHERE
Id = '" . $rubric_id . "'
" );
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
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 ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubrics
2018-03-12 23:35:55 +03:00
SET
2018-05-16 23:14:07 +03:00
rubric_description = '" . $_POST[' rubric_description '] . "'
2018-03-12 23:35:55 +03:00
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 )
{
2018-05-16 23:14:07 +03:00
if ( ! empty ( $title ))
2018-03-12 23:35:55 +03:00
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
SET
2018-05-16 23:14:07 +03:00
rubric_field_title = '" . $title . "' ,
rubric_field_numeric = '" . $_POST[' rubric_field_numeric '][$id] . "' ,
rubric_field_search = '" . $_POST[' rubric_field_search '][$id] . "'
2018-03-12 23:35:55 +03:00
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 )
{
2018-05-16 23:14:07 +03:00
if ( ! empty ( $Del ))
2018-03-12 23:35:55 +03:00
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
DELETE FROM
" . PREFIX . " _rubric_fields
WHERE
Id = '" . $id . "'
AND
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
DELETE FROM
" . PREFIX . " _document_fields
WHERE
rubric_field_id = '" . $id . "'
2018-03-12 23:35:55 +03:00
" );
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 . ')' );
}
}
2018-05-16 23:14:07 +03:00
// Очищаем кэш шаблона документов рубрики
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed = '" . time() . "' ,
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . $rubric_id . "'
" );
2018-04-19 19:11:58 +03:00
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-03-12 23:35:55 +03:00
$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 . ')' );
2018-05-16 23:14:07 +03:00
if ( isAjax ())
2018-03-12 23:35:55 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
2018-05-16 23:14:07 +03:00
else
{
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'message' , $message );
header ( 'Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION );
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
exit ;
}
/**
* Сортировка полей рубрики
*
* @ param array $sorted последовательность id полей
*/
function rubricFieldsSort ()
{
global $AVE_DB , $AVE_Template ;
foreach ( $_REQUEST [ 'sort' ] as $position => $field_id )
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
SET
rubric_field_position = '" . (int)$position . "'
WHERE
Id = '" . (int)$field_id . "'
" );
}
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIK_REPORT_SORTE_FIELDS' ));
2018-05-16 23:14:07 +03:00
if ( isAjax ())
{
2018-03-12 23:35:55 +03:00
$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 ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubrics
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
rubric_position = '" . (int)$position . "'
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
Id = '" . (int)$rub_id . "'
2017-06-24 00:58:56 +03:00
" );
2018-03-12 23:35:55 +03:00
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIK_REPORT_SORTE' ));
2018-05-16 23:14:07 +03:00
if ( isAjax ())
{
2018-03-12 23:35:55 +03:00
$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
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
Id = '" . $fetchId . "'
" )->FetchRow();
2018-03-12 23:35:55 +03:00
// Поля
$sql = $AVE_DB -> Query ( "
SELECT
2018-05-16 23:14:07 +03:00
a .* ,
b . group_title ,
b . group_description ,
b . group_position
2018-03-12 23:35:55 +03:00
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
2018-05-16 23:14:07 +03:00
rubric_template = '" . ($Rtemplate) . "' ,
rubric_header_template = '" . $Htemplate . "' ,
rubric_footer_template = '" . $Ftemplate . "' ,
rubric_teaser_template = '" . $Ttemplate . "' ,
rubric_admin_teaser_template = '" . $Atemplate . "' ,
rubric_changed = '" . time() . "'
2018-03-12 23:35:55 +03:00
WHERE
Id = '" . $rubric_id . "'
" );
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-03-12 23:35:55 +03:00
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 );
}
2018-05-16 23:14:07 +03:00
exit ;
2018-03-12 23:35:55 +03:00
}
/**
* Управление правами доступа к документам рубрик
*
* @ 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
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubric_permissions
WHERE
user_group_id = '" . $user_group_id . "'
AND
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" )->NumRows();
$rubric_permission = @ implode ( '|' , $_POST [ 'perm' ][ $key ]);
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
if ( $exist )
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_permissions
SET
rubric_permission = '" . $rubric_permission . "'
WHERE
user_group_id = '" . $user_group_id . "'
AND
rubric_id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
" );
}
else
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
INSERT
" . PREFIX . " _rubric_permissions
2018-03-12 23:35:55 +03:00
SET
rubric_id = '" . $rubric_id . "' ,
user_group_id = '" . $user_group_id . "' ,
rubric_permission = '" . $rubric_permission . "'
" );
}
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed = '" . time() . "'
WHERE
2018-05-19 09:15:15 +03:00
Id = '" . $rubric_id . "'
2018-05-16 23:14:07 +03:00
" );
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
$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 ())
2017-06-24 00:58:56 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
2018-05-16 23:14:07 +03:00
else
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=edit&Id=' . $rubric_id . '&cp=' . SESSION );
2018-05-16 23:14:07 +03:00
exit ;
2018-03-12 23:35:55 +03:00
}
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Получить наименование и URL - префикс Рубрики по идентификатору
*
* @ param int $rubric_id идентификатор Рубрики
* @ return object наименование Рубрики
*/
function rubricNameByIdGet ( $rubric_id = 0 )
{
global $AVE_DB ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
static $rubrics = array ();
2018-05-16 23:14:07 +03:00
if ( ! isset ( $rubrics [ $rubric_id ]))
2018-03-12 23:35:55 +03:00
{
$rubrics [ $rubric_id ] = $AVE_DB -> Query ( "
SELECT
rubric_title ,
rubric_alias ,
rubric_description
2018-05-16 23:14:07 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
Id = '" . $rubric_id . "'
2018-03-12 23:35:55 +03:00
LIMIT 1
" )->FetchRow();
}
return $rubrics [ $rubric_id ];
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Формирование прав доступа Групп пользователей на все Рубрики
*
*/
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 );
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Получить
*/
function rubricAliasAdd ()
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
}
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
function rubricAliasCheck ( $rubric_id , $field_id , $value )
2017-06-24 00:58:56 +03:00
{
2018-05-16 23:14:07 +03:00
global $AVE_DB , $AVE_Template ;
2018-03-12 23:35:55 +03:00
2018-05-16 23:14:07 +03:00
$errors = array ();
2018-03-12 23:35:55 +03:00
2018-05-16 23:14:07 +03:00
if ( ! intval ( $rubric_id ) > 0 )
2018-03-12 23:35:55 +03:00
$errors [] = $AVE_Template -> get_config_vars ( 'RUBRIK_ALIAS_RUBID' );
2018-05-16 23:14:07 +03:00
if ( ! intval ( $field_id ) > 0 )
2018-03-12 23:35:55 +03:00
$errors [] = $AVE_Template -> get_config_vars ( 'RUBRIK_ALIAS_FIELDID' );
2018-05-16 23:14:07 +03:00
if ( ! preg_match ( '/^[A-Za-z][[:word:]]{0,19}$/' , $value ))
2018-03-12 23:35:55 +03:00
$errors [] = $AVE_Template -> get_config_vars ( 'RUBRIK_ALIAS_MATCH' );
//Проверяем есть такой алиас уже
$res = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
SELECT
COUNT ( * )
2018-03-12 23:35:55 +03:00
FROM
" . PREFIX . " _rubric_fields
WHERE
Id <> " . intval( $field_id ) . "
AND rubric_id = " . intval( $rubric_id ) . "
AND rubric_field_alias = '" . addslashes($value) . "'
" )->GetCell();
2018-05-16 23:14:07 +03:00
if ( $res > 0 )
2018-03-12 23:35:55 +03:00
$errors [] = $AVE_Template -> get_config_vars ( 'RUBRIK_ALIAS_MATCH' );
if ( empty ( $errors ))
2017-06-24 00:58:56 +03:00
{
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
rubric_field_alias = '" . addslashes($value) . "'
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
Id = '" . intval($field_id) . "'
2018-05-16 23:14:07 +03:00
AND
rubric_id = '" . intval($rubric_id) . "'
2017-06-24 00:58:56 +03:00
" );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'success' , true );
}
else
{
$AVE_Template -> assign ( 'errors' , $errors );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
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) . "'
" );
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( $sql );
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'content' , $AVE_Template -> fetch ( 'rubs/alias.tpl' ));
}
2018-05-16 23:14:07 +03:00
function rubricFieldTemplate ()
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
$field = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
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();
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( $field );
$AVE_Template -> assign ( 'content' , $AVE_Template -> fetch ( 'rubs/field_template.tpl' ));
}
2018-04-19 19:11:58 +03:00
function rubricFieldTemplateSave ( $id , $rubric_id )
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
$sql = $AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
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 . "'
" );
2018-05-16 23:14:07 +03:00
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
" );
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
if ( $sql === false )
2018-04-19 19:11:58 +03:00
{
2018-03-12 23:35:55 +03:00
$message = $AVE_Template -> get_config_vars ( 'RUBRIC_SAVED_FLDTPL_ERR' );
$header = $AVE_Template -> get_config_vars ( 'RUBRIK_ERROR' );
$theme = 'error' ;
2018-05-16 23:14:07 +03:00
if ( isAjax () && ! $_REQUEST [ 'save' ])
2018-03-12 23:35:55 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
2018-05-16 23:14:07 +03:00
else
2018-03-12 23:35:55 +03:00
$this -> rubricFieldTemplate ();
2018-05-16 23:14:07 +03:00
exit ;
2018-04-19 19:11:58 +03:00
}
else
{
2018-03-12 23:35:55 +03:00
$message = $AVE_Template -> get_config_vars ( 'RUBRIC_SAVED_FLDTPL' );
$header = $AVE_Template -> get_config_vars ( 'RUBRIC_SUCCESS' );
$theme = 'accept' ;
2018-05-16 23:14:07 +03:00
if ( isAjax ())
{
2018-03-12 23:35:55 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
exit ;
}
2017-06-24 00:58:56 +03:00
}
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
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' ));
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
function rubricFieldChangeSave ( $field_id , $rubric_id )
{
global $AVE_DB , $AVE_Template ;
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
SET
2018-05-16 23:14:07 +03:00
rubric_field_type = '" . trim($_POST[' rubric_field_type ']) . "'
2018-03-12 23:35:55 +03:00
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();
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed_fields = '" . time() . "'
WHERE
Id = '" . intval($rubric_id) . "'
" );
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'rf' , $sql );
$AVE_Template -> assign ( 'fields' , get_field_type ());
$AVE_Template -> assign ( 'content' , $AVE_Template -> fetch ( 'rubs/change.tpl' ));
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
function rubricFieldsGroups ( $rubric_id )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
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 ();
2018-05-16 23:14:07 +03:00
while ( $row = $sql -> FetchRow ())
2018-03-12 23:35:55 +03:00
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' ));
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Сортировка групп полей рубрики
*
* @ param array $sorted последовательность id полей
*/
function rubricFieldsGroupsSort ()
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
foreach ( $_REQUEST [ 'sort' ] as $position => $group_id )
{
$position ++ ;
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
UPDATE
" . PREFIX . " _rubric_fields_group
SET
group_position = '" . (int)$position . "'
WHERE
Id = '" . (int)$group_id . "'
" );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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 ));
2018-05-16 23:14:07 +03:00
exit ;
2018-03-12 23:35:55 +03:00
}
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
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 ++ ;
2017-06-24 00:58:56 +03:00
$AVE_DB -> Query ( "
2018-03-12 23:35:55 +03:00
INSERT
" . PREFIX . " _rubric_fields_group
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
rubric_id = '" . $rubric_id . "' ,
group_position = '" . $position . "' ,
group_title = '" . $_REQUEST[' group_title '] . "'
2017-06-24 00:58:56 +03:00
" );
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
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 . "'
" );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
function rubricDelGroupFields ( $Id , $rubric_id )
{
global $AVE_DB ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
DELETE FROM
" . PREFIX . " _rubric_fields_group
WHERE
Id = '" . $Id . "'
" );
2017-06-24 00:58:56 +03:00
$AVE_DB -> Query ( "
2018-03-12 23:35:55 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2017-06-24 00:58:56 +03:00
SET
2018-03-12 23:35:55 +03:00
rubric_field_group = '0'
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
rubric_field_group = '" . $Id . "'
AND
rubric_id = '" . $rubric_id . "'
2017-06-24 00:58:56 +03:00
" );
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=fieldsgroups&Id=' . $rubric_id . '&cp=' . SESSION );
exit ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
function rubricFieldGroupChange ( $field_id , $rubric_id )
{
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
*
FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
" )->FetchAssocArray();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
function rubricFieldGroupChangeSave ( $field_id , $rubric_id )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubric_fields
2018-03-12 23:35:55 +03:00
SET
2018-05-16 23:14:07 +03:00
rubric_field_group = '" . trim($_POST[' rubric_field_group ']) . "'
2018-03-12 23:35:55 +03:00
WHERE
Id = '" . $field_id . "'
AND
rubric_id = '" . $rubric_id . "'
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
*
FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '" . $rubric_id . "'
AND
Id = " . $field_id . "
" )->FetchAssocArray();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
// Список дополнительных шаблон для данной рубрики
function tmplsList ()
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$templates = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$num = $AVE_DB -> Query ( "
SELECT
COUNT ( * )
FROM
" . PREFIX . " _rubric_templates
WHERE
rubric_id = '" . $_REQUEST[' Id '] . "'
" )->GetCell();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$page_limit = $this -> _limit ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$pages = ceil ( $num / $page_limit );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$set_start = get_current_page () * $page_limit - $page_limit ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $num > $page_limit )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
$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 );
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
rub .* ,
rubrics . rubric_title ,
2018-05-19 20:30:18 +03:00
( SELECT 1 FROM " . PREFIX . " _documents WHERE rubric_id = rub . rubric_id AND rubric_tmpl_id = rub . id LIMIT 1 ) AS doc_count
2018-03-12 23:35:55 +03:00
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
);
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
$row -> author_id = get_username_by_id ( $row -> author_id );
array_push ( $templates , $row );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric = $this -> rubricNameByIdGet (( int ) $_REQUEST [ 'Id' ]);
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'rubric' , $rubric );
$AVE_Template -> assign ( 'templates' , $templates );
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Вывод шаблона рубрики
*
* @ param int $show
* @ param int $extern
*/
function tmplsEdit ()
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$tmpls_id = ( isset ( $_REQUEST [ 'id' ]) && is_numeric ( $_REQUEST [ 'id' ])) ? $_REQUEST [ 'id' ] : 0 ;
$rubric_id = ( int ) $_REQUEST [ 'rubric_id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $tmpls_id )
{
$template = $AVE_DB -> Query ( "
SELECT
title ,
template
FROM
" . PREFIX . " _rubric_templates
WHERE
id = '" . $tmpls_id . "'
" )
-> FetchRow ();
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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 ();
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $_REQUEST [ 'action' ] == 'tmpls_copy' )
{
$template = $AVE_DB -> Query ( "
SELECT
title ,
template
FROM
" . PREFIX . " _rubric_templates
WHERE
id = '" . $_REQUEST[' tmpls_id '] . "'
" )
-> FetchRow ();
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
// Поля
2017-06-24 00:58:56 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
2018-05-16 23:14:07 +03:00
a .* ,
b . group_title ,
b . group_description ,
b . group_position
2017-06-24 00:58:56 +03:00
FROM
2018-03-12 23:35:55 +03:00
" . PREFIX . " _rubric_fields AS a
LEFT JOIN
" . PREFIX . " _rubric_fields_group AS b
ON a . rubric_field_group = b . Id
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
a . rubric_id = '" . $rubric_id . "'
ORDER BY
b . group_position ASC , a . rubric_field_position ASC
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields_list = array ();
$drop_down_fields = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchRow ())
{
$group_id = ( $row -> rubric_field_group ) ? $row -> rubric_field_group : 0 ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $row -> rubric_field_type == 'drop_down' || $row -> rubric_field_type == 'drop_down_key' )
array_push ( $drop_down_fields , $row -> Id );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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 ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields_list = msort ( $fields_list , 'group_position' );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'groups_count' , count ( $fields_list ));
$AVE_Template -> assign ( 'fields_list' , $fields_list );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_Template -> assign ( 'field_array' , get_field_type ());
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Редактирование шаблона рубрики
*
* @ param string $data
*/
function tmplsSave ( $template = '' , $title = '' )
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$tmpls_id = ( int ) $_REQUEST [ 'id' ];
$rubric_id = ( int ) $_REQUEST [ 'rubric_id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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() . "'
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$tmpls_id = $AVE_DB -> InsertId ();
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed = '" . time() . "'
2018-03-12 23:35:55 +03:00
WHERE
2018-05-16 23:14:07 +03:00
Id = '" . intval($rubric_id) . "'
2018-03-12 23:35:55 +03:00
" );
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
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 . ')' );
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
if ( isAjax ())
{
2017-06-24 00:58:56 +03:00
echo json_encode ( array ( 'message' => $message , 'header' => $header , 'theme' => $theme ));
}
2018-03-12 23:35:55 +03:00
else
{
$AVE_Template -> assign ( 'message' , $message );
header ( 'Location:index.php?do=rubs&action=tmpls&Id=' . $rubric_id . '&cp=' . SESSION );
}
2018-05-16 23:14:07 +03:00
exit ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
function tmplsDelete ()
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_id = ( int ) $_REQUEST [ 'rubric_id' ];
$tmpls_id = ( int ) $_REQUEST [ 'tmpls_id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( ! $rubric_not_empty )
{
$AVE_DB -> Query ( "
DELETE
FROM
" . PREFIX . " _rubric_templates
WHERE
id = '" . $tmpls_id . "'
AND
rubric_id = '" . $rubric_id . "'
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$AVE_DB -> Query ( "
2018-05-16 23:14:07 +03:00
UPDATE
" . PREFIX . " _rubrics
SET
rubric_changed = '" . time() . "'
2018-03-12 23:35:55 +03:00
WHERE
2018-05-16 23:14:07 +03:00
Id = '" . intval($rubric_id) . "'
2018-03-12 23:35:55 +03:00
" );
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
$AVE_DB -> clearCache ( 'rub_' . $rubric_id );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
// Сохраняем системное сообщение в журнал
reportLog ( $AVE_Template -> get_config_vars ( 'RUBRIC_TMPLS_LOG_DEL' ) . ' - ' . stripslashes ( htmlspecialchars ( $this -> rubricNameByIdGet ( $rubric_id ) -> rubric_title , ENT_QUOTES )) . ' (Id шаблона: ' . $rubric_id . ')' );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:index.php?do=rubs&action=tmpls&Id=' . $rubric_id . '&cp=' . SESSION );
exit ;
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
function _get_fields_type ( $type = null )
2017-06-24 00:58:56 +03:00
{
2018-03-12 23:35:55 +03:00
static $fields ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( is_array ( $fields ))
return $fields ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$arr = get_defined_functions ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields = array ();
$field = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
foreach ( $arr [ 'user' ] as $v )
{
if ( trim ( substr ( $v , 0 , strlen ( 'get_field_' ))) == 'get_field_' )
{
$d = '' ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$name = @ $v ( '' , 'name' , '' , '' , 0 , $d );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$id = substr ( $v , strlen ( 'get_field_' ));
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( $name != false && is_string ( $name ))
$fields [] = array ( 'id' => $id , 'name' => ( isset ( $fields_vars [ $name ])
? $fields_vars [ $name ]
: $name ));
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( ! empty ( $type ) && $id == $type )
$field = array ( 'id' => $id , 'name' => ( isset ( $fields_vars [ $name ])
? $fields_vars [ $name ]
: $name ));
}
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields = msort ( $fields , array ( 'name' ));
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
return ( ! empty ( $type )) ? $field : $fields ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
function ShowFields ()
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_id = ( int ) $_REQUEST [ 'Id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
rubric_field_type
FROM
" . PREFIX . " _rubric_fields
WHERE
rubric_id = '".$rubric_id."'
GROUP BY
rubric_field_type
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$enable = array ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
while ( $row = $sql -> FetchArray ())
$enable [] = $row [ 'rubric_field_type' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$fields = $this -> _get_fields_type ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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' );
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
SELECT
rubric_title ,
rubric_linked_rubric ,
rubric_description
FROM
" . PREFIX . " _rubrics
WHERE
id = '" . $rubric_id . "'
LIMIT 1
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric = $sql -> FetchRow ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
function ShowFieldsByType ( $fld )
{
global $AVE_DB , $AVE_Template ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric_id = ( int ) $_REQUEST [ 'rubric_id' ];
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$sql = $AVE_DB -> Query ( "
2017-06-24 00:58:56 +03:00
SELECT
2018-03-12 23:35:55 +03:00
a . Id ,
a . rubric_id ,
a . rubric_field_type ,
a . rubric_field_title ,
b . rubric_title
2017-06-24 00:58:56 +03:00
FROM
2018-03-12 23:35:55 +03:00
" . PREFIX . " _rubric_fields AS a
LEFT JOIN
" . PREFIX . " _rubrics AS b
ON a . rubric_id = b . Id
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
a . rubric_field_type = '" . $fld ."'
AND
a . rubric_id = '".$rubric_id."'
ORDER BY
a . rubric_id
" );
2017-06-24 00:58:56 +03:00
2020-07-25 07:38:16 +03:00
$rubrics = [];
2018-03-12 23:35:55 +03:00
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 ( "
2017-06-24 00:58:56 +03:00
SELECT
2018-03-12 23:35:55 +03:00
rubric_title ,
rubric_linked_rubric ,
rubric_description
2017-06-24 00:58:56 +03:00
FROM
" . PREFIX . " _rubrics
WHERE
2018-03-12 23:35:55 +03:00
id = '" . $rubric_id . "'
LIMIT 1
" );
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$rubric = $sql -> FetchRow ();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
function EditFieldTpl ( $id = '' , $fld , $type )
{
global $AVE_DB , $AVE_Template , $_fm_dir ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
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 ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( empty ( $id ))
$file = $source ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
if ( file_exists ( $file ))
$code_text = file_get_contents ( $file );
else
$code_text = file_get_contents ( $source );
2017-06-24 00:58:56 +03:00
$sql = $AVE_DB -> Query ( "
2018-03-12 23:35:55 +03:00
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
2017-06-24 00:58:56 +03:00
WHERE
2018-03-12 23:35:55 +03:00
a . rubric_field_type = '" . $fld ."'
AND
a . Id = '" . $id ."'
" )->FetchAssocArray();
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
$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' ));
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
/**
* Сохранение шаблона
*
*/
function SaveFieldTpl ( $id = '' , $fld , $type , $func )
2017-06-24 00:58:56 +03:00
{
2018-05-16 23:14:07 +03:00
global $AVE_DB ;
2018-03-12 23:35:55 +03:00
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 );
2018-05-16 23:14:07 +03:00
$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 );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
$message = 'Шаблон успешнно сохранен' ;
$header = 'Выполнено' ;
2017-06-24 00:58:56 +03:00
$theme = 'accept' ;
2018-03-12 23:35:55 +03:00
echo json_encode (
array (
'message' => $message ,
'header' => $header ,
'theme' => $theme )
);
2017-06-24 00:58:56 +03:00
exit ;
}
2018-03-12 23:35:55 +03:00
/**
* Удаление шаблона поля
*
*/
function DeleteFieldTpl ( $id , $fld , $type , $func )
{
2018-05-16 23:14:07 +03:00
global $AVE_DB ;
2018-03-12 23:35:55 +03:00
switch ( $type )
{
case 'adm' :
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $id . '.tpl' ;
break ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
case 'doc' :
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $id . '.tpl' ;
break ;
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
case 'req' :
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $id . '.tpl' ;
break ;
}
2017-06-24 00:58:56 +03:00
2018-03-12 23:35:55 +03:00
@ unlink ( $file );
2017-06-24 00:58:56 +03:00
2018-05-16 23:14:07 +03:00
$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 );
2020-07-25 07:38:16 +03:00
$this -> clearChanges ();
2018-05-16 23:14:07 +03:00
2018-03-12 23:35:55 +03:00
header ( 'Location:' . get_referer_link ());
exit ;
2017-06-24 00:58:56 +03:00
}
2018-05-16 23:14:07 +03:00
function clearTemplates ( $rubric_id )
{
}
2020-07-25 07:38:16 +03:00
function clearChanges ()
{
$cache_file = BASE_DIR . '/tmp/cache/sql/rubrics/all/rubrics.cahnges' ;
unlink ( $cache_file );
}
2017-06-24 00:58:56 +03:00
}
2018-03-12 23:35:55 +03:00
?>