From ff8b78bee8961a2b4734b80bb47a362a21546d13 Mon Sep 17 00:00:00 2001 From: SVarlamov Date: Sat, 11 Jun 2016 13:54:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=9F=D1=83?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++ class.editdoc.php | 380 +++++++++++++++++++++++++++++++++++++++ index.php | 4 + lang/index.php | 4 + lang/ru.txt | 39 ++++ module.php | 77 ++++++++ sql.php | 52 ++++++ templates/admin_edit.tpl | 370 ++++++++++++++++++++++++++++++++++++++ templates/admin_list.tpl | 120 +++++++++++++ templates/index.php | 4 + 10 files changed, 1063 insertions(+) create mode 100644 README.md create mode 100644 class.editdoc.php create mode 100644 index.php create mode 100644 lang/index.php create mode 100644 lang/ru.txt create mode 100644 module.php create mode 100644 sql.php create mode 100644 templates/admin_edit.tpl create mode 100644 templates/admin_list.tpl create mode 100644 templates/index.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..4097530 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +## editdoc + +# Модуль Публикатор документов v1.0.1 + + +## Данный модуль предназначен для создания форм ввода и редактирования документов на сайте + + +## Перед копированием модуля в папку modules, удалите файл README.md, копируйте только корневую папку editdoc со всем ее содержимым внутри! + +## Changelog: + +16.01.2013 - версия 1.0.1 \ No newline at end of file diff --git a/class.editdoc.php b/class.editdoc.php new file mode 100644 index 0000000..baba686 --- /dev/null +++ b/class.editdoc.php @@ -0,0 +1,380 @@ +Query($sql); + if($rows->NumRows()>0)$rubric_id=0; + if($rubric_id>0)$rows=$AVE_DB->Query("SELECT * FROM " . PREFIX . "_documents LIMIT 1"); + while ($row = $rows->FetchAssocArray()) { + $header=$row; + } + if($rubric_id>0)foreach($header as $k=>&$v)$v=""; + $felds=array(); + $feldsType=array(); + if(!$rubric_id>0){ + $rows=$AVE_DB->Query(" + SELECT + doc.Id AS df_id, + rub.*, + rubric_field_default, + doc.field_value + FROM " . PREFIX . "_rubric_fields AS rub + LEFT JOIN " . PREFIX . "_document_fields AS doc ON rubric_field_id = rub.Id + WHERE document_id = '" . $document_id . "' AND rubric_id + ORDER BY rubric_field_position ASC + "); + }else{ + $rows=$AVE_DB->Query(" + SELECT + 0 as df_id, + rub.*, + rubric_field_default, + rubric_field_default as field_value + FROM " . PREFIX . "_rubric_fields AS rub + WHERE rub.rubric_id = '" . $rubric_id . "' + ORDER BY rubric_field_position ASC + "); + } + while ($row = $rows->FetchAssocArray()) { + $felds[$row['Id']]=$row['df_id'] ? $row['field_value'] : $row['rubric_field_default']; + $feldsType[$row['Id']]['type']=$row['rubric_field_type']; + $feldsType[$row['Id']]['title']=$row['rubric_field_title']; + } + $result['header']=$header; + $result['body']=$felds; + $result['feld_type']=$feldsType; + //echo "
";
+		//var_dump($result);
+		//echo "
"; + return $result; + } + + public static function EditDocList($tpl_dir) + { + global $AVE_DB, $AVE_Template; + + $imports = array(); + + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_editdoc"); + + while ($result = $sql->FetchRow()) + { + array_push($imports, $result); + } + + $rubs = array(); + + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_rubrics"); + + while ($result = $sql->FetchRow()) + { + array_push($rubs, $result); + } + + $AVE_Template->assign('editdocs', $imports); + $AVE_Template->assign('rubs', $rubs); + $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_list.tpl')); + } + + /** + * Добавление нового + * + * @param int $import_id идентификатор + * @param string $tpl_dir - путь к папке с шаблонами модуля + * + */ + public static function EditDocNew($tpl_dir) + { + global $AVE_DB, $AVE_Template; + + $rubs = array(); + + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_rubrics"); + + while ($result = $sql->FetchRow()) + { + array_push($rubs, $result); + } + + $AVE_Template->assign('rubs',$rubs); + $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_edit.tpl')); + } + + /** + * Редактирование + * + * @param int $import_id идентификатор + * @param string $tpl_dir - путь к папке с шаблонами модуля + * + */ + public static function EditDocEdit($import_id, $tpl_dir) + { + global $AVE_DB, $AVE_Template,$AVE_Document; + + if (is_numeric($import_id)) + { + $sql = $AVE_DB->Query(" + SELECT * + FROM " . PREFIX . "_module_editdoc + WHERE id = '" . $import_id . "' + "); + + $row = $sql->FetchAssocArray(); + } + else + { + $row['editdoc_name'] = ''; + $row['editdoc_fill_filters']=''; + } + + $row['editdoc_fill_filters']=unserialize(base64_decode($row['editdoc_fill_filters'])); + $rubs = array(); + $sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_rubrics"); + while ($result = $sql->FetchRow()) + { + array_push($rubs, $result); + } + + $AVE_Template->assign('rubs',$rubs); + $data=editdoc::getRubricFields($row['editdoc_rub'],$row['editdoc_fill_filters']); + //$data=editdoc::documentGet(null,$import_id); + if(!$row['editdoc_template']){ + + $tmpl="
\r\n + \r\n + \">\r\n + "; + + foreach($data['header'] as $k => $v) + $tmpl.="
[header:$k]
\r\n"; + + foreach($data['body'] as $k => $v) + $tmpl.="
[body:$k]
\r\n"; + + $tmpl.='
'; + $row['editdoc_template']=$tmpl; + } + + $AVE_Template->assign('data',$data); + unset($row['editdoc_fill_filters']); + $AVE_Template->assign($row); + $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_edit.tpl')); + } + + + /** + * Удаление + * + * @param int $import_id идентификатор + */ + public static function EditDocDelete($import_id) + { + global $AVE_DB; + + if (is_numeric($import_id)) + { + $AVE_DB->Query(" + DELETE + FROM " . PREFIX . "_module_editdoc + WHERE id = '" . $import_id . "' + "); + } + + header('Location:index.php?do=modules&action=modedit&mod=editdoc&moduleaction=1&cp=' . SESSION); + } + + + /** + * Получение полей Документа + * + * @param inc $id - идентификатор рубрики + * @param array $array - массив со значениями + */ + public static function getRubricFields($id,$array) + { + global $AVE_DB; + $res=array(); + if(!is_array($array))$array=Array(); + $res=Array(); + $res['header']=array(); + $res['header']['document_parent'][0]=($array['header']['document_parent'] ? $array['header']['document_parent'] : ""); + $res['header']['document_title'][0]=($array['header']['document_title'] ? $array['header']['document_title'] : ""); + $res['header']['document_alias'][0]=($array['header']['document_alias'] ? $array['header']['document_alias'] : ""); + $res['header']['document_published'][0]=($array['header']['document_published'] ? $array['header']['document_published'] : ""); + $res['header']['document_expire'][0]=($array['header']['document_expire'] ? $array['header']['document_expire'] : ""); + $res['header']['document_meta_keywords'][0]=($array['header']['document_meta_keywords'] ? $array['header']['document_meta_keywords'] : ""); + $res['header']['document_meta_description'][0]=($array['header']['document_meta_description'] ? $array['header']['document_meta_description'] : ""); + $res['header']['document_in_search'][0]=($array['header']['document_in_search'] ? $array['header']['document_in_search'] : ""); + $res['header']['document_meta_robots'][0]=($array['header']['document_meta_robots'] ? $array['header']['document_meta_robots'] : ""); + $res['header']['document_status'][0]=($array['header']['document_status'] ? $array['header']['document_status'] : ""); + $res['header']['document_deleted'][0]=($array['header']['document_deleted'] ? $array['header']['document_deleted']: ""); + $res['header']['document_count_print'][0]=($array['header']['document_count_print'] ? $array['header']['document_count_print'] : ""); + $res['header']['document_count_view'][0]=($array['header']['document_count_view'] ? $array['header']['document_count_view'] : ""); + $res['header']['document_linked_navi_id'][0]=($array['header']['document_linked_navi_id'] ? $array['header']['document_linked_navi_id'] : ""); + foreach($res['header'] as $k=>$v)$res['header'][$k][1]=(isset($array['template'][$k]) ? $array['template'][$k] :''); + $sql = $AVE_DB->Query("select * from ".PREFIX."_rubric_fields where rubric_id=".$id); + while ($result = $sql->FetchAssocArray()) + { + $func='get_field_'.$result['rubric_field_type']; + if(!is_callable($func)) $func='get_field_default'; + $val=''; + $field=$func("{{ХХХХ}}",'edit',$result['Id'],'',0,$x,0,0,$result['rubric_field_default']); + $field=str_ireplace('{{ХХХХ}}',$val,$field); + $a=array( + '0'=>$result['rubric_field_title'], + '1'=>( + $array['body'][$result['Id']] ? + $array['body'][$result['Id']]: + "" + ), + '2'=>(isset($array['template'][$result['Id']]) ? $array['template'][$result['Id']] : $field) + ); + $res['body'][$result['Id']]=$a; + } + return $res; + } + + /** + * Сохранение импорта + * + * @param int $import_id идентификатор импорта + */ + public static function EditDocSave($import_id = null) + { + global $AVE_DB; + + function stripslashes_deep($value) + { + $value = is_array($value) ? + array_map('stripslashes_deep', $value) : + stripslashes($value); + + return $value; + } + + $v=base64_encode(serialize(stripslashes_deep($_REQUEST['document']))); + + if (is_numeric($import_id)) + { + $sql=" + UPDATE " . PREFIX . "_module_editdoc + SET + `editdoc_name` = '" . ($_REQUEST['editdoc_name']) . "', + ".($_REQUEST['editdoc_rub']> '' ? "`editdoc_rub` = '" . ($_REQUEST['editdoc_rub']) . "'," : "")." + `editdoc_lastchange` = '" . ($_REQUEST['editdoc_lastchange']) . "', + `editdoc_fill_filters` = '" . $v . "', + `editdoc_template` = '" . $_REQUEST['editdoc_template'] . "', + `editdoc_afteredit` = '" . (($_REQUEST['editdoc_afteredit'] ? $_REQUEST['editdoc_afteredit'] : addslashes(""))) . "' + WHERE + id = '" . $import_id . "' + "; + } + else + { + $sql=" + INSERT + INTO " . PREFIX . "_module_editdoc + SET + id = '', + `editdoc_name` = '" . ($_REQUEST['editdoc_name']) . "', + ".($_REQUEST['editdoc_rub']> '' ? "`editdoc_rub` = '" . ($_REQUEST['editdoc_rub']) . "'," : "")." + `editdoc_lastchange` = '" . ($_REQUEST['editdoc_lastchange']) . "', + `editdoc_fill_filters` = '" . $v . "', + `editdoc_template` = '" . ($_REQUEST['editdoc_template']) . "', + `editdoc_afteredit` = '" . ($_REQUEST['editdoc_afteredit']) . "' + "; + } + $AVE_DB->Query($sql); + header('Location:index.php?do=modules&action=modedit&mod=editdoc&moduleaction=1&cp=' . SESSION); + } + + static function EditDocDo($import_id) + { + global $AVE_DB, $AVE_Document; + + if (is_numeric($import_id)) + { + $sql = $AVE_DB->Query(" + SELECT * + FROM " . PREFIX . "_module_editdoc + WHERE id = '" . $import_id . "' + "); + $row = $sql->FetchAssocArray(); + $row['editdoc_fill_filters']=unserialize(base64_decode($row['editdoc_fill_filters'])); + $document_id=(isset($_REQUEST['editdoc_doc_id']) ? (int)$_REQUEST['editdoc_doc_id'] : null); + $data=editdoc::documentGet($document_id,(int)$row['editdoc_rub']); + //Пришла форма + if(isset($_REQUEST['editdoc_action']) && $_REQUEST['editdoc_action']==$import_id){ + //вот тут сохранение будет + $save=true; + foreach($row['editdoc_fill_filters']['header'] as $k=>$v) + { + $exp=' + function editdoc_reth_'.$import_id.'_'.$k.'($data){ + ?>'.trim($v).'$v) + { + $exp=' + function editdoc_retb_'.$import_id.'_'.$k.'($data){ + ?>'.trim($v).'documentPermissionFetch($row['editdoc_rub']); + require_once(BASE_DIR.'/admin/functions/func.admin.common.php'); + if($save){ + //надо перед сохранением уточнить являюсь ли я хозяином документа .....не забыть!!!!!!!!!! а то админы тут делов наделают + $GLOBALS['mod_editdoc'][$import_id]=@$AVE_Document->documentSave((int)$row['editdoc_rub'],$document_id,$d,true); + eval(' ?>'.$row['editdoc_afteredit'].'$v)$template=str_ireplace("[body:$k]",$row['editdoc_fill_filters']["template"][$k],$template); + foreach($row['editdoc_fill_filters']["header"] as $k=>$v)$template=str_ireplace("[header:$k]",$row['editdoc_fill_filters']["template"][$k],$template); + eval(' ?>'.$template.' \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..4ca25aa --- /dev/null +++ b/index.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/lang/index.php b/lang/index.php new file mode 100644 index 0000000..4ca25aa --- /dev/null +++ b/lang/index.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/lang/ru.txt b/lang/ru.txt new file mode 100644 index 0000000..b7593ea --- /dev/null +++ b/lang/ru.txt @@ -0,0 +1,39 @@ +EDITDOC_EDIT = "Публикатор" +EDITDOC_EDIT_TIP = "В данном разделе предоставлены все публикаторы документов." +EDITDOC_ID = "Id" +EDITDOC_NAME = "Наименование публикатора" +EDITDOC_ACTIONS = "Действия" +EDITDOC_NO_ITEMS = "В настоящий момент нет данных" +EDITDOC_BUTTON_SAVE = "Сохранить изменения" +EDITDOC_BUTTON_ADD = "Добавить публикатор" +EDITDOC_INSERT_H = "Добавление/Редактирование публикаторов" +EDITDOC_INNAME = "Введите название публикатора" +EDITDOC_ENTER_NAME = "Пожалуйста, укажите название публикатора" +EDITDOC_INSERT = "Здесь вы можите добавить или изменить выбранный вами публикатор" +EDITDOC_SAVE = "Сохранить" +EDITDOC_SAVEDIT = "Сохранить изменения" +EDITDOC_INTEXT = "Системный блок" +EDITDOC_ADD = "Добавить новый публикатор" +EDITDOC_EDIT_HINT = "Редактировать публикатор" +EDITDOC_DELETE_HINT = "Удалить публикатор" +EDITDOC_DEL_HINT = "Вы уверены, что хотите удалить публикатор ?" +EDITDOC_LIST_LINK = "Список публикаторов документов" +EDITDOC_FILE = "Файл импорта по умолчанию" +EDITDOC_CHECK_FILE = "Импортировать если файл изменился автоматически" +EDITDOC_SUCCESLOCATION = "Редирект после успешного редактирования" +EDITDOC_RUBRICS = "Рубрика" +EDITDOC_TAG = "Системный тег" +EDITDOC_INNAME = "Введите наименование нового публикатора" +EDITDOC_INSERT_H = "Добавление нового публикатора" +EDITDOC_EDIT_H = "Редактирование публикатора" +EDITDOC_TABLE_HEADER = "?" +EDITDOC_SAVEDIT_NEXT = "Сохранить и продолжить редактирование" +EDITDOC_SAVED = "Шаблон публикатора успешно сохранен" +EDITDOC_HEADER_AFTER = "Код после успешного добавления документа" +EDITDOC_HEADER_BODY = "Основное содержимое документа" +EDITDOC_HEADER_HEAD = "Параметры документа" +EDITDOC_HEADER_FORM = "Шаблон вывода формы в публичной части сайта" +EDITDOC_HEADER_FORM = "Параметры документа" +EDITDOC_HEADER_PHP = "Шаблон PHP" +EDITDOC_HEADER_INSTR = "Инструмент ввода" +EDITDOC_HEADER_CORE = "Обработчик" \ No newline at end of file diff --git a/module.php b/module.php new file mode 100644 index 0000000..fae0377 --- /dev/null +++ b/module.php @@ -0,0 +1,77 @@ +"; +} + + +function mod_editdoc($id) +{ + global $AVE_DB, $AVE_Core, $AVE_Template; + if (! (is_file(BASE_DIR . '/modules/editdoc/class.editdoc.php') && + @require_once(BASE_DIR . '/modules/editdoc/class.editdoc.php'))) module_error(); + echo editdoc::EditDocDo($id); + +} +/** + * Администрирование + */ + +if (defined('ACP') && !empty($_REQUEST['moduleaction'])) +{ + if (! (is_file(BASE_DIR . '/modules/editdoc/class.editdoc.php') && + @require_once(BASE_DIR . '/modules/editdoc/class.editdoc.php'))) module_error(); + + $tpl_dir = BASE_DIR . '/modules/editdoc/templates/'; + $lang_file = BASE_DIR . '/modules/editdoc/lang/' . $_SESSION['user_language'] . '.txt'; + + $AVE_Template->config_load($lang_file); + switch ($_REQUEST['moduleaction']) + { + case '1': + editdoc::EditDocList($tpl_dir); + break; + + case 'del': + editdoc::EditDocDelete($_REQUEST['id']); + break; + + case 'new': + editdoc::EditDocNew($tpl_dir); + break; + + case 'edit': + editdoc::EditDocEdit(isset($_REQUEST['id']) ? $_REQUEST['id'] : null, $tpl_dir); + break; + + case 'saveedit': + editdoc::EditDocSave(isset($_REQUEST['id']) ? $_REQUEST['id'] : null); + break; + } +} + +?> \ No newline at end of file diff --git a/sql.php b/sql.php new file mode 100644 index 0000000..d885b89 --- /dev/null +++ b/sql.php @@ -0,0 +1,52 @@ + \ No newline at end of file diff --git a/templates/admin_edit.tpl b/templates/admin_edit.tpl new file mode 100644 index 0000000..443188a --- /dev/null +++ b/templates/admin_edit.tpl @@ -0,0 +1,370 @@ + + + + + + + + + +{literal} + +{/literal} + +
{#EDITDOC_INSERT_H#}
+ +
+
+ {#EDITDOC_INSERT#} +
+
+ + + +
+ +{if $smarty.request.id != ''} + +
+
{if $smarty.request.id != ''}{#EDITDOC_EDIT_H#}{else}{#EDITDOC_INSERT_H#}{/if}
+ + + + + + + + + + + +
{#EDITDOC_NAME#}
{#EDITDOC_RUBRICS#} + +
+ +
+ + +
+
{#EDITDOC_HEADER_FORM#}
+ + + + + + + + + + + + + + + +
{#EDITDOC_HEADER_PHP#}
+ +
+ |  + OL |  + UL |  + LI |  + P |  + B |  + I |  + H1 |  + H2 |  + H3 |  + H4 |  + H5 |  + DIV |  + A |  + IMG |  + SPAN |  + PRE |  + BR |  + TAB | +
+ +
+ + +
+
{#EDITDOC_HEADER_HEAD#}
+ + + + + + + + + + + + + + + {foreach from=$data.header key=k item=v} + + + + + + {/foreach} + +
 {#EDITDOC_HEADER_CORE#}{#EDITDOC_HEADER_INSTR#}
+ $data['header']['{$k}'] + +
+
+
+
+ +
+ + + +
+
{#EDITDOC_HEADER_BODY#}
+ + + + + + + + + + + + + {foreach from=$data.body key=k item=v} + + + + + + {/foreach} + +
 {#EDITDOC_HEADER_CORE#}{#EDITDOC_HEADER_INSTR#}
+ {$v[0]}
+ $data['body']['{$k}'] +
+
+
+
+
+
+ +
+
{#EDITDOC_HEADER_AFTER#}
+ + + + + + + + + + + + + + + + + +
{#EDITDOC_HEADER_PHP#}
+ +
+ |  + OL |  + UL |  + LI |  + P |  + B |  + I |  + H1 |  + H2 |  + H3 |  + H4 |  + H5 |  + DIV |  + A |  + IMG |  + SPAN |  + PRE |  + BR |  + TAB | +
+ + +  или  + +
+
+ + + + + {else} + +
+
{if $smarty.request.id != ''}{#EDITDOC_EDIT_H#}{else}{#EDITDOC_INSERT_H#}{/if}
+ + + + + + + + + + + + + + +
{#EDITDOC_NAME#}
{#EDITDOC_RUBRICS#} + +
+ +
+ +
+ + {/if} + +
+




\ No newline at end of file diff --git a/templates/admin_list.tpl b/templates/admin_list.tpl new file mode 100644 index 0000000..967ac98 --- /dev/null +++ b/templates/admin_list.tpl @@ -0,0 +1,120 @@ + + +
{#EDITDOC_EDIT#}
+ +
+
+ {#EDITDOC_EDIT_TIP#} +
+
+ + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + {if $editdocs} + + {foreach from=$editdocs item=editdoc} + + + + + + + + {/foreach} + + {else} + + + + {/if} + +
{#EDITDOC_ID#}{#EDITDOC_NAME#}{#EDITDOC_TAG#}{#EDITDOC_ACTIONS#}
{$editdoc->id} + {$editdoc->editdoc_name|escape} +
+ + {foreach from=$rubs item=rub} + {if $rub->Id==$editdoc->editdoc_rub} + ({$rub->rubric_title}) + {/if} + {/foreach} + +
+
+
+ + + +
+
    +
  • {#EDITDOC_NO_ITEMS#}
  • +
+
+ +
+ + +
+
+
\ No newline at end of file diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 0000000..4ca25aa --- /dev/null +++ b/templates/index.php @@ -0,0 +1,4 @@ + \ No newline at end of file