Issues (621)

Security Analysis    not enabled

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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 (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @package      \XoopsModules\Smallworld
14
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @copyright    XOOPS Project https://xoops.org/
16
 * @author       XOOPS Development Team
17
 * @link         https://github.com/XoopsModules25x/smallworld
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Smallworld\Constants;
22
23
require_once __DIR__ . '/admin_header.php';
24
/**
25
 * Vars defined by inclusion of ./admin_header.php
26
 *
27
 * @var \XoopsModules\Smallworld\Admin $admin
28
 * @var \XoopsModules\Smallworld\DoSync $d
29
 * @var \XoopsModules\Smallworld\User $check
30
 * @var \XoopsModules\Smallworld\SwDatabase $swDB
31
 * @var \XoopsModules\Smallworld\WallUpdates $wall
32
 * @var \Xmf\Module\Admin $adminObject
33
 * @var \XoopsModules\Smallworld\Helper $helper
34
 * @var string $moduleDirName
35
 * @var string $moduleDirNameUpper
36
 * @var array $block
37
 */
38
39
if (!$helper->isUserAdmin() || (!$GLOBALS['xoopsModule'] instanceof \XoopsModule)) {
0 ignored issues
show
The class XoopsModule does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
41
}
42
43
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
44
45
$op = Request::getCmd('op', 'list');
46
47
switch ($op) {
48
    case ('list'):
49
        xoops_cp_header();
50
        //        mpu_adm_menu();
51
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
52
        $moduleDirName      = basename(dirname(__DIR__));
53
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
54
        xoops_loadLanguage('admin', 'system');
55
        xoops_loadLanguage('admin/blocksadmin', 'system');
56
        xoops_loadLanguage('admin/groups', 'system');
57
58
        /** @var \XoopsModuleHandler $moduleHandler */
59
        $moduleHandler = xoops_getHandler('module');
60
        /** @var \XoopsMemberHandler $memberHandler */
61
        $memberHandler = xoops_getHandler('member');
62
        /** @var \XoopsGroupPermHandler $grouppermHandler */
63
        $grouppermHandler = xoops_getHandler('groupperm');
64
        $groups           = $memberHandler->getGroups();
65
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
66
        $criteria->add(new \Criteria('isactive', 1));
67
        $module_list     = $moduleHandler->getList($criteria);
68
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
69
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
70
        ksort($module_list);
71
        echo "<h4 class='left'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
72
        $moduleHandler = xoops_getHandler('module');
73
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
74
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
75
        echo "<table class='outer width100' cellpadding='4' cellspacing='1'>\n"
76
           . "    <tr class='middle'>\n"
77
           . "        <th class='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') . "</th>\n"
78
           . "        <th class='center' nowrap='nowrap'>\n"
79
           . "            " . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') . "<br>\n"
80
           . "            " . _LEFT  . '-' . _CENTER . '-' . _RIGHT . "\n"
81
           . "        </th>\n"
82
           . "        <th class='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT') . "</th>\n"
83
           . "        <th class='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE') . "</th>\n"
84
           . "        <th class='center'>" . _AM_SYSTEM_BLOCKS_VISIBLEIN . "</th>\n"
85
           . "        <th class='center'>" . _AM_SYSTEM_ADGS . "</th>\n"
86
           . "        <th class='center'>" . _AM_SYSTEM_BLOCKS_BCACHETIME . "</th>\n"
87
           . "        <th class='center'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION') . "</th>\n"
88
           . "    </tr>\n";
89
90
       $block_arr   = \XoopsBlock::getByModule($helper->getModule()->mid());
91
       //$block_arr   = \XoopsBlock::getByModule($GLOBALS['xoopsModule']->mid());
92
        $class       = 'even';
93
        $cachetimes  = [
94
            '0'       => _NOCACHE,
95
            '30'      => sprintf(_SECONDS, 30),
96
            '60'      => _MINUTE,
97
            '300'     => sprintf(_MINUTES, 5),
98
            '1800'    => sprintf(_MINUTES, 30),
99
            '3600'    => _HOUR,
100
            '18000'   => sprintf(_HOURS, 5),
101
            '86400'   => _DAY,
102
            '259200'  => sprintf(_DAYS, 3),
103
            '604800'  => _WEEK,
104
            '2592000' => _MONTH,
105
        ];
106
        foreach ($block_arr as $i) {
107
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
108
            $sql          = 'SELECT module_id FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
109
            $result       = $GLOBALS['xoopsDB']->query($sql);
110
            $modules      = [];
111
            while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
112
                $modules[] = (int)$row['module_id'];
113
            }
114
115
            $cachetime_options = '';
116
            foreach ($cachetimes as $cachetime => $cachetime_name) {
117
                if ($i->getVar('bcachetime') == $cachetime) {
118
                    $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n";
119
                } else {
120
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
121
                }
122
            }
123
124
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
125
            if (1 === $i->getVar('visible')) {
126
                $sel1 = ' checked';
127
            } else {
128
                $sel0 = ' checked';
129
            }
130
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
131
                $ssel0 = ' checked';
132
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
133
                $ssel1 = ' checked';
134
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
135
                $ssel2 = ' checked';
136
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
137
                $ssel4 = ' checked';
138
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
139
                $ssel3 = ' checked';
140
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
141
                $ssel5 = ' checked';
142
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
143
                $ssel6 = ' checked';
144
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
145
                $ssel7 = ' checked';
146
            }
147
            if ('' === $i->getVar('title')) {
148
                $title = '&nbsp;';
149
            } else {
150
                $title = $i->getVar('title');
151
            }
152
            //$name = $i->getVar('name');
153
            echo "    <tr class='top'>\n"
154
               . "        <td class='{$class} center'>\n"
155
               . "            <input type='text' name='title[" . $i->getVar('bid') . "]' value='{$title}'>\n"
156
               . "        </td>\n"
157
               . "        <td class='{$class} center' nowrap='nowrap'>\n"
158
               . "            <div class='center'>\n"
159
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_LEFT . "'$ssel2>\n"
160
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_CENTER . "'$ssel3>\n"
161
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_RIGHT . "'$ssel4>\n"
162
               . "            </div>\n"
163
               . "        <div>\n"
164
               . "                <span style='float:right;'>\n"
165
               . "                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_SIDEBLOCK_RIGHT . "'$ssel1>\n"
166
               . "                </span>\n"
167
               . "            <div class='left'>\n"
168
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_SIDEBLOCK_LEFT . "'$ssel0></div>\n"
169
               . "            </div>\n"
170
               . "            <div class='center'>\n"
171
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5>\n"
172
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7>\n"
173
               . "                <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6>\n"
174
               . "            </div>\n"
175
               . "        </td>\n"
176
               . "        <td class='{$class} center'>\n"
177
               . "            <input type='text' name='weight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "' size='5' maxlength='5'>\n"
178
               . "        </td>\n"
179
               . "        <td class='{$class} center' nowrap>\n"
180
               . "            <input type='radio' name='visible[" . $i->getVar('bid') . "]' value='1'$sel1>" . _YES . "&nbsp\n"
181
               . "            <input type='radio' name='visible[" . $i->getVar('bid') . "]' value='0'$sel0>" . _NO . "\n"
182
               . "        </td>\n"
183
               . "        <td class='{$class} center'>\n"
184
               . "            <select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple>";
185
            foreach ($module_list as $k => $v) {
186
                echo "                <option value='{$k}'" . (in_array($k, $modules) ? 'selected' : '') . ">{$v}</option>\n";
187
            }
188
            echo "            </select>\n"
189
               . "        </td>\n"
190
               . "        <td class='{$class} center'>\n"
191
               . "            <select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple>\n";
192
            foreach ($groups as $grp) {
193
                echo "            <option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? 'selected' : '') . '>' . $grp->getVar('name') . '</option>\n';
194
            }
195
            echo "            </select>\n"
196
               . "        </td>\n";
197
198
            // Cache lifetime
199
            echo "        <td class='{$class} center'><select name='bcachetime[" . $i->getVar('bid') . "]' size='1'>{$cachetime_options}</select></td>\n";
200
201
            // Actions
202
            echo "        <td class='{$class} center'><a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src='" . $pathIcon16 . '/edit.png' . "' alt='" . _EDIT . "' title='" . _EDIT . "'></a>&nbsp;\n"
203
               . "            <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src='" . $pathIcon16 . '/editcopy.png' . "' alt='" . _CLONE . "' title='" . _CLONE . "'></a>\n";
204
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
205
                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 . "'></a>\n";
206
            }
207
            echo "            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>\n"
208
               . "            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>\n"
209
               . "            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>\n"
210
               . "            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>\n"
211
               . "            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>\n"
212
               . "            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>\n"
213
               . "            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>\n"
214
               . "        </td>\n"
215
               . "    </tr>\n";
216
            $class = ('even' === $class) ? 'odd' : 'even';
217
        }
218
        echo "    <tr>\n"
219
           . "        <td class='foot center' colspan='8'>\n"
220
           . "            <input type='hidden' name='op' value='order'>\n"
221
           . "            " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "\n"
222
           . "            <input type='submit' name='submit' value='" . _SUBMIT . "'>\n"
223
           . "        </td>\n"
224
           . "    </tr>\n"
225
           . "</table>\n"
226
           . "</form>\n"
227
           . "<br><br>\n";
228
        break;
229
    case ('order'):
230 View Code Duplication
        if (!$GLOBALS['xoopsSecurity']->check()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
231
            $helper->redirect('admin/blocksadmin.php', Constants::REDIRECT_DELAY_MEDIUM, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
232
        }
233
        $bid           = Request::getArray('bid', [], 'POST');
234
        $oldtitle      = Request::getArray('oldtitle', [], 'POST');
235
        $title         = Request::getArray('title', [], 'POST');
236
        $oldweight     = Request::getArray('oldweight', [], 'POST');
237
        $weight        = Request::getArray('weight', [], 'POST');
238
        $oldvisible    = Request::getArray('oldvisible', [], 'POST');
239
        $visible       = Request::getArray('visible', [], 'POST');
240
        $oldside       = Request::getArray('oldside', [], 'POST');
241
        $side          = Request::getArray('side', [], 'POST');
242
        $oldbcachetime = Request::getArray('oldbcachetime', [], 'POST');
243
        $bcachetime    = Request::getArray('bcachetime', [], 'POST');
244
245
        foreach ($bid as $i => $val) {
246
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i]
247
                || $oldvisible[$i] != $visible[$i]
248
                || $oldside[$i] != $side[$i]
249
                || $oldbcachetime[$i] != $bcachetime[$i])
250
            {
251
                $myblock = new \XoopsBlock($bid);
252
                $myblock->setVar('title', $title[$i]);
253
                $myblock->setVar('weight', $weight[$i]);
254
                $myblock->setVar('visible', $visible[$i]);
255
                $myblock->setVar('side', $side[$i]);
256
                $myblock->setVar('bcachetime', $bcachetime[$i]);
257
                $myblock->store();
258
            }
259
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
260
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]);
261
                $GLOBALS['xoopsDB']->query($sql);
262
                if (in_array(0, $bmodule[$i])) {
263
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0);
264
                    $GLOBALS['xoopsDB']->query($sql);
265 View Code Duplication
                } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
266
                    foreach ($bmodule[$i] as $bmid) {
267
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid);
268
                        $GLOBALS['xoopsDB']->query($sql);
269
                    }
270
                }
271
            }
272
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]);
273
            $GLOBALS['xoopsDB']->query($sql);
274
            if (!empty($groups[$i])) {
275 View Code Duplication
                foreach ($groups[$i] as $grp) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
276
                    $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]);
277
                    $GLOBALS['xoopsDB']->query($sql);
278
                }
279
            }
280
        }
281
        $helper->redirect('admin/blocksadmin.php', Constants::REDIRECT_DELAY_MEDIUM, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
282
        break;
283 View Code Duplication
    case ('clone'):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
        $bid = Request::getInt('bid', 0);
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
        $sql     = 'SELECT module_id FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
294
        $result  = $GLOBALS['xoopsDB']->query($sql);
295
        $modules = [];
296
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
297
            $modules[] = (int)$row['module_id'];
298
        }
299
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
300
        $block     = [
301
            'title'      => $myblock->getVar('title') . ' Clone',
302
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
303
            'name'       => $myblock->getVar('name'),
304
            'side'       => $myblock->getVar('side'),
305
            'weight'     => $myblock->getVar('weight'),
306
            'visible'    => $myblock->getVar('visible'),
307
            'content'    => $myblock->getVar('content', 'N'),
308
            'modules'    => $modules,
309
            'is_custom'  => $is_custom,
310
            'ctype'      => $myblock->getVar('c_type'),
311
            'bcachetime' => $myblock->getVar('bcachetime'),
312
            'op'         => 'clone_ok',
313
            'bid'        => $myblock->getVar('bid'),
314
            'edit_form'  => $myblock->getOptions(),
315
            'template'   => $myblock->getVar('template'),
316
            'options'    => $myblock->getVar('options'),
317
        ];
318
        echo "<a href='" . $helper->url('admin/blocksadmin.php') . "'>" . _AM_BADMIN . "</a>&nbsp;<span class='bold'>&raquo;&raquo;</span>&nbsp;" . _AM_SYSTEM_BLOCKS_CLONEBLOCK . "<br><br>\n";
319
        require_once __DIR__ . '/blockform.php';
320
        $form->display();
321
        break;
322 View Code Duplication
    case ('edit'):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
323
        $bid = Request::getInt('bid', 0, 'POST');
324
        xoops_cp_header();
325
326
        xoops_loadLanguage('admin', 'system');
327
        xoops_loadLanguage('admin/blocksadmin', 'system');
328
        xoops_loadLanguage('admin/groups', 'system');
329
        //        mpu_adm_menu();
330
        $myblock = new \XoopsBlock($bid);
331
        $sql     = 'SELECT module_id FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . $bid;
332
        $result  = $GLOBALS['xoopsDB']->query($sql);
333
        $modules = [];
334
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
335
            $modules[] = (int)$row['module_id'];
336
        }
337
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
338
        $block     = [
339
            'title'      => $myblock->getVar('title'),
340
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
341
            //        'name'       => $myblock->getVar('name'),
342
            'side'       => $myblock->getVar('side'),
343
            'weight'     => $myblock->getVar('weight'),
344
            'visible'    => $myblock->getVar('visible'),
345
            'content'    => $myblock->getVar('content', 'N'),
346
            'modules'    => $modules,
347
            'is_custom'  => $is_custom,
348
            'ctype'      => $myblock->getVar('c_type'),
349
            'bcachetime' => $myblock->getVar('bcachetime'),
350
            'op'         => 'edit_ok',
351
            'bid'        => $myblock->getVar('bid'),
352
            'edit_form'  => $myblock->getOptions(),
353
            'template'   => $myblock->getVar('template'),
354
            'options'    => $myblock->getVar('options'),
355
        ];
356
        echo "<a href='" . $helper->url('admin/blocksadmin.php') . "'>" . _AM_BADMIN . "</a>&nbsp;<span class='bold'>&raquo;&raquo;</span>&nbsp;" . _AM_SYSTEM_BLOCKS_EDITBLOCK . "<br><br>\n";
357
        require_once __DIR__ . '/blockform.php';
358
        $form->display();
359
        break;
360
    case('edit_ok'):
361
        $bid        = Request::getInt('bid', 0);
362
        $btitle     = Request::getString('btitle');
363
        $bside      = Request::getInt('bside', 0);
364
        $bweight    = Request::getInt('bweight', 0);
365
        $bvisible   = Request::getInt('bvisible', 0);
366
        $bcachetime = Request::getInt('bcachetime', 0);
367
        $bmodule    = Request::getArray('bmodule', []); // array of integers
368
        $options    = Request::getArray('options', []);
369
        $groups     = Request::getArray('groups', []);
370
371
        $myblock = new \XoopsBlock($bid);
372
        $myblock->setVar('title', $btitle);
373
        $myblock->setVar('weight', $bweight);
374
        $myblock->setVar('visible', $bvisible);
375
        $myblock->setVar('side', $bside);
376
        $myblock->setVar('bcachetime', $bcachetime);
377
        $myblock->store();
378
379
        if (!empty($bmodule) && count($bmodule) > 0) {
380
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
381
            $GLOBALS['xoopsDB']->query($sql);
382
            if (in_array(0, $bmodule)) {
383
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
384
                $GLOBALS['xoopsDB']->query($sql);
385 View Code Duplication
            } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
                foreach ($bmodule as $bmid) {
387
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
388
                    $GLOBALS['xoopsDB']->query($sql);
389
                }
390
            }
391
        }
392
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
393
        $GLOBALS['xoopsDB']->query($sql);
394
        if (!empty($groups)) {
395 View Code Duplication
            foreach ($groups as $grp) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
                $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);
397
                $GLOBALS['xoopsDB']->query($sql);
398
            }
399
        }
400
        $helper->redirect('admin/blocksadmin.php', Constants::REDIRECT_DELAY_MEDIUM, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
401
        break;
402
    case ('clone_ok'):
403
404
        $bid        = Request::getInt('bid', 0);
405
        $bside      = Request::getInt('bside', 0);
406
        $bweight    = Request::getInt('weight', 0);
407
        $bvisible   = Request::getInt('visible', 0);
408
        $bcachetime = Request::getInt('bcachetime', 0);
409
        $bmodule    = Request::getInt('bmodule', $helper->getModule()->mid());
410
        $options    = Request::getArray('options', []);
411
412
        xoops_loadLanguage('admin', 'system');
413
        xoops_loadLanguage('admin/blocksadmin', 'system');
414
        xoops_loadLanguage('admin/groups', 'system');
415
416
        $block = new \XoopsBlock($bid);
417
        $clone = $block->xoopsClone();
418
        if (empty($bmodule)) {
419
            xoops_cp_header();
420
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
421
            xoops_cp_footer();
422
            exit();
423
        }
424
        $clone->setVar('side', $bside);
425
        $clone->setVar('weight', $bweight);
426
        $clone->setVar('visible', $bvisible);
427
        //$clone->setVar('content', $_POST['bcontent']);
428
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
429
        $clone->setVar('bcachetime', $bcachetime);
430
        if (isset($options) && (count($options) > 0)) {
431
            $options = implode('|', $options);
432
            $clone->setVar('options', $options);
433
        }
434
        $clone->setVar('bid', 0);
435
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
436
            $clone->setVar('block_type', 'E');
437
        } else {
438
            $clone->setVar('block_type', 'D');
439
        }
440
        $newid = $clone->store();
441
        if (!$newid) {
442
            xoops_cp_header();
443
            $clone->getHtmlErrors();
444
            xoops_cp_footer();
445
            exit();
446
        }
447
        if ('' !== $clone->getVar('template')) {
448
            /** @var \XoopsTplfileHandler $tplfileHandler */
449
            $tplfileHandler = xoops_getHandler('tplfile');
450
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
451
            if (count($btemplate) > 0) {
452
                $tplclone = $btemplate[0]->xoopsClone();
453
                $tplclone->setVar('tpl_id', 0);
454
                $tplclone->setVar('tpl_refid', $newid);
455
                $tplfileHandler->insert($tplclone);
456
            }
457
        }
458
        foreach ($bmodule as $bmid) {
459
            $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
460
            $GLOBALS['xoopsDB']->query($sql);
461
        }
462
        $groups = &$GLOBALS['xoopsUser']->getGroups();
463
        $count  = count($groups);
464
        for ($i = 0; $i < $count; ++$i) {
465
            $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
466
            $GLOBALS['xoopsDB']->query($sql);
467
        }
468
        $helper->redirect('admin/blocksadmin.php?op=listar', Constants::REDIRECT_DELAY_MEDIUM, _AM_DBUPDATED);
469
        break;
470
}
471
require_once __DIR__ . '/admin_footer.php';
472