Passed
Branch master (e5d775)
by Michael
25:14 queued 11:39
created

editBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 47
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 37
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 47
rs 9.328
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.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
16
use Xmf\Module\Admin;
17
use Xmf\Request;
1 ignored issue
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use XoopsModules\Publisher\{
19
    Common\Blocksadmin,
20
    Helper
21
};
22
23
/** @var Admin $adminObject */
24
/** @var Helper $helper */
25
26
require __DIR__ . '/admin_header.php';
27
xoops_cp_header();
28
29
$moduleDirName      = $helper->getDirname();
30
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
31
32
/** @var \XoopsMySQLDatabase $xoopsDB */
33
$xoopsDB     = \XoopsDatabaseFactory::getDatabaseConnection();
34
$blocksadmin = new Blocksadmin($xoopsDB, $helper);
35
36
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
37
38
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
39
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
40
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
41
}
42
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
43
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
44
45
    $op = Request::getCmd('op', 'list');
46
    if (!empty($_POST)) {
47
        $ok             = Request::getInt('ok', 0, 'POST');
48
        $confirm_submit = Request::getCmd('confirm_submit', '', 'POST');
49
        $submit         = Request::getString('submit', '', 'POST');
50
        $bside          = Request::getString('bside', '0', 'POST');
51
        $bweight        = Request::getString('bweight', '0', 'POST');
52
        $bvisible       = Request::getString('bvisible', '0', 'POST');
53
        $bmodule        = Request::getArray('bmodule', [], 'POST');
54
        $btitle         = Request::getString('btitle', '', 'POST');
55
        $bcachetime     = Request::getString('bcachetime', '0', 'POST');
56
        $groups         = Request::getArray('groups', [], 'POST');
57
        $options        = Request::getArray('options', [], 'POST');
58
        $submitblock    = Request::getString('submitblock', '', 'POST');
59
        $fct            = Request::getString('fct', '', 'POST');
60
        $title          = Request::getString('title', '', 'POST');
61
        $side           = Request::getString('side', '0', 'POST');
62
        $weight         = Request::getString('weight', '0', 'POST');
63
        $visible        = Request::getString('visible', '0', 'POST');
64
    }
65
66
    if ('list' === $op) {
67
        //        xoops_cp_header();
68
        $blocksadmin->listBlocks();
69
        require_once __DIR__ . '/admin_footer.php';
70
        exit();
71
    }
72
73
    if (\in_array($op, ['edit', 'edit_ok', 'delete', 'delete_ok', 'clone', 'clone_ok'])) {
74
        $bid = Request::getInt('bid', 0);
75
        $ok  = Request::getInt('ok', 0);
76
77
        if ('clone' === $op) {
78
            $blocksadmin->cloneBlock($bid);
79
        }
80
81
        if ('delete' === $op) {
82
            if (1 === $ok) {
83
                //            if (!$GLOBALS['xoopsSecurity']->check()) {
84
                //                redirect_header($helper->url('admin/blocksadmin.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
85
                //            }
86
                $blocksadmin->deleteBlock($bid);
87
            } else {
88
                //            xoops_cp_header();
89
                xoops_confirm(['ok' => 1, 'op' => 'delete', 'bid' => $bid], 'blocksadmin.php', constant('CO_' . $moduleDirNameUpper . '_' . 'DELETE_BLOCK_CONFIRM'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true);
90
                xoops_cp_footer();
91
            }
92
        }
93
94
        if ('edit' === $op) {
95
            $blocksadmin->editBlock($bid);
96
        }
97
98
        if ('edit_ok' === $op) {
99
            $blocksadmin->updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
100
        }
101
102
        if ('clone_ok' === $op) {
103
            $blocksadmin->isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
104
        }
105
    }
106
107
    if ('order' === $op) {
108
        $bid = Request::getArray('bid', []);
109
110
        $title      = Request::getArray('title', [], 'POST');
111
        $side       = Request::getArray('side', [], 'POST');
112
        $weight     = Request::getArray('weight', [], 'POST');
113
        $visible    = Request::getArray('visible', [], 'POST');
114
        $bcachetime = Request::getArray('bcachetime', [], 'POST');
115
        $bmodule    = Request::getArray('bmodule', [], 'POST');//mb
116
117
        $oldtitle      = Request::getArray('oldtitle', [], 'POST');
118
        $oldside       = Request::getArray('oldside', [], 'POST');
119
        $oldweight     = Request::getArray('oldweight', [], 'POST');
120
        $oldvisible    = Request::getArray('oldvisible', [], 'POST');
121
        $oldgroups     = Request::getArray('oldgroups', [], 'POST');
122
        $oldbcachetime = Request::getArray('oldcachetime', [], 'POST');
123
        $oldbmodule    = Request::getArray('oldbmodule', [], 'POST');//mb
124
125
        $blocksadmin->orderBlock(
126
            $bid,
127
            $oldtitle,
128
            $oldside,
129
            $oldweight,
130
            $oldvisible,
131
            $oldgroups,
132
            $oldbcachetime,
133
            $oldbmodule,
134
            $title,
135
            $weight,
136
            $visible,
137
            $side,
138
            $bcachetime,
139
            $groups,
140
            $bmodule
141
        );
142
    }
143
} else {
144
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
145
}
146
147
require __DIR__ . '/admin_footer.php';
148