Passed
Branch master (11f048)
by Michael
13:33
created

cloneBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 47
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 2
eloc 38
nc 2
nop 1
dl 0
loc 47
rs 9.312
c 3
b 0
f 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project
12
 * @link            https://xoops.org
13
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
16
use Xmf\Module\Admin;
17
use Xmf\Request;
18
use XoopsModules\Publisher\Common\Blocksadmin;
19
use XoopsModules\Publisher\Helper;
20
21
/** @var Admin $adminObject */
22
/** @var Helper $helper */
23
require __DIR__ . '/admin_header.php';
24
xoops_cp_header();
25
26
$moduleDirName      = $helper->getDirname();
27
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
28
29
/** @var \XoopsMySQLDatabase $xoopsDB */
30
$xoopsDB     = \XoopsDatabaseFactory::getDatabaseConnection();
31
$blocksadmin = new Blocksadmin($xoopsDB, $helper);
32
33
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
34
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
35
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
36
}
37
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
38
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
39
40
    $op = Request::getCmd('op', 'list');
41
    if (isset($_POST)) {
42
        $ok             = Request::getInt('ok', 0, 'POST');
43
        $confirm_submit = Request::getCmd('confirm_submit', '', 'POST');
44
        $submit         = Request::getString('submit', '', 'POST');
45
46
        $bside       = Request::getString('bside', '0', 'POST');
47
        $bweight     = Request::getString('bweight', '0', 'POST');
48
        $bvisible    = Request::getString('bvisible', '0', 'POST');
49
        $bmodule     = Request::getArray('bmodule', [], 'POST');
50
        $btitle      = Request::getString('btitle', '', 'POST');
51
        $bcachetime  = Request::getString('bcachetime', '0', 'POST');
52
        $groups      = Request::getArray('groups', [], 'POST');
53
        $options     = Request::getArray('options', [], 'POST');
54
        $submitblock = Request::getString('submitblock', '', 'POST');
55
        $fct         = Request::getString('fct', '', 'POST');
56
57
        $title   = Request::getString('title', '', 'POST');
58
        $side    = Request::getString('side', '0', 'POST');
59
        $weight  = Request::getString('weight', '0', 'POST');
60
        $visible = Request::getString('visible', '0', 'POST');
61
    }
62
63
    if (\in_array($op, ['edit', 'edit_ok', 'delete', 'delete_ok', 'clone', 'clone_ok'], true)) {
64
        $bid = Request::getInt('bid', 0);
65
    }
66
67
    if ('order' === $op) {
68
        $bid = Request::getArray('bid', []);
69
70
        $title      = Request::getArray('title', [], 'POST');
71
        $side       = Request::getArray('side', [], 'POST');
72
        $weight     = Request::getArray('weight', [], 'POST');
73
        $visible    = Request::getArray('visible', [], 'POST');
74
        $bcachetime = Request::getArray('bcachetime', [], 'POST');
75
76
        $oldtitle      = Request::getArray('oldtitle', [], 'POST');
77
        $oldside       = Request::getArray('oldside', [], 'POST');
78
        $oldweight     = Request::getArray('oldweight', [], 'POST');
79
        $oldvisible    = Request::getArray('oldvisible', [], 'POST');
80
        $oldgroups     = Request::getArray('oldgroups', [], 'POST');
81
        $oldbcachetime = Request::getArray('oldcachetime', [], 'POST');
82
    }
83
84
    if ('list' === $op) {
85
        //        xoops_cp_header();
86
        $blocksadmin->listBlocks();
87
        require_once __DIR__ . '/admin_footer.php';
88
        exit();
89
    }
90
91
    if ('order' === $op) {
92
        $blocksadmin->orderBlock(
93
            $bid,
94
            $oldtitle,
95
            $oldside,
96
            $oldweight,
97
            $oldvisible,
98
            $oldgroups,
99
            $oldbcachetime,
100
            $title,
101
            $weight,
102
            $visible,
103
            $side,
104
            $bcachetime,
105
            $groups,
106
            $bmodule = null
107
        );
108
    }
109
110
    if ('clone' === $op) {
111
        $blocksadmin->cloneBlock($bid);
112
    }
113
114
    if ('delete' === $op) {
115
        if (1 === $ok) {
116
            //            if (!$GLOBALS['xoopsSecurity']->check()) {
117
            //                redirect_header($helper->url('admin/blocksadmin.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
118
            //            }
119
            $blocksadmin->deleteBlock($bid);
120
        } else {
121
            //            xoops_cp_header();
122
            xoops_confirm(['ok' => 1, 'op' => 'delete', 'bid' => $bid], 'blocksadmin.php', constant('CO_' . $moduleDirNameUpper . '_' . 'DELETE_BLOCK_CONFIRM'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true);
123
            xoops_cp_footer();
124
        }
125
    }
126
127
    if ('edit' === $op) {
128
        $blocksadmin->editBlock($bid);
129
    }
130
131
    if ('edit_ok' === $op) {
132
        $blocksadmin->updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
133
    }
134
135
    if ('clone_ok' === $op) {
136
        $blocksadmin->isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
137
    }
138
} else {
139
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
140
}
141
142
require __DIR__ . '/admin_footer.php';
143