@@ -18,123 +18,123 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class SmartobjectCategory extends SmartSeoObject |
20 | 20 | { |
21 | - public $_categoryPath; |
|
22 | - |
|
23 | - /** |
|
24 | - * SmartobjectCategory constructor. |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | - $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | - $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | - |
|
34 | - $this->initCommonVar('doxcode'); |
|
35 | - |
|
36 | - $this->setControl('image', ['name' => 'image']); |
|
37 | - $this->setControl('parentid', ['name' => 'parentcategory']); |
|
38 | - $this->setControl('description', [ |
|
39 | - 'name' => 'textarea', |
|
40 | - 'itemHandler' => false, |
|
41 | - 'method' => false, |
|
42 | - 'module' => false, |
|
43 | - 'form_editor' => 'default' |
|
44 | - ]); |
|
45 | - |
|
46 | - // call parent constructor to get SEO fields initiated |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * returns a specific variable for the object in a proper format |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param string $key key of the object's variable to be returned |
|
55 | - * @param string $format format to use for the output |
|
56 | - * @return mixed formatted value of the variable |
|
57 | - */ |
|
58 | - public function getVar($key, $format = 's') |
|
59 | - { |
|
60 | - if ('s' === $format && in_array($key, ['description', 'image'])) { |
|
61 | - // return call_user_func(array($this, $key)); |
|
62 | - return $this->{$key}(); |
|
63 | - } |
|
64 | - |
|
65 | - return parent::getVar($key, $format); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function description() |
|
72 | - { |
|
73 | - return $this->getValueFor('description', false); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return bool|mixed |
|
78 | - */ |
|
79 | - public function image() |
|
80 | - { |
|
81 | - $ret = $this->getVar('image', 'e'); |
|
82 | - if ('-1' == $ret) { |
|
83 | - return false; |
|
84 | - } else { |
|
85 | - return $ret; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function toArray() |
|
93 | - { |
|
94 | - $this->setVar('doxcode', true); |
|
95 | - global $myts; |
|
96 | - $objectArray = parent::toArray(); |
|
97 | - if ($objectArray['image']) { |
|
98 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | - } |
|
100 | - |
|
101 | - return $objectArray; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Create the complete path of a category |
|
106 | - * |
|
107 | - * @todo this could be improved as it uses multiple queries |
|
108 | - * @param bool $withAllLink make all name clickable |
|
109 | - * @param bool $currentCategory |
|
110 | - * @return string complete path (breadcrumb) |
|
111 | - */ |
|
112 | - public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | - { |
|
114 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | - $controller = new SmartObjectController($this->handler); |
|
116 | - |
|
117 | - if (!$this->_categoryPath) { |
|
118 | - if ($withAllLink && !$currentCategory) { |
|
119 | - $ret = $controller->getItemLink($this); |
|
120 | - } else { |
|
121 | - $currentCategory = false; |
|
122 | - $ret = $this->getVar('name'); |
|
123 | - } |
|
124 | - $parentid = $this->getVar('parentid'); |
|
125 | - if (0 != $parentid) { |
|
126 | - $parentObj = $this->handler->get($parentid); |
|
127 | - if ($parentObj->isNew()) { |
|
128 | - exit; |
|
129 | - } |
|
130 | - $parentid = $parentObj->getVar('parentid'); |
|
131 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | - } |
|
133 | - $this->_categoryPath = $ret; |
|
134 | - } |
|
135 | - |
|
136 | - return $this->_categoryPath; |
|
137 | - } |
|
21 | + public $_categoryPath; |
|
22 | + |
|
23 | + /** |
|
24 | + * SmartobjectCategory constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | + $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | + $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | + |
|
34 | + $this->initCommonVar('doxcode'); |
|
35 | + |
|
36 | + $this->setControl('image', ['name' => 'image']); |
|
37 | + $this->setControl('parentid', ['name' => 'parentcategory']); |
|
38 | + $this->setControl('description', [ |
|
39 | + 'name' => 'textarea', |
|
40 | + 'itemHandler' => false, |
|
41 | + 'method' => false, |
|
42 | + 'module' => false, |
|
43 | + 'form_editor' => 'default' |
|
44 | + ]); |
|
45 | + |
|
46 | + // call parent constructor to get SEO fields initiated |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * returns a specific variable for the object in a proper format |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param string $key key of the object's variable to be returned |
|
55 | + * @param string $format format to use for the output |
|
56 | + * @return mixed formatted value of the variable |
|
57 | + */ |
|
58 | + public function getVar($key, $format = 's') |
|
59 | + { |
|
60 | + if ('s' === $format && in_array($key, ['description', 'image'])) { |
|
61 | + // return call_user_func(array($this, $key)); |
|
62 | + return $this->{$key}(); |
|
63 | + } |
|
64 | + |
|
65 | + return parent::getVar($key, $format); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function description() |
|
72 | + { |
|
73 | + return $this->getValueFor('description', false); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return bool|mixed |
|
78 | + */ |
|
79 | + public function image() |
|
80 | + { |
|
81 | + $ret = $this->getVar('image', 'e'); |
|
82 | + if ('-1' == $ret) { |
|
83 | + return false; |
|
84 | + } else { |
|
85 | + return $ret; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function toArray() |
|
93 | + { |
|
94 | + $this->setVar('doxcode', true); |
|
95 | + global $myts; |
|
96 | + $objectArray = parent::toArray(); |
|
97 | + if ($objectArray['image']) { |
|
98 | + $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | + } |
|
100 | + |
|
101 | + return $objectArray; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Create the complete path of a category |
|
106 | + * |
|
107 | + * @todo this could be improved as it uses multiple queries |
|
108 | + * @param bool $withAllLink make all name clickable |
|
109 | + * @param bool $currentCategory |
|
110 | + * @return string complete path (breadcrumb) |
|
111 | + */ |
|
112 | + public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | + { |
|
114 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | + $controller = new SmartObjectController($this->handler); |
|
116 | + |
|
117 | + if (!$this->_categoryPath) { |
|
118 | + if ($withAllLink && !$currentCategory) { |
|
119 | + $ret = $controller->getItemLink($this); |
|
120 | + } else { |
|
121 | + $currentCategory = false; |
|
122 | + $ret = $this->getVar('name'); |
|
123 | + } |
|
124 | + $parentid = $this->getVar('parentid'); |
|
125 | + if (0 != $parentid) { |
|
126 | + $parentObj = $this->handler->get($parentid); |
|
127 | + if ($parentObj->isNew()) { |
|
128 | + exit; |
|
129 | + } |
|
130 | + $parentid = $parentObj->getVar('parentid'); |
|
131 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | + } |
|
133 | + $this->_categoryPath = $ret; |
|
134 | + } |
|
135 | + |
|
136 | + return $this->_categoryPath; |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,91 +142,91 @@ discard block |
||
142 | 142 | */ |
143 | 143 | class SmartobjectCategoryHandler extends SmartPersistableObjectHandler |
144 | 144 | { |
145 | - public $allCategoriesObj = false; |
|
146 | - public $_allCategoriesId = false; |
|
147 | - |
|
148 | - /** |
|
149 | - * SmartobjectCategoryHandler constructor. |
|
150 | - * @param XoopsDatabase $db |
|
151 | - * @param $modulename |
|
152 | - */ |
|
153 | - public function __construct(XoopsDatabase $db, $modulename) |
|
154 | - { |
|
155 | - parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param int $parentid |
|
160 | - * @param bool $perm_name |
|
161 | - * @param string $sort |
|
162 | - * @param string $order |
|
163 | - * @return array|bool |
|
164 | - */ |
|
165 | - public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | - { |
|
167 | - if (!$this->allCategoriesObj) { |
|
168 | - $criteria = new CriteriaCompo(); |
|
169 | - $criteria->setSort($sort); |
|
170 | - $criteria->setOrder($order); |
|
171 | - global $xoopsUser; |
|
172 | - $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | - |
|
174 | - if ($perm_name && !$userIsAdmin) { |
|
175 | - if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | - return false; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | - } |
|
182 | - |
|
183 | - $ret = []; |
|
184 | - if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | - foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | - $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | - if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | - $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | - $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $ret; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $parentid |
|
199 | - * @param bool $asString |
|
200 | - * @return array|string |
|
201 | - */ |
|
202 | - public function getParentIds($parentid, $asString = true) |
|
203 | - { |
|
204 | - if (!$this->allCategoriesId) { |
|
205 | - $ret = []; |
|
206 | - $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | - |
|
208 | - $result = $this->db->query($sql); |
|
209 | - |
|
210 | - if (!$result) { |
|
211 | - return $ret; |
|
212 | - } |
|
213 | - |
|
214 | - while ($myrow = $this->db->fetchArray($result)) { |
|
215 | - $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $retArray = [$parentid]; |
|
220 | - while (0 != $parentid) { |
|
221 | - $parentid = $this->allCategoriesId[$parentid]; |
|
222 | - if (0 != $parentid) { |
|
223 | - $retArray[] = $parentid; |
|
224 | - } |
|
225 | - } |
|
226 | - if ($asString) { |
|
227 | - return implode(', ', $retArray); |
|
228 | - } else { |
|
229 | - return $retArray; |
|
230 | - } |
|
231 | - } |
|
145 | + public $allCategoriesObj = false; |
|
146 | + public $_allCategoriesId = false; |
|
147 | + |
|
148 | + /** |
|
149 | + * SmartobjectCategoryHandler constructor. |
|
150 | + * @param XoopsDatabase $db |
|
151 | + * @param $modulename |
|
152 | + */ |
|
153 | + public function __construct(XoopsDatabase $db, $modulename) |
|
154 | + { |
|
155 | + parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param int $parentid |
|
160 | + * @param bool $perm_name |
|
161 | + * @param string $sort |
|
162 | + * @param string $order |
|
163 | + * @return array|bool |
|
164 | + */ |
|
165 | + public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | + { |
|
167 | + if (!$this->allCategoriesObj) { |
|
168 | + $criteria = new CriteriaCompo(); |
|
169 | + $criteria->setSort($sort); |
|
170 | + $criteria->setOrder($order); |
|
171 | + global $xoopsUser; |
|
172 | + $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | + |
|
174 | + if ($perm_name && !$userIsAdmin) { |
|
175 | + if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | + return false; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | + } |
|
182 | + |
|
183 | + $ret = []; |
|
184 | + if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | + foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | + $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | + if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | + $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | + $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $ret; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $parentid |
|
199 | + * @param bool $asString |
|
200 | + * @return array|string |
|
201 | + */ |
|
202 | + public function getParentIds($parentid, $asString = true) |
|
203 | + { |
|
204 | + if (!$this->allCategoriesId) { |
|
205 | + $ret = []; |
|
206 | + $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | + |
|
208 | + $result = $this->db->query($sql); |
|
209 | + |
|
210 | + if (!$result) { |
|
211 | + return $ret; |
|
212 | + } |
|
213 | + |
|
214 | + while ($myrow = $this->db->fetchArray($result)) { |
|
215 | + $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $retArray = [$parentid]; |
|
220 | + while (0 != $parentid) { |
|
221 | + $parentid = $this->allCategoriesId[$parentid]; |
|
222 | + if (0 != $parentid) { |
|
223 | + $retArray[] = $parentid; |
|
224 | + } |
|
225 | + } |
|
226 | + if ($asString) { |
|
227 | + return implode(', ', $retArray); |
|
228 | + } else { |
|
229 | + return $retArray; |
|
230 | + } |
|
231 | + } |
|
232 | 232 | } |
@@ -5,38 +5,38 @@ |
||
5 | 5 | */ |
6 | 6 | class SmartFormFileElement extends XoopsFormFile |
7 | 7 | { |
8 | - public $object; |
|
9 | - public $key; |
|
8 | + public $object; |
|
9 | + public $key; |
|
10 | 10 | |
11 | - /** |
|
12 | - * SmartFormFileElement constructor. |
|
13 | - * @param string $object |
|
14 | - * @param string $key |
|
15 | - */ |
|
16 | - public function __construct($object, $key) |
|
17 | - { |
|
18 | - $this->object = $object; |
|
19 | - $this->key = $key; |
|
20 | - parent::__construct($object->vars[$key]['form_caption'], $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | - $this->setExtra(' size=50'); |
|
22 | - } |
|
11 | + /** |
|
12 | + * SmartFormFileElement constructor. |
|
13 | + * @param string $object |
|
14 | + * @param string $key |
|
15 | + */ |
|
16 | + public function __construct($object, $key) |
|
17 | + { |
|
18 | + $this->object = $object; |
|
19 | + $this->key = $key; |
|
20 | + parent::__construct($object->vars[$key]['form_caption'], $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | + $this->setExtra(' size=50'); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * prepare HTML for output |
|
26 | - * |
|
27 | - * @return string HTML |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - $ret = ''; |
|
32 | - if ('' !== $this->object->getVar($this->key)) { |
|
33 | - $ret .= '<div>' . _CO_SOBJECT_CURRENT_FILE . $this->object->getVar($this->key) . '</div>'; |
|
34 | - } |
|
24 | + /** |
|
25 | + * prepare HTML for output |
|
26 | + * |
|
27 | + * @return string HTML |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + $ret = ''; |
|
32 | + if ('' !== $this->object->getVar($this->key)) { |
|
33 | + $ret .= '<div>' . _CO_SOBJECT_CURRENT_FILE . $this->object->getVar($this->key) . '</div>'; |
|
34 | + } |
|
35 | 35 | |
36 | - $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
36 | + $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
37 | 37 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
38 | 38 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'></div>"; |
39 | 39 | |
40 | - return $ret; |
|
41 | - } |
|
40 | + return $ret; |
|
41 | + } |
|
42 | 42 | } |
@@ -30,12 +30,12 @@ |
||
30 | 30 | { |
31 | 31 | $ret = ''; |
32 | 32 | if ('' !== $this->object->getVar($this->key)) { |
33 | - $ret .= '<div>' . _CO_SOBJECT_CURRENT_FILE . $this->object->getVar($this->key) . '</div>'; |
|
33 | + $ret .= '<div>'._CO_SOBJECT_CURRENT_FILE.$this->object->getVar($this->key).'</div>'; |
|
34 | 34 | } |
35 | 35 | |
36 | - $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
37 | - <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
|
38 | - <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'></div>"; |
|
36 | + $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'> |
|
37 | + <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra()."> |
|
38 | + <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'></div>"; |
|
39 | 39 | |
40 | 40 | return $ret; |
41 | 41 | } |
@@ -11,31 +11,31 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormUrlLinkElement extends XoopsFormElementTray |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormUrlLinkElement constructor. |
|
16 | - * @param string $form_caption |
|
17 | - * @param string $key |
|
18 | - * @param string $object |
|
19 | - */ |
|
20 | - public function __construct($form_caption, $key, $object) |
|
21 | - { |
|
22 | - parent::__construct($form_caption, ' '); |
|
14 | + /** |
|
15 | + * SmartFormUrlLinkElement constructor. |
|
16 | + * @param string $form_caption |
|
17 | + * @param string $key |
|
18 | + * @param string $object |
|
19 | + */ |
|
20 | + public function __construct($form_caption, $key, $object) |
|
21 | + { |
|
22 | + parent::__construct($form_caption, ' '); |
|
23 | 23 | |
24 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_URL)); |
|
25 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
24 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_URL)); |
|
25 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
26 | 26 | |
27 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
28 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
27 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
28 | + $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
29 | 29 | |
30 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
31 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
30 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
31 | + $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
32 | 32 | |
33 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_TARGET)); |
|
34 | - $targ_val = $object->getVar('target'); |
|
35 | - $targetRadio = new XoopsFormRadio('', 'target_' . $key, '' !== $targ_val ? $targ_val : '_blank'); |
|
36 | - $control = $object->getControl('target'); |
|
37 | - $targetRadio->addOptionArray($control['options']); |
|
33 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_TARGET)); |
|
34 | + $targ_val = $object->getVar('target'); |
|
35 | + $targetRadio = new XoopsFormRadio('', 'target_' . $key, '' !== $targ_val ? $targ_val : '_blank'); |
|
36 | + $control = $object->getControl('target'); |
|
37 | + $targetRadio->addOptionArray($control['options']); |
|
38 | 38 | |
39 | - $this->addElement($targetRadio); |
|
40 | - } |
|
39 | + $this->addElement($targetRadio); |
|
40 | + } |
|
41 | 41 | } |
@@ -21,18 +21,18 @@ |
||
21 | 21 | { |
22 | 22 | parent::__construct($form_caption, ' '); |
23 | 23 | |
24 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_URL)); |
|
25 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
24 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_URLLINK_URL)); |
|
25 | + $this->addElement(new SmartFormTextElement($object, 'url_'.$key)); |
|
26 | 26 | |
27 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
28 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
27 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_CAPTION)); |
|
28 | + $this->addElement(new SmartFormTextElement($object, 'caption_'.$key)); |
|
29 | 29 | |
30 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
31 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
30 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_DESC.'<br>')); |
|
31 | + $this->addElement(new XoopsFormTextArea('', 'desc_'.$key, $object->getVar('description'))); |
|
32 | 32 | |
33 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URLLINK_TARGET)); |
|
33 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_URLLINK_TARGET)); |
|
34 | 34 | $targ_val = $object->getVar('target'); |
35 | - $targetRadio = new XoopsFormRadio('', 'target_' . $key, '' !== $targ_val ? $targ_val : '_blank'); |
|
35 | + $targetRadio = new XoopsFormRadio('', 'target_'.$key, '' !== $targ_val ? $targ_val : '_blank'); |
|
36 | 36 | $control = $object->getControl('target'); |
37 | 37 | $targetRadio->addOptionArray($control['options']); |
38 | 38 |
@@ -11,23 +11,23 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormTimeElement extends XoopsFormSelect |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormTimeElement constructor. |
|
16 | - * @param string $object |
|
17 | - * @param string $key |
|
18 | - */ |
|
19 | - public function __construct($object, $key) |
|
20 | - { |
|
21 | - $var = $object->vars[$key]; |
|
22 | - $timearray = []; |
|
23 | - for ($i = 0; $i < 24; ++$i) { |
|
24 | - for ($j = 0; $j < 60; $j += 10) { |
|
25 | - $key_t = ($i * 3600) + ($j * 60); |
|
26 | - $timearray[$key_t] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j; |
|
27 | - } |
|
28 | - } |
|
29 | - ksort($timearray); |
|
30 | - parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
31 | - $this->addOptionArray($timearray); |
|
32 | - } |
|
14 | + /** |
|
15 | + * SmartFormTimeElement constructor. |
|
16 | + * @param string $object |
|
17 | + * @param string $key |
|
18 | + */ |
|
19 | + public function __construct($object, $key) |
|
20 | + { |
|
21 | + $var = $object->vars[$key]; |
|
22 | + $timearray = []; |
|
23 | + for ($i = 0; $i < 24; ++$i) { |
|
24 | + for ($j = 0; $j < 60; $j += 10) { |
|
25 | + $key_t = ($i * 3600) + ($j * 60); |
|
26 | + $timearray[$key_t] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j; |
|
27 | + } |
|
28 | + } |
|
29 | + ksort($timearray); |
|
30 | + parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
31 | + $this->addOptionArray($timearray); |
|
32 | + } |
|
33 | 33 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | for ($i = 0; $i < 24; ++$i) { |
24 | 24 | for ($j = 0; $j < 60; $j += 10) { |
25 | 25 | $key_t = ($i * 3600) + ($j * 60); |
26 | - $timearray[$key_t] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j; |
|
26 | + $timearray[$key_t] = (0 != $j) ? $i.':'.$j : $i.':0'.$j; |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | ksort($timearray); |
@@ -11,39 +11,39 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormImageElement extends XoopsFormElementTray |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormImageElement constructor. |
|
16 | - * @param string $object |
|
17 | - * @param string $key |
|
18 | - */ |
|
19 | - public function __construct($object, $key) |
|
20 | - { |
|
21 | - $var = $object->vars[$key]; |
|
22 | - $object_imageurl = $object->getImageDir(); |
|
23 | - parent::__construct($var['form_caption'], ' '); |
|
14 | + /** |
|
15 | + * SmartFormImageElement constructor. |
|
16 | + * @param string $object |
|
17 | + * @param string $key |
|
18 | + */ |
|
19 | + public function __construct($object, $key) |
|
20 | + { |
|
21 | + $var = $object->vars[$key]; |
|
22 | + $object_imageurl = $object->getImageDir(); |
|
23 | + parent::__construct($var['form_caption'], ' '); |
|
24 | 24 | |
25 | - $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']); |
|
25 | + $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']); |
|
26 | 26 | |
27 | - if ('' !== $object->getVar($key) |
|
28 | - && (0 === strpos($object->getVar($key), 'http') |
|
29 | - || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) { |
|
30 | - $this->addElement(new XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>")); |
|
31 | - } elseif ('' !== $object->getVar($key)) { |
|
32 | - $this->addElement(new XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>")); |
|
33 | - } |
|
27 | + if ('' !== $object->getVar($key) |
|
28 | + && (0 === strpos($object->getVar($key), 'http') |
|
29 | + || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) { |
|
30 | + $this->addElement(new XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>")); |
|
31 | + } elseif ('' !== $object->getVar($key)) { |
|
32 | + $this->addElement(new XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>")); |
|
33 | + } |
|
34 | 34 | |
35 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
36 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
35 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
36 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
37 | 37 | |
38 | - $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', '')); |
|
39 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php'; |
|
40 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
38 | + $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', '')); |
|
39 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php'; |
|
40 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
41 | 41 | |
42 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
43 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
44 | - $this->addElement(new XoopsFormLabel('', '<br><br>')); |
|
45 | - $delete_check = new SmartFormCheckElement('', 'delete_' . $key); |
|
46 | - $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>'); |
|
47 | - $this->addElement($delete_check); |
|
48 | - } |
|
42 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
43 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
44 | + $this->addElement(new XoopsFormLabel('', '<br><br>')); |
|
45 | + $delete_check = new SmartFormCheckElement('', 'delete_' . $key); |
|
46 | + $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>'); |
|
47 | + $this->addElement($delete_check); |
|
48 | + } |
|
49 | 49 | } |
@@ -27,23 +27,23 @@ |
||
27 | 27 | if ('' !== $object->getVar($key) |
28 | 28 | && (0 === strpos($object->getVar($key), 'http') |
29 | 29 | || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) { |
30 | - $this->addElement(new XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>")); |
|
30 | + $this->addElement(new XoopsFormLabel('', "<img src='".str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key))."' alt=''><br><br>")); |
|
31 | 31 | } elseif ('' !== $object->getVar($key)) { |
32 | - $this->addElement(new XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>")); |
|
32 | + $this->addElement(new XoopsFormLabel('', "<img src='".$object_imageurl.$object->getVar($key)."' alt=''><br><br>")); |
|
33 | 33 | } |
34 | 34 | |
35 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
35 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformfileuploadelement.php'; |
|
36 | 36 | $this->addElement(new SmartFormFileUploadElement($object, $key)); |
37 | 37 | |
38 | - $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', '')); |
|
39 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php'; |
|
40 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
38 | + $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">'._CO_SOBJECT_URL_FILE_DSC.'</div>', '')); |
|
39 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformtextelement.php'; |
|
40 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformcheckelement.php'; |
|
41 | 41 | |
42 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
43 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
42 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_URL_FILE)); |
|
43 | + $this->addElement(new SmartFormTextElement($object, 'url_'.$key)); |
|
44 | 44 | $this->addElement(new XoopsFormLabel('', '<br><br>')); |
45 | - $delete_check = new SmartFormCheckElement('', 'delete_' . $key); |
|
46 | - $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>'); |
|
45 | + $delete_check = new SmartFormCheckElement('', 'delete_'.$key); |
|
46 | + $delete_check->addOption(1, '<span style="color:red;">'._CO_SOBJECT_DELETE.'</span>'); |
|
47 | 47 | $this->addElement($delete_check); |
48 | 48 | } |
49 | 49 | } |
@@ -11,39 +11,39 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormRichFileElement extends XoopsFormElementTray |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormRichFileElement constructor. |
|
16 | - * @param string $form_caption |
|
17 | - * @param string $key |
|
18 | - * @param string $object |
|
19 | - */ |
|
20 | - public function __construct($form_caption, $key, $object) |
|
21 | - { |
|
22 | - parent::__construct($form_caption, ' '); |
|
23 | - if ('' !== $object->getVar('url')) { |
|
24 | - $caption = '' !== $object->getVar('caption') ? $object->getVar('caption') : $object->getVar('url'); |
|
25 | - $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE . "<a href='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url')) . "' target='_blank' >" . $caption . '</a><br><br>')); |
|
26 | - //$this->addElement( new XoopsFormLabel( '', "<br><a href = '".SMARTOBJECT_URL."admin/file.php?op=del&fileid=".$object->id()."'>"._CO_SOBJECT_DELETE_FILE."</a>")); |
|
27 | - } |
|
14 | + /** |
|
15 | + * SmartFormRichFileElement constructor. |
|
16 | + * @param string $form_caption |
|
17 | + * @param string $key |
|
18 | + * @param string $object |
|
19 | + */ |
|
20 | + public function __construct($form_caption, $key, $object) |
|
21 | + { |
|
22 | + parent::__construct($form_caption, ' '); |
|
23 | + if ('' !== $object->getVar('url')) { |
|
24 | + $caption = '' !== $object->getVar('caption') ? $object->getVar('caption') : $object->getVar('url'); |
|
25 | + $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE . "<a href='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url')) . "' target='_blank' >" . $caption . '</a><br><br>')); |
|
26 | + //$this->addElement( new XoopsFormLabel( '', "<br><a href = '".SMARTOBJECT_URL."admin/file.php?op=del&fileid=".$object->id()."'>"._CO_SOBJECT_DELETE_FILE."</a>")); |
|
27 | + } |
|
28 | 28 | |
29 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
30 | - if ($object->isNew()) { |
|
31 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
32 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
33 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
34 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
35 | - } |
|
36 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
37 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
38 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
39 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
29 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
30 | + if ($object->isNew()) { |
|
31 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
32 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
33 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
34 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
35 | + } |
|
36 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
37 | + $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
38 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
39 | + $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
40 | 40 | |
41 | - if (!$object->isNew()) { |
|
42 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CHANGE_FILE)); |
|
43 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
44 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
45 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
46 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
47 | - } |
|
48 | - } |
|
41 | + if (!$object->isNew()) { |
|
42 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CHANGE_FILE)); |
|
43 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
44 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
45 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
46 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -22,28 +22,28 @@ |
||
22 | 22 | parent::__construct($form_caption, ' '); |
23 | 23 | if ('' !== $object->getVar('url')) { |
24 | 24 | $caption = '' !== $object->getVar('caption') ? $object->getVar('caption') : $object->getVar('url'); |
25 | - $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE . "<a href='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url')) . "' target='_blank' >" . $caption . '</a><br><br>')); |
|
25 | + $this->addElement(new XoopsFormLabel('', _CO_SOBJECT_CURRENT_FILE."<a href='".str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar('url'))."' target='_blank' >".$caption.'</a><br><br>')); |
|
26 | 26 | //$this->addElement( new XoopsFormLabel( '', "<br><a href = '".SMARTOBJECT_URL."admin/file.php?op=del&fileid=".$object->id()."'>"._CO_SOBJECT_DELETE_FILE."</a>")); |
27 | 27 | } |
28 | 28 | |
29 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
29 | + require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformfileuploadelement.php'; |
|
30 | 30 | if ($object->isNew()) { |
31 | 31 | $this->addElement(new SmartFormFileUploadElement($object, $key)); |
32 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
33 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
34 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
32 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>'._CO_SOBJECT_URL_FILE_DSC.'</small>')); |
|
33 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_URL_FILE)); |
|
34 | + $this->addElement(new SmartFormTextElement($object, 'url_'.$key)); |
|
35 | 35 | } |
36 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CAPTION)); |
|
37 | - $this->addElement(new SmartFormTextElement($object, 'caption_' . $key)); |
|
38 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_DESC . '<br>')); |
|
39 | - $this->addElement(new XoopsFormTextArea('', 'desc_' . $key, $object->getVar('description'))); |
|
36 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_CAPTION)); |
|
37 | + $this->addElement(new SmartFormTextElement($object, 'caption_'.$key)); |
|
38 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_DESC.'<br>')); |
|
39 | + $this->addElement(new XoopsFormTextArea('', 'desc_'.$key, $object->getVar('description'))); |
|
40 | 40 | |
41 | 41 | if (!$object->isNew()) { |
42 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_CHANGE_FILE)); |
|
42 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_CHANGE_FILE)); |
|
43 | 43 | $this->addElement(new SmartFormFileUploadElement($object, $key)); |
44 | - $this->addElement(new XoopsFormLabel('', '<br><br><small>' . _CO_SOBJECT_URL_FILE_DSC . '</small>')); |
|
45 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
46 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
44 | + $this->addElement(new XoopsFormLabel('', '<br><br><small>'._CO_SOBJECT_URL_FILE_DSC.'</small>')); |
|
45 | + $this->addElement(new XoopsFormLabel('', '<br>'._CO_SOBJECT_URL_FILE)); |
|
46 | + $this->addElement(new SmartFormTextElement($object, 'url_'.$key)); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | } |
@@ -7,41 +7,41 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class SmartFormCheckElement extends XoopsFormCheckBox |
9 | 9 | { |
10 | - /** |
|
11 | - * |
|
12 | - * /** |
|
13 | - * prepare HTML for output |
|
14 | - * |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function render() |
|
18 | - { |
|
19 | - $ret = ''; |
|
20 | - if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) { |
|
21 | - $newname = $this->getName() . '[]'; |
|
22 | - $this->setName($newname); |
|
23 | - } |
|
24 | - foreach ($this->getOptions() as $value => $name) { |
|
25 | - $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
26 | - if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
27 | - $ret .= ' checked'; |
|
28 | - } |
|
29 | - $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
30 | - } |
|
10 | + /** |
|
11 | + * |
|
12 | + * /** |
|
13 | + * prepare HTML for output |
|
14 | + * |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function render() |
|
18 | + { |
|
19 | + $ret = ''; |
|
20 | + if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) { |
|
21 | + $newname = $this->getName() . '[]'; |
|
22 | + $this->setName($newname); |
|
23 | + } |
|
24 | + foreach ($this->getOptions() as $value => $name) { |
|
25 | + $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
26 | + if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
27 | + $ret .= ' checked'; |
|
28 | + } |
|
29 | + $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
30 | + } |
|
31 | 31 | |
32 | - return $ret; |
|
33 | - } |
|
32 | + return $ret; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function renderValidationJS() |
|
39 | - { |
|
40 | - $js .= 'var hasSelections = false;'; |
|
41 | - //sometimes, there is an implicit '[]', sometimes not |
|
42 | - $eltname = $this->getName(); |
|
43 | - if (false === strpos($eltname, '[')) { |
|
44 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function renderValidationJS() |
|
39 | + { |
|
40 | + $js .= 'var hasSelections = false;'; |
|
41 | + //sometimes, there is an implicit '[]', sometimes not |
|
42 | + $eltname = $this->getName(); |
|
43 | + if (false === strpos($eltname, '[')) { |
|
44 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
45 | 45 | if (myform['{$eltname}[]'][i].checked) { |
46 | 46 | hasSelections = true; |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | } |
50 | 50 | if (hasSelections === false) { |
51 | 51 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
52 | - } else { |
|
53 | - $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
52 | + } else { |
|
53 | + $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
54 | 54 | if (myform['{$eltname}'][i].checked) { |
55 | 55 | hasSelections = true; |
56 | 56 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | } |
59 | 59 | if (hasSelections === false) { |
60 | 60 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - return $js; |
|
64 | - } |
|
63 | + return $js; |
|
64 | + } |
|
65 | 65 | } |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | { |
19 | 19 | $ret = ''; |
20 | 20 | if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) { |
21 | - $newname = $this->getName() . '[]'; |
|
21 | + $newname = $this->getName().'[]'; |
|
22 | 22 | $this->setName($newname); |
23 | 23 | } |
24 | 24 | foreach ($this->getOptions() as $value => $name) { |
25 | - $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
25 | + $ret .= "<input type='checkbox' name='".$this->getName()."' value='".$value."'"; |
|
26 | 26 | if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
27 | 27 | $ret .= ' checked'; |
28 | 28 | } |
29 | - $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
29 | + $ret .= $this->getExtra().'>'.$name.'<br>'; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | return $ret; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | if (hasSelections === false) { |
51 | 51 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
52 | 52 | } else { |
53 | - $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
53 | + $js .= "for (var i = 0; i < myform['".$eltname."'].length; i++) { |
|
54 | 54 | if (myform['{$eltname}'][i].checked) { |
55 | 55 | hasSelections = true; |
56 | 56 | } |
@@ -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, 'notset' === $required ? $var['required'] : $required); |
|
145 | - } else { |
|
146 | - parent::addElement($formElement, 'notset' === $required ? 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 ('parentid' === $key) { |
|
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, 'notset' === $required ? $var['required'] : $required); |
|
145 | + } else { |
|
146 | + parent::addElement($formElement, 'notset' === $required ? 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 ('parentid' === $key) { |
|
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 ('default' === $form_editor) { |
|
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 ('textarea' !== $form_editor) { |
|
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 | - && 'cvs' !== strtolower($file)) { |
|
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 ('default' === $form_editor) { |
|
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 ('textarea' !== $form_editor) { |
|
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 | + && 'cvs' !== strtolower($file)) { |
|
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'] = 'SmartFormSectionClose' === get_class($ele); |
|
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 ('xoopsformradio' === strtolower(get_class($elt))) { |
|
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'] = 'SmartFormSectionClose' === get_class($ele); |
|
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 ('xoopsformradio' === strtolower(get_class($elt))) { |
|
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 ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
828 | - $js .= 'var hasSelections = false;'; |
|
829 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
827 | + } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
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 ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
838 | - || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
839 | - $js .= 'var hasSelections = false;'; |
|
840 | - //sometimes, there is an implicit '[]', sometimes not |
|
841 | - if (false === strpos($eltname, '[')) { |
|
842 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
837 | + } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
838 | + || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
839 | + $js .= 'var hasSelections = false;'; |
|
840 | + //sometimes, there is an implicit '[]', sometimes not |
|
841 | + if (false === strpos($eltname, '[')) { |
|
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') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
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') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
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 | && 'cvs' !== strtolower($file)) { |
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') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
868 | 868 | if ($eltjs = $elt->renderValidationJS()) { |
869 | - $js .= $eltjs . "\n"; |
|
869 | + $js .= $eltjs."\n"; |
|
870 | 870 | } |
871 | 871 | } |
872 | 872 | } |
@@ -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]) || (null !== $id && !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]) || (null !== $id && !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]) || (null !== $id && !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]) || (null !== $id && !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 | } |