@@ -10,66 +10,66 @@ |
||
10 | 10 | |
11 | 11 | class SmartAddTo |
12 | 12 | { |
13 | - public $_layout; |
|
14 | - public $_method; |
|
13 | + public $_layout; |
|
14 | + public $_method; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor of SmartAddTo |
|
18 | - * |
|
19 | - * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
20 | - * @param int $method 0=directpage, 1=popup |
|
21 | - */ |
|
22 | - public function __construct($layout = 0, $method = 1) |
|
23 | - { |
|
24 | - $layout = (int)$layout; |
|
25 | - if ($layout < 0 || $layout > 3) { |
|
26 | - $layout = 0; |
|
27 | - } |
|
28 | - $this->_layout = $layout; |
|
16 | + /** |
|
17 | + * Constructor of SmartAddTo |
|
18 | + * |
|
19 | + * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
20 | + * @param int $method 0=directpage, 1=popup |
|
21 | + */ |
|
22 | + public function __construct($layout = 0, $method = 1) |
|
23 | + { |
|
24 | + $layout = (int)$layout; |
|
25 | + if ($layout < 0 || $layout > 3) { |
|
26 | + $layout = 0; |
|
27 | + } |
|
28 | + $this->_layout = $layout; |
|
29 | 29 | |
30 | - $method = (int)$method; |
|
31 | - if ($method < 0 || $method > 1) { |
|
32 | - $method = 1; |
|
33 | - } |
|
34 | - $this->_method = $method; |
|
35 | - } |
|
30 | + $method = (int)$method; |
|
31 | + if ($method < 0 || $method > 1) { |
|
32 | + $method = 1; |
|
33 | + } |
|
34 | + $this->_method = $method; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param bool $fetchOnly |
|
39 | - * @return mixed|string|void |
|
40 | - */ |
|
41 | - public function render($fetchOnly = false) |
|
42 | - { |
|
43 | - global $xoTheme, $xoopsTpl; |
|
37 | + /** |
|
38 | + * @param bool $fetchOnly |
|
39 | + * @return mixed|string|void |
|
40 | + */ |
|
41 | + public function render($fetchOnly = false) |
|
42 | + { |
|
43 | + global $xoTheme, $xoopsTpl; |
|
44 | 44 | |
45 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
45 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
46 | 46 | |
47 | - $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
48 | - $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
47 | + $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
48 | + $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
49 | 49 | |
50 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
50 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
51 | 51 | |
52 | - if ($fetchOnly) { |
|
53 | - return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
54 | - } else { |
|
55 | - $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
56 | - } |
|
57 | - } |
|
52 | + if ($fetchOnly) { |
|
53 | + return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
54 | + } else { |
|
55 | + $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function renderForBlock() |
|
63 | - { |
|
64 | - global $xoTheme; |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function renderForBlock() |
|
63 | + { |
|
64 | + global $xoTheme; |
|
65 | 65 | |
66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
67 | 67 | |
68 | - $block = []; |
|
69 | - $block['smartobject_addto_method'] = $this->_method; |
|
70 | - $block['smartobject_addto_layout'] = $this->_layout; |
|
71 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
68 | + $block = []; |
|
69 | + $block['smartobject_addto_method'] = $this->_method; |
|
70 | + $block['smartobject_addto_layout'] = $this->_layout; |
|
71 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
72 | 72 | |
73 | - return $block; |
|
74 | - } |
|
73 | + return $block; |
|
74 | + } |
|
75 | 75 | } |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __construct($layout = 0, $method = 1) |
23 | 23 | { |
24 | - $layout = (int)$layout; |
|
24 | + $layout = (int) $layout; |
|
25 | 25 | if ($layout < 0 || $layout > 3) { |
26 | 26 | $layout = 0; |
27 | 27 | } |
28 | 28 | $this->_layout = $layout; |
29 | 29 | |
30 | - $method = (int)$method; |
|
30 | + $method = (int) $method; |
|
31 | 31 | if ($method < 0 || $method > 1) { |
32 | 32 | $method = 1; |
33 | 33 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | { |
43 | 43 | global $xoTheme, $xoopsTpl; |
44 | 44 | |
45 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
45 | + $xoTheme->addStylesheet(SMARTOBJECT_URL.'include/addto/addto.css'); |
|
46 | 46 | |
47 | 47 | $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
48 | 48 | $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
49 | 49 | |
50 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
50 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL.'include/addto/'); |
|
51 | 51 | |
52 | 52 | if ($fetchOnly) { |
53 | 53 | return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | { |
64 | 64 | global $xoTheme; |
65 | 65 | |
66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL.'include/addto/addto.css'); |
|
67 | 67 | |
68 | 68 | $block = []; |
69 | 69 | $block['smartobject_addto_method'] = $this->_method; |
70 | 70 | $block['smartobject_addto_layout'] = $this->_layout; |
71 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
71 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL.'include/addto/'; |
|
72 | 72 | |
73 | 73 | return $block; |
74 | 74 | } |
@@ -11,45 +11,45 @@ |
||
11 | 11 | |
12 | 12 | class SmartTip |
13 | 13 | { |
14 | - public $id; |
|
15 | - public $caption; |
|
16 | - public $message; |
|
17 | - public $visible; |
|
18 | - public $_tpl; |
|
14 | + public $id; |
|
15 | + public $caption; |
|
16 | + public $message; |
|
17 | + public $visible; |
|
18 | + public $_tpl; |
|
19 | 19 | |
20 | - /** |
|
21 | - * SmartTip constructor. |
|
22 | - * @param $id |
|
23 | - * @param $caption |
|
24 | - * @param $message |
|
25 | - * @param bool $visible |
|
26 | - */ |
|
27 | - public function __construct($id, $caption, $message, $visible = false) |
|
28 | - { |
|
29 | - $this->id = $id; |
|
30 | - $this->caption = $caption; |
|
31 | - $this->message = $message; |
|
32 | - $this->visible = $visible; |
|
33 | - $this->_tpl = new XoopsTpl(); |
|
34 | - } |
|
20 | + /** |
|
21 | + * SmartTip constructor. |
|
22 | + * @param $id |
|
23 | + * @param $caption |
|
24 | + * @param $message |
|
25 | + * @param bool $visible |
|
26 | + */ |
|
27 | + public function __construct($id, $caption, $message, $visible = false) |
|
28 | + { |
|
29 | + $this->id = $id; |
|
30 | + $this->caption = $caption; |
|
31 | + $this->message = $message; |
|
32 | + $this->visible = $visible; |
|
33 | + $this->_tpl = new XoopsTpl(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param bool $outputNow |
|
38 | - * @return mixed|string|void |
|
39 | - */ |
|
40 | - public function render($outputNow = true) |
|
41 | - { |
|
42 | - $aTip = [ |
|
43 | - 'id' => $this->id, |
|
44 | - 'caption' => $this->caption, |
|
45 | - 'message' => $this->message, |
|
46 | - 'visible' => $this->visible ? 'block' : 'none' |
|
47 | - ]; |
|
48 | - $this->_tpl->assign('tip', $aTip); |
|
49 | - if ($outputNow) { |
|
50 | - $this->_tpl->display('db:smartobject_tip.tpl'); |
|
51 | - } else { |
|
52 | - return $this->_tpl->fetch('db:smartobject_tip.tpl'); |
|
53 | - } |
|
54 | - } |
|
36 | + /** |
|
37 | + * @param bool $outputNow |
|
38 | + * @return mixed|string|void |
|
39 | + */ |
|
40 | + public function render($outputNow = true) |
|
41 | + { |
|
42 | + $aTip = [ |
|
43 | + 'id' => $this->id, |
|
44 | + 'caption' => $this->caption, |
|
45 | + 'message' => $this->message, |
|
46 | + 'visible' => $this->visible ? 'block' : 'none' |
|
47 | + ]; |
|
48 | + $this->_tpl->assign('tip', $aTip); |
|
49 | + if ($outputNow) { |
|
50 | + $this->_tpl->display('db:smartobject_tip.tpl'); |
|
51 | + } else { |
|
52 | + return $this->_tpl->fetch('db:smartobject_tip.tpl'); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
31 | 31 | |
32 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
32 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Class SmartobjectBasedUrl |
@@ -21,84 +21,84 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class SmartObjectColumn |
23 | 23 | { |
24 | - public $_keyname; |
|
25 | - public $_align; |
|
26 | - public $_width; |
|
27 | - public $_customMethodForValue; |
|
28 | - public $_extraParams; |
|
29 | - public $_sortable; |
|
30 | - public $_customCaption; |
|
31 | - |
|
32 | - /** |
|
33 | - * SmartObjectColumn constructor. |
|
34 | - * @param $keyname |
|
35 | - * @param string $align |
|
36 | - * @param bool $width |
|
37 | - * @param bool $customMethodForValue |
|
38 | - * @param bool $param |
|
39 | - * @param bool $customCaption |
|
40 | - * @param bool $sortable |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - $keyname, |
|
44 | - $align = 'left', |
|
45 | - $width = false, |
|
46 | - $customMethodForValue = false, |
|
47 | - $param = false, |
|
48 | - $customCaption = false, |
|
49 | - $sortable = true |
|
50 | - ) { |
|
51 | - $this->_keyname = $keyname; |
|
52 | - $this->_align = $align; |
|
53 | - $this->_width = $width; |
|
54 | - $this->_customMethodForValue = $customMethodForValue; |
|
55 | - $this->_sortable = $sortable; |
|
56 | - $this->_param = $param; |
|
57 | - $this->_customCaption = $customCaption; |
|
58 | - } |
|
59 | - |
|
60 | - public function getKeyName() |
|
61 | - { |
|
62 | - return $this->_keyname; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getAlign() |
|
69 | - { |
|
70 | - return $this->_align; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function isSortable() |
|
77 | - { |
|
78 | - return $this->_sortable; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return bool|string |
|
83 | - */ |
|
84 | - public function getWidth() |
|
85 | - { |
|
86 | - if ($this->_width) { |
|
87 | - $ret = $this->_width; |
|
88 | - } else { |
|
89 | - $ret = ''; |
|
90 | - } |
|
91 | - |
|
92 | - return $ret; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return bool |
|
97 | - */ |
|
98 | - public function getCustomCaption() |
|
99 | - { |
|
100 | - return $this->_customCaption; |
|
101 | - } |
|
24 | + public $_keyname; |
|
25 | + public $_align; |
|
26 | + public $_width; |
|
27 | + public $_customMethodForValue; |
|
28 | + public $_extraParams; |
|
29 | + public $_sortable; |
|
30 | + public $_customCaption; |
|
31 | + |
|
32 | + /** |
|
33 | + * SmartObjectColumn constructor. |
|
34 | + * @param $keyname |
|
35 | + * @param string $align |
|
36 | + * @param bool $width |
|
37 | + * @param bool $customMethodForValue |
|
38 | + * @param bool $param |
|
39 | + * @param bool $customCaption |
|
40 | + * @param bool $sortable |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + $keyname, |
|
44 | + $align = 'left', |
|
45 | + $width = false, |
|
46 | + $customMethodForValue = false, |
|
47 | + $param = false, |
|
48 | + $customCaption = false, |
|
49 | + $sortable = true |
|
50 | + ) { |
|
51 | + $this->_keyname = $keyname; |
|
52 | + $this->_align = $align; |
|
53 | + $this->_width = $width; |
|
54 | + $this->_customMethodForValue = $customMethodForValue; |
|
55 | + $this->_sortable = $sortable; |
|
56 | + $this->_param = $param; |
|
57 | + $this->_customCaption = $customCaption; |
|
58 | + } |
|
59 | + |
|
60 | + public function getKeyName() |
|
61 | + { |
|
62 | + return $this->_keyname; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getAlign() |
|
69 | + { |
|
70 | + return $this->_align; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function isSortable() |
|
77 | + { |
|
78 | + return $this->_sortable; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return bool|string |
|
83 | + */ |
|
84 | + public function getWidth() |
|
85 | + { |
|
86 | + if ($this->_width) { |
|
87 | + $ret = $this->_width; |
|
88 | + } else { |
|
89 | + $ret = ''; |
|
90 | + } |
|
91 | + |
|
92 | + return $ret; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return bool |
|
97 | + */ |
|
98 | + public function getCustomCaption() |
|
99 | + { |
|
100 | + return $this->_customCaption; |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -112,805 +112,805 @@ discard block |
||
112 | 112 | */ |
113 | 113 | class SmartObjectTable |
114 | 114 | { |
115 | - public $_id; |
|
116 | - public $_objectHandler; |
|
117 | - public $_columns; |
|
118 | - public $_criteria; |
|
119 | - public $_actions; |
|
120 | - public $_objects = false; |
|
121 | - public $_aObjects; |
|
122 | - public $_custom_actions; |
|
123 | - public $_sortsel; |
|
124 | - public $_ordersel; |
|
125 | - public $_limitsel; |
|
126 | - public $_filtersel; |
|
127 | - public $_filterseloptions; |
|
128 | - public $_filtersel2; |
|
129 | - public $_filtersel2options; |
|
130 | - public $_filtersel2optionsDefault; |
|
131 | - |
|
132 | - public $_tempObject; |
|
133 | - public $_tpl; |
|
134 | - public $_introButtons; |
|
135 | - public $_quickSearch = false; |
|
136 | - public $_actionButtons = false; |
|
137 | - public $_head_css_class = 'bg3'; |
|
138 | - public $_hasActions = false; |
|
139 | - public $_userSide = false; |
|
140 | - public $_printerFriendlyPage = false; |
|
141 | - public $_tableHeader = false; |
|
142 | - public $_tableFooter = false; |
|
143 | - public $_showActionsColumnTitle = true; |
|
144 | - public $_isTree = false; |
|
145 | - public $_showFilterAndLimit = true; |
|
146 | - public $_enableColumnsSorting = true; |
|
147 | - public $_customTemplate = false; |
|
148 | - public $_withSelectedActions = []; |
|
149 | - |
|
150 | - /** |
|
151 | - * Constructor |
|
152 | - * |
|
153 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
154 | - * @param CriteriaElement $criteria |
|
155 | - * @param array $actions array representing the actions to offer |
|
156 | - * |
|
157 | - * @param bool $userSide |
|
158 | - */ |
|
159 | - public function __construct( |
|
160 | - SmartPersistableObjectHandler $objectHandler, |
|
161 | - CriteriaElement $criteria = null, |
|
162 | - $actions = ['edit', 'delete'], |
|
163 | - $userSide = false |
|
164 | - ) { |
|
165 | - $this->_id = $objectHandler->className; |
|
166 | - $this->_objectHandler = $objectHandler; |
|
167 | - |
|
168 | - if (!$criteria) { |
|
169 | - $criteria = new CriteriaCompo(); |
|
170 | - } |
|
171 | - $this->_criteria = $criteria; |
|
172 | - $this->_actions = $actions; |
|
173 | - $this->_custom_actions = []; |
|
174 | - $this->_userSide = $userSide; |
|
175 | - if ($userSide) { |
|
176 | - $this->_head_css_class = 'head'; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param $op |
|
182 | - * @param bool $caption |
|
183 | - * @param bool $text |
|
184 | - */ |
|
185 | - public function addActionButton($op, $caption = false, $text = false) |
|
186 | - { |
|
187 | - $action = [ |
|
188 | - 'op' => $op, |
|
189 | - 'caption' => $caption, |
|
190 | - 'text' => $text |
|
191 | - ]; |
|
192 | - $this->_actionButtons[] = $action; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param $columnObj |
|
197 | - */ |
|
198 | - public function addColumn($columnObj) |
|
199 | - { |
|
200 | - $this->_columns[] = $columnObj; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param $name |
|
205 | - * @param $location |
|
206 | - * @param $value |
|
207 | - */ |
|
208 | - public function addIntroButton($name, $location, $value) |
|
209 | - { |
|
210 | - $introButton = []; |
|
211 | - $introButton['name'] = $name; |
|
212 | - $introButton['location'] = $location; |
|
213 | - $introButton['value'] = $value; |
|
214 | - $this->_introButtons[] = $introButton; |
|
215 | - unset($introButton); |
|
216 | - } |
|
217 | - |
|
218 | - public function addPrinterFriendlyLink() |
|
219 | - { |
|
220 | - $current_urls = smart_getCurrentUrls(); |
|
221 | - $current_url = $current_urls['full']; |
|
222 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param $fields |
|
227 | - * @param string $caption |
|
228 | - */ |
|
229 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
230 | - { |
|
231 | - $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @param $content |
|
236 | - */ |
|
237 | - public function addHeader($content) |
|
238 | - { |
|
239 | - $this->_tableHeader = $content; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @param $content |
|
244 | - */ |
|
245 | - public function addFooter($content) |
|
246 | - { |
|
247 | - $this->_tableFooter = $content; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @param $caption |
|
252 | - */ |
|
253 | - public function addDefaultIntroButton($caption) |
|
254 | - { |
|
255 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @param $method |
|
260 | - */ |
|
261 | - public function addCustomAction($method) |
|
262 | - { |
|
263 | - $this->_custom_actions[] = $method; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @param $default_sort |
|
268 | - */ |
|
269 | - public function setDefaultSort($default_sort) |
|
270 | - { |
|
271 | - $this->_sortsel = $default_sort; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function getDefaultSort() |
|
278 | - { |
|
279 | - if ($this->_sortsel) { |
|
280 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
281 | - } else { |
|
282 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $default_order |
|
288 | - */ |
|
289 | - public function setDefaultOrder($default_order) |
|
290 | - { |
|
291 | - $this->_ordersel = $default_order; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function getDefaultOrder() |
|
298 | - { |
|
299 | - if ($this->_ordersel) { |
|
300 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
301 | - } else { |
|
302 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * @param array $actions |
|
308 | - */ |
|
309 | - public function addWithSelectedActions($actions = []) |
|
310 | - { |
|
311 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
312 | - $this->_withSelectedActions = $actions; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Adding a filter in the table |
|
317 | - * |
|
318 | - * @param string $key key to the field that will be used for sorting |
|
319 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
320 | - * @param bool $default |
|
321 | - */ |
|
322 | - public function addFilter($key, $method, $default = false) |
|
323 | - { |
|
324 | - $this->_filterseloptions[$key] = $method; |
|
325 | - $this->_filtersel2optionsDefault = $default; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @param $default_filter |
|
330 | - */ |
|
331 | - public function setDefaultFilter($default_filter) |
|
332 | - { |
|
333 | - $this->_filtersel = $default_filter; |
|
334 | - } |
|
335 | - |
|
336 | - public function isForUserSide() |
|
337 | - { |
|
338 | - $this->_userSide = true; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @param $template |
|
343 | - */ |
|
344 | - public function setCustomTemplate($template) |
|
345 | - { |
|
346 | - $this->_customTemplate = $template; |
|
347 | - } |
|
348 | - |
|
349 | - public function setSortOrder() |
|
350 | - { |
|
351 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
352 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
353 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
354 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
355 | - |
|
356 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
357 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
358 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
359 | - } else { |
|
360 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
361 | - } |
|
362 | - |
|
363 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
364 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
365 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
366 | - $ordersArray = $this->getOrdersArray(); |
|
367 | - $this->_criteria->setOrder($this->_ordersel); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * @param $id |
|
372 | - */ |
|
373 | - public function setTableId($id) |
|
374 | - { |
|
375 | - $this->_id = $id; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * @param $objects |
|
380 | - */ |
|
381 | - public function setObjects($objects) |
|
382 | - { |
|
383 | - $this->_objects = $objects; |
|
384 | - } |
|
385 | - |
|
386 | - public function createTableRows() |
|
387 | - { |
|
388 | - $this->_aObjects = []; |
|
389 | - |
|
390 | - $doWeHaveActions = false; |
|
391 | - |
|
392 | - $objectclass = 'odd'; |
|
393 | - if (count($this->_objects) > 0) { |
|
394 | - foreach ($this->_objects as $object) { |
|
395 | - $aObject = []; |
|
396 | - |
|
397 | - $i = 0; |
|
398 | - |
|
399 | - $aColumns = []; |
|
400 | - |
|
401 | - foreach ($this->_columns as $column) { |
|
402 | - $aColumn = []; |
|
403 | - |
|
404 | - if ($i == 0) { |
|
405 | - $class = 'head'; |
|
406 | - } elseif ($i % 2 == 0) { |
|
407 | - $class = 'even'; |
|
408 | - } else { |
|
409 | - $class = 'odd'; |
|
410 | - } |
|
411 | - if (method_exists($object, 'initiateCustomFields')) { |
|
412 | - //$object->initiateCustomFields(); |
|
413 | - } |
|
414 | - if ($column->_keyname === 'checked') { |
|
415 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
416 | - } elseif ($column->_customMethodForValue |
|
417 | - && method_exists($object, $column->_customMethodForValue)) { |
|
418 | - $method = $column->_customMethodForValue; |
|
419 | - if ($column->_param) { |
|
420 | - $value = $object->$method($column->_param); |
|
421 | - } else { |
|
422 | - $value = $object->$method(); |
|
423 | - } |
|
424 | - } else { |
|
425 | - /** |
|
426 | - * If the column is the identifier, then put a link on it |
|
427 | - */ |
|
428 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
429 | - $value = $object->getItemLink(); |
|
430 | - } else { |
|
431 | - $value = $object->getVar($column->getKeyName()); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - $aColumn['value'] = $value; |
|
436 | - $aColumn['class'] = $class; |
|
437 | - $aColumn['width'] = $column->getWidth(); |
|
438 | - $aColumn['align'] = $column->getAlign(); |
|
439 | - |
|
440 | - $aColumns[] = $aColumn; |
|
441 | - ++$i; |
|
442 | - } |
|
443 | - |
|
444 | - $aObject['columns'] = $aColumns; |
|
445 | - $aObject['id'] = $object->id(); |
|
446 | - |
|
447 | - $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
448 | - |
|
449 | - $aObject['class'] = $objectclass; |
|
450 | - |
|
451 | - $actions = []; |
|
452 | - |
|
453 | - // Adding the custom actions if any |
|
454 | - foreach ($this->_custom_actions as $action) { |
|
455 | - if (method_exists($object, $action)) { |
|
456 | - $actions[] = $object->$action(); |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
461 | - $controller = new SmartObjectController($this->_objectHandler); |
|
462 | - |
|
463 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
464 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
465 | - } |
|
466 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
467 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
468 | - } |
|
469 | - $aObject['actions'] = $actions; |
|
470 | - |
|
471 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
472 | - |
|
473 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
474 | - |
|
475 | - $this->_aObjects[] = $aObject; |
|
476 | - } |
|
477 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
478 | - } else { |
|
479 | - $colspan = count($this->_columns) + 1; |
|
480 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
481 | - } |
|
482 | - $this->_hasActions = $doWeHaveActions; |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * @param bool $debug |
|
487 | - * @return mixed |
|
488 | - */ |
|
489 | - public function fetchObjects($debug = false) |
|
490 | - { |
|
491 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function getDefaultFilter() |
|
498 | - { |
|
499 | - if ($this->_filtersel) { |
|
500 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
501 | - } else { |
|
502 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @return array|bool |
|
508 | - */ |
|
509 | - public function getFiltersArray() |
|
510 | - { |
|
511 | - $ret = []; |
|
512 | - $field = []; |
|
513 | - $field['caption'] = _CO_OBJ_NONE; |
|
514 | - $field['selected'] = ''; |
|
515 | - $ret['default'] = $field; |
|
516 | - unset($field); |
|
517 | - |
|
518 | - if ($this->_filterseloptions) { |
|
519 | - foreach ($this->_filterseloptions as $key => $value) { |
|
520 | - $field = []; |
|
521 | - if (is_array($value)) { |
|
522 | - $field['caption'] = $key; |
|
523 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
524 | - } else { |
|
525 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
526 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
527 | - } |
|
528 | - $ret[$key] = $field; |
|
529 | - unset($field); |
|
530 | - } |
|
531 | - } else { |
|
532 | - $ret = false; |
|
533 | - } |
|
534 | - |
|
535 | - return $ret; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * @param $default_filter2 |
|
540 | - */ |
|
541 | - public function setDefaultFilter2($default_filter2) |
|
542 | - { |
|
543 | - $this->_filtersel2 = $default_filter2; |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - public function getDefaultFilter2() |
|
550 | - { |
|
551 | - if ($this->_filtersel2) { |
|
552 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
553 | - } else { |
|
554 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * @return array |
|
560 | - */ |
|
561 | - public function getFilters2Array() |
|
562 | - { |
|
563 | - $ret = []; |
|
564 | - |
|
565 | - foreach ($this->_filtersel2options as $key => $value) { |
|
566 | - $field = []; |
|
567 | - $field['caption'] = $value; |
|
568 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
569 | - $ret[$key] = $field; |
|
570 | - unset($field); |
|
571 | - } |
|
572 | - |
|
573 | - return $ret; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * @param $limitsArray |
|
578 | - * @param $params_of_the_options_sel |
|
579 | - */ |
|
580 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
581 | - { |
|
582 | - // Rendering the form to select options on the table |
|
583 | - $current_urls = smart_getCurrentUrls(); |
|
584 | - $current_url = $current_urls['full']; |
|
585 | - |
|
586 | - /** |
|
587 | - * What was $params_of_the_options_sel doing again ? |
|
588 | - */ |
|
589 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
590 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
591 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * @return array |
|
596 | - */ |
|
597 | - public function getLimitsArray() |
|
598 | - { |
|
599 | - $ret = []; |
|
600 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
601 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
602 | - |
|
603 | - $ret['5']['caption'] = '5'; |
|
604 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
605 | - |
|
606 | - $ret['10']['caption'] = '10'; |
|
607 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
608 | - |
|
609 | - $ret['15']['caption'] = '15'; |
|
610 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
611 | - |
|
612 | - $ret['20']['caption'] = '20'; |
|
613 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
614 | - |
|
615 | - $ret['25']['caption'] = '25'; |
|
616 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
617 | - |
|
618 | - $ret['30']['caption'] = '30'; |
|
619 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
620 | - |
|
621 | - $ret['35']['caption'] = '35'; |
|
622 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
623 | - |
|
624 | - $ret['40']['caption'] = '40'; |
|
625 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
626 | - |
|
627 | - return $ret; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * @return bool |
|
632 | - */ |
|
633 | - public function getObjects() |
|
634 | - { |
|
635 | - return $this->_objects; |
|
636 | - } |
|
637 | - |
|
638 | - public function hideActionColumnTitle() |
|
639 | - { |
|
640 | - $this->_showActionsColumnTitle = false; |
|
641 | - } |
|
642 | - |
|
643 | - public function hideFilterAndLimit() |
|
644 | - { |
|
645 | - $this->_showFilterAndLimit = false; |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * @return array |
|
650 | - */ |
|
651 | - public function getOrdersArray() |
|
652 | - { |
|
653 | - $ret = []; |
|
654 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
655 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
656 | - |
|
657 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
658 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
659 | - |
|
660 | - return $ret; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @return mixed|string|void |
|
665 | - */ |
|
666 | - public function renderD() |
|
667 | - { |
|
668 | - return $this->render(false, true); |
|
669 | - } |
|
670 | - |
|
671 | - public function renderForPrint() |
|
672 | - { |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * @param bool $fetchOnly |
|
677 | - * @param bool $debug |
|
678 | - * @return mixed|string|void |
|
679 | - */ |
|
680 | - public function render($fetchOnly = false, $debug = false) |
|
681 | - { |
|
682 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
683 | - |
|
684 | - $this->_tpl = new XoopsTpl(); |
|
685 | - |
|
686 | - /** |
|
687 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
688 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
689 | - * and we will free it after |
|
690 | - */ |
|
691 | - $this->_tempObject = $this->_objectHandler->create(); |
|
692 | - |
|
693 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
694 | - |
|
695 | - $this->setSortOrder(); |
|
696 | - |
|
697 | - if (!$this->_isTree) { |
|
698 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
699 | - } else { |
|
700 | - $this->_limitsel = 'all'; |
|
701 | - } |
|
702 | - |
|
703 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
704 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
705 | - $limitsArray = $this->getLimitsArray(); |
|
706 | - $this->_criteria->setLimit($this->_limitsel); |
|
707 | - |
|
708 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
709 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
710 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
711 | - $filtersArray = $this->getFiltersArray(); |
|
712 | - |
|
713 | - if ($filtersArray) { |
|
714 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
715 | - } |
|
716 | - |
|
717 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
718 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
719 | - // check if method associate with this filter exists in the handler |
|
720 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
721 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
722 | - $this->_criteria->add($filter['criteria']); |
|
723 | - } else { |
|
724 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
725 | - |
|
726 | - // then we will create the selfilter2 options by calling this method |
|
727 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
728 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
729 | - |
|
730 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
731 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
732 | - |
|
733 | - $filters2Array = $this->getFilters2Array(); |
|
734 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
735 | - |
|
736 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
737 | - if ($this->_filtersel2 !== 'default') { |
|
738 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
739 | - } |
|
740 | - } |
|
741 | - } |
|
742 | - } |
|
743 | - // Check if we have a quicksearch |
|
744 | - |
|
745 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
746 | - $quicksearch_criteria = new CriteriaCompo(); |
|
747 | - if (is_array($this->_quickSearch['fields'])) { |
|
748 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
749 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
750 | - } |
|
751 | - } else { |
|
752 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
753 | - } |
|
754 | - $this->_criteria->add($quicksearch_criteria); |
|
755 | - } |
|
756 | - |
|
757 | - $this->_objects = $this->fetchObjects($debug); |
|
758 | - |
|
759 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
760 | - if ($this->_criteria->getLimit() > 0) { |
|
761 | - |
|
762 | - /** |
|
763 | - * Geeting rid of the old params |
|
764 | - * $new_get_array is an array containing the new GET parameters |
|
765 | - */ |
|
766 | - $new_get_array = []; |
|
767 | - |
|
768 | - /** |
|
769 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
770 | - * but without the pagenave parameters. This array will be used in the |
|
771 | - * OptionsSelection |
|
772 | - */ |
|
773 | - $params_of_the_options_sel = []; |
|
774 | - |
|
775 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
776 | - foreach ($_GET as $k => $v) { |
|
777 | - if (!in_array($k, $not_needed_params)) { |
|
778 | - $new_get_array[] = "$k=$v"; |
|
779 | - $params_of_the_options_sel[] = "$k=$v"; |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * Adding the new params of the pagenav |
|
785 | - */ |
|
786 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
787 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
788 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
789 | - $otherParams = implode('&', $new_get_array); |
|
790 | - |
|
791 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
792 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
793 | - } |
|
794 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
795 | - |
|
796 | - // retreive the current url and the query string |
|
797 | - $current_urls = smart_getCurrentUrls(); |
|
798 | - $current_url = $current_urls['full_phpself']; |
|
799 | - $query_string = $current_urls['querystring']; |
|
800 | - if ($query_string) { |
|
801 | - $query_string = str_replace('?', '', $query_string); |
|
802 | - } |
|
803 | - $query_stringArray = explode('&', $query_string); |
|
804 | - $new_query_stringArray = []; |
|
805 | - foreach ($query_stringArray as $query_string) { |
|
806 | - if (strpos($query_string, 'sortsel') === false && strpos($query_string, 'ordersel') === false) { |
|
807 | - $new_query_stringArray[] = $query_string; |
|
808 | - } |
|
809 | - } |
|
810 | - $new_query_string = implode('&', $new_query_stringArray); |
|
811 | - |
|
812 | - $orderArray = []; |
|
813 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
814 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
815 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
816 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
817 | - |
|
818 | - $aColumns = []; |
|
819 | - |
|
820 | - foreach ($this->_columns as $column) { |
|
821 | - $qs_param = ''; |
|
822 | - $aColumn = []; |
|
823 | - $aColumn['width'] = $column->getWidth(); |
|
824 | - $aColumn['align'] = $column->getAlign(); |
|
825 | - $aColumn['key'] = $column->getKeyName(); |
|
826 | - if ($column->_keyname === 'checked') { |
|
827 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
828 | - } elseif ($column->getCustomCaption()) { |
|
829 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
830 | - } else { |
|
831 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
832 | - } |
|
833 | - // Are we doing a GET sort on this column ? |
|
834 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
835 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
836 | - || ($this->_sortsel == $column->getKeyName()); |
|
837 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
838 | - |
|
839 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
840 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
841 | - } |
|
842 | - if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
843 | - $aColumn['caption'] = $aColumn['caption']; |
|
844 | - } elseif ($getSort) { |
|
845 | - $aColumn['caption'] = '<a href="' |
|
846 | - . $current_url |
|
847 | - . '?' |
|
848 | - . $this->_objectHandler->_itemname |
|
849 | - . '_' |
|
850 | - . 'sortsel=' |
|
851 | - . $column->getKeyName() |
|
852 | - . '&' |
|
853 | - . $this->_objectHandler->_itemname |
|
854 | - . '_' |
|
855 | - . 'ordersel=' |
|
856 | - . $orderArray[$order]['neworder'] |
|
857 | - . $qs_param |
|
858 | - . '&' |
|
859 | - . $new_query_string |
|
860 | - . '">' |
|
861 | - . $aColumn['caption'] |
|
862 | - . ' <img src="' |
|
863 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
864 | - . $orderArray[$order]['image'] |
|
865 | - . '" alt="ASC"></a>'; |
|
866 | - } else { |
|
867 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
868 | - } |
|
869 | - $aColumns[] = $aColumn; |
|
870 | - } |
|
871 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
872 | - |
|
873 | - if ($this->_quickSearch) { |
|
874 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
875 | - } |
|
876 | - |
|
877 | - $this->createTableRows(); |
|
878 | - |
|
879 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
880 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
881 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
882 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
883 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
884 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
885 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
886 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
887 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
888 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
889 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
890 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
891 | - if (!empty($this->_withSelectedActions)) { |
|
892 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
893 | - } |
|
894 | - |
|
895 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
896 | - if ($fetchOnly) { |
|
897 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
898 | - } else { |
|
899 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
900 | - } |
|
901 | - } |
|
902 | - |
|
903 | - public function disableColumnsSorting() |
|
904 | - { |
|
905 | - $this->_enableColumnsSorting = false; |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * @param bool $debug |
|
910 | - * @return mixed|string|void |
|
911 | - */ |
|
912 | - public function fetch($debug = false) |
|
913 | - { |
|
914 | - return $this->render(true, $debug); |
|
915 | - } |
|
115 | + public $_id; |
|
116 | + public $_objectHandler; |
|
117 | + public $_columns; |
|
118 | + public $_criteria; |
|
119 | + public $_actions; |
|
120 | + public $_objects = false; |
|
121 | + public $_aObjects; |
|
122 | + public $_custom_actions; |
|
123 | + public $_sortsel; |
|
124 | + public $_ordersel; |
|
125 | + public $_limitsel; |
|
126 | + public $_filtersel; |
|
127 | + public $_filterseloptions; |
|
128 | + public $_filtersel2; |
|
129 | + public $_filtersel2options; |
|
130 | + public $_filtersel2optionsDefault; |
|
131 | + |
|
132 | + public $_tempObject; |
|
133 | + public $_tpl; |
|
134 | + public $_introButtons; |
|
135 | + public $_quickSearch = false; |
|
136 | + public $_actionButtons = false; |
|
137 | + public $_head_css_class = 'bg3'; |
|
138 | + public $_hasActions = false; |
|
139 | + public $_userSide = false; |
|
140 | + public $_printerFriendlyPage = false; |
|
141 | + public $_tableHeader = false; |
|
142 | + public $_tableFooter = false; |
|
143 | + public $_showActionsColumnTitle = true; |
|
144 | + public $_isTree = false; |
|
145 | + public $_showFilterAndLimit = true; |
|
146 | + public $_enableColumnsSorting = true; |
|
147 | + public $_customTemplate = false; |
|
148 | + public $_withSelectedActions = []; |
|
149 | + |
|
150 | + /** |
|
151 | + * Constructor |
|
152 | + * |
|
153 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
154 | + * @param CriteriaElement $criteria |
|
155 | + * @param array $actions array representing the actions to offer |
|
156 | + * |
|
157 | + * @param bool $userSide |
|
158 | + */ |
|
159 | + public function __construct( |
|
160 | + SmartPersistableObjectHandler $objectHandler, |
|
161 | + CriteriaElement $criteria = null, |
|
162 | + $actions = ['edit', 'delete'], |
|
163 | + $userSide = false |
|
164 | + ) { |
|
165 | + $this->_id = $objectHandler->className; |
|
166 | + $this->_objectHandler = $objectHandler; |
|
167 | + |
|
168 | + if (!$criteria) { |
|
169 | + $criteria = new CriteriaCompo(); |
|
170 | + } |
|
171 | + $this->_criteria = $criteria; |
|
172 | + $this->_actions = $actions; |
|
173 | + $this->_custom_actions = []; |
|
174 | + $this->_userSide = $userSide; |
|
175 | + if ($userSide) { |
|
176 | + $this->_head_css_class = 'head'; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param $op |
|
182 | + * @param bool $caption |
|
183 | + * @param bool $text |
|
184 | + */ |
|
185 | + public function addActionButton($op, $caption = false, $text = false) |
|
186 | + { |
|
187 | + $action = [ |
|
188 | + 'op' => $op, |
|
189 | + 'caption' => $caption, |
|
190 | + 'text' => $text |
|
191 | + ]; |
|
192 | + $this->_actionButtons[] = $action; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param $columnObj |
|
197 | + */ |
|
198 | + public function addColumn($columnObj) |
|
199 | + { |
|
200 | + $this->_columns[] = $columnObj; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param $name |
|
205 | + * @param $location |
|
206 | + * @param $value |
|
207 | + */ |
|
208 | + public function addIntroButton($name, $location, $value) |
|
209 | + { |
|
210 | + $introButton = []; |
|
211 | + $introButton['name'] = $name; |
|
212 | + $introButton['location'] = $location; |
|
213 | + $introButton['value'] = $value; |
|
214 | + $this->_introButtons[] = $introButton; |
|
215 | + unset($introButton); |
|
216 | + } |
|
217 | + |
|
218 | + public function addPrinterFriendlyLink() |
|
219 | + { |
|
220 | + $current_urls = smart_getCurrentUrls(); |
|
221 | + $current_url = $current_urls['full']; |
|
222 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param $fields |
|
227 | + * @param string $caption |
|
228 | + */ |
|
229 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
230 | + { |
|
231 | + $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @param $content |
|
236 | + */ |
|
237 | + public function addHeader($content) |
|
238 | + { |
|
239 | + $this->_tableHeader = $content; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @param $content |
|
244 | + */ |
|
245 | + public function addFooter($content) |
|
246 | + { |
|
247 | + $this->_tableFooter = $content; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @param $caption |
|
252 | + */ |
|
253 | + public function addDefaultIntroButton($caption) |
|
254 | + { |
|
255 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @param $method |
|
260 | + */ |
|
261 | + public function addCustomAction($method) |
|
262 | + { |
|
263 | + $this->_custom_actions[] = $method; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @param $default_sort |
|
268 | + */ |
|
269 | + public function setDefaultSort($default_sort) |
|
270 | + { |
|
271 | + $this->_sortsel = $default_sort; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function getDefaultSort() |
|
278 | + { |
|
279 | + if ($this->_sortsel) { |
|
280 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
281 | + } else { |
|
282 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $default_order |
|
288 | + */ |
|
289 | + public function setDefaultOrder($default_order) |
|
290 | + { |
|
291 | + $this->_ordersel = $default_order; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function getDefaultOrder() |
|
298 | + { |
|
299 | + if ($this->_ordersel) { |
|
300 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
301 | + } else { |
|
302 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * @param array $actions |
|
308 | + */ |
|
309 | + public function addWithSelectedActions($actions = []) |
|
310 | + { |
|
311 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
312 | + $this->_withSelectedActions = $actions; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Adding a filter in the table |
|
317 | + * |
|
318 | + * @param string $key key to the field that will be used for sorting |
|
319 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
320 | + * @param bool $default |
|
321 | + */ |
|
322 | + public function addFilter($key, $method, $default = false) |
|
323 | + { |
|
324 | + $this->_filterseloptions[$key] = $method; |
|
325 | + $this->_filtersel2optionsDefault = $default; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * @param $default_filter |
|
330 | + */ |
|
331 | + public function setDefaultFilter($default_filter) |
|
332 | + { |
|
333 | + $this->_filtersel = $default_filter; |
|
334 | + } |
|
335 | + |
|
336 | + public function isForUserSide() |
|
337 | + { |
|
338 | + $this->_userSide = true; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * @param $template |
|
343 | + */ |
|
344 | + public function setCustomTemplate($template) |
|
345 | + { |
|
346 | + $this->_customTemplate = $template; |
|
347 | + } |
|
348 | + |
|
349 | + public function setSortOrder() |
|
350 | + { |
|
351 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
352 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
353 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
354 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
355 | + |
|
356 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
357 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
358 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
359 | + } else { |
|
360 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
361 | + } |
|
362 | + |
|
363 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
364 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
365 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
366 | + $ordersArray = $this->getOrdersArray(); |
|
367 | + $this->_criteria->setOrder($this->_ordersel); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * @param $id |
|
372 | + */ |
|
373 | + public function setTableId($id) |
|
374 | + { |
|
375 | + $this->_id = $id; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * @param $objects |
|
380 | + */ |
|
381 | + public function setObjects($objects) |
|
382 | + { |
|
383 | + $this->_objects = $objects; |
|
384 | + } |
|
385 | + |
|
386 | + public function createTableRows() |
|
387 | + { |
|
388 | + $this->_aObjects = []; |
|
389 | + |
|
390 | + $doWeHaveActions = false; |
|
391 | + |
|
392 | + $objectclass = 'odd'; |
|
393 | + if (count($this->_objects) > 0) { |
|
394 | + foreach ($this->_objects as $object) { |
|
395 | + $aObject = []; |
|
396 | + |
|
397 | + $i = 0; |
|
398 | + |
|
399 | + $aColumns = []; |
|
400 | + |
|
401 | + foreach ($this->_columns as $column) { |
|
402 | + $aColumn = []; |
|
403 | + |
|
404 | + if ($i == 0) { |
|
405 | + $class = 'head'; |
|
406 | + } elseif ($i % 2 == 0) { |
|
407 | + $class = 'even'; |
|
408 | + } else { |
|
409 | + $class = 'odd'; |
|
410 | + } |
|
411 | + if (method_exists($object, 'initiateCustomFields')) { |
|
412 | + //$object->initiateCustomFields(); |
|
413 | + } |
|
414 | + if ($column->_keyname === 'checked') { |
|
415 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
416 | + } elseif ($column->_customMethodForValue |
|
417 | + && method_exists($object, $column->_customMethodForValue)) { |
|
418 | + $method = $column->_customMethodForValue; |
|
419 | + if ($column->_param) { |
|
420 | + $value = $object->$method($column->_param); |
|
421 | + } else { |
|
422 | + $value = $object->$method(); |
|
423 | + } |
|
424 | + } else { |
|
425 | + /** |
|
426 | + * If the column is the identifier, then put a link on it |
|
427 | + */ |
|
428 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
429 | + $value = $object->getItemLink(); |
|
430 | + } else { |
|
431 | + $value = $object->getVar($column->getKeyName()); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + $aColumn['value'] = $value; |
|
436 | + $aColumn['class'] = $class; |
|
437 | + $aColumn['width'] = $column->getWidth(); |
|
438 | + $aColumn['align'] = $column->getAlign(); |
|
439 | + |
|
440 | + $aColumns[] = $aColumn; |
|
441 | + ++$i; |
|
442 | + } |
|
443 | + |
|
444 | + $aObject['columns'] = $aColumns; |
|
445 | + $aObject['id'] = $object->id(); |
|
446 | + |
|
447 | + $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
448 | + |
|
449 | + $aObject['class'] = $objectclass; |
|
450 | + |
|
451 | + $actions = []; |
|
452 | + |
|
453 | + // Adding the custom actions if any |
|
454 | + foreach ($this->_custom_actions as $action) { |
|
455 | + if (method_exists($object, $action)) { |
|
456 | + $actions[] = $object->$action(); |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
461 | + $controller = new SmartObjectController($this->_objectHandler); |
|
462 | + |
|
463 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
464 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
465 | + } |
|
466 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
467 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
468 | + } |
|
469 | + $aObject['actions'] = $actions; |
|
470 | + |
|
471 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
472 | + |
|
473 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
474 | + |
|
475 | + $this->_aObjects[] = $aObject; |
|
476 | + } |
|
477 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
478 | + } else { |
|
479 | + $colspan = count($this->_columns) + 1; |
|
480 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
481 | + } |
|
482 | + $this->_hasActions = $doWeHaveActions; |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * @param bool $debug |
|
487 | + * @return mixed |
|
488 | + */ |
|
489 | + public function fetchObjects($debug = false) |
|
490 | + { |
|
491 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function getDefaultFilter() |
|
498 | + { |
|
499 | + if ($this->_filtersel) { |
|
500 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
501 | + } else { |
|
502 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @return array|bool |
|
508 | + */ |
|
509 | + public function getFiltersArray() |
|
510 | + { |
|
511 | + $ret = []; |
|
512 | + $field = []; |
|
513 | + $field['caption'] = _CO_OBJ_NONE; |
|
514 | + $field['selected'] = ''; |
|
515 | + $ret['default'] = $field; |
|
516 | + unset($field); |
|
517 | + |
|
518 | + if ($this->_filterseloptions) { |
|
519 | + foreach ($this->_filterseloptions as $key => $value) { |
|
520 | + $field = []; |
|
521 | + if (is_array($value)) { |
|
522 | + $field['caption'] = $key; |
|
523 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
524 | + } else { |
|
525 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
526 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
527 | + } |
|
528 | + $ret[$key] = $field; |
|
529 | + unset($field); |
|
530 | + } |
|
531 | + } else { |
|
532 | + $ret = false; |
|
533 | + } |
|
534 | + |
|
535 | + return $ret; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * @param $default_filter2 |
|
540 | + */ |
|
541 | + public function setDefaultFilter2($default_filter2) |
|
542 | + { |
|
543 | + $this->_filtersel2 = $default_filter2; |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + public function getDefaultFilter2() |
|
550 | + { |
|
551 | + if ($this->_filtersel2) { |
|
552 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
553 | + } else { |
|
554 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * @return array |
|
560 | + */ |
|
561 | + public function getFilters2Array() |
|
562 | + { |
|
563 | + $ret = []; |
|
564 | + |
|
565 | + foreach ($this->_filtersel2options as $key => $value) { |
|
566 | + $field = []; |
|
567 | + $field['caption'] = $value; |
|
568 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
569 | + $ret[$key] = $field; |
|
570 | + unset($field); |
|
571 | + } |
|
572 | + |
|
573 | + return $ret; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * @param $limitsArray |
|
578 | + * @param $params_of_the_options_sel |
|
579 | + */ |
|
580 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
581 | + { |
|
582 | + // Rendering the form to select options on the table |
|
583 | + $current_urls = smart_getCurrentUrls(); |
|
584 | + $current_url = $current_urls['full']; |
|
585 | + |
|
586 | + /** |
|
587 | + * What was $params_of_the_options_sel doing again ? |
|
588 | + */ |
|
589 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
590 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
591 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * @return array |
|
596 | + */ |
|
597 | + public function getLimitsArray() |
|
598 | + { |
|
599 | + $ret = []; |
|
600 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
601 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
602 | + |
|
603 | + $ret['5']['caption'] = '5'; |
|
604 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
605 | + |
|
606 | + $ret['10']['caption'] = '10'; |
|
607 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
608 | + |
|
609 | + $ret['15']['caption'] = '15'; |
|
610 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
611 | + |
|
612 | + $ret['20']['caption'] = '20'; |
|
613 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
614 | + |
|
615 | + $ret['25']['caption'] = '25'; |
|
616 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
617 | + |
|
618 | + $ret['30']['caption'] = '30'; |
|
619 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
620 | + |
|
621 | + $ret['35']['caption'] = '35'; |
|
622 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
623 | + |
|
624 | + $ret['40']['caption'] = '40'; |
|
625 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
626 | + |
|
627 | + return $ret; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * @return bool |
|
632 | + */ |
|
633 | + public function getObjects() |
|
634 | + { |
|
635 | + return $this->_objects; |
|
636 | + } |
|
637 | + |
|
638 | + public function hideActionColumnTitle() |
|
639 | + { |
|
640 | + $this->_showActionsColumnTitle = false; |
|
641 | + } |
|
642 | + |
|
643 | + public function hideFilterAndLimit() |
|
644 | + { |
|
645 | + $this->_showFilterAndLimit = false; |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * @return array |
|
650 | + */ |
|
651 | + public function getOrdersArray() |
|
652 | + { |
|
653 | + $ret = []; |
|
654 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
655 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
656 | + |
|
657 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
658 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
659 | + |
|
660 | + return $ret; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @return mixed|string|void |
|
665 | + */ |
|
666 | + public function renderD() |
|
667 | + { |
|
668 | + return $this->render(false, true); |
|
669 | + } |
|
670 | + |
|
671 | + public function renderForPrint() |
|
672 | + { |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * @param bool $fetchOnly |
|
677 | + * @param bool $debug |
|
678 | + * @return mixed|string|void |
|
679 | + */ |
|
680 | + public function render($fetchOnly = false, $debug = false) |
|
681 | + { |
|
682 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
683 | + |
|
684 | + $this->_tpl = new XoopsTpl(); |
|
685 | + |
|
686 | + /** |
|
687 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
688 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
689 | + * and we will free it after |
|
690 | + */ |
|
691 | + $this->_tempObject = $this->_objectHandler->create(); |
|
692 | + |
|
693 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
694 | + |
|
695 | + $this->setSortOrder(); |
|
696 | + |
|
697 | + if (!$this->_isTree) { |
|
698 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
699 | + } else { |
|
700 | + $this->_limitsel = 'all'; |
|
701 | + } |
|
702 | + |
|
703 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
704 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
705 | + $limitsArray = $this->getLimitsArray(); |
|
706 | + $this->_criteria->setLimit($this->_limitsel); |
|
707 | + |
|
708 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
709 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
710 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
711 | + $filtersArray = $this->getFiltersArray(); |
|
712 | + |
|
713 | + if ($filtersArray) { |
|
714 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
715 | + } |
|
716 | + |
|
717 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
718 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
719 | + // check if method associate with this filter exists in the handler |
|
720 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
721 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
722 | + $this->_criteria->add($filter['criteria']); |
|
723 | + } else { |
|
724 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
725 | + |
|
726 | + // then we will create the selfilter2 options by calling this method |
|
727 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
728 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
729 | + |
|
730 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
731 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
732 | + |
|
733 | + $filters2Array = $this->getFilters2Array(); |
|
734 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
735 | + |
|
736 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
737 | + if ($this->_filtersel2 !== 'default') { |
|
738 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
739 | + } |
|
740 | + } |
|
741 | + } |
|
742 | + } |
|
743 | + // Check if we have a quicksearch |
|
744 | + |
|
745 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
746 | + $quicksearch_criteria = new CriteriaCompo(); |
|
747 | + if (is_array($this->_quickSearch['fields'])) { |
|
748 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
749 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
750 | + } |
|
751 | + } else { |
|
752 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
753 | + } |
|
754 | + $this->_criteria->add($quicksearch_criteria); |
|
755 | + } |
|
756 | + |
|
757 | + $this->_objects = $this->fetchObjects($debug); |
|
758 | + |
|
759 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
760 | + if ($this->_criteria->getLimit() > 0) { |
|
761 | + |
|
762 | + /** |
|
763 | + * Geeting rid of the old params |
|
764 | + * $new_get_array is an array containing the new GET parameters |
|
765 | + */ |
|
766 | + $new_get_array = []; |
|
767 | + |
|
768 | + /** |
|
769 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
770 | + * but without the pagenave parameters. This array will be used in the |
|
771 | + * OptionsSelection |
|
772 | + */ |
|
773 | + $params_of_the_options_sel = []; |
|
774 | + |
|
775 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
776 | + foreach ($_GET as $k => $v) { |
|
777 | + if (!in_array($k, $not_needed_params)) { |
|
778 | + $new_get_array[] = "$k=$v"; |
|
779 | + $params_of_the_options_sel[] = "$k=$v"; |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * Adding the new params of the pagenav |
|
785 | + */ |
|
786 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
787 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
788 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
789 | + $otherParams = implode('&', $new_get_array); |
|
790 | + |
|
791 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
792 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
793 | + } |
|
794 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
795 | + |
|
796 | + // retreive the current url and the query string |
|
797 | + $current_urls = smart_getCurrentUrls(); |
|
798 | + $current_url = $current_urls['full_phpself']; |
|
799 | + $query_string = $current_urls['querystring']; |
|
800 | + if ($query_string) { |
|
801 | + $query_string = str_replace('?', '', $query_string); |
|
802 | + } |
|
803 | + $query_stringArray = explode('&', $query_string); |
|
804 | + $new_query_stringArray = []; |
|
805 | + foreach ($query_stringArray as $query_string) { |
|
806 | + if (strpos($query_string, 'sortsel') === false && strpos($query_string, 'ordersel') === false) { |
|
807 | + $new_query_stringArray[] = $query_string; |
|
808 | + } |
|
809 | + } |
|
810 | + $new_query_string = implode('&', $new_query_stringArray); |
|
811 | + |
|
812 | + $orderArray = []; |
|
813 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
814 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
815 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
816 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
817 | + |
|
818 | + $aColumns = []; |
|
819 | + |
|
820 | + foreach ($this->_columns as $column) { |
|
821 | + $qs_param = ''; |
|
822 | + $aColumn = []; |
|
823 | + $aColumn['width'] = $column->getWidth(); |
|
824 | + $aColumn['align'] = $column->getAlign(); |
|
825 | + $aColumn['key'] = $column->getKeyName(); |
|
826 | + if ($column->_keyname === 'checked') { |
|
827 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
828 | + } elseif ($column->getCustomCaption()) { |
|
829 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
830 | + } else { |
|
831 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
832 | + } |
|
833 | + // Are we doing a GET sort on this column ? |
|
834 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
835 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
836 | + || ($this->_sortsel == $column->getKeyName()); |
|
837 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
838 | + |
|
839 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
840 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
841 | + } |
|
842 | + if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
843 | + $aColumn['caption'] = $aColumn['caption']; |
|
844 | + } elseif ($getSort) { |
|
845 | + $aColumn['caption'] = '<a href="' |
|
846 | + . $current_url |
|
847 | + . '?' |
|
848 | + . $this->_objectHandler->_itemname |
|
849 | + . '_' |
|
850 | + . 'sortsel=' |
|
851 | + . $column->getKeyName() |
|
852 | + . '&' |
|
853 | + . $this->_objectHandler->_itemname |
|
854 | + . '_' |
|
855 | + . 'ordersel=' |
|
856 | + . $orderArray[$order]['neworder'] |
|
857 | + . $qs_param |
|
858 | + . '&' |
|
859 | + . $new_query_string |
|
860 | + . '">' |
|
861 | + . $aColumn['caption'] |
|
862 | + . ' <img src="' |
|
863 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
864 | + . $orderArray[$order]['image'] |
|
865 | + . '" alt="ASC"></a>'; |
|
866 | + } else { |
|
867 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
868 | + } |
|
869 | + $aColumns[] = $aColumn; |
|
870 | + } |
|
871 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
872 | + |
|
873 | + if ($this->_quickSearch) { |
|
874 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
875 | + } |
|
876 | + |
|
877 | + $this->createTableRows(); |
|
878 | + |
|
879 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
880 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
881 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
882 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
883 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
884 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
885 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
886 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
887 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
888 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
889 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
890 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
891 | + if (!empty($this->_withSelectedActions)) { |
|
892 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
893 | + } |
|
894 | + |
|
895 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
896 | + if ($fetchOnly) { |
|
897 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
898 | + } else { |
|
899 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
900 | + } |
|
901 | + } |
|
902 | + |
|
903 | + public function disableColumnsSorting() |
|
904 | + { |
|
905 | + $this->_enableColumnsSorting = false; |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * @param bool $debug |
|
910 | + * @return mixed|string|void |
|
911 | + */ |
|
912 | + public function fetch($debug = false) |
|
913 | + { |
|
914 | + return $this->render(true, $debug); |
|
915 | + } |
|
916 | 916 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function addActionButton($op, $caption = false, $text = false) |
186 | 186 | { |
187 | - $action = [ |
|
187 | + $action = [ |
|
188 | 188 | 'op' => $op, |
189 | 189 | 'caption' => $caption, |
190 | 190 | 'text' => $text |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | { |
220 | 220 | $current_urls = smart_getCurrentUrls(); |
221 | 221 | $current_url = $current_urls['full']; |
222 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
222 | + $this->_printerFriendlyPage = $current_url.'&print'; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function addDefaultIntroButton($caption) |
254 | 254 | { |
255 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
255 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | public function getDefaultSort() |
278 | 278 | { |
279 | 279 | if ($this->_sortsel) { |
280 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
280 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
281 | 281 | } else { |
282 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
282 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | public function getDefaultOrder() |
298 | 298 | { |
299 | 299 | if ($this->_ordersel) { |
300 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
300 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
301 | 301 | } else { |
302 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
302 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC'); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
@@ -348,21 +348,21 @@ discard block |
||
348 | 348 | |
349 | 349 | public function setSortOrder() |
350 | 350 | { |
351 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
351 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort(); |
|
352 | 352 | //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
353 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
353 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
354 | 354 | $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
355 | 355 | |
356 | 356 | if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
357 | 357 | && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
358 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
358 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel); |
|
359 | 359 | } else { |
360 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
360 | + $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel); |
|
361 | 361 | } |
362 | 362 | |
363 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
363 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder(); |
|
364 | 364 | //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
365 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
365 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
366 | 366 | $ordersArray = $this->getOrdersArray(); |
367 | 367 | $this->_criteria->setOrder($this->_ordersel); |
368 | 368 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | //$object->initiateCustomFields(); |
413 | 413 | } |
414 | 414 | if ($column->_keyname === 'checked') { |
415 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
415 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">'; |
|
416 | 416 | } elseif ($column->_customMethodForValue |
417 | 417 | && method_exists($object, $column->_customMethodForValue)) { |
418 | 418 | $method = $column->_customMethodForValue; |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
460 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
461 | 461 | $controller = new SmartObjectController($this->_objectHandler); |
462 | 462 | |
463 | 463 | if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | public function getDefaultFilter() |
498 | 498 | { |
499 | 499 | if ($this->_filtersel) { |
500 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
500 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
501 | 501 | } else { |
502 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
502 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default'); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
@@ -549,9 +549,9 @@ discard block |
||
549 | 549 | public function getDefaultFilter2() |
550 | 550 | { |
551 | 551 | if ($this->_filtersel2) { |
552 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
552 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
553 | 553 | } else { |
554 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
554 | + return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default'); |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | */ |
680 | 680 | public function render($fetchOnly = false, $debug = false) |
681 | 681 | { |
682 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
682 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
683 | 683 | |
684 | 684 | $this->_tpl = new XoopsTpl(); |
685 | 685 | |
@@ -690,24 +690,24 @@ discard block |
||
690 | 690 | */ |
691 | 691 | $this->_tempObject = $this->_objectHandler->create(); |
692 | 692 | |
693 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
693 | + $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0); |
|
694 | 694 | |
695 | 695 | $this->setSortOrder(); |
696 | 696 | |
697 | 697 | if (!$this->_isTree) { |
698 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
698 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15'); |
|
699 | 699 | } else { |
700 | 700 | $this->_limitsel = 'all'; |
701 | 701 | } |
702 | 702 | |
703 | 703 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
704 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
704 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel); |
|
705 | 705 | $limitsArray = $this->getLimitsArray(); |
706 | 706 | $this->_criteria->setLimit($this->_limitsel); |
707 | 707 | |
708 | 708 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
709 | 709 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
710 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
710 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
711 | 711 | $filtersArray = $this->getFiltersArray(); |
712 | 712 | |
713 | 713 | if ($filtersArray) { |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | $filters2Array = $this->getFilters2Array(); |
734 | 734 | $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
735 | 735 | |
736 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
736 | + smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
737 | 737 | if ($this->_filtersel2 !== 'default') { |
738 | 738 | $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
739 | 739 | } |
@@ -742,21 +742,21 @@ discard block |
||
742 | 742 | } |
743 | 743 | // Check if we have a quicksearch |
744 | 744 | |
745 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
745 | + if (isset($_POST['quicksearch_'.$this->_id]) && $_POST['quicksearch_'.$this->_id] != '') { |
|
746 | 746 | $quicksearch_criteria = new CriteriaCompo(); |
747 | 747 | if (is_array($this->_quickSearch['fields'])) { |
748 | 748 | foreach ($this->_quickSearch['fields'] as $v) { |
749 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
749 | + $quicksearch_criteria->add(new Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR'); |
|
750 | 750 | } |
751 | 751 | } else { |
752 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
752 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE')); |
|
753 | 753 | } |
754 | 754 | $this->_criteria->add($quicksearch_criteria); |
755 | 755 | } |
756 | 756 | |
757 | 757 | $this->_objects = $this->fetchObjects($debug); |
758 | 758 | |
759 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
759 | + require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
760 | 760 | if ($this->_criteria->getLimit() > 0) { |
761 | 761 | |
762 | 762 | /** |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | */ |
773 | 773 | $params_of_the_options_sel = []; |
774 | 774 | |
775 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
775 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName]; |
|
776 | 776 | foreach ($_GET as $k => $v) { |
777 | 777 | if (!in_array($k, $not_needed_params)) { |
778 | 778 | $new_get_array[] = "$k=$v"; |
@@ -783,12 +783,12 @@ discard block |
||
783 | 783 | /** |
784 | 784 | * Adding the new params of the pagenav |
785 | 785 | */ |
786 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
787 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
788 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
786 | + $new_get_array[] = 'sortsel='.$this->_sortsel; |
|
787 | + $new_get_array[] = 'ordersel='.$this->_ordersel; |
|
788 | + $new_get_array[] = 'limitsel='.$this->_limitsel; |
|
789 | 789 | $otherParams = implode('&', $new_get_array); |
790 | 790 | |
791 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
791 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams); |
|
792 | 792 | $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
793 | 793 | } |
794 | 794 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
@@ -824,20 +824,20 @@ discard block |
||
824 | 824 | $aColumn['align'] = $column->getAlign(); |
825 | 825 | $aColumn['key'] = $column->getKeyName(); |
826 | 826 | if ($column->_keyname === 'checked') { |
827 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
827 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">'; |
|
828 | 828 | } elseif ($column->getCustomCaption()) { |
829 | 829 | $aColumn['caption'] = $column->getCustomCaption(); |
830 | 830 | } else { |
831 | 831 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
832 | 832 | } |
833 | 833 | // Are we doing a GET sort on this column ? |
834 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
835 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
834 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) |
|
835 | + && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName()) |
|
836 | 836 | || ($this->_sortsel == $column->getKeyName()); |
837 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
837 | + $order = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC'; |
|
838 | 838 | |
839 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
840 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
839 | + if (isset($_REQUEST['quicksearch_'.$this->_id]) && $_REQUEST['quicksearch_'.$this->_id] != '') { |
|
840 | + $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id]; |
|
841 | 841 | } |
842 | 842 | if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
843 | 843 | $aColumn['caption'] = $aColumn['caption']; |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | . $orderArray[$order]['image'] |
865 | 865 | . '" alt="ASC"></a>'; |
866 | 866 | } else { |
867 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
867 | + $aColumn['caption'] = '<a href="'.$current_url.'?'.$this->_objectHandler->_itemname.'_'.'sortsel='.$column->getKeyName().'&'.$this->_objectHandler->_itemname.'_'.'ordersel=ASC'.$qs_param.'&'.$new_query_string.'">'.$aColumn['caption'].'</a>'; |
|
868 | 868 | } |
869 | 869 | $aColumns[] = $aColumn; |
870 | 870 | } |
@@ -894,9 +894,9 @@ discard block |
||
894 | 894 | |
895 | 895 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
896 | 896 | if ($fetchOnly) { |
897 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
897 | + return $this->_tpl->fetch('db:'.$smartobjectTable_template); |
|
898 | 898 | } else { |
899 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
899 | + $this->_tpl->display('db:'.$smartobjectTable_template); |
|
900 | 900 | } |
901 | 901 | } |
902 | 902 |
@@ -19,96 +19,96 @@ |
||
19 | 19 | */ |
20 | 20 | class SmartHighlighter |
21 | 21 | { |
22 | - /** |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - public $preg_keywords = ''; |
|
26 | - /** |
|
27 | - * @access private |
|
28 | - */ |
|
29 | - public $keywords = ''; |
|
30 | - /** |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - public $singlewords = false; |
|
34 | - /** |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public $replace_callback = null; |
|
22 | + /** |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + public $preg_keywords = ''; |
|
26 | + /** |
|
27 | + * @access private |
|
28 | + */ |
|
29 | + public $keywords = ''; |
|
30 | + /** |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + public $singlewords = false; |
|
34 | + /** |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public $replace_callback = null; |
|
38 | 38 | |
39 | - public $content; |
|
39 | + public $content; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Main constructor |
|
43 | - * |
|
44 | - * This is the main constructor of keyhighlighter class. <br> |
|
45 | - * It's the only public method of the class. |
|
46 | - * @param string $keywords the keywords you want to highlight |
|
47 | - * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | - * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | - * <code> |
|
50 | - * <?php |
|
51 | - * require ('keyhighlighter.class.php'); |
|
52 | - * |
|
53 | - * function my_highlighter ($matches) { |
|
54 | - * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | - * } |
|
56 | - * |
|
57 | - * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | - * readfile ('http://www.w3c.org/'); |
|
59 | - * ?> |
|
60 | - * </code> |
|
61 | - */ |
|
62 | - // public function __construct () |
|
63 | - public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | - { |
|
65 | - $this->keywords = $keywords; |
|
66 | - $this->singlewords = $singlewords; |
|
67 | - $this->replace_callback = $replace_callback; |
|
68 | - } |
|
41 | + /** |
|
42 | + * Main constructor |
|
43 | + * |
|
44 | + * This is the main constructor of keyhighlighter class. <br> |
|
45 | + * It's the only public method of the class. |
|
46 | + * @param string $keywords the keywords you want to highlight |
|
47 | + * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | + * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | + * <code> |
|
50 | + * <?php |
|
51 | + * require ('keyhighlighter.class.php'); |
|
52 | + * |
|
53 | + * function my_highlighter ($matches) { |
|
54 | + * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | + * } |
|
56 | + * |
|
57 | + * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | + * readfile ('http://www.w3c.org/'); |
|
59 | + * ?> |
|
60 | + * </code> |
|
61 | + */ |
|
62 | + // public function __construct () |
|
63 | + public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | + { |
|
65 | + $this->keywords = $keywords; |
|
66 | + $this->singlewords = $singlewords; |
|
67 | + $this->replace_callback = $replace_callback; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @access private |
|
72 | - * @param $replace_matches |
|
73 | - * @return mixed |
|
74 | - */ |
|
75 | - public function replace($replace_matches) |
|
76 | - { |
|
77 | - $patterns = []; |
|
78 | - if ($this->singlewords) { |
|
79 | - $keywords = explode(' ', $this->preg_keywords); |
|
80 | - foreach ($keywords as $keyword) { |
|
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | - } |
|
83 | - } else { |
|
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | - } |
|
70 | + /** |
|
71 | + * @access private |
|
72 | + * @param $replace_matches |
|
73 | + * @return mixed |
|
74 | + */ |
|
75 | + public function replace($replace_matches) |
|
76 | + { |
|
77 | + $patterns = []; |
|
78 | + if ($this->singlewords) { |
|
79 | + $keywords = explode(' ', $this->preg_keywords); |
|
80 | + foreach ($keywords as $keyword) { |
|
81 | + $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | + } |
|
83 | + } else { |
|
84 | + $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | + } |
|
86 | 86 | |
87 | - $result = $replace_matches[0]; |
|
87 | + $result = $replace_matches[0]; |
|
88 | 88 | |
89 | - foreach ($patterns as $pattern) { |
|
90 | - if (null !== $this->replace_callback) { |
|
91 | - $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | - } else { |
|
93 | - $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | - } |
|
95 | - } |
|
89 | + foreach ($patterns as $pattern) { |
|
90 | + if (null !== $this->replace_callback) { |
|
91 | + $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | + } else { |
|
93 | + $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return $result; |
|
98 | - } |
|
97 | + return $result; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @access private |
|
102 | - * @param $buffer |
|
103 | - * @return mixed|string |
|
104 | - */ |
|
105 | - public function highlight($buffer) |
|
106 | - { |
|
107 | - $buffer = '>' . $buffer . '<'; |
|
108 | - $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | - $buffer = substr($buffer, 1, -1); |
|
100 | + /** |
|
101 | + * @access private |
|
102 | + * @param $buffer |
|
103 | + * @return mixed|string |
|
104 | + */ |
|
105 | + public function highlight($buffer) |
|
106 | + { |
|
107 | + $buffer = '>' . $buffer . '<'; |
|
108 | + $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | + $buffer = substr($buffer, 1, -1); |
|
111 | 111 | |
112 | - return $buffer; |
|
113 | - } |
|
112 | + return $buffer; |
|
113 | + } |
|
114 | 114 | } |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | if ($this->singlewords) { |
79 | 79 | $keywords = explode(' ', $this->preg_keywords); |
80 | 80 | foreach ($keywords as $keyword) { |
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
81 | + $patterns[] = '/(?'.'>'.$keyword.'+)/si'; |
|
82 | 82 | } |
83 | 83 | } else { |
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
84 | + $patterns[] = '/(?'.'>'.$this->preg_keywords.'+)/si'; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $result = $replace_matches[0]; |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function highlight($buffer) |
106 | 106 | { |
107 | - $buffer = '>' . $buffer . '<'; |
|
107 | + $buffer = '>'.$buffer.'<'; |
|
108 | 108 | $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?".">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | 110 | $buffer = substr($buffer, 1, -1); |
111 | 111 | |
112 | 112 | return $buffer; |
@@ -12,18 +12,18 @@ discard block |
||
12 | 12 | |
13 | 13 | class SmartobjectPermissionHandler extends XoopsObjectHandler |
14 | 14 | { |
15 | - public $handler; |
|
16 | - |
|
17 | - /** |
|
18 | - * SmartobjectPermissionHandler constructor. |
|
19 | - * @param XoopsDatabase $handler |
|
20 | - */ |
|
21 | - public function __construct($handler) |
|
22 | - { |
|
23 | - $this->handler = $handler; |
|
24 | - } |
|
25 | - |
|
26 | - /* |
|
15 | + public $handler; |
|
16 | + |
|
17 | + /** |
|
18 | + * SmartobjectPermissionHandler constructor. |
|
19 | + * @param XoopsDatabase $handler |
|
20 | + */ |
|
21 | + public function __construct($handler) |
|
22 | + { |
|
23 | + $this->handler = $handler; |
|
24 | + } |
|
25 | + |
|
26 | + /* |
|
27 | 27 | * Returns permissions for a certain type |
28 | 28 | * |
29 | 29 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -31,74 +31,74 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - /** |
|
35 | - * @param $gperm_name |
|
36 | - * @param null $id |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function getGrantedGroups($gperm_name, $id = null) |
|
40 | - { |
|
41 | - static $groups; |
|
42 | - |
|
43 | - if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
44 | - $smartModule = $this->handler->getModuleInfo(); |
|
45 | - //Get group permissions handler |
|
46 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
47 | - |
|
48 | - //Get groups allowed for an item id |
|
49 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
50 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
51 | - } |
|
52 | - |
|
53 | - //Return the permission array |
|
54 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param $item_ids_array |
|
59 | - * @param bool $gperm_name |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
63 | - { |
|
64 | - static $groups; |
|
65 | - |
|
66 | - if ($gperm_name) { |
|
67 | - if (isset($groups[$gperm_name])) { |
|
68 | - return $groups[$gperm_name]; |
|
69 | - } |
|
70 | - } else { |
|
71 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
72 | - return $groups; |
|
73 | - } |
|
74 | - |
|
75 | - $smartModule = $this->handler->getModuleInfo(); |
|
76 | - |
|
77 | - $criteria = new CriteriaCompo(); |
|
78 | - $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
79 | - |
|
80 | - if ($gperm_name) { |
|
81 | - $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
82 | - } |
|
83 | - |
|
84 | - //Get group permissions handler |
|
85 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
86 | - |
|
87 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
88 | - |
|
89 | - foreach ($permissionsObj as $permissionObj) { |
|
90 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
91 | - } |
|
92 | - |
|
93 | - //Return the permission array |
|
94 | - if ($gperm_name) { |
|
95 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
96 | - } else { |
|
97 | - return isset($groups) ? $groups : []; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /* |
|
34 | + /** |
|
35 | + * @param $gperm_name |
|
36 | + * @param null $id |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function getGrantedGroups($gperm_name, $id = null) |
|
40 | + { |
|
41 | + static $groups; |
|
42 | + |
|
43 | + if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) { |
|
44 | + $smartModule = $this->handler->getModuleInfo(); |
|
45 | + //Get group permissions handler |
|
46 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
47 | + |
|
48 | + //Get groups allowed for an item id |
|
49 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
50 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
51 | + } |
|
52 | + |
|
53 | + //Return the permission array |
|
54 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param $item_ids_array |
|
59 | + * @param bool $gperm_name |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
63 | + { |
|
64 | + static $groups; |
|
65 | + |
|
66 | + if ($gperm_name) { |
|
67 | + if (isset($groups[$gperm_name])) { |
|
68 | + return $groups[$gperm_name]; |
|
69 | + } |
|
70 | + } else { |
|
71 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
72 | + return $groups; |
|
73 | + } |
|
74 | + |
|
75 | + $smartModule = $this->handler->getModuleInfo(); |
|
76 | + |
|
77 | + $criteria = new CriteriaCompo(); |
|
78 | + $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
79 | + |
|
80 | + if ($gperm_name) { |
|
81 | + $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
82 | + } |
|
83 | + |
|
84 | + //Get group permissions handler |
|
85 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
86 | + |
|
87 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
88 | + |
|
89 | + foreach ($permissionsObj as $permissionObj) { |
|
90 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
91 | + } |
|
92 | + |
|
93 | + //Return the permission array |
|
94 | + if ($gperm_name) { |
|
95 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
96 | + } else { |
|
97 | + return isset($groups) ? $groups : []; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /* |
|
102 | 102 | * Returns permissions for a certain type |
103 | 103 | * |
104 | 104 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -106,123 +106,123 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - /** |
|
110 | - * @param $gperm_name |
|
111 | - * @param null $id |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function getGrantedItems($gperm_name, $id = null) |
|
115 | - { |
|
116 | - global $xoopsUser; |
|
117 | - static $permissions; |
|
118 | - |
|
119 | - if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
120 | - $smartModule = $this->handler->getModuleInfo(); |
|
121 | - |
|
122 | - if (is_object($smartModule)) { |
|
123 | - |
|
124 | - //Get group permissions handler |
|
125 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
126 | - |
|
127 | - //Get user's groups |
|
128 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
129 | - |
|
130 | - //Get all allowed item ids in this module and for this user's groups |
|
131 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
132 | - $permissions[$gperm_name] = $userpermissions; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - //Return the permission array |
|
137 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param $id |
|
142 | - */ |
|
143 | - public function storeAllPermissionsForId($id) |
|
144 | - { |
|
145 | - foreach ($this->handler->getPermissions() as $permission) { |
|
146 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Saves permissions for the selected item |
|
152 | - * |
|
153 | - * saveItem_Permissions() |
|
154 | - * |
|
155 | - * @param array $groups : group with granted permission |
|
156 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
157 | - * @param string $perm_name : name of the permission |
|
158 | - * @return bool : TRUE if the no errors occured |
|
159 | - */ |
|
160 | - |
|
161 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
162 | - { |
|
163 | - $smartModule = $this->handler->getModuleInfo(); |
|
164 | - |
|
165 | - $result = true; |
|
166 | - $module_id = $smartModule->getVar('mid'); |
|
167 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
168 | - |
|
169 | - // First, if the permissions are already there, delete them |
|
170 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
171 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
172 | - //exit; |
|
173 | - // Save the new permissions |
|
174 | - |
|
175 | - if (count($groups) > 0) { |
|
176 | - foreach ($groups as $group_id) { |
|
177 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - return $result; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Delete all permission for a specific item |
|
186 | - * |
|
187 | - * deletePermissions() |
|
188 | - * |
|
189 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
190 | - * @param $gperm_name |
|
191 | - * @return bool: TRUE if the no errors occured |
|
192 | - */ |
|
193 | - public function deletePermissions($itemid, $gperm_name) |
|
194 | - { |
|
195 | - global $xoopsModule; |
|
196 | - |
|
197 | - $smartModule =& smartsection_getModuleInfo(); |
|
198 | - |
|
199 | - $result = true; |
|
200 | - $module_id = $smartModule->getVar('mid'); |
|
201 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
202 | - |
|
203 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
204 | - |
|
205 | - return $result; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Checks if the user has access to a specific permission on a given object |
|
210 | - * |
|
211 | - * @param string $gperm_name name of the permission to test |
|
212 | - * @param int $gperm_itemid id of the object to check |
|
213 | - * @return boolean: TRUE if user has access, FALSE if not |
|
214 | - **/ |
|
215 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
216 | - { |
|
217 | - global $xoopsUser; |
|
218 | - |
|
219 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
220 | - $smartModule = $this->handler->getModuleInfo(); |
|
221 | - $gperm_modid = $smartModule->getVar('mid'); |
|
222 | - |
|
223 | - //Get group permissions handler |
|
224 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
225 | - |
|
226 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
227 | - } |
|
109 | + /** |
|
110 | + * @param $gperm_name |
|
111 | + * @param null $id |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function getGrantedItems($gperm_name, $id = null) |
|
115 | + { |
|
116 | + global $xoopsUser; |
|
117 | + static $permissions; |
|
118 | + |
|
119 | + if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) { |
|
120 | + $smartModule = $this->handler->getModuleInfo(); |
|
121 | + |
|
122 | + if (is_object($smartModule)) { |
|
123 | + |
|
124 | + //Get group permissions handler |
|
125 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
126 | + |
|
127 | + //Get user's groups |
|
128 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
129 | + |
|
130 | + //Get all allowed item ids in this module and for this user's groups |
|
131 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
132 | + $permissions[$gperm_name] = $userpermissions; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + //Return the permission array |
|
137 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param $id |
|
142 | + */ |
|
143 | + public function storeAllPermissionsForId($id) |
|
144 | + { |
|
145 | + foreach ($this->handler->getPermissions() as $permission) { |
|
146 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Saves permissions for the selected item |
|
152 | + * |
|
153 | + * saveItem_Permissions() |
|
154 | + * |
|
155 | + * @param array $groups : group with granted permission |
|
156 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
157 | + * @param string $perm_name : name of the permission |
|
158 | + * @return bool : TRUE if the no errors occured |
|
159 | + */ |
|
160 | + |
|
161 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
162 | + { |
|
163 | + $smartModule = $this->handler->getModuleInfo(); |
|
164 | + |
|
165 | + $result = true; |
|
166 | + $module_id = $smartModule->getVar('mid'); |
|
167 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
168 | + |
|
169 | + // First, if the permissions are already there, delete them |
|
170 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
171 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
172 | + //exit; |
|
173 | + // Save the new permissions |
|
174 | + |
|
175 | + if (count($groups) > 0) { |
|
176 | + foreach ($groups as $group_id) { |
|
177 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + return $result; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Delete all permission for a specific item |
|
186 | + * |
|
187 | + * deletePermissions() |
|
188 | + * |
|
189 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
190 | + * @param $gperm_name |
|
191 | + * @return bool: TRUE if the no errors occured |
|
192 | + */ |
|
193 | + public function deletePermissions($itemid, $gperm_name) |
|
194 | + { |
|
195 | + global $xoopsModule; |
|
196 | + |
|
197 | + $smartModule =& smartsection_getModuleInfo(); |
|
198 | + |
|
199 | + $result = true; |
|
200 | + $module_id = $smartModule->getVar('mid'); |
|
201 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
202 | + |
|
203 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
204 | + |
|
205 | + return $result; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Checks if the user has access to a specific permission on a given object |
|
210 | + * |
|
211 | + * @param string $gperm_name name of the permission to test |
|
212 | + * @param int $gperm_itemid id of the object to check |
|
213 | + * @return boolean: TRUE if user has access, FALSE if not |
|
214 | + **/ |
|
215 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
216 | + { |
|
217 | + global $xoopsUser; |
|
218 | + |
|
219 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
220 | + $smartModule = $this->handler->getModuleInfo(); |
|
221 | + $gperm_modid = $smartModule->getVar('mid'); |
|
222 | + |
|
223 | + //Get group permissions handler |
|
224 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
225 | + |
|
226 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
227 | + } |
|
228 | 228 | } |
@@ -37,125 +37,125 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectRating extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectRating constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | - $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | - $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | - $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | - $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | - $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | - |
|
55 | - $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | - |
|
57 | - $this->setControl('dirname', [ |
|
58 | - 'handler' => 'rating', |
|
59 | - 'method' => 'getModuleList', |
|
60 | - 'onSelect' => 'submit' |
|
61 | - ]); |
|
62 | - |
|
63 | - $this->setControl('item', [ |
|
64 | - 'object' => &$this, |
|
65 | - 'method' => 'getItemList' |
|
66 | - ]); |
|
67 | - |
|
68 | - $this->setControl('uid', 'user'); |
|
69 | - |
|
70 | - $this->setControl('rate', [ |
|
71 | - 'handler' => 'rating', |
|
72 | - 'method' => 'getRateList' |
|
73 | - ]); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $key |
|
78 | - * @param string $format |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public function getVar($key, $format = 's') |
|
82 | - { |
|
83 | - if ($format === 's' && in_array($key, ['name', 'dirname'])) { |
|
84 | - // return call_user_func(array($this, $key)); |
|
85 | - return $this->{$key}(); |
|
86 | - } |
|
87 | - |
|
88 | - return parent::getVar($key, $format); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function name() |
|
95 | - { |
|
96 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
97 | - |
|
98 | - return $ret; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function dirname() |
|
105 | - { |
|
106 | - global $smartobjectRatingHandler; |
|
107 | - $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | - |
|
109 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return mixed |
|
114 | - */ |
|
115 | - public function getItemList() |
|
116 | - { |
|
117 | - $plugin = $this->getModulePlugin(); |
|
118 | - |
|
119 | - return $plugin->getItemList(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function getItemValue() |
|
126 | - { |
|
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | - $plugin = $this->getModulePlugin(); |
|
129 | - $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | - if (!$pluginItemInfo) { |
|
131 | - return ''; |
|
132 | - } |
|
133 | - $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | - |
|
136 | - return $ret; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return mixed |
|
141 | - */ |
|
142 | - public function getRateValue() |
|
143 | - { |
|
144 | - return $this->getVar('rate'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function getModulePlugin() |
|
151 | - { |
|
152 | - if (!$this->_modulePlugin) { |
|
153 | - global $smartobjectRatingHandler; |
|
154 | - $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | - } |
|
156 | - |
|
157 | - return $this->_modulePlugin; |
|
158 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectRating constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | + $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | + $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | + $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | + $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | + |
|
55 | + $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | + |
|
57 | + $this->setControl('dirname', [ |
|
58 | + 'handler' => 'rating', |
|
59 | + 'method' => 'getModuleList', |
|
60 | + 'onSelect' => 'submit' |
|
61 | + ]); |
|
62 | + |
|
63 | + $this->setControl('item', [ |
|
64 | + 'object' => &$this, |
|
65 | + 'method' => 'getItemList' |
|
66 | + ]); |
|
67 | + |
|
68 | + $this->setControl('uid', 'user'); |
|
69 | + |
|
70 | + $this->setControl('rate', [ |
|
71 | + 'handler' => 'rating', |
|
72 | + 'method' => 'getRateList' |
|
73 | + ]); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $key |
|
78 | + * @param string $format |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public function getVar($key, $format = 's') |
|
82 | + { |
|
83 | + if ($format === 's' && in_array($key, ['name', 'dirname'])) { |
|
84 | + // return call_user_func(array($this, $key)); |
|
85 | + return $this->{$key}(); |
|
86 | + } |
|
87 | + |
|
88 | + return parent::getVar($key, $format); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function name() |
|
95 | + { |
|
96 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
97 | + |
|
98 | + return $ret; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function dirname() |
|
105 | + { |
|
106 | + global $smartobjectRatingHandler; |
|
107 | + $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | + |
|
109 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return mixed |
|
114 | + */ |
|
115 | + public function getItemList() |
|
116 | + { |
|
117 | + $plugin = $this->getModulePlugin(); |
|
118 | + |
|
119 | + return $plugin->getItemList(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function getItemValue() |
|
126 | + { |
|
127 | + $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | + $plugin = $this->getModulePlugin(); |
|
129 | + $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | + if (!$pluginItemInfo) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | + $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | + $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | + |
|
136 | + return $ret; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + public function getRateValue() |
|
143 | + { |
|
144 | + return $this->getVar('rate'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function getModulePlugin() |
|
151 | + { |
|
152 | + if (!$this->_modulePlugin) { |
|
153 | + global $smartobjectRatingHandler; |
|
154 | + $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | + } |
|
156 | + |
|
157 | + return $this->_modulePlugin; |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,93 +163,93 @@ discard block |
||
163 | 163 | */ |
164 | 164 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler |
165 | 165 | { |
166 | - public $_rateOptions = []; |
|
167 | - public $_moduleList = false; |
|
168 | - public $pluginsObject; |
|
169 | - |
|
170 | - /** |
|
171 | - * SmartobjectRatingHandler constructor. |
|
172 | - * @param XoopsDatabase $db |
|
173 | - */ |
|
174 | - public function __construct(XoopsDatabase $db) |
|
175 | - { |
|
176 | - parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | - $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | - |
|
179 | - $this->_rateOptions[1] = 1; |
|
180 | - $this->_rateOptions[2] = 2; |
|
181 | - $this->_rateOptions[3] = 3; |
|
182 | - $this->_rateOptions[4] = 4; |
|
183 | - $this->_rateOptions[5] = 5; |
|
184 | - |
|
185 | - $this->pluginsObject = new SmartPluginHandler(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function getModuleList() |
|
192 | - { |
|
193 | - if (!$this->_moduleList) { |
|
194 | - $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | - $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | - foreach ($moduleArray as $k => $v) { |
|
197 | - $this->_moduleList[$k] = $v; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $this->_moduleList; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function getRateList() |
|
208 | - { |
|
209 | - return $this->_rateOptions; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param $itemid |
|
214 | - * @param $dirname |
|
215 | - * @param $item |
|
216 | - * @return int |
|
217 | - */ |
|
218 | - public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | - { |
|
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | - $result = $this->db->query($sql); |
|
222 | - if (!$result) { |
|
223 | - return 0; |
|
224 | - } |
|
225 | - list($average, $sum) = $this->db->fetchRow($result); |
|
226 | - $ret['average'] = isset($average) ? $average : 0; |
|
227 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | - |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $item |
|
234 | - * @param $itemid |
|
235 | - * @param $dirname |
|
236 | - * @param $uid |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | - { |
|
241 | - $criteria = new CriteriaCompo(); |
|
242 | - $criteria->add(new Criteria('item', $item)); |
|
243 | - $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | - $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | - $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | - |
|
247 | - $ret = $this->getObjects($criteria); |
|
248 | - |
|
249 | - if (!$ret) { |
|
250 | - return false; |
|
251 | - } else { |
|
252 | - return $ret[0]; |
|
253 | - } |
|
254 | - } |
|
166 | + public $_rateOptions = []; |
|
167 | + public $_moduleList = false; |
|
168 | + public $pluginsObject; |
|
169 | + |
|
170 | + /** |
|
171 | + * SmartobjectRatingHandler constructor. |
|
172 | + * @param XoopsDatabase $db |
|
173 | + */ |
|
174 | + public function __construct(XoopsDatabase $db) |
|
175 | + { |
|
176 | + parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | + $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | + |
|
179 | + $this->_rateOptions[1] = 1; |
|
180 | + $this->_rateOptions[2] = 2; |
|
181 | + $this->_rateOptions[3] = 3; |
|
182 | + $this->_rateOptions[4] = 4; |
|
183 | + $this->_rateOptions[5] = 5; |
|
184 | + |
|
185 | + $this->pluginsObject = new SmartPluginHandler(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function getModuleList() |
|
192 | + { |
|
193 | + if (!$this->_moduleList) { |
|
194 | + $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | + $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | + foreach ($moduleArray as $k => $v) { |
|
197 | + $this->_moduleList[$k] = $v; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $this->_moduleList; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function getRateList() |
|
208 | + { |
|
209 | + return $this->_rateOptions; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param $itemid |
|
214 | + * @param $dirname |
|
215 | + * @param $item |
|
216 | + * @return int |
|
217 | + */ |
|
218 | + public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | + { |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | + $result = $this->db->query($sql); |
|
222 | + if (!$result) { |
|
223 | + return 0; |
|
224 | + } |
|
225 | + list($average, $sum) = $this->db->fetchRow($result); |
|
226 | + $ret['average'] = isset($average) ? $average : 0; |
|
227 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | + |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $item |
|
234 | + * @param $itemid |
|
235 | + * @param $dirname |
|
236 | + * @param $uid |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | + { |
|
241 | + $criteria = new CriteriaCompo(); |
|
242 | + $criteria->add(new Criteria('item', $item)); |
|
243 | + $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | + $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | + $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | + |
|
247 | + $ret = $this->getObjects($criteria); |
|
248 | + |
|
249 | + if (!$ret) { |
|
250 | + return false; |
|
251 | + } else { |
|
252 | + return $ret[0]; |
|
253 | + } |
|
254 | + } |
|
255 | 255 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
31 | 31 | |
32 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
33 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php'; |
|
32 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
33 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartplugins.php'; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Class SmartobjectRating |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getItemValue() |
126 | 126 | { |
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
127 | + $moduleUrl = XOOPS_URL.'/modules/'.$this->getVar('dirname', 'n').'/'; |
|
128 | 128 | $plugin = $this->getModulePlugin(); |
129 | 129 | $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
130 | 130 | if (!$pluginItemInfo) { |
131 | 131 | return ''; |
132 | 132 | } |
133 | 133 | $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
134 | + $ret = '<a href="'.$moduleUrl.$itemPath.'">'.$pluginItemInfo['caption'].'</a>'; |
|
135 | 135 | |
136 | 136 | return $ret; |
137 | 137 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function __construct(XoopsDatabase $db) |
175 | 175 | { |
176 | 176 | parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
177 | - $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
177 | + $this->generalSQL = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->db->prefix('users').' AS user ON '.$this->_itemname.'.uid=user.uid'; |
|
178 | 178 | |
179 | 179 | $this->_rateOptions[1] = 1; |
180 | 180 | $this->_rateOptions[2] = 2; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function getRatingAverageByItemId($itemid, $dirname, $item) |
219 | 219 | { |
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM '.$this->table." WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | 221 | $result = $this->db->query($sql); |
222 | 222 | if (!$result) { |
223 | 223 | return 0; |
@@ -20,39 +20,39 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class SmartObjectRow |
22 | 22 | { |
23 | - public $_keyname; |
|
24 | - public $_align; |
|
25 | - public $_customMethodForValue; |
|
26 | - public $_header; |
|
27 | - public $_class; |
|
23 | + public $_keyname; |
|
24 | + public $_align; |
|
25 | + public $_customMethodForValue; |
|
26 | + public $_header; |
|
27 | + public $_class; |
|
28 | 28 | |
29 | - /** |
|
30 | - * SmartObjectRow constructor. |
|
31 | - * @param $keyname |
|
32 | - * @param bool $customMethodForValue |
|
33 | - * @param bool $header |
|
34 | - * @param bool $class |
|
35 | - */ |
|
36 | - public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
37 | - { |
|
38 | - $this->_keyname = $keyname; |
|
39 | - $this->_customMethodForValue = $customMethodForValue; |
|
40 | - $this->_header = $header; |
|
41 | - $this->_class = $class; |
|
42 | - } |
|
29 | + /** |
|
30 | + * SmartObjectRow constructor. |
|
31 | + * @param $keyname |
|
32 | + * @param bool $customMethodForValue |
|
33 | + * @param bool $header |
|
34 | + * @param bool $class |
|
35 | + */ |
|
36 | + public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
37 | + { |
|
38 | + $this->_keyname = $keyname; |
|
39 | + $this->_customMethodForValue = $customMethodForValue; |
|
40 | + $this->_header = $header; |
|
41 | + $this->_class = $class; |
|
42 | + } |
|
43 | 43 | |
44 | - public function getKeyName() |
|
45 | - { |
|
46 | - return $this->_keyname; |
|
47 | - } |
|
44 | + public function getKeyName() |
|
45 | + { |
|
46 | + return $this->_keyname; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function isHeader() |
|
53 | - { |
|
54 | - return $this->_header; |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function isHeader() |
|
53 | + { |
|
54 | + return $this->_header; |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -66,94 +66,94 @@ discard block |
||
66 | 66 | */ |
67 | 67 | class SmartObjectSingleView |
68 | 68 | { |
69 | - public $_object; |
|
70 | - public $_userSide; |
|
71 | - public $_tpl; |
|
72 | - public $_rows; |
|
73 | - public $_actions; |
|
74 | - public $_headerAsRow = true; |
|
69 | + public $_object; |
|
70 | + public $_userSide; |
|
71 | + public $_tpl; |
|
72 | + public $_rows; |
|
73 | + public $_actions; |
|
74 | + public $_headerAsRow = true; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Constructor |
|
78 | - * @param $object |
|
79 | - * @param bool $userSide |
|
80 | - * @param array $actions |
|
81 | - * @param bool $headerAsRow |
|
82 | - */ |
|
83 | - public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
84 | - { |
|
85 | - $this->_object = $object; |
|
86 | - $this->_userSide = $userSide; |
|
87 | - $this->_actions = $actions; |
|
88 | - $this->_headerAsRow = $headerAsRow; |
|
89 | - } |
|
76 | + /** |
|
77 | + * Constructor |
|
78 | + * @param $object |
|
79 | + * @param bool $userSide |
|
80 | + * @param array $actions |
|
81 | + * @param bool $headerAsRow |
|
82 | + */ |
|
83 | + public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
84 | + { |
|
85 | + $this->_object = $object; |
|
86 | + $this->_userSide = $userSide; |
|
87 | + $this->_actions = $actions; |
|
88 | + $this->_headerAsRow = $headerAsRow; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param $rowObj |
|
93 | - */ |
|
94 | - public function addRow($rowObj) |
|
95 | - { |
|
96 | - $this->_rows[] = $rowObj; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @param $rowObj |
|
93 | + */ |
|
94 | + public function addRow($rowObj) |
|
95 | + { |
|
96 | + $this->_rows[] = $rowObj; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param bool $fetchOnly |
|
101 | - * @param bool $debug |
|
102 | - * @return mixed|string|void |
|
103 | - */ |
|
104 | - public function render($fetchOnly = false, $debug = false) |
|
105 | - { |
|
106 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
99 | + /** |
|
100 | + * @param bool $fetchOnly |
|
101 | + * @param bool $debug |
|
102 | + * @return mixed|string|void |
|
103 | + */ |
|
104 | + public function render($fetchOnly = false, $debug = false) |
|
105 | + { |
|
106 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
107 | 107 | |
108 | - $this->_tpl = new XoopsTpl(); |
|
109 | - $vars = $this->_object->vars; |
|
110 | - $smartobjectObjectArray = []; |
|
108 | + $this->_tpl = new XoopsTpl(); |
|
109 | + $vars = $this->_object->vars; |
|
110 | + $smartobjectObjectArray = []; |
|
111 | 111 | |
112 | - foreach ($this->_rows as $row) { |
|
113 | - $key = $row->getKeyName(); |
|
114 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
115 | - $method = $row->_customMethodForValue; |
|
116 | - $value = $this->_object->$method(); |
|
117 | - } else { |
|
118 | - $value = $this->_object->getVar($row->getKeyName()); |
|
119 | - } |
|
120 | - if ($row->isHeader()) { |
|
121 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
122 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
123 | - } else { |
|
124 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
125 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
126 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
127 | - } |
|
128 | - } |
|
129 | - $action_row = ''; |
|
130 | - if (in_array('edit', $this->_actions)) { |
|
131 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
132 | - } |
|
133 | - if (in_array('delete', $this->_actions)) { |
|
134 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
135 | - } |
|
136 | - if ($action_row) { |
|
137 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
138 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
139 | - } |
|
112 | + foreach ($this->_rows as $row) { |
|
113 | + $key = $row->getKeyName(); |
|
114 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
115 | + $method = $row->_customMethodForValue; |
|
116 | + $value = $this->_object->$method(); |
|
117 | + } else { |
|
118 | + $value = $this->_object->getVar($row->getKeyName()); |
|
119 | + } |
|
120 | + if ($row->isHeader()) { |
|
121 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
122 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
123 | + } else { |
|
124 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
125 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
126 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
127 | + } |
|
128 | + } |
|
129 | + $action_row = ''; |
|
130 | + if (in_array('edit', $this->_actions)) { |
|
131 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
132 | + } |
|
133 | + if (in_array('delete', $this->_actions)) { |
|
134 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
135 | + } |
|
136 | + if ($action_row) { |
|
137 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
138 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
139 | + } |
|
140 | 140 | |
141 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
142 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
141 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
142 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
143 | 143 | |
144 | - if ($fetchOnly) { |
|
145 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
146 | - } else { |
|
147 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
148 | - } |
|
149 | - } |
|
144 | + if ($fetchOnly) { |
|
145 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
146 | + } else { |
|
147 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param bool $debug |
|
153 | - * @return mixed|string|void |
|
154 | - */ |
|
155 | - public function fetch($debug = false) |
|
156 | - { |
|
157 | - return $this->render(true, $debug); |
|
158 | - } |
|
151 | + /** |
|
152 | + * @param bool $debug |
|
153 | + * @return mixed|string|void |
|
154 | + */ |
|
155 | + public function fetch($debug = false) |
|
156 | + { |
|
157 | + return $this->render(true, $debug); |
|
158 | + } |
|
159 | 159 | } |
@@ -30,803 +30,803 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class SmartObjectForm extends XoopsThemeForm |
32 | 32 | { |
33 | - public $targetObject = null; |
|
34 | - public $form_fields = null; |
|
35 | - public $_cancel_js_action = false; |
|
36 | - public $_custom_button = false; |
|
37 | - public $_captcha = false; |
|
38 | - public $_form_name = false; |
|
39 | - public $_form_caption = false; |
|
40 | - public $_submit_button_caption = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectForm constructor. |
|
44 | - * @param string $target |
|
45 | - * @param string $form_name |
|
46 | - * @param string $form_caption |
|
47 | - * @param string $form_action |
|
48 | - * @param null $form_fields |
|
49 | - * @param bool $submit_button_caption |
|
50 | - * @param bool $cancel_js_action |
|
51 | - * @param bool $captcha |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - &$target, |
|
55 | - $form_name, |
|
56 | - $form_caption, |
|
57 | - $form_action, |
|
58 | - $form_fields = null, |
|
59 | - $submit_button_caption = false, |
|
60 | - $cancel_js_action = false, |
|
61 | - $captcha = false |
|
62 | - ) { |
|
63 | - $this->targetObject =& $target; |
|
64 | - $this->form_fields = $form_fields; |
|
65 | - $this->_cancel_js_action = $cancel_js_action; |
|
66 | - $this->_captcha = $captcha; |
|
67 | - $this->_form_name = $form_name; |
|
68 | - $this->_form_caption = $form_caption; |
|
69 | - $this->_submit_button_caption = $submit_button_caption; |
|
70 | - |
|
71 | - if (!isset($form_action)) { |
|
72 | - $form_action = xoops_getenv('PHP_SELF'); |
|
73 | - } |
|
74 | - |
|
75 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
76 | - $this->setExtra('enctype="multipart/form-data"'); |
|
77 | - |
|
78 | - $this->createElements(); |
|
79 | - |
|
80 | - if ($captcha) { |
|
81 | - $this->addCaptcha(); |
|
82 | - } |
|
83 | - |
|
84 | - $this->createPermissionControls(); |
|
85 | - |
|
86 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
87 | - } |
|
88 | - |
|
89 | - public function addCaptcha() |
|
90 | - { |
|
91 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
92 | - $this->addElement(new XoopsFormCaptcha(), true); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @param $name |
|
97 | - * @param $caption |
|
98 | - * @param bool $onclick |
|
99 | - */ |
|
100 | - public function addCustomButton($name, $caption, $onclick = false) |
|
101 | - { |
|
102 | - $custom_button_array = [ |
|
103 | - 'name' => $name, |
|
104 | - 'caption' => $caption, |
|
105 | - 'onclick' => $onclick |
|
106 | - ]; |
|
107 | - $this->_custom_button[] = $custom_button_array; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Add an element to the form |
|
112 | - * |
|
113 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
114 | - * @param bool $key |
|
115 | - * @param bool $var |
|
116 | - * @param bool|string $required is this a "required" element? |
|
117 | - */ |
|
118 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
119 | - { |
|
120 | - if ($key) { |
|
121 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
122 | - $formElement->setExtra('disabled="disabled"'); |
|
123 | - $formElement->setName($key . '-readonly'); |
|
124 | - // Since this element is disable, we still want to pass it's value in the form |
|
125 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
126 | - $this->addElement($hidden); |
|
127 | - } |
|
128 | - $formElement->setDescription($var['form_dsc']); |
|
129 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
130 | - $hidden = new XoopsFormHidden('changedField', false); |
|
131 | - $this->addElement($hidden); |
|
132 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
133 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
134 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
135 | - } else { |
|
136 | - if (isset($var['form_extra'])) { |
|
137 | - $formElement->setExtra($var['form_extra']); |
|
138 | - } |
|
139 | - } |
|
140 | - $controls = $this->targetObject->controls; |
|
141 | - if (isset($controls[$key]['js'])) { |
|
142 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
143 | - } |
|
144 | - parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
145 | - } else { |
|
146 | - parent::addElement($formElement, $required === 'notset' ? false : true); |
|
147 | - } |
|
148 | - unset($formElement); |
|
149 | - } |
|
150 | - |
|
151 | - public function createElements() |
|
152 | - { |
|
153 | - $controls = $this->targetObject->controls; |
|
154 | - $vars = $this->targetObject->vars; |
|
155 | - foreach ($vars as $key => $var) { |
|
156 | - |
|
157 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
158 | - // need to be displayed, then we only create an hidden field |
|
159 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
160 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
161 | - $this->addElement($elementToAdd, $key, $var, false); |
|
162 | - unset($elementToAdd); |
|
163 | - // If not, the we need to create the proper form control for this fields |
|
164 | - } else { |
|
165 | - // If this field has a specific control, we will use it |
|
166 | - |
|
167 | - if ($key === 'parentid') { |
|
168 | - /** |
|
169 | - * Why this ? |
|
170 | - */ |
|
171 | - } |
|
172 | - if (isset($controls[$key])) { |
|
173 | - /* If the control has name, it's because it's an object already present in the script |
|
33 | + public $targetObject = null; |
|
34 | + public $form_fields = null; |
|
35 | + public $_cancel_js_action = false; |
|
36 | + public $_custom_button = false; |
|
37 | + public $_captcha = false; |
|
38 | + public $_form_name = false; |
|
39 | + public $_form_caption = false; |
|
40 | + public $_submit_button_caption = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectForm constructor. |
|
44 | + * @param string $target |
|
45 | + * @param string $form_name |
|
46 | + * @param string $form_caption |
|
47 | + * @param string $form_action |
|
48 | + * @param null $form_fields |
|
49 | + * @param bool $submit_button_caption |
|
50 | + * @param bool $cancel_js_action |
|
51 | + * @param bool $captcha |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + &$target, |
|
55 | + $form_name, |
|
56 | + $form_caption, |
|
57 | + $form_action, |
|
58 | + $form_fields = null, |
|
59 | + $submit_button_caption = false, |
|
60 | + $cancel_js_action = false, |
|
61 | + $captcha = false |
|
62 | + ) { |
|
63 | + $this->targetObject =& $target; |
|
64 | + $this->form_fields = $form_fields; |
|
65 | + $this->_cancel_js_action = $cancel_js_action; |
|
66 | + $this->_captcha = $captcha; |
|
67 | + $this->_form_name = $form_name; |
|
68 | + $this->_form_caption = $form_caption; |
|
69 | + $this->_submit_button_caption = $submit_button_caption; |
|
70 | + |
|
71 | + if (!isset($form_action)) { |
|
72 | + $form_action = xoops_getenv('PHP_SELF'); |
|
73 | + } |
|
74 | + |
|
75 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
76 | + $this->setExtra('enctype="multipart/form-data"'); |
|
77 | + |
|
78 | + $this->createElements(); |
|
79 | + |
|
80 | + if ($captcha) { |
|
81 | + $this->addCaptcha(); |
|
82 | + } |
|
83 | + |
|
84 | + $this->createPermissionControls(); |
|
85 | + |
|
86 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
87 | + } |
|
88 | + |
|
89 | + public function addCaptcha() |
|
90 | + { |
|
91 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
92 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @param $name |
|
97 | + * @param $caption |
|
98 | + * @param bool $onclick |
|
99 | + */ |
|
100 | + public function addCustomButton($name, $caption, $onclick = false) |
|
101 | + { |
|
102 | + $custom_button_array = [ |
|
103 | + 'name' => $name, |
|
104 | + 'caption' => $caption, |
|
105 | + 'onclick' => $onclick |
|
106 | + ]; |
|
107 | + $this->_custom_button[] = $custom_button_array; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Add an element to the form |
|
112 | + * |
|
113 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
114 | + * @param bool $key |
|
115 | + * @param bool $var |
|
116 | + * @param bool|string $required is this a "required" element? |
|
117 | + */ |
|
118 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
119 | + { |
|
120 | + if ($key) { |
|
121 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
122 | + $formElement->setExtra('disabled="disabled"'); |
|
123 | + $formElement->setName($key . '-readonly'); |
|
124 | + // Since this element is disable, we still want to pass it's value in the form |
|
125 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
126 | + $this->addElement($hidden); |
|
127 | + } |
|
128 | + $formElement->setDescription($var['form_dsc']); |
|
129 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
130 | + $hidden = new XoopsFormHidden('changedField', false); |
|
131 | + $this->addElement($hidden); |
|
132 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
133 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
134 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
135 | + } else { |
|
136 | + if (isset($var['form_extra'])) { |
|
137 | + $formElement->setExtra($var['form_extra']); |
|
138 | + } |
|
139 | + } |
|
140 | + $controls = $this->targetObject->controls; |
|
141 | + if (isset($controls[$key]['js'])) { |
|
142 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
143 | + } |
|
144 | + parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
145 | + } else { |
|
146 | + parent::addElement($formElement, $required === 'notset' ? false : true); |
|
147 | + } |
|
148 | + unset($formElement); |
|
149 | + } |
|
150 | + |
|
151 | + public function createElements() |
|
152 | + { |
|
153 | + $controls = $this->targetObject->controls; |
|
154 | + $vars = $this->targetObject->vars; |
|
155 | + foreach ($vars as $key => $var) { |
|
156 | + |
|
157 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
158 | + // need to be displayed, then we only create an hidden field |
|
159 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
160 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
161 | + $this->addElement($elementToAdd, $key, $var, false); |
|
162 | + unset($elementToAdd); |
|
163 | + // If not, the we need to create the proper form control for this fields |
|
164 | + } else { |
|
165 | + // If this field has a specific control, we will use it |
|
166 | + |
|
167 | + if ($key === 'parentid') { |
|
168 | + /** |
|
169 | + * Why this ? |
|
170 | + */ |
|
171 | + } |
|
172 | + if (isset($controls[$key])) { |
|
173 | + /* If the control has name, it's because it's an object already present in the script |
|
174 | 174 | * for example, "user" |
175 | 175 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
176 | 176 | */ |
177 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
178 | - $controls[$key]['name'] = 'select'; |
|
179 | - } |
|
180 | - |
|
181 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
182 | - |
|
183 | - // Adding on the form, the control for this field |
|
184 | - $this->addElement($form_select, $key, $var); |
|
185 | - unset($form_select); |
|
186 | - |
|
187 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
188 | - } else { |
|
189 | - switch ($var['data_type']) { |
|
190 | - |
|
191 | - case XOBJ_DTYPE_TXTBOX: |
|
192 | - |
|
193 | - $form_text = $this->getControl('text', $key); |
|
194 | - $this->addElement($form_text, $key, $var); |
|
195 | - unset($form_text); |
|
196 | - break; |
|
197 | - |
|
198 | - case XOBJ_DTYPE_INT: |
|
199 | - $this->targetObject->setControl($key, [ |
|
200 | - 'name' => 'text', |
|
201 | - 'size' => '5' |
|
202 | - ]); |
|
203 | - $form_text = $this->getControl('text', $key); |
|
204 | - $this->addElement($form_text, $key, $var); |
|
205 | - unset($form_text); |
|
206 | - break; |
|
207 | - |
|
208 | - case XOBJ_DTYPE_FLOAT: |
|
209 | - $this->targetObject->setControl($key, [ |
|
210 | - 'name' => 'text', |
|
211 | - 'size' => '5' |
|
212 | - ]); |
|
213 | - $form_text = $this->getControl('text', $key); |
|
214 | - $this->addElement($form_text, $key, $var); |
|
215 | - unset($form_text); |
|
216 | - break; |
|
217 | - |
|
218 | - case XOBJ_DTYPE_LTIME: |
|
219 | - $form_date_time = $this->getControl('date_time', $key); |
|
220 | - $this->addElement($form_date_time, $key, $var); |
|
221 | - unset($form_date_time); |
|
222 | - break; |
|
223 | - |
|
224 | - case XOBJ_DTYPE_STIME: |
|
225 | - $form_date_time = $this->getControl('date', $key); |
|
226 | - $this->addElement($form_date_time, $key, $var); |
|
227 | - unset($form_date_time); |
|
228 | - break; |
|
229 | - |
|
230 | - case XOBJ_DTYPE_TIME_ONLY: |
|
231 | - $form_time = $this->getControl('time', $key); |
|
232 | - $this->addElement($form_time, $key, $var); |
|
233 | - unset($form_time); |
|
234 | - break; |
|
235 | - |
|
236 | - case XOBJ_DTYPE_CURRENCY: |
|
237 | - $this->targetObject->setControl($key, [ |
|
238 | - 'name' => 'text', |
|
239 | - 'size' => '15' |
|
240 | - ]); |
|
241 | - $form_currency = $this->getControl('text', $key); |
|
242 | - $this->addElement($form_currency, $key, $var); |
|
243 | - unset($form_currency); |
|
244 | - break; |
|
245 | - |
|
246 | - case XOBJ_DTYPE_URLLINK: |
|
247 | - $form_urllink = $this->getControl('urllink', $key); |
|
248 | - $this->addElement($form_urllink, $key, $var); |
|
249 | - unset($form_urllink); |
|
250 | - break; |
|
251 | - |
|
252 | - case XOBJ_DTYPE_FILE: |
|
253 | - $form_file = $this->getControl('richfile', $key); |
|
254 | - $this->addElement($form_file, $key, $var); |
|
255 | - unset($form_file); |
|
256 | - break; |
|
257 | - |
|
258 | - case XOBJ_DTYPE_TXTAREA: |
|
259 | - |
|
260 | - $form_text_area = $this->getTextArea($key, $var); |
|
261 | - $this->addElement($form_text_area, $key, $var); |
|
262 | - unset($form_text_area); |
|
263 | - break; |
|
264 | - |
|
265 | - case XOBJ_DTYPE_ARRAY: |
|
266 | - // TODO: To come... |
|
267 | - break; |
|
268 | - case XOBJ_DTYPE_SOURCE: |
|
269 | - // TODO: To come... |
|
270 | - break; |
|
271 | - case XOBJ_DTYPE_FORM_SECTION: |
|
272 | - $section_control = new SmartFormSection($key, $var['value']); |
|
273 | - $this->addElement($section_control, $key, $var); |
|
274 | - unset($section_control); |
|
275 | - break; |
|
276 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
277 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
278 | - $this->addElement($section_control, $key, $var); |
|
279 | - unset($section_control); |
|
280 | - break; |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - // Add an hidden field to store the URL of the page before this form |
|
286 | - $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
287 | - } |
|
288 | - |
|
289 | - public function createPermissionControls() |
|
290 | - { |
|
291 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
292 | - |
|
293 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
294 | - |
|
295 | - if ($permissions) { |
|
296 | - $memberHandler = xoops_getHandler('member'); |
|
297 | - $group_list = $memberHandler->getGroupList(); |
|
298 | - asort($group_list); |
|
299 | - foreach ($permissions as $permission) { |
|
300 | - if ($this->targetObject->isNew()) { |
|
301 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
302 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
303 | - } |
|
304 | - } else { |
|
305 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
306 | - } |
|
307 | - $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
308 | - $groups_select->setDescription($permission['description']); |
|
309 | - $groups_select->addOptionArray($group_list); |
|
310 | - $this->addElement($groups_select); |
|
311 | - unset($groups_select); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @param $form_name |
|
318 | - * @param $form_caption |
|
319 | - * @param bool $submit_button_caption |
|
320 | - */ |
|
321 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
322 | - { |
|
323 | - $button_tray = new XoopsFormElementTray('', ''); |
|
324 | - $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
325 | - if (!$submit_button_caption) { |
|
326 | - if ($this->targetObject->isNew()) { |
|
327 | - $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
328 | - } else { |
|
329 | - $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
330 | - } |
|
331 | - } else { |
|
332 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
333 | - } |
|
334 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
335 | - $button_tray->addElement($butt_create); |
|
336 | - |
|
337 | - //creating custom buttons |
|
338 | - if ($this->_custom_button) { |
|
339 | - foreach ($this->_custom_button as $custom_button) { |
|
340 | - $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
341 | - if ($custom_button['onclick']) { |
|
342 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
343 | - } |
|
344 | - $button_tray->addElement($butt_custom); |
|
345 | - unset($butt_custom); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - // creating the "cancel" button |
|
350 | - $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
351 | - if ($this->_cancel_js_action) { |
|
352 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
353 | - } else { |
|
354 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
355 | - } |
|
356 | - $button_tray->addElement($butt_cancel); |
|
357 | - |
|
358 | - $this->addElement($button_tray); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * @param $controlName |
|
363 | - * @param $key |
|
364 | - * @return XoopsFormLabel |
|
365 | - */ |
|
366 | - public function getControl($controlName, $key) |
|
367 | - { |
|
368 | - switch ($controlName) { |
|
369 | - case 'check': |
|
370 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
371 | - $control = $this->targetObject->getControl($key); |
|
372 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
373 | - $controlObj->addOptionArray($control['options']); |
|
374 | - |
|
375 | - return $controlObj; |
|
376 | - break; |
|
377 | - |
|
378 | - case 'color': |
|
379 | - $control = $this->targetObject->getControl($key); |
|
380 | - $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
381 | - |
|
382 | - return $controlObj; |
|
383 | - break; |
|
384 | - |
|
385 | - case 'radio': |
|
386 | - $control = $this->targetObject->getControl($key); |
|
387 | - |
|
388 | - $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
389 | - $controlObj->addOptionArray($control['options']); |
|
390 | - |
|
391 | - return $controlObj; |
|
392 | - break; |
|
393 | - |
|
394 | - case 'label': |
|
395 | - return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
396 | - break; |
|
397 | - |
|
398 | - case 'textarea': |
|
399 | - return $this->getTextArea($key); |
|
400 | - |
|
401 | - case 'theme': |
|
402 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
403 | - |
|
404 | - case 'theme_multi': |
|
405 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
406 | - break; |
|
407 | - |
|
408 | - case 'timezone': |
|
409 | - return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
410 | - break; |
|
411 | - |
|
412 | - case 'group': |
|
413 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
414 | - break; |
|
415 | - |
|
416 | - case 'group_multi': |
|
417 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
418 | - break; |
|
419 | - |
|
420 | - /*case 'user': |
|
177 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
178 | + $controls[$key]['name'] = 'select'; |
|
179 | + } |
|
180 | + |
|
181 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
182 | + |
|
183 | + // Adding on the form, the control for this field |
|
184 | + $this->addElement($form_select, $key, $var); |
|
185 | + unset($form_select); |
|
186 | + |
|
187 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
188 | + } else { |
|
189 | + switch ($var['data_type']) { |
|
190 | + |
|
191 | + case XOBJ_DTYPE_TXTBOX: |
|
192 | + |
|
193 | + $form_text = $this->getControl('text', $key); |
|
194 | + $this->addElement($form_text, $key, $var); |
|
195 | + unset($form_text); |
|
196 | + break; |
|
197 | + |
|
198 | + case XOBJ_DTYPE_INT: |
|
199 | + $this->targetObject->setControl($key, [ |
|
200 | + 'name' => 'text', |
|
201 | + 'size' => '5' |
|
202 | + ]); |
|
203 | + $form_text = $this->getControl('text', $key); |
|
204 | + $this->addElement($form_text, $key, $var); |
|
205 | + unset($form_text); |
|
206 | + break; |
|
207 | + |
|
208 | + case XOBJ_DTYPE_FLOAT: |
|
209 | + $this->targetObject->setControl($key, [ |
|
210 | + 'name' => 'text', |
|
211 | + 'size' => '5' |
|
212 | + ]); |
|
213 | + $form_text = $this->getControl('text', $key); |
|
214 | + $this->addElement($form_text, $key, $var); |
|
215 | + unset($form_text); |
|
216 | + break; |
|
217 | + |
|
218 | + case XOBJ_DTYPE_LTIME: |
|
219 | + $form_date_time = $this->getControl('date_time', $key); |
|
220 | + $this->addElement($form_date_time, $key, $var); |
|
221 | + unset($form_date_time); |
|
222 | + break; |
|
223 | + |
|
224 | + case XOBJ_DTYPE_STIME: |
|
225 | + $form_date_time = $this->getControl('date', $key); |
|
226 | + $this->addElement($form_date_time, $key, $var); |
|
227 | + unset($form_date_time); |
|
228 | + break; |
|
229 | + |
|
230 | + case XOBJ_DTYPE_TIME_ONLY: |
|
231 | + $form_time = $this->getControl('time', $key); |
|
232 | + $this->addElement($form_time, $key, $var); |
|
233 | + unset($form_time); |
|
234 | + break; |
|
235 | + |
|
236 | + case XOBJ_DTYPE_CURRENCY: |
|
237 | + $this->targetObject->setControl($key, [ |
|
238 | + 'name' => 'text', |
|
239 | + 'size' => '15' |
|
240 | + ]); |
|
241 | + $form_currency = $this->getControl('text', $key); |
|
242 | + $this->addElement($form_currency, $key, $var); |
|
243 | + unset($form_currency); |
|
244 | + break; |
|
245 | + |
|
246 | + case XOBJ_DTYPE_URLLINK: |
|
247 | + $form_urllink = $this->getControl('urllink', $key); |
|
248 | + $this->addElement($form_urllink, $key, $var); |
|
249 | + unset($form_urllink); |
|
250 | + break; |
|
251 | + |
|
252 | + case XOBJ_DTYPE_FILE: |
|
253 | + $form_file = $this->getControl('richfile', $key); |
|
254 | + $this->addElement($form_file, $key, $var); |
|
255 | + unset($form_file); |
|
256 | + break; |
|
257 | + |
|
258 | + case XOBJ_DTYPE_TXTAREA: |
|
259 | + |
|
260 | + $form_text_area = $this->getTextArea($key, $var); |
|
261 | + $this->addElement($form_text_area, $key, $var); |
|
262 | + unset($form_text_area); |
|
263 | + break; |
|
264 | + |
|
265 | + case XOBJ_DTYPE_ARRAY: |
|
266 | + // TODO: To come... |
|
267 | + break; |
|
268 | + case XOBJ_DTYPE_SOURCE: |
|
269 | + // TODO: To come... |
|
270 | + break; |
|
271 | + case XOBJ_DTYPE_FORM_SECTION: |
|
272 | + $section_control = new SmartFormSection($key, $var['value']); |
|
273 | + $this->addElement($section_control, $key, $var); |
|
274 | + unset($section_control); |
|
275 | + break; |
|
276 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
277 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
278 | + $this->addElement($section_control, $key, $var); |
|
279 | + unset($section_control); |
|
280 | + break; |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + // Add an hidden field to store the URL of the page before this form |
|
286 | + $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
287 | + } |
|
288 | + |
|
289 | + public function createPermissionControls() |
|
290 | + { |
|
291 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
292 | + |
|
293 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
294 | + |
|
295 | + if ($permissions) { |
|
296 | + $memberHandler = xoops_getHandler('member'); |
|
297 | + $group_list = $memberHandler->getGroupList(); |
|
298 | + asort($group_list); |
|
299 | + foreach ($permissions as $permission) { |
|
300 | + if ($this->targetObject->isNew()) { |
|
301 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
302 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
303 | + } |
|
304 | + } else { |
|
305 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
306 | + } |
|
307 | + $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
308 | + $groups_select->setDescription($permission['description']); |
|
309 | + $groups_select->addOptionArray($group_list); |
|
310 | + $this->addElement($groups_select); |
|
311 | + unset($groups_select); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @param $form_name |
|
318 | + * @param $form_caption |
|
319 | + * @param bool $submit_button_caption |
|
320 | + */ |
|
321 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
322 | + { |
|
323 | + $button_tray = new XoopsFormElementTray('', ''); |
|
324 | + $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
325 | + if (!$submit_button_caption) { |
|
326 | + if ($this->targetObject->isNew()) { |
|
327 | + $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
328 | + } else { |
|
329 | + $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
330 | + } |
|
331 | + } else { |
|
332 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
333 | + } |
|
334 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
335 | + $button_tray->addElement($butt_create); |
|
336 | + |
|
337 | + //creating custom buttons |
|
338 | + if ($this->_custom_button) { |
|
339 | + foreach ($this->_custom_button as $custom_button) { |
|
340 | + $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
341 | + if ($custom_button['onclick']) { |
|
342 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
343 | + } |
|
344 | + $button_tray->addElement($butt_custom); |
|
345 | + unset($butt_custom); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + // creating the "cancel" button |
|
350 | + $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
351 | + if ($this->_cancel_js_action) { |
|
352 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
353 | + } else { |
|
354 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
355 | + } |
|
356 | + $button_tray->addElement($butt_cancel); |
|
357 | + |
|
358 | + $this->addElement($button_tray); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * @param $controlName |
|
363 | + * @param $key |
|
364 | + * @return XoopsFormLabel |
|
365 | + */ |
|
366 | + public function getControl($controlName, $key) |
|
367 | + { |
|
368 | + switch ($controlName) { |
|
369 | + case 'check': |
|
370 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
371 | + $control = $this->targetObject->getControl($key); |
|
372 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
373 | + $controlObj->addOptionArray($control['options']); |
|
374 | + |
|
375 | + return $controlObj; |
|
376 | + break; |
|
377 | + |
|
378 | + case 'color': |
|
379 | + $control = $this->targetObject->getControl($key); |
|
380 | + $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
381 | + |
|
382 | + return $controlObj; |
|
383 | + break; |
|
384 | + |
|
385 | + case 'radio': |
|
386 | + $control = $this->targetObject->getControl($key); |
|
387 | + |
|
388 | + $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
389 | + $controlObj->addOptionArray($control['options']); |
|
390 | + |
|
391 | + return $controlObj; |
|
392 | + break; |
|
393 | + |
|
394 | + case 'label': |
|
395 | + return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
396 | + break; |
|
397 | + |
|
398 | + case 'textarea': |
|
399 | + return $this->getTextArea($key); |
|
400 | + |
|
401 | + case 'theme': |
|
402 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
403 | + |
|
404 | + case 'theme_multi': |
|
405 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
406 | + break; |
|
407 | + |
|
408 | + case 'timezone': |
|
409 | + return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
410 | + break; |
|
411 | + |
|
412 | + case 'group': |
|
413 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
414 | + break; |
|
415 | + |
|
416 | + case 'group_multi': |
|
417 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
418 | + break; |
|
419 | + |
|
420 | + /*case 'user': |
|
421 | 421 | return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
422 | 422 | break;*/ |
423 | 423 | |
424 | - case 'user_multi': |
|
425 | - return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
426 | - break; |
|
427 | - |
|
428 | - case 'password': |
|
429 | - return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
430 | - break; |
|
431 | - |
|
432 | - case 'country': |
|
433 | - return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
434 | - break; |
|
435 | - |
|
436 | - case 'urllink': |
|
437 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
438 | - |
|
439 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
440 | - break; |
|
441 | - |
|
442 | - case 'richfile': |
|
443 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
444 | - |
|
445 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
446 | - break; |
|
447 | - case 'section': |
|
448 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
449 | - |
|
450 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
451 | - break; |
|
452 | - |
|
453 | - default: |
|
454 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
455 | - if (!class_exists($classname)) { |
|
456 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
457 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
458 | - } else { |
|
459 | - // perhaps this is a control created by the module |
|
460 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
461 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
462 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
463 | - $classFileName = strtolower($classname) . '.php'; |
|
464 | - |
|
465 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
466 | - require_once $moduleFormElementsPath . $classFileName; |
|
467 | - } else { |
|
468 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
469 | - |
|
470 | - return new XoopsFormLabel(); //Empty object |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - return new $classname($this->targetObject, $key); |
|
476 | - break; |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @param $key |
|
482 | - * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
483 | - */ |
|
484 | - public function getTextArea($key) |
|
485 | - { |
|
486 | - $var = $this->targetObject->vars[$key]; |
|
487 | - |
|
488 | - // if no control has been created, let's create a default one |
|
489 | - if (!isset($this->targetObject->controls[$key])) { |
|
490 | - $control = [ |
|
491 | - 'name' => 'textarea', |
|
492 | - 'itemHandler' => false, |
|
493 | - 'method' => false, |
|
494 | - 'module' => false, |
|
495 | - 'form_editor' => 'default' |
|
496 | - ]; |
|
497 | - } else { |
|
498 | - $control = $this->targetObject->controls[$key]; |
|
499 | - } |
|
500 | - $xoops22 = smart_isXoops22(); |
|
501 | - |
|
502 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
503 | - /** |
|
504 | - * If the editor is 'default', retreive the default editor of this module |
|
505 | - */ |
|
506 | - if ($form_editor === 'default') { |
|
507 | - global $xoopsModuleConfig; |
|
508 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
509 | - } |
|
510 | - |
|
511 | - $caption = $var['form_caption']; |
|
512 | - $name = $key; |
|
513 | - |
|
514 | - $value = $this->targetObject->getVar($key); |
|
515 | - |
|
516 | - $value = $this->targetObject->getValueFor($key, true); |
|
517 | - |
|
518 | - $editor_configs = []; |
|
519 | - $editor_configs['name'] = $name; |
|
520 | - $editor_configs['value'] = $value; |
|
521 | - if ($form_editor !== 'textarea') { |
|
522 | - $editor_configs['rows'] = 35; |
|
523 | - $editor_configs['cols'] = 60; |
|
524 | - } |
|
525 | - |
|
526 | - if (isset($control['rows'])) { |
|
527 | - $editor_configs['rows'] = $control['rows']; |
|
528 | - } |
|
529 | - if (isset($control['cols'])) { |
|
530 | - $editor_configs['cols'] = $control['cols']; |
|
531 | - } |
|
532 | - |
|
533 | - $editor_configs['width'] = '100%'; |
|
534 | - $editor_configs['height'] = '400px'; |
|
535 | - |
|
536 | - $dhtml = true; |
|
537 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
538 | - |
|
539 | - if (file_exists($xoopseditorclass)) { |
|
540 | - require_once $xoopseditorclass; |
|
541 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
542 | - } else { |
|
543 | - switch ($form_editor) { |
|
544 | - |
|
545 | - case 'tiny': |
|
546 | - if (!$xoops22) { |
|
547 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
548 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
549 | - $editor = new XoopsFormTinyTextArea([ |
|
550 | - 'caption' => $caption, |
|
551 | - 'name' => $name, |
|
552 | - 'value' => $value, |
|
553 | - 'width' => '100%', |
|
554 | - 'height' => '300px' |
|
555 | - ], true); |
|
556 | - } else { |
|
557 | - if ($dhtml) { |
|
558 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
559 | - } else { |
|
560 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
561 | - } |
|
562 | - } |
|
563 | - } else { |
|
564 | - $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
565 | - } |
|
566 | - break; |
|
567 | - |
|
568 | - case 'dhtmltextarea': |
|
569 | - case 'dhtmltext': |
|
570 | - $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
571 | - if ($var['form_dsc']) { |
|
572 | - $editor->setDescription($var['form_dsc']); |
|
573 | - } |
|
574 | - break; |
|
575 | - |
|
576 | - case 'fckeditor': |
|
577 | - if (!$xoops22) { |
|
578 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
579 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
580 | - $editor = new XoopsFormFckeditor([ |
|
581 | - 'caption' => $caption, |
|
582 | - 'name' => $name, |
|
583 | - 'value' => $value, |
|
584 | - 'width' => '100%', |
|
585 | - 'height' => '300px' |
|
586 | - ], true); |
|
587 | - } else { |
|
588 | - if ($dhtml) { |
|
589 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
590 | - } else { |
|
591 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
592 | - } |
|
593 | - } |
|
594 | - } else { |
|
595 | - $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
596 | - } |
|
597 | - break; |
|
598 | - |
|
599 | - case 'inbetween': |
|
600 | - if (!$xoops22) { |
|
601 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
602 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
603 | - $editor = new XoopsFormInbetweenTextArea([ |
|
604 | - 'caption' => $caption, |
|
605 | - 'name' => $name, |
|
606 | - 'value' => $value, |
|
607 | - 'width' => '100%', |
|
608 | - 'height' => '300px' |
|
609 | - ], true); |
|
610 | - } else { |
|
611 | - if ($dhtml) { |
|
612 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
613 | - } else { |
|
614 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
615 | - } |
|
616 | - } |
|
617 | - } else { |
|
618 | - $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
619 | - } |
|
620 | - break; |
|
621 | - |
|
622 | - case 'koivi': |
|
623 | - if (!$xoops22) { |
|
624 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
625 | - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
626 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
627 | - } else { |
|
628 | - if ($dhtml) { |
|
629 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
630 | - } else { |
|
631 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
632 | - } |
|
633 | - } |
|
634 | - } else { |
|
635 | - $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
636 | - } |
|
637 | - break; |
|
638 | - |
|
639 | - case 'spaw': |
|
640 | - if (!$xoops22) { |
|
641 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
642 | - require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
643 | - $editor = new XoopsFormSpaw($caption, $name, $value); |
|
644 | - } |
|
645 | - } else { |
|
646 | - $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
647 | - } |
|
648 | - break; |
|
649 | - |
|
650 | - case 'htmlarea': |
|
651 | - if (!$xoops22) { |
|
652 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
653 | - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
654 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
655 | - } |
|
656 | - } else { |
|
657 | - $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
658 | - } |
|
659 | - break; |
|
660 | - |
|
661 | - default: |
|
662 | - case 'textarea': |
|
663 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
664 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
665 | - |
|
666 | - $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
667 | - if ($var['form_dsc']) { |
|
668 | - $editor->setDescription($var['form_dsc']); |
|
669 | - } |
|
670 | - break; |
|
671 | - |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - return $editor; |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * @param $key |
|
680 | - * @param $var |
|
681 | - * @param bool $multiple |
|
682 | - * @return XoopsFormSelect |
|
683 | - */ |
|
684 | - public function getThemeSelect($key, $var, $multiple = false) |
|
685 | - { |
|
686 | - $size = $multiple ? 5 : 1; |
|
687 | - $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
688 | - |
|
689 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
690 | - $dirlist = []; |
|
691 | - while (false !== ($file = readdir($handle))) { |
|
692 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
693 | - && strtolower($file) !== 'cvs') { |
|
694 | - $dirlist[$file] = $file; |
|
695 | - } |
|
696 | - } |
|
697 | - closedir($handle); |
|
698 | - if (!empty($dirlist)) { |
|
699 | - asort($dirlist); |
|
700 | - $theme_select->addOptionArray($dirlist); |
|
701 | - } |
|
702 | - |
|
703 | - return $theme_select; |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * @param $keyname |
|
708 | - * @return bool |
|
709 | - */ |
|
710 | - public function &getElementById($keyname) |
|
711 | - { |
|
712 | - foreach ($this->_elements as $eleObj) { |
|
713 | - if ($eleObj->getName() == $keyname) { |
|
714 | - $ret =& $eleObj; |
|
715 | - break; |
|
716 | - } |
|
717 | - } |
|
718 | - |
|
719 | - return isset($ret) ? $ret : false; |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * create HTML to output the form as a theme-enabled table with validation. |
|
724 | - * |
|
725 | - * @return string |
|
726 | - */ |
|
727 | - public function render() |
|
728 | - { |
|
729 | - $required = $this->getRequired(); |
|
730 | - $ret = " |
|
424 | + case 'user_multi': |
|
425 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
426 | + break; |
|
427 | + |
|
428 | + case 'password': |
|
429 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
430 | + break; |
|
431 | + |
|
432 | + case 'country': |
|
433 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
434 | + break; |
|
435 | + |
|
436 | + case 'urllink': |
|
437 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
438 | + |
|
439 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
440 | + break; |
|
441 | + |
|
442 | + case 'richfile': |
|
443 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
444 | + |
|
445 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
446 | + break; |
|
447 | + case 'section': |
|
448 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
449 | + |
|
450 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
451 | + break; |
|
452 | + |
|
453 | + default: |
|
454 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
455 | + if (!class_exists($classname)) { |
|
456 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
457 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
458 | + } else { |
|
459 | + // perhaps this is a control created by the module |
|
460 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
461 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
462 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
463 | + $classFileName = strtolower($classname) . '.php'; |
|
464 | + |
|
465 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
466 | + require_once $moduleFormElementsPath . $classFileName; |
|
467 | + } else { |
|
468 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
469 | + |
|
470 | + return new XoopsFormLabel(); //Empty object |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + return new $classname($this->targetObject, $key); |
|
476 | + break; |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @param $key |
|
482 | + * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
483 | + */ |
|
484 | + public function getTextArea($key) |
|
485 | + { |
|
486 | + $var = $this->targetObject->vars[$key]; |
|
487 | + |
|
488 | + // if no control has been created, let's create a default one |
|
489 | + if (!isset($this->targetObject->controls[$key])) { |
|
490 | + $control = [ |
|
491 | + 'name' => 'textarea', |
|
492 | + 'itemHandler' => false, |
|
493 | + 'method' => false, |
|
494 | + 'module' => false, |
|
495 | + 'form_editor' => 'default' |
|
496 | + ]; |
|
497 | + } else { |
|
498 | + $control = $this->targetObject->controls[$key]; |
|
499 | + } |
|
500 | + $xoops22 = smart_isXoops22(); |
|
501 | + |
|
502 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
503 | + /** |
|
504 | + * If the editor is 'default', retreive the default editor of this module |
|
505 | + */ |
|
506 | + if ($form_editor === 'default') { |
|
507 | + global $xoopsModuleConfig; |
|
508 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
509 | + } |
|
510 | + |
|
511 | + $caption = $var['form_caption']; |
|
512 | + $name = $key; |
|
513 | + |
|
514 | + $value = $this->targetObject->getVar($key); |
|
515 | + |
|
516 | + $value = $this->targetObject->getValueFor($key, true); |
|
517 | + |
|
518 | + $editor_configs = []; |
|
519 | + $editor_configs['name'] = $name; |
|
520 | + $editor_configs['value'] = $value; |
|
521 | + if ($form_editor !== 'textarea') { |
|
522 | + $editor_configs['rows'] = 35; |
|
523 | + $editor_configs['cols'] = 60; |
|
524 | + } |
|
525 | + |
|
526 | + if (isset($control['rows'])) { |
|
527 | + $editor_configs['rows'] = $control['rows']; |
|
528 | + } |
|
529 | + if (isset($control['cols'])) { |
|
530 | + $editor_configs['cols'] = $control['cols']; |
|
531 | + } |
|
532 | + |
|
533 | + $editor_configs['width'] = '100%'; |
|
534 | + $editor_configs['height'] = '400px'; |
|
535 | + |
|
536 | + $dhtml = true; |
|
537 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
538 | + |
|
539 | + if (file_exists($xoopseditorclass)) { |
|
540 | + require_once $xoopseditorclass; |
|
541 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
542 | + } else { |
|
543 | + switch ($form_editor) { |
|
544 | + |
|
545 | + case 'tiny': |
|
546 | + if (!$xoops22) { |
|
547 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
548 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
549 | + $editor = new XoopsFormTinyTextArea([ |
|
550 | + 'caption' => $caption, |
|
551 | + 'name' => $name, |
|
552 | + 'value' => $value, |
|
553 | + 'width' => '100%', |
|
554 | + 'height' => '300px' |
|
555 | + ], true); |
|
556 | + } else { |
|
557 | + if ($dhtml) { |
|
558 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
559 | + } else { |
|
560 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
561 | + } |
|
562 | + } |
|
563 | + } else { |
|
564 | + $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
565 | + } |
|
566 | + break; |
|
567 | + |
|
568 | + case 'dhtmltextarea': |
|
569 | + case 'dhtmltext': |
|
570 | + $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
571 | + if ($var['form_dsc']) { |
|
572 | + $editor->setDescription($var['form_dsc']); |
|
573 | + } |
|
574 | + break; |
|
575 | + |
|
576 | + case 'fckeditor': |
|
577 | + if (!$xoops22) { |
|
578 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
579 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
580 | + $editor = new XoopsFormFckeditor([ |
|
581 | + 'caption' => $caption, |
|
582 | + 'name' => $name, |
|
583 | + 'value' => $value, |
|
584 | + 'width' => '100%', |
|
585 | + 'height' => '300px' |
|
586 | + ], true); |
|
587 | + } else { |
|
588 | + if ($dhtml) { |
|
589 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
590 | + } else { |
|
591 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
592 | + } |
|
593 | + } |
|
594 | + } else { |
|
595 | + $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
596 | + } |
|
597 | + break; |
|
598 | + |
|
599 | + case 'inbetween': |
|
600 | + if (!$xoops22) { |
|
601 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
602 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
603 | + $editor = new XoopsFormInbetweenTextArea([ |
|
604 | + 'caption' => $caption, |
|
605 | + 'name' => $name, |
|
606 | + 'value' => $value, |
|
607 | + 'width' => '100%', |
|
608 | + 'height' => '300px' |
|
609 | + ], true); |
|
610 | + } else { |
|
611 | + if ($dhtml) { |
|
612 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
613 | + } else { |
|
614 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
615 | + } |
|
616 | + } |
|
617 | + } else { |
|
618 | + $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
619 | + } |
|
620 | + break; |
|
621 | + |
|
622 | + case 'koivi': |
|
623 | + if (!$xoops22) { |
|
624 | + if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
625 | + require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
626 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
627 | + } else { |
|
628 | + if ($dhtml) { |
|
629 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
630 | + } else { |
|
631 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
632 | + } |
|
633 | + } |
|
634 | + } else { |
|
635 | + $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
636 | + } |
|
637 | + break; |
|
638 | + |
|
639 | + case 'spaw': |
|
640 | + if (!$xoops22) { |
|
641 | + if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
642 | + require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
643 | + $editor = new XoopsFormSpaw($caption, $name, $value); |
|
644 | + } |
|
645 | + } else { |
|
646 | + $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
647 | + } |
|
648 | + break; |
|
649 | + |
|
650 | + case 'htmlarea': |
|
651 | + if (!$xoops22) { |
|
652 | + if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
653 | + require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
654 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
655 | + } |
|
656 | + } else { |
|
657 | + $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
658 | + } |
|
659 | + break; |
|
660 | + |
|
661 | + default: |
|
662 | + case 'textarea': |
|
663 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
664 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
665 | + |
|
666 | + $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
667 | + if ($var['form_dsc']) { |
|
668 | + $editor->setDescription($var['form_dsc']); |
|
669 | + } |
|
670 | + break; |
|
671 | + |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + return $editor; |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * @param $key |
|
680 | + * @param $var |
|
681 | + * @param bool $multiple |
|
682 | + * @return XoopsFormSelect |
|
683 | + */ |
|
684 | + public function getThemeSelect($key, $var, $multiple = false) |
|
685 | + { |
|
686 | + $size = $multiple ? 5 : 1; |
|
687 | + $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
688 | + |
|
689 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
690 | + $dirlist = []; |
|
691 | + while (false !== ($file = readdir($handle))) { |
|
692 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
693 | + && strtolower($file) !== 'cvs') { |
|
694 | + $dirlist[$file] = $file; |
|
695 | + } |
|
696 | + } |
|
697 | + closedir($handle); |
|
698 | + if (!empty($dirlist)) { |
|
699 | + asort($dirlist); |
|
700 | + $theme_select->addOptionArray($dirlist); |
|
701 | + } |
|
702 | + |
|
703 | + return $theme_select; |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * @param $keyname |
|
708 | + * @return bool |
|
709 | + */ |
|
710 | + public function &getElementById($keyname) |
|
711 | + { |
|
712 | + foreach ($this->_elements as $eleObj) { |
|
713 | + if ($eleObj->getName() == $keyname) { |
|
714 | + $ret =& $eleObj; |
|
715 | + break; |
|
716 | + } |
|
717 | + } |
|
718 | + |
|
719 | + return isset($ret) ? $ret : false; |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * create HTML to output the form as a theme-enabled table with validation. |
|
724 | + * |
|
725 | + * @return string |
|
726 | + */ |
|
727 | + public function render() |
|
728 | + { |
|
729 | + $required = $this->getRequired(); |
|
730 | + $ret = " |
|
731 | 731 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
732 | 732 | <table width='100%' class='outer' cellspacing='1'> |
733 | 733 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
734 | 734 | '; |
735 | - $hidden = ''; |
|
736 | - $class = 'even'; |
|
737 | - foreach ($this->getElements() as $ele) { |
|
738 | - if (!is_object($ele)) { |
|
739 | - $ret .= $ele; |
|
740 | - } elseif (!$ele->isHidden()) { |
|
741 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
742 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
743 | - if ($ele->getDescription() !== '') { |
|
744 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
745 | - } |
|
746 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
747 | - } else { |
|
748 | - $hidden .= $ele->render(); |
|
749 | - } |
|
750 | - } |
|
751 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
752 | - $ret .= $this->renderValidationJS(true); |
|
753 | - |
|
754 | - return $ret; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * assign to smarty form template instead of displaying directly |
|
759 | - * |
|
760 | - * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
761 | - * @param bool $smartyName |
|
762 | - * @see Smarty |
|
763 | - */ |
|
764 | - public function assign(XoopsTpl $tpl, $smartyName = false) |
|
765 | - { |
|
766 | - $i = 0; |
|
767 | - $elements = []; |
|
768 | - foreach ($this->getElements() as $ele) { |
|
769 | - $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
770 | - $elements[$n]['name'] = $ele->getName(); |
|
771 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
772 | - $elements[$n]['body'] = $ele->render(); |
|
773 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
774 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
775 | - $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
776 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
777 | - if ($ele->getDescription() !== '') { |
|
778 | - $elements[$n]['description'] = $ele->getDescription(); |
|
779 | - } |
|
780 | - ++$i; |
|
781 | - } |
|
782 | - $js = $this->renderValidationJS(); |
|
783 | - if (!$smartyName) { |
|
784 | - $smartyName = $this->getName(); |
|
785 | - } |
|
786 | - |
|
787 | - $tpl->assign($smartyName, [ |
|
788 | - 'title' => $this->getTitle(), |
|
789 | - 'name' => $this->getName(), |
|
790 | - 'action' => $this->getAction(), |
|
791 | - 'method' => $this->getMethod(), |
|
792 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
793 | - 'javascript' => $js, |
|
794 | - 'elements' => $elements |
|
795 | - ]); |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * @param bool $withtags |
|
800 | - * @return string |
|
801 | - */ |
|
802 | - public function renderValidationJS($withtags = true) |
|
803 | - { |
|
804 | - $js = ''; |
|
805 | - if ($withtags) { |
|
806 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
807 | - } |
|
808 | - $myts = MyTextSanitizer::getInstance(); |
|
809 | - $formname = $this->getName(); |
|
810 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
811 | - // First, output code to check required elements |
|
812 | - $elements = $this->getRequired(); |
|
813 | - foreach ($elements as $elt) { |
|
814 | - $eltname = $elt->getName(); |
|
815 | - $eltcaption = trim($elt->getCaption()); |
|
816 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
817 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
818 | - if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
819 | - $js .= 'var myOption = -1;'; |
|
820 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
735 | + $hidden = ''; |
|
736 | + $class = 'even'; |
|
737 | + foreach ($this->getElements() as $ele) { |
|
738 | + if (!is_object($ele)) { |
|
739 | + $ret .= $ele; |
|
740 | + } elseif (!$ele->isHidden()) { |
|
741 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
742 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
743 | + if ($ele->getDescription() !== '') { |
|
744 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
745 | + } |
|
746 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
747 | + } else { |
|
748 | + $hidden .= $ele->render(); |
|
749 | + } |
|
750 | + } |
|
751 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
752 | + $ret .= $this->renderValidationJS(true); |
|
753 | + |
|
754 | + return $ret; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * assign to smarty form template instead of displaying directly |
|
759 | + * |
|
760 | + * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
761 | + * @param bool $smartyName |
|
762 | + * @see Smarty |
|
763 | + */ |
|
764 | + public function assign(XoopsTpl $tpl, $smartyName = false) |
|
765 | + { |
|
766 | + $i = 0; |
|
767 | + $elements = []; |
|
768 | + foreach ($this->getElements() as $ele) { |
|
769 | + $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
770 | + $elements[$n]['name'] = $ele->getName(); |
|
771 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
772 | + $elements[$n]['body'] = $ele->render(); |
|
773 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
774 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
775 | + $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
776 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
777 | + if ($ele->getDescription() !== '') { |
|
778 | + $elements[$n]['description'] = $ele->getDescription(); |
|
779 | + } |
|
780 | + ++$i; |
|
781 | + } |
|
782 | + $js = $this->renderValidationJS(); |
|
783 | + if (!$smartyName) { |
|
784 | + $smartyName = $this->getName(); |
|
785 | + } |
|
786 | + |
|
787 | + $tpl->assign($smartyName, [ |
|
788 | + 'title' => $this->getTitle(), |
|
789 | + 'name' => $this->getName(), |
|
790 | + 'action' => $this->getAction(), |
|
791 | + 'method' => $this->getMethod(), |
|
792 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
793 | + 'javascript' => $js, |
|
794 | + 'elements' => $elements |
|
795 | + ]); |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * @param bool $withtags |
|
800 | + * @return string |
|
801 | + */ |
|
802 | + public function renderValidationJS($withtags = true) |
|
803 | + { |
|
804 | + $js = ''; |
|
805 | + if ($withtags) { |
|
806 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
807 | + } |
|
808 | + $myts = MyTextSanitizer::getInstance(); |
|
809 | + $formname = $this->getName(); |
|
810 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
811 | + // First, output code to check required elements |
|
812 | + $elements = $this->getRequired(); |
|
813 | + foreach ($elements as $elt) { |
|
814 | + $eltname = $elt->getName(); |
|
815 | + $eltcaption = trim($elt->getCaption()); |
|
816 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
817 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
818 | + if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
819 | + $js .= 'var myOption = -1;'; |
|
820 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
821 | 821 | if (myform.{$eltname}[i].checked) { |
822 | 822 | myOption = i; i = -1; |
823 | 823 | } |
824 | 824 | } |
825 | 825 | if (myOption == -1) { |
826 | 826 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
827 | - } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
828 | - $js .= 'var hasSelections = false;'; |
|
829 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
827 | + } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
828 | + $js .= 'var hasSelections = false;'; |
|
829 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
830 | 830 | if (myform['{$eltname}[]'].options[i].selected) { |
831 | 831 | hasSelections = true; |
832 | 832 | } |
@@ -834,12 +834,12 @@ discard block |
||
834 | 834 | } |
835 | 835 | if (hasSelections === false) { |
836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
837 | - } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
838 | - || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
839 | - $js .= 'var hasSelections = false;'; |
|
840 | - //sometimes, there is an implicit '[]', sometimes not |
|
841 | - if (strpos($eltname, '[') === false) { |
|
842 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
837 | + } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
838 | + || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
839 | + $js .= 'var hasSelections = false;'; |
|
840 | + //sometimes, there is an implicit '[]', sometimes not |
|
841 | + if (strpos($eltname, '[') === false) { |
|
842 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
843 | 843 | if (myform['{$eltname}[]'][i].checked) { |
844 | 844 | hasSelections = true; |
845 | 845 | } |
@@ -847,8 +847,8 @@ discard block |
||
847 | 847 | } |
848 | 848 | if (hasSelections === false) { |
849 | 849 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
850 | - } else { |
|
851 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
850 | + } else { |
|
851 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
852 | 852 | if (myform['{$eltname}'][i].checked) { |
853 | 853 | hasSelections = true; |
854 | 854 | } |
@@ -856,25 +856,25 @@ discard block |
||
856 | 856 | } |
857 | 857 | if (hasSelections === false) { |
858 | 858 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
859 | - } |
|
860 | - } else { |
|
861 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
862 | - } |
|
863 | - } |
|
864 | - // Now, handle custom validation code |
|
865 | - $elements =& $this->getElements(true); |
|
866 | - foreach ($elements as $elt) { |
|
867 | - if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
868 | - if ($eltjs = $elt->renderValidationJS()) { |
|
869 | - $js .= $eltjs . "\n"; |
|
870 | - } |
|
871 | - } |
|
872 | - } |
|
873 | - $js .= "return true;\n}\n"; |
|
874 | - if ($withtags) { |
|
875 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
876 | - } |
|
877 | - |
|
878 | - return $js; |
|
879 | - } |
|
859 | + } |
|
860 | + } else { |
|
861 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
862 | + } |
|
863 | + } |
|
864 | + // Now, handle custom validation code |
|
865 | + $elements =& $this->getElements(true); |
|
866 | + foreach ($elements as $elt) { |
|
867 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
868 | + if ($eltjs = $elt->renderValidationJS()) { |
|
869 | + $js .= $eltjs . "\n"; |
|
870 | + } |
|
871 | + } |
|
872 | + } |
|
873 | + $js .= "return true;\n}\n"; |
|
874 | + if ($withtags) { |
|
875 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
876 | + } |
|
877 | + |
|
878 | + return $js; |
|
879 | + } |
|
880 | 880 | } |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Including the XoopsFormLoader classes |
17 | 17 | */ |
18 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
19 | -require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
20 | -require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php'; |
|
18 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
19 | +require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php'; |
|
20 | +require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsectionclose.php'; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * SmartForm base class |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $cancel_js_action = false, |
61 | 61 | $captcha = false |
62 | 62 | ) { |
63 | - $this->targetObject =& $target; |
|
63 | + $this->targetObject = & $target; |
|
64 | 64 | $this->form_fields = $form_fields; |
65 | 65 | $this->_cancel_js_action = $cancel_js_action; |
66 | 66 | $this->_captcha = $captcha; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | public function addCaptcha() |
90 | 90 | { |
91 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
91 | + require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php'; |
|
92 | 92 | $this->addElement(new XoopsFormCaptcha(), true); |
93 | 93 | } |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function addCustomButton($name, $caption, $onclick = false) |
101 | 101 | { |
102 | - $custom_button_array = [ |
|
102 | + $custom_button_array = [ |
|
103 | 103 | 'name' => $name, |
104 | 104 | 'caption' => $caption, |
105 | 105 | 'onclick' => $onclick |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | if ($key) { |
121 | 121 | if ($this->targetObject->vars[$key]['readonly']) { |
122 | 122 | $formElement->setExtra('disabled="disabled"'); |
123 | - $formElement->setName($key . '-readonly'); |
|
123 | + $formElement->setName($key.'-readonly'); |
|
124 | 124 | // Since this element is disable, we still want to pass it's value in the form |
125 | 125 | $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
126 | 126 | $this->addElement($hidden); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $this->addElement($hidden); |
132 | 132 | $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
133 | 133 | $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
134 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
134 | + $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra); |
|
135 | 135 | } else { |
136 | 136 | if (isset($var['form_extra'])) { |
137 | 137 | $formElement->setExtra($var['form_extra']); |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | asort($group_list); |
299 | 299 | foreach ($permissions as $permission) { |
300 | 300 | if ($this->targetObject->isNew()) { |
301 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
302 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
301 | + if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) { |
|
302 | + $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']]; |
|
303 | 303 | } |
304 | 304 | } else { |
305 | 305 | $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | } else { |
332 | 332 | $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
333 | 333 | } |
334 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
334 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"'); |
|
335 | 335 | $button_tray->addElement($butt_create); |
336 | 336 | |
337 | 337 | //creating custom buttons |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | foreach ($this->_custom_button as $custom_button) { |
340 | 340 | $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
341 | 341 | if ($custom_button['onclick']) { |
342 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
342 | + $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"'); |
|
343 | 343 | } |
344 | 344 | $button_tray->addElement($butt_custom); |
345 | 345 | unset($butt_custom); |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | // creating the "cancel" button |
350 | 350 | $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
351 | 351 | if ($this->_cancel_js_action) { |
352 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
352 | + $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"'); |
|
353 | 353 | } else { |
354 | 354 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
355 | 355 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | { |
368 | 368 | switch ($controlName) { |
369 | 369 | case 'check': |
370 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
370 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformcheckelement.php'; |
|
371 | 371 | $control = $this->targetObject->getControl($key); |
372 | 372 | $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
373 | 373 | $controlObj->addOptionArray($control['options']); |
@@ -434,38 +434,38 @@ discard block |
||
434 | 434 | break; |
435 | 435 | |
436 | 436 | case 'urllink': |
437 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
437 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformurllinkelement.php'; |
|
438 | 438 | |
439 | 439 | return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
440 | 440 | break; |
441 | 441 | |
442 | 442 | case 'richfile': |
443 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
443 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformrichfileelement.php'; |
|
444 | 444 | |
445 | 445 | return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
446 | 446 | break; |
447 | 447 | case 'section': |
448 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
448 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php'; |
|
449 | 449 | |
450 | 450 | return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
451 | 451 | break; |
452 | 452 | |
453 | 453 | default: |
454 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
454 | + $classname = 'SmartForm'.ucfirst($controlName).'Element'; |
|
455 | 455 | if (!class_exists($classname)) { |
456 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
457 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
456 | + if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) { |
|
457 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php'; |
|
458 | 458 | } else { |
459 | 459 | // perhaps this is a control created by the module |
460 | 460 | $moduleName = $this->targetObject->handler->_moduleName; |
461 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
462 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
463 | - $classFileName = strtolower($classname) . '.php'; |
|
461 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/'; |
|
462 | + $classname = ucfirst($moduleName).ucfirst($controlName).'Element'; |
|
463 | + $classFileName = strtolower($classname).'.php'; |
|
464 | 464 | |
465 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
466 | - require_once $moduleFormElementsPath . $classFileName; |
|
465 | + if (file_exists($moduleFormElementsPath.$classFileName)) { |
|
466 | + require_once $moduleFormElementsPath.$classFileName; |
|
467 | 467 | } else { |
468 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
468 | + trigger_error($classname.' Not found', E_USER_WARNING); |
|
469 | 469 | |
470 | 470 | return new XoopsFormLabel(); //Empty object |
471 | 471 | } |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | $editor_configs['height'] = '400px'; |
535 | 535 | |
536 | 536 | $dhtml = true; |
537 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
537 | + $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php'; |
|
538 | 538 | |
539 | 539 | if (file_exists($xoopseditorclass)) { |
540 | 540 | require_once $xoopseditorclass; |
@@ -544,8 +544,8 @@ discard block |
||
544 | 544 | |
545 | 545 | case 'tiny': |
546 | 546 | if (!$xoops22) { |
547 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
548 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
547 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
548 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
549 | 549 | $editor = new XoopsFormTinyTextArea([ |
550 | 550 | 'caption' => $caption, |
551 | 551 | 'name' => $name, |
@@ -575,8 +575,8 @@ discard block |
||
575 | 575 | |
576 | 576 | case 'fckeditor': |
577 | 577 | if (!$xoops22) { |
578 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
579 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
578 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
579 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php'; |
|
580 | 580 | $editor = new XoopsFormFckeditor([ |
581 | 581 | 'caption' => $caption, |
582 | 582 | 'name' => $name, |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | |
599 | 599 | case 'inbetween': |
600 | 600 | if (!$xoops22) { |
601 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
602 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
601 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
602 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php'; |
|
603 | 603 | $editor = new XoopsFormInbetweenTextArea([ |
604 | 604 | 'caption' => $caption, |
605 | 605 | 'name' => $name, |
@@ -621,8 +621,8 @@ discard block |
||
621 | 621 | |
622 | 622 | case 'koivi': |
623 | 623 | if (!$xoops22) { |
624 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
625 | - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
|
624 | + if (is_readable(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php')) { |
|
625 | + require_once XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php'; |
|
626 | 626 | $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
627 | 627 | } else { |
628 | 628 | if ($dhtml) { |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | |
639 | 639 | case 'spaw': |
640 | 640 | if (!$xoops22) { |
641 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
642 | - require_once XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'; |
|
641 | + if (is_readable(XOOPS_ROOT_PATH.'/class/spaw/formspaw.php')) { |
|
642 | + require_once XOOPS_ROOT_PATH.'/class/spaw/formspaw.php'; |
|
643 | 643 | $editor = new XoopsFormSpaw($caption, $name, $value); |
644 | 644 | } |
645 | 645 | } else { |
@@ -649,8 +649,8 @@ discard block |
||
649 | 649 | |
650 | 650 | case 'htmlarea': |
651 | 651 | if (!$xoops22) { |
652 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
653 | - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
|
652 | + if (is_readable(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php')) { |
|
653 | + require_once XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php'; |
|
654 | 654 | $editor = new XoopsFormHtmlarea($caption, $name, $value); |
655 | 655 | } |
656 | 656 | } else { |
@@ -686,10 +686,10 @@ discard block |
||
686 | 686 | $size = $multiple ? 5 : 1; |
687 | 687 | $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
688 | 688 | |
689 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
689 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
690 | 690 | $dirlist = []; |
691 | 691 | while (false !== ($file = readdir($handle))) { |
692 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
692 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/", $file) |
|
693 | 693 | && strtolower($file) !== 'cvs') { |
694 | 694 | $dirlist[$file] = $file; |
695 | 695 | } |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | { |
712 | 712 | foreach ($this->_elements as $eleObj) { |
713 | 713 | if ($eleObj->getName() == $keyname) { |
714 | - $ret =& $eleObj; |
|
714 | + $ret = & $eleObj; |
|
715 | 715 | break; |
716 | 716 | } |
717 | 717 | } |
@@ -728,9 +728,9 @@ discard block |
||
728 | 728 | { |
729 | 729 | $required = $this->getRequired(); |
730 | 730 | $ret = " |
731 | - <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
731 | + <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
732 | 732 | <table width='100%' class='outer' cellspacing='1'> |
733 | - <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
|
733 | + <tr><th colspan='2'>" . $this->getTitle().'</th></tr> |
|
734 | 734 | '; |
735 | 735 | $hidden = ''; |
736 | 736 | $class = 'even'; |
@@ -739,11 +739,11 @@ discard block |
||
739 | 739 | $ret .= $ele; |
740 | 740 | } elseif (!$ele->isHidden()) { |
741 | 741 | //$class = ( $class == 'even' ) ? 'odd': 'even'; |
742 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
742 | + $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
743 | 743 | if ($ele->getDescription() !== '') { |
744 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
744 | + $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
745 | 745 | } |
746 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
746 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
747 | 747 | } else { |
748 | 748 | $hidden .= $ele->render(); |
749 | 749 | } |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | 'name' => $this->getName(), |
790 | 790 | 'action' => $this->getAction(), |
791 | 791 | 'method' => $this->getMethod(), |
792 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
792 | + 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), |
|
793 | 793 | 'javascript' => $js, |
794 | 794 | 'elements' => $elements |
795 | 795 | ]); |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | } |
808 | 808 | $myts = MyTextSanitizer::getInstance(); |
809 | 809 | $formname = $this->getName(); |
810 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
810 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
811 | 811 | // First, output code to check required elements |
812 | 812 | $elements = $this->getRequired(); |
813 | 813 | foreach ($elements as $elt) { |
@@ -858,15 +858,15 @@ discard block |
||
858 | 858 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
859 | 859 | } |
860 | 860 | } else { |
861 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
861 | + $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
862 | 862 | } |
863 | 863 | } |
864 | 864 | // Now, handle custom validation code |
865 | - $elements =& $this->getElements(true); |
|
865 | + $elements = & $this->getElements(true); |
|
866 | 866 | foreach ($elements as $elt) { |
867 | 867 | if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
868 | 868 | if ($eltjs = $elt->renderValidationJS()) { |
869 | - $js .= $eltjs . "\n"; |
|
869 | + $js .= $eltjs."\n"; |
|
870 | 870 | } |
871 | 871 | } |
872 | 872 | } |