Passed
Push — master ( 0cff9c...dfbbd0 )
by Goffy
14:51
created

UserPages   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 515
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 287
dl 0
loc 515
rs 9.76
c 0
b 0
f 0
wmc 33

14 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 5 1
A getInstance() 0 8 2
A __construct() 0 3 1
A getUserPagesList() 0 36 1
A getUserPagesHeader() 0 35 1
F getUserPagesSave() 0 112 12
A getUserPagesDelete() 0 15 1
A getUserPagesNew() 0 11 1
A getUserPagesBroken() 0 35 2
A getUserPagesEdit() 0 15 1
A getUserPagesFooter() 0 23 1
A getPermissionsSave() 0 12 1
A getUserPagesSwitch() 0 18 3
A render() 0 40 5
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\User;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\Files;
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
 * modulebuilder module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 */
28
29
/**
30
 * Class UserPages.
31
 */
32
class UserPages extends Files\CreateFile
33
{
34
    /**
35
     * @public function constructor
36
     * @param null
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * @static function getInstance
45
     * @param null
46
     * @return UserPages
47
     */
48
    public static function getInstance()
49
    {
50
        static $instance = false;
51
        if (!$instance) {
52
            $instance = new self();
53
        }
54
55
        return $instance;
56
    }
57
58
    /**
59
     * @public function write
60
     * @param $module
61
     * @param $table
62
     * @param $filename
63
     */
64
    public function write($module, $table, $filename)
65
    {
66
        $this->setModule($module);
67
        $this->setTable($table);
68
        $this->setFileName($filename);
69
    }
70
71
    /**
72
     * @private function getUserPagesHeader
73
     * @param $moduleDirname
74
     * @param $tableName
75
     * @param $fieldId
76
     * @return string
77
     */
78
    private function getUserPagesHeader($moduleDirname, $tableName, $fieldId)
79
    {
80
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
81
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
82
        $uxc = UserXoopsCode::getInstance();
83
84
        $stuModuleDirname = mb_strtoupper($moduleDirname);
85
        $ccFieldId        = $this->getCamelCase($fieldId, false, true);
86
        $ret       = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
87
        $ret       .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
88
        $ret       .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
89
        $ret       .= $this->getInclude();
90
        $ret       .= $uxc->getUserTplMain($moduleDirname, $tableName);
91
        $ret       .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
92
        $ret       .= $pc->getPhpCodeBlankLine();
93
        $ret       .= $xc->getXcXoopsRequest('op   ', 'op', 'list', 'Cmd');
94
        $ret       .= $xc->getXcXoopsRequest('start', 'start', '0', 'Int');
95
        $userpager = $xc->getXcGetConfig('userpager');
96
        $ret       .= $xc->getXcXoopsRequest('limit', 'limit', $userpager, 'Int');
97
        $ret       .= $xc->getXcXoopsRequest($ccFieldId, $fieldId, '0', 'Int');
98
        $ret       .= $pc->getPhpCodeBlankLine();
99
        $ret       .= $pc->getPhpCodeCommentLine('Define Stylesheet');
100
        $ret       .= $xc->getXcXoThemeAddStylesheet();
101
        $ret       .= $pc->getPhpCodeBlankLine();
102
        $ret       .= $xc->getXcXoopsTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
103
        $ret       .= $xc->getXcXoopsTplAssign("{$moduleDirname}_url", "{$stuModuleDirname}_URL");
104
        $ret       .= $pc->getPhpCodeBlankLine();
105
        $ret       .= $pc->getPhpCodeArray('keywords', null, false, '');
106
        $ret       .= $pc->getPhpCodeBlankLine();
107
        $ret       .= $xc->getXcEqualsOperator('$permEdit', '$permissionsHandler->getPermGlobalSubmit()', );
108
        $ret       .= $xc->getXcXoopsTplAssign("permEdit", '$permEdit');
109
        $ret       .= $xc->getXcXoopsTplAssign("showItem", "\${$ccFieldId} > 0");
110
        $ret       .= $pc->getPhpCodeBlankLine();
111
112
        return $ret;
113
    }
114
115
    /**
116
     * @private function getUserPagesList
117
     * @param $tableName
118
     * @param $fieldId
119
     * @param $fieldMain
120
     * @param string $t
121
     * @return string
122
     */
123
    private function getUserPagesList($tableName, $fieldId, $fieldMain, $t = '')
124
    {
125
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
126
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
127
128
        $ucfTableName     = ucfirst($tableName);
129
        $ccFieldId        = $this->getCamelCase($fieldId, false, true);
130
131
        $critName  = 'cr' . $ucfTableName;
132
        $ret       = $xc->getXcCriteriaCompo($critName, $t);
133
        $crit      = $xc->getXcCriteria('', "'{$fieldId}'", "\${$ccFieldId}",'',true);
134
        $contIf    = $xc->getXcCriteriaAdd($critName, $crit, $t . "\t");
135
        $ret       .= $pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $contIf, false, $t);
136
        $ret       .= $xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t);
137
        $ret       .= $xc->getXcXoopsTplAssign($tableName . 'Count', "\${$tableName}Count", '', $t);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type boolean expected by parameter $leftIsString of XoopsModules\Modulebuild...::getXcXoopsTplAssign(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
        $ret       .= $xc->getXcXoopsTplAssign($tableName . 'Count', "\${$tableName}Count", /** @scrutinizer ignore-type */ '', $t);
Loading history...
138
        $ret       .= $xc->getXcCriteriaSetStart($critName, '$start', $t);
139
        $ret       .= $xc->getXcCriteriaSetLimit($critName, '$limit', $t);
140
        $ret       .= $xc->getXcHandlerAllClear($tableName . 'All', $tableName, '$' . $critName, $t);
141
        $condIf    = $pc->getPhpCodeArray($tableName, null, false, $t . "\t");
142
        $condIf    .= $pc->getPhpCodeCommentLine('Get All', $ucfTableName, $t . "\t");
143
        $foreach   = $xc->getXcGetValues($tableName, $tableName . '[]', 'i', false, $t . "\t\t");
144
        $foreach   .= $xc->getXcGetVar('keywords[]', "{$tableName}All[\$i]", $fieldMain, false, $t . "\t\t");
145
        $condIf    .= $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, $t . "\t");
146
        $condIf    .= $xc->getXcXoopsTplAssign($tableName, "\${$tableName}", true, $t . "\t");
147
        $condIf    .= $pc->getPhpCodeUnset($tableName, $t . "\t");
148
        $condIf    .= $xc->getXcPageNav($tableName, $t . "\t");
149
        $tableType = $xc->getXcGetConfig('table_type');
150
        $condIf    .= $xc->getXcXoopsTplAssign('type', $tableType, true, $t . "\t");
151
        $divideby  = $xc->getXcGetConfig('divideby');
152
        $condIf    .= $xc->getXcXoopsTplAssign('divideby', $divideby, true, $t . "\t");
153
        $numbCol   = $xc->getXcGetConfig('numb_col');
154
        $condIf    .= $xc->getXcXoopsTplAssign('numb_col', $numbCol, true, $t . "\t");
155
156
        $ret       .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf, false, $t);
157
158
        return $ret;
159
    }
160
161
    /**
162
     * @public function getUserSubmitSave
163
     * @param string $moduleDirname
164
     * @param        $fields
165
     * @param string $tableName
166
     * @param        $tableSoleName
167
     * @param $tablePermissions
168
     * @param $tableNotifications
169
     * @param        $language
170
     * @param string $t
171
     * @return string
172
     */
173
    public function getUserPagesSave($moduleDirname, $fields, $tableName, $tableSoleName, $tablePermissions, $tableNotifications, $language, $t = '')
174
    {
175
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
176
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
177
178
        $ucfTableName  = ucfirst($tableName);
179
        $countUploader = 0;
180
        $fieldId       = '';
181
        $ccFieldId     = '';
182
        $fieldMain     = '';
183
        $fieldStatus   = '';
184
        foreach (array_keys($fields) as $f) {
185
            $fieldName = $fields[$f]->getVar('field_name');
186
            if (0 == $f) {
187
                $fieldId   = $fieldName;
188
                $ccFieldId = $this->getCamelCase($fieldId, false, true);
189
                $ucfFieldId = ucfirst($ccFieldId);
190
            }
191
            if ($fields[$f]->getVar('field_type') >= 10 && $fields[$f]->getVar('field_type') <= 14) {
192
                $countUploader++;
193
            }
194
            if (1 == $fields[$f]->getVar('field_main')) {
195
                $fieldMain    = $fieldName; // fieldMain = fields parameters main field
196
                $stuFieldMain = mb_strtoupper($fieldMain);
0 ignored issues
show
Unused Code introduced by
The assignment to $stuFieldMain is dead and can be removed.
Loading history...
197
                $ccFieldMain  = $this->getCamelCase($fieldMain, false, true);
198
            }
199
            if ($fields[$f]->getVar('field_element') == 16) {
200
                $fieldStatus   = $fieldName;
201
                $ccFieldStatus = $this->getCamelCase($fieldStatus, false, true);
202
203
            }
204
        }
205
206
        $ret                = $pc->getPhpCodeCommentLine('Security Check', '', $t);
207
        $xoopsSecurityCheck = $xc->getXcXoopsSecurityCheck();
208
        $securityError      = $xc->getXcXoopsSecurityErrors();
209
        $implode            = $pc->getPhpCodeImplode(',', $securityError);
210
        $redirectError      = $xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t");
211
        $ret                .= $pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectError, false, $t);
212
        $ret                .= $pc->getPhpCodeCommentLine('Check permissions', '', $t);
213
        $contIf             = $xc->getXcRedirectHeader($tableName, '?op=list', 3, '_NOPERM', true, $t . "\t");
214
        $ret                .= $pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
215
        $getObj             = $xc->getXcHandlerGetObj($tableName, $ccFieldId,  $t . "\t");
216
        $createObj          = $xc->getXcHandlerCreateObj($tableName, $t . "\t");
217
        $ret                .= $pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $getObj, $createObj, $t);
218
        $ret                .= $xc->getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $fields, $t);
219
        $ret                .= $pc->getPhpCodeCommentLine('Insert Data', null, $t);
220
        $insert             = $xc->getXcHandlerInsert($tableName, $tableName, 'Obj', 'Handler');
221
222
        $contentInsert = '';
223
        $contentInsert .= $pc->getPhpCodeTernaryOperator("new{$ucfFieldId}", "\${$ccFieldId} > 0", "\${$ccFieldId}", "\${$tableName}Obj->getNewInsertedId{$ucfTableName}()", $t . "\t");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ucfFieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
224
225
        if (1 == $tablePermissions) {
226
            $contentInsert .= $xc->getXcXoopsHandler('groupperm', $t . "\t");
227
            $contentInsert .= $xc->getXcEqualsOperator('$mid', "\$GLOBALS['xoopsModule']->getVar('mid')", null, $t . "\t");
228
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId,'view_' . $tableName);
229
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId, 'submit_' . $tableName);
230
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId, 'approve_' . $tableName);
231
        }
232
233
        if (1 == $tableNotifications) {
234
            $contentInsert .= $pc->getPhpCodeCommentLine('Handle notification', null, $t . "\t");
235
            $contentInsert .= $xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t. "\t");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ccFieldMain does not seem to be defined for all execution paths leading up to this point.
Loading history...
236
            if ('' !== $fieldStatus) {
237
                $contentInsert .= $xc->getXcGetVar($ccFieldStatus, "{$tableName}Obj", $fieldStatus, false, $t . "\t");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ccFieldStatus does not seem to be defined for all execution paths leading up to this point.
Loading history...
238
            }
239
            $contentInsert .= $pc->getPhpCodeArray('tags', [], false, $t . "\t");
240
            $contentInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t");
241
            $url = "XOOPS_URL . '/modules/{$moduleDirname}/{$tableName}.php?op=show&{$fieldId}=' . \${$ccFieldId}";
242
            $contentInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_URL'] ", $url, '', $t . "\t");
243
            $contentInsert .= $xc->getXcXoopsHandler('notification', $t . "\t");
244
            if ('' === $fieldStatus) {
245
                $not2If        = $pc->getPhpCodeCommentLine('Event modify notification', null, $t . "\t\t");
246
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_modify', \$tags);", $t . "\t\t");
247
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_modify', \$tags);", $t . "\t\t");
248
                $not2Else      = $pc->getPhpCodeCommentLine('Event new notification', null, $t . "\t\t");
249
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_new', \$tags);", $t . "\t\t");
250
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_new', \$tags);", $t . "\t\t");
251
                $not1Else      = $pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $not2If, $not2Else, $t . "\t");
252
                $contentInsert .= $not1Else;
253
            } else {
254
                $not1If        = $pc->getPhpCodeCommentLine('Event approve notification', null, $t . "\t\t");
255
                $not1If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_approve', \$tags);", $t . "\t\t");
256
                $not1If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_approve', \$tags);", $t . "\t\t");
257
                $not2If        = $pc->getPhpCodeCommentLine('Event modify notification', null, $t . "\t\t\t");
258
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_modify', \$tags);", $t . "\t\t\t");
259
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_modify', \$tags);", $t . "\t\t\t");
260
                $not2Else      = $pc->getPhpCodeCommentLine('Event new notification', null, $t . "\t\t\t");
261
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_new', \$tags);", $t . "\t\t\t");
262
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_new', \$tags);", $t . "\t\t\t");
263
                $not1Else      = $pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $not2If, $not2Else, $t . "\t\t");
264
                $contentInsert .= $pc->getPhpCodeConditions("\${$ccFieldStatus}", ' == ', $xc->getXcGetConstants('STATUS_APPROVED'), $not1If, $not1Else, $t . "\t");
265
            }
266
        }
267
268
        $contentInsert .= $pc->getPhpCodeCommentLine('redirect after insert', null, $t . "\t");
269
        if ($countUploader > 0) {
270
            $errIf     = $xc->getXcRedirectHeader("'{$tableName}.php?op=edit&{$fieldId}=' . \$new{$ucfFieldId}", '', '5', '$uploaderErrors', false, $t . "\t\t");
271
            $errElse   = $xc->getXcRedirectHeader($tableName, '?op=list', '2', "{$language}FORM_OK", true, $t . "\t\t");
272
            $confirmOk = $pc->getPhpCodeConditions('$uploaderErrors', ' !== ', "''", $errIf, $errElse, $t . "\t");
273
        } else {
274
            $confirmOk = $xc->getXcRedirectHeader('index', '', '2', "{$language}FORM_OK", true, $t . "\t");
275
        }
276
        $contentInsert .= $confirmOk;
277
        $ret           .= $pc->getPhpCodeConditions($insert, '', '', $contentInsert, false, $t);
278
279
        $ret .= $pc->getPhpCodeCommentLine('Get Form Error', null, $t);
280
        $ret .= $xc->getXcXoopsTplAssign('error', "\${$tableName}Obj->getHtmlErrors()", true, $t);
281
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
282
        $ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
283
284
        return $ret;
285
    }
286
287
    /**
288
     * @private function getPermissionsSave
289
     * @param $moduleDirname
290
     * @param $ucfFieldId
291
     * @param string $perm
292
     *
293
     * @return string
294
     */
295
    private function getPermissionsSave($moduleDirname, $ucfFieldId, $perm = 'view')
296
    {
297
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
298
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
299
300
        $ret     = $pc->getPhpCodeCommentLine('Permission to', $perm, "\t\t\t");
301
        $ret     .= $xc->getXcDeleteRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$mid', "\$new{$ucfFieldId}", false, "\t\t\t");
302
        $content = $xc->getXcAddRight('grouppermHandler', "{$moduleDirname}_{$perm}", "\$new{$ucfFieldId}", '$onegroupId', '$mid', false, "\t\t\t\t\t");
303
        $foreach = $pc->getPhpCodeForeach("_POST['groups_{$perm}']", false, false, 'onegroupId', $content, "\t\t\t\t");
304
        $ret     .= $pc->getPhpCodeConditions("isset(\$_POST['groups_{$perm}'])", null, null, $foreach, false, "\t\t\t");
305
306
        return $ret;
307
    }
308
309
    /**
310
     * @public function getUserPagesNew
311
     * @param        $tableName
312
     * @param string $t
313
     * @return string
314
     */
315
    public function getUserPagesNew($tableName, $t = '')
316
    {
317
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
318
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
319
320
        $ret    = $pc->getPhpCodeCommentLine('Check permissions', '', $t);
321
        $contIf = $xc->getXcRedirectHeader($tableName, '?op=list', 3, '_NOPERM', true, $t . "\t");
322
        $ret    .= $pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
323
        $ret    .= $xc->getXcCommonPagesNew($tableName, $t);
324
325
        return $ret;
326
    }
327
328
    /**
329
     * @public function getUserPagesEdit
330
     * @param        $tableName
331
     * @param $fieldId
332
     * @param        $language
333
     * @param string $t
334
     * @return string
335
     */
336
    public function getUserPagesEdit($tableName, $fieldId, $language, $t = '')
337
    {
338
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
339
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
340
341
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
342
        $ret       = $pc->getPhpCodeCommentLine('Check permissions', '', $t);
343
        $contIf    = $xc->getXcRedirectHeader($tableName, '?op=list', 3, '_NOPERM', true, $t . "\t");
344
        $ret       .= $pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
345
        $ret       .= $pc->getPhpCodeCommentLine('Check params', '', $t);
346
        $contIf    = $xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
347
        $ret       .= $pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
348
        $ret       .= $xc->getXcCommonPagesEdit($tableName, $ccFieldId, $t);
349
350
        return $ret;
351
    }
352
353
    /**
354
     * @private function getUserPagesDelete
355
     * @param        $tableName
356
     * @param $tableSoleName
357
     * @param        $language
358
     * @param        $fieldId
359
     * @param        $fieldMain
360
     * @param $tableNotifications
361
     * @param string $t
362
     * @return string
363
     */
364
    private function getUserPagesDelete($tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications, $t = '')
365
    {
366
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
367
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
368
369
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
370
        $ret       = $pc->getPhpCodeCommentLine('Check permissions', '', $t);
371
        $contIf    = $xc->getXcRedirectHeader($tableName, '?op=list', 3, '_NOPERM', true, $t . "\t");
372
        $ret       .= $pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
373
        $ret       .= $pc->getPhpCodeCommentLine('Check params', '', $t);
374
        $contIf    = $xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
375
        $ret       .= $pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
376
        $ret       .= $xc->getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t);
377
378
        return $ret;
379
    }
380
381
    /**
382
     * @private function getUserPagesBroken
383
     * @param        $language
384
     * @param $moduleDirname
385
     * @param        $tableName
386
     * @param $tableSoleName
387
     * @param        $fieldId
388
     * @param $fieldSatus
389
     * @param        $fieldMain
390
     * @param $tableNotifications
391
     * @param string $t
392
     * @return string
393
     */
394
    private function getUserPagesBroken($language, $moduleDirname, $tableName, $tableSoleName, $fieldId, $fieldSatus, $fieldMain, $tableNotifications, $t = '')
395
    {
396
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
397
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
398
399
        //$stuFieldMain     = mb_strtoupper($fieldMain);
400
        //$stuTableSoleName = mb_strtoupper($tableSoleName);
401
        $ccFieldId        = $this->getCamelCase($fieldId, false, true);
402
        $ccFieldMain      = $this->getCamelCase($fieldMain, false, true);
403
404
        $ret        = $pc->getPhpCodeCommentLine('Check params', '', $t);
405
        $contIf     = $xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
406
        $ret        .= $pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
407
        $ret        .= $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', false, $t);
408
		$constant   = $xc->getXcGetConstants('STATUS_BROKEN');
409
        $ret        .= $xc->getXcSetVarObj($tableName, $fieldSatus, $constant, $t);
410
        $ret        .= $xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t);
411
        $ret        .= $pc->getPhpCodeCommentLine('Insert Data', null, $t);
412
        $insert     = $xc->getXcHandlerInsert($tableName, $tableName, 'Obj');
413
        $contInsert = '';
414
        if (1 == $tableNotifications) {
415
            $contInsert .= $pc->getPhpCodeCommentLine('Event broken notification', null, $t . "\t");
416
            $contInsert .= $pc->getPhpCodeArray('tags', [], false, $t . "\t");
417
            $contInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t");
418
            $url = "XOOPS_URL . '/modules/{$moduleDirname}/{$tableName}.php?op=show&{$fieldId}=' . \${$ccFieldId}";
419
            $contInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_URL'] ", $url, '', $t . "\t");
420
            $contInsert .= $xc->getXcXoopsHandler('notification', $t . "\t");
421
            $contInsert .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_broken', \$tags);", $t . "\t");
422
            $contInsert .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \${$ccFieldId}, '{$tableSoleName}_broken', \$tags);", $t . "\t");
423
        }
424
        $contInsert .= $pc->getPhpCodeCommentLine('redirect after success', null, $t . "\t");
425
        $contInsert .= $xc->getXcRedirectHeader($tableName, '', '2', "{$language}FORM_OK", true, $t . "\t");
426
        $ret        .= $pc->getPhpCodeConditions($insert, '', '', $contInsert, false, $t);
427
428
        return $ret;
429
    }
430
431
    /**
432
     * @private function getUserPagesFooter
433
     * @param $moduleDirname
434
     * @param $tableName
435
     * @param $language
436
     *
437
     * @return string
438
     */
439
    private function getUserPagesFooter($moduleDirname, $tableName, $language)
440
    {
441
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
442
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
443
        $uxc = UserXoopsCode::getInstance();
444
445
        $stuModuleDirname = mb_strtoupper($moduleDirname);
446
        $stuTableName     = mb_strtoupper($tableName);
447
        $ret              = $pc->getPhpCodeBlankLine();
448
        $ret              .= $pc->getPhpCodeCommentLine('Breadcrumbs');
449
        $ret              .= $uxc->getUserBreadcrumbs($language, $stuTableName);
450
        $ret              .= $pc->getPhpCodeBlankLine();
451
        $ret              .= $pc->getPhpCodeCommentLine('Keywords');
452
        $ret              .= $uxc->getUserMetaKeywords($moduleDirname);
453
        $ret              .= $pc->getPhpCodeUnset('keywords');
454
        $ret              .= $pc->getPhpCodeBlankLine();
455
        $ret              .= $pc->getPhpCodeCommentLine('Description');
456
        $ret              .= $uxc->getUserMetaDesc($moduleDirname, $language, $stuTableName);
457
        $ret              .= $xc->getXcXoopsTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/{$tableName}.php'");
458
        $ret              .= $xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
459
        $ret              .= $this->getInclude('footer');
460
461
        return $ret;
462
    }
463
464
    /**
465
     * @private function getUserPagesSwitch
466
     * @param $moduleDirname
467
     * @param $tableId
468
     * @param $tableMid
469
     * @param $tableName
470
     * @param $tableSoleName
471
     * @param $tableSubmit
472
     * @param $tablePermissions
473
     * @param $tableBroken
474
     * @param $fieldId
475
     * @param $fieldMain
476
     * @param $fieldSatus
477
     * @param $tableNotifications
478
     * @param $language
479
     * @param $t
480
     * @return string
481
     */
482
    private function getUserPagesSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tablePermissions, $tableBroken, $fieldId, $fieldMain, $fieldSatus, $tableNotifications, $language, $t)
483
    {
484
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
485
486
        $fields = $this->getTableFields($tableMid, $tableId);
487
        $cases['show'] = [];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cases was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cases = array(); before regardless.
Loading history...
488
        $cases['list'] = [$this->getUserPagesList($tableName, $fieldId, $fieldMain, $t . "\t")];
489
        if (1 == $tableSubmit) {
490
            $cases['save']   = [$this->getUserPagesSave($moduleDirname, $fields, $tableName, $tableSoleName, $tablePermissions, $tableNotifications, $language, $t . "\t")];
491
            $cases['new']    = [$this->getUserPagesNew($tableName, $t . "\t")];
492
            $cases['edit']   = [$this->getUserPagesEdit($tableName, $fieldId, $language, $t . "\t")];
493
            $cases['delete'] = [$this->getUserPagesDelete($tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications,$t . "\t")];
494
        }
495
        if (1 == $tableBroken) {
496
            $cases['broken']  = [$this->getUserPagesBroken($language, $moduleDirname, $tableName, $tableSoleName, $fieldId, $fieldSatus, $fieldMain, $tableNotifications, $t . "\t")];
497
        }
498
499
        return $xc->getXcSwitch('op', $cases, true, false);
500
    }
501
502
    /**
503
     * @public function render
504
     * @param null
505
     * @return bool|string
506
     */
507
    public function render()
508
    {
509
        $module             = $this->getModule();
510
        $table              = $this->getTable();
511
        $tableId            = $table->getVar('table_id');
512
        $tableMid           = $table->getVar('table_mid');
513
        $tableName          = $table->getVar('table_name');
514
        $tableSubmit        = $table->getVar('table_submit');
515
        $tablePermissions   = $table->getVar('table_permissions');
516
        $tableSoleName      = $table->getVar('table_solename');
517
        $tableBroken        = $table->getVar('table_broken');
518
        $tableNotifications = $table->getVar('table_notifications');
519
        $filename           = $this->getFileName();
520
        $moduleDirname      = $module->getVar('mod_dirname');
521
        $language           = $this->getLanguage($moduleDirname, 'MA');
522
        // Fields
523
        $fieldId    = '';
524
        $fieldMain  = '';
525
        $fieldSatus = '';
526
        $fields    = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
527
        foreach (array_keys($fields) as $f) {
528
            $fieldName = $fields[$f]->getVar('field_name');
529
            if (0 == $f) {
530
                $fieldId = $fieldName;
531
            }
532
            if (1 == $fields[$f]->getVar('field_main')) {
533
                $fieldMain = $fieldName; // fieldMain = fields parameters main field
534
            }
535
            if (16 == $fields[$f]->getVar('field_element')) {
536
                $fieldSatus = $fieldName; // fieldMain = fields parameters main field
537
            }
538
        }
539
        $content       = $this->getHeaderFilesComments($module);
540
        $content       .= $this->getUserPagesHeader($moduleDirname, $tableName, $fieldId);
541
        $content       .= $this->getUserPagesSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tablePermissions, $tableBroken, $fieldId, $fieldMain, $fieldSatus, $tableNotifications, $language, "\t");
542
        $content       .= $this->getUserPagesFooter($moduleDirname, $tableName, $language);
543
544
        $this->create($moduleDirname, '/', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED);
545
546
        return $this->renderFile();
547
    }
548
}
549