Passed
Push — master ( 4761c2...696f77 )
by
unknown
05:50 queued 19s
created

admin/blocksadmin.php (7 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * PHP version 5
11
 *
12
 * @category        Module
13
 * @author          XOOPS Development Team
14
 * @copyright       XOOPS Project
15
 * @link            https://xoops.org
16
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 */
18
19
use Xmf\Request;
20
21
require __DIR__ . '/admin_header.php';
22
$moduleDirName      = basename(dirname(__DIR__));
23
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
24
//$helper = \XoopsModules\Suico\Helper::getInstance();
25
//$helper->loadLanguage('blocksadmin');
26
xoops_loadLanguage('blocksadmin', $moduleDirName);
27
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
28
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
29
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
30
}
31
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
32
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
33
    $op = 'list';
34
    if (isset($_POST)) {
35
        foreach ($_POST as $k => $v) {
36
            ${$k} = $v;
37
        }
38
    }
39
40
    $op = Request::getString(
41
        'op',
42
        $op
43
    );
44
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'], true)) {
45
        $bid = Request::getInt('bid', 0, 'GET');
46
    }
47
    function listBlocks()
48
    {
49
        global $xoopsModule, $pathIcon16;
50
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
51
        $moduleDirName      = basename(dirname(__DIR__));
52
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
53
        $db                 = XoopsDatabaseFactory::getDatabaseConnection();
54
        xoops_loadLanguage('admin', 'system');
55
        xoops_loadLanguage('admin/blocksadmin', 'system');
56
        xoops_loadLanguage('admin/groups', 'system');
57
        /** @var XoopsModuleHandler $moduleHandler */
58
        $moduleHandler = xoops_getHandler('module');
59
        /** @var XoopsMemberHandler $memberHandler */
60
        $memberHandler = xoops_getHandler('member');
61
        /** @var XoopsGroupPermHandler $grouppermHandler */
62
        $grouppermHandler = xoops_getHandler('groupperm');
63
        $groups           = $memberHandler->getGroups();
64
        $criteria         = new CriteriaCompo(new Criteria('hasmain', 1));
65
        $criteria->add(new Criteria('isactive', 1));
66
        $module_list     = $moduleHandler->getList($criteria);
67
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
68
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
69
        ksort($module_list);
70
        echo "
71
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
72
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
The assignment to $moduleHandler is dead and can be removed.
Loading history...
73
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
74
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
75
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
76
        <tr valign='middle'><th align='center'>" . constant(
77
                'CO_' . $moduleDirNameUpper . '_' . 'TITLE'
78
            ) . "</th><th align='center' nowrap='nowrap'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') . '<br>' . _LEFT . '-' . _CENTER . '-' . _RIGHT . "</th><th align='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT') . "</th><th align='center'>" . constant(
79
                 'CO_' . $moduleDirNameUpper . '_' . 'VISIBLE'
80
             ) . "</th><th align='center'>" . _AM_SYSTEM_BLOCKS_VISIBLEIN . "</th><th align='center'>" . _AM_SYSTEM_ADGS . "</th><th align='center'>" . _AM_SYSTEM_BLOCKS_BCACHETIME . "</th><th align='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION') . '</th></tr>
81
        ';
82
        $block_arr   = XoopsBlock::getByModule($xoopsModule->mid());
83
        $block_count = count($block_arr);
0 ignored issues
show
The assignment to $block_count is dead and can be removed.
Loading history...
84
        $class       = 'even';
85
        $cachetimes  = [
86
            '0'       => _NOCACHE,
87
            '30'      => sprintf(_SECONDS, 30),
88
            '60'      => _MINUTE,
89
            '300'     => sprintf(_MINUTES, 5),
90
            '1800'    => sprintf(_MINUTES, 30),
91
            '3600'    => _HOUR,
92
            '18000'   => sprintf(_HOURS, 5),
93
            '86400'   => _DAY,
94
            '259200'  => sprintf(_DAYS, 3),
95
            '604800'  => _WEEK,
96
            '2592000' => _MONTH,
97
        ];
98
        foreach ($block_arr as $i) {
99
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
100
            $sql          = 'SELECT `module_id` FROM ' . $db->prefix(
101
                    'block_module_link'
102
                ) . ' WHERE `block_id` =' . $i->getVar(
103
                    'bid'
104
                );
105
            $result       = $db->query($sql);
106
            $modules      = [];
107
            while (false !== ($row = $db->fetchArray($result))) {
108
                $modules[] = (int)$row['module_id'];
109
            }
110
            $cachetime_options = '';
111
            foreach ($cachetimes as $cachetime => $cachetime_name) {
112
                if ($i->getVar('bcachetime') === $cachetime) {
113
                    $cachetime_options .= "<option value='${cachetime}' selected>${cachetime_name}</option>\n";
114
                } else {
115
                    $cachetime_options .= "<option value='${cachetime}'>${cachetime_name}</option>\n";
116
                }
117
            }
118
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
119
            if (1 === $i->getVar('visible')) {
120
                $sel1 = ' checked';
121
            } else {
122
                $sel0 = ' checked';
123
            }
124
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
125
                $ssel0 = ' checked';
126
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
127
                $ssel1 = ' checked';
128
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
129
                $ssel2 = ' checked';
130
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
131
                $ssel4 = ' checked';
132
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
133
                $ssel3 = ' checked';
134
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
135
                $ssel5 = ' checked';
136
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
137
                $ssel6 = ' checked';
138
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
139
                $ssel7 = ' checked';
140
            }
141
            if ('' === $i->getVar('title')) {
142
                $title = '&nbsp;';
143
            } else {
144
                $title = $i->getVar('title');
145
            }
146
            $name = $i->getVar('name');
0 ignored issues
show
The assignment to $name is dead and can be removed.
Loading history...
147
            echo "<tr valign='top'><td class='${class}' align='center'><input type='text' name='title["
148
                 . $i->getVar('bid')
149
                 . "]' value='"
150
                 . $title
151
                 . "'></td><td class='${class}' align='center' nowrap='nowrap'>
152
                    <div align='center' >
153
                    <input type='radio' name='side["
154
                 . $i->getVar('bid')
155
                 . "]' value='"
156
                 . XOOPS_CENTERBLOCK_LEFT
157
                 . "'${ssel2}>
158
                        <input type='radio' name='side["
159
                 . $i->getVar('bid')
160
                 . "]' value='"
161
                 . XOOPS_CENTERBLOCK_CENTER
162
                 . "'${ssel3}>
163
                    <input type='radio' name='side["
164
                 . $i->getVar('bid')
165
                 . "]' value='"
166
                 . XOOPS_CENTERBLOCK_RIGHT
167
                 . "'${ssel4}>
168
                    </div>
169
                    <div>
170
                        <span style='float:right;'><input type='radio' name='side["
171
                 . $i->getVar('bid')
172
                 . "]' value='"
173
                 . XOOPS_SIDEBLOCK_RIGHT
174
                 . "'${ssel1}></span>
175
                    <div align='left'><input type='radio' name='side["
176
                 . $i->getVar('bid')
177
                 . "]' value='"
178
                 . XOOPS_SIDEBLOCK_LEFT
179
                 . "'${ssel0}></div>
180
                    </div>
181
                    <div align='center'>
182
                    <input type='radio' name='side["
183
                 . $i->getVar('bid')
184
                 . "]' value='"
185
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
186
                 . "'${ssel5}>
187
                        <input type='radio' name='side["
188
                 . $i->getVar('bid')
189
                 . "]' value='"
190
                 . XOOPS_CENTERBLOCK_BOTTOM
191
                 . "'${ssel7}>
192
                    <input type='radio' name='side["
193
                 . $i->getVar('bid')
194
                 . "]' value='"
195
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
196
                 . "'${ssel6}>
197
                    </div>
198
                </td><td class='${class}' align='center'><input type='text' name='weight["
199
                 . $i->getVar('bid')
200
                 . "]' value='"
201
                 . $i->getVar('weight')
202
                 . "' size='5' maxlength='5'></td><td class='${class}' align='center' nowrap><input type='radio' name='visible["
203
                 . $i->getVar('bid')
204
                 . "]' value='1'${sel1}>"
205
                 . _YES
206
                 . "&nbsp;<input type='radio' name='visible["
207
                 . $i->getVar('bid')
208
                 . "]' value='0'${sel0}>"
209
                 . _NO
210
                 . '</td>';
211
            echo "<td class='${class}' align='center'><select size='5' name='bmodule[" . $i->getVar(
212
                    'bid'
213
                ) . "][]' id='bmodule[" . $i->getVar(
214
                    'bid'
215
                ) . "][]' multiple='multiple'>";
216
            foreach ($module_list as $k => $v) {
217
                echo "<option value='${k}'" . (in_array($k, $modules, true) ? 'selected' : '') . ">${v}</option>";
218
            }
219
            echo '</select></td>';
220
            echo "<td class='${class}' align='center'><select size='5' name='groups[" . $i->getVar(
221
                    'bid'
222
                ) . "][]' id='groups[" . $i->getVar(
223
                    'bid'
224
                ) . "][]' multiple='multiple'>";
225
            foreach ($groups as $grp) {
226
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array(
227
                        $grp->getVar('groupid'),
228
                        $groups_perms,
229
                        true
230
                    ) ? 'selected' : '') . '>' . $grp->getVar(
231
                        'name'
232
                    ) . '</option>';
233
            }
234
            echo '</select></td>';
235
            // Cache lifetime
236
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar(
237
                    'bid'
238
                ) . ']" size="1">' . $cachetime_options . '</select>
239
                                    </td>';
240
            // Actions
241
            echo "<td class='${class}' align='center'><a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar(
242
                    'bid'
243
                ) . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>
244
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar(
245
                    'bid'
246
                ) . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
247
                 </a>";
248
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
249
                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar(
250
                        'bid'
251
                    ) . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
252
                     </a>";
253
            }
254
            echo "
255
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
256
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
257
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
258
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
259
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
260
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar(
261
                    'bcachetime'
262
                ) . "'>
263
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
264
            </td></tr>
265
            ";
266
            $class = 'even' === $class ? 'odd' : 'even';
267
        }
268
        echo "<tr><td class='foot' align='center' colspan='8'>
269
        <input type='hidden' name='op' value='order'>
270
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
271
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
272
        </td></tr></table>
273
        </form>
274
        <br><br>";
275
    }
276
277
    /**
278
     * @param int $bid
279
     */
280
    function cloneBlock($bid)
281
    {
282
        require_once __DIR__ . '/admin_header.php';
283
        //require_once __DIR__ . '/admin_header.php';
284
        xoops_cp_header();
285
        xoops_loadLanguage('admin', 'system');
286
        xoops_loadLanguage('admin/blocksadmin', 'system');
287
        xoops_loadLanguage('admin/groups', 'system');
288
        //        mpu_adm_menu();
289
        $myblock = new XoopsBlock($bid);
290
        $db      = XoopsDatabaseFactory::getDatabaseConnection();
291
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
292
        $result  = $db->query($sql);
293
        $modules = [];
294
        while (false !== ($row = $db->fetchArray($result))) {
295
            $modules[] = (int)$row['module_id'];
296
        }
297
        $isCustom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
298
        $block    = [
0 ignored issues
show
The assignment to $block is dead and can be removed.
Loading history...
299
            'title'      => $myblock->getVar('title') . ' Clone',
300
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
301
            'name'       => $myblock->getVar('name'),
302
            'side'       => $myblock->getVar('side'),
303
            'weight'     => $myblock->getVar('weight'),
304
            'visible'    => $myblock->getVar('visible'),
305
            'content'    => $myblock->getVar('content', 'N'),
306
            'modules'    => $modules,
307
            'is_custom'  => $isCustom,
308
            'ctype'      => $myblock->getVar('c_type'),
309
            'bcachetime' => $myblock->getVar('bcachetime'),
310
            'op'         => 'clone_ok',
311
            'bid'        => $myblock->getVar('bid'),
312
            'edit_form'  => $myblock->getOptions(),
313
            'template'   => $myblock->getVar('template'),
314
            'options'    => $myblock->getVar('options'),
315
        ];
316
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
317
        require_once __DIR__ . '/blockform.php';
318
        $form->display();
319
        //        xoops_cp_footer();
320
        require_once __DIR__ . '/admin_footer.php';
321
        exit();
322
    }
323
324
    /**
325
     * @param int               $bid
326
     * @param string            $bside
327
     * @param int               $bweight
328
     * @param bool              $bvisible
329
     * @param int               $bcachetime
330
     * @param array             $bmodule
331
     * @param array|string|null $options
332
     */
333
    function isBlockCloned(
334
        $bid,
335
        $bside,
336
        $bweight,
337
        $bvisible,
338
        $bcachetime,
339
        $bmodule,
340
        $options
341
    ) {
342
        xoops_loadLanguage('admin', 'system');
343
        xoops_loadLanguage('admin/blocksadmin', 'system');
344
        xoops_loadLanguage('admin/groups', 'system');
345
        $block = new XoopsBlock($bid);
346
        $clone = $block->xoopsClone();
347
        if (empty($bmodule)) {
348
            xoops_cp_header();
349
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
350
            xoops_cp_footer();
351
            exit();
352
        }
353
        $clone->setVar('side', $bside);
354
        $clone->setVar('weight', $bweight);
355
        $clone->setVar('visible', $bvisible);
356
        //$clone->setVar('content', Request::getString('bcontent', '', 'POST'));
357
        $clone->setVar(
358
            'title',
359
            Request::getString('btitle', '', 'POST')
360
        );
361
        $clone->setVar('bcachetime', $bcachetime);
362
        if (is_array($options) && (count($options) > 0)) {
363
            $options = implode('|', $options);
364
            $clone->setVar('options', $options);
365
        }
366
        $clone->setVar('bid', 0);
367
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
368
            $clone->setVar('block_type', 'E');
369
        } else {
370
            $clone->setVar('block_type', 'D');
371
        }
372
        $newid = $clone->store();
373
        if (!$newid) {
374
            xoops_cp_header();
375
            $clone->getHtmlErrors();
376
            xoops_cp_footer();
377
            exit();
378
        }
379
        if ('' !== $clone->getVar('template')) {
380
            /** @var XoopsTplfileHandler $tplfileHandler */
381
            $tplfileHandler = xoops_getHandler('tplfile');
382
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
383
            if (count($btemplate) > 0) {
384
                $tplclone = $btemplate[0]->xoopsClone();
385
                $tplclone->setVar('tpl_id', 0);
386
                $tplclone->setVar('tpl_refid', $newid);
387
                $tplfileHandler->insert($tplclone);
388
            }
389
        }
390
        $db = XoopsDatabaseFactory::getDatabaseConnection();
391
        foreach ($bmodule as $bmid) {
392
            $sql = 'INSERT INTO ' . $db->prefix(
393
                    'block_module_link'
394
                ) . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
395
            $db->query($sql);
396
        }
397
        $groups = &$GLOBALS['xoopsUser']->getGroups();
398
        foreach ($groups as $iValue) {
399
            $sql = 'INSERT INTO ' . $db->prefix(
400
                    'group_permission'
401
                ) . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
402
            $db->query($sql);
403
        }
404
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
405
    }
406
407
    /**
408
     * @param int    $bid
409
     * @param string $title
410
     * @param int    $weight
411
     * @param bool   $visible
412
     * @param string $side
413
     * @param int    $bcachetime
414
     */
415
    function setOrder(
416
        $bid,
417
        $title,
418
        $weight,
419
        $visible,
420
        $side,
421
        $bcachetime
422
    ) {
423
        $myblock = new XoopsBlock($bid);
424
        $myblock->setVar('title', $title);
425
        $myblock->setVar('weight', $weight);
426
        $myblock->setVar('visible', $visible);
427
        $myblock->setVar('side', $side);
428
        $myblock->setVar('bcachetime', $bcachetime);
429
        $myblock->store();
430
    }
431
432
    /**
433
     * @param int $bid
434
     */
435
    function editBlock($bid)
436
    {
437
        require_once __DIR__ . '/admin_header.php';
438
        xoops_cp_header();
439
        $moduleDirName      = basename(dirname(__DIR__));
440
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
441
        xoops_loadLanguage('admin', 'system');
442
        xoops_loadLanguage('admin/blocksadmin', 'system');
443
        xoops_loadLanguage('admin/groups', 'system');
444
        //        mpu_adm_menu();
445
        $myblock = new XoopsBlock($bid);
446
        $db      = XoopsDatabaseFactory::getDatabaseConnection();
447
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
448
        $result  = $db->query($sql);
449
        $modules = [];
450
        while (false !== ($row = $db->fetchArray($result))) {
451
            $modules[] = (int)$row['module_id'];
452
        }
453
        $isCustom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
454
        $block    = [
0 ignored issues
show
The assignment to $block is dead and can be removed.
Loading history...
455
            'title'      => $myblock->getVar('title'),
456
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
457
            //        'name'       => $myblock->getVar('name'),
458
            'side'       => $myblock->getVar('side'),
459
            'weight'     => $myblock->getVar('weight'),
460
            'visible'    => $myblock->getVar('visible'),
461
            'content'    => $myblock->getVar('content', 'N'),
462
            'modules'    => $modules,
463
            'is_custom'  => $isCustom,
464
            'ctype'      => $myblock->getVar('c_type'),
465
            'bcachetime' => $myblock->getVar('bcachetime'),
466
            'op'         => 'edit_ok',
467
            'bid'        => $myblock->getVar('bid'),
468
            'edit_form'  => $myblock->getOptions(),
469
            'template'   => $myblock->getVar('template'),
470
            'options'    => $myblock->getVar('options'),
471
        ];
472
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
473
        require_once __DIR__ . '/blockform.php';
474
        /** @var \XoopsThemeForm $form */
475
        $form->display();
476
        //        xoops_cp_footer();
477
        require_once __DIR__ . '/admin_footer.php';
478
        exit();
479
    }
480
481
    /**
482
     * @param int $bid
483
     * @param     $btitle
484
     * @param     $bside
485
     * @param     $bweight
486
     * @param     $bvisible
487
     * @param     $bcachetime
488
     * @param     $bmodule
489
     * @param     $options
490
     * @param     $groups
491
     */
492
    function updateBlock(
493
        $bid,
494
        $btitle,
495
        $bside,
496
        $bweight,
497
        $bvisible,
498
        $bcachetime,
499
        $bmodule,
500
        $options,
0 ignored issues
show
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

500
        /** @scrutinizer ignore-unused */ $options,

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...
501
        $groups
502
    ) {
503
        $myblock = new XoopsBlock($bid);
504
        $myblock->setVar('title', $btitle);
505
        $myblock->setVar('weight', $bweight);
506
        $myblock->setVar('visible', $bvisible);
507
        $myblock->setVar('side', $bside);
508
        $myblock->setVar('bcachetime', $bcachetime);
509
        $myblock->store();
510
        global $xoopsDB;
511
        $moduleDirName      = basename(dirname(__DIR__));
512
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
513
        if (!empty($bmodule) && count($bmodule) > 0) {
514
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
515
            $xoopsDB->query($sql);
516
            if (in_array(0, $bmodule, true)) {
517
                $sql = sprintf(
518
                    'INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)',
519
                    $xoopsDB->prefix('block_module_link'),
520
                    $bid,
521
                    0
522
                );
523
                $xoopsDB->query($sql);
524
            } else {
525
                foreach ($bmodule as $bmid) {
526
                    $sql = sprintf(
527
                        'INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)',
528
                        $xoopsDB->prefix('block_module_link'),
529
                        $bid,
530
                        (int)$bmid
531
                    );
532
                    $xoopsDB->query($sql);
533
                }
534
            }
535
        }
536
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
537
        $xoopsDB->query($sql);
538
        if (!empty($groups)) {
539
            foreach ($groups as $grp) {
540
                $sql = sprintf(
541
                    "INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')",
542
                    $xoopsDB->prefix('group_permission'),
543
                    $grp,
544
                    $bid
545
                );
546
                $xoopsDB->query($sql);
547
            }
548
        }
549
        redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
550
    }
551
552
    if ('list' === $op) {
553
        xoops_cp_header();
554
        //        mpu_adm_menu();
555
        listBlocks();
556
        require_once __DIR__ . '/admin_footer.php';
557
        exit();
558
    }
559
    if ('order' === $op) {
560
        if (!$GLOBALS['xoopsSecurity']->check()) {
561
            redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
562
        }
563
        foreach (array_keys($bid) as $i) {
564
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
565
                || $oldside[$i] !== $side[$i]
566
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
567
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
0 ignored issues
show
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

567
                /** @scrutinizer ignore-call */ 
568
                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...
568
            }
569
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
570
                $sql = sprintf(
571
                    'DELETE FROM `%s` WHERE block_id = %u',
572
                    $xoopsDB->prefix('block_module_link'),
573
                    $bid[$i]
574
                );
575
                $xoopsDB->query($sql);
576
                if (in_array(0, $bmodule[$i], true)) {
577
                    $sql = sprintf(
578
                        'INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)',
579
                        $xoopsDB->prefix('block_module_link'),
580
                        $bid[$i],
581
                        0
582
                    );
583
                    $xoopsDB->query($sql);
584
                } else {
585
                    foreach ($bmodule[$i] as $bmid) {
586
                        $sql = sprintf(
587
                            'INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)',
588
                            $xoopsDB->prefix('block_module_link'),
589
                            $bid[$i],
590
                            (int)$bmid
591
                        );
592
                        $xoopsDB->query($sql);
593
                    }
594
                }
595
            }
596
            $sql = sprintf(
597
                'DELETE FROM `%s` WHERE gperm_itemid = %u',
598
                $xoopsDB->prefix('group_permission'),
599
                $bid[$i]
600
            );
601
            $xoopsDB->query($sql);
602
            if (!empty($groups[$i])) {
603
                foreach ($groups[$i] as $grp) {
604
                    $sql = sprintf(
605
                        "INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')",
606
                        $xoopsDB->prefix('group_permission'),
607
                        $grp,
608
                        $bid[$i]
609
                    );
610
                    $xoopsDB->query($sql);
611
                }
612
            }
613
        }
614
        redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
615
    }
616
    if ('clone' === $op) {
617
        cloneBlock($bid);
618
    }
619
    if ('edit' === $op) {
620
        editBlock($bid);
621
    }
622
    if ('edit_ok' === $op) {
623
        updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
624
    }
625
    if ('clone_ok' === $op) {
626
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
627
    }
628
} else {
629
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
630
}
631