Passed
Branch master (7e303a)
by Michael
02:15
created

admin/blocksadmin.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * PHP version 5
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project
12
 * @link            https://www.xoops.org
13
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
16
use Xmf\Request;
17
18
require __DIR__ . '/admin_header.php';
19
20
$moduleDirName      = basename(dirname(__DIR__));
21
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
22
23
if (!is_object($xoopsModule) || !is_object($GLOBALS['xoopsUser'])
24
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
25
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
26
}
27
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
28
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
29
    $op = 'list';
30
    if (isset($_POST)) {
31
        foreach ($_POST as $k => $v) {
32
            ${$k} = $v;
33
        }
34
    }
35
    /*
36
        if (Request::hasVar('op')) {
37
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
38
                || $_GET['op'] === "edit"
39
            ) {
40
                $op  = $_GET['op'];
41
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
42
            }
43
        }
44
    */
45
46
    $op = Request::getString('op', $op);
47
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
48
        $bid = Request::getInt('bid', 0, 'GET');
49
    }
50
51
    function listBlocks()
52
    {
53
        global $xoopsModule, $pathIcon16;
54
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
55
        $moduleDirName      = basename(dirname(__DIR__));
56
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
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;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
77
        $moduleHandler = xoops_getHandler('module');
78
        echo "<form action='" . $_SERVER['PHP_SELF'] . "' name='blockadmin' method='post'>";
79
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
80
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
81
        <tr valign='middle'><th align='center'>"
82
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
83
             . "</th><th align='center' nowrap='nowrap'>"
84
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
85
             . '<br>'
86
             . _LEFT
87
             . '-'
88
             . _CENTER
89
             . '-'
90
             . _RIGHT
91
             . "</th><th align='center'>"
92
             . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT')
93
             . "</th><th align='center'>"
94
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
95
             . "</th><th align='center'>"
96
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
97
             . "</th><th align='center'>"
98
             . _AM_SYSTEM_ADGS
99
             . "</th><th align='center'>"
100
             . _AM_SYSTEM_BLOCKS_BCACHETIME
101
             . "</th><th align='center'>"
102
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
103
             . '</th></tr>
104
        ';
105
        $block_arr   = \XoopsBlock::getByModule($xoopsModule->mid());
106
        $block_count = count($block_arr);
107
        $class       = 'even';
108
        $cachetimes  = [
109
            '0'       => _NOCACHE,
110
            '30'      => sprintf(_SECONDS, 30),
111
            '60'      => _MINUTE,
112
            '300'     => sprintf(_MINUTES, 5),
113
            '1800'    => sprintf(_MINUTES, 30),
114
            '3600'    => _HOUR,
115
            '18000'   => sprintf(_HOURS, 5),
116
            '86400'   => _DAY,
117
            '259200'  => sprintf(_DAYS, 3),
118
            '604800'  => _WEEK,
119
            '2592000' => _MONTH,
120
        ];
121
        foreach ($block_arr as $i) {
122
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
123
            $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
124
            $result       = $db->query($sql);
125
            $modules      = [];
126
            while (false !== ($row = $db->fetchArray($result))) {
127
                $modules[] = (int)$row['module_id'];
128
            }
129
130
            $cachetime_options = '';
131
            foreach ($cachetimes as $cachetime => $cachetime_name) {
132
                if ($i->getVar('bcachetime') == $cachetime) {
133
                    $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n";
134
                } else {
135
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
136
                }
137
            }
138
139
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
140
            if (1 === $i->getVar('visible')) {
141
                $sel1 = ' checked';
142
            } else {
143
                $sel0 = ' checked';
144
            }
145
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
146
                $ssel0 = ' checked';
147
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
148
                $ssel1 = ' checked';
149
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
150
                $ssel2 = ' checked';
151
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
152
                $ssel4 = ' checked';
153
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
154
                $ssel3 = ' checked';
155
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
156
                $ssel5 = ' checked';
157
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
158
                $ssel6 = ' checked';
159
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
160
                $ssel7 = ' checked';
161
            }
162
            if ('' === $i->getVar('title')) {
163
                $title = '&nbsp;';
164
            } else {
165
                $title = $i->getVar('title');
166
            }
167
            $name = $i->getVar('name');
168
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
169
                 . $i->getVar('bid')
170
                 . "]' value='"
171
                 . $title
172
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
173
                    <div align='center' >
174
                    <input type='radio' name='side["
175
                 . $i->getVar('bid')
176
                 . "]' value='"
177
                 . XOOPS_CENTERBLOCK_LEFT
178
                 . "'$ssel2>
179
                        <input type='radio' name='side["
180
                 . $i->getVar('bid')
181
                 . "]' value='"
182
                 . XOOPS_CENTERBLOCK_CENTER
183
                 . "'$ssel3>
184
                    <input type='radio' name='side["
185
                 . $i->getVar('bid')
186
                 . "]' value='"
187
                 . XOOPS_CENTERBLOCK_RIGHT
188
                 . "'$ssel4>
189
                    </div>
190
                    <div>
191
                        <span style='float:right;'><input type='radio' name='side["
192
                 . $i->getVar('bid')
193
                 . "]' value='"
194
                 . XOOPS_SIDEBLOCK_RIGHT
195
                 . "'$ssel1></span>
196
                    <div align='left'><input type='radio' name='side["
197
                 . $i->getVar('bid')
198
                 . "]' value='"
199
                 . XOOPS_SIDEBLOCK_LEFT
200
                 . "'$ssel0></div>
201
                    </div>
202
                    <div align='center'>
203
                    <input type='radio' name='side["
204
                 . $i->getVar('bid')
205
                 . "]' value='"
206
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
207
                 . "'$ssel5>
208
                        <input type='radio' name='side["
209
                 . $i->getVar('bid')
210
                 . "]' value='"
211
                 . XOOPS_CENTERBLOCK_BOTTOM
212
                 . "'$ssel7>
213
                    <input type='radio' name='side["
214
                 . $i->getVar('bid')
215
                 . "]' value='"
216
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
217
                 . "'$ssel6>
218
                    </div>
219
                </td><td class='$class' align='center'><input type='text' name='weight["
220
                 . $i->getVar('bid')
221
                 . "]' value='"
222
                 . $i->getVar('weight')
223
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
224
                 . $i->getVar('bid')
225
                 . "]' value='1'$sel1>"
226
                 . _YES
227
                 . "&nbsp;<input type='radio' name='visible["
228
                 . $i->getVar('bid')
229
                 . "]' value='0'$sel0>"
230
                 . _NO
231
                 . '</td>';
232
233
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
234
            foreach ($module_list as $k => $v) {
235
                echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
236
            }
237
            echo '</select></td>';
238
239
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
240
            foreach ($groups as $grp) {
241
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
242
            }
243
            echo '</select></td>';
244
245
            // Cache lifetime
246
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
247
                                    </td>';
248
249
            // Actions
250
251
            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 . "'>
252
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
253
                 </a>";
254
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
255
                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 . "'>
256
                     </a>";
257
            }
258
            echo "
259
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
260
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
261
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
262
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
263
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
264
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
265
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
266
            </td></tr>
267
            ";
268
            $class = ('even' === $class) ? 'odd' : 'even';
269
        }
270
        echo "<tr><td class='foot' align='center' colspan='7'>
271
        <input type='hidden' name='op' value='order'>
272
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
273
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
274
        </td></tr></table>
275
        </form>
276
        <br><br>";
277
    }
278
279
    /**
280
     * @param $bid
281
     */
282
    function cloneBlock($bid)
283
    {
284
        require_once __DIR__ . '/admin_header.php';
285
286
        xoops_cp_header();
287
288
        /** @var \Xmf\Module\Admin $adminObject */
289
        $adminObject = \Xmf\Module\Admin::getInstance();
290
        $adminObject->displayNavigation(basename(__FILE__));
291
        $moduleDirName      = basename(dirname(__DIR__));
292
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
293
294
        xoops_loadLanguage('admin', 'system');
295
        xoops_loadLanguage('admin/blocksadmin', 'system');
296
        xoops_loadLanguage('admin/groups', 'system');
297
298
        //        mpu_adm_menu();
299
        $myblock = new \XoopsBlock($bid);
300
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
301
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
302
        $result  = $db->query($sql);
303
        $modules = [];
304
        while (false !== ($row = $db->fetchArray($result))) {
305
            $modules[] = (int)$row['module_id'];
306
        }
307
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
308
        $block     = [
309
            'title'      => $myblock->getVar('title') . ' Clone',
310
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
311
            'name'       => $myblock->getVar('name'),
312
            'side'       => $myblock->getVar('side'),
313
            'weight'     => $myblock->getVar('weight'),
314
            'visible'    => $myblock->getVar('visible'),
315
            'content'    => $myblock->getVar('content', 'N'),
316
            'modules'    => $modules,
317
            'is_custom'  => $is_custom,
318
            'ctype'      => $myblock->getVar('c_type'),
319
            'bcachetime' => $myblock->getVar('bcachetime'),
320
            'op'         => 'clone_ok',
321
            'bid'        => $myblock->getVar('bid'),
322
            'edit_form'  => $myblock->getOptions(),
323
            'template'   => $myblock->getVar('template'),
324
            'options'    => $myblock->getVar('options'),
325
        ];
326
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
327
        require_once __DIR__ . '/blockform.php';
328
        $form->display();
329
        //        xoops_cp_footer();
330
        require_once __DIR__ . '/admin_footer.php';
331
        exit();
332
    }
333
334
    /**
335
     * @param int $bid
336
     * @param string $bside
337
     * @param int $bweight
338
     * @param bool $bvisible
339
     * @param int $bcachetime
340
     * @param string $bmodule
341
     * @param null|array $options
342
     */
343
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options = null)
344
    {
345
        xoops_loadLanguage('admin', 'system');
346
        xoops_loadLanguage('admin/blocksadmin', 'system');
347
        xoops_loadLanguage('admin/groups', 'system');
348
349
        /** @var \XoopsBlock $block */
350
        $block = new \XoopsBlock($bid);
351
        $clone = $block->xoopsClone();
352
        if (empty($bmodule)) {
353
            xoops_cp_header();
354
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
355
            xoops_cp_footer();
356
            exit();
357
        }
358
        $clone->setVar('side', $bside);
359
        $clone->setVar('weight', $bweight);
360
        $clone->setVar('visible', $bvisible);
361
        //$clone->setVar('content', $_POST['bcontent']);
362
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
363
        $clone->setVar('bcachetime', $bcachetime);
364
        if (null !== $options && (count($options) > 0)) {
365
            $options = implode('|', $options);
366
            $clone->setVar('options', $options);
367
        }
368
        $clone->setVar('bid', 0);
369
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
370
            $clone->setVar('block_type', 'E');
371
        } else {
372
            $clone->setVar('block_type', 'D');
373
        }
374
        $newid = $clone->store();
375
        if (!$newid) {
376
            xoops_cp_header();
377
            $clone->getHtmlErrors();
378
            xoops_cp_footer();
379
            exit();
380
        }
381
        if ('' !== $clone->getVar('template')) {
382
            /** @var \XoopsTplfileHandler $tplfileHandler */
383
            $tplfileHandler = xoops_getHandler('tplfile');
384
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
385
            if (count($btemplate) > 0) {
386
                $tplclone = $btemplate[0]->xoopsClone();
387
                $tplclone->setVar('tpl_id', 0);
388
                $tplclone->setVar('tpl_refid', $newid);
389
                $tplfileHandler->insert($tplclone);
390
            }
391
        }
392
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
393
        foreach ($bmodule as $bmid) {
0 ignored issues
show
The expression $bmodule of type string is not traversable.
Loading history...
394
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
395
            $db->query($sql);
396
        }
397
        $groups =& $GLOBALS['xoopsUser']->getGroups();
398
        $count  = count($groups);
399
        for ($i = 0; $i < $count; ++$i) {
400
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
401
            $db->query($sql);
402
        }
403
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
404
    }
405
406
    /**
407
     * @param $bid
408
     * @param $title
409
     * @param $weight
410
     * @param $visible
411
     * @param $side
412
     * @param $bcachetime
413
     */
414
    function xtubeSetOrder($bid, $title, $weight, $visible, $side, $bcachetime)
415
    {
416
        $myblock = new \XoopsBlock($bid);
417
        $myblock->setVar('title', $title);
418
        $myblock->setVar('weight', $weight);
419
        $myblock->setVar('visible', $visible);
420
        $myblock->setVar('side', $side);
421
        $myblock->setVar('bcachetime', $bcachetime);
422
        $myblock->store();
423
    }
424
425
    /**
426
     * @param $bid
427
     */
428
    function xtubeEditBlock($bid)
429
    {
430
        require_once __DIR__ . '/admin_header.php';
431
        xoops_cp_header();
432
        /** @var \Xmf\Module\Admin $adminObject */
433
        $adminObject = \Xmf\Module\Admin::getInstance();
434
        $adminObject->displayNavigation(basename(__FILE__));
435
        $moduleDirName      = basename(dirname(__DIR__));
436
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
437
438
        xoops_loadLanguage('admin', 'system');
439
        xoops_loadLanguage('admin/blocksadmin', 'system');
440
        xoops_loadLanguage('admin/groups', 'system');
441
        //        mpu_adm_menu();
442
        $myblock = new \XoopsBlock($bid);
443
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
444
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
445
        $result  = $db->query($sql);
446
        $modules = [];
447
        while (false !== ($row = $db->fetchArray($result))) {
448
            $modules[] = (int)$row['module_id'];
449
        }
450
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
451
        $block     = [
452
            'title'      => $myblock->getVar('title'),
453
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
454
            //        'name'       => $myblock->getVar('name'),
455
            'side'       => $myblock->getVar('side'),
456
            'weight'     => $myblock->getVar('weight'),
457
            'visible'    => $myblock->getVar('visible'),
458
            'content'    => $myblock->getVar('content', 'N'),
459
            'modules'    => $modules,
460
            'is_custom'  => $is_custom,
461
            'ctype'      => $myblock->getVar('c_type'),
462
            'bcachetime' => $myblock->getVar('bcachetime'),
463
            'op'         => 'edit_ok',
464
            'bid'        => $myblock->getVar('bid'),
465
            'edit_form'  => $myblock->getOptions(),
466
            'template'   => $myblock->getVar('template'),
467
            'options'    => $myblock->getVar('options'),
468
        ];
469
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
470
        require_once __DIR__ . '/blockform.php';
471
        $form->display();
472
        //        xoops_cp_footer();
473
        require_once __DIR__ . '/admin_footer.php';
474
        exit();
475
    }
476
477
    /**
478
     * @param $bid
479
     * @param $btitle
480
     * @param $bside
481
     * @param $bweight
482
     * @param $bvisible
483
     * @param $bcachetime
484
     * @param $bmodule
485
     * @param $options
486
     * @param $groups
487
     */
488
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
489
    {
490
        $myblock = new \XoopsBlock($bid);
491
        $myblock->setVar('title', $btitle);
492
        $myblock->setVar('weight', $bweight);
493
        $myblock->setVar('visible', $bvisible);
494
        $myblock->setVar('side', $bside);
495
        $myblock->setVar('bcachetime', $bcachetime);
496
        $myblock->store();
497
498
        if (!empty($bmodule) && count($bmodule) > 0) {
499
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
500
            $GLOBALS['xoopsDB']->query($sql);
501
            if (in_array(0, $bmodule)) {
502
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
503
                $GLOBALS['xoopsDB']->query($sql);
504
            } else {
505
                foreach ($bmodule as $bmid) {
506
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
507
                    $GLOBALS['xoopsDB']->query($sql);
508
                }
509
            }
510
        }
511
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
512
        $GLOBALS['xoopsDB']->query($sql);
513
        if (!empty($groups)) {
514
            foreach ($groups as $grp) {
515
                $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);
516
                $GLOBALS['xoopsDB']->query($sql);
517
            }
518
        }
519
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
520
    }
521
522
    if ('list' === $op) {
523
        xoops_cp_header();
524
        $adminObject->displayNavigation(basename(__FILE__));
525
        listBlocks();
526
        require_once __DIR__ . '/admin_footer.php';
527
        exit();
528
    }
529
530
    if ('order' === $op) {
531
        if (!$GLOBALS['xoopsSecurity']->check()) {
532
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
533
        }
534
        foreach (array_keys($bid) as $i) {
535
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
536
                || $oldside[$i] !== $side[$i]
537
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
538
                xtubeSetOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
539
            }
540
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
541
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]);
542
                $GLOBALS['xoopsDB']->query($sql);
543
                if (in_array(0, $bmodule[$i])) {
544
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0);
545
                    $GLOBALS['xoopsDB']->query($sql);
546
                } else {
547
                    foreach ($bmodule[$i] as $bmid) {
548
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid);
549
                        $GLOBALS['xoopsDB']->query($sql);
550
                    }
551
                }
552
            }
553
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]);
554
            $GLOBALS['xoopsDB']->query($sql);
555
            if (!empty($groups[$i])) {
556
                foreach ($groups[$i] as $grp) {
557
                    $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]);
558
                    $GLOBALS['xoopsDB']->query($sql);
559
                }
560
            }
561
        }
562
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
563
    }
564
    if ('clone' === $op) {
565
        cloneBlock($bid);
566
    }
567
568
    if ('edit' === $op) {
569
        xtubeEditBlock($bid);
570
    }
571
572
    if ('edit_ok' === $op) {
573
        xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
574
    }
575
576
    if ('clone_ok' === $op) {
577
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
578
    }
579
} else {
580
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
581
}
582