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.
311 lines
7.3 KiB
311 lines
7.3 KiB
9 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Класс работы с модулем
|
||
|
*
|
||
|
* @package AVE.cms
|
||
|
* @subpackage
|
||
|
* @filesource
|
||
|
*/
|
||
|
|
||
|
class FieldsManager
|
||
|
{
|
||
|
|
||
|
public static function __get_fields_type($type = null)
|
||
|
{
|
||
|
static $fields;
|
||
|
|
||
|
if(is_array($fields))
|
||
|
return $fields;
|
||
|
|
||
|
$arr = get_defined_functions();
|
||
|
|
||
|
$fields = array();
|
||
|
$field = array();
|
||
|
|
||
|
foreach($arr['user'] as $v)
|
||
|
{
|
||
|
if(trim(substr($v, 0, strlen('get_field_'))) == 'get_field_')
|
||
|
{
|
||
|
$d = '';
|
||
|
|
||
|
$name = @$v('', 'name', '', '', 0, $d);
|
||
|
|
||
|
$id = substr($v, strlen('get_field_'));
|
||
|
|
||
|
if ($name != false && is_string($name))
|
||
|
$fields[] = array('id' => $id,'name' => (isset($fields_vars[$name])
|
||
|
? $fields_vars[$name]
|
||
|
: $name));
|
||
|
|
||
|
if (! empty($type) && $id == $type)
|
||
|
$field = array('id' => $id,'name' => (isset($fields_vars[$name])
|
||
|
? $fields_vars[$name]
|
||
|
: $name));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$fields = msort($fields, array('name'));
|
||
|
|
||
|
return (! empty($type)) ? $field : $fields;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Вывод списка полей
|
||
|
*
|
||
|
*/
|
||
|
public static function ShowFields()
|
||
|
{
|
||
|
global $AVE_DB, $AVE_Template, $_fm_dir;
|
||
|
|
||
|
$sql = $AVE_DB->Query("
|
||
|
SELECT (rubric_field_type)
|
||
|
FROM " . PREFIX . "_rubric_fields
|
||
|
GROUP BY rubric_field_type
|
||
|
");
|
||
|
|
||
|
$enable = array();
|
||
|
|
||
|
while ($row = $sql->FetchArray())
|
||
|
{
|
||
|
$enable[] = $row['rubric_field_type'];
|
||
|
}
|
||
|
|
||
|
$fields = self::__get_fields_type();
|
||
|
|
||
|
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');
|
||
|
}
|
||
|
|
||
|
$AVE_Template->assign("enable", $enable);
|
||
|
$AVE_Template->assign("exists", $exists);
|
||
|
$AVE_Template->assign("fields", $fields);
|
||
|
$AVE_Template->assign("content", $AVE_Template->fetch($_fm_dir . "admin/fields-list.tpl"));
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Вывод поля по рубрикам
|
||
|
*
|
||
|
*/
|
||
|
public static function ShowField($fld)
|
||
|
{
|
||
|
global $AVE_DB, $AVE_Template, $_fm_dir;
|
||
|
|
||
|
$sql = $AVE_DB->Query("
|
||
|
SELECT
|
||
|
a.Id,
|
||
|
a.rubric_id,
|
||
|
a.rubric_field_type,
|
||
|
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
|
||
|
WHERE
|
||
|
a.rubric_field_type = '" . $fld ."'
|
||
|
ORDER BY
|
||
|
a.rubric_id
|
||
|
");
|
||
|
|
||
|
$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]['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');
|
||
|
}
|
||
|
|
||
|
$AVE_Template->assign('main', self::__get_fields_type($fld));
|
||
|
$AVE_Template->assign("rubrics", $rubrics);
|
||
|
$AVE_Template->assign("content", $AVE_Template->fetch($_fm_dir . "admin/field-list.tpl"));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Создание шаблона
|
||
|
*
|
||
|
*/
|
||
|
public static function EditTpl($id = '', $fld, $type)
|
||
|
{
|
||
|
global $AVE_DB, $AVE_Template, $_fm_dir;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
if (empty($id))
|
||
|
$file = $source;
|
||
|
|
||
|
if (file_exists($file))
|
||
|
{
|
||
|
$code_text = file_get_contents($file);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$code_text = file_get_contents($source);
|
||
|
}
|
||
|
|
||
|
$sql = $AVE_DB->Query("
|
||
|
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
|
||
|
WHERE
|
||
|
a.rubric_field_type = '" . $fld ."'
|
||
|
AND
|
||
|
a.Id = '" . $id ."'
|
||
|
")->FetchAssocArray();
|
||
|
|
||
|
$params =
|
||
|
array(
|
||
|
'id' => $id,
|
||
|
'fld' => $fld,
|
||
|
'type' => $type,
|
||
|
'func' => (file_exists($file) ? 'edit' : 'new'),
|
||
|
'field' => $sql,
|
||
|
);
|
||
|
|
||
|
$AVE_Template->assign('main', self::__get_fields_type($fld));
|
||
|
$AVE_Template->assign('params', $params);
|
||
|
$AVE_Template->assign('code_text', $code_text);
|
||
|
$AVE_Template->assign("content", $AVE_Template->fetch($_fm_dir . "admin/field-code.tpl"));
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Сохранение шаблона
|
||
|
*
|
||
|
*/
|
||
|
public static function SaveTpl($id = '', $fld, $type, $func)
|
||
|
{
|
||
|
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);
|
||
|
|
||
|
$message = 'Шаблон успешнно сохранен';
|
||
|
$header = 'Выполнено';
|
||
|
$theme = 'accept';
|
||
|
|
||
|
echo json_encode(
|
||
|
array(
|
||
|
'message' => $message,
|
||
|
'header' => $header,
|
||
|
'theme' => $theme)
|
||
|
);
|
||
|
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Удаление шаблона поля
|
||
|
*
|
||
|
*/
|
||
|
public static function DeleteTpl($id, $fld, $type, $func)
|
||
|
{
|
||
|
switch ($type)
|
||
|
{
|
||
|
case 'adm':
|
||
|
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-' . $id . '.tpl';
|
||
|
break;
|
||
|
|
||
|
case 'doc':
|
||
|
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-doc-' . $id . '.tpl';
|
||
|
break;
|
||
|
|
||
|
case 'req':
|
||
|
$file = BASE_DIR . '/fields/' . $fld . '/tpl/field-req-' . $id . '.tpl';
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
@unlink($file);
|
||
|
|
||
|
header('Location:' . get_referer_link());
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Удаление поля из системы
|
||
|
*
|
||
|
*/
|
||
|
public static function UnlinkField($dir)
|
||
|
{
|
||
|
/*
|
||
|
$dirPath = (! empty($type))
|
||
|
? BASE_DIR . '/fields/' . $dir
|
||
|
: $dir;
|
||
|
*/
|
||
|
|
||
|
$dirPath = BASE_DIR . '/fields/' . $dir;
|
||
|
|
||
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
||
|
$dirPath .= '/';
|
||
|
}
|
||
|
|
||
|
$files = glob($dirPath . '*', GLOB_MARK);
|
||
|
|
||
|
foreach($files as $file)
|
||
|
{
|
||
|
if(substr($file, -1) == '/')
|
||
|
self::UnlinkField($file);
|
||
|
else
|
||
|
@unlink($file);
|
||
|
}
|
||
|
|
||
|
@rrmdir($dirPath);
|
||
|
}
|
||
|
}
|
||
|
?>
|