Passed
Push — master ( 1f7c29...9231af )
by Michael
09:42
created

updateBlock()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 35
rs 8.5706
cc 7
nc 6
nop 9

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://xoops.org
13
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
16
use Xmf\Request;
17
use XoopsModules\Extcal\{
18
    Form
19
};
20
21
require __DIR__ . '/admin_header.php';
22
23
$moduleDirName      = basename(dirname(__DIR__));
24
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
25
26
global $xoopsModule;
27
28
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
29
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
30
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
31
}
32
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
33
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
34
    $op = 'list';
35
    if (isset($_POST)) {
36
        foreach ($_POST as $k => $v) {
37
            ${$k} = $v;
38
        }
39
    }
40
    /*
41
        if (Request::hasVar('op')) {
42
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
43
                || $_GET['op'] === "edit"
44
            ) {
45
                $op  = $_GET['op'];
46
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
47
            }
48
        }
49
    */
50
51
    $op = Request::getString('op', $op);
52
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
53
        $bid = Request::getInt('bid', 0, 'GET');
54
    }
55
56
    function listBlocks()
57
    {
58
        global $xoopsModule, $pathIcon16;
59
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
60
        $moduleDirName      = basename(dirname(__DIR__));
61
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
62
        $db                 = \XoopsDatabaseFactory::getDatabaseConnection();
63
        xoops_loadLanguage('admin', 'system');
64
        xoops_loadLanguage('admin/blocksadmin', 'system');
65
        xoops_loadLanguage('admin/groups', 'system');
66
67
        /** @var \XoopsModuleHandler $moduleHandler */
68
        $moduleHandler = xoops_getHandler('module');
69
        /** @var \XoopsMemberHandler $memberHandler */
70
        $memberHandler = xoops_getHandler('member');
71
        /** @var \XoopsGroupPermHandler $grouppermHandler */
72
        $grouppermHandler = xoops_getHandler('groupperm');
73
        $groups           = $memberHandler->getGroups();
74
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
75
        $criteria->add(new \Criteria('isactive', 1));
76
        $module_list     = $moduleHandler->getList($criteria);
77
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
78
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
79
        ksort($module_list);
80
        echo "
81
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
82
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleHandler is dead and can be removed.
Loading history...
83
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
84
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
85
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
86
        <tr valign='middle'><th align='center'>"
87
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
88
             . "</th><th align='center' nowrap='nowrap'>"
89
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
90
             . '<br>'
91
             . _LEFT
92
             . '-'
93
             . _CENTER
94
             . '-'
95
             . _RIGHT
96
             . "</th><th align='center'>"
97
             . constant(
98
                 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'
99
             )
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
        $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

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

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

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

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