ClassFormElements   F
last analyzed

Complexity

Total Complexity 82

Size/Duplication

Total Lines 1017
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
eloc 520
c 2
b 2
f 0
dl 0
loc 1017
rs 2
wmc 82

31 Methods

Rating   Name   Duplication   Size   Complexity  
A getXoopsFormUploadImage() 0 43 1
A getXoopsFormUrlFile() 0 16 1
A getXoopsFormUploadFile() 0 27 1
A getXoopsFormColorPicker() 0 10 1
A getXoopsFormSelectBox() 0 14 1
A getXoopsFormSelectFile() 0 38 1
A getInstance() 0 8 2
A getXoopsFormSelectCountry() 0 12 1
A getXoopsFormText() 0 15 2
A getXoopsFormHidden() 0 8 1
A getXoopsFormDateTime() 0 10 1
A initForm() 0 4 1
A getXoopsFormTextUuid() 0 10 1
A __construct() 0 9 1
A getXoopsFormSelectStatus() 0 21 3
A getXoopsFormRadio() 0 15 1
A getXoopsFormTag() 0 14 1
A getXoopsFormPassword() 0 9 1
A getXoopsFormSelectCombo() 0 17 1
A getXoopsFormRadioYN() 0 10 1
A getXoopsFormTextArea() 0 8 1
A getXoopsFormCheckBox() 0 26 2
F renderElements() 0 157 46
A getXoopsFormImageList() 0 34 1
A getXoopsFormTopic() 0 20 1
A getXoopsFormSelectLang() 0 12 1
A getXoopsFormTable() 0 14 1
A getXoopsFormTextIp() 0 10 1
A getXoopsFormDhtmlTextArea() 0 28 2
A getXoopsFormSelectUser() 0 10 1
A getXoopsFormTextDateSelect() 0 10 1

How to fix   Complexity   

Complex Class

Complex classes like ClassFormElements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ClassFormElements, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\Classes;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\Constants;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tc module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops https://xoops.org 
26
 *                  Goffy https://myxoops.org
27
 *
28
 */
29
30
/**
31
 * Class ClassFormElements.
32
 */
33
class ClassFormElements extends Modulebuilder\Files\CreateAbstractClass
34
{
35
    /**
36
     * @var mixed
37
     */
38
    private $cf = null;
39
40
    /**
41
     * @var mixed
42
     */
43
    private $tf = null;
44
45
    /**
46
     * @var mixed
47
     */
48
    private $uxc = null;
49
50
    /**
51
     * @var mixed
52
     */
53
    private $cxc = null;
54
55
    /**
56
     * @var mixed
57
     */
58
    private $xc = null;
59
60
    /**
61
     * @var mixed
62
     */
63
    private $pc = null;
64
65
    /**
66
     * @var mixed
67
     */
68
    private $helper = null;
69
70
71
    /**
72
     * @public function constructor
73
     * @param null
74
     */
75
    public function __construct()
76
    {
77
        $this->helper = Modulebuilder\Helper::getInstance();
78
        $this->cf     = Modulebuilder\Files\CreateFile::getInstance();
79
        $this->xc     = Modulebuilder\Files\CreateXoopsCode::getInstance();
80
        $this->pc     = Modulebuilder\Files\CreatePhpCode::getInstance();
81
        $this->tf     = Modulebuilder\Files\CreateTableFields::getInstance();
82
        $this->uxc    = Modulebuilder\Files\User\UserXoopsCode::getInstance();
83
        $this->cxc    = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance();
84
    }
85
86
    /**
87
     * @static function getInstance
88
     * @param null
89
     *
90
     * @return ClassFormElements
91
     */
92
    public static function getInstance()
93
    {
94
        static $instance = false;
95
        if (!$instance) {
96
            $instance = new self();
97
        }
98
99
        return $instance;
100
    }
101
102
    /**
103
     * @public function initForm
104
     *
105
     * @param $module
106
     * @param $table
107
     */
108
    public function initForm($module, $table)
109
    {
110
        $this->setModule($module);
111
        $this->setTable($table);
112
    }
113
114
    /**
115
     * @private function getXoopsFormText
116
     *
117
     * @param        $language
118
     * @param        $fieldName
119
     * @param        $fieldDefault
120
     * @param string $required
121
     * @return string
122
     */
123
    private function getXoopsFormText($language, $fieldName, $fieldDefault, $required = 'false')
124
    {
125
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
126
        if ('' != $fieldDefault) {
127
            $ret      = $this->pc->getPhpCodeCommentLine('Form Text', $ccFieldName, "\t\t");
128
            $ret      .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', "'{$fieldDefault}'", "\$this->getVar('{$fieldName}')", "\t\t");
129
            $formText = $this->cxc->getClassXoopsFormText('', $language, $fieldName, 20, 150, $ccFieldName, true);
130
            $ret      .= $this->cxc->getClassAddElement('form', $formText . $required);
131
        } else {
132
            $ret      = $this->pc->getPhpCodeCommentLine('Form Text', $ccFieldName, "\t\t");
133
            $formText = $this->cxc->getClassXoopsFormText('', $language, $fieldName, 50, 255, "this->getVar('{$fieldName}')", true);
134
            $ret      .= $this->cxc->getClassAddElement('form', $formText . $required);
135
        }
136
137
        return $ret;
138
    }
139
140
    /**
141
     * @private function getXoopsFormText
142
     *
143
     * @param $language
144
     * @param $fieldName
145
     * @param $required
146
     *
147
     * @return string
148
     */
149
    private function getXoopsFormTextArea($language, $fieldName, $required = 'false')
150
    {
151
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
152
        $ret          = $this->pc->getPhpCodeCommentLine('Form Editor', 'TextArea ' . $ccFieldName, "\t\t");
153
        $formTextArea = $this->cxc->getClassXoopsFormTextArea('', $language, $fieldName, 4, 47, true);
154
        $ret          .= $this->cxc->getClassAddElement('form', $formTextArea . $required);
155
156
        return $ret;
157
    }
158
159
    /**
160
     * @private function getXoopsFormDhtmlTextArea
161
     *
162
     * @param $language
163
     * @param $fieldName
164
     * @param $required
165
     *
166
     * @return string
167
     */
168
    private function getXoopsFormDhtmlTextArea($language, $fieldName, $required = 'false')
169
    {
170
        $ccFieldName = $this->cf->getCamelCase($fieldName, false, true);
171
        $ret         = $this->pc->getPhpCodeCommentLine('Form Editor', 'DhtmlTextArea ' . $ccFieldName, "\t\t");
172
        $ret         .= $this->pc->getPhpCodeArray('editorConfigs', null, false, "\t\t");
173
        $getConfig    = $this->xc->getXcGetConfig('editor_admin');
174
        $contIf       = $this->xc->getXcEqualsOperator("\$editor", $getConfig, null, "\t\t\t");
175
        $getConfig    = $this->xc->getXcGetConfig('editor_user');
176
        $contElse     = $this->xc->getXcEqualsOperator("\$editor", $getConfig, null, "\t\t\t");
177
        $ret      .= $this->pc->getPhpCodeConditions('$isAdmin','','', $contIf,  $contElse, "\t\t");
178
179
180
        $configs     = [
181
            'name'   => "'{$fieldName}'",
182
            'value'  => "\$this->getVar('{$fieldName}', 'e')",
183
            'rows'   => 5,
184
            'cols'   => 40,
185
            'width'  => "'100%'",
186
            'height' => "'400px'",
187
            'editor' => '$editor',
188
        ];
189
        foreach ($configs as $c => $d) {
190
            $ret .= $this->xc->getXcEqualsOperator("\$editorConfigs['{$c}']", $d, null, "\t\t");
191
        }
192
        $formEditor = $this->cxc->getClassXoopsFormEditor('', $language, $fieldName, 'editorConfigs', true);
193
        $ret        .= $this->cxc->getClassAddElement('form', $formEditor . $required);
194
195
        return $ret;
196
    }
197
198
    /**
199
     * @private function getXoopsFormCheckBox
200
     *
201
     * @param        $language
202
     * @param        $tableSoleName
203
     * @param        $fieldName
204
     * @param        $fieldElementId
205
     * @param string $required
206
     * @return string
207
     */
208
    private function getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required = 'false')
209
    {
210
        $stuTableSoleName = \mb_strtoupper($tableSoleName);
211
        $ucfFieldName     = $this->cf->getCamelCase($fieldName, true);
212
        $ccFieldName      = $this->cf->getCamelCase($fieldName, false, true);
213
        $t                = "\t\t";
214
        if (\in_array(5, $fieldElementId) > 1) {
215
            $ret     = $this->pc->getPhpCodeCommentLine('Form Check Box', 'List Options ' . $ccFieldName, $t);
216
            $ret     .= $this->xc->getXcEqualsOperator('$checkOption', '$this->getOptions()');
217
            $foreach = $this->cxc->getClassXoopsFormCheckBox('check' . $ucfFieldName, '<hr />', $tableSoleName . '_option', '$checkOption', false, $t . "\t");
218
            $foreach .= $this->cxc->getClassSetDescription('check' . $ucfFieldName, "{$language}{$stuTableSoleName}_OPTIONS_DESC", $t . "\t");
219
            $foreach .= $this->cxc->getClassAddOption('check' . $ucfFieldName, "\$option, {$language}{$stuTableSoleName}_ . strtoupper(\$option)", $t . "\t");
220
            $ret     .= $this->pc->getPhpCodeForeach("{$tableSoleName}All", false, false, 'option', $foreach, $t);
221
            $intElem = "\$check{$ucfFieldName}{$required}";
222
            $ret     .= $this->cxc->getClassAddElement('form', $intElem, $t);
223
        } else {
224
            $ret     = $this->pc->getPhpCodeCommentLine('Form Check Box', $ccFieldName, $t);
225
            $ret     .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', 0, "\$this->getVar('{$fieldName}')", $t);
226
            $ret     .= $this->cxc->getClassXoopsFormCheckBox('check' . $ucfFieldName, $language, $fieldName, "\${$ccFieldName}", false, $t);
227
            $option  = "1, {$language}";
228
            $ret     .= $this->cxc->getClassAddOption('check' . $ucfFieldName, $option, $t);
229
            $intElem = "\$check{$ucfFieldName}{$required}";
230
            $ret     .= $this->cxc->getClassAddElement('form', $intElem, $t);
231
        }
232
233
        return $ret;
234
    }
235
236
    /**
237
     * @private function getXoopsFormHidden
238
     *
239
     * @param $fieldName
240
     *
241
     * @return string
242
     */
243
    private function getXoopsFormHidden($fieldName)
244
    {
245
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
246
        $ret          = $this->pc->getPhpCodeCommentLine('Form Hidden', $ccFieldName, "\t\t");
247
        $formHidden   = $this->cxc->getClassXoopsFormHidden('', $fieldName, $fieldName, true, true);
248
        $ret          .= $this->cxc->getClassAddElement('form', $formHidden);
249
250
        return $ret;
251
    }
252
253
    /**
254
     * @private function getXoopsFormImageList
255
     *          provides listbox for select image, a preview of image and an upload field
256
     *
257
     * @param $language
258
     * @param $moduleDirname
259
     * @param $fieldName
260
     * @param $required
261
     *
262
     * @return string
263
     */
264
    private function getXoopsFormImageList($language, $moduleDirname, $fieldName, $required = 'false')
265
    {
266
        $ucfFieldName    = $this->cf->getCamelCase($fieldName, true);
267
        $ccFieldName     = $this->cf->getCamelCase($fieldName, false, true);
268
        $languageShort   = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
269
        $t               = "\t\t";
270
        $ret             = $this->pc->getPhpCodeCommentLine('Form Frameworks Images', 'Files ' . $ccFieldName, $t);
271
        $ret             .= $this->pc->getPhpCodeCommentLine('Form Frameworks Images', $ccFieldName .': Select Uploaded Image', $t);
272
        $ret             .= $this->xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, $t);
273
        $ret             .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '', "'blank.gif'", $t);
274
        $ret             .= $this->xc->getXcEqualsOperator('$imageDirectory', "'/Frameworks/moduleclasses/icons/32'", null, $t);
275
        $ret             .= $this->cxc->getClassXoopsFormElementTray('imageTray', $language, '<br>', $t);
276
        $sprintf         = $this->pc->getPhpCodeSprintf($language . '_UPLOADS', '".{$imageDirectory}/"');
277
        $ret             .= $this->cxc->getClassXoopsFormSelect('imageSelect', $sprintf, $fieldName, $ccFieldName, 5, 'false', false, $t);
278
        $ret             .= $this->xc->getXcXoopsListImgListArray('imageArray', '\XOOPS_ROOT_PATH . $imageDirectory', $t);
279
        $contForeach     = $this->cxc->getClassAddOption('imageSelect', '($image1), $image1', $t . "\t");
280
        $ret             .= $this->pc->getPhpCodeForeach('imageArray', false, false, 'image1', $contForeach, $t);
281
        $setExtraParam   = "\"onchange='showImgSelected(\\\"imglabel_{$fieldName}\\\", \\\"{$fieldName}\\\", \\\"\" . \$imageDirectory . '\", \"\", \"' . \XOOPS_URL . \"\\\")'\"";
282
        $ret             .= $this->cxc->getClassSetExtra('imageSelect', $setExtraParam, $t);
283
        $ret             .= $this->cxc->getClassAddElement('imageTray', '$imageSelect, false', $t);
284
        $paramLabel      = "\"<br><img src='\" . \XOOPS_URL . '/' . \$imageDirectory . '/' . \${$ccFieldName} . \"' id='imglabel_{$fieldName}' alt='' style='max-width:100px' >\"";
285
        $xoopsFormLabel  = $this->cxc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
286
        $ret             .= $this->cxc->getClassAddElement('imageTray', $xoopsFormLabel, $t);
287
        $ret             .= $this->pc->getPhpCodeCommentLine('Form Frameworks Images', $ccFieldName .': Upload new image', $t);
288
        $ret             .= $this->cxc->getClassXoopsFormElementTray('fileSelectTray', "''", '<br>', $t);
289
        $getConfig       = $this->xc->getXcGetConfig('maxsize_image');
290
        $xoopsFormFile   = $this->cxc->getClassXoopsFormFile('', $languageShort . 'FORM_UPLOAD_NEW', $fieldName, $getConfig, true, '');
291
        $ret             .= $this->cxc->getClassAddElement('fileSelectTray', $xoopsFormFile, $t);
292
        $xoopsFormLabel1 = $this->cxc->getClassXoopsFormLabel('', "''", null, true, $t);
293
        $ret             .= $this->cxc->getClassAddElement('fileSelectTray', $xoopsFormLabel1, $t);
294
        $ret             .= $this->cxc->getClassAddElement('imageTray', '$fileSelectTray', $t);
295
        $ret             .= $this->cxc->getClassAddElement('form', "\$imageTray{$required}", $t);
296
297
        return $ret;
298
    }
299
300
    /**
301
     * @private function getXoopsFormSelectFile
302
     *          provides listbox for select file and an upload field
303
     *
304
     * @param $language
305
     * @param $moduleDirname
306
     * @param $tableName
307
     * @param $fieldName
308
     * @param $required
309
     *
310
     * @return string
311
     */
312
    private function getXoopsFormSelectFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
313
    {
314
        $ucfFieldName    = $this->cf->getCamelCase($fieldName, true);
315
        $ccFieldName     = $this->cf->getCamelCase($fieldName, false, true);
316
        $languageShort   = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
317
        $t               = "\t\t";
318
        $ret             = $this->pc->getPhpCodeCommentLine('Form File', $ccFieldName, $t);
319
        $ret             .= $this->pc->getPhpCodeCommentLine("Form File {$ccFieldName}:", 'Select Uploaded File ', $t);
320
        $ret             .= $this->xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, $t);
321
        $ret             .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '', "'blank.gif'", $t);
322
        $ret             .= $this->xc->getXcEqualsOperator('$fileDirectory', "'/uploads/{$moduleDirname}/files/{$tableName}'", null, $t);
323
        $ret             .= $this->cxc->getClassXoopsFormElementTray('fileTray', $language, '<br>', $t);
324
        $sprintf         = $this->pc->getPhpCodeSprintf($language . '_UPLOADS', '".{$fileDirectory}/"');
325
        $ret             .= $this->cxc->getClassXoopsFormSelect('fileSelect', $sprintf, $fieldName, $ccFieldName, 5, 'false', false, $t);
326
        $ret             .= $this->xc->getXcXoopsListImgListArray('fileArray', '\XOOPS_ROOT_PATH . $fileDirectory', $t);
327
        $contForeach     = $this->cxc->getClassAddOption('fileSelect', '($file1), $file1', $t . "\t");
328
        $ret             .= $this->pc->getPhpCodeForeach('fileArray', false, false, 'file1', $contForeach, $t);
329
        //TODO: make preview for images or show "no preview possible"
330
        //$setExtraParam   = "\"onchange='showImgSelected(\\\"imglabel_{$fieldName}\\\", \\\"{$fieldName}\\\", \\\"\" . \$imageDirectory . '\", \"\", \"' . \XOOPS_URL . \"\\\")'\"";
331
        //$ret             .= $cc->getClassSetExtra('fileSelect', $setExtraParam, $t);
332
        $ret             .= $this->cxc->getClassAddElement('fileTray', '$fileSelect, false', $t);
333
        //$paramLabel      = "\"<br><img src='\" . \XOOPS_URL . '/' . \$imageDirectory . '/' . \${$ccFieldName} . \"' id='imglabel_{$fieldName}' alt='' style='max-width:100px' />\"";
334
        //$xoopsFormLabel  = $cc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
335
        //$ret             .= $cc->getClassAddElement('fileTray', $xoopsFormLabel, $t);
336
        $ret             .= $this->pc->getPhpCodeCommentLine("Form File {$ccFieldName}:", 'Upload new file', $t);
337
        $getConfigSize   = $this->xc->getXcGetConfig('maxsize_file');
338
        $contIf          = $this->xc->getXcEqualsOperator('$maxsize', $getConfigSize,'', "\t\t\t");
339
        $xoopsFormFile   = $this->cxc->getClassXoopsFormFile('fileTray', "'<br>' . " . $languageShort . 'FORM_UPLOAD_NEW', $fieldName, '$maxsize', true, '');
340
        $contIf          .= $this->cxc->getClassAddElement('fileTray', $xoopsFormFile, $t . "\t");
341
        $configText      = "(\$maxsize / 1048576) . ' '  . " . $languageShort . 'FORM_UPLOAD_SIZE_MB';
342
        $labelInfo1      = $this->cxc->getClassXoopsFormLabel('',  $languageShort . 'FORM_UPLOAD_SIZE', $configText, true, '');
343
        $contIf          .= $this->cxc->getClassAddElement('fileTray', $labelInfo1, $t . "\t");
344
        $formHidden      = $this->cxc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, $t, true);
345
        $contElse        = $this->cxc->getClassAddElement('fileTray', $formHidden, $t . "\t");
346
        $ret             .= $this->pc->getPhpCodeConditions('$permissionUpload', null, null, $contIf, $contElse, "\t\t");
347
        $ret             .= $this->cxc->getClassAddElement('form', "\$fileTray{$required}", $t);
348
349
        return $ret;
350
    }
351
352
    /**
353
     * @private function getXoopsFormUrlFile
354
     *          provides textbox with last uploaded url and an upload field
355
     *
356
     * @param   $language
357
     * @param   $moduleDirname
358
     * @param   $fieldName
359
     * @param   $fieldDefault
360
     * @param   $required
361
     *
362
     * @return string
363
     */
364
    private function getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $required = 'false')
365
    {
366
        $ccFieldName    = $this->cf->getCamelCase($fieldName, false, true);
367
        $languageShort = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
368
        $t             = "\t\t";
369
        $ret           = $this->pc->getPhpCodeCommentLine('Form Url', 'Text File ' . $ccFieldName, $t);
370
        $ret           .= $this->cxc->getClassXoopsFormElementTray('formUrlFile', $language, '<br>', $t);
371
        $ret           .= $this->pc->getPhpCodeTernaryOperator('formUrl', '$this->isNew()', "'{$fieldDefault}'", "\$this->getVar('{$fieldName}')", $t);
372
        $ret           .= $this->cxc->getClassXoopsFormText('formText', $language . '_UPLOADS', $fieldName, 75, 255, 'formUrl', false, $t);
373
        $ret           .= $this->cxc->getClassAddElement('formUrlFile', '$formText' . $required, $t);
374
        $getConfig     = $this->xc->getXcGetConfig('maxsize_file');
375
        $xoopsFormFile = $this->cxc->getClassXoopsFormFile('', $languageShort . 'FORM_UPLOAD', $fieldName, $getConfig, true, '');
376
        $ret           .= $this->cxc->getClassAddElement('formUrlFile', $xoopsFormFile . $required, $t);
377
        $ret           .= $this->cxc->getClassAddElement('form', '$formUrlFile', $t);
378
379
        return $ret;
380
    }
381
382
    /**
383
     * @private function getXoopsFormUploadImage
384
     *          provides listbox for select image, a preview of image and an upload field
385
     *
386
     * @param        $language
387
     * @param        $moduleDirname
388
     * @param        $tableName
389
     * @param        $fieldName
390
     * @param string $required
391
     * @return string
392
     */
393
    private function getXoopsFormUploadImage($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
394
    {
395
        $ucfFieldName    = $this->cf->getCamelCase($fieldName, true);
396
        $ccFieldName     = $this->cf->getCamelCase($fieldName, false, true);
397
        $languageShort   = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
398
        $t               = "\t\t";
399
        $ret             = $this->pc->getPhpCodeCommentLine('Form Image', $ccFieldName, $t);
400
        $ret             .= $this->pc->getPhpCodeCommentLine("Form Image {$ccFieldName}:", 'Select Uploaded Image ', $t);
401
        $ret             .= $this->xc->getXcEqualsOperator('$get' . $ucfFieldName, "\$this->getVar('{$fieldName}')", null, $t);
402
        $ret             .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$get' . $ucfFieldName, '', "'blank.gif'", $t);
403
        $ret             .= $this->xc->getXcEqualsOperator('$imageDirectory', "'/uploads/{$moduleDirname}/images/{$tableName}'", null, $t);
404
        $ret             .= $this->cxc->getClassXoopsFormElementTray('imageTray', $language, '<br>', $t);
405
        $sprintf         = $this->pc->getPhpCodeSprintf($language . '_UPLOADS', '".{$imageDirectory}/"');
406
        $ret             .= $this->cxc->getClassXoopsFormSelect('imageSelect', $sprintf, $fieldName, $ccFieldName, 5, 'false', false, $t);
407
        $ret             .= $this->xc->getXcXoopsListImgListArray('imageArray', '\XOOPS_ROOT_PATH . $imageDirectory', $t);
408
        $contForeach     = $this->cxc->getClassAddOption('imageSelect', '($image1), $image1', $t . "\t");
409
        $ret             .= $this->pc->getPhpCodeForeach('imageArray', false, false, 'image1', $contForeach, $t);
410
        $setExtraParam   = "\"onchange='showImgSelected(\\\"imglabel_{$fieldName}\\\", \\\"{$fieldName}\\\", \\\"\" . \$imageDirectory . '\", \"\", \"' . \XOOPS_URL . \"\\\")'\"";
411
        $ret             .= $this->cxc->getClassSetExtra('imageSelect', $setExtraParam, $t);
412
        $ret             .= $this->cxc->getClassAddElement('imageTray', '$imageSelect, false', $t);
413
        $paramLabel      = "\"<br><img src='\" . \XOOPS_URL . '/' . \$imageDirectory . '/' . \${$ccFieldName} . \"' id='imglabel_{$fieldName}' alt='' style='max-width:100px' >\"";
414
        $xoopsFormLabel  = $this->cxc->getClassXoopsFormLabel('', "''", $paramLabel, true, '');
415
        $ret             .= $this->cxc->getClassAddElement('imageTray', $xoopsFormLabel, $t);
416
        $ret             .= $this->pc->getPhpCodeCommentLine("Form Image {$ccFieldName}:", 'Upload new image', $t);
417
        $getConfigSize   = $this->xc->getXcGetConfig('maxsize_image');
418
        $contIf          = $this->xc->getXcEqualsOperator('$maxsize', $getConfigSize,'', "\t\t\t");
419
        $xoopsFormFile   = $this->cxc->getClassXoopsFormFile('imageTray', "'<br>' . " . $languageShort . 'FORM_UPLOAD_NEW', $fieldName, '$maxsize', true, '');
420
        $contIf          .= $this->cxc->getClassAddElement('imageTray', $xoopsFormFile, $t . "\t");
421
        $configText      = "(\$maxsize / 1048576) . ' '  . " . $languageShort . 'FORM_UPLOAD_SIZE_MB';
422
        $labelInfo1      = $this->cxc->getClassXoopsFormLabel('',  $languageShort . 'FORM_UPLOAD_SIZE', $configText, true, '');
423
        $contIf          .= $this->cxc->getClassAddElement('imageTray', $labelInfo1, $t . "\t");
424
        $getConfig       = $this->xc->getXcGetConfig('maxwidth_image');
425
        $labelInfo2      = $this->cxc->getClassXoopsFormLabel('',  $languageShort . 'FORM_UPLOAD_IMG_WIDTH', $getConfig . " . ' px'", true, '');
426
        $contIf          .= $this->cxc->getClassAddElement('imageTray', $labelInfo2, $t . "\t");
427
        $getConfig       = $this->xc->getXcGetConfig('maxheight_image');
428
        $labelInfo3      = $this->cxc->getClassXoopsFormLabel('',  $languageShort . 'FORM_UPLOAD_IMG_HEIGHT', $getConfig . " . ' px'", true, '');
429
        $contIf          .= $this->cxc->getClassAddElement('imageTray', $labelInfo3, $t . "\t");
430
        $formHidden      = $this->cxc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, $t, true);
431
        $contElse        = $this->cxc->getClassAddElement('imageTray', $formHidden, $t . "\t");
432
        $ret             .= $this->pc->getPhpCodeConditions('$permissionUpload', null, null, $contIf, $contElse, "\t\t");
433
        $ret             .= $this->cxc->getClassAddElement('form', "\$imageTray{$required}", $t);
434
435
        return $ret;
436
    }
437
438
    /**
439
     * @private function getXoopsFormUploadFile
440
     *          provides label with last uploaded file and an upload field
441
     *
442
     * @param $language
443
     * @param $moduleDirname
444
     * @param $tableName
445
     * @param $fieldName
446
     *
447
     * @param string $required
448
     * @return string
449
     */
450
    private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
451
    {
452
        $ccFieldName    = $this->cf->getCamelCase($fieldName, false, true);
453
        $languageShort  = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
454
        $t              = "\t\t\t";
455
        $ret            = $this->pc->getPhpCodeCommentLine('Form File:', 'Upload ' . $ccFieldName, "\t\t");
456
        $ret            .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', "''", "\$this->getVar('{$fieldName}')", "\t\t");
457
        $uForm          = $this->cxc->getClassXoopsFormElementTray('fileUploadTray', $language, '<br>', $t);
458
        $uForm          .= $this->xc->getXcEqualsOperator('$fileDirectory', "'/uploads/{$moduleDirname}/files/{$tableName}'", null, $t);
459
        $sprintf        = $this->pc->getPhpCodeSprintf($language . '_UPLOADS', '".{$fileDirectory}/"');
460
        $xoopsFormLabel = $this->cxc->getClassXoopsFormLabel('', $sprintf, $ccFieldName, true, "\t\t", true);
461
        $condIf         = $this->cxc->getClassAddElement('fileUploadTray', $xoopsFormLabel, $t . "\t");
462
        $uForm          .= $this->pc->getPhpCodeConditions('!$this->isNew()', null, null, $condIf, false, "\t\t\t");
463
        $getConfig      = $this->xc->getXcGetConfig('maxsize_file');
464
        $uForm          .= $this->xc->getXcEqualsOperator('$maxsize', $getConfig,'', "\t\t\t");
465
        $xoopsFormFile  = $this->cxc->getClassXoopsFormFile('', "''", $fieldName, '$maxsize', true, '');
466
        $uForm          .= $this->cxc->getClassAddElement('fileUploadTray', $xoopsFormFile, $t);
467
        $configText     = "(\$maxsize / 1048576) . ' '  . " . $languageShort . 'FORM_UPLOAD_SIZE_MB';
468
        $labelInfo1      = $this->cxc->getClassXoopsFormLabel('',  $languageShort . 'FORM_UPLOAD_SIZE', $configText, true, '');
469
        $uForm          .= $this->cxc->getClassAddElement('fileUploadTray', $labelInfo1, $t );
470
        $uForm          .= $this->cxc->getClassAddElement('form', "\$fileUploadTray{$required}", $t);
471
        $formHidden     = $this->cxc->getClassXoopsFormHidden('', $fieldName, $ccFieldName, true, true, "\t\t", true);
472
        $contElse       = $this->cxc->getClassAddElement('form', $formHidden, $t);
473
474
        $ret           .= $this->pc->getPhpCodeConditions('$permissionUpload', null, null, $uForm, $contElse, "\t\t");
475
476
        return $ret;
477
    }
478
479
    /**
480
     * @private function getXoopsFormColorPicker
481
     *
482
     * @param $language
483
     * @param $fieldName
484
     *
485
     * @param string $required
486
     * @return string
487
     */
488
    private function getXoopsFormColorPicker($language, $fieldName, $required = 'false')
489
    {
490
        $ccFieldName   = $this->cf->getCamelCase($fieldName, false, true);
491
        $t             = "\t\t";
492
        $ret           = $this->pc->getPhpCodeCommentLine('Form Color', 'Picker ' . $ccFieldName, $t);
493
        $getVar        = $this->xc->getXcGetVar('', 'this', $fieldName, true);
494
        $xoopsFormFile = $this->cxc->getClassXoopsFormColorPicker('', $language, $fieldName, $getVar, true, '');
495
        $ret           .= $this->cxc->getClassAddElement('form', $xoopsFormFile. $required, $t);
496
497
        return $ret;
498
    }
499
500
    /**
501
     * @private function getXoopsFormSelectBox
502
     *
503
     * @param $language
504
     * @param $tableName
505
     * @param $fieldName
506
     * @param $required
507
     *
508
     * @return string
509
     */
510
    private function getXoopsFormSelectBox($language, $tableName, $fieldName, $required = 'false')
511
    {
512
        $ucfTableName = \ucfirst($tableName);
513
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
514
        $t            = "\t\t";
515
        $ret          = $this->pc->getPhpCodeCommentLine($ucfTableName, 'Handler', $t);
516
        $ret          .= $this->xc->getXcHandlerLine($tableName, $t);
517
        $ret          .= $this->pc->getPhpCodeCommentLine('Form', 'Select ' . $ccFieldName, $t);
518
        $ret          .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
519
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'Empty'", $t);
520
        $ret          .= $this->cxc->getClassAddOptionArray($ccFieldName . 'Select', "\${$tableName}Handler->getList()", $t);
521
        $ret          .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
522
523
        return $ret;
524
    }
525
526
    /**
527
     * @private function getXoopsFormSelectUser
528
     *
529
     * @param        $language
530
     * @param        $fieldName
531
     * @param string $required
532
     * @return string
533
     */
534
    private function getXoopsFormSelectUser($language, $fieldName, $required = 'false')
535
    {
536
        $ccFieldName     = $this->cf->getCamelCase($fieldName, false, true);
537
        $t               = "\t\t";
538
        $ret             = $this->pc->getPhpCodeCommentLine('Form Select', 'User ' . $ccFieldName, $t);
539
        $ret             .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '$GLOBALS[\'xoopsUser\']->uid()', "\$this->getVar('{$fieldName}')", $t);
540
        $xoopsSelectUser = $this->cxc->getClassXoopsFormSelectUser('', $language, $fieldName, 'false', '$' . $ccFieldName, true, $t);
541
        $ret             .= $this->cxc->getClassAddElement('form', $xoopsSelectUser . $required, $t);
542
543
        return $ret;
544
    }
545
546
    /**
547
     * @private function getXoopsFormRadioYN
548
     *
549
     * @param $language
550
     * @param $fieldName
551
     * @param $required
552
     *
553
     * @return string
554
     */
555
    private function getXoopsFormRadioYN($language, $fieldName, $required = 'false')
556
    {
557
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
558
        $t            = "\t\t";
559
        $ret          = $this->pc->getPhpCodeCommentLine('Form Radio', 'Yes/No ' . $ccFieldName, $t);
560
        $ret          .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', 0, "\$this->getVar('{$fieldName}')", $t);
561
        $xoopsRadioYN = $this->cxc->getClassXoopsFormRadioYN('', $language, $fieldName, $ccFieldName, true, $t);
562
        $ret          .= $this->cxc->getClassAddElement('form', $xoopsRadioYN . $required, $t);
563
564
        return $ret;
565
    }
566
567
    /**
568
     * @private function getXoopsFormTextDateSelect
569
     *
570
     * @param $language
571
     * @param $fieldName
572
     * @param $required
573
     *
574
     * @return string
575
     */
576
    private function getXoopsFormTextDateSelect($language, $fieldName, $required = 'false')
577
    {
578
        $t                   = "\t\t";
579
        $ccFieldName         = $this->cf->getCamelCase($fieldName, false, true);
580
        $ret                 = $this->pc->getPhpCodeCommentLine('Form Text', 'Date Select ' . $ccFieldName, $t);
581
        $ret                 .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '\time()', "\$this->getVar('{$fieldName}')", $t);
582
        $xoopsTextDateSelect = $this->cxc->getClassXoopsFormTextDateSelect('', $language, $fieldName, $fieldName, $ccFieldName, true, $t);
583
        $ret                 .= $this->cxc->getClassAddElement('form', $xoopsTextDateSelect . $required, $t);
584
585
        return $ret;
586
    }
587
588
    /**
589
     * @private function getXoopsFormDateTime
590
     *
591
     * @param $language
592
     * @param $fieldName
593
     * @param $required
594
     *
595
     * @return string
596
     */
597
    private function getXoopsFormDateTime($language, $fieldName, $required = 'false')
598
    {
599
        $t                   = "\t\t";
600
        $ccFieldName         = $this->cf->getCamelCase($fieldName, false, true);
601
        $ret                 = $this->pc->getPhpCodeCommentLine('Form Text', 'Date Select ' . $ccFieldName, $t);
602
        $ret                 .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '\time()', "\$this->getVar('{$fieldName}')", $t);
603
        $xoopsTextDateSelect = $this->cxc->getClassXoopsFormDateTime('', $language, $fieldName, $fieldName, $ccFieldName, true, $t);
604
        $ret                 .= $this->cxc->getClassAddElement('form', $xoopsTextDateSelect . $required, $t);
605
606
        return $ret;
607
    }
608
609
    /**
610
     * @private function getXoopsFormSelectStatus
611
     *
612
     * @param $language
613
     * @param $moduleDirname
614
     * @param $fieldName
615
     * @param $tablePermissions
616
     * @param string $required
617
     *
618
     * @return string
619
     */
620
    private function getXoopsFormSelectStatus($language, $moduleDirname, $fieldName, $tablePermissions, $required = 'false')
621
    {
622
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
623
        $languageShort = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
624
        $t            = "\t\t";
625
        $ret          = $this->pc->getPhpCodeCommentLine('Form Select', 'Status ' . $ccFieldName, $t);
626
        if (1 == $tablePermissions) {
627
            $ret .= $this->xc->getXcHandlerLine('permissions', $t);
628
        }
629
        $ret          .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
630
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', $this->xc->getXcGetConstants('STATUS_NONE') . ", {$languageShort}STATUS_NONE", $t);
631
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', $this->xc->getXcGetConstants('STATUS_OFFLINE') . ", {$languageShort}STATUS_OFFLINE", $t);
632
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', $this->xc->getXcGetConstants('STATUS_SUBMITTED') . ", {$languageShort}STATUS_SUBMITTED", $t);
633
        if (1 == $tablePermissions) {
634
            $contIf = $this->cxc->getClassAddOption($ccFieldName . 'Select', $this->xc->getXcGetConstants('STATUS_APPROVED') . ", {$languageShort}STATUS_APPROVED", $t . "\t");
635
            $ret .= $this->pc->getPhpCodeConditions('$permissionsHandler->getPermGlobalApprove()', '', '', $contIf, false, $t);
636
        }
637
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', $this->xc->getXcGetConstants('STATUS_BROKEN') . ", {$languageShort}STATUS_BROKEN", $t);
638
        $ret          .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
639
640
        return $ret;
641
    }
642
643
    /**
644
     * @private function getXoopsFormPassword
645
     *
646
     * @param $language
647
     * @param $fieldName
648
     * @param $required
649
     *
650
     * @return string
651
     */
652
    private function getXoopsFormPassword($language, $fieldName, $required = 'false')
653
    {
654
        $t             = "\t\t";
655
        $ccFieldName   = $this->cf->getCamelCase($fieldName, false, true);
656
        $ret           = $this->pc->getPhpCodeCommentLine('Form Text', 'Enter Password ' . $ccFieldName, $t);
657
        $xoopsPassword = $this->cxc->getClassXoopsFormPassword('', $language, $fieldName, 10, 32, true, $t);
658
        $ret           .= $this->cxc->getClassAddElement('form', $xoopsPassword . $required, $t);
659
660
        return $ret;
661
    }
662
663
    /**
664
     * @private function getXoopsFormSelectCountry
665
     *
666
     * @param $language
667
     * @param $fieldName
668
     * @param string $required
669
     *
670
     * @return string
671
     */
672
    private function getXoopsFormSelectCountry($language, $fieldName, $required = 'false')
673
    {
674
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
675
        $t            = "\t\t";
676
        $ret          = $this->pc->getPhpCodeCommentLine('Form Select', 'Country ' . $ccFieldName, $t);
677
        $ret          .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
678
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'', \_NONE", $t);
679
        $ret          .= $this->xc->getXcXoopsListCountryList('countryArray', $t);
680
        $ret          .= $this->cxc->getClassAddOptionArray($ccFieldName . 'Select', '$countryArray', $t);
681
        $ret          .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
682
683
        return $ret;
684
    }
685
686
    /**
687
     * @private function getXoopsFormSelectLang
688
     *
689
     * @param $language
690
     * @param $fieldName
691
     * @param string $required
692
     *
693
     * @return string
694
     */
695
    private function getXoopsFormSelectLang($language, $fieldName, $required = 'false')
696
    {
697
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
698
        $t            = "\t\t";
699
        $ret          = $this->pc->getPhpCodeCommentLine('Form Select', 'Lang ' . $ccFieldName, $t);
700
        $ret          .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
701
        $ret          .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'', \_NONE", $t);
702
        $ret          .= $this->xc->getXcXoopsListLangList('langArray', $t);
703
        $ret          .= $this->cxc->getClassAddOptionArray($ccFieldName . 'Select', '$langArray', $t);
704
        $ret          .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
705
706
        return $ret;
707
    }
708
709
    /**
710
     * @private function getXoopsFormRadio
711
     *
712
     * @param $language
713
     * @param $moduleDirname
714
     * @param $fieldName
715
     * @param string $required
716
     *
717
     * @return string
718
     */
719
    private function getXoopsFormRadio($language, $moduleDirname, $fieldName, $required = 'false')
720
    {
721
        $ccFieldName   = $this->cf->getCamelCase($fieldName, false, true);
722
        $languageShort = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
723
        $t             = "\t\t";
724
        $ret           = $this->pc->getPhpCodeCommentLine('Form Radio', $ccFieldName, $t);
725
        $ret           .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '0', "\$this->getVar('{$fieldName}')", $t);
726
        $ret           .= $this->cxc->getClassXoopsFormRadio($ccFieldName . 'Select', $language, $fieldName, "{$ccFieldName}", false, $t);
727
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'0', \_NONE", $t);
728
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'1', {$languageShort}LIST_1", $t);
729
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'2', {$languageShort}LIST_2", $t);
730
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'3', {$languageShort}LIST_3", $t);
731
        $ret           .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
732
733
        return $ret;
734
    }
735
736
    /**
737
     * @private function getXoopsFormSelectCombo
738
     *
739
     * @param $language
740
     * @param $moduleDirname
741
     * @param $tableName
742
     * @param $fieldName
743
     * @param string $required
744
     *
745
     * @return string
746
     */
747
    private function getXoopsFormSelectCombo($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
748
    {
749
        $ucfTableName  = \ucfirst($tableName);
750
        $ccFieldName   = $this->cf->getCamelCase($fieldName, false, true);
751
        $languageShort = \substr($language, 0, 5) . \mb_strtoupper($moduleDirname) . '_';
752
        $t             = "\t\t";
753
        $ret           = $this->pc->getPhpCodeCommentLine($ucfTableName, 'Handler', $t);
754
        $ret           .= $this->xc->getXcHandlerLine($tableName, $t);
755
        $ret           .= $this->pc->getPhpCodeCommentLine('Form', 'Select ' . $ccFieldName, $t);
756
        $ret           .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", '5', '', false, $t);
757
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'0', \_NONE", $t);
758
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'1', {$languageShort}LIST_1", $t);
759
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'2', {$languageShort}LIST_2", $t);
760
        $ret           .= $this->cxc->getClassAddOption($ccFieldName . 'Select', "'3', {$languageShort}LIST_3", $t);
761
        $ret           .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
762
763
        return $ret;
764
    }
765
766
    /**
767
     * @private function getXoopsFormTable
768
     *
769
     * @param $language
770
     * @param $fieldName
771
     * @param $fieldElement
772
     * @param $required
773
     *
774
     * @return string
775
     */
776
    private function getXoopsFormTable($language,$fieldName, $fieldElement, $required = 'false')
777
    {
778
        $t   = "\t\t";
779
        $ret = '';
780
        $fElement           = $this->helper->getHandler('Fieldelements')->get($fieldElement);
781
        $rpFieldelementName = \mb_strtolower(\str_replace('Table : ', '', $fElement->getVar('fieldelement_name')));
782
        $ret                .= $this->pc->getPhpCodeCommentLine('Form Table', $rpFieldelementName, $t);
783
        $ccFieldName        = $this->cf->getCamelCase($fieldName, false, true);
784
        $ret                .= $this->xc->getXcHandlerLine($rpFieldelementName, $t);
785
        $ret                .= $this->cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
786
        $ret                .= $this->cxc->getClassAddOptionArray($ccFieldName . 'Select', "\${$rpFieldelementName}Handler->getList()", $t);
787
        $ret                .= $this->cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
788
789
        return $ret;
790
    }
791
792
    /**
793
     * @private  function getXoopsFormTopic
794
     *
795
     * @param        $language
796
     * @param        $topicTableName
797
     * @param        $fieldId
798
     * @param        $fieldPid
799
     * @param        $fieldMain
800
     * @return string
801
     */
802
    private function getXoopsFormTopic($language, $topicTableName, $fieldId, $fieldPid, $fieldMain)
803
    {
804
        $ucfTopicTableName = \ucfirst($topicTableName);
805
        $stlTopicTableName = \mb_strtolower($topicTableName);
806
        $ccFieldPid        = $this->cf->getCamelCase($fieldPid, false, true);
807
        $t                 = "\t\t";
808
        $ret               = $this->pc->getPhpCodeCommentLine('Form Table', $ucfTopicTableName, $t);
809
        $ret               .= $this->xc->getXcHandlerLine($stlTopicTableName, $t);
810
        $ret               .= $this->xc->getXcCriteriaCompo('cr' . $ucfTopicTableName, $t);
811
        $ret               .= $this->xc->getXcHandlerCountClear($stlTopicTableName . 'Count', $stlTopicTableName, '$cr' . $ucfTopicTableName, $t);
812
        $contIf            = $this->pc->getPhpCodeIncludeDir('\XOOPS_ROOT_PATH', 'class/tree', true, false, 'require', $t . "\t");
813
        $contIf            .= $this->xc->getXcHandlerAllClear($stlTopicTableName . 'All', $stlTopicTableName, '$cr' . $ucfTopicTableName, $t . "\t");
814
        $contIf            .= $this->cxc->getClassXoopsObjectTree($stlTopicTableName . 'Tree', $stlTopicTableName . 'All', $fieldId, $fieldPid, $t . "\t");
815
        $contIf            .= $this->cxc->getClassXoopsMakeSelBox($ccFieldPid, $stlTopicTableName . 'Tree', $fieldPid, $fieldMain, '--', $fieldPid, $t . "\t");
816
        $formLabel         = $this->cxc->getClassXoopsFormLabel('', $language, "\${$ccFieldPid}", true, '');
817
        $contIf            .= $this->cxc->getClassAddElement('form', $formLabel, $t . "\t");
818
        $ret               .= $this->pc->getPhpCodeConditions("\${$stlTopicTableName}Count", null, null, $contIf, false, $t);
819
        $ret               .= $this->pc->getPhpCodeUnset('cr' . $ucfTopicTableName, $t);
820
821
        return $ret;
822
    }
823
824
    /**
825
     * @private function getXoopsFormTag
826
     *
827
     * @param $fieldId
828
     * @param $required
829
     *
830
     * @return string
831
     */
832
    private function getXoopsFormTag($fieldId, $required = 'false')
833
    {
834
        $t         = "\t\t";
835
        $ret       = $this->pc->getPhpCodeCommentLine('Use tag', 'module', $t);
836
        $isDir     = $this->pc->getPhpCodeIsDir("\XOOPS_ROOT_PATH . '/modules/tag'");
837
        $ret       .= $this->pc->getPhpCodeTernaryOperator('dirTag', $isDir, 'true', 'false', $t);
838
        $paramIf   = '(' . $this->xc->getXcGetConfig('usetag') . ' == 1)';
839
        $condIf    = $this->pc->getPhpCodeTernaryOperator('tagId', '$this->isNew()', '0', "\$this->getVar('{$fieldId}')", $t . "\t");
840
        $condIf    .= $this->pc->getPhpCodeIncludeDir('\XOOPS_ROOT_PATH', 'modules/tag/include/formtag', true, false, $type = 'require', $t . "\t");
841
        $paramElem = $this->cxc->getClassXoopsFormTag('', 'tag', 60, 255, 'tagId', 0, true, '');
842
        $condIf    .= $this->cxc->getClassAddElement('form', $paramElem . $required, $t . "\t");
843
        $ret       .= $this->pc->getPhpCodeConditions($paramIf, ' && ', '$dirTag', $condIf, false, $t);
844
845
        return $ret;
846
    }
847
848
    /**
849
     * @private function getXoopsFormTextUuid
850
     *
851
     * @param        $language
852
     * @param        $fieldName
853
     * @param string $required
854
     * @return string
855
     */
856
    private function getXoopsFormTextUuid($language, $fieldName, $required = 'false')
857
    {
858
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
859
        $ret      = $this->pc->getPhpCodeCommentLine('Form Text Uuid', $ccFieldName, "\t\t");
860
        $ret      .= $this->pc->getPhpCodeTernaryOperator($ccFieldName, '$this->isNew()', '\Xmf\Uuid::generate()', "\$this->getVar('{$fieldName}')", "\t\t");
861
        $formText = $this->cxc->getClassXoopsFormText('', $language, $fieldName, 50, 150, $ccFieldName, true);
862
        $ret      .= $this->cxc->getClassAddElement('form', $formText . $required);
863
864
865
        return $ret;
866
    }
867
    
868
    /**
869
     * @private function getXoopsFormTextIp
870
     *
871
     * @param        $language
872
     * @param        $fieldName
873
     * @param string $required
874
     * @return string
875
     */
876
    private function getXoopsFormTextIp($language, $fieldName, $required = 'false')
877
    {
878
        $ccFieldName  = $this->cf->getCamelCase($fieldName, false, true);
879
880
        $ret      = $this->pc->getPhpCodeCommentLine('Form Text IP', $ccFieldName, "\t\t");
881
        $ret      .= $this->xc->getXcEqualsOperator('$' . $ccFieldName, "\$_SERVER['REMOTE_ADDR']", null, "\t\t");
882
        $formText = $this->cxc->getClassXoopsFormText('', $language, $fieldName, 20, 150, $ccFieldName, true);
883
        $ret      .= $this->cxc->getClassAddElement('form', $formText . $required);
884
885
        return $ret;
886
    }
887
888
    /**
889
     * @public function renderElements
890
     * @param null
891
     * @return string
892
     */
893
    public function renderElements()
894
    {
895
        $module           = $this->getModule();
896
        $table            = $this->getTable();
897
        $moduleDirname    = $module->getVar('mod_dirname');
898
        $tableName        = $table->getVar('table_name');
899
        $tableSoleName    = $table->getVar('table_solename');
900
        $tablePermissions = $table->getVar('table_permissions');
901
        $languageFunct    = $this->cf->getLanguage($moduleDirname, 'AM');
902
        $ret               = '';
903
        $fields            = $this->tf->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order ASC, field_id');
904
        $fieldId           = '';
905
        $fieldIdTopic      = '';
906
        $fieldPidTopic     = '';
907
        $fieldMainTopic    = '';
908
        $fieldElementId    = [];
909
        $counter           = 0;
910
        $tagDone           = false;
911
        foreach (\array_keys($fields) as $f) {
912
            $fieldName    = $fields[$f]->getVar('field_name');
913
            $fieldDefault = $fields[$f]->getVar('field_default');
914
            $fieldElement = $fields[$f]->getVar('field_element');
915
            $fieldParent  = $fields[$f]->getVar('field_parent');
916
            $fieldInForm  = $fields[$f]->getVar('field_inform');
917
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
918
                $fieldId = $fieldName;
919
            }
920
            $rpFieldName = $this->cf->getRightString($fieldName);
921
            $language    = $languageFunct . \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName);
922
            $required    = (1 == $fields[$f]->getVar('field_required')) ? ', true' : '';
923
924
            $fieldElements    = $this->helper->getHandler('Fieldelements')->get($fieldElement);
925
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
926
927
            if (1 == $fieldInForm) {
928
                $counter++;
929
                // Switch elements
930
                switch ($fieldElement) {
931
                    case 1:
932
                        break;
933
                    case Constants::FIELD_ELE_TEXT:  // textbox
934
                    case Constants::FIELD_ELE_TEXTCOMMENTS: // textbox comments
935
                    case Constants::FIELD_ELE_TEXTRATINGS: // textbox ratings
936
                    case Constants::FIELD_ELE_TEXTVOTES: // textbox votes
937
                    case Constants::FIELD_ELE_TEXTREADS: // textbox reads
938
                        $ret .= $this->getXoopsFormText($language, $fieldName, $fieldDefault, $required);
939
                        break;
940
                    case Constants::FIELD_ELE_TEXTAREA:
941
                        $ret .= $this->getXoopsFormTextArea($language, $fieldName, $required);
942
                        break;
943
                    case Constants::FIELD_ELE_DHTMLTEXTAREA:
944
                        $ret .= $this->getXoopsFormDhtmlTextArea($language, $fieldName, $required);
945
                        break;
946
                    case Constants::FIELD_ELE_CHECKBOX:
947
                        $ret .= $this->getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required);
948
                        break;
949
                    case Constants::FIELD_ELE_RADIOYN:
950
                        $ret .= $this->getXoopsFormRadioYN($language, $fieldName, $required);
951
                        break;
952
                    case Constants::FIELD_ELE_SELECTBOX:
953
                        $ret .= $this->getXoopsFormSelectBox($language, $tableName, $fieldName, $required);
954
                        break;
955
                    case Constants::FIELD_ELE_SELECTUSER:
956
                        $ret .= $this->getXoopsFormSelectUser($language, $fieldName, $required);
957
                        break;
958
                    case Constants::FIELD_ELE_COLORPICKER:
959
                        $ret .= $this->getXoopsFormColorPicker($language, $fieldName, $required);
960
                        break;
961
                    case Constants::FIELD_ELE_IMAGELIST:
962
                        $ret .= $this->getXoopsFormImageList($language, $moduleDirname, $fieldName, $required);
963
                        break;
964
                    case Constants::FIELD_ELE_SELECTFILE:
965
                        $ret .= $this->getXoopsFormSelectFile($language, $moduleDirname, $tableName, $fieldName, $required);
966
                        break;
967
                    case Constants::FIELD_ELE_URLFILE:
968
                        $ret .= $this->getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $required);
969
                        break;
970
                    case Constants::FIELD_ELE_UPLOADIMAGE:
971
                        $ret .= $this->getXoopsFormUploadImage($language, $moduleDirname, $tableName, $fieldName, $required);
972
                        break;
973
                    case Constants::FIELD_ELE_UPLOADFILE:
974
                        $ret .= $this->getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required);
975
                        break;
976
                    case Constants::FIELD_ELE_TEXTDATESELECT:
977
                        $ret .= $this->getXoopsFormTextDateSelect($language, $fieldName, $required);
978
                        break;
979
                    case Constants::FIELD_ELE_SELECTSTATUS:
980
                        $ret .= $this->getXoopsFormSelectStatus($language, $moduleDirname, $fieldName, $tablePermissions, $required);
981
                        break;
982
                    case Constants::FIELD_ELE_PASSWORD:
983
                        $ret .= $this->getXoopsFormPassword($language,  $fieldName, $required);
984
                        break;
985
                    case Constants::FIELD_ELE_SELECTCOUNTRY:
986
                        $ret .= $this->getXoopsFormSelectCountry($language, $fieldName, $required);
987
                        break;
988
                    case Constants::FIELD_ELE_SELECTLANG:
989
                        $ret .= $this->getXoopsFormSelectLang($language, $fieldName, $required);
990
                        break;
991
                    case Constants::FIELD_ELE_RADIO:
992
                        $ret .= $this->getXoopsFormRadio($language, $moduleDirname, $fieldName, $required);
993
                        break;
994
                    case Constants::FIELD_ELE_DATETIME:
995
                        $ret .= $this->getXoopsFormDateTime($language, $fieldName, $required);
996
                        break;
997
                    case Constants::FIELD_ELE_SELECTCOMBO:
998
                        $ret .= $this->getXoopsFormSelectCombo($language, $moduleDirname, $tableName, $fieldName, $required);
999
                        break;
1000
                    case Constants::FIELD_ELE_TEXTUUID:
1001
                        $ret .= $this->getXoopsFormTextUuid($language, $fieldName, $required);
1002
                        break;
1003
                    case Constants::FIELD_ELE_TEXTIP:
1004
                        $ret .= $this->getXoopsFormTextIp($language, $fieldName, $required);
1005
                        break;
1006
                    default:
1007
                        // If we use tag module
1008
                        if (!$tagDone && 1 == $table->getVar('table_tag')) {
1009
                            $ret .= $this->getXoopsFormTag($fieldId, $required);
1010
                            $tagDone = true;
1011
                        }
1012
                        // If we want to hide XoopsFormHidden() or field id
1013
                        if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
1014
                            $ret .= $this->getXoopsFormHidden($fieldName);
1015
                        }
1016
                        break;
1017
                }
1018
1019
                $fieldElements    = $this->helper->getHandler('Fieldelements')->get($fieldElement);
1020
                $fieldElementTid  = $fieldElements->getVar('fieldelement_tid');
1021
                if ((int)$fieldElementTid > 0 ) {
1022
                    if ((1 == $fieldParent) || 1 == $table->getVar('table_category')) {
1023
                        $fieldElementMid  = $fieldElements->getVar('fieldelement_mid');
1024
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
1025
                        $fieldNameDesc    = mb_substr($fieldElementName, \mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
1026
                        $topicTableName   = \str_replace(': ', '', $fieldNameDesc);
1027
                        $fieldsTopics     = $this->tf->getTableFields($fieldElementMid, $fieldElementTid);
1028
                        foreach (\array_keys($fieldsTopics) as $g) {
1029
                            $fieldNameTopic = $fieldsTopics[$g]->getVar('field_name');
1030
                            if ((0 == $g) && (1 == $table->getVar('table_autoincrement'))) {
1031
                                $fieldIdTopic = $fieldNameTopic;
1032
                            }
1033
                            if (1 == $fieldsTopics[$g]->getVar('field_parent')) {
1034
                                $fieldPidTopic = $fieldNameTopic;
1035
                            }
1036
                            if (1 == $fieldsTopics[$g]->getVar('field_main')) {
1037
                                $fieldMainTopic = $fieldNameTopic;
1038
                            }
1039
                        }
1040
                        $ret .= $this->getXoopsFormTopic($language, $topicTableName, $fieldIdTopic, $fieldPidTopic, $fieldMainTopic);
1041
                    } else {
1042
                        $ret .= $this->getXoopsFormTable($language, $fieldName, $fieldElement, $required);
1043
                    }
1044
                }
1045
            }
1046
        }
1047
        unset($fieldElementId);
1048
1049
        return $ret;
1050
    }
1051
}
1052