@@ -152,11 +152,11 @@ |
||
| 152 | 152 | define('_CO_SOBJECT_UPLOAD_IMAGE', 'Upload a new image:'); |
| 153 | 153 | define('_CO_SOBJECT_VERSION_HISTORY', 'Version History'); |
| 154 | 154 | define('_CO_SOBJECT_WARNING_BETA', |
| 155 | - 'This module comes as is, without any guarantees whatsoever. This module is BETA, meaning it is still under active development. This release is meant for <b>testing purposes only</b> and we <b>strongly</b> recommend that you do not use it on a live website or in a production environment.'); |
|
| 155 | + 'This module comes as is, without any guarantees whatsoever. This module is BETA, meaning it is still under active development. This release is meant for <b>testing purposes only</b> and we <b>strongly</b> recommend that you do not use it on a live website or in a production environment.'); |
|
| 156 | 156 | define('_CO_SOBJECT_WARNING_FINAL', |
| 157 | - 'This module comes as is, without any guarantees whatsoever. Although this module is not beta, it is still under active development. This release can be used in a live website or a production environment, but its use is under your own responsibility, which means the author is not responsible.'); |
|
| 157 | + 'This module comes as is, without any guarantees whatsoever. Although this module is not beta, it is still under active development. This release can be used in a live website or a production environment, but its use is under your own responsibility, which means the author is not responsible.'); |
|
| 158 | 158 | define('_CO_SOBJECT_WARNING_RC', |
| 159 | - 'This module comes as is, without any guarantees whatsoever. This module is a Release Candidate and should not be used on a production web site. The module is still under active development and its use is under your own responsibility, which means the author is not responsible.'); |
|
| 159 | + 'This module comes as is, without any guarantees whatsoever. This module is a Release Candidate and should not be used on a production web site. The module is still under active development and its use is under your own responsibility, which means the author is not responsible.'); |
|
| 160 | 160 | define('_CO_SOBJECT_WEIGHT_FORM_CAPTION', 'Weight'); |
| 161 | 161 | define('_CO_SOBJECT_WEIGHT_FORM_DSC', ''); |
| 162 | 162 | |
@@ -9,17 +9,17 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class SmartObjectTree extends XoopsObjectTree |
| 11 | 11 | { |
| 12 | - public function _initialize() |
|
| 13 | - { |
|
| 14 | - foreach (array_keys($this->_objects) as $i) { |
|
| 15 | - $key1 = $this->_objects[$i]->getVar($this->_myId); |
|
| 16 | - $this->tree[$key1]['obj'] = $this->_objects[$i]; |
|
| 17 | - $key2 = $this->_objects[$i]->getVar($this->_parentId, 'e'); |
|
| 18 | - $this->tree[$key1]['parent'] = $key2; |
|
| 19 | - $this->tree[$key2]['child'][] = $key1; |
|
| 20 | - if (isset($this->_rootId)) { |
|
| 21 | - $this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId); |
|
| 22 | - } |
|
| 23 | - } |
|
| 24 | - } |
|
| 12 | + public function _initialize() |
|
| 13 | + { |
|
| 14 | + foreach (array_keys($this->_objects) as $i) { |
|
| 15 | + $key1 = $this->_objects[$i]->getVar($this->_myId); |
|
| 16 | + $this->tree[$key1]['obj'] = $this->_objects[$i]; |
|
| 17 | + $key2 = $this->_objects[$i]->getVar($this->_parentId, 'e'); |
|
| 18 | + $this->tree[$key1]['parent'] = $key2; |
|
| 19 | + $this->tree[$key2]['child'][] = $key1; |
|
| 20 | + if (isset($this->_rootId)) { |
|
| 21 | + $this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId); |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -36,87 +36,87 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | class SmartobjectAdsense extends SmartObject |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * SmartobjectAdsense constructor. |
|
| 41 | - */ |
|
| 42 | - public function __construct() |
|
| 43 | - { |
|
| 44 | - $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 45 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 46 | - $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 47 | - $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 48 | - $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 49 | - $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 50 | - $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 51 | - $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 52 | - $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 53 | - $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 54 | - $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 55 | - |
|
| 56 | - $this->setControl('format', array( |
|
| 57 | - 'handler' => 'adsense', |
|
| 58 | - 'method' => 'getFormats' |
|
| 59 | - )); |
|
| 60 | - |
|
| 61 | - $this->setControl('border_color', array( |
|
| 62 | - 'name' => 'text', |
|
| 63 | - 'size' => 6, |
|
| 64 | - 'maxlength' => 6 |
|
| 65 | - )); |
|
| 66 | - |
|
| 67 | - $this->setControl('background_color', array( |
|
| 68 | - 'name' => 'text', |
|
| 69 | - 'size' => 6, |
|
| 70 | - 'maxlength' => 6 |
|
| 71 | - )); |
|
| 72 | - |
|
| 73 | - $this->setControl('link_color', array( |
|
| 74 | - 'name' => 'text', |
|
| 75 | - 'size' => 6, |
|
| 76 | - 'maxlength' => 6 |
|
| 77 | - )); |
|
| 78 | - |
|
| 79 | - $this->setControl('url_color', array( |
|
| 80 | - 'name' => 'text', |
|
| 81 | - 'size' => 6, |
|
| 82 | - 'maxlength' => 6 |
|
| 83 | - )); |
|
| 84 | - |
|
| 85 | - $this->setControl('text_color', array( |
|
| 86 | - 'name' => 'text', |
|
| 87 | - 'size' => 6, |
|
| 88 | - 'maxlength' => 6 |
|
| 89 | - )); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $key |
|
| 94 | - * @param string $format |
|
| 95 | - * @return mixed |
|
| 96 | - */ |
|
| 97 | - public function getVar($key, $format = 's') |
|
| 98 | - { |
|
| 99 | - if ($format === 's' && in_array($key, array())) { |
|
| 100 | - // return call_user_func(array($this, $key)); |
|
| 101 | - return $this->{$key}(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return parent::getVar($key, $format); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function render() |
|
| 111 | - { |
|
| 112 | - global $smartobjectAdsenseHandler; |
|
| 113 | - if ($this->getVar('style', 'n') !== '') { |
|
| 114 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 115 | - } else { |
|
| 116 | - $ret = '<div>'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $ret .= '<script type="text/javascript"><!-- |
|
| 39 | + /** |
|
| 40 | + * SmartobjectAdsense constructor. |
|
| 41 | + */ |
|
| 42 | + public function __construct() |
|
| 43 | + { |
|
| 44 | + $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
| 45 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
| 46 | + $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
| 47 | + $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
| 48 | + $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
| 49 | + $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 50 | + $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
| 51 | + $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
| 52 | + $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
| 53 | + $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
| 54 | + $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
| 55 | + |
|
| 56 | + $this->setControl('format', array( |
|
| 57 | + 'handler' => 'adsense', |
|
| 58 | + 'method' => 'getFormats' |
|
| 59 | + )); |
|
| 60 | + |
|
| 61 | + $this->setControl('border_color', array( |
|
| 62 | + 'name' => 'text', |
|
| 63 | + 'size' => 6, |
|
| 64 | + 'maxlength' => 6 |
|
| 65 | + )); |
|
| 66 | + |
|
| 67 | + $this->setControl('background_color', array( |
|
| 68 | + 'name' => 'text', |
|
| 69 | + 'size' => 6, |
|
| 70 | + 'maxlength' => 6 |
|
| 71 | + )); |
|
| 72 | + |
|
| 73 | + $this->setControl('link_color', array( |
|
| 74 | + 'name' => 'text', |
|
| 75 | + 'size' => 6, |
|
| 76 | + 'maxlength' => 6 |
|
| 77 | + )); |
|
| 78 | + |
|
| 79 | + $this->setControl('url_color', array( |
|
| 80 | + 'name' => 'text', |
|
| 81 | + 'size' => 6, |
|
| 82 | + 'maxlength' => 6 |
|
| 83 | + )); |
|
| 84 | + |
|
| 85 | + $this->setControl('text_color', array( |
|
| 86 | + 'name' => 'text', |
|
| 87 | + 'size' => 6, |
|
| 88 | + 'maxlength' => 6 |
|
| 89 | + )); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $key |
|
| 94 | + * @param string $format |
|
| 95 | + * @return mixed |
|
| 96 | + */ |
|
| 97 | + public function getVar($key, $format = 's') |
|
| 98 | + { |
|
| 99 | + if ($format === 's' && in_array($key, array())) { |
|
| 100 | + // return call_user_func(array($this, $key)); |
|
| 101 | + return $this->{$key}(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return parent::getVar($key, $format); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function render() |
|
| 111 | + { |
|
| 112 | + global $smartobjectAdsenseHandler; |
|
| 113 | + if ($this->getVar('style', 'n') !== '') { |
|
| 114 | + $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
| 115 | + } else { |
|
| 116 | + $ret = '<div>'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $ret .= '<script type="text/javascript"><!-- |
|
| 120 | 120 | google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
| 121 | 121 | google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
| 122 | 122 | google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
@@ -134,139 +134,139 @@ discard block |
||
| 134 | 134 | </script> |
| 135 | 135 | </div>'; |
| 136 | 136 | |
| 137 | - return $ret; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function getXoopsCode() |
|
| 144 | - { |
|
| 145 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 146 | - |
|
| 147 | - return $ret; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param $var |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - public function emptyString($var) |
|
| 155 | - { |
|
| 156 | - return (strlen($var) > 0); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return mixed|string |
|
| 161 | - */ |
|
| 162 | - public function generateTag() |
|
| 163 | - { |
|
| 164 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 165 | - $title = xoops_substr($title, 0, 10, ''); |
|
| 166 | - // Transformation des ponctuations |
|
| 167 | - $pattern = array( |
|
| 168 | - '/%09/', // Tab |
|
| 169 | - '/%20/', // Space |
|
| 170 | - '/%21/', // ! |
|
| 171 | - '/%22/', // " |
|
| 172 | - '/%23/', // # |
|
| 173 | - '/%25/', // % |
|
| 174 | - '/%26/', // & |
|
| 175 | - '/%27/', // ' |
|
| 176 | - '/%28/', // ( |
|
| 177 | - '/%29/', // ) |
|
| 178 | - '/%2C/', // , |
|
| 179 | - '/%2F/', // / |
|
| 180 | - '/%3A/', // : |
|
| 181 | - '/%3B/', // ; |
|
| 182 | - '/%3C/', // < |
|
| 183 | - '/%3D/', // = |
|
| 184 | - '/%3E/', // > |
|
| 185 | - '/%3F/', // ? |
|
| 186 | - '/%40/', // @ |
|
| 187 | - '/%5B/', // [ |
|
| 188 | - '/%5C/', // \ |
|
| 189 | - '/%5D/', // ] |
|
| 190 | - '/%5E/', // ^ |
|
| 191 | - '/%7B/', // { |
|
| 192 | - '/%7C/', // | |
|
| 193 | - '/%7D/', // } |
|
| 194 | - '/%7E/', // ~ |
|
| 195 | - "/\./" // . |
|
| 196 | - ); |
|
| 197 | - $rep_pat = array( |
|
| 198 | - '-', |
|
| 199 | - '-', |
|
| 200 | - '-', |
|
| 201 | - '-', |
|
| 202 | - '-', |
|
| 203 | - '-100', |
|
| 204 | - '-', |
|
| 205 | - '-', |
|
| 206 | - '-', |
|
| 207 | - '-', |
|
| 208 | - '-', |
|
| 209 | - '-', |
|
| 210 | - '-', |
|
| 211 | - '-', |
|
| 212 | - '-', |
|
| 213 | - '-', |
|
| 214 | - '-', |
|
| 215 | - '-', |
|
| 216 | - '-at-', |
|
| 217 | - '-', |
|
| 218 | - '-', |
|
| 219 | - '-', |
|
| 220 | - '-', |
|
| 221 | - '-', |
|
| 222 | - '-', |
|
| 223 | - '-', |
|
| 224 | - '-', |
|
| 225 | - '-' |
|
| 226 | - ); |
|
| 227 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 228 | - |
|
| 229 | - // Transformation des caractères accentués |
|
| 230 | - $pattern = array( |
|
| 231 | - '/%B0/', // ° |
|
| 232 | - '/%E8/', // è |
|
| 233 | - '/%E9/', // é |
|
| 234 | - '/%EA/', // ê |
|
| 235 | - '/%EB/', // ë |
|
| 236 | - '/%E7/', // ç |
|
| 237 | - '/%E0/', // à |
|
| 238 | - '/%E2/', // â |
|
| 239 | - '/%E4/', // ä |
|
| 240 | - '/%EE/', // î |
|
| 241 | - '/%EF/', // ï |
|
| 242 | - '/%F9/', // ù |
|
| 243 | - '/%FC/', // ü |
|
| 244 | - '/%FB/', // û |
|
| 245 | - '/%F4/', // ô |
|
| 246 | - '/%F6/', // ö |
|
| 247 | - ); |
|
| 248 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 249 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
| 250 | - |
|
| 251 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 252 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 253 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 254 | - |
|
| 255 | - $title .= time(); |
|
| 256 | - $title = md5($title); |
|
| 257 | - |
|
| 258 | - return $title; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function getCloneLink() |
|
| 265 | - { |
|
| 266 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 267 | - |
|
| 268 | - return $ret; |
|
| 269 | - } |
|
| 137 | + return $ret; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function getXoopsCode() |
|
| 144 | + { |
|
| 145 | + $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
| 146 | + |
|
| 147 | + return $ret; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param $var |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + public function emptyString($var) |
|
| 155 | + { |
|
| 156 | + return (strlen($var) > 0); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return mixed|string |
|
| 161 | + */ |
|
| 162 | + public function generateTag() |
|
| 163 | + { |
|
| 164 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
| 165 | + $title = xoops_substr($title, 0, 10, ''); |
|
| 166 | + // Transformation des ponctuations |
|
| 167 | + $pattern = array( |
|
| 168 | + '/%09/', // Tab |
|
| 169 | + '/%20/', // Space |
|
| 170 | + '/%21/', // ! |
|
| 171 | + '/%22/', // " |
|
| 172 | + '/%23/', // # |
|
| 173 | + '/%25/', // % |
|
| 174 | + '/%26/', // & |
|
| 175 | + '/%27/', // ' |
|
| 176 | + '/%28/', // ( |
|
| 177 | + '/%29/', // ) |
|
| 178 | + '/%2C/', // , |
|
| 179 | + '/%2F/', // / |
|
| 180 | + '/%3A/', // : |
|
| 181 | + '/%3B/', // ; |
|
| 182 | + '/%3C/', // < |
|
| 183 | + '/%3D/', // = |
|
| 184 | + '/%3E/', // > |
|
| 185 | + '/%3F/', // ? |
|
| 186 | + '/%40/', // @ |
|
| 187 | + '/%5B/', // [ |
|
| 188 | + '/%5C/', // \ |
|
| 189 | + '/%5D/', // ] |
|
| 190 | + '/%5E/', // ^ |
|
| 191 | + '/%7B/', // { |
|
| 192 | + '/%7C/', // | |
|
| 193 | + '/%7D/', // } |
|
| 194 | + '/%7E/', // ~ |
|
| 195 | + "/\./" // . |
|
| 196 | + ); |
|
| 197 | + $rep_pat = array( |
|
| 198 | + '-', |
|
| 199 | + '-', |
|
| 200 | + '-', |
|
| 201 | + '-', |
|
| 202 | + '-', |
|
| 203 | + '-100', |
|
| 204 | + '-', |
|
| 205 | + '-', |
|
| 206 | + '-', |
|
| 207 | + '-', |
|
| 208 | + '-', |
|
| 209 | + '-', |
|
| 210 | + '-', |
|
| 211 | + '-', |
|
| 212 | + '-', |
|
| 213 | + '-', |
|
| 214 | + '-', |
|
| 215 | + '-', |
|
| 216 | + '-at-', |
|
| 217 | + '-', |
|
| 218 | + '-', |
|
| 219 | + '-', |
|
| 220 | + '-', |
|
| 221 | + '-', |
|
| 222 | + '-', |
|
| 223 | + '-', |
|
| 224 | + '-', |
|
| 225 | + '-' |
|
| 226 | + ); |
|
| 227 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 228 | + |
|
| 229 | + // Transformation des caractères accentués |
|
| 230 | + $pattern = array( |
|
| 231 | + '/%B0/', // ° |
|
| 232 | + '/%E8/', // è |
|
| 233 | + '/%E9/', // é |
|
| 234 | + '/%EA/', // ê |
|
| 235 | + '/%EB/', // ë |
|
| 236 | + '/%E7/', // ç |
|
| 237 | + '/%E0/', // à |
|
| 238 | + '/%E2/', // â |
|
| 239 | + '/%E4/', // ä |
|
| 240 | + '/%EE/', // î |
|
| 241 | + '/%EF/', // ï |
|
| 242 | + '/%F9/', // ù |
|
| 243 | + '/%FC/', // ü |
|
| 244 | + '/%FB/', // û |
|
| 245 | + '/%F4/', // ô |
|
| 246 | + '/%F6/', // ö |
|
| 247 | + ); |
|
| 248 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
| 249 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
| 250 | + |
|
| 251 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
| 252 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
| 253 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
| 254 | + |
|
| 255 | + $title .= time(); |
|
| 256 | + $title = md5($title); |
|
| 257 | + |
|
| 258 | + return $title; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function getCloneLink() |
|
| 265 | + { |
|
| 266 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '"></a>'; |
|
| 267 | + |
|
| 268 | + return $ret; |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -274,116 +274,116 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | class SmartobjectAdsenseHandler extends SmartPersistableObjectHandler |
| 276 | 276 | { |
| 277 | - public $adFormats; |
|
| 278 | - public $adFormatsList; |
|
| 279 | - public $objects = false; |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * SmartobjectAdsenseHandler constructor. |
|
| 283 | - * @param XoopsDatabase $db |
|
| 284 | - */ |
|
| 285 | - public function __construct(XoopsDatabase $db) |
|
| 286 | - { |
|
| 287 | - parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 288 | - $this->adFormats = array(); |
|
| 289 | - $this->adFormatsList = array(); |
|
| 290 | - |
|
| 291 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 292 | - $this->adFormats['728x90_as']['width'] = 728; |
|
| 293 | - $this->adFormats['728x90_as']['height'] = 90; |
|
| 294 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 295 | - |
|
| 296 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 297 | - $this->adFormats['468x60_as']['width'] = 468; |
|
| 298 | - $this->adFormats['468x60_as']['height'] = 60; |
|
| 299 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 300 | - |
|
| 301 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 302 | - $this->adFormats['234x60_as']['width'] = 234; |
|
| 303 | - $this->adFormats['234x60_as']['height'] = 60; |
|
| 304 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 305 | - |
|
| 306 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 307 | - $this->adFormats['120x600_as']['width'] = 120; |
|
| 308 | - $this->adFormats['120x600_as']['height'] = 600; |
|
| 309 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 310 | - |
|
| 311 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 312 | - $this->adFormats['160x600_as']['width'] = 160; |
|
| 313 | - $this->adFormats['160x600_as']['height'] = 600; |
|
| 314 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 315 | - |
|
| 316 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 317 | - $this->adFormats['120x240_as']['width'] = 120; |
|
| 318 | - $this->adFormats['120x240_as']['height'] = 240; |
|
| 319 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 320 | - |
|
| 321 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 322 | - $this->adFormats['336x280_as']['width'] = 136; |
|
| 323 | - $this->adFormats['336x280_as']['height'] = 280; |
|
| 324 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 325 | - |
|
| 326 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 327 | - $this->adFormats['300x250_as']['width'] = 300; |
|
| 328 | - $this->adFormats['300x250_as']['height'] = 250; |
|
| 329 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 330 | - |
|
| 331 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 332 | - $this->adFormats['250x250_as']['width'] = 250; |
|
| 333 | - $this->adFormats['250x250_as']['height'] = 250; |
|
| 334 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 335 | - |
|
| 336 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 337 | - $this->adFormats['200x200_as']['width'] = 200; |
|
| 338 | - $this->adFormats['200x200_as']['height'] = 200; |
|
| 339 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 340 | - |
|
| 341 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 342 | - $this->adFormats['180x150_as']['width'] = 180; |
|
| 343 | - $this->adFormats['180x150_as']['height'] = 150; |
|
| 344 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 345 | - |
|
| 346 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 347 | - $this->adFormats['125x125_as']['width'] = 125; |
|
| 348 | - $this->adFormats['125x125_as']['height'] = 125; |
|
| 349 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function getFormats() |
|
| 356 | - { |
|
| 357 | - return $this->adFormatsList; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param $obj |
|
| 362 | - * @return bool |
|
| 363 | - */ |
|
| 364 | - public function beforeSave($obj) |
|
| 365 | - { |
|
| 366 | - if ($obj->getVar('tag') === '') { |
|
| 367 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return true; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @return array|bool |
|
| 375 | - */ |
|
| 376 | - public function getAdsensesByTag() |
|
| 377 | - { |
|
| 378 | - if (!$this->objects) { |
|
| 379 | - $adsensesObj = $this->getObjects(null, true); |
|
| 380 | - $ret = array(); |
|
| 381 | - foreach ($adsensesObj as $adsenseObj) { |
|
| 382 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 383 | - } |
|
| 384 | - $this->objects = $ret; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $this->objects; |
|
| 388 | - } |
|
| 277 | + public $adFormats; |
|
| 278 | + public $adFormatsList; |
|
| 279 | + public $objects = false; |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * SmartobjectAdsenseHandler constructor. |
|
| 283 | + * @param XoopsDatabase $db |
|
| 284 | + */ |
|
| 285 | + public function __construct(XoopsDatabase $db) |
|
| 286 | + { |
|
| 287 | + parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 288 | + $this->adFormats = array(); |
|
| 289 | + $this->adFormatsList = array(); |
|
| 290 | + |
|
| 291 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 292 | + $this->adFormats['728x90_as']['width'] = 728; |
|
| 293 | + $this->adFormats['728x90_as']['height'] = 90; |
|
| 294 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 295 | + |
|
| 296 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 297 | + $this->adFormats['468x60_as']['width'] = 468; |
|
| 298 | + $this->adFormats['468x60_as']['height'] = 60; |
|
| 299 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 300 | + |
|
| 301 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 302 | + $this->adFormats['234x60_as']['width'] = 234; |
|
| 303 | + $this->adFormats['234x60_as']['height'] = 60; |
|
| 304 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 305 | + |
|
| 306 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 307 | + $this->adFormats['120x600_as']['width'] = 120; |
|
| 308 | + $this->adFormats['120x600_as']['height'] = 600; |
|
| 309 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 310 | + |
|
| 311 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 312 | + $this->adFormats['160x600_as']['width'] = 160; |
|
| 313 | + $this->adFormats['160x600_as']['height'] = 600; |
|
| 314 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 315 | + |
|
| 316 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 317 | + $this->adFormats['120x240_as']['width'] = 120; |
|
| 318 | + $this->adFormats['120x240_as']['height'] = 240; |
|
| 319 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 320 | + |
|
| 321 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 322 | + $this->adFormats['336x280_as']['width'] = 136; |
|
| 323 | + $this->adFormats['336x280_as']['height'] = 280; |
|
| 324 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 325 | + |
|
| 326 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 327 | + $this->adFormats['300x250_as']['width'] = 300; |
|
| 328 | + $this->adFormats['300x250_as']['height'] = 250; |
|
| 329 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 330 | + |
|
| 331 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 332 | + $this->adFormats['250x250_as']['width'] = 250; |
|
| 333 | + $this->adFormats['250x250_as']['height'] = 250; |
|
| 334 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 335 | + |
|
| 336 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 337 | + $this->adFormats['200x200_as']['width'] = 200; |
|
| 338 | + $this->adFormats['200x200_as']['height'] = 200; |
|
| 339 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 340 | + |
|
| 341 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 342 | + $this->adFormats['180x150_as']['width'] = 180; |
|
| 343 | + $this->adFormats['180x150_as']['height'] = 150; |
|
| 344 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 345 | + |
|
| 346 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 347 | + $this->adFormats['125x125_as']['width'] = 125; |
|
| 348 | + $this->adFormats['125x125_as']['height'] = 125; |
|
| 349 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function getFormats() |
|
| 356 | + { |
|
| 357 | + return $this->adFormatsList; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param $obj |
|
| 362 | + * @return bool |
|
| 363 | + */ |
|
| 364 | + public function beforeSave($obj) |
|
| 365 | + { |
|
| 366 | + if ($obj->getVar('tag') === '') { |
|
| 367 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return true; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @return array|bool |
|
| 375 | + */ |
|
| 376 | + public function getAdsensesByTag() |
|
| 377 | + { |
|
| 378 | + if (!$this->objects) { |
|
| 379 | + $adsensesObj = $this->getObjects(null, true); |
|
| 380 | + $ret = array(); |
|
| 381 | + foreach ($adsensesObj as $adsenseObj) { |
|
| 382 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 383 | + } |
|
| 384 | + $this->objects = $ret; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $this->objects; |
|
| 388 | + } |
|
| 389 | 389 | } |
@@ -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 = array( |
|
| 103 | - 'name' => $name, |
|
| 104 | - 'caption' => $caption, |
|
| 105 | - 'onclick' => $onclick |
|
| 106 | - ); |
|
| 107 | - $this->_custom_button[] = $custom_button_array; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Add an element to the form |
|
| 112 | - * |
|
| 113 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 114 | - * @param bool $key |
|
| 115 | - * @param bool $var |
|
| 116 | - * @param bool|string $required is this a "required" element? |
|
| 117 | - */ |
|
| 118 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 119 | - { |
|
| 120 | - if ($key) { |
|
| 121 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 122 | - $formElement->setExtra('disabled="disabled"'); |
|
| 123 | - $formElement->setName($key . '-readonly'); |
|
| 124 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 125 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 126 | - $this->addElement($hidden); |
|
| 127 | - } |
|
| 128 | - $formElement->setDescription($var['form_dsc']); |
|
| 129 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 130 | - $hidden = new XoopsFormHidden('changedField', false); |
|
| 131 | - $this->addElement($hidden); |
|
| 132 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 133 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 134 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 135 | - } else { |
|
| 136 | - if (isset($var['form_extra'])) { |
|
| 137 | - $formElement->setExtra($var['form_extra']); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - $controls = $this->targetObject->controls; |
|
| 141 | - if (isset($controls[$key]['js'])) { |
|
| 142 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 143 | - } |
|
| 144 | - parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 145 | - } else { |
|
| 146 | - parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 147 | - } |
|
| 148 | - unset($formElement); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function createElements() |
|
| 152 | - { |
|
| 153 | - $controls = $this->targetObject->controls; |
|
| 154 | - $vars = $this->targetObject->vars; |
|
| 155 | - foreach ($vars as $key => $var) { |
|
| 156 | - |
|
| 157 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 158 | - // need to be displayed, then we only create an hidden field |
|
| 159 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 160 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 161 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 162 | - unset($elementToAdd); |
|
| 163 | - // If not, the we need to create the proper form control for this fields |
|
| 164 | - } else { |
|
| 165 | - // If this field has a specific control, we will use it |
|
| 166 | - |
|
| 167 | - if ($key === 'parentid') { |
|
| 168 | - /** |
|
| 169 | - * Why this ? |
|
| 170 | - */ |
|
| 171 | - } |
|
| 172 | - if (isset($controls[$key])) { |
|
| 173 | - /* If the control has name, it's because it's an object already present in the script |
|
| 33 | + public $targetObject = null; |
|
| 34 | + public $form_fields = null; |
|
| 35 | + public $_cancel_js_action = false; |
|
| 36 | + public $_custom_button = false; |
|
| 37 | + public $_captcha = false; |
|
| 38 | + public $_form_name = false; |
|
| 39 | + public $_form_caption = false; |
|
| 40 | + public $_submit_button_caption = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * SmartobjectForm constructor. |
|
| 44 | + * @param string $target |
|
| 45 | + * @param string $form_name |
|
| 46 | + * @param string $form_caption |
|
| 47 | + * @param string $form_action |
|
| 48 | + * @param null $form_fields |
|
| 49 | + * @param bool $submit_button_caption |
|
| 50 | + * @param bool $cancel_js_action |
|
| 51 | + * @param bool $captcha |
|
| 52 | + */ |
|
| 53 | + public function __construct( |
|
| 54 | + &$target, |
|
| 55 | + $form_name, |
|
| 56 | + $form_caption, |
|
| 57 | + $form_action, |
|
| 58 | + $form_fields = null, |
|
| 59 | + $submit_button_caption = false, |
|
| 60 | + $cancel_js_action = false, |
|
| 61 | + $captcha = false |
|
| 62 | + ) { |
|
| 63 | + $this->targetObject =& $target; |
|
| 64 | + $this->form_fields = $form_fields; |
|
| 65 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 66 | + $this->_captcha = $captcha; |
|
| 67 | + $this->_form_name = $form_name; |
|
| 68 | + $this->_form_caption = $form_caption; |
|
| 69 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 70 | + |
|
| 71 | + if (!isset($form_action)) { |
|
| 72 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 76 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 77 | + |
|
| 78 | + $this->createElements(); |
|
| 79 | + |
|
| 80 | + if ($captcha) { |
|
| 81 | + $this->addCaptcha(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->createPermissionControls(); |
|
| 85 | + |
|
| 86 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function addCaptcha() |
|
| 90 | + { |
|
| 91 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 92 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param $name |
|
| 97 | + * @param $caption |
|
| 98 | + * @param bool $onclick |
|
| 99 | + */ |
|
| 100 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 101 | + { |
|
| 102 | + $custom_button_array = array( |
|
| 103 | + 'name' => $name, |
|
| 104 | + 'caption' => $caption, |
|
| 105 | + 'onclick' => $onclick |
|
| 106 | + ); |
|
| 107 | + $this->_custom_button[] = $custom_button_array; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Add an element to the form |
|
| 112 | + * |
|
| 113 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 114 | + * @param bool $key |
|
| 115 | + * @param bool $var |
|
| 116 | + * @param bool|string $required is this a "required" element? |
|
| 117 | + */ |
|
| 118 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 119 | + { |
|
| 120 | + if ($key) { |
|
| 121 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 122 | + $formElement->setExtra('disabled="disabled"'); |
|
| 123 | + $formElement->setName($key . '-readonly'); |
|
| 124 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 125 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 126 | + $this->addElement($hidden); |
|
| 127 | + } |
|
| 128 | + $formElement->setDescription($var['form_dsc']); |
|
| 129 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 130 | + $hidden = new XoopsFormHidden('changedField', false); |
|
| 131 | + $this->addElement($hidden); |
|
| 132 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 133 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 134 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 135 | + } else { |
|
| 136 | + if (isset($var['form_extra'])) { |
|
| 137 | + $formElement->setExtra($var['form_extra']); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + $controls = $this->targetObject->controls; |
|
| 141 | + if (isset($controls[$key]['js'])) { |
|
| 142 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 143 | + } |
|
| 144 | + parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
| 145 | + } else { |
|
| 146 | + parent::addElement($formElement, $required === 'notset' ? false : true); |
|
| 147 | + } |
|
| 148 | + unset($formElement); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function createElements() |
|
| 152 | + { |
|
| 153 | + $controls = $this->targetObject->controls; |
|
| 154 | + $vars = $this->targetObject->vars; |
|
| 155 | + foreach ($vars as $key => $var) { |
|
| 156 | + |
|
| 157 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 158 | + // need to be displayed, then we only create an hidden field |
|
| 159 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 160 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
| 161 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 162 | + unset($elementToAdd); |
|
| 163 | + // If not, the we need to create the proper form control for this fields |
|
| 164 | + } else { |
|
| 165 | + // If this field has a specific control, we will use it |
|
| 166 | + |
|
| 167 | + if ($key === 'parentid') { |
|
| 168 | + /** |
|
| 169 | + * Why this ? |
|
| 170 | + */ |
|
| 171 | + } |
|
| 172 | + if (isset($controls[$key])) { |
|
| 173 | + /* If the control has name, it's because it's an object already present in the script |
|
| 174 | 174 | * for example, "user" |
| 175 | 175 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 176 | 176 | */ |
| 177 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 178 | - $controls[$key]['name'] = 'select'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 182 | - |
|
| 183 | - // Adding on the form, the control for this field |
|
| 184 | - $this->addElement($form_select, $key, $var); |
|
| 185 | - unset($form_select); |
|
| 186 | - |
|
| 187 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 188 | - } else { |
|
| 189 | - switch ($var['data_type']) { |
|
| 190 | - |
|
| 191 | - case XOBJ_DTYPE_TXTBOX: |
|
| 192 | - |
|
| 193 | - $form_text = $this->getControl('text', $key); |
|
| 194 | - $this->addElement($form_text, $key, $var); |
|
| 195 | - unset($form_text); |
|
| 196 | - break; |
|
| 197 | - |
|
| 198 | - case XOBJ_DTYPE_INT: |
|
| 199 | - $this->targetObject->setControl($key, array( |
|
| 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, array( |
|
| 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, array( |
|
| 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, array( |
|
| 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, array( |
|
| 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, array( |
|
| 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 = array( |
|
| 491 | - 'name' => 'textarea', |
|
| 492 | - 'itemHandler' => false, |
|
| 493 | - 'method' => false, |
|
| 494 | - 'module' => false, |
|
| 495 | - 'form_editor' => 'default' |
|
| 496 | - ); |
|
| 497 | - } else { |
|
| 498 | - $control = $this->targetObject->controls[$key]; |
|
| 499 | - } |
|
| 500 | - $xoops22 = smart_isXoops22(); |
|
| 501 | - |
|
| 502 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 503 | - /** |
|
| 504 | - * If the editor is 'default', retreive the default editor of this module |
|
| 505 | - */ |
|
| 506 | - if ($form_editor === 'default') { |
|
| 507 | - global $xoopsModuleConfig; |
|
| 508 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - $caption = $var['form_caption']; |
|
| 512 | - $name = $key; |
|
| 513 | - |
|
| 514 | - $value = $this->targetObject->getVar($key); |
|
| 515 | - |
|
| 516 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 517 | - |
|
| 518 | - $editor_configs = array(); |
|
| 519 | - $editor_configs['name'] = $name; |
|
| 520 | - $editor_configs['value'] = $value; |
|
| 521 | - if ($form_editor !== 'textarea') { |
|
| 522 | - $editor_configs['rows'] = 35; |
|
| 523 | - $editor_configs['cols'] = 60; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - if (isset($control['rows'])) { |
|
| 527 | - $editor_configs['rows'] = $control['rows']; |
|
| 528 | - } |
|
| 529 | - if (isset($control['cols'])) { |
|
| 530 | - $editor_configs['cols'] = $control['cols']; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $editor_configs['width'] = '100%'; |
|
| 534 | - $editor_configs['height'] = '400px'; |
|
| 535 | - |
|
| 536 | - $dhtml = true; |
|
| 537 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 538 | - |
|
| 539 | - if (file_exists($xoopseditorclass)) { |
|
| 540 | - require_once $xoopseditorclass; |
|
| 541 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 542 | - } else { |
|
| 543 | - switch ($form_editor) { |
|
| 544 | - |
|
| 545 | - case 'tiny': |
|
| 546 | - if (!$xoops22) { |
|
| 547 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 549 | - $editor = new XoopsFormTinyTextArea(array( |
|
| 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(array( |
|
| 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(array( |
|
| 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 = array(); |
|
| 691 | - while (false !== ($file = readdir($handle))) { |
|
| 692 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 693 | - && strtolower($file) !== 'cvs') { |
|
| 694 | - $dirlist[$file] = $file; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - closedir($handle); |
|
| 698 | - if (!empty($dirlist)) { |
|
| 699 | - asort($dirlist); |
|
| 700 | - $theme_select->addOptionArray($dirlist); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - return $theme_select; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @param $keyname |
|
| 708 | - * @return bool |
|
| 709 | - */ |
|
| 710 | - public function &getElementById($keyname) |
|
| 711 | - { |
|
| 712 | - foreach ($this->_elements as $eleObj) { |
|
| 713 | - if ($eleObj->getName() == $keyname) { |
|
| 714 | - $ret =& $eleObj; |
|
| 715 | - break; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - return isset($ret) ? $ret : false; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 724 | - * |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function render() |
|
| 728 | - { |
|
| 729 | - $required = $this->getRequired(); |
|
| 730 | - $ret = " |
|
| 424 | + case 'user_multi': |
|
| 425 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 426 | + break; |
|
| 427 | + |
|
| 428 | + case 'password': |
|
| 429 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 430 | + break; |
|
| 431 | + |
|
| 432 | + case 'country': |
|
| 433 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 434 | + break; |
|
| 435 | + |
|
| 436 | + case 'urllink': |
|
| 437 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
|
| 438 | + |
|
| 439 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 440 | + break; |
|
| 441 | + |
|
| 442 | + case 'richfile': |
|
| 443 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
|
| 444 | + |
|
| 445 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 446 | + break; |
|
| 447 | + case 'section': |
|
| 448 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
|
| 449 | + |
|
| 450 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 451 | + break; |
|
| 452 | + |
|
| 453 | + default: |
|
| 454 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 455 | + if (!class_exists($classname)) { |
|
| 456 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 457 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
|
| 458 | + } else { |
|
| 459 | + // perhaps this is a control created by the module |
|
| 460 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 461 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 462 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 463 | + $classFileName = strtolower($classname) . '.php'; |
|
| 464 | + |
|
| 465 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 466 | + require_once $moduleFormElementsPath . $classFileName; |
|
| 467 | + } else { |
|
| 468 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 469 | + |
|
| 470 | + return new XoopsFormLabel(); //Empty object |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + return new $classname($this->targetObject, $key); |
|
| 476 | + break; |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @param $key |
|
| 482 | + * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
| 483 | + */ |
|
| 484 | + public function getTextArea($key) |
|
| 485 | + { |
|
| 486 | + $var = $this->targetObject->vars[$key]; |
|
| 487 | + |
|
| 488 | + // if no control has been created, let's create a default one |
|
| 489 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 490 | + $control = array( |
|
| 491 | + 'name' => 'textarea', |
|
| 492 | + 'itemHandler' => false, |
|
| 493 | + 'method' => false, |
|
| 494 | + 'module' => false, |
|
| 495 | + 'form_editor' => 'default' |
|
| 496 | + ); |
|
| 497 | + } else { |
|
| 498 | + $control = $this->targetObject->controls[$key]; |
|
| 499 | + } |
|
| 500 | + $xoops22 = smart_isXoops22(); |
|
| 501 | + |
|
| 502 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 503 | + /** |
|
| 504 | + * If the editor is 'default', retreive the default editor of this module |
|
| 505 | + */ |
|
| 506 | + if ($form_editor === 'default') { |
|
| 507 | + global $xoopsModuleConfig; |
|
| 508 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + $caption = $var['form_caption']; |
|
| 512 | + $name = $key; |
|
| 513 | + |
|
| 514 | + $value = $this->targetObject->getVar($key); |
|
| 515 | + |
|
| 516 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 517 | + |
|
| 518 | + $editor_configs = array(); |
|
| 519 | + $editor_configs['name'] = $name; |
|
| 520 | + $editor_configs['value'] = $value; |
|
| 521 | + if ($form_editor !== 'textarea') { |
|
| 522 | + $editor_configs['rows'] = 35; |
|
| 523 | + $editor_configs['cols'] = 60; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + if (isset($control['rows'])) { |
|
| 527 | + $editor_configs['rows'] = $control['rows']; |
|
| 528 | + } |
|
| 529 | + if (isset($control['cols'])) { |
|
| 530 | + $editor_configs['cols'] = $control['cols']; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $editor_configs['width'] = '100%'; |
|
| 534 | + $editor_configs['height'] = '400px'; |
|
| 535 | + |
|
| 536 | + $dhtml = true; |
|
| 537 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 538 | + |
|
| 539 | + if (file_exists($xoopseditorclass)) { |
|
| 540 | + require_once $xoopseditorclass; |
|
| 541 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 542 | + } else { |
|
| 543 | + switch ($form_editor) { |
|
| 544 | + |
|
| 545 | + case 'tiny': |
|
| 546 | + if (!$xoops22) { |
|
| 547 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 548 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 549 | + $editor = new XoopsFormTinyTextArea(array( |
|
| 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(array( |
|
| 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(array( |
|
| 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 = array(); |
|
| 691 | + while (false !== ($file = readdir($handle))) { |
|
| 692 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) |
|
| 693 | + && strtolower($file) !== 'cvs') { |
|
| 694 | + $dirlist[$file] = $file; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + closedir($handle); |
|
| 698 | + if (!empty($dirlist)) { |
|
| 699 | + asort($dirlist); |
|
| 700 | + $theme_select->addOptionArray($dirlist); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + return $theme_select; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @param $keyname |
|
| 708 | + * @return bool |
|
| 709 | + */ |
|
| 710 | + public function &getElementById($keyname) |
|
| 711 | + { |
|
| 712 | + foreach ($this->_elements as $eleObj) { |
|
| 713 | + if ($eleObj->getName() == $keyname) { |
|
| 714 | + $ret =& $eleObj; |
|
| 715 | + break; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + return isset($ret) ? $ret : false; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 724 | + * |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function render() |
|
| 728 | + { |
|
| 729 | + $required = $this->getRequired(); |
|
| 730 | + $ret = " |
|
| 731 | 731 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
| 732 | 732 | <table width='100%' class='outer' cellspacing='1'> |
| 733 | 733 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
| 734 | 734 | '; |
| 735 | - $hidden = ''; |
|
| 736 | - $class = 'even'; |
|
| 737 | - foreach ($this->getElements() as $ele) { |
|
| 738 | - if (!is_object($ele)) { |
|
| 739 | - $ret .= $ele; |
|
| 740 | - } elseif (!$ele->isHidden()) { |
|
| 741 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 742 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 743 | - if ($ele->getDescription() !== '') { |
|
| 744 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 745 | - } |
|
| 746 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 747 | - } else { |
|
| 748 | - $hidden .= $ele->render(); |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 752 | - $ret .= $this->renderValidationJS(true); |
|
| 753 | - |
|
| 754 | - return $ret; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * assign to smarty form template instead of displaying directly |
|
| 759 | - * |
|
| 760 | - * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 761 | - * @param bool $smartyName |
|
| 762 | - * @see Smarty |
|
| 763 | - */ |
|
| 764 | - public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 765 | - { |
|
| 766 | - $i = 0; |
|
| 767 | - $elements = array(); |
|
| 768 | - foreach ($this->getElements() as $ele) { |
|
| 769 | - $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 770 | - $elements[$n]['name'] = $ele->getName(); |
|
| 771 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 772 | - $elements[$n]['body'] = $ele->render(); |
|
| 773 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 774 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 775 | - $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 776 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 777 | - if ($ele->getDescription() !== '') { |
|
| 778 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 779 | - } |
|
| 780 | - ++$i; |
|
| 781 | - } |
|
| 782 | - $js = $this->renderValidationJS(); |
|
| 783 | - if (!$smartyName) { |
|
| 784 | - $smartyName = $this->getName(); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - $tpl->assign($smartyName, array( |
|
| 788 | - 'title' => $this->getTitle(), |
|
| 789 | - 'name' => $this->getName(), |
|
| 790 | - 'action' => $this->getAction(), |
|
| 791 | - 'method' => $this->getMethod(), |
|
| 792 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 793 | - 'javascript' => $js, |
|
| 794 | - 'elements' => $elements |
|
| 795 | - )); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * @param bool $withtags |
|
| 800 | - * @return string |
|
| 801 | - */ |
|
| 802 | - public function renderValidationJS($withtags = true) |
|
| 803 | - { |
|
| 804 | - $js = ''; |
|
| 805 | - if ($withtags) { |
|
| 806 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 807 | - } |
|
| 808 | - $myts = MyTextSanitizer::getInstance(); |
|
| 809 | - $formname = $this->getName(); |
|
| 810 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 811 | - // First, output code to check required elements |
|
| 812 | - $elements = $this->getRequired(); |
|
| 813 | - foreach ($elements as $elt) { |
|
| 814 | - $eltname = $elt->getName(); |
|
| 815 | - $eltcaption = trim($elt->getCaption()); |
|
| 816 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 817 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 818 | - if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 819 | - $js .= 'var myOption = -1;'; |
|
| 820 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 735 | + $hidden = ''; |
|
| 736 | + $class = 'even'; |
|
| 737 | + foreach ($this->getElements() as $ele) { |
|
| 738 | + if (!is_object($ele)) { |
|
| 739 | + $ret .= $ele; |
|
| 740 | + } elseif (!$ele->isHidden()) { |
|
| 741 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 742 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 743 | + if ($ele->getDescription() !== '') { |
|
| 744 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 745 | + } |
|
| 746 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 747 | + } else { |
|
| 748 | + $hidden .= $ele->render(); |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 752 | + $ret .= $this->renderValidationJS(true); |
|
| 753 | + |
|
| 754 | + return $ret; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * assign to smarty form template instead of displaying directly |
|
| 759 | + * |
|
| 760 | + * @param XoopsTpl &$tpl reference to a {@link Smarty} object |
|
| 761 | + * @param bool $smartyName |
|
| 762 | + * @see Smarty |
|
| 763 | + */ |
|
| 764 | + public function assign(XoopsTpl $tpl, $smartyName = false) |
|
| 765 | + { |
|
| 766 | + $i = 0; |
|
| 767 | + $elements = array(); |
|
| 768 | + foreach ($this->getElements() as $ele) { |
|
| 769 | + $n = ($ele->getName() !== '') ? $ele->getName() : $i; |
|
| 770 | + $elements[$n]['name'] = $ele->getName(); |
|
| 771 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 772 | + $elements[$n]['body'] = $ele->render(); |
|
| 773 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 774 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 775 | + $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
| 776 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 777 | + if ($ele->getDescription() !== '') { |
|
| 778 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 779 | + } |
|
| 780 | + ++$i; |
|
| 781 | + } |
|
| 782 | + $js = $this->renderValidationJS(); |
|
| 783 | + if (!$smartyName) { |
|
| 784 | + $smartyName = $this->getName(); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + $tpl->assign($smartyName, array( |
|
| 788 | + 'title' => $this->getTitle(), |
|
| 789 | + 'name' => $this->getName(), |
|
| 790 | + 'action' => $this->getAction(), |
|
| 791 | + 'method' => $this->getMethod(), |
|
| 792 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 793 | + 'javascript' => $js, |
|
| 794 | + 'elements' => $elements |
|
| 795 | + )); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * @param bool $withtags |
|
| 800 | + * @return string |
|
| 801 | + */ |
|
| 802 | + public function renderValidationJS($withtags = true) |
|
| 803 | + { |
|
| 804 | + $js = ''; |
|
| 805 | + if ($withtags) { |
|
| 806 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 807 | + } |
|
| 808 | + $myts = MyTextSanitizer::getInstance(); |
|
| 809 | + $formname = $this->getName(); |
|
| 810 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 811 | + // First, output code to check required elements |
|
| 812 | + $elements = $this->getRequired(); |
|
| 813 | + foreach ($elements as $elt) { |
|
| 814 | + $eltname = $elt->getName(); |
|
| 815 | + $eltcaption = trim($elt->getCaption()); |
|
| 816 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 817 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 818 | + if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
| 819 | + $js .= 'var myOption = -1;'; |
|
| 820 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 821 | 821 | if (myform.{$eltname}[i].checked) { |
| 822 | 822 | myOption = i; i = -1; |
| 823 | 823 | } |
| 824 | 824 | } |
| 825 | 825 | if (myOption == -1) { |
| 826 | 826 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 827 | - } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 828 | - $js .= 'var hasSelections = false;'; |
|
| 829 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 827 | + } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
| 828 | + $js .= 'var hasSelections = false;'; |
|
| 829 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 830 | 830 | if (myform['{$eltname}[]'].options[i].selected) { |
| 831 | 831 | hasSelections = true; |
| 832 | 832 | } |
@@ -834,12 +834,12 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | if (hasSelections === false) { |
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 837 | - } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
| 838 | - || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 839 | - $js .= 'var hasSelections = false;'; |
|
| 840 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 841 | - if (strpos($eltname, '[') === false) { |
|
| 842 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 837 | + } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' |
|
| 838 | + || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
| 839 | + $js .= 'var hasSelections = false;'; |
|
| 840 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 841 | + if (strpos($eltname, '[') === false) { |
|
| 842 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 843 | 843 | if (myform['{$eltname}[]'][i].checked) { |
| 844 | 844 | hasSelections = true; |
| 845 | 845 | } |
@@ -847,8 +847,8 @@ discard block |
||
| 847 | 847 | } |
| 848 | 848 | if (hasSelections === false) { |
| 849 | 849 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 850 | - } else { |
|
| 851 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 850 | + } else { |
|
| 851 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 852 | 852 | if (myform['{$eltname}'][i].checked) { |
| 853 | 853 | hasSelections = true; |
| 854 | 854 | } |
@@ -856,25 +856,25 @@ discard block |
||
| 856 | 856 | } |
| 857 | 857 | if (hasSelections === false) { |
| 858 | 858 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 859 | - } |
|
| 860 | - } else { |
|
| 861 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - // Now, handle custom validation code |
|
| 865 | - $elements =& $this->getElements(true); |
|
| 866 | - foreach ($elements as $elt) { |
|
| 867 | - if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 868 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 869 | - $js .= $eltjs . "\n"; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - $js .= "return true;\n}\n"; |
|
| 874 | - if ($withtags) { |
|
| 875 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return $js; |
|
| 879 | - } |
|
| 859 | + } |
|
| 860 | + } else { |
|
| 861 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + // Now, handle custom validation code |
|
| 865 | + $elements =& $this->getElements(true); |
|
| 866 | + foreach ($elements as $elt) { |
|
| 867 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
| 868 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 869 | + $js .= $eltjs . "\n"; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + $js .= "return true;\n}\n"; |
|
| 874 | + if ($withtags) { |
|
| 875 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return $js; |
|
| 879 | + } |
|
| 880 | 880 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class SmartFormImageUploadElement extends SmartFormUploadElement |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * SmartFormImageUploadElement constructor. |
|
| 21 | - * @param string $object |
|
| 22 | - * @param string $key |
|
| 23 | - */ |
|
| 24 | - public function __construct($object, $key) |
|
| 25 | - { |
|
| 26 | - $this->SmartFormFileElement($object, $key); |
|
| 27 | - // Override name for upload purposes |
|
| 28 | - $this->setName('upload_' . $key); |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * SmartFormImageUploadElement constructor. |
|
| 21 | + * @param string $object |
|
| 22 | + * @param string $key |
|
| 23 | + */ |
|
| 24 | + public function __construct($object, $key) |
|
| 25 | + { |
|
| 26 | + $this->SmartFormFileElement($object, $key); |
|
| 27 | + // Override name for upload purposes |
|
| 28 | + $this->setName('upload_' . $key); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * prepare HTML for output |
|
| 33 | - * |
|
| 34 | - * @return string HTML |
|
| 35 | - */ |
|
| 36 | - public function render() |
|
| 37 | - { |
|
| 38 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 31 | + /** |
|
| 32 | + * prepare HTML for output |
|
| 33 | + * |
|
| 34 | + * @return string HTML |
|
| 35 | + */ |
|
| 36 | + public function render() |
|
| 37 | + { |
|
| 38 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 39 | 39 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
| 40 | 40 | <input type='hidden' name='smart_upload_image[]' id='smart_upload_image[]' value='" . $this->getName() . "'>"; |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class SmartFormFileUploadElement extends SmartFormUploadElement |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * SmartFormFileUploadElement constructor. |
|
| 21 | - * @param string $object |
|
| 22 | - * @param string $key |
|
| 23 | - */ |
|
| 24 | - public function __construct($object, $key) |
|
| 25 | - { |
|
| 26 | - $this->SmartFormFileElement($object, $key); |
|
| 27 | - // Override name for upload purposes |
|
| 28 | - $this->setName('upload_' . $key); |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * SmartFormFileUploadElement constructor. |
|
| 21 | + * @param string $object |
|
| 22 | + * @param string $key |
|
| 23 | + */ |
|
| 24 | + public function __construct($object, $key) |
|
| 25 | + { |
|
| 26 | + $this->SmartFormFileElement($object, $key); |
|
| 27 | + // Override name for upload purposes |
|
| 28 | + $this->setName('upload_' . $key); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * prepare HTML for output |
|
| 33 | - * |
|
| 34 | - * @return string HTML |
|
| 35 | - */ |
|
| 36 | - public function render() |
|
| 37 | - { |
|
| 38 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 31 | + /** |
|
| 32 | + * prepare HTML for output |
|
| 33 | + * |
|
| 34 | + * @return string HTML |
|
| 35 | + */ |
|
| 36 | + public function render() |
|
| 37 | + { |
|
| 38 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
| 39 | 39 | <input type='file' name='upload_" . $this->getName() . "' id='upload_" . $this->getName() . "'" . $this->getExtra() . "> |
| 40 | 40 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -11,38 +11,38 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class SmartAutocompleteElement extends XoopsFormText |
| 13 | 13 | { |
| 14 | - public $_include_file; |
|
| 14 | + public $_include_file; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * SmartAutocompleteElement constructor. |
|
| 18 | - * @param string $caption |
|
| 19 | - * @param string $name |
|
| 20 | - * @param int $include_file |
|
| 21 | - * @param int $size |
|
| 22 | - * @param string $maxlength |
|
| 23 | - * @param string $value |
|
| 24 | - */ |
|
| 25 | - public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '') |
|
| 26 | - { |
|
| 27 | - $this->_include_file = $include_file; |
|
| 28 | - parent::__construct($caption, $name, $size, $maxlength, $value); |
|
| 29 | - } |
|
| 16 | + /** |
|
| 17 | + * SmartAutocompleteElement constructor. |
|
| 18 | + * @param string $caption |
|
| 19 | + * @param string $name |
|
| 20 | + * @param int $include_file |
|
| 21 | + * @param int $size |
|
| 22 | + * @param string $maxlength |
|
| 23 | + * @param string $value |
|
| 24 | + */ |
|
| 25 | + public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '') |
|
| 26 | + { |
|
| 27 | + $this->_include_file = $include_file; |
|
| 28 | + parent::__construct($caption, $name, $size, $maxlength, $value); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Prepare HTML for output |
|
| 33 | - * |
|
| 34 | - * @return string HTML |
|
| 35 | - */ |
|
| 36 | - public function render() |
|
| 37 | - { |
|
| 38 | - $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>'; |
|
| 31 | + /** |
|
| 32 | + * Prepare HTML for output |
|
| 33 | + * |
|
| 34 | + * @return string HTML |
|
| 35 | + */ |
|
| 36 | + public function render() |
|
| 37 | + { |
|
| 38 | + $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>'; |
|
| 39 | 39 | |
| 40 | - $ret .= ' <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div> |
|
| 40 | + $ret .= ' <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div> |
|
| 41 | 41 | |
| 42 | 42 | <script type="text/javascript"> |
| 43 | 43 | new Ajax.Autocompleter("' . $this->getName() . '","smartobject_autocomplete_hint' . $this->getName() . '","' . $this->_include_file . '?key=' . $this->getName() . '"); |
| 44 | 44 | </script>'; |
| 45 | 45 | |
| 46 | - return $ret; |
|
| 47 | - } |
|
| 46 | + return $ret; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -13,50 +13,50 @@ |
||
| 13 | 13 | |
| 14 | 14 | class SmartFormSet_passwordElement extends XoopsFormElementTray |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Size of the field. |
|
| 18 | - * @var int |
|
| 19 | - * @access private |
|
| 20 | - */ |
|
| 21 | - public $_size; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Maximum length of the text |
|
| 25 | - * @var int |
|
| 26 | - * @access private |
|
| 27 | - */ |
|
| 28 | - public $_maxlength; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Initial content of the field. |
|
| 32 | - * @var string |
|
| 33 | - * @access private |
|
| 34 | - */ |
|
| 35 | - public $_value; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Constructor |
|
| 39 | - * |
|
| 40 | - * @param string $object |
|
| 41 | - * @param string $key |
|
| 42 | - * @internal param string $caption Caption |
|
| 43 | - * @internal param string $name "name" attribute |
|
| 44 | - * @internal param int $size Size of the field |
|
| 45 | - * @internal param int $maxlength Maximum length of the text |
|
| 46 | - * @internal param int $value Initial value of the field. |
|
| 47 | - * <b>Warning:</b> this is readable in cleartext in the page's source! |
|
| 48 | - */ |
|
| 49 | - public function __construct($object, $key) |
|
| 50 | - { |
|
| 51 | - $var = $object->vars[$key]; |
|
| 52 | - $control = $object->controls[$key]; |
|
| 53 | - |
|
| 54 | - parent::__construct($var['form_caption'] . '<br>' . _US_TYPEPASSTWICE, ' ', $key . '_password_tray'); |
|
| 55 | - |
|
| 56 | - $password_box1 = new XoopsFormPassword('', $key . '1', 10, 32); |
|
| 57 | - $this->addElement($password_box1); |
|
| 58 | - |
|
| 59 | - $password_box2 = new XoopsFormPassword('', $key . '2', 10, 32); |
|
| 60 | - $this->addElement($password_box2); |
|
| 61 | - } |
|
| 16 | + /** |
|
| 17 | + * Size of the field. |
|
| 18 | + * @var int |
|
| 19 | + * @access private |
|
| 20 | + */ |
|
| 21 | + public $_size; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Maximum length of the text |
|
| 25 | + * @var int |
|
| 26 | + * @access private |
|
| 27 | + */ |
|
| 28 | + public $_maxlength; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Initial content of the field. |
|
| 32 | + * @var string |
|
| 33 | + * @access private |
|
| 34 | + */ |
|
| 35 | + public $_value; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Constructor |
|
| 39 | + * |
|
| 40 | + * @param string $object |
|
| 41 | + * @param string $key |
|
| 42 | + * @internal param string $caption Caption |
|
| 43 | + * @internal param string $name "name" attribute |
|
| 44 | + * @internal param int $size Size of the field |
|
| 45 | + * @internal param int $maxlength Maximum length of the text |
|
| 46 | + * @internal param int $value Initial value of the field. |
|
| 47 | + * <b>Warning:</b> this is readable in cleartext in the page's source! |
|
| 48 | + */ |
|
| 49 | + public function __construct($object, $key) |
|
| 50 | + { |
|
| 51 | + $var = $object->vars[$key]; |
|
| 52 | + $control = $object->controls[$key]; |
|
| 53 | + |
|
| 54 | + parent::__construct($var['form_caption'] . '<br>' . _US_TYPEPASSTWICE, ' ', $key . '_password_tray'); |
|
| 55 | + |
|
| 56 | + $password_box1 = new XoopsFormPassword('', $key . '1', 10, 32); |
|
| 57 | + $this->addElement($password_box1); |
|
| 58 | + |
|
| 59 | + $password_box2 = new XoopsFormPassword('', $key . '2', 10, 32); |
|
| 60 | + $this->addElement($password_box2); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -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 | } |