Passed
Push — master ( 6499a1...73e8f6 )
by Michael
36s queued 12s
created

xtubeSetOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 6
dl 0
loc 12
rs 10
1
<?php
2
/**
3
 * Module: XoopsTube
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Xoopstube
13
 * @author          Fernando Santos (topet05), [email protected]
14
 * @copyright       Mastop InfoDigital (c) 2003-2007
15
 * @link            http://www.mastop.com.br
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @since           1.0.6
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Xoopstube;
22
23
require_once __DIR__ . '/admin_header.php';
24
25
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
26
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
27
    exit(_AM_XOOPSTUBE_ERROR403);
28
}
29
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
30
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
31
    $op = 'list';
32
    if (isset($_POST)) {
33
        foreach ($_POST as $k => $v) {
34
            ${$k} = $v;
35
        }
36
    }
37
    /*
38
        if (Request::hasVar('op')) {
39
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
40
                || $_GET['op'] === "edit"
41
            ) {
42
                $op  = $_GET['op'];
43
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
44
            }
45
        }
46
    */
47
48
    $op = Request::getString('op', $op);
49
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
50
        $bid = Request::getInt('bid', 0, 'GET');
51
    }
52
53
    function listBlocks()
54
    {
55
        global $xoopsModule, $pathIcon16;
56
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
57
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
58
        xoops_loadLanguage('admin', 'system');
59
        xoops_loadLanguage('admin/blocksadmin', 'system');
60
        xoops_loadLanguage('admin/groups', 'system');
61
62
        /** @var \XoopsModuleHandler $moduleHandler */
63
        $moduleHandler = xoops_getHandler('module');
64
        /** @var \XoopsMemberHandler $memberHandler */
65
        $memberHandler = xoops_getHandler('member');
66
        /** @var \XoopsGroupPermHandler $grouppermHandler */
67
        $grouppermHandler = xoops_getHandler('groupperm');
68
        $groups           = $memberHandler->getGroups();
69
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
70
        $criteria->add(new \Criteria('isactive', 1));
71
        $module_list     = $moduleHandler->getList($criteria);
72
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
73
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
74
        ksort($module_list);
75
        echo "
76
        <h4 style='text-align:left;'>" . _AM_XOOPSTUBE_BADMIN . '</h4>';
77
        /** @var \XoopsModuleHandler $moduleHandler */
78
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleHandler is dead and can be removed.
Loading history...
79
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
80
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
81
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
82
        <tr valign='middle'><th align='center'>"
83
             . _AM_XOOPSTUBE_TITLE
84
             . "</th><th align='center' nowrap='nowrap'>"
85
             . _AM_XOOPSTUBE_SIDE
86
             . '<br>'
87
             . _LEFT
88
             . '-'
89
             . _CENTER
90
             . '-'
91
             . _RIGHT
92
             . "</th><th align='center'>"
93
             . _AM_XOOPSTUBE_WEIGHT
94
             . "</th><th align='center'>"
95
             . _AM_XOOPSTUBE_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
             . _AM_XOOPSTUBE_ACTION
104
             . '</th></tr>
105
        ';
106
        $block_arr   = \XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

106
        $block_arr   = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($xoopsModule->mid());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
107
        $block_count = count($block_arr);
0 ignored issues
show
Unused Code introduced by
The assignment to $block_count is dead and can be removed.
Loading history...
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
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
124
            $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
125
            $result       = $db->query($sql);
126
            $modules      = [];
127
            while (false !== ($row = $db->fetchArray($result))) {
128
                $modules[] = (int)$row['module_id'];
129
            }
130
131
            $cachetime_options = '';
132
            foreach ($cachetimes as $cachetime => $cachetime_name) {
133
                if ($i->getVar('bcachetime') == $cachetime) {
134
                    $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n";
135
                } else {
136
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
137
                }
138
            }
139
140
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
141
            if (1 === $i->getVar('visible')) {
142
                $sel1 = ' checked';
143
            } else {
144
                $sel0 = ' checked';
145
            }
146
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
147
                $ssel0 = ' checked';
148
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
149
                $ssel1 = ' checked';
150
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
151
                $ssel2 = ' checked';
152
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
153
                $ssel4 = ' checked';
154
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
155
                $ssel3 = ' checked';
156
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
157
                $ssel5 = ' checked';
158
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
159
                $ssel6 = ' checked';
160
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
161
                $ssel7 = ' checked';
162
            }
163
            if ('' === $i->getVar('title')) {
164
                $title = '&nbsp;';
165
            } else {
166
                $title = $i->getVar('title');
167
            }
168
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
169
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
170
                 . $i->getVar('bid')
171
                 . "]' value='"
172
                 . $title
173
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
174
                    <div align='center' >
175
                    <input type='radio' name='side["
176
                 . $i->getVar('bid')
177
                 . "]' value='"
178
                 . XOOPS_CENTERBLOCK_LEFT
179
                 . "'$ssel2>
180
                        <input type='radio' name='side["
181
                 . $i->getVar('bid')
182
                 . "]' value='"
183
                 . XOOPS_CENTERBLOCK_CENTER
184
                 . "'$ssel3>
185
                    <input type='radio' name='side["
186
                 . $i->getVar('bid')
187
                 . "]' value='"
188
                 . XOOPS_CENTERBLOCK_RIGHT
189
                 . "'$ssel4>
190
                    </div>
191
                    <div>
192
                        <span style='float:right;'><input type='radio' name='side["
193
                 . $i->getVar('bid')
194
                 . "]' value='"
195
                 . XOOPS_SIDEBLOCK_RIGHT
196
                 . "'$ssel1></span>
197
                    <div align='left'><input type='radio' name='side["
198
                 . $i->getVar('bid')
199
                 . "]' value='"
200
                 . XOOPS_SIDEBLOCK_LEFT
201
                 . "'$ssel0></div>
202
                    </div>
203
                    <div align='center'>
204
                    <input type='radio' name='side["
205
                 . $i->getVar('bid')
206
                 . "]' value='"
207
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
208
                 . "'$ssel5>
209
                        <input type='radio' name='side["
210
                 . $i->getVar('bid')
211
                 . "]' value='"
212
                 . XOOPS_CENTERBLOCK_BOTTOM
213
                 . "'$ssel7>
214
                    <input type='radio' name='side["
215
                 . $i->getVar('bid')
216
                 . "]' value='"
217
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
218
                 . "'$ssel6>
219
                    </div>
220
                </td><td class='$class' align='center'><input type='text' name='weight["
221
                 . $i->getVar('bid')
222
                 . "]' value='"
223
                 . $i->getVar('weight')
224
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
225
                 . $i->getVar('bid')
226
                 . "]' value='1'$sel1>"
227
                 . _YES
228
                 . "&nbsp;<input type='radio' name='visible["
229
                 . $i->getVar('bid')
230
                 . "]' value='0'$sel0>"
231
                 . _NO
232
                 . '</td>';
233
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
240
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
241
            foreach ($groups as $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
246
            // Cache lifetime
247
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
248
                                    </td>';
249
250
            // Actions
251
252
            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 . "'>
253
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
254
                 </a>";
255
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
256
                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 . "'>
257
                     </a>";
258
            }
259
            echo "
260
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
261
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
262
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
263
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
264
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
265
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
266
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
267
            </td></tr>
268
            ";
269
            $class = ('even' === $class) ? 'odd' : 'even';
270
        }
271
        echo "<tr><td class='foot' align='center' colspan='8'>
272
        <input type='hidden' name='op' value='order'>
273
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
274
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
275
        </td></tr></table>
276
        </form>
277
        <br><br>";
278
    }
279
280
    /**
281
     * @param int $bid
282
     */
283
    function cloneBlock($bid)
284
    {
285
        require_once __DIR__ . '/admin_header.php';
286
        //require_once __DIR__ . '/admin_header.php';
287
        xoops_cp_header();
288
289
        xoops_loadLanguage('admin', 'system');
290
        xoops_loadLanguage('admin/blocksadmin', 'system');
291
        xoops_loadLanguage('admin/groups', 'system');
292
293
        //        mpu_adm_menu();
294
        $myblock = new \XoopsBlock($bid);
295
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
296
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
297
        $result  = $db->query($sql);
298
        $modules = [];
299
        while (false !== ($row = $db->fetchArray($result))) {
300
            $modules[] = (int)$row['module_id'];
301
        }
302
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
303
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
304
            'title'      => $myblock->getVar('title') . ' Clone',
305
            'form_title' => _AM_XOOPSTUBE_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
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
324
        //        xoops_cp_footer();
325
        require_once __DIR__ . '/admin_footer.php';
326
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

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

Loading history...
327
    }
328
329
    /**
330
     * @param int $bid
331
     * @param     $bside
332
     * @param     $bweight
333
     * @param     $bvisible
334
     * @param     $bcachetime
335
     * @param     $bmodule
336
     * @param     $options
337
     */
338
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
339
    {
340
        xoops_loadLanguage('admin', 'system');
341
        xoops_loadLanguage('admin/blocksadmin', 'system');
342
        xoops_loadLanguage('admin/groups', 'system');
343
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
Best Practice introduced by
Using exit here is not recommended.

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

Loading history...
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
Best Practice introduced by
Using exit here is not recommended.

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

Loading history...
374
        }
375
        if ('' !== $clone->getVar('template')) {
376
            /** @var \XoopsTplfileHandler $tplfileHandler */
377
            $tplfileHandler = xoops_getHandler('tplfile');
378
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
379
            if (count($btemplate) > 0) {
380
                $tplclone = $btemplate[0]->xoopsClone();
381
                $tplclone->setVar('tpl_id', 0);
382
                $tplclone->setVar('tpl_refid', $newid);
383
                $tplfileHandler->insert($tplclone);
384
            }
385
        }
386
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
387
        foreach ($bmodule as $bmid) {
388
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
389
            $db->query($sql);
390
        }
391
        $groups = &$GLOBALS['xoopsUser']->getGroups();
392
        foreach ($groups as $iValue) {
393
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
394
            $db->query($sql);
395
        }
396
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
397
    }
398
399
    /**
400
     * @param int    $bid
401
     * @param string $title
402
     * @param int    $weight
403
     * @param bool   $visible
404
     * @param        $side
405
     * @param int    $bcachetime
406
     */
407
    function xtubeSetOrder($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();
416
        /** @var \XoopsBlockHandler $blockHandler */
417
        $blockHandler = xoops_getHandler('block');
418
        return $blockHandler->insert($myblock);
419
    }
420
421
    /**
422
     * @param int $bid
423
     */
424
    function xtubeEditBlock($bid)
425
    {
426
        require_once __DIR__ . '/admin_header.php';
427
        //require_once __DIR__ . '/admin_header.php';
428
        xoops_cp_header();
429
430
        xoops_loadLanguage('admin', 'system');
431
        xoops_loadLanguage('admin/blocksadmin', 'system');
432
        xoops_loadLanguage('admin/groups', 'system');
433
        //        mpu_adm_menu();
434
        $myblock = new \XoopsBlock($bid);
435
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
436
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
437
        $result  = $db->query($sql);
438
        $modules = [];
439
        while (false !== ($row = $db->fetchArray($result))) {
440
            $modules[] = (int)$row['module_id'];
441
        }
442
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
443
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
444
            'title'      => $myblock->getVar('title'),
445
            'form_title' => _AM_XOOPSTUBE_BLOCKS_EDITBLOCK,
446
            //        'name'       => $myblock->getVar('name'),
447
            'side'       => $myblock->getVar('side'),
448
            'weight'     => $myblock->getVar('weight'),
449
            'visible'    => $myblock->getVar('visible'),
450
            'content'    => $myblock->getVar('content', 'N'),
451
            'modules'    => $modules,
452
            'is_custom'  => $is_custom,
453
            'ctype'      => $myblock->getVar('c_type'),
454
            'bcachetime' => $myblock->getVar('bcachetime'),
455
            'op'         => 'edit_ok',
456
            'bid'        => $myblock->getVar('bid'),
457
            'edit_form'  => $myblock->getOptions(),
458
            'template'   => $myblock->getVar('template'),
459
            'options'    => $myblock->getVar('options'),
460
        ];
461
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
462
        require_once __DIR__ . '/blockform.php';
463
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
464
        //        xoops_cp_footer();
465
        require_once __DIR__ . '/admin_footer.php';
466
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

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

Loading history...
467
    }
468
469
    /**
470
     * @param int               $bid
471
     * @param string            $btitle
472
     * @param string            $bside
473
     * @param int               $bweight
474
     * @param bool              $bvisible
475
     * @param int               $bcachetime
476
     * @param array             $bmodule
477
     * @param null|array|string $options
478
     * @param null|array        $groups
479
     */
480
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

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

480
    function xtubeUpdateBlock($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...
Unused Code introduced by
The parameter $bmodule 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

480
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, /** @scrutinizer ignore-unused */ $bmodule, $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...
Unused Code introduced by
The parameter $groups 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

480
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, /** @scrutinizer ignore-unused */ $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...
481
    {
482
        $myblock = new \XoopsBlock($bid);
483
        $myblock->setVar('title', $btitle);
484
        $myblock->setVar('weight', $bweight);
485
        $myblock->setVar('visible', $bvisible);
486
        $myblock->setVar('side', $bside);
487
        $myblock->setVar('bcachetime', $bcachetime);
488
        //        $myblock->store();
489
        /** @var \XoopsBlockHandler $blockHandler */
490
        $blockHandler = xoops_getHandler('block');
491
        return $blockHandler->insert($myblock);
492
493
        if (!empty($bmodule) && count($bmodule) > 0) {
0 ignored issues
show
Unused Code introduced by
IfNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

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

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