Passed
Branch master (6a08cb)
by Michael
10:08 queued 20s
created

editBlock()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 47
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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