Passed
Push — master ( 7331d1...59e477 )
by Goffy
05:28
created

UserPages::getUserPagesClone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
c 0
b 0
f 0
nc 2
nop 6
dl 0
loc 17
rs 9.8333
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\User;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\{
7
    Files,
8
    Constants
9
};
10
11
/*
12
 You may not change or alter any portion of this comment or credits
13
 of supporting developers from this source code or any supporting source code
14
 which is considered copyrighted (c) material of the original comment or credit authors.
15
16
 This program is distributed in the hope that it will be useful,
17
 but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
 */
20
/**
21
 * modulebuilder module.
22
 *
23
 * @copyright       XOOPS Project (https://xoops.org)
24
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
25
 *
26
 * @since           2.5.0
27
 *
28
 * @author          Txmod Xoops https://xoops.org 
29
 *                  Goffy https://myxoops.org
30
 *
31
 */
32
33
/**
34
 * Class UserPages.
35
 */
36
class UserPages extends Files\CreateFile
37
{
38
    /**
39
     * @var mixed
40
     */
41
    private $uxc = null;
42
43
    /**
44
     * @var mixed
45
     */
46
    private $xc = null;
47
48
    /**
49
     * @var mixed
50
     */
51
    private $pc = null;
52
53
    /**
54
     * @public function constructor
55
     * @param null
56
     */
57
    public function __construct()
58
    {
59
        parent::__construct();
60
        $this->xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
61
        $this->pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
62
        $this->uxc = Modulebuilder\Files\User\UserXoopsCode::getInstance();
63
    }
64
65
    /**
66
     * @static function getInstance
67
     * @param null
68
     * @return UserPages
69
     */
70
    public static function getInstance()
71
    {
72
        static $instance = false;
73
        if (!$instance) {
74
            $instance = new self();
75
        }
76
77
        return $instance;
78
    }
79
80
    /**
81
     * @public function write
82
     * @param $module
83
     * @param $table
84
     * @param $filename
85
     */
86
    public function write($module, $table, $filename)
87
    {
88
        $this->setModule($module);
89
        $this->setTable($table);
90
        $this->setFileName($filename);
91
    }
92
93
    /**
94
     * @private function getUserPagesHeader
95
     * @param $moduleDirname
96
     * @param $tableName
97
     * @param $fieldId
98
     * @param $tablePermissions
99
     * @param $language
100
     * @return string
101
     */
102
    private function getUserPagesHeader($moduleDirname, $tableName, $fieldId, $tablePermissions, $language)
103
    {
104
        $stuModuleDirname = \mb_strtoupper($moduleDirname);
105
        $ccFieldId        = $this->getCamelCase($fieldId, false, true);
106
107
        $ret       = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
108
        $ret       .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
109
        $ret       .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants'], '', '');
110
        $ret       .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Common']);
111
        $ret       .= $this->getRequire();
112
        $ret       .= $this->uxc->getUserTplMain($moduleDirname, $tableName);
113
        $ret       .= $this->pc->getPhpCodeIncludeDir('\XOOPS_ROOT_PATH', 'header', true);
114
        $ret       .= $this->pc->getPhpCodeBlankLine();
115
        $ret       .= $this->xc->getXcXoopsRequest('op   ', 'op', 'list', 'Cmd');
116
        $ret       .= $this->xc->getXcXoopsRequest('start', 'start', '0', 'Int');
117
        $userpager = $this->xc->getXcGetConfig('userpager');
118
        $ret       .= $this->xc->getXcXoopsRequest('limit', 'limit', $userpager, 'Int');
119
        $ret       .= $this->xc->getXcXoopsRequest($ccFieldId, $fieldId, '0', 'Int');
120
        $ret       .= $this->pc->getPhpCodeBlankLine();
121
        $ret       .= $this->pc->getPhpCodeCommentLine('Define Stylesheet');
122
        $ret       .= $this->xc->getXcXoThemeAddStylesheet();
123
        $ret       .= $this->pc->getPhpCodeCommentLine('Paths');
124
        $ret       .= $this->xc->getXcXoopsTplAssign('xoops_icons32_url', '\XOOPS_ICONS32_URL');
125
        $ret       .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_url", "\\{$stuModuleDirname}_URL");
126
        $ret       .= $this->pc->getPhpCodeCommentLine('Keywords');
127
        $ret       .= $this->pc->getPhpCodeArray('keywords', null, false, '');
128
        $ret       .= $this->uxc->getUserBreadcrumbs($language, 'index', '', 'index.php');
129
        $ret       .= $this->pc->getPhpCodeCommentLine('Permissions');
130
        if (1 == $tablePermissions) {
131
            $ret .= $this->xc->getXcEqualsOperator('$permEdit', '$permissionsHandler->getPermGlobalSubmit()');
132
            $ret .= $this->xc->getXcXoopsTplAssign("permEdit", '$permEdit');
133
        }
134
        $ret       .= $this->xc->getXcXoopsTplAssign("showItem", "\${$ccFieldId} > 0");
135
        $ret       .= $this->pc->getPhpCodeBlankLine();
136
137
        return $ret;
138
    }
139
140
    /**
141
     * @private function getUserPagesList
142
     * @param $moduleDirname
143
     * @param $tableName
144
     * @param $fieldId
145
     * @param $fieldMain
146
     * @param $tableRate
147
     * @param $fieldReads
148
     * @param $language
149
     * @param string $t
150
     * @return string
151
     */
152
    private function getUserPagesList($moduleDirname, $tableName, $fieldId, $fieldMain, $tableRate, $fieldReads, $language, $t = '')
153
    {
154
        $ucfTableName     = \ucfirst($tableName);
155
        $stuTableName     = \mb_strtoupper($tableName);
156
        $ccFieldId        = $this->getCamelCase($fieldId, false, true);
157
        $ccFieldMain      = $this->getCamelCase($fieldMain, false, true);
158
        $ccFieldReads     = $this->getCamelCase($fieldReads, false, true);
159
        $stuModuleDirname = \mb_strtoupper($moduleDirname);
160
161
        $ret = '';
162
        $ret .= $this->uxc->getUserBreadcrumbs($language, $tableName, 'list', '', "\t\t");
163
        if ($tableRate) {
164
            $varRate = '$ratingbars';
165
            $ret .= $this->xc->getXcEqualsOperator($varRate, '(int)' . $this->xc->getXcGetConfig('ratingbars'),'', $t);
166
            $contIf = $this->xc->getXcXoThemeAddStylesheet("\\{$stuModuleDirname}_URL . '/assets/css/rating.css'", $t . "\t", false);
167
            $contIf .= $this->xc->getXcXoopsTplAssign('rating', $varRate, true, $t . "\t");
168
            $contIf .= $this->xc->getXcXoopsTplAssign('rating_5stars', "(Constants::RATING_5STARS === {$varRate})", true, $t . "\t");
169
            $contIf .= $this->xc->getXcXoopsTplAssign('rating_10stars', "(Constants::RATING_10STARS === {$varRate})", true, $t . "\t");
170
            $contIf .= $this->xc->getXcXoopsTplAssign('rating_10num', "(Constants::RATING_10NUM === {$varRate})", true, $t . "\t");
171
            $contIf .= $this->xc->getXcXoopsTplAssign('rating_likes', "(Constants::RATING_LIKES === {$varRate})", true, $t . "\t");
172
            $contIf .= $this->xc->getXcXoopsTplAssign('itemid', "'{$fieldId}'", true, $t . "\t");
173
            $contIf .= $this->xc->getXcXoopsTplAssign($moduleDirname . '_icon_url_16', "\\{$stuModuleDirname}_URL . '/' . \$modPathIcon16", true, $t . "\t");
174
            $ret .= $this->pc->getPhpCodeConditions($varRate, ' > ', '0', $contIf, false, $t);
175
        }
176
        $critName  = 'cr' . $ucfTableName;
177
        $ret       .= $this->xc->getXcCriteriaCompo($critName, $t);
178
        $crit      = $this->xc->getXcCriteria('', "'{$fieldId}'", "\${$ccFieldId}",'',true);
179
        $contIf    = $this->xc->getXcCriteriaAdd($critName, $crit, $t . "\t");
180
        $ret       .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $contIf, false, $t);
181
        $ret       .= $this->xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t);
182
        $ret       .= $this->xc->getXcXoopsTplAssign($tableName . 'Count', "\${$tableName}Count", '', $t);
183
        $ret       .= $this->xc->getXcCriteriaSetStart($critName, '$start', $t);
184
        $ret       .= $this->xc->getXcCriteriaSetLimit($critName, '$limit', $t);
185
        $ret       .= $this->xc->getXcHandlerAllClear($tableName . 'All', $tableName, '$' . $critName, $t);
186
        $condIf    = $this->pc->getPhpCodeArray($tableName, null, false, $t . "\t");
187
        $condIf    .= $this->xc->getXcEqualsOperator("\${$ccFieldMain}", "''",'', $t . "\t");
188
        $condIf    .= $this->pc->getPhpCodeCommentLine('Get All', $ucfTableName, $t . "\t");
189
        $foreach   = $this->xc->getXcGetValues($tableName, $tableName . '[$i]', 'i', false, $t . "\t\t");
190
        $foreach   .= $this->xc->getXcGetVar($ccFieldMain, "{$tableName}All[\$i]", $fieldMain, false, $t . "\t\t");
191
        $foreach   .= $this->xc->getXcEqualsOperator('$keywords[$i]', "\${$ccFieldMain}",'', $t . "\t\t");
192
        if ($tableRate) {
193
            $itemId   = $this->xc->getXcGetVar($ccFieldId, "{$tableName}All[\$i]", $fieldId, true);
194
            $const  = $this->xc->getXcGetConstants('TABLE_' . $stuTableName);
195
            $foreach .= $this->xc->getXcEqualsOperator("\${$tableName}[\$i]['rating']", "\$ratingsHandler->getItemRating({$itemId}, {$const})",'', $t . "\t\t");
196
        }
197
        $condIf    .= $this->pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, $t . "\t");
198
        $condIf    .= $this->xc->getXcXoopsTplAssign($tableName, "\${$tableName}", true, $t . "\t");
199
        $condIf    .= $this->pc->getPhpCodeUnset($tableName, $t . "\t");
200
        $condIf    .= $this->xc->getXcPageNav($tableName, $t . "\t");
201
        $config    = $this->xc->getXcGetConfig('table_type');
202
        $condIf    .= $this->xc->getXcXoopsTplAssign('table_type', $config, true, $t . "\t");
203
        $config    = $this->xc->getXcGetConfig('panel_type');
204
        $condIf    .= $this->xc->getXcXoopsTplAssign('panel_type', $config, true, $t . "\t");
205
        $divideby  = $this->xc->getXcGetConfig('divideby');
206
        $condIf    .= $this->xc->getXcXoopsTplAssign('divideby', $divideby, true, $t . "\t");
207
        $numbCol   = $this->xc->getXcGetConfig('numb_col');
208
        $condIf    .= $this->xc->getXcXoopsTplAssign('numb_col', $numbCol, true, $t . "\t");
209
        $stripTags      = $this->pc->getPhpCodeStripTags('', "\${$ccFieldMain} . ' - ' . " . "\$GLOBALS['xoopsModule']->getVar('name')", true);
210
        $condIf2         = $this->xc->getXcXoopsTplAssign('xoops_pagetitle', $stripTags, true, $t . "\t\t");
211
        $condIf       .= $this->pc->getPhpCodeConditions("'show' == \$op && '' != \${$ccFieldMain}", '', "", $condIf2, false, $t . "\t");
212
213
        if ('' !== $fieldReads) {
214
            $condIf3 = $this->xc->getXcHandlerGetObj($tableName, $ccFieldId, $t . "\t\t");
215
216
217
            $getVar = $this->xc->getXcGetVar('', "{$tableName}Obj", $fieldReads, true);
218
            $condIf3 .= $this->xc->getXcEqualsOperator("\${$ccFieldReads}", "(int)" . $getVar . ' + 1', false, $t . "\t\t");
219
            $condIf3 .= $this->xc->getXcSetVarObj($tableName, $fieldReads, "\${$ccFieldReads}", $t . "\t\t");
220
            $condIf3 .= $this->pc->getPhpCodeCommentLine('Insert Data', null, $t . "\t\t");
221
            $insert = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj', 'Handler');
222
            $condIf3 .= $this->getSimpleString($insert .';',$t . "\t\t");
223
            //$contentInsert = $this->xc->getXcRedirectHeader("'{$tableName}.php?op=list&{$fieldId}=' . \${$ccFieldId}", '', '5', "\${$tableName}Obj->getHtmlErrors()", false, $t . "\t\t\t");
224
            //$condIf3 .= $this->pc->getPhpCodeConditions('!' . $insert, '', '', $contentInsert, false, $t . "\t\t");
225
            $condIf .= $this->pc->getPhpCodeConditions("'show' == \$op", '', "", $condIf3, false, $t . "\t");
226
227
        }
228
229
230
        $ret       .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf, false, $t);
231
232
        return $ret;
233
    }
234
235
    /**
236
     * @public function getUserSubmitSave
237
     * @param string $moduleDirname
238
     * @param        $fields
239
     * @param string $tableName
240
     * @param        $tableSoleName
241
     * @param $tablePermissions
242
     * @param $tableNotifications
243
     * @param        $language
244
     * @param string $t
245
     * @return string
246
     */
247
    public function getUserPagesSave($moduleDirname, $fields, $tableName, $tableSoleName, $tablePermissions, $tableNotifications, $language, $t = '')
248
    {
249
        $ucfTableName  = \ucfirst($tableName);
250
        $countUploader = 0;
251
        $fieldId       = '';
252
        $ccFieldId     = '';
253
        $fieldMain     = '';
254
        $fieldStatus   = '';
255
        $ucfFieldId    = '';
256
        $ccFieldMain   = '';
257
        $ccFieldStatus = '';
258
        foreach (\array_keys($fields) as $f) {
259
            $fieldName = $fields[$f]->getVar('field_name');
260
            if (0 == $f) {
261
                $fieldId   = $fieldName;
262
                $ccFieldId = $this->getCamelCase($fieldId, false, true);
263
                $ucfFieldId = \ucfirst($ccFieldId);
264
            }
265
            if ($fields[$f]->getVar('field_element') >= Constants::FIELD_ELE_IMAGELIST && $fields[$f]->getVar('field_element') <= Constants::FIELD_ELE_UPLOADFILE) {
266
                $countUploader++;
267
            }
268
            if (1 == $fields[$f]->getVar('field_main')) {
269
                $fieldMain    = $fieldName; // fieldMain = fields parameters main field
270
                $ccFieldMain  = $this->getCamelCase($fieldMain, false, true);
271
            }
272
            if ($fields[$f]->getVar('field_element') == Constants::FIELD_ELE_SELECTSTATUS) {
273
                $fieldStatus   = $fieldName;
274
                $ccFieldStatus = $this->getCamelCase($fieldStatus, false, true);
275
            }
276
        }
277
278
        $ret                = $this->pc->getPhpCodeCommentLine('Security Check', '', $t);
279
        $xoopsSecurityCheck = $this->xc->getXcXoopsSecurityCheck();
280
        $securityError      = $this->xc->getXcXoopsSecurityErrors();
281
        $implode            = $this->pc->getPhpCodeImplode(',', $securityError);
282
        $redirectError      = $this->xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t");
283
        $ret                .= $this->pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectError, false, $t);
284
        if (1 == $tablePermissions) {
285
            $ret                .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t);
286
            $contIf             = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, '\_NOPERM', true, $t . "\t");
287
            $ret                .= $this->pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
288
        }
289
        $getObj             = $this->xc->getXcHandlerGetObj($tableName, $ccFieldId,  $t . "\t");
290
        $createObj          = $this->xc->getXcHandlerCreateObj($tableName, $t . "\t");
291
        $ret                .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $getObj, $createObj, $t);
292
        $ret                .= $this->xc->getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $fields, $t);
293
        $ret                .= $this->pc->getPhpCodeCommentLine('Insert Data', null, $t);
294
        $insert             = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj', 'Handler');
295
296
        $contentInsert = '';
297
        if (1 == $tableNotifications || $countUploader > 0) {
298
            $contentInsert .= $this->pc->getPhpCodeTernaryOperator("new{$ucfFieldId}", "\${$ccFieldId} > 0", "\${$ccFieldId}", "\${$tableName}Obj->getNewInsertedId{$ucfTableName}()", $t . "\t");
299
        }
300
301
        if (1 == $tablePermissions) {
302
            $contentInsert .= $this->xc->getXcXoopsHandler('groupperm', $t . "\t");
303
            $contentInsert .= $this->xc->getXcEqualsOperator('$mid', "\$GLOBALS['xoopsModule']->getVar('mid')", null, $t . "\t");
304
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId,'view_' . $tableName);
305
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId, 'submit_' . $tableName);
306
            $contentInsert .= $this->getPermissionsSave($moduleDirname, $ucfFieldId, 'approve_' . $tableName);
307
        }
308
309
        if (1 == $tableNotifications) {
310
            $contentInsert .= $this->pc->getPhpCodeCommentLine('Handle notification', null, $t . "\t");
311
            $contentInsert .= $this->xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t. "\t");
312
            if ('' !== $fieldStatus) {
313
                $contentInsert .= $this->xc->getXcGetVar($ccFieldStatus, "{$tableName}Obj", $fieldStatus, false, $t . "\t");
314
            }
315
            $contentInsert .= $this->pc->getPhpCodeArray('tags', [], false, $t . "\t");
316
            $contentInsert .= $this->xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t");
317
            $url = "\XOOPS_URL . '/modules/{$moduleDirname}/{$tableName}.php?op=show&{$fieldId}=' . \${$ccFieldId}";
318
            $contentInsert .= $this->xc->getXcEqualsOperator("\$tags['ITEM_URL'] ", $url, '', $t . "\t");
319
            $contentInsert .= $this->xc->getXcXoopsHandler('notification', $t . "\t");
320
            if ('' === $fieldStatus) {
321
                $not2If        = $this->pc->getPhpCodeCommentLine('Event modify notification', null, $t . "\t\t");
322
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_modify', \$tags);", $t . "\t\t");
323
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_modify', \$tags);", $t . "\t\t");
324
                $not2Else      = $this->pc->getPhpCodeCommentLine('Event new notification', null, $t . "\t\t");
325
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_new', \$tags);", $t . "\t\t");
326
                //$not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_new', \$tags);", $t . "\t\t");
327
                $not1Else      = $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $not2If, $not2Else, $t . "\t");
328
                $contentInsert .= $not1Else;
329
            } else {
330
                $not1If        = $this->pc->getPhpCodeCommentLine('Event approve notification', null, $t . "\t\t");
331
                $not1If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_approve', \$tags);", $t . "\t\t");
332
                $not1If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_approve', \$tags);", $t . "\t\t");
333
                $not2If        = $this->pc->getPhpCodeCommentLine('Event modify notification', null, $t . "\t\t\t");
334
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_modify', \$tags);", $t . "\t\t\t");
335
                $not2If        .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \$new{$ucfFieldId}, '{$tableSoleName}_modify', \$tags);", $t . "\t\t\t");
336
                $not2Else      = $this->pc->getPhpCodeCommentLine('Event new notification', null, $t . "\t\t\t");
337
                $not2Else      .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_new', \$tags);", $t . "\t\t\t");
338
                $not1Else      = $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $not2If, $not2Else, $t . "\t\t");
339
                $contentInsert .= $this->pc->getPhpCodeConditions("\${$ccFieldStatus}", ' == ', $this->xc->getXcGetConstants('STATUS_SUBMITTED'), $not1If, $not1Else, $t . "\t");
340
            }
341
        }
342
343
        $contentInsert .= $this->pc->getPhpCodeCommentLine('redirect after insert', null, $t . "\t");
344
        if ($countUploader > 0) {
345
            $errIf     = $this->xc->getXcRedirectHeader("'{$tableName}.php?op=edit&{$fieldId}=' . \$new{$ucfFieldId}", '', '5', '$uploaderErrors', false, $t . "\t\t");
346
            $errElse   = $this->xc->getXcRedirectHeader($tableName, '?op=list', '2', "{$language}FORM_OK", true, $t . "\t\t");
347
            $confirmOk = $this->pc->getPhpCodeConditions('$uploaderErrors', ' !== ', "''", $errIf, $errElse, $t . "\t");
348
        } else {
349
            $confirmOk = $this->xc->getXcRedirectHeader($tableName, '', '2', "{$language}FORM_OK", true, $t . "\t");
350
        }
351
        $contentInsert .= $confirmOk;
352
        $ret           .= $this->pc->getPhpCodeConditions($insert, '', '', $contentInsert, false, $t);
353
354
        $ret .= $this->pc->getPhpCodeCommentLine('Get Form Error', null, $t);
355
        $ret .= $this->xc->getXcXoopsTplAssign('error', "\${$tableName}Obj->getHtmlErrors()", true, $t);
356
        $ret .= $this->xc->getXcGetForm('form', $tableName, 'Obj', $t);
357
        $ret .= $this->xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
358
359
        return $ret;
360
    }
361
362
    /**
363
     * @private function getPermissionsSave
364
     * @param $moduleDirname
365
     * @param $ucfFieldId
366
     * @param string $perm
367
     *
368
     * @return string
369
     */
370
    private function getPermissionsSave($moduleDirname, $ucfFieldId, $perm = 'view')
371
    {
372
        $ret     = $this->pc->getPhpCodeCommentLine('Permission to', $perm, "\t\t\t");
373
        $ret     .= $this->xc->getXcDeleteRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$mid', "\$new{$ucfFieldId}", false, "\t\t\t");
374
        $content = $this->xc->getXcAddRight('grouppermHandler', "{$moduleDirname}_{$perm}", "\$new{$ucfFieldId}", '$onegroupId', '$mid', false, "\t\t\t\t\t");
375
        $foreach = $this->pc->getPhpCodeForeach("_POST['groups_{$perm}']", false, false, 'onegroupId', $content, "\t\t\t\t");
376
        $ret     .= $this->pc->getPhpCodeConditions("isset(\$_POST['groups_{$perm}'])", null, null, $foreach, false, "\t\t\t");
377
378
        return $ret;
379
    }
380
381
    /**
382
     * @public function getUserPagesNew
383
     * @param        $tableName
384
     * @param        $tableSoleName
385
     * @param        $tablePermissions
386
     * @param        $language
387
     * @param string $t
388
     * @return string
389
     */
390
    public function getUserPagesNew($tableName, $tableSoleName, $tablePermissions, $language, $t = '')
391
    {
392
        $ret    = $this->uxc->getUserBreadcrumbs($language, $tableSoleName, 'add', '', "\t\t");
393
        if (1 == $tablePermissions) {
394
            $ret    .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t);
395
            $contIf = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, '\_NOPERM', true, $t . "\t");
396
            $ret    .= $this->pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
397
        }
398
        $ret    .= $this->xc->getXcCommonPagesNew($tableName, $t);
399
400
        return $ret;
401
    }
402
403
    /**
404
     * @public function getUserPagesEdit
405
     * @param        $tableName
406
     * @param        $tableSoleName
407
     * @param        $tablePermissions
408
     * @param        $fieldId
409
     * @param        $language
410
     * @param string $t
411
     * @return string
412
     */
413
    public function getUserPagesEdit($tableName, $tableSoleName, $tablePermissions, $fieldId, $language, $t = '')
414
    {
415
        $ret       = $this->uxc->getUserBreadcrumbs($language, $tableSoleName, 'edit', '', "\t\t");
416
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
417
        if (1 == $tablePermissions) {
418
            $ret       .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t);
419
            $contIf    = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, '\_NOPERM', true, $t . "\t");
420
            $ret       .= $this->pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
421
        }
422
        $ret       .= $this->pc->getPhpCodeCommentLine('Check params', '', $t);
423
        $contIf    = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
424
        $ret       .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
425
        $ret       .= $this->xc->getXcCommonPagesEdit($tableName, $ccFieldId, $t);
426
427
        return $ret;
428
    }
429
430
    /**
431
     * @public function getUserPagesClone
432
     * @param        $tableName
433
     * @param        $tableSoleName
434
     * @param        $tablePermissions
435
     * @param        $fieldId
436
     * @param        $language
437
     * @param string $t
438
     * @return string
439
     */
440
    public function getUserPagesClone($tableName, $tableSoleName, $tablePermissions, $fieldId, $language, $t = '')
441
    {
442
        $ret       = $this->uxc->getUserBreadcrumbs($language, $tableSoleName, 'clone', '', "\t\t");
443
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
444
        if (1 == $tablePermissions) {
445
            $ret       .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t);
446
            $contIf    = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, '\_NOPERM', true, $t . "\t");
447
            $ret       .= $this->pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
448
        }
449
        $ret    .= $this->pc->getPhpCodeCommentLine("Request source", '', $t);
450
        $ret    .= $this->xc->getXcXoopsRequest($ccFieldId . 'Source', $fieldId . '_source', '', 'Int', false, $t);
451
        $ret    .= $this->pc->getPhpCodeCommentLine('Check params', '', $t);
452
        $contIf = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
453
        $ret    .= $this->pc->getPhpCodeConditions("\${$ccFieldId}Source", ' == ', '0', $contIf, false, $t);
454
        $ret    .= $this->xc->getXcCommonPagesClone($tableName, $ccFieldId, $t);
455
456
        return $ret;
457
    }
458
459
    /**
460
     * @private function getUserPagesDelete
461
     * @param        $tableName
462
     * @param        $tableSoleName
463
     * @param        $tablePermissions
464
     * @param        $language
465
     * @param        $fieldId
466
     * @param        $fieldMain
467
     * @param        $tableNotifications
468
     * @param string $t
469
     * @return string
470
     */
471
    private function getUserPagesDelete($tableName, $tableSoleName, $tablePermissions, $language, $fieldId, $fieldMain, $tableNotifications, $t = '')
472
    {
473
        $ret       = $this->uxc->getUserBreadcrumbs($language, $tableSoleName, 'delete', '', "\t\t");
474
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
475
        if (1 == $tablePermissions) {
476
            $ret       .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t);
477
            $contIf    = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, '\_NOPERM', true, $t . "\t");
478
            $ret       .= $this->pc->getPhpCodeConditions('!$permissionsHandler->getPermGlobalSubmit()', '', '', $contIf, false, $t);
479
        }
480
        $ret       .= $this->pc->getPhpCodeCommentLine('Check params', '', $t);
481
        $contIf    = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
482
        $ret       .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
483
        $ret       .= $this->xc->getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t);
484
485
        return $ret;
486
    }
487
488
    /**
489
     * @private function getUserPagesBroken
490
     * @param        $language
491
     * @param        $moduleDirname
492
     * @param        $tableName
493
     * @param        $tableSoleName
494
     * @param        $fieldId
495
     * @param $fieldStatus
496
     * @param        $fieldMain
497
     * @param        $tableNotifications
498
     * @param string $t
499
     * @return string
500
     */
501
    private function getUserPagesBroken($language, $moduleDirname, $tableName, $tableSoleName, $fieldId, $fieldStatus, $fieldMain, $tableNotifications, $t = '')
502
    {
503
        $ccFieldId   = $this->getCamelCase($fieldId, false, true);
504
        $ccFieldMain = $this->getCamelCase($fieldMain, false, true);
505
        $ret    = $this->uxc->getUserBreadcrumbs($language, '', 'broken', '', "\t\t");
506
        $ret    .= $this->pc->getPhpCodeCommentLine('Check params', '', $t);
507
        $contIf = $this->xc->getXcRedirectHeader($tableName, '?op=list', 3, "{$language}INVALID_PARAM", true, $t . "\t");
508
        $ret    .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' == ', '0', $contIf, false, $t);
509
510
        $ret                  .= $this->xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', false, $t);
511
        $ret                  .= $this->xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t);
512
        $reqOk                = "_REQUEST['ok']";
513
        $isset                = $this->pc->getPhpCodeIsset($reqOk);
514
        $xoopsSecurityCheck   = $this->xc->getXcXoopsSecurityCheck();
515
        $xoopsSecurityErrors  = $this->xc->getXcXoopsSecurityErrors();
516
        $implode              = $this->pc->getPhpCodeImplode(', ', $xoopsSecurityErrors);
517
        $redirectHeaderErrors = $this->xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t\t");
518
        $insert               = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj', 'Handler');
519
        $condition            = $this->pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectHeaderErrors, false, $t . "\t");
520
        $constant             = $this->xc->getXcGetConstants('STATUS_BROKEN');
521
        $condition            .= $this->xc->getXcSetVarObj($tableName, $fieldStatus, $constant, $t . "\t");
522
523
        $contInsert = '';
524
        if (1 == $tableNotifications) {
525
            $contInsert .= $this->pc->getPhpCodeCommentLine('Event broken notification', null, $t . "\t\t");
526
            $contInsert .= $this->pc->getPhpCodeArray('tags', [], false, $t . "\t\t");
527
            $contInsert .= $this->xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t\t");
528
            $url = "\XOOPS_URL . '/modules/{$moduleDirname}/{$tableName}.php?op=show&{$fieldId}=' . \${$ccFieldId}";
529
            $contInsert .= $this->xc->getXcEqualsOperator("\$tags['ITEM_URL'] ", $url, '', $t . "\t\t");
530
            $contInsert .= $this->xc->getXcXoopsHandler('notification', $t . "\t\t");
531
            $contInsert .= $this->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_broken', \$tags);", $t . "\t\t");
532
            $contInsert .= $this->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \${$ccFieldId}, '{$tableSoleName}_broken', \$tags);", $t . "\t\t");
533
        }
534
        $contInsert   .= $this->xc->getXcRedirectHeader($tableName, '', '3', "{$language}FORM_OK", true, $t . "\t\t");
535
        $htmlErrors   = $this->xc->getXcHtmlErrors($tableName, true);
536
        $internalElse = $this->xc->getXcXoopsTplAssign('error', $htmlErrors, true, $t . "\t\t");
537
        $condition    .= $this->pc->getPhpCodeConditions($insert, '', '', $contInsert, $internalElse, $t . "\t");
538
        $mainElse     = $this->xc->getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, 'broken', $t . "\t");
539
        $ret          .= $this->pc->getPhpCodeConditions($isset, ' && ', "1 == \${$reqOk}", $condition, $mainElse, $t);
540
541
        return $ret;
542
    }
543
544
    /**
545
     * @private function getUserPagesFooter
546
     * @param $moduleDirname
547
     * @param $tableName
548
     * @param $tableComments
549
     * @param $language
550
     *
551
     * @return string
552
     */
553
    private function getUserPagesFooter($moduleDirname, $tableName, $tableComments, $language)
554
    {
555
        $stuModuleDirname = \mb_strtoupper($moduleDirname);
556
        $stuTableName     = \mb_strtoupper($tableName);
557
        $ret = $this->pc->getPhpCodeBlankLine();
558
        $ret .= $this->pc->getPhpCodeCommentLine('Keywords');
559
        $ret .= $this->uxc->getUserMetaKeywords($moduleDirname);
560
        $ret .= $this->pc->getPhpCodeUnset('keywords');
561
        $ret .= $this->pc->getPhpCodeBlankLine();
562
        $ret .= $this->pc->getPhpCodeCommentLine('Description');
563
        $ret .= $this->uxc->getUserMetaDesc($moduleDirname, $language, $stuTableName);
564
        $ret .= $this->xc->getXcXoopsTplAssign('xoops_mpageurl', "\\{$stuModuleDirname}_URL.'/{$tableName}.php'");
565
        $ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "\\{$stuModuleDirname}_UPLOAD_URL");
566
        if (1 == $tableComments) {
567
            $ret .= $this->pc->getPhpCodeBlankLine();
568
            $ret .= $this->pc->getPhpCodeCommentLine('View comments');
569
            $ret .= $this->pc->getPhpCodeIncludeDir('\XOOPS_ROOT_PATH', 'include/comment_view', true, false, 'require');
570
        }
571
        $ret .= $this->pc->getPhpCodeBlankLine();
572
        $ret .= $this->getRequire('footer');
573
574
        return $ret;
575
    }
576
577
    /**
578
     * @private function getUserPagesSwitch
579
     * @param $moduleDirname
580
     * @param $tableId
581
     * @param $tableMid
582
     * @param $tableName
583
     * @param $tableSoleName
584
     * @param $tableSubmit
585
     * @param $tablePermissions
586
     * @param $tableBroken
587
     * @param $fieldId
588
     * @param $fieldMain
589
     * @param $fieldStatus
590
     * @param $tableNotifications
591
     * @param $tableRate
592
     * @param $fieldReads
593
     * @param $language
594
     * @param $t
595
     * @return string
596
     */
597
    private function getUserPagesSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tablePermissions, $tableBroken, $fieldId, $fieldMain, $fieldStatus, $tableNotifications, $tableRate, $fieldReads, $language, $t)
598
    {
599
        $fields = $this->getTableFields($tableMid, $tableId);
600
        $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...
601
        $cases['list'] = [$this->getUserPagesList($moduleDirname, $tableName, $fieldId, $fieldMain, $tableRate, $fieldReads, $language,$t . "\t")];
602
        if (1 == $tableSubmit) {
603
            $cases['save']   = [$this->getUserPagesSave($moduleDirname, $fields, $tableName, $tableSoleName, $tablePermissions, $tableNotifications, $language, $t . "\t")];
604
            $cases['new']    = [$this->getUserPagesNew($tableName, $tableSoleName, $tablePermissions, $language, $t . "\t")];
605
            $cases['edit']   = [$this->getUserPagesEdit($tableName, $tableSoleName, $tablePermissions, $fieldId, $language, $t . "\t")];
606
            $cases['clone']  = [$this->getUserPagesClone($tableName, $tableSoleName, $tablePermissions, $fieldId, $language, $t . "\t")];
607
            $cases['delete'] = [$this->getUserPagesDelete($tableName, $tableSoleName, $tablePermissions, $language, $fieldId, $fieldMain, $tableNotifications,$t . "\t")];
608
        }
609
        if (1 == $tableBroken) {
610
            $cases['broken']  = [$this->getUserPagesBroken($language, $moduleDirname, $tableName, $tableSoleName, $fieldId, $fieldStatus, $fieldMain, $tableNotifications, $t . "\t")];
611
        }
612
613
        return $this->xc->getXcSwitch('op', $cases, true, false);
614
    }
615
616
    /**
617
     * @public function render
618
     * @param null
619
     * @return bool|string
620
     */
621
    public function render()
622
    {
623
        $module             = $this->getModule();
624
        $table              = $this->getTable();
625
        $tableId            = $table->getVar('table_id');
626
        $tableMid           = $table->getVar('table_mid');
627
        $tableName          = $table->getVar('table_name');
628
        $tableSubmit        = $table->getVar('table_submit');
629
        $tablePermissions   = $table->getVar('table_permissions');
630
        $tableSoleName      = $table->getVar('table_solename');
631
        $tableBroken        = $table->getVar('table_broken');
632
        $tableNotifications = $table->getVar('table_notifications');
633
        $tableComments      = $table->getVar('table_comments');
634
        $tableRate          = $table->getVar('table_rate');
635
        $filename           = $this->getFileName();
636
        $moduleDirname      = $module->getVar('mod_dirname');
637
        $language           = $this->getLanguage($moduleDirname, 'MA');
638
639
        // Fields
640
        $fieldId    = '';
641
        $fieldMain  = '';
642
        $fieldStatus = '';
643
        $fieldReads = '';
644
        $fields    = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
645
        foreach (\array_keys($fields) as $f) {
646
            $fieldName = $fields[$f]->getVar('field_name');
647
            if (0 == $f) {
648
                $fieldId = $fieldName;
649
            }
650
            if (1 == $fields[$f]->getVar('field_main')) {
651
                $fieldMain = $fieldName; // fields parameters main field
652
            }
653
            if (Constants::FIELD_ELE_SELECTSTATUS == $fields[$f]->getVar('field_element')) {
654
                $fieldStatus = $fieldName; // fields for status
655
            }
656
            if (Constants::FIELD_ELE_TEXTREADS == $fields[$f]->getVar('field_element')) {
657
                $fieldReads = $fieldName; // fields for count reads
658
            }
659
        }
660
        $content = $this->getHeaderFilesComments($module);
661
        $content .= $this->getUserPagesHeader($moduleDirname, $tableName, $fieldId, $tablePermissions, $language);
662
        $content .= $this->getUserPagesSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tablePermissions, $tableBroken, $fieldId, $fieldMain, $fieldStatus, $tableNotifications, $tableRate, $fieldReads, $language, "\t");
663
        $content .= $this->getUserPagesFooter($moduleDirname, $tableName, $tableComments, $language);
664
665
        $this->create($moduleDirname, '/', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
666
667
        return $this->renderFile();
668
    }
669
}
670