Passed
Push — master ( 4f2b44...e97b8d )
by Michael
01:58
created

updateBlock()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 27
c 1
b 0
f 0
nc 6
nop 9
dl 0
loc 37
rs 8.5546

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * PHP version 5
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project
12
 * @link            https://www.xoops.org
13
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
use Xmf\Request;
16
17
require __DIR__ . '/admin_header.php';
18
19
$moduleDirName = basename(dirname(__DIR__));
20
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
21
22
$helper->loadLanguage('blocksadmin');
23
24
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
25
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
26
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
27
}
28
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
29
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
30
    $op = 'list';
31
    if (isset($_POST)) {
32
        foreach ($_POST as $k => $v) {
33
            ${$k} = $v;
34
        }
35
    }
36
    /*
37
    if (\Xmf\Request::hasVar('op', 'GET')) {
38
        if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op']
39
            || 'edit' === $_GET['op']) {
40
            $op  = $_GET['op'];
41
            $bid = \Xmf\Request::getInt('bid', 0, 'GET');
42
        }
43
    */
44
45
    $op = Request::getString('op', $op);
46
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
47
        $bid = Request::getInt('bid', 0, 'GET');
48
    }
49
50
    function listBlocks()
51
    {
52
        global $xoopsModule, $pathIcon16;
53
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
54
        $moduleDirName = basename(dirname(__DIR__));
55
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
56
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
57
        xoops_loadLanguage('admin', 'system');
58
        xoops_loadLanguage('admin/blocksadmin', 'system');
59
        xoops_loadLanguage('admin/groups', 'system');
60
61
        /** @var \XoopsModuleHandler $moduleHandler */
62
        $moduleHandler = xoops_getHandler('module');
63
        /** @var \XoopsMemberHandler $memberHandler */
64
        $memberHandler = xoops_getHandler('member');
65
        /** @var \XoopsGroupPermHandler $grouppermHandler */
66
        $grouppermHandler = xoops_getHandler('groupperm');
67
        $groups = $memberHandler->getGroups();
68
        $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1));
69
        $criteria->add(new \Criteria('isactive', 1));
70
        $module_list = $moduleHandler->getList($criteria);
71
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
72
        $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES;
73
        ksort($module_list);
74
        echo "
75
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
76
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleHandler is dead and can be removed.
Loading history...
77
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
78
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
79
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
80
        <tr valign='middle'><th align='center'>"
81
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
82
             . "</th><th align='center' nowrap='nowrap'>"
83
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
84
             . '<br>'
85
             . _LEFT
86
             . '-'
87
             . _CENTER
88
             . '-'
89
             . _RIGHT
90
             . "</th><th align='center'>"
91
             . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT')
92
             . "</th><th align='center'>"
93
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
94
             . "</th><th align='center'>"
95
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
96
             . "</th><th align='center'>"
97
             . _AM_SYSTEM_ADGS
98
             . "</th><th align='center'>"
99
             . _AM_SYSTEM_BLOCKS_BCACHETIME
100
             . "</th><th align='center'>"
101
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
102
             . '</th></tr>
103
        ';
104
        $block_arr = \XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
Bug introduced by
The method getByModule() does not exist on XoopsBlock. ( Ignorable by Annotation )

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

104
        /** @scrutinizer ignore-call */ 
105
        $block_arr = \XoopsBlock::getByModule($xoopsModule->mid());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
        $block_count = count($block_arr);
0 ignored issues
show
Unused Code introduced by
The assignment to $block_count is dead and can be removed.
Loading history...
106
        $class = 'even';
107
        $cachetimes = [
108
            '0' => _NOCACHE,
109
            '30' => sprintf(_SECONDS, 30),
110
            '60' => _MINUTE,
111
            '300' => sprintf(_MINUTES, 5),
112
            '1800' => sprintf(_MINUTES, 30),
113
            '3600' => _HOUR,
114
            '18000' => sprintf(_HOURS, 5),
115
            '86400' => _DAY,
116
            '259200' => sprintf(_DAYS, 3),
117
            '604800' => _WEEK,
118
            '2592000' => _MONTH,
119
        ];
120
        foreach ($block_arr as $i) {
121
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
122
            $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
123
            $result = $db->query($sql);
124
            $modules = [];
125
            while (false !== ($row = $db->fetchArray($result))) {
126
                $modules[] = (int)$row['module_id'];
127
            }
128
129
            $cachetime_options = '';
130
            foreach ($cachetimes as $cachetime => $cachetime_name) {
131
                if ($i->getVar('bcachetime') == $cachetime) {
132
                    $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n";
133
                } else {
134
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
135
                }
136
            }
137
138
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
139
            if (1 === $i->getVar('visible')) {
140
                $sel1 = ' checked';
141
            } else {
142
                $sel0 = ' checked';
143
            }
144
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
145
                $ssel0 = ' checked';
146
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
147
                $ssel1 = ' checked';
148
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
149
                $ssel2 = ' checked';
150
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
151
                $ssel4 = ' checked';
152
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
153
                $ssel3 = ' checked';
154
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
155
                $ssel5 = ' checked';
156
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
157
                $ssel6 = ' checked';
158
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
159
                $ssel7 = ' checked';
160
            }
161
            if ('' === $i->getVar('title')) {
162
                $title = '&nbsp;';
163
            } else {
164
                $title = $i->getVar('title');
165
            }
166
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
167
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
168
                 . $i->getVar('bid')
169
                 . "]' value='"
170
                 . $title
171
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
172
                    <div align='center' >
173
                    <input type='radio' name='side["
174
                 . $i->getVar('bid')
175
                 . "]' value='"
176
                 . XOOPS_CENTERBLOCK_LEFT
177
                 . "'$ssel2>
178
                        <input type='radio' name='side["
179
                 . $i->getVar('bid')
180
                 . "]' value='"
181
                 . XOOPS_CENTERBLOCK_CENTER
182
                 . "'$ssel3>
183
                    <input type='radio' name='side["
184
                 . $i->getVar('bid')
185
                 . "]' value='"
186
                 . XOOPS_CENTERBLOCK_RIGHT
187
                 . "'$ssel4>
188
                    </div>
189
                    <div>
190
                        <span style='float:right;'><input type='radio' name='side["
191
                 . $i->getVar('bid')
192
                 . "]' value='"
193
                 . XOOPS_SIDEBLOCK_RIGHT
194
                 . "'$ssel1></span>
195
                    <div align='left'><input type='radio' name='side["
196
                 . $i->getVar('bid')
197
                 . "]' value='"
198
                 . XOOPS_SIDEBLOCK_LEFT
199
                 . "'$ssel0></div>
200
                    </div>
201
                    <div align='center'>
202
                    <input type='radio' name='side["
203
                 . $i->getVar('bid')
204
                 . "]' value='"
205
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
206
                 . "'$ssel5>
207
                        <input type='radio' name='side["
208
                 . $i->getVar('bid')
209
                 . "]' value='"
210
                 . XOOPS_CENTERBLOCK_BOTTOM
211
                 . "'$ssel7>
212
                    <input type='radio' name='side["
213
                 . $i->getVar('bid')
214
                 . "]' value='"
215
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
216
                 . "'$ssel6>
217
                    </div>
218
                </td><td class='$class' align='center'><input type='text' name='weight["
219
                 . $i->getVar('bid')
220
                 . "]' value='"
221
                 . $i->getVar('weight')
222
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
223
                 . $i->getVar('bid')
224
                 . "]' value='1'$sel1>"
225
                 . _YES
226
                 . "&nbsp;<input type='radio' name='visible["
227
                 . $i->getVar('bid')
228
                 . "]' value='0'$sel0>"
229
                 . _NO
230
                 . '</td>';
231
232
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
233
            foreach ($module_list as $k => $v) {
234
                echo "<option value='$k'" . (in_array($k, $modules) ? 'selected' : '') . ">$v</option>";
235
            }
236
            echo '</select></td>';
237
238
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
239
            foreach ($groups as $grp) {
240
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? 'selected' : '') . '>' . $grp->getVar('name') . '</option>';
241
            }
242
            echo '</select></td>';
243
244
            // Cache lifetime
245
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
246
                                    </td>';
247
248
            // Actions
249
250
            echo "<td class='$class' align='center'><a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>
251
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
252
                 </a>";
253
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
254
                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
255
                     </a>";
256
            }
257
            echo "
258
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
259
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
260
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
261
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
262
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
263
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
264
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
265
            </td></tr>
266
            ";
267
            $class = ('even' === $class) ? 'odd' : 'even';
268
        }
269
        echo "<tr><td class='foot' align='center' colspan='8'>
270
        <input type='hidden' name='op' value='order'>
271
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
272
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
273
        </td></tr></table>
274
        </form>
275
        <br><br>";
276
    }
277
278
    /**
279
     * @param int $bid
280
     */
281
    function cloneBlock($bid)
282
    {
283
        require_once __DIR__ . '/admin_header.php';
284
        //require_once __DIR__ . '/admin_header.php';
285
        xoops_cp_header();
286
287
        xoops_loadLanguage('admin', 'system');
288
        xoops_loadLanguage('admin/blocksadmin', 'system');
289
        xoops_loadLanguage('admin/groups', 'system');
290
291
        //        mpu_adm_menu();
292
        $myblock = new \XoopsBlock($bid);
293
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
294
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
295
        $result = $db->query($sql);
296
        $modules = [];
297
        while (false !== ($row = $db->fetchArray($result))) {
298
            $modules[] = (int)$row['module_id'];
299
        }
300
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
301
        $block = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
302
            'title' => $myblock->getVar('title') . ' Clone',
303
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper seems to be never defined.
Loading history...
304
            'name' => $myblock->getVar('name'),
305
            'side' => $myblock->getVar('side'),
306
            'weight' => $myblock->getVar('weight'),
307
            'visible' => $myblock->getVar('visible'),
308
            'content' => $myblock->getVar('content', 'N'),
309
            'modules' => $modules,
310
            'is_custom' => $is_custom,
311
            'ctype' => $myblock->getVar('c_type'),
312
            'bcachetime' => $myblock->getVar('bcachetime'),
313
            'op' => 'clone_ok',
314
            'bid' => $myblock->getVar('bid'),
315
            'edit_form' => $myblock->getOptions(),
316
            'template' => $myblock->getVar('template'),
317
            'options' => $myblock->getVar('options'),
318
        ];
319
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
320
        require_once __DIR__ . '/blockform.php';
321
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
322
        //        xoops_cp_footer();
323
        require_once __DIR__ . '/admin_footer.php';
324
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
325
    }
326
327
    /**
328
     * @param int               $bid
329
     * @param string            $bside
330
     * @param int               $bweight
331
     * @param bool              $bvisible
332
     * @param int               $bcachetime
333
     * @param array             $bmodule
334
     * @param null|array|string $options
335
     */
336
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
337
    {
338
        xoops_loadLanguage('admin', 'system');
339
        xoops_loadLanguage('admin/blocksadmin', 'system');
340
        xoops_loadLanguage('admin/groups', 'system');
341
342
        /** @var \XoopsBlock $block */
343
        $block = new \XoopsBlock($bid);
344
        $clone = $block->xoopsClone();
345
        if (empty($bmodule)) {
346
            xoops_cp_header();
347
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
0 ignored issues
show
Bug introduced by
The constant _AM_NOTSELNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
348
            xoops_cp_footer();
349
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
350
        }
351
        $clone->setVar('side', $bside);
352
        $clone->setVar('weight', $bweight);
353
        $clone->setVar('visible', $bvisible);
354
        //$clone->setVar('content', $_POST['bcontent']);
355
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
356
        $clone->setVar('bcachetime', $bcachetime);
357
        if (isset($options) && (count($options) > 0)) {
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

357
        if (isset($options) && (count(/** @scrutinizer ignore-type */ $options) > 0)) {
Loading history...
358
            $options = implode('|', $options);
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

358
            $options = implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
359
            $clone->setVar('options', $options);
360
        }
361
        $clone->setVar('bid', 0);
362
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
363
            $clone->setVar('block_type', 'E');
364
        } else {
365
            $clone->setVar('block_type', 'D');
366
        }
367
        $newid = $clone->store();
368
        if (!$newid) {
369
            xoops_cp_header();
370
            $clone->getHtmlErrors();
371
            xoops_cp_footer();
372
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
373
        }
374
        if ('' !== $clone->getVar('template')) {
375
            /** @var \XoopsTplfileHandler $tplfileHandler */
376
            $tplfileHandler = xoops_getHandler('tplfile');
377
            $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
378
            if (count($btemplate) > 0) {
379
                $tplclone = $btemplate[0]->xoopsClone();
380
                $tplclone->setVar('tpl_id', 0);
381
                $tplclone->setVar('tpl_refid', $newid);
382
                $tplfileHandler->insert($tplclone);
383
            }
384
        }
385
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
386
        foreach ($bmodule as $bmid) {
387
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
388
            $db->query($sql);
389
        }
390
        $groups = &$GLOBALS['xoopsUser']->getGroups();
391
        $count = count($groups);
392
        for ($i = 0; $i < $count; ++$i) {
393
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
394
            $db->query($sql);
395
        }
396
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
397
    }
398
399
    /**
400
     * @param int               $bid
401
     * @param string            $title
402
     * @param int               $weight
403
     * @param bool              $visible
404
     * @param string            $side
405
     * @param int               $bcachetime
406
     */
407
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime)
408
    {
409
        $myblock = new \XoopsBlock($bid);
410
        $myblock->setVar('title', $title);
411
        $myblock->setVar('weight', $weight);
412
        $myblock->setVar('visible', $visible);
413
        $myblock->setVar('side', $side);
414
        $myblock->setVar('bcachetime', $bcachetime);
415
        $myblock->store();
0 ignored issues
show
Bug introduced by
The method store() does not exist on XoopsBlock. ( Ignorable by Annotation )

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

415
        $myblock->/** @scrutinizer ignore-call */ 
416
                  store();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
416
    }
417
418
    /**
419
     * @param int $bid
420
     */
421
    function editBlock($bid)
422
    {
423
        require_once __DIR__ . '/admin_header.php';
424
        //require_once __DIR__ . '/admin_header.php';
425
        xoops_cp_header();
426
        $moduleDirName = basename(dirname(__DIR__));
427
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
428
        xoops_loadLanguage('admin', 'system');
429
        xoops_loadLanguage('admin/blocksadmin', 'system');
430
        xoops_loadLanguage('admin/groups', 'system');
431
        //        mpu_adm_menu();
432
        $myblock = new \XoopsBlock($bid);
433
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
434
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
435
        $result = $db->query($sql);
436
        $modules = [];
437
        while (false !== ($row = $db->fetchArray($result))) {
438
            $modules[] = (int)$row['module_id'];
439
        }
440
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
441
        $block = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
442
            'title' => $myblock->getVar('title'),
443
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
444
            //        'name'       => $myblock->getVar('name'),
445
            'side' => $myblock->getVar('side'),
446
            'weight' => $myblock->getVar('weight'),
447
            'visible' => $myblock->getVar('visible'),
448
            'content' => $myblock->getVar('content', 'N'),
449
            'modules' => $modules,
450
            'is_custom' => $is_custom,
451
            'ctype' => $myblock->getVar('c_type'),
452
            'bcachetime' => $myblock->getVar('bcachetime'),
453
            'op' => 'edit_ok',
454
            'bid' => $myblock->getVar('bid'),
455
            'edit_form' => $myblock->getOptions(),
456
            'template' => $myblock->getVar('template'),
457
            'options' => $myblock->getVar('options'),
458
        ];
459
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
460
        require_once __DIR__ . '/blockform.php';
461
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
462
        //        xoops_cp_footer();
463
        require_once __DIR__ . '/admin_footer.php';
464
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
465
    }
466
467
    /**
468
     * @param int $bid
469
     * @param $btitle
470
     * @param $bside
471
     * @param $bweight
472
     * @param $bvisible
473
     * @param $bcachetime
474
     * @param $bmodule
475
     * @param $options
476
     * @param $groups
477
     */
478
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

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

478
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, /** @scrutinizer ignore-unused */ $options, $groups)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
479
    {
480
        $myblock = new \XoopsBlock($bid);
481
        $myblock->setVar('title', $btitle);
482
        $myblock->setVar('weight', $bweight);
483
        $myblock->setVar('visible', $bvisible);
484
        $myblock->setVar('side', $bside);
485
        $myblock->setVar('bcachetime', $bcachetime);
486
        $myblock->store();
487
488
        global $xoopsDB;
489
490
        $moduleDirName = basename(dirname(__DIR__));
491
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
492
493
        if (!empty($bmodule) && count($bmodule) > 0) {
494
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
495
            $xoopsDB->query($sql);
496
            if (in_array(0, $bmodule)) {
497
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, 0);
498
                $xoopsDB->query($sql);
499
            } else {
500
                foreach ($bmodule as $bmid) {
501
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, (int)$bmid);
502
                    $xoopsDB->query($sql);
503
                }
504
            }
505
        }
506
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
507
        $xoopsDB->query($sql);
508
        if (!empty($groups)) {
509
            foreach ($groups as $grp) {
510
                $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid);
511
                $xoopsDB->query($sql);
512
            }
513
        }
514
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
515
    }
516
517
    if ('list' === $op) {
518
        xoops_cp_header();
519
        //        mpu_adm_menu();
520
        listBlocks();
521
        require_once __DIR__ . '/admin_footer.php';
522
        exit();
523
    }
524
525
    if ('order' === $op) {
526
        if (!$GLOBALS['xoopsSecurity']->check()) {
527
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
528
        }
529
        foreach (array_keys($bid) as $i) {
530
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i]
531
                || $oldside[$i] != $side[$i]
532
                || $oldbcachetime[$i] != $bcachetime[$i]) {
533
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
0 ignored issues
show
Unused Code introduced by
The call to setOrder() has too many arguments starting with $bmodule[$i]. ( Ignorable by Annotation )

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

533
                /** @scrutinizer ignore-call */ 
534
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
534
            }
535
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
536
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid[$i]);
537
                $xoopsDB->query($sql);
538
                if (in_array(0, $bmodule[$i])) {
539
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], 0);
540
                    $xoopsDB->query($sql);
541
                } else {
542
                    foreach ($bmodule[$i] as $bmid) {
543
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], (int)$bmid);
544
                        $xoopsDB->query($sql);
545
                    }
546
                }
547
            }
548
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid[$i]);
549
            $xoopsDB->query($sql);
550
            if (!empty($groups[$i])) {
551
                foreach ($groups[$i] as $grp) {
552
                    $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid[$i]);
553
                    $xoopsDB->query($sql);
554
                }
555
            }
556
        }
557
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
558
    }
559
    if ('clone' === $op) {
560
        cloneBlock($bid);
561
    }
562
563
    if ('edit' === $op) {
564
        editBlock($bid);
565
    }
566
567
    if ('edit_ok' === $op) {
568
        updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
569
    }
570
571
    if ('clone_ok' === $op) {
572
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
573
    }
574
} else {
575
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
576
}
577