1
|
|
|
<?php namespace Xoopsmodules\instruction; |
2
|
|
|
|
3
|
|
|
//if (!defined("XOOPS_ROOT_PATH")) { |
|
|
|
|
4
|
|
|
// die("XOOPS root path not defined"); |
5
|
|
|
//} |
6
|
|
|
|
7
|
|
|
include_once $GLOBALS['xoops']->path('include/common.php'); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Page |
11
|
|
|
* @package Xoopsmodules\instruction |
12
|
|
|
*/ |
13
|
|
|
class Page extends \XoopsObject |
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
|
|
|
$criteria = new \CriteriaCompo(); |
79
|
|
|
// ID инструкции в которой данная страница |
80
|
|
|
$instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid'); |
81
|
|
|
// Находим все страницы данной инструкции |
82
|
|
|
$criteria->add(new \Criteria('instrid', $instrid_page, '=')); |
83
|
|
|
// Если мы редактируем, то убрать текущую страницу из списка выбора родительской |
84
|
|
|
if (!$this->isNew()) { |
85
|
|
|
$criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>')); |
86
|
|
|
} |
87
|
|
|
$criteria->setSort('weight'); |
88
|
|
|
$criteria->setOrder('ASC'); |
89
|
|
|
$inspage_arr = $pageHandler->getall($criteria); |
|
|
|
|
90
|
|
|
unset($criteria); |
91
|
|
|
// Подключаем трей |
92
|
|
|
include_once $GLOBALS['xoops']->path('class/tree.php'); |
93
|
|
|
$mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid'); |
94
|
|
|
|
95
|
|
|
// $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
|
|
|
|
96
|
|
|
$helper = Helper::getInstance(); |
97
|
|
|
$module = $helper->getModule(); |
98
|
|
|
|
99
|
|
View Code Duplication |
if (Utility::checkVerXoops($module, '2.5.9')) { |
|
|
|
|
100
|
|
|
$mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC); |
101
|
|
|
$form->addElement($mytree_select); |
102
|
|
|
} else { |
103
|
|
|
$form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true))); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// Вес |
107
|
|
|
$form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true); |
108
|
|
|
// Основной текст |
109
|
|
|
$form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true); |
110
|
|
|
// Сноска |
111
|
|
|
$form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e')); |
112
|
|
|
$form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC); |
113
|
|
|
$form->addElement($form_footnote, false); |
114
|
|
|
unset($form_footnote); |
115
|
|
|
// Статус |
116
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false); |
117
|
|
|
// Тип страницы |
118
|
|
|
$form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type')); |
119
|
|
|
$form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC); |
120
|
|
|
$form_type->addOptionArray($pagetypes); |
121
|
|
|
$form->addElement($form_type, false); |
122
|
|
|
// Мета-теги ключевых слов |
123
|
|
|
$form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false); |
124
|
|
|
// Мета-теги описания |
125
|
|
|
$form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false); |
126
|
|
|
|
127
|
|
|
// Настройки |
128
|
|
|
$option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>'); |
129
|
|
|
// HTML |
130
|
|
|
$html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml')); |
131
|
|
|
$html_checkbox->addOption(1, _AM_INSTR_DOHTML); |
132
|
|
|
$option_tray->addElement($html_checkbox); |
133
|
|
|
// Смайлы |
134
|
|
|
$smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley')); |
135
|
|
|
$smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY); |
136
|
|
|
$option_tray->addElement($smiley_checkbox); |
137
|
|
|
// ББ коды |
138
|
|
|
$xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode')); |
139
|
|
|
$xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE); |
140
|
|
|
$option_tray->addElement($xcode_checkbox); |
141
|
|
|
// |
142
|
|
|
$br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr')); |
143
|
|
|
$br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP); |
144
|
|
|
$option_tray->addElement($br_checkbox); |
145
|
|
|
// |
146
|
|
|
$form->addElement($option_tray); |
147
|
|
|
|
148
|
|
|
// Если мы редактируем страницу |
149
|
|
|
if (!$this->isNew()) { |
150
|
|
|
$form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid'))); |
151
|
|
|
} else { |
152
|
|
|
$form->addElement(new \XoopsFormHidden('pageid', 0)); |
153
|
|
|
} |
154
|
|
|
// ID инструкции |
155
|
|
|
if ($instrid) { |
156
|
|
|
$form->addElement(new \XoopsFormHidden('instrid', $instrid)); |
157
|
|
|
} else { |
158
|
|
|
$form->addElement(new \XoopsFormHidden('instrid', 0)); |
159
|
|
|
} |
160
|
|
|
// |
161
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'savepage')); |
162
|
|
|
// Кнопка |
163
|
|
|
$button_tray = new \XoopsFormElementTray('', ''); |
164
|
|
|
$button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
165
|
|
|
$save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM); |
166
|
|
|
$save_btn->setExtra('onclick="instrSavePage();"'); |
167
|
|
|
$button_tray->addElement($save_btn); |
168
|
|
|
$form->addElement($button_tray); |
169
|
|
|
|
170
|
|
|
return $form; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return mixed |
177
|
|
|
*/ |
178
|
|
|
public function getInstrid() |
179
|
|
|
{ |
180
|
|
|
// Возвращаем ID инструкции |
181
|
|
|
return $this->getVar('instrid'); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.