myblocksadmin.php ➔ list_groups()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 0
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
// ------------------------------------------------------------------------- //
3
//                            myblocksadmin.php                              //
4
//                - XOOPS block admin for each modules -                     //
5
//                          GIJOE <http://www.peak.ne.jp/>                   //
6
// ------------------------------------------------------------------------- //
7
8
include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
9
include __DIR__ . '/admin_header.php';
10
//include_once XOOPS_ROOT_PATH."/modules/" . $xoopsModule->getVar("dirname") . "/class/admin.php";
11
12
include_once __DIR__ . '/mygrouppermform.php';
13
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
14
include_once dirname(__DIR__) . '/include/gtickets.php';// GIJ
15
16
$xoops_system_path = XOOPS_ROOT_PATH . '/modules/system';
17
18
// language files
19
$language = $xoopsConfig['language'];
20
if (!file_exists("{$xoops_system_path}/language/{$language}/admin/blocksadmin.php")) {
21
    $language = 'english';
22
}
23
24
// to prevent from notice that constants already defined
25
$error_reporting_level = error_reporting(0);
26
include_once "{$xoops_system_path}/constants.php";
27
include_once "{$xoops_system_path}/language/{$language}/admin.php";
28
include_once "{$xoops_system_path}/language/{$language}/admin/blocksadmin.php";
29
error_reporting($error_reporting_level);
30
31
$group_defs = file("{$xoops_system_path}/language/{$language}/admin/groups.php");
32
foreach ($group_defs as $def) {
33
    if (false !== strpos($def, '_AM_MYLINKS_ACCESSRIGHTS') || false !== strpos($def, '_AM_MYLINKS_ACTIVERIGHTS')) {
34
        eval($def);
35
    }
36
}
37
38
// check $xoopsModule
39
if (!is_object($xoopsModule)) {
40
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
41
}
42
43
// set target_module if specified by $_GET['dirname']
44
$moduleHandler = xoops_getHandler('module');
45
46
if (!empty($_GET['dirname'])) {
47
    $target_module = $moduleHandler->getByDirname($_GET['dirname']);
48
}/* else if( ! empty( $_GET['mid'] ) ) {
49
  $target_module = $moduleHandler->get( intval( $_GET['mid'] ) );
50
}*/
51
52
if (!empty($target_module) && is_object($target_module)) {
53
    // specified by dirname
54
    $target_mid     = $target_module->getVar('mid');
55
    $target_mname   = $target_module->getVar('name') . '&nbsp;' . sprintf('(%2.2f)', $target_module->getVar('version') / 100.0);
56
    $query4redirect = '?dirname=' . urlencode(strip_tags($_GET['dirname']));
57
} elseif (isset($_GET['mid']) && $_GET['mid'] == 0 || $xoopsModule->getVar('dirname') == 'blocksadmin') {
58
    $target_mid     = 0;
59
    $target_mname   = '';
60
    $query4redirect = '?mid=0';
61
} else {
62
    $target_mid     = $xoopsModule->getVar('mid');
63
    $target_mname   = $xoopsModule->getVar('name');
64
    $query4redirect = '';
65
}
66
67
// check access right (needs system_admin of BLOCK)
68
$syspermHandler = xoops_getHandler('groupperm');
69 View Code Duplication
if (!$syspermHandler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) {
0 ignored issues
show
Duplication introduced by
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...
70
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
71
}
72
73
// get blocks owned by the module (Imported from xoopsblock.php then modified)
74
//$block_arr =& XoopsBlock::getByModule( $target_mid );
75
$db        = XoopsDatabaseFactory::getDatabaseConnection();
76
$sql       = 'SELECT * FROM ' . $db->prefix('newblocks') . " WHERE mid='{$target_mid}' ORDER BY visible DESC,side,weight";
77
$result    = $db->query($sql);
78
$block_arr = array();
79
while ($myrow = $db->fetchArray($result)) {
80
    $block_arr[] = new XoopsBlock($myrow);
81
}
82
83
function list_groups()
84
{
85
    global $target_mid, $target_mname, $block_arr;
86
87
    $item_list = array();
88
    foreach (array_keys($block_arr) as $i) {
89
        $item_list[$block_arr[$i]->getVar('bid')] = $block_arr[$i]->getVar('title');
90
    }
91
92
    $form = new MyXoopsGroupPermForm(_AM_MYLINKS_AGDS, 1, 'block_read', '');
93
    if ($target_mid > 1) {
94
        $form->addAppendix('module_admin', $target_mid, $target_mname . ' ' . _AM_MYLINKS_ACTIVERIGHTS);
95
        $form->addAppendix('module_read', $target_mid, $target_mname . ' ' . _AM_MYLINKS_ACCESSRIGHTS);
96
    }
97
    foreach ($item_list as $item_id => $item_name) {
98
        $form->addItem($item_id, $item_name);
99
    }
100
    echo $form->render();
101
}
102
103
if (!empty($_POST['submit'])) {
104 View Code Duplication
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
0 ignored issues
show
Duplication introduced by
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...
105
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
106
    }
107
108
    include 'mygroupperm.php';
109
    redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/admin/myblocksadmin.php{$query4redirect}", 1, _MD_MYLINKS_DBUPDATED);
110
}
111
112
xoops_cp_header();
113
$indexAdmin = new ModuleAdmin();
114
echo $indexAdmin->addNavigation(basename(__FILE__));
115
116
if (file_exists('./mymenu.php')) {
117
    include './mymenu.php';
118
}
119
120
list_groups();
121
include __DIR__ . '/admin_footer.php';
122