@@ -12,174 +12,174 @@ |
||
12 | 12 | */ |
13 | 13 | class Page extends \XoopsObject |
14 | 14 | { |
15 | - // constructor |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - // $this->XoopsObject(); |
|
19 | - $this->initVar('pageid', XOBJ_DTYPE_INT, null, false, 11); |
|
20 | - $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 11); |
|
21 | - $this->initVar('instrid', XOBJ_DTYPE_INT, 0, false, 11); |
|
22 | - $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11); |
|
23 | - $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
24 | - $this->initVar('status', XOBJ_DTYPE_INT, 1, false, 1); |
|
25 | - $this->initVar('type', XOBJ_DTYPE_INT, 1, false, 1); |
|
26 | - $this->initVar('hometext', XOBJ_DTYPE_TXTAREA, null, false); |
|
27 | - $this->initVar('footnote', XOBJ_DTYPE_TXTAREA, '', false); |
|
28 | - $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11); |
|
29 | - $this->initVar('keywords', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
30 | - $this->initVar('description', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
31 | - $this->initVar('comments', XOBJ_DTYPE_INT, 0, false, 11); |
|
32 | - $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
33 | - $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
34 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false, 1); |
|
35 | - $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false, 1); |
|
36 | - $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false, 1); |
|
37 | - $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false, 1); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public function getNewInstertId() |
|
44 | - { |
|
45 | - $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
46 | - return $newEnreg; |
|
47 | - } |
|
48 | - |
|
49 | - // Получаем форму |
|
50 | - |
|
51 | - /** |
|
52 | - * @param bool|null|string $action |
|
53 | - * @param int $instrid |
|
54 | - * @return \XoopsThemeForm |
|
55 | - */ |
|
56 | - public function getForm($action = false, $instrid = 0) |
|
57 | - { |
|
58 | - // Если нет $action |
|
59 | - if (false === $action) { |
|
60 | - $action = xoops_getenv('REQUEST_URI'); |
|
61 | - } |
|
62 | - |
|
63 | - // Подключаем формы |
|
64 | - include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
65 | - // Подключаем типы страниц |
|
66 | - $pagetypes = include $GLOBALS['xoops']->path('modules/instruction/include/pagetypes.inc.php'); |
|
67 | - |
|
68 | - // Название формы |
|
69 | - $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDPAGE) : sprintf(_AM_INSTRUCTION_FORMEDITPAGE); |
|
70 | - |
|
71 | - // Форма |
|
72 | - $form = new \XoopsThemeForm($title, 'instr_form_page', $action, 'post', true); |
|
73 | - // Название |
|
74 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
75 | - |
|
76 | - // Родительская страница |
|
77 | - // $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
|
78 | - $pageHandler = new PageHandler; |
|
79 | - |
|
80 | - $criteria = new \CriteriaCompo(); |
|
81 | - // ID инструкции в которой данная страница |
|
82 | - $instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid'); |
|
83 | - // Находим все страницы данной инструкции |
|
84 | - $criteria->add(new \Criteria('instrid', $instrid_page, '=')); |
|
85 | - // Если мы редактируем, то убрать текущую страницу из списка выбора родительской |
|
86 | - if (!$this->isNew()) { |
|
87 | - $criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>')); |
|
88 | - } |
|
89 | - $criteria->setSort('weight'); |
|
90 | - $criteria->setOrder('ASC'); |
|
91 | - $inspage_arr = $pageHandler->getall($criteria); |
|
92 | - unset($criteria); |
|
93 | - // Подключаем трей |
|
94 | - include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
95 | - $mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid'); |
|
96 | - |
|
97 | - // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
98 | - $helper = Helper::getInstance(); |
|
99 | - $module = $helper->getModule(); |
|
100 | - |
|
101 | - if (Utility::checkVerXoops($module, '2.5.9')) { |
|
102 | - $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC); |
|
103 | - $form->addElement($mytree_select); |
|
104 | - } else { |
|
105 | - $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
106 | - } |
|
107 | - |
|
108 | - // Вес |
|
109 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
|
110 | - // Основной текст |
|
111 | - $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true); |
|
112 | - // Сноска |
|
113 | - $form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e')); |
|
114 | - $form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC); |
|
115 | - $form->addElement($form_footnote, false); |
|
116 | - unset($form_footnote); |
|
117 | - // Статус |
|
118 | - $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
|
119 | - // Тип страницы |
|
120 | - $form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type')); |
|
121 | - $form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC); |
|
122 | - $form_type->addOptionArray($pagetypes); |
|
123 | - $form->addElement($form_type, false); |
|
124 | - // Мета-теги ключевых слов |
|
125 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false); |
|
126 | - // Мета-теги описания |
|
127 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false); |
|
128 | - |
|
129 | - // Настройки |
|
130 | - $option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
|
131 | - // HTML |
|
132 | - $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml')); |
|
133 | - $html_checkbox->addOption(1, _AM_INSTR_DOHTML); |
|
134 | - $option_tray->addElement($html_checkbox); |
|
135 | - // Смайлы |
|
136 | - $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley')); |
|
137 | - $smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY); |
|
138 | - $option_tray->addElement($smiley_checkbox); |
|
139 | - // ББ коды |
|
140 | - $xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode')); |
|
141 | - $xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE); |
|
142 | - $option_tray->addElement($xcode_checkbox); |
|
143 | - // |
|
144 | - $br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr')); |
|
145 | - $br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP); |
|
146 | - $option_tray->addElement($br_checkbox); |
|
147 | - // |
|
148 | - $form->addElement($option_tray); |
|
149 | - |
|
150 | - // Если мы редактируем страницу |
|
151 | - if (!$this->isNew()) { |
|
152 | - $form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid'))); |
|
153 | - } else { |
|
154 | - $form->addElement(new \XoopsFormHidden('pageid', 0)); |
|
155 | - } |
|
156 | - // ID инструкции |
|
157 | - if ($instrid) { |
|
158 | - $form->addElement(new \XoopsFormHidden('instrid', $instrid)); |
|
159 | - } else { |
|
160 | - $form->addElement(new \XoopsFormHidden('instrid', 0)); |
|
161 | - } |
|
162 | - // |
|
163 | - $form->addElement(new \XoopsFormHidden('op', 'savepage')); |
|
164 | - // Кнопка |
|
165 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
166 | - $button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
167 | - $save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM); |
|
168 | - $save_btn->setExtra('onclick="instrSavePage();"'); |
|
169 | - $button_tray->addElement($save_btn); |
|
170 | - $form->addElement($button_tray); |
|
171 | - |
|
172 | - return $form; |
|
173 | - } |
|
174 | - |
|
175 | - // |
|
176 | - |
|
177 | - /** |
|
178 | - * @return mixed |
|
179 | - */ |
|
180 | - public function getInstrid() |
|
181 | - { |
|
182 | - // Возвращаем ID инструкции |
|
183 | - return $this->getVar('instrid'); |
|
184 | - } |
|
15 | + // constructor |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + // $this->XoopsObject(); |
|
19 | + $this->initVar('pageid', XOBJ_DTYPE_INT, null, false, 11); |
|
20 | + $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 11); |
|
21 | + $this->initVar('instrid', XOBJ_DTYPE_INT, 0, false, 11); |
|
22 | + $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11); |
|
23 | + $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
24 | + $this->initVar('status', XOBJ_DTYPE_INT, 1, false, 1); |
|
25 | + $this->initVar('type', XOBJ_DTYPE_INT, 1, false, 1); |
|
26 | + $this->initVar('hometext', XOBJ_DTYPE_TXTAREA, null, false); |
|
27 | + $this->initVar('footnote', XOBJ_DTYPE_TXTAREA, '', false); |
|
28 | + $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11); |
|
29 | + $this->initVar('keywords', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
30 | + $this->initVar('description', XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
31 | + $this->initVar('comments', XOBJ_DTYPE_INT, 0, false, 11); |
|
32 | + $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
33 | + $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
34 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false, 1); |
|
35 | + $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false, 1); |
|
36 | + $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false, 1); |
|
37 | + $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false, 1); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public function getNewInstertId() |
|
44 | + { |
|
45 | + $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
46 | + return $newEnreg; |
|
47 | + } |
|
48 | + |
|
49 | + // Получаем форму |
|
50 | + |
|
51 | + /** |
|
52 | + * @param bool|null|string $action |
|
53 | + * @param int $instrid |
|
54 | + * @return \XoopsThemeForm |
|
55 | + */ |
|
56 | + public function getForm($action = false, $instrid = 0) |
|
57 | + { |
|
58 | + // Если нет $action |
|
59 | + if (false === $action) { |
|
60 | + $action = xoops_getenv('REQUEST_URI'); |
|
61 | + } |
|
62 | + |
|
63 | + // Подключаем формы |
|
64 | + include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
65 | + // Подключаем типы страниц |
|
66 | + $pagetypes = include $GLOBALS['xoops']->path('modules/instruction/include/pagetypes.inc.php'); |
|
67 | + |
|
68 | + // Название формы |
|
69 | + $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDPAGE) : sprintf(_AM_INSTRUCTION_FORMEDITPAGE); |
|
70 | + |
|
71 | + // Форма |
|
72 | + $form = new \XoopsThemeForm($title, 'instr_form_page', $action, 'post', true); |
|
73 | + // Название |
|
74 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
75 | + |
|
76 | + // Родительская страница |
|
77 | + // $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
|
78 | + $pageHandler = new PageHandler; |
|
79 | + |
|
80 | + $criteria = new \CriteriaCompo(); |
|
81 | + // ID инструкции в которой данная страница |
|
82 | + $instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid'); |
|
83 | + // Находим все страницы данной инструкции |
|
84 | + $criteria->add(new \Criteria('instrid', $instrid_page, '=')); |
|
85 | + // Если мы редактируем, то убрать текущую страницу из списка выбора родительской |
|
86 | + if (!$this->isNew()) { |
|
87 | + $criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>')); |
|
88 | + } |
|
89 | + $criteria->setSort('weight'); |
|
90 | + $criteria->setOrder('ASC'); |
|
91 | + $inspage_arr = $pageHandler->getall($criteria); |
|
92 | + unset($criteria); |
|
93 | + // Подключаем трей |
|
94 | + include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
95 | + $mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid'); |
|
96 | + |
|
97 | + // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
98 | + $helper = Helper::getInstance(); |
|
99 | + $module = $helper->getModule(); |
|
100 | + |
|
101 | + if (Utility::checkVerXoops($module, '2.5.9')) { |
|
102 | + $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC); |
|
103 | + $form->addElement($mytree_select); |
|
104 | + } else { |
|
105 | + $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
106 | + } |
|
107 | + |
|
108 | + // Вес |
|
109 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
|
110 | + // Основной текст |
|
111 | + $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true); |
|
112 | + // Сноска |
|
113 | + $form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e')); |
|
114 | + $form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC); |
|
115 | + $form->addElement($form_footnote, false); |
|
116 | + unset($form_footnote); |
|
117 | + // Статус |
|
118 | + $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
|
119 | + // Тип страницы |
|
120 | + $form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type')); |
|
121 | + $form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC); |
|
122 | + $form_type->addOptionArray($pagetypes); |
|
123 | + $form->addElement($form_type, false); |
|
124 | + // Мета-теги ключевых слов |
|
125 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false); |
|
126 | + // Мета-теги описания |
|
127 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false); |
|
128 | + |
|
129 | + // Настройки |
|
130 | + $option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
|
131 | + // HTML |
|
132 | + $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml')); |
|
133 | + $html_checkbox->addOption(1, _AM_INSTR_DOHTML); |
|
134 | + $option_tray->addElement($html_checkbox); |
|
135 | + // Смайлы |
|
136 | + $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley')); |
|
137 | + $smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY); |
|
138 | + $option_tray->addElement($smiley_checkbox); |
|
139 | + // ББ коды |
|
140 | + $xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode')); |
|
141 | + $xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE); |
|
142 | + $option_tray->addElement($xcode_checkbox); |
|
143 | + // |
|
144 | + $br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr')); |
|
145 | + $br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP); |
|
146 | + $option_tray->addElement($br_checkbox); |
|
147 | + // |
|
148 | + $form->addElement($option_tray); |
|
149 | + |
|
150 | + // Если мы редактируем страницу |
|
151 | + if (!$this->isNew()) { |
|
152 | + $form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid'))); |
|
153 | + } else { |
|
154 | + $form->addElement(new \XoopsFormHidden('pageid', 0)); |
|
155 | + } |
|
156 | + // ID инструкции |
|
157 | + if ($instrid) { |
|
158 | + $form->addElement(new \XoopsFormHidden('instrid', $instrid)); |
|
159 | + } else { |
|
160 | + $form->addElement(new \XoopsFormHidden('instrid', 0)); |
|
161 | + } |
|
162 | + // |
|
163 | + $form->addElement(new \XoopsFormHidden('op', 'savepage')); |
|
164 | + // Кнопка |
|
165 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
166 | + $button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
167 | + $save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM); |
|
168 | + $save_btn->setExtra('onclick="instrSavePage();"'); |
|
169 | + $button_tray->addElement($save_btn); |
|
170 | + $form->addElement($button_tray); |
|
171 | + |
|
172 | + return $form; |
|
173 | + } |
|
174 | + |
|
175 | + // |
|
176 | + |
|
177 | + /** |
|
178 | + * @return mixed |
|
179 | + */ |
|
180 | + public function getInstrid() |
|
181 | + { |
|
182 | + // Возвращаем ID инструкции |
|
183 | + return $this->getVar('instrid'); |
|
184 | + } |
|
185 | 185 | } |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class InstructionHandler extends \XoopsPersistableObjectHandler |
16 | 16 | { |
17 | - /** |
|
18 | - * @param null|mixed $db |
|
19 | - */ |
|
20 | - public function __construct(\XoopsDatabase $db = null) |
|
21 | - { |
|
22 | - parent::__construct($db, 'instruction_instr', Instruction::class, 'instrid', 'title'); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @param null|mixed $db |
|
19 | + */ |
|
20 | + public function __construct(\XoopsDatabase $db = null) |
|
21 | + { |
|
22 | + parent::__construct($db, 'instruction_instr', Instruction::class, 'instrid', 'title'); |
|
23 | + } |
|
24 | 24 | |
25 | - // Обновление даты обновления инструкций |
|
25 | + // Обновление даты обновления инструкций |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $instrid |
|
29 | - * @param bool|int $time |
|
30 | - * @return mixed |
|
31 | - */ |
|
32 | - public function updateDateupdated($instrid = 0, $time = null) |
|
33 | - { |
|
34 | - // Если не передали время |
|
35 | - $time = null === $time ? time() : (int)$time; |
|
36 | - // |
|
37 | - $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `instrid` = %u', $this->table, $time, (int)$instrid); |
|
38 | - // |
|
39 | - return $this->db->query($sql); |
|
40 | - } |
|
27 | + /** |
|
28 | + * @param int $instrid |
|
29 | + * @param bool|int $time |
|
30 | + * @return mixed |
|
31 | + */ |
|
32 | + public function updateDateupdated($instrid = 0, $time = null) |
|
33 | + { |
|
34 | + // Если не передали время |
|
35 | + $time = null === $time ? time() : (int)$time; |
|
36 | + // |
|
37 | + $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `instrid` = %u', $this->table, $time, (int)$instrid); |
|
38 | + // |
|
39 | + return $this->db->query($sql); |
|
40 | + } |
|
41 | 41 | |
42 | - // Обновление числа страниц |
|
42 | + // Обновление числа страниц |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $instrid |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public function updatePages($instrid = 0) |
|
49 | - { |
|
50 | - // $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
|
51 | - $pageHandler = new PageHandler; |
|
52 | - // Находим число активных страниц |
|
53 | - $criteria = new \CriteriaCompo(); |
|
54 | - $criteria->add(new \Criteria('instrid', $instrid, '=')); |
|
55 | - $criteria->add(new \Criteria('status ', '0', '>')); |
|
56 | - // Число страниц |
|
57 | - $pages = $pageHandler->getCount($criteria); |
|
58 | - unset($criteria); |
|
44 | + /** |
|
45 | + * @param int $instrid |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public function updatePages($instrid = 0) |
|
49 | + { |
|
50 | + // $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
|
51 | + $pageHandler = new PageHandler; |
|
52 | + // Находим число активных страниц |
|
53 | + $criteria = new \CriteriaCompo(); |
|
54 | + $criteria->add(new \Criteria('instrid', $instrid, '=')); |
|
55 | + $criteria->add(new \Criteria('status ', '0', '>')); |
|
56 | + // Число страниц |
|
57 | + $pages = $pageHandler->getCount($criteria); |
|
58 | + unset($criteria); |
|
59 | 59 | |
60 | - // Сохраняем это число |
|
61 | - $sql = sprintf('UPDATE `%s` SET `pages` = %u, `dateupdated` = %u WHERE `instrid` = %u', $this->table, $pages, time(), $instrid); |
|
62 | - // |
|
63 | - return $this->db->query($sql); |
|
64 | - } |
|
60 | + // Сохраняем это число |
|
61 | + $sql = sprintf('UPDATE `%s` SET `pages` = %u, `dateupdated` = %u WHERE `instrid` = %u', $this->table, $pages, time(), $instrid); |
|
62 | + // |
|
63 | + return $this->db->query($sql); |
|
64 | + } |
|
65 | 65 | } |
@@ -12,114 +12,114 @@ |
||
12 | 12 | */ |
13 | 13 | class Instruction extends \XoopsObject |
14 | 14 | { |
15 | - // constructor |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - // $this->XoopsObject(); |
|
19 | - $this->initVar('instrid', XOBJ_DTYPE_INT, null, false, 11); |
|
20 | - $this->initVar('cid', XOBJ_DTYPE_INT, 0, false, 5); |
|
21 | - $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11); |
|
22 | - $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false); |
|
23 | - $this->initVar('status', XOBJ_DTYPE_INT, 0, false, 1); |
|
24 | - $this->initVar('pages', XOBJ_DTYPE_INT, 0, false, 11); |
|
25 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); |
|
26 | - $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
27 | - $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
28 | - $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false); |
|
29 | - $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false); |
|
15 | + // constructor |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + // $this->XoopsObject(); |
|
19 | + $this->initVar('instrid', XOBJ_DTYPE_INT, null, false, 11); |
|
20 | + $this->initVar('cid', XOBJ_DTYPE_INT, 0, false, 5); |
|
21 | + $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11); |
|
22 | + $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false); |
|
23 | + $this->initVar('status', XOBJ_DTYPE_INT, 0, false, 1); |
|
24 | + $this->initVar('pages', XOBJ_DTYPE_INT, 0, false, 11); |
|
25 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); |
|
26 | + $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
27 | + $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
28 | + $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false); |
|
29 | + $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false); |
|
30 | 30 | |
31 | - // Нет в таблице |
|
32 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
33 | - $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false); |
|
34 | - } |
|
31 | + // Нет в таблице |
|
32 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
33 | + $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function getNewInstertId() |
|
40 | - { |
|
41 | - $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
42 | - return $newEnreg; |
|
43 | - } |
|
36 | + /** |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function getNewInstertId() |
|
40 | + { |
|
41 | + $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
42 | + return $newEnreg; |
|
43 | + } |
|
44 | 44 | |
45 | - // Получаем форму |
|
45 | + // Получаем форму |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param bool|null|string $action |
|
49 | - * @return \XoopsThemeForm |
|
50 | - */ |
|
51 | - public function getForm($action = false) |
|
52 | - { |
|
53 | - global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
|
54 | - // Если нет $action |
|
55 | - if (false === $action) { |
|
56 | - $action = xoops_getenv('REQUEST_URI'); |
|
57 | - } |
|
58 | - // Подключаем формы |
|
59 | - include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
47 | + /** |
|
48 | + * @param bool|null|string $action |
|
49 | + * @return \XoopsThemeForm |
|
50 | + */ |
|
51 | + public function getForm($action = false) |
|
52 | + { |
|
53 | + global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
|
54 | + // Если нет $action |
|
55 | + if (false === $action) { |
|
56 | + $action = xoops_getenv('REQUEST_URI'); |
|
57 | + } |
|
58 | + // Подключаем формы |
|
59 | + include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
60 | 60 | |
61 | - // Название формы |
|
62 | - $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR); |
|
61 | + // Название формы |
|
62 | + $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR); |
|
63 | 63 | |
64 | - // Форма |
|
65 | - $form = new \XoopsThemeForm($title, 'forminstr', $action, 'post', true); |
|
66 | - //$form->setExtra('enctype="multipart/form-data"'); |
|
67 | - // Название инструкции |
|
68 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
69 | - // Категория |
|
70 | - $categoryHandler = new CategoryHandler; |
|
71 | - $criteria = new \CriteriaCompo(); |
|
72 | - $criteria->setSort('weight ASC, title'); |
|
73 | - $criteria->setOrder('ASC'); |
|
74 | - $instructioncat_arr = $categoryHandler->getall($criteria); |
|
75 | - unset($criteria); |
|
76 | - // Подключаем трей |
|
77 | - include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
78 | - $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid'); |
|
64 | + // Форма |
|
65 | + $form = new \XoopsThemeForm($title, 'forminstr', $action, 'post', true); |
|
66 | + //$form->setExtra('enctype="multipart/form-data"'); |
|
67 | + // Название инструкции |
|
68 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
69 | + // Категория |
|
70 | + $categoryHandler = new CategoryHandler; |
|
71 | + $criteria = new \CriteriaCompo(); |
|
72 | + $criteria->setSort('weight ASC, title'); |
|
73 | + $criteria->setOrder('ASC'); |
|
74 | + $instructioncat_arr = $categoryHandler->getall($criteria); |
|
75 | + unset($criteria); |
|
76 | + // Подключаем трей |
|
77 | + include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
78 | + $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid'); |
|
79 | 79 | |
80 | - // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
|
81 | - $helper = Helper::getInstance(); |
|
82 | - $module = $helper->getModule(); |
|
80 | + // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
|
81 | + $helper = Helper::getInstance(); |
|
82 | + $module = $helper->getModule(); |
|
83 | 83 | |
84 | - if (Utility::checkVerXoops($module, '2.5.9')) { |
|
85 | - $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC); |
|
86 | - $form->addElement($mytree_select); |
|
87 | - } else { |
|
88 | - $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
|
89 | - } |
|
84 | + if (Utility::checkVerXoops($module, '2.5.9')) { |
|
85 | + $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC); |
|
86 | + $form->addElement($mytree_select); |
|
87 | + } else { |
|
88 | + $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true))); |
|
89 | + } |
|
90 | 90 | |
91 | - // Описание |
|
92 | - $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true); |
|
93 | - // Статус |
|
94 | - $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
|
91 | + // Описание |
|
92 | + $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true); |
|
93 | + // Статус |
|
94 | + $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
|
95 | 95 | |
96 | - // Теги |
|
97 | - $dir_tag_ok = false; |
|
98 | - if (is_dir('../../tag') || is_dir('../tag')) { |
|
99 | - $dir_tag_ok = true; |
|
100 | - } |
|
101 | - // Если влючена поддержка тегов и есть модуль tag |
|
102 | - if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) { |
|
103 | - $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid'); |
|
104 | - // Подключаем форму тегов |
|
105 | - include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php'); |
|
106 | - // Добавляем элемент в форму |
|
107 | - $form->addElement(new \XoopsFormTag('tag', 60, 255, $itemIdForTag, 0)); |
|
108 | - } |
|
96 | + // Теги |
|
97 | + $dir_tag_ok = false; |
|
98 | + if (is_dir('../../tag') || is_dir('../tag')) { |
|
99 | + $dir_tag_ok = true; |
|
100 | + } |
|
101 | + // Если влючена поддержка тегов и есть модуль tag |
|
102 | + if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) { |
|
103 | + $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid'); |
|
104 | + // Подключаем форму тегов |
|
105 | + include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php'); |
|
106 | + // Добавляем элемент в форму |
|
107 | + $form->addElement(new \XoopsFormTag('tag', 60, 255, $itemIdForTag, 0)); |
|
108 | + } |
|
109 | 109 | |
110 | - // Мета-теги ключевых слов |
|
111 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false); |
|
112 | - // Мета-теги описания |
|
113 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false); |
|
110 | + // Мета-теги ключевых слов |
|
111 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false); |
|
112 | + // Мета-теги описания |
|
113 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false); |
|
114 | 114 | |
115 | - // Если мы редактируем категорию |
|
116 | - if (!$this->isNew()) { |
|
117 | - $form->addElement(new \XoopsFormHidden('instrid', $this->getVar('instrid'))); |
|
118 | - } |
|
119 | - // |
|
120 | - $form->addElement(new \XoopsFormHidden('op', 'saveinstr')); |
|
121 | - // Кнопка |
|
122 | - $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
123 | - return $form; |
|
124 | - } |
|
115 | + // Если мы редактируем категорию |
|
116 | + if (!$this->isNew()) { |
|
117 | + $form->addElement(new \XoopsFormHidden('instrid', $this->getVar('instrid'))); |
|
118 | + } |
|
119 | + // |
|
120 | + $form->addElement(new \XoopsFormHidden('op', 'saveinstr')); |
|
121 | + // Кнопка |
|
122 | + $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
123 | + return $form; |
|
124 | + } |
|
125 | 125 | } |
@@ -14,28 +14,28 @@ |
||
14 | 14 | */ |
15 | 15 | class CategoryHandler extends \XoopsPersistableObjectHandler |
16 | 16 | { |
17 | - /** |
|
18 | - * @param null|mixed $db |
|
19 | - */ |
|
20 | - public function __construct(\XoopsDatabase $db = null) |
|
21 | - { |
|
22 | - parent::__construct($db, 'instruction_cat', Category::class, 'cid', 'title'); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @param null|mixed $db |
|
19 | + */ |
|
20 | + public function __construct(\XoopsDatabase $db = null) |
|
21 | + { |
|
22 | + parent::__construct($db, 'instruction_cat', Category::class, 'cid', 'title'); |
|
23 | + } |
|
24 | 24 | |
25 | - // Обновление даты обновления категории |
|
25 | + // Обновление даты обновления категории |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $cid |
|
29 | - * @param null|int $time |
|
30 | - * @return mixed |
|
31 | - */ |
|
32 | - public function updateDateupdated($cid = 0, $time = null) |
|
33 | - { |
|
34 | - // Если не передали время |
|
35 | - $time = null === $time ? time() : (int)$time; |
|
36 | - // |
|
37 | - $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `cid` = %u', $this->table, $time, (int)$cid); |
|
38 | - // |
|
39 | - return $this->db->query($sql); |
|
40 | - } |
|
27 | + /** |
|
28 | + * @param int $cid |
|
29 | + * @param null|int $time |
|
30 | + * @return mixed |
|
31 | + */ |
|
32 | + public function updateDateupdated($cid = 0, $time = null) |
|
33 | + { |
|
34 | + // Если не передали время |
|
35 | + $time = null === $time ? time() : (int)$time; |
|
36 | + // |
|
37 | + $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `cid` = %u', $this->table, $time, (int)$cid); |
|
38 | + // |
|
39 | + return $this->db->query($sql); |
|
40 | + } |
|
41 | 41 | } |
@@ -16,60 +16,60 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Category extends \XoopsObject |
18 | 18 | { |
19 | - // constructor |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - // $this->XoopsObject(); |
|
23 | - $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5); |
|
24 | - $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 5); |
|
25 | - $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false); |
|
26 | - $this->initVar('imgurl', XOBJ_DTYPE_TXTBOX, '', false); |
|
27 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); |
|
28 | - $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11); |
|
29 | - $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
30 | - $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
31 | - $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false); |
|
32 | - $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function getNewInstertId() |
|
39 | - { |
|
40 | - $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
41 | - return $newEnreg; |
|
42 | - } |
|
43 | - |
|
44 | - // Получаем форму |
|
45 | - |
|
46 | - /** |
|
47 | - * @param bool|null|string $action |
|
48 | - * @return \XoopsThemeForm |
|
49 | - */ |
|
50 | - public function getForm($action = false) |
|
51 | - { |
|
52 | - //global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
|
53 | - require_once __DIR__ . '/../include/common.php'; |
|
54 | - // Если нет $action |
|
55 | - if (false === $action) { |
|
56 | - $action = xoops_getenv('REQUEST_URI'); |
|
57 | - } |
|
58 | - // Подключаем формы |
|
59 | - include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
60 | - |
|
61 | - // Название формы |
|
62 | - $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDCAT) : sprintf(_AM_INSTRUCTION_FORMEDITCAT); |
|
63 | - |
|
64 | - // Форма |
|
65 | - $form = new \XoopsThemeForm($title, 'formcat', $action, 'post', true); |
|
66 | - //$form->setExtra('enctype="multipart/form-data"'); |
|
67 | - // Название категории |
|
68 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
69 | - // Редактор |
|
70 | - $form->addElement(new \XoopsFormTextArea(_AM_INSTRUCTION_DSCC, 'description', $this->getVar('description', 'e')), true); |
|
71 | - //image |
|
72 | - /* |
|
19 | + // constructor |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + // $this->XoopsObject(); |
|
23 | + $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5); |
|
24 | + $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 5); |
|
25 | + $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false); |
|
26 | + $this->initVar('imgurl', XOBJ_DTYPE_TXTBOX, '', false); |
|
27 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false); |
|
28 | + $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11); |
|
29 | + $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10); |
|
30 | + $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10); |
|
31 | + $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false); |
|
32 | + $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function getNewInstertId() |
|
39 | + { |
|
40 | + $newEnreg = $GLOBALS['xoopsDB']->getInsertId(); |
|
41 | + return $newEnreg; |
|
42 | + } |
|
43 | + |
|
44 | + // Получаем форму |
|
45 | + |
|
46 | + /** |
|
47 | + * @param bool|null|string $action |
|
48 | + * @return \XoopsThemeForm |
|
49 | + */ |
|
50 | + public function getForm($action = false) |
|
51 | + { |
|
52 | + //global $xoopsDB, $xoopsModule, $xoopsModuleConfig; |
|
53 | + require_once __DIR__ . '/../include/common.php'; |
|
54 | + // Если нет $action |
|
55 | + if (false === $action) { |
|
56 | + $action = xoops_getenv('REQUEST_URI'); |
|
57 | + } |
|
58 | + // Подключаем формы |
|
59 | + include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
60 | + |
|
61 | + // Название формы |
|
62 | + $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDCAT) : sprintf(_AM_INSTRUCTION_FORMEDITCAT); |
|
63 | + |
|
64 | + // Форма |
|
65 | + $form = new \XoopsThemeForm($title, 'formcat', $action, 'post', true); |
|
66 | + //$form->setExtra('enctype="multipart/form-data"'); |
|
67 | + // Название категории |
|
68 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true); |
|
69 | + // Редактор |
|
70 | + $form->addElement(new \XoopsFormTextArea(_AM_INSTRUCTION_DSCC, 'description', $this->getVar('description', 'e')), true); |
|
71 | + //image |
|
72 | + /* |
|
73 | 73 | $downloadscat_img = $this->getVar('imgurl') ? $this->getVar('imgurl') : 'blank.gif'; |
74 | 74 | $uploadirectory='/uploads/tdmdownloads/images/cats'; |
75 | 75 | $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG,'<br>'); |
@@ -88,107 +88,107 @@ discard block |
||
88 | 88 | $imgtray->addElement($fileseltray); |
89 | 89 | $form->addElement($imgtray); |
90 | 90 | */ |
91 | - // Родительская категория |
|
92 | - // $categoryHandler = xoops_getModuleHandler('category', 'instruction'); |
|
93 | - $criteria = new \CriteriaCompo(); |
|
94 | - // Если мы редактируем, то убрать текущую категорию из списка выбора родительской |
|
95 | - if (!$this->isNew()) { |
|
96 | - $criteria->add(new \Criteria('cid', $this->getVar('cid'), '<>')); |
|
97 | - } |
|
98 | - $criteria->setSort('weight ASC, title'); |
|
99 | - $criteria->setOrder('ASC'); |
|
100 | - |
|
101 | - $categoryHandler = new CategoryHandler; |
|
102 | - $instructioncat_arr = $categoryHandler->getall($criteria); |
|
103 | - unset($criteria); |
|
104 | - // Подключаем трей |
|
105 | - include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
106 | - $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid'); |
|
107 | - |
|
108 | - // $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
109 | - |
|
110 | - $helper = Helper::getInstance(); |
|
111 | - $module = $helper->getModule(); |
|
112 | - |
|
113 | - if (Utility::checkVerXoops($module, '2.5.9')) { |
|
114 | - $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PCATC); |
|
115 | - $form->addElement($mytree_select); |
|
116 | - } else { |
|
117 | - $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
118 | - } |
|
119 | - |
|
120 | - // Вес |
|
121 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
|
122 | - // Мета-теги ключевых слов |
|
123 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false); |
|
124 | - // Мета-теги описания |
|
125 | - $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false); |
|
126 | - |
|
127 | - // ========================================================== |
|
128 | - // ========================================================== |
|
129 | - |
|
130 | - // Права |
|
131 | - $memberHandler = xoops_getHandler('member'); |
|
132 | - $group_list = $memberHandler->getGroupList(); |
|
133 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
134 | - $full_list = array_keys($group_list); |
|
135 | - |
|
136 | - // Права на просмотр |
|
137 | - $groups_ids = []; |
|
138 | - // Если мы редактируем |
|
139 | - if (!$this->isNew()) { |
|
140 | - $groups_ids = $gpermHandler->getGroupIds('instruction_view', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
141 | - $groups_ids = array_values($groups_ids); |
|
142 | - $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $groups_ids); |
|
143 | - } else { |
|
144 | - $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $full_list); |
|
145 | - } |
|
146 | - $groups_instr_view->addOptionArray($group_list); |
|
147 | - $form->addElement($groups_instr_view); |
|
148 | - |
|
149 | - // Права на отправку |
|
150 | - $groups_ids = []; |
|
151 | - if (!$this->isNew()) { |
|
152 | - $groups_ids = $gpermHandler->getGroupIds('instruction_submit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
153 | - $groups_ids = array_values($groups_ids); |
|
154 | - $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $groups_ids); |
|
155 | - } else { |
|
156 | - $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $full_list); |
|
157 | - } |
|
158 | - $groups_instr_submit->addOptionArray($group_list); |
|
159 | - $form->addElement($groups_instr_submit); |
|
160 | - |
|
161 | - // Права на редактирование |
|
162 | - $groups_ids = []; |
|
163 | - if (!$this->isNew()) { |
|
164 | - $groups_ids = $gpermHandler->getGroupIds('instruction_edit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
165 | - $groups_ids = array_values($groups_ids); |
|
166 | - $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $groups_ids); |
|
167 | - } else { |
|
168 | - $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $full_list); |
|
169 | - } |
|
170 | - $groups_instr_edit->addOptionArray($group_list); |
|
171 | - $form->addElement($groups_instr_edit); |
|
172 | - |
|
173 | - // ========================================================== |
|
174 | - // ========================================================== |
|
175 | - |
|
176 | - // Если мы редактируем категорию |
|
177 | - if (!$this->isNew()) { |
|
178 | - $form->addElement(new \XoopsFormHidden('cid', $this->getVar('cid'))); |
|
179 | - //$form->addElement( new \XoopsFormHidden( 'catmodify', true)); |
|
180 | - } |
|
181 | - // |
|
182 | - $form->addElement(new \XoopsFormHidden('op', 'savecat')); |
|
183 | - // Кнопка |
|
184 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
185 | - $submit_btn = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'); |
|
186 | - $button_tray->addElement($submit_btn); |
|
187 | - $cancel_btn = new \XoopsFormButton('', 'cancel', _CANCEL, 'cancel'); |
|
188 | - $cancel_btn->setExtra('onclick="javascript:history.go(-1);"'); |
|
189 | - $button_tray->addElement($cancel_btn); |
|
190 | - $form->addElement($button_tray); |
|
191 | - |
|
192 | - return $form; |
|
193 | - } |
|
91 | + // Родительская категория |
|
92 | + // $categoryHandler = xoops_getModuleHandler('category', 'instruction'); |
|
93 | + $criteria = new \CriteriaCompo(); |
|
94 | + // Если мы редактируем, то убрать текущую категорию из списка выбора родительской |
|
95 | + if (!$this->isNew()) { |
|
96 | + $criteria->add(new \Criteria('cid', $this->getVar('cid'), '<>')); |
|
97 | + } |
|
98 | + $criteria->setSort('weight ASC, title'); |
|
99 | + $criteria->setOrder('ASC'); |
|
100 | + |
|
101 | + $categoryHandler = new CategoryHandler; |
|
102 | + $instructioncat_arr = $categoryHandler->getall($criteria); |
|
103 | + unset($criteria); |
|
104 | + // Подключаем трей |
|
105 | + include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
106 | + $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid'); |
|
107 | + |
|
108 | + // $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
109 | + |
|
110 | + $helper = Helper::getInstance(); |
|
111 | + $module = $helper->getModule(); |
|
112 | + |
|
113 | + if (Utility::checkVerXoops($module, '2.5.9')) { |
|
114 | + $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PCATC); |
|
115 | + $form->addElement($mytree_select); |
|
116 | + } else { |
|
117 | + $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
118 | + } |
|
119 | + |
|
120 | + // Вес |
|
121 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
|
122 | + // Мета-теги ключевых слов |
|
123 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false); |
|
124 | + // Мета-теги описания |
|
125 | + $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false); |
|
126 | + |
|
127 | + // ========================================================== |
|
128 | + // ========================================================== |
|
129 | + |
|
130 | + // Права |
|
131 | + $memberHandler = xoops_getHandler('member'); |
|
132 | + $group_list = $memberHandler->getGroupList(); |
|
133 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
134 | + $full_list = array_keys($group_list); |
|
135 | + |
|
136 | + // Права на просмотр |
|
137 | + $groups_ids = []; |
|
138 | + // Если мы редактируем |
|
139 | + if (!$this->isNew()) { |
|
140 | + $groups_ids = $gpermHandler->getGroupIds('instruction_view', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
141 | + $groups_ids = array_values($groups_ids); |
|
142 | + $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $groups_ids); |
|
143 | + } else { |
|
144 | + $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $full_list); |
|
145 | + } |
|
146 | + $groups_instr_view->addOptionArray($group_list); |
|
147 | + $form->addElement($groups_instr_view); |
|
148 | + |
|
149 | + // Права на отправку |
|
150 | + $groups_ids = []; |
|
151 | + if (!$this->isNew()) { |
|
152 | + $groups_ids = $gpermHandler->getGroupIds('instruction_submit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
153 | + $groups_ids = array_values($groups_ids); |
|
154 | + $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $groups_ids); |
|
155 | + } else { |
|
156 | + $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $full_list); |
|
157 | + } |
|
158 | + $groups_instr_submit->addOptionArray($group_list); |
|
159 | + $form->addElement($groups_instr_submit); |
|
160 | + |
|
161 | + // Права на редактирование |
|
162 | + $groups_ids = []; |
|
163 | + if (!$this->isNew()) { |
|
164 | + $groups_ids = $gpermHandler->getGroupIds('instruction_edit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
165 | + $groups_ids = array_values($groups_ids); |
|
166 | + $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $groups_ids); |
|
167 | + } else { |
|
168 | + $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $full_list); |
|
169 | + } |
|
170 | + $groups_instr_edit->addOptionArray($group_list); |
|
171 | + $form->addElement($groups_instr_edit); |
|
172 | + |
|
173 | + // ========================================================== |
|
174 | + // ========================================================== |
|
175 | + |
|
176 | + // Если мы редактируем категорию |
|
177 | + if (!$this->isNew()) { |
|
178 | + $form->addElement(new \XoopsFormHidden('cid', $this->getVar('cid'))); |
|
179 | + //$form->addElement( new \XoopsFormHidden( 'catmodify', true)); |
|
180 | + } |
|
181 | + // |
|
182 | + $form->addElement(new \XoopsFormHidden('op', 'savecat')); |
|
183 | + // Кнопка |
|
184 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
185 | + $submit_btn = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'); |
|
186 | + $button_tray->addElement($submit_btn); |
|
187 | + $cancel_btn = new \XoopsFormButton('', 'cancel', _CANCEL, 'cancel'); |
|
188 | + $cancel_btn->setExtra('onclick="javascript:history.go(-1);"'); |
|
189 | + $button_tray->addElement($cancel_btn); |
|
190 | + $form->addElement($button_tray); |
|
191 | + |
|
192 | + return $form; |
|
193 | + } |
|
194 | 194 | } |
@@ -33,48 +33,48 @@ |
||
33 | 33 | */ |
34 | 34 | class Breadcrumb |
35 | 35 | { |
36 | - public $dirname; |
|
37 | - private $bread = []; |
|
36 | + public $dirname; |
|
37 | + private $bread = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - $this->dirname = basename(dirname(dirname(__DIR__))); |
|
45 | - } |
|
39 | + /** |
|
40 | + * |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $this->dirname = basename(dirname(dirname(__DIR__))); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Add link to breadcrumb |
|
49 | - * |
|
50 | - * @param string $title |
|
51 | - * @param string $link |
|
52 | - */ |
|
53 | - public function addLink($title = '', $link = '') |
|
54 | - { |
|
55 | - $this->bread[] = [ |
|
56 | - 'link' => $link, |
|
57 | - 'title' => $title |
|
58 | - ]; |
|
59 | - } |
|
47 | + /** |
|
48 | + * Add link to breadcrumb |
|
49 | + * |
|
50 | + * @param string $title |
|
51 | + * @param string $link |
|
52 | + */ |
|
53 | + public function addLink($title = '', $link = '') |
|
54 | + { |
|
55 | + $this->bread[] = [ |
|
56 | + 'link' => $link, |
|
57 | + 'title' => $title |
|
58 | + ]; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Render BreadCrumb |
|
63 | - * |
|
64 | - */ |
|
65 | - public function render() |
|
66 | - { |
|
67 | - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
68 | - require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
69 | - $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
70 | - } |
|
61 | + /** |
|
62 | + * Render BreadCrumb |
|
63 | + * |
|
64 | + */ |
|
65 | + public function render() |
|
66 | + { |
|
67 | + if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
68 | + require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
69 | + $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
|
70 | + } |
|
71 | 71 | |
72 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
73 | - $breadcrumbTpl = new \XoopsTpl(); |
|
74 | - $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
75 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
76 | - unset($breadcrumbTpl); |
|
72 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
73 | + $breadcrumbTpl = new \XoopsTpl(); |
|
74 | + $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
75 | + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
76 | + unset($breadcrumbTpl); |
|
77 | 77 | |
78 | - return $html; |
|
79 | - } |
|
78 | + return $html; |
|
79 | + } |
|
80 | 80 | } |
@@ -17,230 +17,230 @@ |
||
17 | 17 | */ |
18 | 18 | trait FilesManagement |
19 | 19 | { |
20 | - /** |
|
21 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | - * |
|
23 | - * @param string $folder The full path of the directory to check |
|
24 | - * |
|
25 | - * @return void |
|
26 | - * @throws \RuntimeException |
|
27 | - */ |
|
28 | - public static function createFolder($folder) |
|
29 | - { |
|
30 | - try { |
|
31 | - if (!file_exists($folder)) { |
|
32 | - if (!mkdir($folder) && !is_dir($folder)) { |
|
33 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | - } |
|
35 | - |
|
36 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | - } |
|
38 | - } catch (\Exception $e) { |
|
39 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param $file |
|
45 | - * @param $folder |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function copyFile($file, $folder) |
|
49 | - { |
|
50 | - return copy($file, $folder); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param $src |
|
55 | - * @param $dst |
|
56 | - * @throws \RuntimeException |
|
57 | - */ |
|
58 | - public static function recurseCopy($src, $dst) |
|
59 | - { |
|
60 | - $dir = opendir($src); |
|
61 | - if (!mkdir($dst) && !is_dir($dst)) { |
|
62 | - throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); |
|
63 | - } |
|
64 | - while (false !== ($file = readdir($dir))) { |
|
65 | - if (('.' !== $file) && ('..' !== $file)) { |
|
66 | - if (is_dir($src . '/' . $file)) { |
|
67 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
68 | - } else { |
|
69 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
73 | - closedir($dir); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * |
|
78 | - * Remove files and (sub)directories |
|
79 | - * |
|
80 | - * @param string $src source directory to delete |
|
81 | - * |
|
82 | - * @uses \Xmf\Module\Helper::getHelper() |
|
83 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
84 | - * |
|
85 | - * @return bool true on success |
|
86 | - */ |
|
87 | - public static function deleteDirectory($src) |
|
88 | - { |
|
89 | - // Only continue if user is a 'global' Admin |
|
90 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
91 | - return false; |
|
92 | - } |
|
93 | - |
|
94 | - $success = true; |
|
95 | - // remove old files |
|
96 | - $dirInfo = new \SplFileInfo($src); |
|
97 | - // validate is a directory |
|
98 | - if ($dirInfo->isDir()) { |
|
99 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
100 | - foreach ($fileList as $k => $v) { |
|
101 | - $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
102 | - if ($fileInfo->isDir()) { |
|
103 | - // recursively handle subdirectories |
|
104 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
105 | - break; |
|
106 | - } |
|
107 | - } else { |
|
108 | - // delete the file |
|
109 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
110 | - break; |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - // now delete this (sub)directory if all the files are gone |
|
115 | - if ($success) { |
|
116 | - $success = rmdir($dirInfo->getRealPath()); |
|
117 | - } |
|
118 | - } else { |
|
119 | - // input is not a valid directory |
|
120 | - $success = false; |
|
121 | - } |
|
122 | - return $success; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * |
|
127 | - * Recursively remove directory |
|
128 | - * |
|
129 | - * @todo currently won't remove directories with hidden files, should it? |
|
130 | - * |
|
131 | - * @param string $src directory to remove (delete) |
|
132 | - * |
|
133 | - * @return bool true on success |
|
134 | - */ |
|
135 | - public static function rrmdir($src) |
|
136 | - { |
|
137 | - // Only continue if user is a 'global' Admin |
|
138 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - // If source is not a directory stop processing |
|
143 | - if (!is_dir($src)) { |
|
144 | - return false; |
|
145 | - } |
|
146 | - |
|
147 | - $success = true; |
|
148 | - |
|
149 | - // Open the source directory to read in files |
|
150 | - $iterator = new \DirectoryIterator($src); |
|
151 | - foreach ($iterator as $fObj) { |
|
152 | - if ($fObj->isFile()) { |
|
153 | - $filename = $fObj->getPathname(); |
|
154 | - $fObj = null; // clear this iterator object to close the file |
|
155 | - if (!unlink($filename)) { |
|
156 | - return false; // couldn't delete the file |
|
157 | - } |
|
158 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
159 | - // Try recursively on directory |
|
160 | - self::rrmdir($fObj->getPathname()); |
|
161 | - } |
|
162 | - } |
|
163 | - $iterator = null; // clear iterator Obj to close file/directory |
|
164 | - return rmdir($src); // remove the directory & return results |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Recursively move files from one directory to another |
|
169 | - * |
|
170 | - * @param string $src - Source of files being moved |
|
171 | - * @param string $dest - Destination of files being moved |
|
172 | - * |
|
173 | - * @return bool true on success |
|
174 | - */ |
|
175 | - public static function rmove($src, $dest) |
|
176 | - { |
|
177 | - // Only continue if user is a 'global' Admin |
|
178 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - |
|
182 | - // If source is not a directory stop processing |
|
183 | - if (!is_dir($src)) { |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - // If the destination directory does not exist and could not be created stop processing |
|
188 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - |
|
192 | - // Open the source directory to read in files |
|
193 | - $iterator = new \DirectoryIterator($src); |
|
194 | - foreach ($iterator as $fObj) { |
|
195 | - if ($fObj->isFile()) { |
|
196 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
197 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
198 | - // Try recursively on directory |
|
199 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
200 | - // rmdir($fObj->getPath()); // now delete the directory |
|
201 | - } |
|
202 | - } |
|
203 | - $iterator = null; // clear iterator Obj to close file/directory |
|
204 | - return rmdir($src); // remove the directory & return results |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Recursively copy directories and files from one directory to another |
|
209 | - * |
|
210 | - * @param string $src - Source of files being moved |
|
211 | - * @param string $dest - Destination of files being moved |
|
212 | - * |
|
213 | - * @uses \Xmf\Module\Helper::getHelper() |
|
214 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
215 | - * |
|
216 | - * @return bool true on success |
|
217 | - */ |
|
218 | - public static function rcopy($src, $dest) |
|
219 | - { |
|
220 | - // Only continue if user is a 'global' Admin |
|
221 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - // If source is not a directory stop processing |
|
226 | - if (!is_dir($src)) { |
|
227 | - return false; |
|
228 | - } |
|
229 | - |
|
230 | - // If the destination directory does not exist and could not be created stop processing |
|
231 | - if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - // Open the source directory to read in files |
|
236 | - $iterator = new \DirectoryIterator($src); |
|
237 | - foreach ($iterator as $fObj) { |
|
238 | - if ($fObj->isFile()) { |
|
239 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
241 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
242 | - } |
|
243 | - } |
|
244 | - return true; |
|
245 | - } |
|
20 | + /** |
|
21 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | + * |
|
23 | + * @param string $folder The full path of the directory to check |
|
24 | + * |
|
25 | + * @return void |
|
26 | + * @throws \RuntimeException |
|
27 | + */ |
|
28 | + public static function createFolder($folder) |
|
29 | + { |
|
30 | + try { |
|
31 | + if (!file_exists($folder)) { |
|
32 | + if (!mkdir($folder) && !is_dir($folder)) { |
|
33 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
34 | + } |
|
35 | + |
|
36 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
37 | + } |
|
38 | + } catch (\Exception $e) { |
|
39 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param $file |
|
45 | + * @param $folder |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function copyFile($file, $folder) |
|
49 | + { |
|
50 | + return copy($file, $folder); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param $src |
|
55 | + * @param $dst |
|
56 | + * @throws \RuntimeException |
|
57 | + */ |
|
58 | + public static function recurseCopy($src, $dst) |
|
59 | + { |
|
60 | + $dir = opendir($src); |
|
61 | + if (!mkdir($dst) && !is_dir($dst)) { |
|
62 | + throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); |
|
63 | + } |
|
64 | + while (false !== ($file = readdir($dir))) { |
|
65 | + if (('.' !== $file) && ('..' !== $file)) { |
|
66 | + if (is_dir($src . '/' . $file)) { |
|
67 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
68 | + } else { |
|
69 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | + closedir($dir); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * |
|
78 | + * Remove files and (sub)directories |
|
79 | + * |
|
80 | + * @param string $src source directory to delete |
|
81 | + * |
|
82 | + * @uses \Xmf\Module\Helper::getHelper() |
|
83 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
84 | + * |
|
85 | + * @return bool true on success |
|
86 | + */ |
|
87 | + public static function deleteDirectory($src) |
|
88 | + { |
|
89 | + // Only continue if user is a 'global' Admin |
|
90 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
91 | + return false; |
|
92 | + } |
|
93 | + |
|
94 | + $success = true; |
|
95 | + // remove old files |
|
96 | + $dirInfo = new \SplFileInfo($src); |
|
97 | + // validate is a directory |
|
98 | + if ($dirInfo->isDir()) { |
|
99 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
100 | + foreach ($fileList as $k => $v) { |
|
101 | + $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
102 | + if ($fileInfo->isDir()) { |
|
103 | + // recursively handle subdirectories |
|
104 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
105 | + break; |
|
106 | + } |
|
107 | + } else { |
|
108 | + // delete the file |
|
109 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
110 | + break; |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + // now delete this (sub)directory if all the files are gone |
|
115 | + if ($success) { |
|
116 | + $success = rmdir($dirInfo->getRealPath()); |
|
117 | + } |
|
118 | + } else { |
|
119 | + // input is not a valid directory |
|
120 | + $success = false; |
|
121 | + } |
|
122 | + return $success; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * |
|
127 | + * Recursively remove directory |
|
128 | + * |
|
129 | + * @todo currently won't remove directories with hidden files, should it? |
|
130 | + * |
|
131 | + * @param string $src directory to remove (delete) |
|
132 | + * |
|
133 | + * @return bool true on success |
|
134 | + */ |
|
135 | + public static function rrmdir($src) |
|
136 | + { |
|
137 | + // Only continue if user is a 'global' Admin |
|
138 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + // If source is not a directory stop processing |
|
143 | + if (!is_dir($src)) { |
|
144 | + return false; |
|
145 | + } |
|
146 | + |
|
147 | + $success = true; |
|
148 | + |
|
149 | + // Open the source directory to read in files |
|
150 | + $iterator = new \DirectoryIterator($src); |
|
151 | + foreach ($iterator as $fObj) { |
|
152 | + if ($fObj->isFile()) { |
|
153 | + $filename = $fObj->getPathname(); |
|
154 | + $fObj = null; // clear this iterator object to close the file |
|
155 | + if (!unlink($filename)) { |
|
156 | + return false; // couldn't delete the file |
|
157 | + } |
|
158 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
159 | + // Try recursively on directory |
|
160 | + self::rrmdir($fObj->getPathname()); |
|
161 | + } |
|
162 | + } |
|
163 | + $iterator = null; // clear iterator Obj to close file/directory |
|
164 | + return rmdir($src); // remove the directory & return results |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Recursively move files from one directory to another |
|
169 | + * |
|
170 | + * @param string $src - Source of files being moved |
|
171 | + * @param string $dest - Destination of files being moved |
|
172 | + * |
|
173 | + * @return bool true on success |
|
174 | + */ |
|
175 | + public static function rmove($src, $dest) |
|
176 | + { |
|
177 | + // Only continue if user is a 'global' Admin |
|
178 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + |
|
182 | + // If source is not a directory stop processing |
|
183 | + if (!is_dir($src)) { |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + // If the destination directory does not exist and could not be created stop processing |
|
188 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + |
|
192 | + // Open the source directory to read in files |
|
193 | + $iterator = new \DirectoryIterator($src); |
|
194 | + foreach ($iterator as $fObj) { |
|
195 | + if ($fObj->isFile()) { |
|
196 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
197 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
198 | + // Try recursively on directory |
|
199 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
200 | + // rmdir($fObj->getPath()); // now delete the directory |
|
201 | + } |
|
202 | + } |
|
203 | + $iterator = null; // clear iterator Obj to close file/directory |
|
204 | + return rmdir($src); // remove the directory & return results |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Recursively copy directories and files from one directory to another |
|
209 | + * |
|
210 | + * @param string $src - Source of files being moved |
|
211 | + * @param string $dest - Destination of files being moved |
|
212 | + * |
|
213 | + * @uses \Xmf\Module\Helper::getHelper() |
|
214 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
215 | + * |
|
216 | + * @return bool true on success |
|
217 | + */ |
|
218 | + public static function rcopy($src, $dest) |
|
219 | + { |
|
220 | + // Only continue if user is a 'global' Admin |
|
221 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + // If source is not a directory stop processing |
|
226 | + if (!is_dir($src)) { |
|
227 | + return false; |
|
228 | + } |
|
229 | + |
|
230 | + // If the destination directory does not exist and could not be created stop processing |
|
231 | + if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + // Open the source directory to read in files |
|
236 | + $iterator = new \DirectoryIterator($src); |
|
237 | + foreach ($iterator as $fObj) { |
|
238 | + if ($fObj->isFile()) { |
|
239 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
241 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
242 | + } |
|
243 | + } |
|
244 | + return true; |
|
245 | + } |
|
246 | 246 | } |
@@ -23,178 +23,178 @@ |
||
23 | 23 | |
24 | 24 | // Выбор |
25 | 25 | switch ($op) { |
26 | - // Сохранение страницы |
|
27 | - case 'savepage': |
|
28 | - // Выходной массив |
|
29 | - $ret = []; |
|
30 | - |
|
31 | - // Ошибки |
|
32 | - $err = false; |
|
33 | - $message_err = ''; |
|
34 | - |
|
35 | - // |
|
36 | - $title = Request::getString('title', '', 'POST'); |
|
37 | - $pid = Request::getInt('pid', 0, 'POST'); |
|
38 | - $weight = Request::getInt('weight', 0, 'POST'); |
|
39 | - $hometext = Request::getString('hometext', '', 'POST'); |
|
40 | - $footnote = Request::getString('footnote', '', 'POST'); |
|
41 | - $status = Request::getInt('status', 0, 'POST'); |
|
42 | - $type = Request::getInt('type', 0, 'POST'); |
|
43 | - $keywords = Request::getString('keywords', '', 'POST'); |
|
44 | - $description = Request::getString('description', '', 'POST'); |
|
45 | - $dosmiley = (Request::getInt('dosmiley', 0, 'POST') > 0) ? 1 : 0; |
|
46 | - $doxcode = (Request::getInt('doxcode', 0, 'POST') > 0) ? 1 : 0; |
|
47 | - $dobr = (Request::getInt('dobr', 0, 'POST') > 0) ? 1 : 0; |
|
48 | - $dohtml = (Request::getInt('dohtml', 0, 'POST') > 0) ? 1 : 0; |
|
49 | - //$dohtml = Request::getInt( 'dohtml', 0, 'POST' ); |
|
50 | - //$dosmiley = Request::getInt( 'dosmiley', 0, 'POST' ); |
|
51 | - //$doxcode = Request::getInt( 'doxcode', 0, 'POST' ); |
|
52 | - //$dobr = Request::getInt( 'dobr', 0, 'POST' ); |
|
53 | - $pageid = Request::getInt('pageid', 0, 'POST'); |
|
54 | - $instrid = Request::getInt('instrid', 0, 'POST'); |
|
55 | - |
|
56 | - // Проверка |
|
57 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
58 | - $err = true; |
|
59 | - $err_txt = implode(', ', $GLOBALS['xoopsSecurity']->getErrors()); |
|
60 | - $message_err .= $err_txt . '<br>' . _AM_INSTR_TRY_AGAIN . '<br>'; |
|
61 | - } |
|
62 | - // ========================= |
|
63 | - // Устанавливаем новый token |
|
64 | - $token_name = 'XOOPS_TOKEN'; |
|
65 | - $token_timeout = 0; |
|
66 | - // $token_name . '_REQUEST' - название элемента формы |
|
67 | - $ret['toket'] = $GLOBALS['xoopsSecurity']->createToken($token_timeout, $token_name); |
|
68 | - // ========================= |
|
69 | - |
|
70 | - // Если мы редактируем |
|
71 | - if ($pageid) { |
|
72 | - $objInspage = $pageHandler->get($pageid); |
|
73 | - } elseif ($instrid) { |
|
74 | - $objInspage = $pageHandler->create(); |
|
75 | - // Если мы создаём страницу необходимо указать к какой инструкции |
|
76 | - $objInspage->setVar('instrid', $instrid); |
|
77 | - // Указываем дату создания |
|
78 | - $objInspage->setVar('datecreated', $time); |
|
79 | - // Указываем пользователя |
|
80 | - $objInspage->setVar('uid', $uid); |
|
81 | - } else { |
|
82 | - // Устанавливаем сообщение |
|
83 | - $ret['message'] = _AM_INSTRUCTION_BADREQUEST; |
|
84 | - // Возвращаем ответ скрипту через JSON |
|
85 | - echo json_encode($ret); |
|
86 | - // Прерываем выполнение |
|
87 | - exit(); |
|
88 | - } |
|
89 | - |
|
90 | - // Родительская страница |
|
91 | - $objInspage->setVar('pid', $pid); |
|
92 | - // Дата обновления |
|
93 | - $objInspage->setVar('dateupdated', $time); |
|
94 | - // Название |
|
95 | - $objInspage->setVar('title', $title); |
|
96 | - // Вес |
|
97 | - $objInspage->setVar('weight', $weight); |
|
98 | - // Текст |
|
99 | - $objInspage->setVar('hometext', $hometext); |
|
100 | - // Сноска |
|
101 | - $objInspage->setVar('footnote', $footnote); |
|
102 | - // Статус |
|
103 | - $objInspage->setVar('status', $status); |
|
104 | - // Тип |
|
105 | - $objInspage->setVar('type', $type); |
|
106 | - // Мета-теги ключевых слов |
|
107 | - $objInspage->setVar('keywords', $keywords); |
|
108 | - // Мета-теги описания |
|
109 | - $objInspage->setVar('description', $description); |
|
110 | - // |
|
111 | - $objInspage->setVar('dohtml', $dohtml); |
|
112 | - $objInspage->setVar('dosmiley', $dosmiley); |
|
113 | - $objInspage->setVar('doxcode', $doxcode); |
|
114 | - $objInspage->setVar('dobr', $dobr); |
|
115 | - |
|
116 | - // Проверка категорий |
|
117 | - if (!$pageid && !$instrid) { |
|
118 | - $err = true; |
|
119 | - $message_err .= _AM_INSTRUCTION_ERR_INSTR . '<br>'; |
|
120 | - } |
|
121 | - // Проверка веса |
|
122 | - if (0 == $weight) { |
|
123 | - $err = true; |
|
124 | - $message_err .= _AM_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
125 | - } |
|
126 | - // Проверка родительской страницы |
|
127 | - if ($pageid && ($pageid == $pid)) { |
|
128 | - $err = true; |
|
129 | - $message_err .= _AM_INSTRUCTION_ERR_PPAGE . '<br>'; |
|
130 | - } |
|
131 | - // Проверка названия |
|
132 | - if (!$title) { |
|
133 | - $err = true; |
|
134 | - $message_err .= _AM_INSTR_ERR_TITLE . '<br>'; |
|
135 | - } |
|
136 | - // Проверка основного текста |
|
137 | - if (!$hometext) { |
|
138 | - $err = true; |
|
139 | - $message_err .= _AM_INSTR_ERR_HOMETEXT . '<br>'; |
|
140 | - } |
|
141 | - |
|
142 | - // Если были ошибки |
|
143 | - if (true === $err) { |
|
144 | - // |
|
145 | - $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
146 | - // Устанавливаем сообщение |
|
147 | - $ret['message'] = $message_err; |
|
148 | - // Возвращаем ответ скрипту через JSON |
|
149 | - echo json_encode($ret); |
|
150 | - // Прерываем выполнение |
|
151 | - exit(); |
|
152 | - // Если небыло ошибок |
|
153 | - } else { |
|
154 | - // Вставляем данные в БД |
|
155 | - if ($pageHandler->insert($objInspage)) { |
|
156 | - // Находим ID созданной записи |
|
157 | - $pageid_new = $pageid ?: $objInspage->getNewInstertId(); |
|
158 | - // |
|
159 | - $ret['pageid'] = $pageid_new; |
|
160 | - // Получаем ID инструкции |
|
161 | - $instrid = $objInspage->getInstrid(); |
|
162 | - // Обновляем в инструкции число страниц и дату |
|
163 | - $instructionHandler->updatePages($instrid); |
|
164 | - // Если мы редактируем |
|
165 | - if ($pageid) { |
|
166 | - // Устанавливаем сообщение |
|
167 | - $ret['message'] = '<div class="successMsg" style="text-align: left;">' . _AM_INSTRUCTION_PAGEMODIFY . '</div>'; |
|
168 | - // Возвращаем ответ скрипту через JSON |
|
169 | - echo json_encode($ret); |
|
170 | - // Прерываем выполнение |
|
171 | - exit(); |
|
172 | - |
|
173 | - // Если мы добавляем |
|
174 | - } else { |
|
175 | - // Инкримент комментов |
|
176 | - $pageHandler->updateposts($uid, $status, 'add'); |
|
177 | - |
|
178 | - // Устанавливаем сообщение |
|
179 | - $ret['message'] = '<div class="successMsg" style="text-align: left;">' . _AM_INSTRUCTION_PAGEADDED . '</div>'; |
|
180 | - // Возвращаем ответ скрипту через JSON |
|
181 | - echo json_encode($ret); |
|
182 | - // Прерываем выполнение |
|
183 | - exit(); |
|
184 | - } |
|
185 | - // Если не получилось вставить данные |
|
186 | - } else { |
|
187 | - |
|
188 | - // |
|
189 | - $message_err = '<div class="errorMsg" style="text-align: left;">' . $objInspage->getHtmlErrors() . '</div>'; |
|
190 | - // Устанавливаем сообщение |
|
191 | - $ret['message'] = $message_err; |
|
192 | - // Возвращаем ответ скрипту через JSON |
|
193 | - echo json_encode($ret); |
|
194 | - // Прерываем выполнение |
|
195 | - exit(); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - break; |
|
26 | + // Сохранение страницы |
|
27 | + case 'savepage': |
|
28 | + // Выходной массив |
|
29 | + $ret = []; |
|
30 | + |
|
31 | + // Ошибки |
|
32 | + $err = false; |
|
33 | + $message_err = ''; |
|
34 | + |
|
35 | + // |
|
36 | + $title = Request::getString('title', '', 'POST'); |
|
37 | + $pid = Request::getInt('pid', 0, 'POST'); |
|
38 | + $weight = Request::getInt('weight', 0, 'POST'); |
|
39 | + $hometext = Request::getString('hometext', '', 'POST'); |
|
40 | + $footnote = Request::getString('footnote', '', 'POST'); |
|
41 | + $status = Request::getInt('status', 0, 'POST'); |
|
42 | + $type = Request::getInt('type', 0, 'POST'); |
|
43 | + $keywords = Request::getString('keywords', '', 'POST'); |
|
44 | + $description = Request::getString('description', '', 'POST'); |
|
45 | + $dosmiley = (Request::getInt('dosmiley', 0, 'POST') > 0) ? 1 : 0; |
|
46 | + $doxcode = (Request::getInt('doxcode', 0, 'POST') > 0) ? 1 : 0; |
|
47 | + $dobr = (Request::getInt('dobr', 0, 'POST') > 0) ? 1 : 0; |
|
48 | + $dohtml = (Request::getInt('dohtml', 0, 'POST') > 0) ? 1 : 0; |
|
49 | + //$dohtml = Request::getInt( 'dohtml', 0, 'POST' ); |
|
50 | + //$dosmiley = Request::getInt( 'dosmiley', 0, 'POST' ); |
|
51 | + //$doxcode = Request::getInt( 'doxcode', 0, 'POST' ); |
|
52 | + //$dobr = Request::getInt( 'dobr', 0, 'POST' ); |
|
53 | + $pageid = Request::getInt('pageid', 0, 'POST'); |
|
54 | + $instrid = Request::getInt('instrid', 0, 'POST'); |
|
55 | + |
|
56 | + // Проверка |
|
57 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
58 | + $err = true; |
|
59 | + $err_txt = implode(', ', $GLOBALS['xoopsSecurity']->getErrors()); |
|
60 | + $message_err .= $err_txt . '<br>' . _AM_INSTR_TRY_AGAIN . '<br>'; |
|
61 | + } |
|
62 | + // ========================= |
|
63 | + // Устанавливаем новый token |
|
64 | + $token_name = 'XOOPS_TOKEN'; |
|
65 | + $token_timeout = 0; |
|
66 | + // $token_name . '_REQUEST' - название элемента формы |
|
67 | + $ret['toket'] = $GLOBALS['xoopsSecurity']->createToken($token_timeout, $token_name); |
|
68 | + // ========================= |
|
69 | + |
|
70 | + // Если мы редактируем |
|
71 | + if ($pageid) { |
|
72 | + $objInspage = $pageHandler->get($pageid); |
|
73 | + } elseif ($instrid) { |
|
74 | + $objInspage = $pageHandler->create(); |
|
75 | + // Если мы создаём страницу необходимо указать к какой инструкции |
|
76 | + $objInspage->setVar('instrid', $instrid); |
|
77 | + // Указываем дату создания |
|
78 | + $objInspage->setVar('datecreated', $time); |
|
79 | + // Указываем пользователя |
|
80 | + $objInspage->setVar('uid', $uid); |
|
81 | + } else { |
|
82 | + // Устанавливаем сообщение |
|
83 | + $ret['message'] = _AM_INSTRUCTION_BADREQUEST; |
|
84 | + // Возвращаем ответ скрипту через JSON |
|
85 | + echo json_encode($ret); |
|
86 | + // Прерываем выполнение |
|
87 | + exit(); |
|
88 | + } |
|
89 | + |
|
90 | + // Родительская страница |
|
91 | + $objInspage->setVar('pid', $pid); |
|
92 | + // Дата обновления |
|
93 | + $objInspage->setVar('dateupdated', $time); |
|
94 | + // Название |
|
95 | + $objInspage->setVar('title', $title); |
|
96 | + // Вес |
|
97 | + $objInspage->setVar('weight', $weight); |
|
98 | + // Текст |
|
99 | + $objInspage->setVar('hometext', $hometext); |
|
100 | + // Сноска |
|
101 | + $objInspage->setVar('footnote', $footnote); |
|
102 | + // Статус |
|
103 | + $objInspage->setVar('status', $status); |
|
104 | + // Тип |
|
105 | + $objInspage->setVar('type', $type); |
|
106 | + // Мета-теги ключевых слов |
|
107 | + $objInspage->setVar('keywords', $keywords); |
|
108 | + // Мета-теги описания |
|
109 | + $objInspage->setVar('description', $description); |
|
110 | + // |
|
111 | + $objInspage->setVar('dohtml', $dohtml); |
|
112 | + $objInspage->setVar('dosmiley', $dosmiley); |
|
113 | + $objInspage->setVar('doxcode', $doxcode); |
|
114 | + $objInspage->setVar('dobr', $dobr); |
|
115 | + |
|
116 | + // Проверка категорий |
|
117 | + if (!$pageid && !$instrid) { |
|
118 | + $err = true; |
|
119 | + $message_err .= _AM_INSTRUCTION_ERR_INSTR . '<br>'; |
|
120 | + } |
|
121 | + // Проверка веса |
|
122 | + if (0 == $weight) { |
|
123 | + $err = true; |
|
124 | + $message_err .= _AM_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
125 | + } |
|
126 | + // Проверка родительской страницы |
|
127 | + if ($pageid && ($pageid == $pid)) { |
|
128 | + $err = true; |
|
129 | + $message_err .= _AM_INSTRUCTION_ERR_PPAGE . '<br>'; |
|
130 | + } |
|
131 | + // Проверка названия |
|
132 | + if (!$title) { |
|
133 | + $err = true; |
|
134 | + $message_err .= _AM_INSTR_ERR_TITLE . '<br>'; |
|
135 | + } |
|
136 | + // Проверка основного текста |
|
137 | + if (!$hometext) { |
|
138 | + $err = true; |
|
139 | + $message_err .= _AM_INSTR_ERR_HOMETEXT . '<br>'; |
|
140 | + } |
|
141 | + |
|
142 | + // Если были ошибки |
|
143 | + if (true === $err) { |
|
144 | + // |
|
145 | + $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
146 | + // Устанавливаем сообщение |
|
147 | + $ret['message'] = $message_err; |
|
148 | + // Возвращаем ответ скрипту через JSON |
|
149 | + echo json_encode($ret); |
|
150 | + // Прерываем выполнение |
|
151 | + exit(); |
|
152 | + // Если небыло ошибок |
|
153 | + } else { |
|
154 | + // Вставляем данные в БД |
|
155 | + if ($pageHandler->insert($objInspage)) { |
|
156 | + // Находим ID созданной записи |
|
157 | + $pageid_new = $pageid ?: $objInspage->getNewInstertId(); |
|
158 | + // |
|
159 | + $ret['pageid'] = $pageid_new; |
|
160 | + // Получаем ID инструкции |
|
161 | + $instrid = $objInspage->getInstrid(); |
|
162 | + // Обновляем в инструкции число страниц и дату |
|
163 | + $instructionHandler->updatePages($instrid); |
|
164 | + // Если мы редактируем |
|
165 | + if ($pageid) { |
|
166 | + // Устанавливаем сообщение |
|
167 | + $ret['message'] = '<div class="successMsg" style="text-align: left;">' . _AM_INSTRUCTION_PAGEMODIFY . '</div>'; |
|
168 | + // Возвращаем ответ скрипту через JSON |
|
169 | + echo json_encode($ret); |
|
170 | + // Прерываем выполнение |
|
171 | + exit(); |
|
172 | + |
|
173 | + // Если мы добавляем |
|
174 | + } else { |
|
175 | + // Инкримент комментов |
|
176 | + $pageHandler->updateposts($uid, $status, 'add'); |
|
177 | + |
|
178 | + // Устанавливаем сообщение |
|
179 | + $ret['message'] = '<div class="successMsg" style="text-align: left;">' . _AM_INSTRUCTION_PAGEADDED . '</div>'; |
|
180 | + // Возвращаем ответ скрипту через JSON |
|
181 | + echo json_encode($ret); |
|
182 | + // Прерываем выполнение |
|
183 | + exit(); |
|
184 | + } |
|
185 | + // Если не получилось вставить данные |
|
186 | + } else { |
|
187 | + |
|
188 | + // |
|
189 | + $message_err = '<div class="errorMsg" style="text-align: left;">' . $objInspage->getHtmlErrors() . '</div>'; |
|
190 | + // Устанавливаем сообщение |
|
191 | + $ret['message'] = $message_err; |
|
192 | + // Возвращаем ответ скрипту через JSON |
|
193 | + echo json_encode($ret); |
|
194 | + // Прерываем выполнение |
|
195 | + exit(); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + break; |
|
200 | 200 | } |
@@ -29,264 +29,264 @@ |
||
29 | 29 | // Выбор |
30 | 30 | switch ($op) { |
31 | 31 | |
32 | - case 'main': |
|
33 | - |
|
34 | - // Подключаем трей |
|
35 | - |
|
36 | - // include_once __DIR__ . '/../class/Tree.php'; |
|
37 | - //include_once $GLOBALS['xoops']->path('modules/instruction/class/Tree.php'); |
|
38 | - |
|
39 | - // Заголовок админки |
|
40 | - xoops_cp_header(); |
|
41 | - // Навигация |
|
42 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
43 | - |
|
44 | - // Находим ID-категории => Число страниц |
|
45 | - $cidinstrids = []; |
|
46 | - $sql = "SELECT `cid`, COUNT( `instrid` ) FROM {$instructionHandler->table} GROUP BY `cid`"; |
|
47 | - $result = $GLOBALS['xoopsDB']->query($sql); |
|
48 | - while (list($cid, $count) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
|
49 | - // Заполняем массив |
|
50 | - $cidinstrids[$cid] = $count; |
|
51 | - } |
|
52 | - |
|
53 | - // Выбираем категории из БД |
|
54 | - $criteria = new \CriteriaCompo(); |
|
55 | - $criteria->setSort('weight ASC, title'); |
|
56 | - $criteria->setOrder('ASC'); |
|
57 | - $ins_cat = $categoryHandler->getall($criteria); |
|
58 | - unset($criteria); |
|
59 | - |
|
60 | - // Инициализируем |
|
61 | - $cattree = new instruction\Tree($ins_cat, 'cid', 'pid'); |
|
62 | - // Выводим списко категорий в шаблон |
|
63 | - $GLOBALS['xoopsTpl']->assign('insListCat', $cattree->makeCatsAdmin('--', $cidinstrids)); |
|
64 | - |
|
65 | - // Создание новой категории |
|
66 | - $objInstructioncat = $categoryHandler->create(); |
|
67 | - $form = $objInstructioncat->getForm('cat.php'); |
|
68 | - // Форма |
|
69 | - $GLOBALS['xoopsTpl']->assign('insFormCat', $form->render()); |
|
70 | - // Выводим шаблон |
|
71 | - $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_cat.tpl'); |
|
72 | - |
|
73 | - // Текст внизу админки |
|
74 | - include __DIR__ . '/admin_footer.php'; |
|
75 | - |
|
76 | - break; |
|
77 | - |
|
78 | - // Редактирование категории |
|
79 | - case 'editcat': |
|
80 | - |
|
81 | - // Заголовок админки |
|
82 | - xoops_cp_header(); |
|
83 | - // Навигация |
|
84 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
85 | - |
|
86 | - $objInstructioncat = $categoryHandler->get($cid); |
|
87 | - $form = $objInstructioncat->getForm('cat.php'); |
|
88 | - // Форма |
|
89 | - //$GLOBALS['xoopsTpl']->assign( 'insFormCat', $form->render() ); |
|
90 | - echo $form->render(); |
|
91 | - // Выводим шаблон |
|
92 | - $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_editcat.tpl'); |
|
93 | - |
|
94 | - // Текст внизу админки |
|
95 | - include __DIR__ . '/admin_footer.php'; |
|
96 | - |
|
97 | - break; |
|
98 | - |
|
99 | - // Сохранение категорий |
|
100 | - case 'savecat': |
|
101 | - |
|
102 | - // Проверка |
|
103 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
104 | - redirect_header('cat.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
105 | - } |
|
106 | - // Если мы редактируем |
|
107 | - if ($cid) { |
|
108 | - $objInstructioncat = $categoryHandler->get($cid); |
|
109 | - } else { |
|
110 | - $objInstructioncat = $categoryHandler->create(); |
|
111 | - // Указываем дату создания |
|
112 | - $objInstructioncat->setVar('datecreated', $time); |
|
113 | - } |
|
114 | - |
|
115 | - $err = false; |
|
116 | - $message_err = ''; |
|
117 | - |
|
118 | - // Дата обновления |
|
119 | - $objInstructioncat->setVar('dateupdated', $time); |
|
120 | - $objInstructioncat->setVar('pid', $pid); |
|
121 | - $objInstructioncat->setVar('title', Request::getString('title', '', 'POST')); |
|
122 | - $objInstructioncat->setVar('description', Request::getString('description', '', 'POST')); |
|
123 | - $objInstructioncat->setVar('weight', $weight); |
|
124 | - $objInstructioncat->setVar('metakeywords', Request::getString('metakeywords', '', 'POST')); |
|
125 | - $objInstructioncat->setVar('metadescription', Request::getString('metadescription', '', 'POST')); |
|
126 | - |
|
127 | - // Проверка веса |
|
128 | - if (0 == $weight) { |
|
129 | - $err = true; |
|
130 | - $message_err .= _AM_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
131 | - } |
|
132 | - // Проверка категорий |
|
133 | - if ($cid && ($cid == $pid)) { |
|
134 | - $err = true; |
|
135 | - $message_err .= _AM_INSTRUCTION_ERR_PCAT . '<br>'; |
|
136 | - } |
|
137 | - // Если были ошибки |
|
138 | - if (true === $err) { |
|
139 | - xoops_cp_header(); |
|
140 | - // Навигация |
|
141 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
142 | - |
|
143 | - $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
144 | - // Выводим ошибки в шаблон |
|
145 | - $GLOBALS['xoopsTpl']->assign('insErrorMsg', $message_err); |
|
146 | - // Если небыло ошибок |
|
147 | - } else { |
|
148 | - // Вставляем данные в БД |
|
149 | - if ($categoryHandler->insert($objInstructioncat)) { |
|
150 | - |
|
151 | - // ID категории. Если редактируем - то не изменяется. Если создаём новую - то получаем ID созданной записи. |
|
152 | - $new_cid = $cid ?: $objInstructioncat->getNewInstertId(); |
|
153 | - |
|
154 | - // =============== |
|
155 | - // ==== Права ==== |
|
156 | - // =============== |
|
157 | - |
|
158 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
159 | - |
|
160 | - // Если мы редактируем категорию, то старые права нужно удалить |
|
161 | - if ($cid) { |
|
162 | - // Права на просмотр |
|
163 | - $criteria = new\ CriteriaCompo(); |
|
164 | - $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
165 | - $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
166 | - $criteria->add(new \Criteria('gperm_name', 'instruction_view', '=')); |
|
167 | - $gpermHandler->deleteAll($criteria); |
|
168 | - // Права на добавление |
|
169 | - $criteria = new \CriteriaCompo(); |
|
170 | - $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
171 | - $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
172 | - $criteria->add(new \Criteria('gperm_name', 'instruction_submit', '=')); |
|
173 | - $gpermHandler->deleteAll($criteria); |
|
174 | - // Права на редактирование |
|
175 | - $criteria = new \CriteriaCompo(); |
|
176 | - $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
177 | - $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
178 | - $criteria->add(new \Criteria('gperm_name', 'instruction_edit', '=')); |
|
179 | - $gpermHandler->deleteAll($criteria); |
|
180 | - } |
|
181 | - |
|
182 | - // Добавляем права |
|
183 | - // Права на просмотр |
|
184 | - if (Request::hasVar('groups_instr_view', 'POST')) { |
|
185 | - foreach (Request::getArray('groups_instr_view', '', 'POST') as $onegroup_id) { |
|
186 | - $gpermHandler->addRight('instruction_view', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
187 | - } |
|
188 | - } |
|
189 | - // Права на добавление |
|
190 | - if (Request::hasVar('groups_instr_submit', 'POST')) { |
|
191 | - foreach (Request::getArray('groups_instr_submit', '', 'POST') as $onegroup_id) { |
|
192 | - $gpermHandler->addRight('instruction_submit', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
193 | - } |
|
194 | - } |
|
195 | - // Права на редактирование |
|
196 | - if (Request::hasVar('groups_instr_edit', 'POST')) { |
|
197 | - foreach (Request::getArray('groups_instr_edit', '', 'POST') as $onegroup_id) { |
|
198 | - $gpermHandler->addRight('instruction_edit', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - // |
|
203 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_NEWCATADDED); |
|
204 | - } |
|
205 | - xoops_cp_header(); |
|
206 | - // Навигация |
|
207 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
208 | - // Выводим ошибки в шаблон |
|
209 | - $GLOBALS['xoopsTpl']->assign('insErrorMsg', $objInstructioncat->getHtmlErrors()); |
|
210 | - } |
|
211 | - // Выводим шаблон |
|
212 | - $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_savecat.tpl'); |
|
213 | - // Выводим форму |
|
214 | - $form = $objInstructioncat->getForm(); |
|
215 | - // Форма |
|
216 | - echo $form->render(); |
|
217 | - // Текст внизу админки |
|
218 | - include __DIR__ . '/admin_footer.php'; |
|
219 | - |
|
220 | - break; |
|
221 | - |
|
222 | - // Удаление категории |
|
223 | - case 'delcat': |
|
224 | - |
|
225 | - // Находим число инструкций в данной категории |
|
226 | - // Критерий выборки |
|
227 | - $criteria = new \CriteriaCompo(); |
|
228 | - // Все инструкции в данной категории |
|
229 | - $criteria->add(new \Criteria('cid', $cid, '=')); |
|
230 | - $numrows = $instructionHandler->getCount($criteria); |
|
231 | - // |
|
232 | - unset($criteria); |
|
233 | - // Если есть хоть одна инструкция |
|
234 | - if ($numrows) { |
|
235 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATNOTEMPTY); |
|
236 | - } |
|
237 | - |
|
238 | - $objInscat = $categoryHandler->get($cid); |
|
239 | - // Если нет такой категории |
|
240 | - if (!is_object($objInscat)) { |
|
241 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATNOTSELECT); |
|
242 | - } |
|
243 | - |
|
244 | - // Нельзя удалять пока есть доченрии категории |
|
245 | - // Подключаем трей |
|
246 | - include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
247 | - $inscat_arr = $categoryHandler->getall(); |
|
248 | - $mytree = new \XoopsObjectTree($inscat_arr, 'cid', 'pid'); |
|
249 | - $ins_childcat = $mytree->getAllChild($cid); |
|
250 | - // Если есть дочернии категории |
|
251 | - if (count($ins_childcat)) { |
|
252 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATCHILDREN); |
|
253 | - } |
|
254 | - |
|
255 | - // Нажали ли мы на кнопку OK |
|
256 | - $ok = Request::getInt('ok', 0, 'POST'); |
|
257 | - // Если мы нажали на кнопку |
|
258 | - if ($ok) { |
|
259 | - |
|
260 | - // Проверка |
|
261 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
262 | - redirect_header('cat.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
263 | - } |
|
264 | - // Пытаемся удалить категорию |
|
265 | - if ($categoryHandler->delete($objInscat)) { |
|
266 | - |
|
267 | - // Удалить права доступа к категории |
|
268 | - // ================================= |
|
269 | - |
|
270 | - // Редирект |
|
271 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_CATDELETED); |
|
272 | - // Если не смогли удалить категорию |
|
273 | - } else { |
|
274 | - // Редирект |
|
275 | - redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_DELCAT); |
|
276 | - } |
|
277 | - } else { |
|
278 | - |
|
279 | - // Заголовок админки |
|
280 | - xoops_cp_header(); |
|
281 | - // Навигация |
|
282 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
283 | - |
|
284 | - xoops_confirm(['ok' => 1, 'cid' => $cid, 'op' => 'delcat'], 'cat.php', sprintf(_AM_INSTRUCTION_FORMDELCAT, $objInscat->getVar('title'))); |
|
285 | - |
|
286 | - // Текст внизу админки |
|
287 | - include __DIR__ . '/admin_footer.php'; |
|
288 | - } |
|
289 | - |
|
290 | - break; |
|
32 | + case 'main': |
|
33 | + |
|
34 | + // Подключаем трей |
|
35 | + |
|
36 | + // include_once __DIR__ . '/../class/Tree.php'; |
|
37 | + //include_once $GLOBALS['xoops']->path('modules/instruction/class/Tree.php'); |
|
38 | + |
|
39 | + // Заголовок админки |
|
40 | + xoops_cp_header(); |
|
41 | + // Навигация |
|
42 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
43 | + |
|
44 | + // Находим ID-категории => Число страниц |
|
45 | + $cidinstrids = []; |
|
46 | + $sql = "SELECT `cid`, COUNT( `instrid` ) FROM {$instructionHandler->table} GROUP BY `cid`"; |
|
47 | + $result = $GLOBALS['xoopsDB']->query($sql); |
|
48 | + while (list($cid, $count) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
|
49 | + // Заполняем массив |
|
50 | + $cidinstrids[$cid] = $count; |
|
51 | + } |
|
52 | + |
|
53 | + // Выбираем категории из БД |
|
54 | + $criteria = new \CriteriaCompo(); |
|
55 | + $criteria->setSort('weight ASC, title'); |
|
56 | + $criteria->setOrder('ASC'); |
|
57 | + $ins_cat = $categoryHandler->getall($criteria); |
|
58 | + unset($criteria); |
|
59 | + |
|
60 | + // Инициализируем |
|
61 | + $cattree = new instruction\Tree($ins_cat, 'cid', 'pid'); |
|
62 | + // Выводим списко категорий в шаблон |
|
63 | + $GLOBALS['xoopsTpl']->assign('insListCat', $cattree->makeCatsAdmin('--', $cidinstrids)); |
|
64 | + |
|
65 | + // Создание новой категории |
|
66 | + $objInstructioncat = $categoryHandler->create(); |
|
67 | + $form = $objInstructioncat->getForm('cat.php'); |
|
68 | + // Форма |
|
69 | + $GLOBALS['xoopsTpl']->assign('insFormCat', $form->render()); |
|
70 | + // Выводим шаблон |
|
71 | + $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_cat.tpl'); |
|
72 | + |
|
73 | + // Текст внизу админки |
|
74 | + include __DIR__ . '/admin_footer.php'; |
|
75 | + |
|
76 | + break; |
|
77 | + |
|
78 | + // Редактирование категории |
|
79 | + case 'editcat': |
|
80 | + |
|
81 | + // Заголовок админки |
|
82 | + xoops_cp_header(); |
|
83 | + // Навигация |
|
84 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
85 | + |
|
86 | + $objInstructioncat = $categoryHandler->get($cid); |
|
87 | + $form = $objInstructioncat->getForm('cat.php'); |
|
88 | + // Форма |
|
89 | + //$GLOBALS['xoopsTpl']->assign( 'insFormCat', $form->render() ); |
|
90 | + echo $form->render(); |
|
91 | + // Выводим шаблон |
|
92 | + $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_editcat.tpl'); |
|
93 | + |
|
94 | + // Текст внизу админки |
|
95 | + include __DIR__ . '/admin_footer.php'; |
|
96 | + |
|
97 | + break; |
|
98 | + |
|
99 | + // Сохранение категорий |
|
100 | + case 'savecat': |
|
101 | + |
|
102 | + // Проверка |
|
103 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
104 | + redirect_header('cat.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
105 | + } |
|
106 | + // Если мы редактируем |
|
107 | + if ($cid) { |
|
108 | + $objInstructioncat = $categoryHandler->get($cid); |
|
109 | + } else { |
|
110 | + $objInstructioncat = $categoryHandler->create(); |
|
111 | + // Указываем дату создания |
|
112 | + $objInstructioncat->setVar('datecreated', $time); |
|
113 | + } |
|
114 | + |
|
115 | + $err = false; |
|
116 | + $message_err = ''; |
|
117 | + |
|
118 | + // Дата обновления |
|
119 | + $objInstructioncat->setVar('dateupdated', $time); |
|
120 | + $objInstructioncat->setVar('pid', $pid); |
|
121 | + $objInstructioncat->setVar('title', Request::getString('title', '', 'POST')); |
|
122 | + $objInstructioncat->setVar('description', Request::getString('description', '', 'POST')); |
|
123 | + $objInstructioncat->setVar('weight', $weight); |
|
124 | + $objInstructioncat->setVar('metakeywords', Request::getString('metakeywords', '', 'POST')); |
|
125 | + $objInstructioncat->setVar('metadescription', Request::getString('metadescription', '', 'POST')); |
|
126 | + |
|
127 | + // Проверка веса |
|
128 | + if (0 == $weight) { |
|
129 | + $err = true; |
|
130 | + $message_err .= _AM_INSTRUCTION_ERR_WEIGHT . '<br>'; |
|
131 | + } |
|
132 | + // Проверка категорий |
|
133 | + if ($cid && ($cid == $pid)) { |
|
134 | + $err = true; |
|
135 | + $message_err .= _AM_INSTRUCTION_ERR_PCAT . '<br>'; |
|
136 | + } |
|
137 | + // Если были ошибки |
|
138 | + if (true === $err) { |
|
139 | + xoops_cp_header(); |
|
140 | + // Навигация |
|
141 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
142 | + |
|
143 | + $message_err = '<div class="errorMsg" style="text-align: left;">' . $message_err . '</div>'; |
|
144 | + // Выводим ошибки в шаблон |
|
145 | + $GLOBALS['xoopsTpl']->assign('insErrorMsg', $message_err); |
|
146 | + // Если небыло ошибок |
|
147 | + } else { |
|
148 | + // Вставляем данные в БД |
|
149 | + if ($categoryHandler->insert($objInstructioncat)) { |
|
150 | + |
|
151 | + // ID категории. Если редактируем - то не изменяется. Если создаём новую - то получаем ID созданной записи. |
|
152 | + $new_cid = $cid ?: $objInstructioncat->getNewInstertId(); |
|
153 | + |
|
154 | + // =============== |
|
155 | + // ==== Права ==== |
|
156 | + // =============== |
|
157 | + |
|
158 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
159 | + |
|
160 | + // Если мы редактируем категорию, то старые права нужно удалить |
|
161 | + if ($cid) { |
|
162 | + // Права на просмотр |
|
163 | + $criteria = new\ CriteriaCompo(); |
|
164 | + $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
165 | + $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
166 | + $criteria->add(new \Criteria('gperm_name', 'instruction_view', '=')); |
|
167 | + $gpermHandler->deleteAll($criteria); |
|
168 | + // Права на добавление |
|
169 | + $criteria = new \CriteriaCompo(); |
|
170 | + $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
171 | + $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
172 | + $criteria->add(new \Criteria('gperm_name', 'instruction_submit', '=')); |
|
173 | + $gpermHandler->deleteAll($criteria); |
|
174 | + // Права на редактирование |
|
175 | + $criteria = new \CriteriaCompo(); |
|
176 | + $criteria->add(new \Criteria('gperm_itemid', $new_cid, '=')); |
|
177 | + $criteria->add(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'), '=')); |
|
178 | + $criteria->add(new \Criteria('gperm_name', 'instruction_edit', '=')); |
|
179 | + $gpermHandler->deleteAll($criteria); |
|
180 | + } |
|
181 | + |
|
182 | + // Добавляем права |
|
183 | + // Права на просмотр |
|
184 | + if (Request::hasVar('groups_instr_view', 'POST')) { |
|
185 | + foreach (Request::getArray('groups_instr_view', '', 'POST') as $onegroup_id) { |
|
186 | + $gpermHandler->addRight('instruction_view', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
187 | + } |
|
188 | + } |
|
189 | + // Права на добавление |
|
190 | + if (Request::hasVar('groups_instr_submit', 'POST')) { |
|
191 | + foreach (Request::getArray('groups_instr_submit', '', 'POST') as $onegroup_id) { |
|
192 | + $gpermHandler->addRight('instruction_submit', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
193 | + } |
|
194 | + } |
|
195 | + // Права на редактирование |
|
196 | + if (Request::hasVar('groups_instr_edit', 'POST')) { |
|
197 | + foreach (Request::getArray('groups_instr_edit', '', 'POST') as $onegroup_id) { |
|
198 | + $gpermHandler->addRight('instruction_edit', $new_cid, $onegroup_id, $GLOBALS['xoopsModule']->getVar('mid')); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + // |
|
203 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_NEWCATADDED); |
|
204 | + } |
|
205 | + xoops_cp_header(); |
|
206 | + // Навигация |
|
207 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
208 | + // Выводим ошибки в шаблон |
|
209 | + $GLOBALS['xoopsTpl']->assign('insErrorMsg', $objInstructioncat->getHtmlErrors()); |
|
210 | + } |
|
211 | + // Выводим шаблон |
|
212 | + $GLOBALS['xoopsTpl']->display('db:admin/instruction_admin_savecat.tpl'); |
|
213 | + // Выводим форму |
|
214 | + $form = $objInstructioncat->getForm(); |
|
215 | + // Форма |
|
216 | + echo $form->render(); |
|
217 | + // Текст внизу админки |
|
218 | + include __DIR__ . '/admin_footer.php'; |
|
219 | + |
|
220 | + break; |
|
221 | + |
|
222 | + // Удаление категории |
|
223 | + case 'delcat': |
|
224 | + |
|
225 | + // Находим число инструкций в данной категории |
|
226 | + // Критерий выборки |
|
227 | + $criteria = new \CriteriaCompo(); |
|
228 | + // Все инструкции в данной категории |
|
229 | + $criteria->add(new \Criteria('cid', $cid, '=')); |
|
230 | + $numrows = $instructionHandler->getCount($criteria); |
|
231 | + // |
|
232 | + unset($criteria); |
|
233 | + // Если есть хоть одна инструкция |
|
234 | + if ($numrows) { |
|
235 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATNOTEMPTY); |
|
236 | + } |
|
237 | + |
|
238 | + $objInscat = $categoryHandler->get($cid); |
|
239 | + // Если нет такой категории |
|
240 | + if (!is_object($objInscat)) { |
|
241 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATNOTSELECT); |
|
242 | + } |
|
243 | + |
|
244 | + // Нельзя удалять пока есть доченрии категории |
|
245 | + // Подключаем трей |
|
246 | + include_once $GLOBALS['xoops']->path('class/tree.php'); |
|
247 | + $inscat_arr = $categoryHandler->getall(); |
|
248 | + $mytree = new \XoopsObjectTree($inscat_arr, 'cid', 'pid'); |
|
249 | + $ins_childcat = $mytree->getAllChild($cid); |
|
250 | + // Если есть дочернии категории |
|
251 | + if (count($ins_childcat)) { |
|
252 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_CATCHILDREN); |
|
253 | + } |
|
254 | + |
|
255 | + // Нажали ли мы на кнопку OK |
|
256 | + $ok = Request::getInt('ok', 0, 'POST'); |
|
257 | + // Если мы нажали на кнопку |
|
258 | + if ($ok) { |
|
259 | + |
|
260 | + // Проверка |
|
261 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
262 | + redirect_header('cat.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
263 | + } |
|
264 | + // Пытаемся удалить категорию |
|
265 | + if ($categoryHandler->delete($objInscat)) { |
|
266 | + |
|
267 | + // Удалить права доступа к категории |
|
268 | + // ================================= |
|
269 | + |
|
270 | + // Редирект |
|
271 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_CATDELETED); |
|
272 | + // Если не смогли удалить категорию |
|
273 | + } else { |
|
274 | + // Редирект |
|
275 | + redirect_header('cat.php', 3, _AM_INSTRUCTION_ERR_DELCAT); |
|
276 | + } |
|
277 | + } else { |
|
278 | + |
|
279 | + // Заголовок админки |
|
280 | + xoops_cp_header(); |
|
281 | + // Навигация |
|
282 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
283 | + |
|
284 | + xoops_confirm(['ok' => 1, 'cid' => $cid, 'op' => 'delcat'], 'cat.php', sprintf(_AM_INSTRUCTION_FORMDELCAT, $objInscat->getVar('title'))); |
|
285 | + |
|
286 | + // Текст внизу админки |
|
287 | + include __DIR__ . '/admin_footer.php'; |
|
288 | + } |
|
289 | + |
|
290 | + break; |
|
291 | 291 | |
292 | 292 | } |