Issues (167)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/blocksadmin.php (15 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 (https://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
if (!is_object($xoopsModule) || !is_object($GLOBALS['xoopsUser'])
25
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
26
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
27
}
28
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
29
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
30
    $op = 'list';
31
    if (isset($_POST)) {
32
        foreach ($_POST as $k => $v) {
33
            ${$k} = $v;
34
        }
35
    }
36
    /*
37
        if (Request::hasVar('op')) {
38
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
39
                || $_GET['op'] === "edit"
40
            ) {
41
                $op  = $_GET['op'];
42
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
43
            }
44
        }
45
    */
46
    $op = Request::getString('op', $op);
47
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
48
        $bid = Request::getInt('bid', 0, 'GET');
49
    }
50
    function listBlocks()
51
    {
52
        global $xoopsModule, $pathIcon16;
53
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
54
        $moduleDirName      = basename(dirname(__DIR__));
55
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName
56
        /** @var \XoopsMySQLDatabase $db */
57
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
58
        xoops_loadLanguage('admin', 'system');
59
        xoops_loadLanguage('admin/blocksadmin', 'system');
60
        xoops_loadLanguage('admin/groups', 'system');
61
        /** @var \XoopsModuleHandler $moduleHandler */
62
        $moduleHandler = xoops_getHandler('module');
63
        /** @var \XoopsMemberHandler $memberHandler */
64
        $memberHandler = xoops_getHandler('member');
65
        /** @var \XoopsGroupPermHandler $grouppermHandler */
66
        $grouppermHandler = xoops_getHandler('groupperm');
67
        $groups           = $memberHandler->getGroups();
68
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
69
        $criteria->add(new \Criteria('isactive', 1));
70
        $module_list     = $moduleHandler->getList($criteria);
71
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
72
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
73
        ksort($module_list);
74
        echo "
75
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
76
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
The assignment to $moduleHandler is dead and can be removed.
Loading history...
77
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
78
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
79
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
80
        <tr valign='middle'><th align='center'>"
81
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
82
             . "</th><th align='center' nowrap='nowrap'>"
83
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
84
             . '<br>'
85
             . _LEFT
86
             . '-'
87
             . _CENTER
88
             . '-'
89
             . _RIGHT
90
             . "</th><th align='center'>"
91
             . constant(
92
                 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'
93
             )
94
             . "</th><th align='center'>"
95
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
96
             . "</th><th align='center'>"
97
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
98
             . "</th><th align='center'>"
99
             . _AM_SYSTEM_ADGS
100
             . "</th><th align='center'>"
101
             . _AM_SYSTEM_BLOCKS_BCACHETIME
102
             . "</th><th align='center'>"
103
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
104
             . '</th></tr>
105
        ';
106
        $block_arr   = \XoopsBlock::getByModule($xoopsModule->mid());
107
        $block_count = count($block_arr);
0 ignored issues
show
The assignment to $block_count is dead and can be removed.
Loading history...
108
        $class       = 'even';
109
        $cachetimes  = [
110
            '0'       => _NOCACHE,
111
            '30'      => sprintf(_SECONDS, 30),
112
            '60'      => _MINUTE,
113
            '300'     => sprintf(_MINUTES, 5),
114
            '1800'    => sprintf(_MINUTES, 30),
115
            '3600'    => _HOUR,
116
            '18000'   => sprintf(_HOURS, 5),
117
            '86400'   => _DAY,
118
            '259200'  => sprintf(_DAYS, 3),
119
            '604800'  => _WEEK,
120
            '2592000' => _MONTH,
121
        ];
122
        foreach ($block_arr as $i) {
123
            /** @var \XoopsBlock $i */
124
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
125
            $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
126
            $result       = $db->query($sql);
127
            $modules      = [];
128
            if ($result instanceof \mysqli_result) {
129
                while (false !== ($row = $db->fetchArray($result))) {
130
                    $modules[] = (int)$row['module_id'];
131
                }
132
            }
133
            $cachetime_options = '';
134
            foreach ($cachetimes as $cachetime => $cachetime_name) {
135
                if ($i->getVar('bcachetime') == $cachetime) {
136
                    $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n";
137
                } else {
138
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
139
                }
140
            }
141
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
142
            if (1 === $i->getVar('visible')) {
143
                $sel1 = ' checked';
144
            } else {
145
                $sel0 = ' checked';
146
            }
147
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
148
                $ssel0 = ' checked';
149
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
150
                $ssel1 = ' checked';
151
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
152
                $ssel2 = ' checked';
153
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
154
                $ssel4 = ' checked';
155
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
156
                $ssel3 = ' checked';
157
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
158
                $ssel5 = ' checked';
159
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
160
                $ssel6 = ' checked';
161
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
162
                $ssel7 = ' checked';
163
            }
164
            if ('' === $i->getVar('title')) {
165
                $title = '&nbsp;';
166
            } else {
167
                $title = $i->getVar('title');
168
            }
169
            $name = $i->getVar('name');
0 ignored issues
show
The assignment to $name is dead and can be removed.
Loading history...
170
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
171
                 . $i->getVar('bid')
172
                 . "]' value='"
173
                 . $title
174
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
175
                    <div align='center' >
176
                    <input type='radio' name='side["
177
                 . $i->getVar('bid')
178
                 . "]' value='"
179
                 . XOOPS_CENTERBLOCK_LEFT
180
                 . "'$ssel2>
181
                        <input type='radio' name='side["
182
                 . $i->getVar('bid')
183
                 . "]' value='"
184
                 . XOOPS_CENTERBLOCK_CENTER
185
                 . "'$ssel3>
186
                    <input type='radio' name='side["
187
                 . $i->getVar('bid')
188
                 . "]' value='"
189
                 . XOOPS_CENTERBLOCK_RIGHT
190
                 . "'$ssel4>
191
                    </div>
192
                    <div>
193
                        <span style='float:right;'><input type='radio' name='side["
194
                 . $i->getVar('bid')
195
                 . "]' value='"
196
                 . XOOPS_SIDEBLOCK_RIGHT
197
                 . "'$ssel1></span>
198
                    <div align='left'><input type='radio' name='side["
199
                 . $i->getVar('bid')
200
                 . "]' value='"
201
                 . XOOPS_SIDEBLOCK_LEFT
202
                 . "'$ssel0></div>
203
                    </div>
204
                    <div align='center'>
205
                    <input type='radio' name='side["
206
                 . $i->getVar('bid')
207
                 . "]' value='"
208
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
209
                 . "'$ssel5>
210
                        <input type='radio' name='side["
211
                 . $i->getVar('bid')
212
                 . "]' value='"
213
                 . XOOPS_CENTERBLOCK_BOTTOM
214
                 . "'$ssel7>
215
                    <input type='radio' name='side["
216
                 . $i->getVar('bid')
217
                 . "]' value='"
218
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
219
                 . "'$ssel6>
220
                    </div>
221
                </td><td class='$class' align='center'><input type='text' name='weight["
222
                 . $i->getVar('bid')
223
                 . "]' value='"
224
                 . $i->getVar('weight')
225
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
226
                 . $i->getVar('bid')
227
                 . "]' value='1'$sel1>"
228
                 . _YES
229
                 . "&nbsp;<input type='radio' name='visible["
230
                 . $i->getVar('bid')
231
                 . "]' value='0'$sel0>"
232
                 . _NO
233
                 . '</td>';
234
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
235
            foreach ($module_list as $k => $v) {
236
                echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
237
            }
238
            echo '</select></td>';
239
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
240
            foreach ($groups as $grp) {
241
                /** @var \XoopsGroup $grp */
242
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
243
            }
244
            echo '</select></td>';
245
            // Cache lifetime
246
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
247
                                    </td>';
248
            // Actions
249
            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 . "'>
250
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
251
                 </a>";
252
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
253
                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 . "'>
254
                     </a>";
255
            }
256
            echo "
257
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
258
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
259
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
260
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
261
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
262
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
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='7'>
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
        $moduleDirName      = basename(dirname(__DIR__));
286
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName
287
        xoops_loadLanguage('admin', 'system');
288
        xoops_loadLanguage('admin/blocksadmin', 'system');
289
        xoops_loadLanguage('admin/groups', 'system');
290
        //        mpu_adm_menu();
291
        $myblock = new \XoopsBlock($bid);
292
        /** @var \XoopsMySQLDatabase $db */
293
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
294
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
295
        $result  = $db->query($sql);
296
        $modules = [];
297
        if ($result instanceof \mysqli_result) {
298
            while (false !== ($row = $db->fetchArray($result))) {
299
                $modules[] = (int)$row['module_id'];
300
            }
301
        }
302
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
303
        $block     = [
0 ignored issues
show
The assignment to $block is dead and can be removed.
Loading history...
304
            'title'      => $myblock->getVar('title') . ' Clone',
305
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
306
            'name'       => $myblock->getVar('name'),
307
            'side'       => $myblock->getVar('side'),
308
            'weight'     => $myblock->getVar('weight'),
309
            'visible'    => $myblock->getVar('visible'),
310
            'content'    => $myblock->getVar('content', 'N'),
311
            'modules'    => $modules,
312
            'is_custom'  => $is_custom,
313
            'ctype'      => $myblock->getVar('c_type'),
314
            'bcachetime' => $myblock->getVar('bcachetime'),
315
            'op'         => 'clone_ok',
316
            'bid'        => $myblock->getVar('bid'),
317
            'edit_form'  => $myblock->getOptions(),
318
            'template'   => $myblock->getVar('template'),
319
            'options'    => $myblock->getVar('options'),
320
        ];
321
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
322
        require_once __DIR__ . '/blockform.php';
323
        /** @var \XoopsThemeForm $form */
324
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
325
        //        xoops_cp_footer();
326
        require_once __DIR__ . '/admin_footer.php';
327
        exit();
0 ignored issues
show
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...
328
    }
329
330
    /**
331
     * @param int $bid
332
     * @param     $bside
333
     * @param     $bweight
334
     * @param     $bvisible
335
     * @param     $bcachetime
336
     * @param     $bmodule
337
     * @param     $options
338
     */
339
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
340
    {
341
        xoops_loadLanguage('admin', 'system');
342
        xoops_loadLanguage('admin/blocksadmin', 'system');
343
        xoops_loadLanguage('admin/groups', 'system');
344
        $block = new \XoopsBlock($bid);
345
        $clone = $block->xoopsClone();
346
        if (empty($bmodule)) {
347
            xoops_cp_header();
348
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
349
            xoops_cp_footer();
350
            exit();
0 ignored issues
show
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...
351
        }
352
        $clone->setVar('side', $bside);
353
        $clone->setVar('weight', $bweight);
354
        $clone->setVar('visible', $bvisible);
355
        //$clone->setVar('content', $_POST['bcontent']);
356
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
357
        $clone->setVar('bcachetime', $bcachetime);
358
        if (isset($options) && (count($options) > 0)) {
359
            $options = implode('|', $options);
360
            $clone->setVar('options', $options);
361
        }
362
        $clone->setVar('bid', 0);
363
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
364
            $clone->setVar('block_type', 'E');
365
        } else {
366
            $clone->setVar('block_type', 'D');
367
        }
368
        $newid = $clone->store();
369
        if (!$newid) {
370
            xoops_cp_header();
371
            $clone->getHtmlErrors();
372
            xoops_cp_footer();
373
            exit();
0 ignored issues
show
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...
374
        }
375
        if ('' !== $clone->getVar('template')) {
376
            /** @var \XoopsTplfileHandler $tplfileHandler */
377
            $tplfileHandler = xoops_getHandler('tplfile');
378
            /** @var \XoopsTplfile[] $btemplate */
379
            $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
380
            if (count($btemplate) > 0) {
381
                /** @var \XoopsObject $tplclone */
382
                $tplclone = $btemplate[0]->xoopsClone();
383
                $tplclone->setVar('tpl_id', 0);
384
                $tplclone->setVar('tpl_refid', $newid);
385
                $tplfileHandler->insert($tplclone);
386
            }
387
        }
388
        /** @var \XoopsMySQLDatabase $db */
389
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
390
        foreach ($bmodule as $bmid) {
391
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
392
            $db->query($sql);
393
        }
394
        $groups = &$GLOBALS['xoopsUser']->getGroups();
395
        $count  = count($groups);
396
        for ($i = 0; $i < $count; ++$i) {
397
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
398
            $db->query($sql);
399
        }
400
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
401
    }
402
403
    /**
404
     * @param int    $bid
405
     * @param string $title
406
     * @param int    $weight
407
     * @param bool   $visible
408
     * @param string $side
409
     * @param int    $bcachetime
410
     */
411
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime)
412
    {
413
        $myblock = new \XoopsBlock($bid);
414
        $myblock->setVar('title', $title);
415
        $myblock->setVar('weight', $weight);
416
        $myblock->setVar('visible', $visible);
417
        $myblock->setVar('side', $side);
418
        $myblock->setVar('bcachetime', $bcachetime);
419
        $myblock->store();
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::store() has been deprecated. ( Ignorable by Annotation )

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

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

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

Loading history...
473
    }
474
475
    /**
476
     * @param int               $bid
477
     * @param string            $btitle
478
     * @param string            $bside
479
     * @param int               $bweight
480
     * @param bool              $bvisible
481
     * @param int               $bcachetime
482
     * @param array             $bmodule
483
     * @param null|array|string $options
484
     * @param null|array        $groups
485
     */
486
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
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

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

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

Loading history...
487
    {
488
        $moduleDirName      = basename(dirname(__DIR__));
489
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName
490
        $myblock            = new \XoopsBlock($bid);
491
        $myblock->setVar('title', $btitle);
492
        $myblock->setVar('weight', $bweight);
493
        $myblock->setVar('visible', $bvisible);
494
        $myblock->setVar('side', $bside);
495
        $myblock->setVar('bcachetime', $bcachetime);
496
        $myblock->store();
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::store() has been deprecated. ( Ignorable by Annotation )

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

496
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
497
        if (!empty($bmodule) && count($bmodule) > 0) {
498
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
499
            $GLOBALS['xoopsDB']->query($sql);
500
            if (in_array(0, $bmodule)) {
501
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
502
                $GLOBALS['xoopsDB']->query($sql);
503
            } else {
504
                foreach ($bmodule as $bmid) {
505
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
506
                    $GLOBALS['xoopsDB']->query($sql);
507
                }
508
            }
509
        }
510
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
511
        $GLOBALS['xoopsDB']->query($sql);
512
        if (!empty($groups)) {
513
            foreach ($groups as $grp) {
514
                $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);
515
                $GLOBALS['xoopsDB']->query($sql);
516
            }
517
        }
518
        redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
519
    }
520
521
    if ('list' === $op) {
522
        xoops_cp_header();
523
        //        mpu_adm_menu();
524
        listBlocks();
525
        require_once __DIR__ . '/admin_footer.php';
526
        exit();
527
    }
528
    if ('order' === $op) {
529
        if (!$GLOBALS['xoopsSecurity']->check()) {
530
            redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
531
        }
532
        foreach (array_keys($bid) as $i) {
533
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
534
                || $oldside[$i] !== $side[$i]
535
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
536
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
0 ignored issues
show
The call to setOrder() has too many arguments starting with $bmodule[$i]. ( Ignorable by Annotation )

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

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

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

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

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