@@ -40,548 +40,548 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | class SmartObjectForm extends \XoopsThemeForm |
| 42 | 42 | { |
| 43 | - public $targetObject = null; |
|
| 44 | - public $form_fields = null; |
|
| 45 | - public $_cancel_js_action = false; |
|
| 46 | - public $_custom_button = false; |
|
| 47 | - public $_captcha = false; |
|
| 48 | - public $_form_name = false; |
|
| 49 | - public $_form_caption = false; |
|
| 50 | - public $_submit_button_caption = false; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * SmartobjectForm constructor. |
|
| 54 | - * @param string $target |
|
| 55 | - * @param string $form_name |
|
| 56 | - * @param string $form_caption |
|
| 57 | - * @param string $form_action |
|
| 58 | - * @param null $form_fields |
|
| 59 | - * @param bool $submit_button_caption |
|
| 60 | - * @param bool $cancel_js_action |
|
| 61 | - * @param bool $captcha |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - &$target, |
|
| 65 | - $form_name, |
|
| 66 | - $form_caption, |
|
| 67 | - $form_action, |
|
| 68 | - $form_fields = null, |
|
| 69 | - $submit_button_caption = false, |
|
| 70 | - $cancel_js_action = false, |
|
| 71 | - $captcha = false |
|
| 72 | - ) { |
|
| 73 | - $this->targetObject =& $target; |
|
| 74 | - $this->form_fields = $form_fields; |
|
| 75 | - $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | - $this->_captcha = $captcha; |
|
| 77 | - $this->_form_name = $form_name; |
|
| 78 | - $this->_form_caption = $form_caption; |
|
| 79 | - $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | - |
|
| 81 | - if (!isset($form_action)) { |
|
| 82 | - $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | - $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | - |
|
| 88 | - $this->createElements(); |
|
| 89 | - |
|
| 90 | - if ($captcha) { |
|
| 91 | - $this->addCaptcha(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->createPermissionControls(); |
|
| 95 | - |
|
| 96 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function addCaptcha() |
|
| 100 | - { |
|
| 101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | - $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param $name |
|
| 107 | - * @param $caption |
|
| 108 | - * @param bool $onclick |
|
| 109 | - */ |
|
| 110 | - public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | - { |
|
| 112 | - $custom_button_array = [ |
|
| 113 | - 'name' => $name, |
|
| 114 | - 'caption' => $caption, |
|
| 115 | - 'onclick' => $onclick |
|
| 116 | - ]; |
|
| 117 | - $this->_custom_button[] = $custom_button_array; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Add an element to the form |
|
| 122 | - * |
|
| 123 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | - * @param bool $key |
|
| 125 | - * @param bool $var |
|
| 126 | - * @param bool|string $required is this a "required" element? |
|
| 127 | - */ |
|
| 128 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | - { |
|
| 130 | - if ($key) { |
|
| 131 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | - $formElement->setExtra('disabled="disabled"'); |
|
| 133 | - $formElement->setName($key . '-readonly'); |
|
| 134 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | - $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | - $this->addElement($hidden); |
|
| 137 | - } |
|
| 138 | - $formElement->setDescription($var['form_dsc']); |
|
| 139 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | - $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | - $this->addElement($hidden); |
|
| 142 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | - } else { |
|
| 146 | - if (isset($var['form_extra'])) { |
|
| 147 | - $formElement->setExtra($var['form_extra']); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $controls = $this->targetObject->controls; |
|
| 151 | - if (isset($controls[$key]['js'])) { |
|
| 152 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | - } |
|
| 154 | - parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | - } else { |
|
| 156 | - parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | - } |
|
| 158 | - unset($formElement); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function createElements() |
|
| 162 | - { |
|
| 163 | - $controls = $this->targetObject->controls; |
|
| 164 | - $vars = $this->targetObject->vars; |
|
| 165 | - foreach ($vars as $key => $var) { |
|
| 166 | - |
|
| 167 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | - // need to be displayed, then we only create an hidden field |
|
| 169 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | - $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | - unset($elementToAdd); |
|
| 173 | - // If not, the we need to create the proper form control for this fields |
|
| 174 | - } else { |
|
| 175 | - // If this field has a specific control, we will use it |
|
| 176 | - |
|
| 177 | - if ('parentid' === $key) { |
|
| 178 | - /** |
|
| 179 | - * Why this ? |
|
| 180 | - */ |
|
| 181 | - } |
|
| 182 | - if (isset($controls[$key])) { |
|
| 183 | - /* If the control has name, it's because it's an object already present in the script |
|
| 43 | + public $targetObject = null; |
|
| 44 | + public $form_fields = null; |
|
| 45 | + public $_cancel_js_action = false; |
|
| 46 | + public $_custom_button = false; |
|
| 47 | + public $_captcha = false; |
|
| 48 | + public $_form_name = false; |
|
| 49 | + public $_form_caption = false; |
|
| 50 | + public $_submit_button_caption = false; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * SmartobjectForm constructor. |
|
| 54 | + * @param string $target |
|
| 55 | + * @param string $form_name |
|
| 56 | + * @param string $form_caption |
|
| 57 | + * @param string $form_action |
|
| 58 | + * @param null $form_fields |
|
| 59 | + * @param bool $submit_button_caption |
|
| 60 | + * @param bool $cancel_js_action |
|
| 61 | + * @param bool $captcha |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + &$target, |
|
| 65 | + $form_name, |
|
| 66 | + $form_caption, |
|
| 67 | + $form_action, |
|
| 68 | + $form_fields = null, |
|
| 69 | + $submit_button_caption = false, |
|
| 70 | + $cancel_js_action = false, |
|
| 71 | + $captcha = false |
|
| 72 | + ) { |
|
| 73 | + $this->targetObject =& $target; |
|
| 74 | + $this->form_fields = $form_fields; |
|
| 75 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | + $this->_captcha = $captcha; |
|
| 77 | + $this->_form_name = $form_name; |
|
| 78 | + $this->_form_caption = $form_caption; |
|
| 79 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | + |
|
| 81 | + if (!isset($form_action)) { |
|
| 82 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | + |
|
| 88 | + $this->createElements(); |
|
| 89 | + |
|
| 90 | + if ($captcha) { |
|
| 91 | + $this->addCaptcha(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->createPermissionControls(); |
|
| 95 | + |
|
| 96 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function addCaptcha() |
|
| 100 | + { |
|
| 101 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | + $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param $name |
|
| 107 | + * @param $caption |
|
| 108 | + * @param bool $onclick |
|
| 109 | + */ |
|
| 110 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | + { |
|
| 112 | + $custom_button_array = [ |
|
| 113 | + 'name' => $name, |
|
| 114 | + 'caption' => $caption, |
|
| 115 | + 'onclick' => $onclick |
|
| 116 | + ]; |
|
| 117 | + $this->_custom_button[] = $custom_button_array; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Add an element to the form |
|
| 122 | + * |
|
| 123 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | + * @param bool $key |
|
| 125 | + * @param bool $var |
|
| 126 | + * @param bool|string $required is this a "required" element? |
|
| 127 | + */ |
|
| 128 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | + { |
|
| 130 | + if ($key) { |
|
| 131 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | + $formElement->setExtra('disabled="disabled"'); |
|
| 133 | + $formElement->setName($key . '-readonly'); |
|
| 134 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | + $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | + $this->addElement($hidden); |
|
| 137 | + } |
|
| 138 | + $formElement->setDescription($var['form_dsc']); |
|
| 139 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | + $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | + $this->addElement($hidden); |
|
| 142 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | + } else { |
|
| 146 | + if (isset($var['form_extra'])) { |
|
| 147 | + $formElement->setExtra($var['form_extra']); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $controls = $this->targetObject->controls; |
|
| 151 | + if (isset($controls[$key]['js'])) { |
|
| 152 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | + } |
|
| 154 | + parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | + } else { |
|
| 156 | + parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | + } |
|
| 158 | + unset($formElement); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function createElements() |
|
| 162 | + { |
|
| 163 | + $controls = $this->targetObject->controls; |
|
| 164 | + $vars = $this->targetObject->vars; |
|
| 165 | + foreach ($vars as $key => $var) { |
|
| 166 | + |
|
| 167 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | + // need to be displayed, then we only create an hidden field |
|
| 169 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | + $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | + unset($elementToAdd); |
|
| 173 | + // If not, the we need to create the proper form control for this fields |
|
| 174 | + } else { |
|
| 175 | + // If this field has a specific control, we will use it |
|
| 176 | + |
|
| 177 | + if ('parentid' === $key) { |
|
| 178 | + /** |
|
| 179 | + * Why this ? |
|
| 180 | + */ |
|
| 181 | + } |
|
| 182 | + if (isset($controls[$key])) { |
|
| 183 | + /* If the control has name, it's because it's an object already present in the script |
|
| 184 | 184 | * for example, "user" |
| 185 | 185 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 186 | 186 | */ |
| 187 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | - $controls[$key]['name'] = 'select'; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | - |
|
| 193 | - // Adding on the form, the control for this field |
|
| 194 | - $this->addElement($form_select, $key, $var); |
|
| 195 | - unset($form_select); |
|
| 196 | - |
|
| 197 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | - } else { |
|
| 199 | - switch ($var['data_type']) { |
|
| 200 | - |
|
| 201 | - case XOBJ_DTYPE_TXTBOX: |
|
| 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_INT: |
|
| 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_FLOAT: |
|
| 219 | - $this->targetObject->setControl($key, [ |
|
| 220 | - 'name' => 'text', |
|
| 221 | - 'size' => '5' |
|
| 222 | - ]); |
|
| 223 | - $form_text = $this->getControl('text', $key); |
|
| 224 | - $this->addElement($form_text, $key, $var); |
|
| 225 | - unset($form_text); |
|
| 226 | - break; |
|
| 227 | - |
|
| 228 | - case XOBJ_DTYPE_LTIME: |
|
| 229 | - $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | - $this->addElement($form_date_time, $key, $var); |
|
| 231 | - unset($form_date_time); |
|
| 232 | - break; |
|
| 233 | - |
|
| 234 | - case XOBJ_DTYPE_STIME: |
|
| 235 | - $form_date_time = $this->getControl('date', $key); |
|
| 236 | - $this->addElement($form_date_time, $key, $var); |
|
| 237 | - unset($form_date_time); |
|
| 238 | - break; |
|
| 239 | - |
|
| 240 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | - $form_time = $this->getControl('time', $key); |
|
| 242 | - $this->addElement($form_time, $key, $var); |
|
| 243 | - unset($form_time); |
|
| 244 | - break; |
|
| 245 | - |
|
| 246 | - case XOBJ_DTYPE_CURRENCY: |
|
| 247 | - $this->targetObject->setControl($key, [ |
|
| 248 | - 'name' => 'text', |
|
| 249 | - 'size' => '15' |
|
| 250 | - ]); |
|
| 251 | - $form_currency = $this->getControl('text', $key); |
|
| 252 | - $this->addElement($form_currency, $key, $var); |
|
| 253 | - unset($form_currency); |
|
| 254 | - break; |
|
| 255 | - |
|
| 256 | - case XOBJ_DTYPE_URLLINK: |
|
| 257 | - $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | - $this->addElement($form_urllink, $key, $var); |
|
| 259 | - unset($form_urllink); |
|
| 260 | - break; |
|
| 261 | - |
|
| 262 | - case XOBJ_DTYPE_FILE: |
|
| 263 | - $form_file = $this->getControl('richfile', $key); |
|
| 264 | - $this->addElement($form_file, $key, $var); |
|
| 265 | - unset($form_file); |
|
| 266 | - break; |
|
| 267 | - |
|
| 268 | - case XOBJ_DTYPE_TXTAREA: |
|
| 269 | - |
|
| 270 | - $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | - $this->addElement($form_text_area, $key, $var); |
|
| 272 | - unset($form_text_area); |
|
| 273 | - break; |
|
| 274 | - |
|
| 275 | - case XOBJ_DTYPE_ARRAY: |
|
| 276 | - // TODO: To come... |
|
| 277 | - break; |
|
| 278 | - case XOBJ_DTYPE_SOURCE: |
|
| 279 | - // TODO: To come... |
|
| 280 | - break; |
|
| 281 | - case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | - $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | - $this->addElement($section_control, $key, $var); |
|
| 284 | - unset($section_control); |
|
| 285 | - break; |
|
| 286 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | - $this->addElement($section_control, $key, $var); |
|
| 289 | - unset($section_control); |
|
| 290 | - break; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - // Add an hidden field to store the URL of the page before this form |
|
| 296 | - $this->addElement(new \XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - public function createPermissionControls() |
|
| 300 | - { |
|
| 301 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | - |
|
| 303 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | - |
|
| 305 | - if ($permissions) { |
|
| 306 | - $memberHandler = xoops_getHandler('member'); |
|
| 307 | - $group_list = $memberHandler->getGroupList(); |
|
| 308 | - asort($group_list); |
|
| 309 | - foreach ($permissions as $permission) { |
|
| 310 | - if ($this->targetObject->isNew()) { |
|
| 311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | - } |
|
| 317 | - $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | - $groups_select->setDescription($permission['description']); |
|
| 319 | - $groups_select->addOptionArray($group_list); |
|
| 320 | - $this->addElement($groups_select); |
|
| 321 | - unset($groups_select); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param $form_name |
|
| 328 | - * @param $form_caption |
|
| 329 | - * @param bool $submit_button_caption |
|
| 330 | - */ |
|
| 331 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | - { |
|
| 333 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | - $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | - if (!$submit_button_caption) { |
|
| 336 | - if ($this->targetObject->isNew()) { |
|
| 337 | - $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | - } else { |
|
| 339 | - $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | - } |
|
| 344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | - $button_tray->addElement($butt_create); |
|
| 346 | - |
|
| 347 | - //creating custom buttons |
|
| 348 | - if ($this->_custom_button) { |
|
| 349 | - foreach ($this->_custom_button as $custom_button) { |
|
| 350 | - $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | - if ($custom_button['onclick']) { |
|
| 352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | - } |
|
| 354 | - $button_tray->addElement($butt_custom); |
|
| 355 | - unset($butt_custom); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // creating the "cancel" button |
|
| 360 | - $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | - if ($this->_cancel_js_action) { |
|
| 362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | - } else { |
|
| 364 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | - } |
|
| 366 | - $button_tray->addElement($butt_cancel); |
|
| 367 | - |
|
| 368 | - $this->addElement($button_tray); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param $controlName |
|
| 373 | - * @param $key |
|
| 374 | - * @return \XoopsFormLabel |
|
| 375 | - */ |
|
| 376 | - public function getControl($controlName, $key) |
|
| 377 | - { |
|
| 378 | - switch ($controlName) { |
|
| 379 | - case 'check': |
|
| 187 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | + $controls[$key]['name'] = 'select'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | + |
|
| 193 | + // Adding on the form, the control for this field |
|
| 194 | + $this->addElement($form_select, $key, $var); |
|
| 195 | + unset($form_select); |
|
| 196 | + |
|
| 197 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | + } else { |
|
| 199 | + switch ($var['data_type']) { |
|
| 200 | + |
|
| 201 | + case XOBJ_DTYPE_TXTBOX: |
|
| 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_INT: |
|
| 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_FLOAT: |
|
| 219 | + $this->targetObject->setControl($key, [ |
|
| 220 | + 'name' => 'text', |
|
| 221 | + 'size' => '5' |
|
| 222 | + ]); |
|
| 223 | + $form_text = $this->getControl('text', $key); |
|
| 224 | + $this->addElement($form_text, $key, $var); |
|
| 225 | + unset($form_text); |
|
| 226 | + break; |
|
| 227 | + |
|
| 228 | + case XOBJ_DTYPE_LTIME: |
|
| 229 | + $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | + $this->addElement($form_date_time, $key, $var); |
|
| 231 | + unset($form_date_time); |
|
| 232 | + break; |
|
| 233 | + |
|
| 234 | + case XOBJ_DTYPE_STIME: |
|
| 235 | + $form_date_time = $this->getControl('date', $key); |
|
| 236 | + $this->addElement($form_date_time, $key, $var); |
|
| 237 | + unset($form_date_time); |
|
| 238 | + break; |
|
| 239 | + |
|
| 240 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | + $form_time = $this->getControl('time', $key); |
|
| 242 | + $this->addElement($form_time, $key, $var); |
|
| 243 | + unset($form_time); |
|
| 244 | + break; |
|
| 245 | + |
|
| 246 | + case XOBJ_DTYPE_CURRENCY: |
|
| 247 | + $this->targetObject->setControl($key, [ |
|
| 248 | + 'name' => 'text', |
|
| 249 | + 'size' => '15' |
|
| 250 | + ]); |
|
| 251 | + $form_currency = $this->getControl('text', $key); |
|
| 252 | + $this->addElement($form_currency, $key, $var); |
|
| 253 | + unset($form_currency); |
|
| 254 | + break; |
|
| 255 | + |
|
| 256 | + case XOBJ_DTYPE_URLLINK: |
|
| 257 | + $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | + $this->addElement($form_urllink, $key, $var); |
|
| 259 | + unset($form_urllink); |
|
| 260 | + break; |
|
| 261 | + |
|
| 262 | + case XOBJ_DTYPE_FILE: |
|
| 263 | + $form_file = $this->getControl('richfile', $key); |
|
| 264 | + $this->addElement($form_file, $key, $var); |
|
| 265 | + unset($form_file); |
|
| 266 | + break; |
|
| 267 | + |
|
| 268 | + case XOBJ_DTYPE_TXTAREA: |
|
| 269 | + |
|
| 270 | + $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | + $this->addElement($form_text_area, $key, $var); |
|
| 272 | + unset($form_text_area); |
|
| 273 | + break; |
|
| 274 | + |
|
| 275 | + case XOBJ_DTYPE_ARRAY: |
|
| 276 | + // TODO: To come... |
|
| 277 | + break; |
|
| 278 | + case XOBJ_DTYPE_SOURCE: |
|
| 279 | + // TODO: To come... |
|
| 280 | + break; |
|
| 281 | + case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | + $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | + $this->addElement($section_control, $key, $var); |
|
| 284 | + unset($section_control); |
|
| 285 | + break; |
|
| 286 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | + $this->addElement($section_control, $key, $var); |
|
| 289 | + unset($section_control); |
|
| 290 | + break; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + // Add an hidden field to store the URL of the page before this form |
|
| 296 | + $this->addElement(new \XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + public function createPermissionControls() |
|
| 300 | + { |
|
| 301 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | + |
|
| 303 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | + |
|
| 305 | + if ($permissions) { |
|
| 306 | + $memberHandler = xoops_getHandler('member'); |
|
| 307 | + $group_list = $memberHandler->getGroupList(); |
|
| 308 | + asort($group_list); |
|
| 309 | + foreach ($permissions as $permission) { |
|
| 310 | + if ($this->targetObject->isNew()) { |
|
| 311 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | + } |
|
| 317 | + $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | + $groups_select->setDescription($permission['description']); |
|
| 319 | + $groups_select->addOptionArray($group_list); |
|
| 320 | + $this->addElement($groups_select); |
|
| 321 | + unset($groups_select); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param $form_name |
|
| 328 | + * @param $form_caption |
|
| 329 | + * @param bool $submit_button_caption |
|
| 330 | + */ |
|
| 331 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | + { |
|
| 333 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | + $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | + if (!$submit_button_caption) { |
|
| 336 | + if ($this->targetObject->isNew()) { |
|
| 337 | + $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | + } else { |
|
| 339 | + $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | + } |
|
| 344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | + $button_tray->addElement($butt_create); |
|
| 346 | + |
|
| 347 | + //creating custom buttons |
|
| 348 | + if ($this->_custom_button) { |
|
| 349 | + foreach ($this->_custom_button as $custom_button) { |
|
| 350 | + $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | + if ($custom_button['onclick']) { |
|
| 352 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | + } |
|
| 354 | + $button_tray->addElement($butt_custom); |
|
| 355 | + unset($butt_custom); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + // creating the "cancel" button |
|
| 360 | + $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | + if ($this->_cancel_js_action) { |
|
| 362 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | + } else { |
|
| 364 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | + } |
|
| 366 | + $button_tray->addElement($butt_cancel); |
|
| 367 | + |
|
| 368 | + $this->addElement($button_tray); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param $controlName |
|
| 373 | + * @param $key |
|
| 374 | + * @return \XoopsFormLabel |
|
| 375 | + */ |
|
| 376 | + public function getControl($controlName, $key) |
|
| 377 | + { |
|
| 378 | + switch ($controlName) { |
|
| 379 | + case 'check': |
|
| 380 | 380 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
| 381 | - $control = $this->targetObject->getControl($key); |
|
| 382 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | - $controlObj->addOptionArray($control['options']); |
|
| 381 | + $control = $this->targetObject->getControl($key); |
|
| 382 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | + $controlObj->addOptionArray($control['options']); |
|
| 384 | 384 | |
| 385 | - return $controlObj; |
|
| 386 | - break; |
|
| 385 | + return $controlObj; |
|
| 386 | + break; |
|
| 387 | 387 | |
| 388 | - case 'color': |
|
| 389 | - $control = $this->targetObject->getControl($key); |
|
| 390 | - $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 388 | + case 'color': |
|
| 389 | + $control = $this->targetObject->getControl($key); |
|
| 390 | + $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 391 | 391 | |
| 392 | - return $controlObj; |
|
| 393 | - break; |
|
| 392 | + return $controlObj; |
|
| 393 | + break; |
|
| 394 | 394 | |
| 395 | - case 'radio': |
|
| 396 | - $control = $this->targetObject->getControl($key); |
|
| 395 | + case 'radio': |
|
| 396 | + $control = $this->targetObject->getControl($key); |
|
| 397 | 397 | |
| 398 | - $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | - $controlObj->addOptionArray($control['options']); |
|
| 398 | + $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | + $controlObj->addOptionArray($control['options']); |
|
| 400 | 400 | |
| 401 | - return $controlObj; |
|
| 402 | - break; |
|
| 401 | + return $controlObj; |
|
| 402 | + break; |
|
| 403 | 403 | |
| 404 | - case 'label': |
|
| 405 | - return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | - break; |
|
| 404 | + case 'label': |
|
| 405 | + return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | + break; |
|
| 407 | 407 | |
| 408 | - case 'textarea': |
|
| 409 | - return $this->getTextArea($key); |
|
| 408 | + case 'textarea': |
|
| 409 | + return $this->getTextArea($key); |
|
| 410 | 410 | |
| 411 | - case 'theme': |
|
| 412 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 411 | + case 'theme': |
|
| 412 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 413 | 413 | |
| 414 | - case 'theme_multi': |
|
| 415 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | - break; |
|
| 414 | + case 'theme_multi': |
|
| 415 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | + break; |
|
| 417 | 417 | |
| 418 | - case 'timezone': |
|
| 419 | - return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | - break; |
|
| 418 | + case 'timezone': |
|
| 419 | + return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | + break; |
|
| 421 | 421 | |
| 422 | - case 'group': |
|
| 423 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | - break; |
|
| 422 | + case 'group': |
|
| 423 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | + break; |
|
| 425 | 425 | |
| 426 | - case 'group_multi': |
|
| 427 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | - break; |
|
| 426 | + case 'group_multi': |
|
| 427 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | + break; |
|
| 429 | 429 | |
| 430 | - /*case 'user': |
|
| 430 | + /*case 'user': |
|
| 431 | 431 | return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
| 432 | 432 | break;*/ |
| 433 | 433 | |
| 434 | - case 'user_multi': |
|
| 435 | - return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | - break; |
|
| 434 | + case 'user_multi': |
|
| 435 | + return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | + break; |
|
| 437 | 437 | |
| 438 | - case 'password': |
|
| 439 | - return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | - break; |
|
| 438 | + case 'password': |
|
| 439 | + return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | + break; |
|
| 441 | 441 | |
| 442 | - case 'country': |
|
| 443 | - return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | - break; |
|
| 442 | + case 'country': |
|
| 443 | + return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | + break; |
|
| 445 | 445 | |
| 446 | - case 'urllink': |
|
| 446 | + case 'urllink': |
|
| 447 | 447 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
| 448 | 448 | |
| 449 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | - break; |
|
| 449 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | + break; |
|
| 451 | 451 | |
| 452 | - case 'richfile': |
|
| 452 | + case 'richfile': |
|
| 453 | 453 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
| 454 | 454 | |
| 455 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | - break; |
|
| 457 | - case 'section': |
|
| 455 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | + break; |
|
| 457 | + case 'section': |
|
| 458 | 458 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
| 459 | 459 | |
| 460 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | - break; |
|
| 460 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | + break; |
|
| 462 | 462 | |
| 463 | - default: |
|
| 464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | - if (!class_exists($classname)) { |
|
| 466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 463 | + default: |
|
| 464 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | + if (!class_exists($classname)) { |
|
| 466 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
| 468 | - } else { |
|
| 469 | - // perhaps this is a control created by the module |
|
| 470 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | - $classFileName = strtolower($classname) . '.php'; |
|
| 474 | - |
|
| 475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 468 | + } else { |
|
| 469 | + // perhaps this is a control created by the module |
|
| 470 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | + $classFileName = strtolower($classname) . '.php'; |
|
| 474 | + |
|
| 475 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
| 477 | - } else { |
|
| 478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | - |
|
| 480 | - return new \XoopsFormLabel(); //Empty object |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - return new $classname($this->targetObject, $key); |
|
| 486 | - break; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @param $key |
|
| 492 | - * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | - */ |
|
| 494 | - public function getTextArea($key) |
|
| 495 | - { |
|
| 496 | - $var = $this->targetObject->vars[$key]; |
|
| 497 | - |
|
| 498 | - // if no control has been created, let's create a default one |
|
| 499 | - if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | - $control = [ |
|
| 501 | - 'name' => 'textarea', |
|
| 502 | - 'itemHandler' => false, |
|
| 503 | - 'method' => false, |
|
| 504 | - 'module' => false, |
|
| 505 | - 'form_editor' => 'default' |
|
| 506 | - ]; |
|
| 507 | - } else { |
|
| 508 | - $control = $this->targetObject->controls[$key]; |
|
| 509 | - } |
|
| 510 | - $xoops22 = smart_isXoops22(); |
|
| 511 | - |
|
| 512 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | - /** |
|
| 514 | - * If the editor is 'default', retreive the default editor of this module |
|
| 515 | - */ |
|
| 516 | - if ('default' === $form_editor) { |
|
| 517 | - global $xoopsModuleConfig; |
|
| 518 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $caption = $var['form_caption']; |
|
| 522 | - $name = $key; |
|
| 523 | - |
|
| 524 | - $value = $this->targetObject->getVar($key); |
|
| 525 | - |
|
| 526 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | - |
|
| 528 | - $editor_configs = []; |
|
| 529 | - $editor_configs['name'] = $name; |
|
| 530 | - $editor_configs['value'] = $value; |
|
| 531 | - if ('textarea' !== $form_editor) { |
|
| 532 | - $editor_configs['rows'] = 35; |
|
| 533 | - $editor_configs['cols'] = 60; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - if (isset($control['rows'])) { |
|
| 537 | - $editor_configs['rows'] = $control['rows']; |
|
| 538 | - } |
|
| 539 | - if (isset($control['cols'])) { |
|
| 540 | - $editor_configs['cols'] = $control['cols']; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $editor_configs['width'] = '100%'; |
|
| 544 | - $editor_configs['height'] = '400px'; |
|
| 545 | - |
|
| 546 | - $dhtml = true; |
|
| 547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | - |
|
| 549 | - if (file_exists($xoopseditorclass)) { |
|
| 550 | - require_once $xoopseditorclass; |
|
| 551 | - $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | - } else { |
|
| 553 | - switch ($form_editor) { |
|
| 554 | - |
|
| 555 | - case 'tiny': |
|
| 556 | - if (!$xoops22) { |
|
| 557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | - $editor = new \XoopsFormTinymce([ |
|
| 560 | - 'caption' => $caption, |
|
| 561 | - 'name' => $name, |
|
| 562 | - 'value' => $value, |
|
| 563 | - 'width' => '100%', |
|
| 564 | - 'height' => '300px' |
|
| 565 | - ], true); |
|
| 566 | - } else { |
|
| 567 | - if ($dhtml) { |
|
| 568 | - $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | - } else { |
|
| 570 | - $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - } else { |
|
| 574 | - $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | - } |
|
| 576 | - break; |
|
| 577 | - |
|
| 578 | - case 'dhtmltextarea': |
|
| 579 | - case 'dhtmltext': |
|
| 580 | - $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | - if ($var['form_dsc']) { |
|
| 582 | - $editor->setDescription($var['form_dsc']); |
|
| 583 | - } |
|
| 584 | - break; |
|
| 477 | + } else { |
|
| 478 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | + |
|
| 480 | + return new \XoopsFormLabel(); //Empty object |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + return new $classname($this->targetObject, $key); |
|
| 486 | + break; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @param $key |
|
| 492 | + * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | + */ |
|
| 494 | + public function getTextArea($key) |
|
| 495 | + { |
|
| 496 | + $var = $this->targetObject->vars[$key]; |
|
| 497 | + |
|
| 498 | + // if no control has been created, let's create a default one |
|
| 499 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | + $control = [ |
|
| 501 | + 'name' => 'textarea', |
|
| 502 | + 'itemHandler' => false, |
|
| 503 | + 'method' => false, |
|
| 504 | + 'module' => false, |
|
| 505 | + 'form_editor' => 'default' |
|
| 506 | + ]; |
|
| 507 | + } else { |
|
| 508 | + $control = $this->targetObject->controls[$key]; |
|
| 509 | + } |
|
| 510 | + $xoops22 = smart_isXoops22(); |
|
| 511 | + |
|
| 512 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | + /** |
|
| 514 | + * If the editor is 'default', retreive the default editor of this module |
|
| 515 | + */ |
|
| 516 | + if ('default' === $form_editor) { |
|
| 517 | + global $xoopsModuleConfig; |
|
| 518 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $caption = $var['form_caption']; |
|
| 522 | + $name = $key; |
|
| 523 | + |
|
| 524 | + $value = $this->targetObject->getVar($key); |
|
| 525 | + |
|
| 526 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | + |
|
| 528 | + $editor_configs = []; |
|
| 529 | + $editor_configs['name'] = $name; |
|
| 530 | + $editor_configs['value'] = $value; |
|
| 531 | + if ('textarea' !== $form_editor) { |
|
| 532 | + $editor_configs['rows'] = 35; |
|
| 533 | + $editor_configs['cols'] = 60; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + if (isset($control['rows'])) { |
|
| 537 | + $editor_configs['rows'] = $control['rows']; |
|
| 538 | + } |
|
| 539 | + if (isset($control['cols'])) { |
|
| 540 | + $editor_configs['cols'] = $control['cols']; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $editor_configs['width'] = '100%'; |
|
| 544 | + $editor_configs['height'] = '400px'; |
|
| 545 | + |
|
| 546 | + $dhtml = true; |
|
| 547 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | + |
|
| 549 | + if (file_exists($xoopseditorclass)) { |
|
| 550 | + require_once $xoopseditorclass; |
|
| 551 | + $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | + } else { |
|
| 553 | + switch ($form_editor) { |
|
| 554 | + |
|
| 555 | + case 'tiny': |
|
| 556 | + if (!$xoops22) { |
|
| 557 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | + $editor = new \XoopsFormTinymce([ |
|
| 560 | + 'caption' => $caption, |
|
| 561 | + 'name' => $name, |
|
| 562 | + 'value' => $value, |
|
| 563 | + 'width' => '100%', |
|
| 564 | + 'height' => '300px' |
|
| 565 | + ], true); |
|
| 566 | + } else { |
|
| 567 | + if ($dhtml) { |
|
| 568 | + $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | + } else { |
|
| 570 | + $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | + } |
|
| 576 | + break; |
|
| 577 | + |
|
| 578 | + case 'dhtmltextarea': |
|
| 579 | + case 'dhtmltext': |
|
| 580 | + $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | + if ($var['form_dsc']) { |
|
| 582 | + $editor->setDescription($var['form_dsc']); |
|
| 583 | + } |
|
| 584 | + break; |
|
| 585 | 585 | |
| 586 | 586 | // case 'inbetween': |
| 587 | 587 | // if (!$xoops22) { |
@@ -634,177 +634,177 @@ discard block |
||
| 634 | 634 | // } |
| 635 | 635 | // break; |
| 636 | 636 | |
| 637 | - default: |
|
| 638 | - case 'textarea': |
|
| 639 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | - |
|
| 642 | - $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | - if ($var['form_dsc']) { |
|
| 644 | - $editor->setDescription($var['form_dsc']); |
|
| 645 | - } |
|
| 646 | - break; |
|
| 647 | - |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $editor; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @param $key |
|
| 656 | - * @param $var |
|
| 657 | - * @param bool $multiple |
|
| 658 | - * @return \XoopsFormSelect |
|
| 659 | - */ |
|
| 660 | - public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | - { |
|
| 662 | - $size = $multiple ? 5 : 1; |
|
| 663 | - $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | - |
|
| 665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | - $dirlist = []; |
|
| 667 | - while (false !== ($file = readdir($handle))) { |
|
| 668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | - && 'cvs' !== strtolower($file)) { |
|
| 670 | - $dirlist[$file] = $file; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - closedir($handle); |
|
| 674 | - if (!empty($dirlist)) { |
|
| 675 | - asort($dirlist); |
|
| 676 | - $theme_select->addOptionArray($dirlist); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return $theme_select; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @param $keyname |
|
| 684 | - * @return bool |
|
| 685 | - */ |
|
| 686 | - public function &getElementById($keyname) |
|
| 687 | - { |
|
| 688 | - foreach ($this->_elements as $eleObj) { |
|
| 689 | - if ($eleObj->getName() == $keyname) { |
|
| 690 | - $ret =& $eleObj; |
|
| 691 | - break; |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return isset($ret) ? $ret : false; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | - * |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public function render() |
|
| 704 | - { |
|
| 705 | - $required = $this->getRequired(); |
|
| 706 | - $ret = " |
|
| 637 | + default: |
|
| 638 | + case 'textarea': |
|
| 639 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | + |
|
| 642 | + $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | + if ($var['form_dsc']) { |
|
| 644 | + $editor->setDescription($var['form_dsc']); |
|
| 645 | + } |
|
| 646 | + break; |
|
| 647 | + |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $editor; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @param $key |
|
| 656 | + * @param $var |
|
| 657 | + * @param bool $multiple |
|
| 658 | + * @return \XoopsFormSelect |
|
| 659 | + */ |
|
| 660 | + public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | + { |
|
| 662 | + $size = $multiple ? 5 : 1; |
|
| 663 | + $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | + |
|
| 665 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | + $dirlist = []; |
|
| 667 | + while (false !== ($file = readdir($handle))) { |
|
| 668 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | + && 'cvs' !== strtolower($file)) { |
|
| 670 | + $dirlist[$file] = $file; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + closedir($handle); |
|
| 674 | + if (!empty($dirlist)) { |
|
| 675 | + asort($dirlist); |
|
| 676 | + $theme_select->addOptionArray($dirlist); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return $theme_select; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @param $keyname |
|
| 684 | + * @return bool |
|
| 685 | + */ |
|
| 686 | + public function &getElementById($keyname) |
|
| 687 | + { |
|
| 688 | + foreach ($this->_elements as $eleObj) { |
|
| 689 | + if ($eleObj->getName() == $keyname) { |
|
| 690 | + $ret =& $eleObj; |
|
| 691 | + break; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return isset($ret) ? $ret : false; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | + * |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public function render() |
|
| 704 | + { |
|
| 705 | + $required = $this->getRequired(); |
|
| 706 | + $ret = " |
|
| 707 | 707 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
| 708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
| 709 | 709 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
| 710 | 710 | '; |
| 711 | - $hidden = ''; |
|
| 712 | - $class = 'even'; |
|
| 713 | - foreach ($this->getElements() as $ele) { |
|
| 714 | - if (!is_object($ele)) { |
|
| 715 | - $ret .= $ele; |
|
| 716 | - } elseif (!$ele->isHidden()) { |
|
| 717 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | - if ('' !== $ele->getDescription()) { |
|
| 720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | - } |
|
| 722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | - } else { |
|
| 724 | - $hidden .= $ele->render(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | - $ret .= $this->renderValidationJS(true); |
|
| 729 | - |
|
| 730 | - return $ret; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * assign to smarty form template instead of displaying directly |
|
| 735 | - * |
|
| 736 | - * @param \XoopsTpl $tpl |
|
| 737 | - * |
|
| 738 | - * object |
|
| 739 | - * @param bool $smartyName |
|
| 740 | - * @see Smarty |
|
| 741 | - */ |
|
| 742 | - public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | - { |
|
| 744 | - $i = 0; |
|
| 745 | - $elements = []; |
|
| 746 | - foreach ($this->getElements() as $ele) { |
|
| 747 | - $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | - $elements[$n]['name'] = $ele->getName(); |
|
| 749 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | - $elements[$n]['body'] = $ele->render(); |
|
| 751 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | - $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | - if ('' !== $ele->getDescription()) { |
|
| 756 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | - } |
|
| 758 | - ++$i; |
|
| 759 | - } |
|
| 760 | - $js = $this->renderValidationJS(); |
|
| 761 | - if (!$smartyName) { |
|
| 762 | - $smartyName = $this->getName(); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - $tpl->assign($smartyName, [ |
|
| 766 | - 'title' => $this->getTitle(), |
|
| 767 | - 'name' => $this->getName(), |
|
| 768 | - 'action' => $this->getAction(), |
|
| 769 | - 'method' => $this->getMethod(), |
|
| 770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | - 'javascript' => $js, |
|
| 772 | - 'elements' => $elements |
|
| 773 | - ]); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * @param bool $withtags |
|
| 778 | - * @return string |
|
| 779 | - */ |
|
| 780 | - public function renderValidationJS($withtags = true) |
|
| 781 | - { |
|
| 782 | - $js = ''; |
|
| 783 | - if ($withtags) { |
|
| 784 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | - } |
|
| 786 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | - $formname = $this->getName(); |
|
| 788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | - // First, output code to check required elements |
|
| 790 | - $elements = $this->getRequired(); |
|
| 791 | - foreach ($elements as $elt) { |
|
| 792 | - $eltname = $elt->getName(); |
|
| 793 | - $eltcaption = trim($elt->getCaption()); |
|
| 794 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | - if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | - $js .= 'var myOption = -1;'; |
|
| 798 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 711 | + $hidden = ''; |
|
| 712 | + $class = 'even'; |
|
| 713 | + foreach ($this->getElements() as $ele) { |
|
| 714 | + if (!is_object($ele)) { |
|
| 715 | + $ret .= $ele; |
|
| 716 | + } elseif (!$ele->isHidden()) { |
|
| 717 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | + if ('' !== $ele->getDescription()) { |
|
| 720 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | + } |
|
| 722 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | + } else { |
|
| 724 | + $hidden .= $ele->render(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | + $ret .= $this->renderValidationJS(true); |
|
| 729 | + |
|
| 730 | + return $ret; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * assign to smarty form template instead of displaying directly |
|
| 735 | + * |
|
| 736 | + * @param \XoopsTpl $tpl |
|
| 737 | + * |
|
| 738 | + * object |
|
| 739 | + * @param bool $smartyName |
|
| 740 | + * @see Smarty |
|
| 741 | + */ |
|
| 742 | + public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | + { |
|
| 744 | + $i = 0; |
|
| 745 | + $elements = []; |
|
| 746 | + foreach ($this->getElements() as $ele) { |
|
| 747 | + $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | + $elements[$n]['name'] = $ele->getName(); |
|
| 749 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | + $elements[$n]['body'] = $ele->render(); |
|
| 751 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | + $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | + if ('' !== $ele->getDescription()) { |
|
| 756 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | + } |
|
| 758 | + ++$i; |
|
| 759 | + } |
|
| 760 | + $js = $this->renderValidationJS(); |
|
| 761 | + if (!$smartyName) { |
|
| 762 | + $smartyName = $this->getName(); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + $tpl->assign($smartyName, [ |
|
| 766 | + 'title' => $this->getTitle(), |
|
| 767 | + 'name' => $this->getName(), |
|
| 768 | + 'action' => $this->getAction(), |
|
| 769 | + 'method' => $this->getMethod(), |
|
| 770 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | + 'javascript' => $js, |
|
| 772 | + 'elements' => $elements |
|
| 773 | + ]); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * @param bool $withtags |
|
| 778 | + * @return string |
|
| 779 | + */ |
|
| 780 | + public function renderValidationJS($withtags = true) |
|
| 781 | + { |
|
| 782 | + $js = ''; |
|
| 783 | + if ($withtags) { |
|
| 784 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | + } |
|
| 786 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | + $formname = $this->getName(); |
|
| 788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | + // First, output code to check required elements |
|
| 790 | + $elements = $this->getRequired(); |
|
| 791 | + foreach ($elements as $elt) { |
|
| 792 | + $eltname = $elt->getName(); |
|
| 793 | + $eltcaption = trim($elt->getCaption()); |
|
| 794 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | + if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | + $js .= 'var myOption = -1;'; |
|
| 798 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 799 | 799 | if (myform.{$eltname}[i].checked) { |
| 800 | 800 | myOption = i; i = -1; |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | if (myOption == -1) { |
| 804 | 804 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 805 | - } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | - $js .= 'var hasSelections = false;'; |
|
| 807 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 805 | + } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | + $js .= 'var hasSelections = false;'; |
|
| 807 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 808 | 808 | if (myform['{$eltname}[]'].options[i].selected) { |
| 809 | 809 | hasSelections = true; |
| 810 | 810 | } |
@@ -812,12 +812,12 @@ discard block |
||
| 812 | 812 | } |
| 813 | 813 | if (hasSelections === false) { |
| 814 | 814 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 815 | - } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | - || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | - $js .= 'var hasSelections = false;'; |
|
| 818 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | - if (false === strpos($eltname, '[')) { |
|
| 820 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 815 | + } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | + || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | + $js .= 'var hasSelections = false;'; |
|
| 818 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | + if (false === strpos($eltname, '[')) { |
|
| 820 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 821 | 821 | if (myform['{$eltname}[]'][i].checked) { |
| 822 | 822 | hasSelections = true; |
| 823 | 823 | } |
@@ -825,8 +825,8 @@ discard block |
||
| 825 | 825 | } |
| 826 | 826 | if (hasSelections === false) { |
| 827 | 827 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 828 | - } else { |
|
| 829 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 828 | + } else { |
|
| 829 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 830 | 830 | if (myform['{$eltname}'][i].checked) { |
| 831 | 831 | hasSelections = true; |
| 832 | 832 | } |
@@ -834,25 +834,25 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | if (hasSelections === false) { |
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 837 | - } |
|
| 838 | - } else { |
|
| 839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - // Now, handle custom validation code |
|
| 843 | - $elements =& $this->getElements(true); |
|
| 844 | - foreach ($elements as $elt) { |
|
| 845 | - if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | - $js .= $eltjs . "\n"; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - $js .= "return true;\n}\n"; |
|
| 852 | - if ($withtags) { |
|
| 853 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $js; |
|
| 857 | - } |
|
| 837 | + } |
|
| 838 | + } else { |
|
| 839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + // Now, handle custom validation code |
|
| 843 | + $elements =& $this->getElements(true); |
|
| 844 | + foreach ($elements as $elt) { |
|
| 845 | + if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | + $js .= $eltjs . "\n"; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + $js .= "return true;\n}\n"; |
|
| 852 | + if ($withtags) { |
|
| 853 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $js; |
|
| 857 | + } |
|
| 858 | 858 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | use XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
| 26 | 26 | use XoopsModules\Smartobject\Form\Elements\SmartFormUrlLinkElement; |
| 27 | 27 | |
| 28 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
| 28 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
| 29 | 29 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
| 30 | 30 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php'; |
| 31 | 31 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $cancel_js_action = false, |
| 71 | 71 | $captcha = false |
| 72 | 72 | ) { |
| 73 | - $this->targetObject =& $target; |
|
| 73 | + $this->targetObject = & $target; |
|
| 74 | 74 | $this->form_fields = $form_fields; |
| 75 | 75 | $this->_cancel_js_action = $cancel_js_action; |
| 76 | 76 | $this->_captcha = $captcha; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function addCaptcha() |
| 100 | 100 | { |
| 101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 101 | + require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php'; |
|
| 102 | 102 | $this->addElement(new \XoopsFormCaptcha(), true); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function addCustomButton($name, $caption, $onclick = false) |
| 111 | 111 | { |
| 112 | - $custom_button_array = [ |
|
| 112 | + $custom_button_array = [ |
|
| 113 | 113 | 'name' => $name, |
| 114 | 114 | 'caption' => $caption, |
| 115 | 115 | 'onclick' => $onclick |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | if ($key) { |
| 131 | 131 | if ($this->targetObject->vars[$key]['readonly']) { |
| 132 | 132 | $formElement->setExtra('disabled="disabled"'); |
| 133 | - $formElement->setName($key . '-readonly'); |
|
| 133 | + $formElement->setName($key.'-readonly'); |
|
| 134 | 134 | // Since this element is disable, we still want to pass it's value in the form |
| 135 | 135 | $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
| 136 | 136 | $this->addElement($hidden); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->addElement($hidden); |
| 142 | 142 | $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
| 143 | 143 | $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
| 144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 144 | + $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra); |
|
| 145 | 145 | } else { |
| 146 | 146 | if (isset($var['form_extra'])) { |
| 147 | 147 | $formElement->setExtra($var['form_extra']); |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | asort($group_list); |
| 309 | 309 | foreach ($permissions as $permission) { |
| 310 | 310 | if ($this->targetObject->isNew()) { |
| 311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 311 | + if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) { |
|
| 312 | + $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']]; |
|
| 313 | 313 | } |
| 314 | 314 | } else { |
| 315 | 315 | $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | } else { |
| 342 | 342 | $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
| 343 | 343 | } |
| 344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"'); |
|
| 345 | 345 | $button_tray->addElement($butt_create); |
| 346 | 346 | |
| 347 | 347 | //creating custom buttons |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | foreach ($this->_custom_button as $custom_button) { |
| 350 | 350 | $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
| 351 | 351 | if ($custom_button['onclick']) { |
| 352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 352 | + $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"'); |
|
| 353 | 353 | } |
| 354 | 354 | $button_tray->addElement($butt_custom); |
| 355 | 355 | unset($butt_custom); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | // creating the "cancel" button |
| 360 | 360 | $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
| 361 | 361 | if ($this->_cancel_js_action) { |
| 362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 362 | + $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"'); |
|
| 363 | 363 | } else { |
| 364 | 364 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
| 365 | 365 | } |
@@ -461,21 +461,21 @@ discard block |
||
| 461 | 461 | break; |
| 462 | 462 | |
| 463 | 463 | default: |
| 464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 464 | + $classname = 'SmartForm'.ucfirst($controlName).'Element'; |
|
| 465 | 465 | if (!class_exists($classname)) { |
| 466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 466 | + if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) { |
|
| 467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
| 468 | 468 | } else { |
| 469 | 469 | // perhaps this is a control created by the module |
| 470 | 470 | $moduleName = $this->targetObject->handler->_moduleName; |
| 471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | - $classFileName = strtolower($classname) . '.php'; |
|
| 471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/'; |
|
| 472 | + $classname = ucfirst($moduleName).ucfirst($controlName).'Element'; |
|
| 473 | + $classFileName = strtolower($classname).'.php'; |
|
| 474 | 474 | |
| 475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 475 | + if (file_exists($moduleFormElementsPath.$classFileName)) { |
|
| 476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
| 477 | 477 | } else { |
| 478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 478 | + trigger_error($classname.' Not found', E_USER_WARNING); |
|
| 479 | 479 | |
| 480 | 480 | return new \XoopsFormLabel(); //Empty object |
| 481 | 481 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | $editor_configs['height'] = '400px'; |
| 545 | 545 | |
| 546 | 546 | $dhtml = true; |
| 547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 547 | + $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php'; |
|
| 548 | 548 | |
| 549 | 549 | if (file_exists($xoopseditorclass)) { |
| 550 | 550 | require_once $xoopseditorclass; |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | case 'tiny': |
| 556 | 556 | if (!$xoops22) { |
| 557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 557 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | 559 | $editor = new \XoopsFormTinymce([ |
| 560 | 560 | 'caption' => $caption, |
| 561 | 561 | 'name' => $name, |
@@ -662,10 +662,10 @@ discard block |
||
| 662 | 662 | $size = $multiple ? 5 : 1; |
| 663 | 663 | $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
| 664 | 664 | |
| 665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 665 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
| 666 | 666 | $dirlist = []; |
| 667 | 667 | while (false !== ($file = readdir($handle))) { |
| 668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 668 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | 669 | && 'cvs' !== strtolower($file)) { |
| 670 | 670 | $dirlist[$file] = $file; |
| 671 | 671 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | { |
| 688 | 688 | foreach ($this->_elements as $eleObj) { |
| 689 | 689 | if ($eleObj->getName() == $keyname) { |
| 690 | - $ret =& $eleObj; |
|
| 690 | + $ret = & $eleObj; |
|
| 691 | 691 | break; |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -704,9 +704,9 @@ discard block |
||
| 704 | 704 | { |
| 705 | 705 | $required = $this->getRequired(); |
| 706 | 706 | $ret = " |
| 707 | - <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
| 707 | + <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
| 708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
| 709 | - <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
|
| 709 | + <tr><th colspan='2'>" . $this->getTitle().'</th></tr> |
|
| 710 | 710 | '; |
| 711 | 711 | $hidden = ''; |
| 712 | 712 | $class = 'even'; |
@@ -715,11 +715,11 @@ discard block |
||
| 715 | 715 | $ret .= $ele; |
| 716 | 716 | } elseif (!$ele->isHidden()) { |
| 717 | 717 | //$class = ( $class == 'even' ) ? 'odd': 'even'; |
| 718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 718 | + $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
| 719 | 719 | if ('' !== $ele->getDescription()) { |
| 720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 720 | + $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
| 721 | 721 | } |
| 722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 722 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
| 723 | 723 | } else { |
| 724 | 724 | $hidden .= $ele->render(); |
| 725 | 725 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | 'name' => $this->getName(), |
| 768 | 768 | 'action' => $this->getAction(), |
| 769 | 769 | 'method' => $this->getMethod(), |
| 770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 770 | + 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), |
|
| 771 | 771 | 'javascript' => $js, |
| 772 | 772 | 'elements' => $elements |
| 773 | 773 | ]); |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | $myts = \MyTextSanitizer::getInstance(); |
| 787 | 787 | $formname = $this->getName(); |
| 788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | 789 | // First, output code to check required elements |
| 790 | 790 | $elements = $this->getRequired(); |
| 791 | 791 | foreach ($elements as $elt) { |
@@ -836,15 +836,15 @@ discard block |
||
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 837 | 837 | } |
| 838 | 838 | } else { |
| 839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | 840 | } |
| 841 | 841 | } |
| 842 | 842 | // Now, handle custom validation code |
| 843 | - $elements =& $this->getElements(true); |
|
| 843 | + $elements = & $this->getElements(true); |
|
| 844 | 844 | foreach ($elements as $elt) { |
| 845 | 845 | if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
| 846 | 846 | if ($eltjs = $elt->renderValidationJS()) { |
| 847 | - $js .= $eltjs . "\n"; |
|
| 847 | + $js .= $eltjs."\n"; |
|
| 848 | 848 | } |
| 849 | 849 | } |
| 850 | 850 | } |
@@ -9,41 +9,41 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | class SmartFormCheckElement extends \XoopsFormCheckBox |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * |
|
| 14 | - * /** |
|
| 15 | - * prepare HTML for output |
|
| 16 | - * |
|
| 17 | - * @return string |
|
| 18 | - */ |
|
| 19 | - public function render() |
|
| 20 | - { |
|
| 21 | - $ret = ''; |
|
| 22 | - if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) { |
|
| 23 | - $newname = $this->getName() . '[]'; |
|
| 24 | - $this->setName($newname); |
|
| 25 | - } |
|
| 26 | - foreach ($this->getOptions() as $value => $name) { |
|
| 27 | - $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
| 28 | - if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
| 29 | - $ret .= ' checked'; |
|
| 30 | - } |
|
| 31 | - $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
| 32 | - } |
|
| 12 | + /** |
|
| 13 | + * |
|
| 14 | + * /** |
|
| 15 | + * prepare HTML for output |
|
| 16 | + * |
|
| 17 | + * @return string |
|
| 18 | + */ |
|
| 19 | + public function render() |
|
| 20 | + { |
|
| 21 | + $ret = ''; |
|
| 22 | + if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) { |
|
| 23 | + $newname = $this->getName() . '[]'; |
|
| 24 | + $this->setName($newname); |
|
| 25 | + } |
|
| 26 | + foreach ($this->getOptions() as $value => $name) { |
|
| 27 | + $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
| 28 | + if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
| 29 | + $ret .= ' checked'; |
|
| 30 | + } |
|
| 31 | + $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return $ret; |
|
| 35 | - } |
|
| 34 | + return $ret; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function renderValidationJS() |
|
| 41 | - { |
|
| 42 | - $js .= 'var hasSelections = false;'; |
|
| 43 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 44 | - $eltname = $this->getName(); |
|
| 45 | - if (false === strpos($eltname, '[')) { |
|
| 46 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 37 | + /** |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function renderValidationJS() |
|
| 41 | + { |
|
| 42 | + $js .= 'var hasSelections = false;'; |
|
| 43 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 44 | + $eltname = $this->getName(); |
|
| 45 | + if (false === strpos($eltname, '[')) { |
|
| 46 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 47 | 47 | if (myform['{$eltname}[]'][i].checked) { |
| 48 | 48 | hasSelections = true; |
| 49 | 49 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | if (hasSelections === false) { |
| 53 | 53 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 54 | - } else { |
|
| 55 | - $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
| 54 | + } else { |
|
| 55 | + $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
| 56 | 56 | if (myform['{$eltname}'][i].checked) { |
| 57 | 57 | hasSelections = true; |
| 58 | 58 | } |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | if (hasSelections === false) { |
| 62 | 62 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $js; |
|
| 66 | - } |
|
| 65 | + return $js; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -18,13 +18,13 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartFormYesnoElement extends \XoopsFormRadioYN |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * SmartFormYesnoElement constructor. |
|
| 23 | - * @param string $object |
|
| 24 | - * @param string $key |
|
| 25 | - */ |
|
| 26 | - public function __construct($object, $key) |
|
| 27 | - { |
|
| 28 | - parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * SmartFormYesnoElement constructor. |
|
| 23 | + * @param string $object |
|
| 24 | + * @param string $key |
|
| 25 | + */ |
|
| 26 | + public function __construct($object, $key) |
|
| 27 | + { |
|
| 28 | + parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -18,38 +18,38 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartAutocompleteElement extends \XoopsFormText |
| 20 | 20 | { |
| 21 | - public $_include_file; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * SmartAutocompleteElement constructor. |
|
| 25 | - * @param string $caption |
|
| 26 | - * @param string $name |
|
| 27 | - * @param int $include_file |
|
| 28 | - * @param int $size |
|
| 29 | - * @param string $maxlength |
|
| 30 | - * @param string $value |
|
| 31 | - */ |
|
| 32 | - public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '') |
|
| 33 | - { |
|
| 34 | - $this->_include_file = $include_file; |
|
| 35 | - parent::__construct($caption, $name, $size, $maxlength, $value); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Prepare HTML for output |
|
| 40 | - * |
|
| 41 | - * @return string HTML |
|
| 42 | - */ |
|
| 43 | - public function render() |
|
| 44 | - { |
|
| 45 | - $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>'; |
|
| 46 | - |
|
| 47 | - $ret .= ' <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div> |
|
| 21 | + public $_include_file; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * SmartAutocompleteElement constructor. |
|
| 25 | + * @param string $caption |
|
| 26 | + * @param string $name |
|
| 27 | + * @param int $include_file |
|
| 28 | + * @param int $size |
|
| 29 | + * @param string $maxlength |
|
| 30 | + * @param string $value |
|
| 31 | + */ |
|
| 32 | + public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '') |
|
| 33 | + { |
|
| 34 | + $this->_include_file = $include_file; |
|
| 35 | + parent::__construct($caption, $name, $size, $maxlength, $value); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Prepare HTML for output |
|
| 40 | + * |
|
| 41 | + * @return string HTML |
|
| 42 | + */ |
|
| 43 | + public function render() |
|
| 44 | + { |
|
| 45 | + $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>'; |
|
| 46 | + |
|
| 47 | + $ret .= ' <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div> |
|
| 48 | 48 | |
| 49 | 49 | <script type="text/javascript"> |
| 50 | 50 | new Ajax.Autocompleter("' . $this->getName() . '","smartobject_autocomplete_hint' . $this->getName() . '","' . $this->_include_file . '?key=' . $this->getName() . '"); |
| 51 | 51 | </script>'; |
| 52 | 52 | |
| 53 | - return $ret; |
|
| 54 | - } |
|
| 53 | + return $ret; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -18,18 +18,18 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartFormAutocompleteElement extends Smartobject\Form\Elements\SmartAutocompleteElement |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * SmartFormAutocompleteElement constructor. |
|
| 23 | - * @param string $object |
|
| 24 | - * @param string $key |
|
| 25 | - */ |
|
| 26 | - public function __construct($object, $key) |
|
| 27 | - { |
|
| 28 | - $var = $object->vars[$key]; |
|
| 29 | - $control = $object->controls[$key]; |
|
| 30 | - $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
|
| 21 | + /** |
|
| 22 | + * SmartFormAutocompleteElement constructor. |
|
| 23 | + * @param string $object |
|
| 24 | + * @param string $key |
|
| 25 | + */ |
|
| 26 | + public function __construct($object, $key) |
|
| 27 | + { |
|
| 28 | + $var = $object->vars[$key]; |
|
| 29 | + $control = $object->controls[$key]; |
|
| 30 | + $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
|
| 31 | 31 | |
| 32 | - $form_size = isset($control['size']) ? $control['size'] : 50; |
|
| 33 | - parent::__construct($var['form_caption'], $key, $form_size, $form_maxlength, $object->getVar($key, 'e')); |
|
| 34 | - } |
|
| 32 | + $form_size = isset($control['size']) ? $control['size'] : 50; |
|
| 33 | + parent::__construct($var['form_caption'], $key, $form_size, $form_maxlength, $object->getVar($key, 'e')); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -19,14 +19,14 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class SmartFormSelectMultiElement extends Smartobject\Form\Elements\SmartFormSelectElement |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * SmartFormSelectMultiElement constructor. |
|
| 24 | - * @param string $object |
|
| 25 | - * @param string $key |
|
| 26 | - */ |
|
| 27 | - public function __construct($object, $key) |
|
| 28 | - { |
|
| 29 | - $this->multiple = true; |
|
| 30 | - parent::__construct($object, $key); |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * SmartFormSelectMultiElement constructor. |
|
| 24 | + * @param string $object |
|
| 25 | + * @param string $key |
|
| 26 | + */ |
|
| 27 | + public function __construct($object, $key) |
|
| 28 | + { |
|
| 29 | + $this->multiple = true; |
|
| 30 | + parent::__construct($object, $key); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -18,23 +18,23 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartFormTimeElement extends \XoopsFormSelect |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * SmartFormTimeElement constructor. |
|
| 23 | - * @param string $object |
|
| 24 | - * @param string $key |
|
| 25 | - */ |
|
| 26 | - public function __construct($object, $key) |
|
| 27 | - { |
|
| 28 | - $var = $object->vars[$key]; |
|
| 29 | - $timearray = []; |
|
| 30 | - for ($i = 0; $i < 24; ++$i) { |
|
| 31 | - for ($j = 0; $j < 60; $j += 10) { |
|
| 32 | - $key_t = ($i * 3600) + ($j * 60); |
|
| 33 | - $timearray[$key_t] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j; |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - ksort($timearray); |
|
| 37 | - parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 38 | - $this->addOptionArray($timearray); |
|
| 39 | - } |
|
| 21 | + /** |
|
| 22 | + * SmartFormTimeElement constructor. |
|
| 23 | + * @param string $object |
|
| 24 | + * @param string $key |
|
| 25 | + */ |
|
| 26 | + public function __construct($object, $key) |
|
| 27 | + { |
|
| 28 | + $var = $object->vars[$key]; |
|
| 29 | + $timearray = []; |
|
| 30 | + for ($i = 0; $i < 24; ++$i) { |
|
| 31 | + for ($j = 0; $j < 60; $j += 10) { |
|
| 32 | + $key_t = ($i * 3600) + ($j * 60); |
|
| 33 | + $timearray[$key_t] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j; |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + ksort($timearray); |
|
| 37 | + parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 38 | + $this->addOptionArray($timearray); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -17,13 +17,13 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class SmartFormDateElement extends \XoopsFormTextDateSelect |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * SmartFormDateElement constructor. |
|
| 22 | - * @param $object |
|
| 23 | - * @param $key |
|
| 24 | - */ |
|
| 25 | - public function __construct($object, $key) |
|
| 26 | - { |
|
| 27 | - parent::__construct($object->vars[$key]['form_caption'], $key, 15, $object->getVar($key, 'e')); |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * SmartFormDateElement constructor. |
|
| 22 | + * @param $object |
|
| 23 | + * @param $key |
|
| 24 | + */ |
|
| 25 | + public function __construct($object, $key) |
|
| 26 | + { |
|
| 27 | + parent::__construct($object->vars[$key]['form_caption'], $key, 15, $object->getVar($key, 'e')); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -18,20 +18,20 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class SmartFormLanguageElement extends \XoopsFormSelectLang |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * SmartFormLanguageElement constructor. |
|
| 23 | - * @param string $object |
|
| 24 | - * @param string $key |
|
| 25 | - */ |
|
| 26 | - public function __construct($object, $key) |
|
| 27 | - { |
|
| 28 | - $var = $object->vars[$key]; |
|
| 29 | - $control = $object->controls[$key]; |
|
| 30 | - $all = isset($control['all']) ? true : false; |
|
| 21 | + /** |
|
| 22 | + * SmartFormLanguageElement constructor. |
|
| 23 | + * @param string $object |
|
| 24 | + * @param string $key |
|
| 25 | + */ |
|
| 26 | + public function __construct($object, $key) |
|
| 27 | + { |
|
| 28 | + $var = $object->vars[$key]; |
|
| 29 | + $control = $object->controls[$key]; |
|
| 30 | + $all = isset($control['all']) ? true : false; |
|
| 31 | 31 | |
| 32 | - parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 33 | - if ($all) { |
|
| 34 | - $this->addOption('all', _ALL); |
|
| 35 | - } |
|
| 36 | - } |
|
| 32 | + parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
| 33 | + if ($all) { |
|
| 34 | + $this->addOption('all', _ALL); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | } |