Issues (132)

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 (17 issues)

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
use Xmf\Request;
16
17
require __DIR__ . '/admin_header.php';
18
19
$moduleDirName = basename(dirname(__DIR__));
20
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
21
22
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
23
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
24
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
25
}
26
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
27
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
28
    $op = 'list';
29
    if (isset($_POST)) {
30
        foreach ($_POST as $k => $v) {
31
            ${$k} = $v;
32
        }
33
    }
34
    /*
35
        if (Request::hasVar('op')) {
36
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
37
                || $_GET['op'] === "edit"
38
            ) {
39
                $op  = $_GET['op'];
40
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
41
            }
42
        }
43
    */
44
45
    $op = Request::getString('op', $op);
46
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'], true)) {
47
        $bid = Request::getInt('bid', 0, 'GET');
48
    }
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
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
57
        xoops_loadLanguage('admin', 'system');
58
        xoops_loadLanguage('admin/blocksadmin', 'system');
59
        xoops_loadLanguage('admin/groups', 'system');
60
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['PHP_SELF'] . "' 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('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT')
92
             . "</th><th align='center'>"
93
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
94
             . "</th><th align='center'>"
95
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
96
             . "</th><th align='center'>"
97
             . _AM_SYSTEM_ADGS
98
             . "</th><th align='center'>"
99
             . _AM_SYSTEM_BLOCKS_BCACHETIME
100
             . "</th><th align='center'>"
101
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
102
             . '</th></tr>
103
        ';
104
        $block_arr = \XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
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

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

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

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

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