Passed
Pull Request — master (#5)
by Michael
02:50
created

updateBlock()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 24
nc 6
nop 9
dl 0
loc 32
rs 8.6026
c 1
b 0
f 0

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

113
        /** @scrutinizer ignore-call */ 
114
        $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...
114
        $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...
115
        $class       = 'even';
116
        $cachetimes  = [
117
            '0'       => _NOCACHE,
118
            '30'      => sprintf(_SECONDS, 30),
119
            '60'      => _MINUTE,
120
            '300'     => sprintf(_MINUTES, 5),
121
            '1800'    => sprintf(_MINUTES, 30),
122
            '3600'    => _HOUR,
123
            '18000'   => sprintf(_HOURS, 5),
124
            '86400'   => _DAY,
125
            '259200'  => sprintf(_DAYS, 3),
126
            '604800'  => _WEEK,
127
            '2592000' => _MONTH
128
        ];
129
        foreach ($block_arr as $i) {
130
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
131
            $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
132
            $result       = $db->query($sql);
133
            $modules      = [];
134
            while (false !== ($row = $db->fetchArray($result))) {
135
                $modules[] = (int)$row['module_id'];
136
            }
137
138
            $cachetime_options = '';
139
            foreach ($cachetimes as $cachetime => $cachetime_name) {
140
                if ($i->getVar('bcachetime') == $cachetime) {
141
                    $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n";
142
                } else {
143
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
144
                }
145
            }
146
147
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
148
            if (1 === $i->getVar('visible')) {
149
                $sel1 = ' checked';
150
            } else {
151
                $sel0 = ' checked';
152
            }
153
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
154
                $ssel0 = ' checked';
155
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
156
                $ssel1 = ' checked';
157
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
158
                $ssel2 = ' checked';
159
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
160
                $ssel4 = ' checked';
161
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
162
                $ssel3 = ' checked';
163
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
164
                $ssel5 = ' checked';
165
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
166
                $ssel6 = ' checked';
167
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
168
                $ssel7 = ' checked';
169
            }
170
            if ('' === $i->getVar('title')) {
171
                $title = '&nbsp;';
172
            } else {
173
                $title = $i->getVar('title');
174
            }
175
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
176
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
177
                 . $i->getVar('bid')
178
                 . "]' value='"
179
                 . $title
180
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
181
                    <div align='center' >
182
                    <input type='radio' name='side["
183
                 . $i->getVar('bid')
184
                 . "]' value='"
185
                 . XOOPS_CENTERBLOCK_LEFT
186
                 . "'$ssel2>
187
                        <input type='radio' name='side["
188
                 . $i->getVar('bid')
189
                 . "]' value='"
190
                 . XOOPS_CENTERBLOCK_CENTER
191
                 . "'$ssel3>
192
                    <input type='radio' name='side["
193
                 . $i->getVar('bid')
194
                 . "]' value='"
195
                 . XOOPS_CENTERBLOCK_RIGHT
196
                 . "'$ssel4>
197
                    </div>
198
                    <div>
199
                        <span style='float:right;'><input type='radio' name='side["
200
                 . $i->getVar('bid')
201
                 . "]' value='"
202
                 . XOOPS_SIDEBLOCK_RIGHT
203
                 . "'$ssel1></span>
204
                    <div align='left'><input type='radio' name='side["
205
                 . $i->getVar('bid')
206
                 . "]' value='"
207
                 . XOOPS_SIDEBLOCK_LEFT
208
                 . "'$ssel0></div>
209
                    </div>
210
                    <div align='center'>
211
                    <input type='radio' name='side["
212
                 . $i->getVar('bid')
213
                 . "]' value='"
214
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
215
                 . "'$ssel5>
216
                        <input type='radio' name='side["
217
                 . $i->getVar('bid')
218
                 . "]' value='"
219
                 . XOOPS_CENTERBLOCK_BOTTOM
220
                 . "'$ssel7>
221
                    <input type='radio' name='side["
222
                 . $i->getVar('bid')
223
                 . "]' value='"
224
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
225
                 . "'$ssel6>
226
                    </div>
227
                </td><td class='$class' align='center'><input type='text' name='weight["
228
                 . $i->getVar('bid')
229
                 . "]' value='"
230
                 . $i->getVar('weight')
231
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
232
                 . $i->getVar('bid')
233
                 . "]' value='1'$sel1>"
234
                 . _YES
235
                 . "&nbsp;<input type='radio' name='visible["
236
                 . $i->getVar('bid')
237
                 . "]' value='0'$sel0>"
238
                 . _NO
239
                 . '</td>';
240
241
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
242
            foreach ($module_list as $k => $v) {
243
                echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
244
            }
245
            echo '</select></td>';
246
247
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
248
            foreach ($groups as $grp) {
249
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
250
            }
251
            echo '</select></td>';
252
253
            // Cache lifetime
254
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
255
                                    </td>';
256
257
            // Actions
258
259
            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 . "'>
260
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
261
                 </a>";
262
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
263
                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 . "'>
264
                     </a>";
265
            }
266
            echo "
267
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
268
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
269
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
270
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
271
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
272
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
273
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
274
            </td></tr>
275
            ";
276
            $class = ('even' === $class) ? 'odd' : 'even';
277
        }
278
        echo "<tr><td class='foot' align='center' colspan='7'>
279
        <input type='hidden' name='op' value='order'>
280
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
281
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
282
        </td></tr></table>
283
        </form>
284
        <br><br>";
285
    }
286
287
    /**
288
     * @param $bid
289
     */
290
    function cloneBlock($bid)
291
    {
292
        require_once __DIR__ . '/admin_header.php';
293
        //require_once __DIR__ . '/admin_header.php';
294
        xoops_cp_header();
295
296
        xoops_loadLanguage('admin', 'system');
297
        xoops_loadLanguage('admin/blocksadmin', 'system');
298
        xoops_loadLanguage('admin/groups', 'system');
299
300
        //        mpu_adm_menu();
301
        $myblock = new \XoopsBlock($bid);
302
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
303
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
304
        $result  = $db->query($sql);
305
        $modules = [];
306
        while (false !== ($row = $db->fetchArray($result))) {
307
            $modules[] = (int)$row['module_id'];
308
        }
309
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
310
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
311
            'title'      => $myblock->getVar('title') . ' Clone',
312
            '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...
313
            'name'       => $myblock->getVar('name'),
314
            'side'       => $myblock->getVar('side'),
315
            'weight'     => $myblock->getVar('weight'),
316
            'visible'    => $myblock->getVar('visible'),
317
            'content'    => $myblock->getVar('content', 'N'),
318
            'modules'    => $modules,
319
            'is_custom'  => $is_custom,
320
            'ctype'      => $myblock->getVar('c_type'),
321
            'bcachetime' => $myblock->getVar('bcachetime'),
322
            'op'         => 'clone_ok',
323
            'bid'        => $myblock->getVar('bid'),
324
            'edit_form'  => $myblock->getOptions(),
325
            'template'   => $myblock->getVar('template'),
326
            'options'    => $myblock->getVar('options')
327
        ];
328
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
329
        require_once __DIR__ . '/blockform.php';
330
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
331
        //        xoops_cp_footer();
332
        require_once __DIR__ . '/admin_footer.php';
333
        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...
334
    }
335
336
    /**
337
     * @param $bid
338
     * @param $bside
339
     * @param $bweight
340
     * @param $bvisible
341
     * @param $bcachetime
342
     * @param $bmodule
343
     * @param $options
344
     */
345
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
346
    {
347
        xoops_loadLanguage('admin', 'system');
348
        xoops_loadLanguage('admin/blocksadmin', 'system');
349
        xoops_loadLanguage('admin/groups', 'system');
350
351
        /** @var \XoopsBlock $block */
352
        $block = new \XoopsBlock($bid);
353
        $clone = $block->xoopsClone();
354
        if (empty($bmodule)) {
355
            xoops_cp_header();
356
            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...
357
            xoops_cp_footer();
358
            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...
359
        }
360
        $clone->setVar('side', $bside);
361
        $clone->setVar('weight', $bweight);
362
        $clone->setVar('visible', $bvisible);
363
        //$clone->setVar('content', $_POST['bcontent']);
364
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
365
        $clone->setVar('bcachetime', $bcachetime);
366
        if (isset($options) && (count($options) > 0)) {
367
            $options = implode('|', $options);
368
            $clone->setVar('options', $options);
369
        }
370
        $clone->setVar('bid', 0);
371
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
372
            $clone->setVar('block_type', 'E');
373
        } else {
374
            $clone->setVar('block_type', 'D');
375
        }
376
        $newid = $clone->store();
377
        if (!$newid) {
378
            xoops_cp_header();
379
            $clone->getHtmlErrors();
380
            xoops_cp_footer();
381
            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...
382
        }
383
        if ('' !== $clone->getVar('template')) {
384
            /** @var \XoopsTplfileHandler $tplfileHandler */
385
            $tplfileHandler = xoops_getHandler('tplfile');
386
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
387
            if (count($btemplate) > 0) {
388
                $tplclone = $btemplate[0]->xoopsClone();
389
                $tplclone->setVar('tpl_id', 0);
390
                $tplclone->setVar('tpl_refid', $newid);
391
                $tplfileHandler->insert($tplclone);
392
            }
393
        }
394
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
395
        foreach ($bmodule as $bmid) {
396
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
397
            $db->query($sql);
398
        }
399
        $groups =& $GLOBALS['xoopsUser']->getGroups();
400
        $count  = count($groups);
401
        for ($i = 0; $i < $count; ++$i) {
402
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
403
            $db->query($sql);
404
        }
405
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
406
    }
407
408
    /**
409
     * @param $bid
410
     * @param $title
411
     * @param $weight
412
     * @param $visible
413
     * @param $side
414
     * @param $bcachetime
415
     */
416
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime)
417
    {
418
        $myblock = new \XoopsBlock($bid);
419
        $myblock->setVar('title', $title);
420
        $myblock->setVar('weight', $weight);
421
        $myblock->setVar('visible', $visible);
422
        $myblock->setVar('side', $side);
423
        $myblock->setVar('bcachetime', $bcachetime);
424
        $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

424
        $myblock->/** @scrutinizer ignore-call */ 
425
                  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...
425
    }
426
427
    /**
428
     * @param $bid
429
     */
430
    function editBlock($bid)
431
    {
432
        require_once __DIR__ . '/admin_header.php';
433
        //require_once __DIR__ . '/admin_header.php';
434
        xoops_cp_header();
435
436
        xoops_loadLanguage('admin', 'system');
437
        xoops_loadLanguage('admin/blocksadmin', 'system');
438
        xoops_loadLanguage('admin/groups', 'system');
439
        //        mpu_adm_menu();
440
        $myblock = new \XoopsBlock($bid);
441
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
442
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
443
        $result  = $db->query($sql);
444
        $modules = [];
445
        while (false !== ($row = $db->fetchArray($result))) {
446
            $modules[] = (int)$row['module_id'];
447
        }
448
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
449
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
450
            'title'      => $myblock->getVar('title'),
451
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper seems to be never defined.
Loading history...
452
            //        'name'       => $myblock->getVar('name'),
453
            'side'       => $myblock->getVar('side'),
454
            'weight'     => $myblock->getVar('weight'),
455
            'visible'    => $myblock->getVar('visible'),
456
            'content'    => $myblock->getVar('content', 'N'),
457
            'modules'    => $modules,
458
            'is_custom'  => $is_custom,
459
            'ctype'      => $myblock->getVar('c_type'),
460
            'bcachetime' => $myblock->getVar('bcachetime'),
461
            'op'         => 'edit_ok',
462
            'bid'        => $myblock->getVar('bid'),
463
            'edit_form'  => $myblock->getOptions(),
464
            'template'   => $myblock->getVar('template'),
465
            'options'    => $myblock->getVar('options')
466
        ];
467
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
468
        require_once __DIR__ . '/blockform.php';
469
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
470
        //        xoops_cp_footer();
471
        require_once __DIR__ . '/admin_footer.php';
472
        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...
473
    }
474
475
    /**
476
     * @param $bid
477
     * @param $btitle
478
     * @param $bside
479
     * @param $bweight
480
     * @param $bvisible
481
     * @param $bcachetime
482
     * @param $bmodule
483
     * @param $options
484
     * @param $groups
485
     */
486
    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

486
    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...
487
    {
488
        $myblock = new \XoopsBlock($bid);
489
        $myblock->setVar('title', $btitle);
490
        $myblock->setVar('weight', $bweight);
491
        $myblock->setVar('visible', $bvisible);
492
        $myblock->setVar('side', $bside);
493
        $myblock->setVar('bcachetime', $bcachetime);
494
        $myblock->store();
495
496
        if (!empty($bmodule) && count($bmodule) > 0) {
497
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
498
            $GLOBALS['xoopsDB']->query($sql);
499
            if (in_array(0, $bmodule)) {
500
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
501
                $GLOBALS['xoopsDB']->query($sql);
502
            } else {
503
                foreach ($bmodule as $bmid) {
504
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
505
                    $GLOBALS['xoopsDB']->query($sql);
506
                }
507
            }
508
        }
509
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
510
        $GLOBALS['xoopsDB']->query($sql);
511
        if (!empty($groups)) {
512
            foreach ($groups as $grp) {
513
                $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid);
514
                $GLOBALS['xoopsDB']->query($sql);
515
            }
516
        }
517
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
518
    }
519
520
    if ('list' === $op) {
521
        xoops_cp_header();
522
        //        mpu_adm_menu();
523
        listBlocks();
524
        require_once __DIR__ . '/admin_footer.php';
525
        exit();
526
    }
527
528
    if ('order' === $op) {
529
        if (!$GLOBALS['xoopsSecurity']->check()) {
530
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
531
        }
532
        foreach (array_keys($bid) as $i) {
533
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
534
                || $oldside[$i] !== $side[$i]
535
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
536
                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

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