showButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
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
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Chess\Common;
21
22
require __DIR__ . '/admin_header.php';
23
// Display Admin header
24
xoops_cp_header();
25
$adminObject = \Xmf\Module\Admin::getInstance();
26
27
//check or upload folders
28
$configurator = new Common\Configurator();
29
//foreach (array_keys($configurator->uploadFolders) as $i) {
30
//    $utility::createFolder($configurator->uploadFolders[$i]);
31
//    $adminObject->addConfigBoxLine($configurator->uploadFolders[$i], 'folder');
32
//}
33
34
$adminObject->displayNavigation(basename(__FILE__));
35
36
//check for latest release
37
//$newRelease = $utility->checkVerModule($helper);
38
//if (!empty($newRelease)) {
39
//    $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"');
40
//}
41
42
//------------- Test Data ----------------------------
43
44
if ($helper->getConfig('displaySampleButton')) {
45
    $yamlFile = dirname(__DIR__) . '/config/admin.yml';
46
47
    $config = loadAdminConfig($yamlFile);
48
49
    $displaySampleButton = $config['displaySampleButton'];
50
51
    if (1 == $displaySampleButton) {
52
        xoops_loadLanguage('admin/modulesadmin', 'system');
53
54
        require_once dirname(__DIR__) . '/testdata/index.php';
55
56
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add');
57
58
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add');
59
60
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add');
61
62
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
63
    } else {
64
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
65
66
        $displaySampleButton = $config['displaySampleButton'];
67
    }
68
69
    $adminObject->displayButton('left', '');
70
}
71
72
//------------- End Test Data ----------------------------
73
74
$adminObject->displayIndex();
75
76
/**
77
 * @param $yamlFile
78
 * @return array|bool
79
 */
80
function loadAdminConfig($yamlFile)
81
{
82
    return \Xmf\Yaml::readWrapped($yamlFile);
83
}
84
85
/**
86
 * @param $yamlFile
87
 */
88
function hideButtons($yamlFile)
89
{
90
    $app['displaySampleButton'] = 0;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
91
92
    \Xmf\Yaml::save($app, $yamlFile);
93
94
    redirect_header('index.php', 0, '');
95
}
96
97
/**
98
 * @param $yamlFile
99
 */
100
function showButtons($yamlFile)
101
{
102
    $app['displaySampleButton'] = 1;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
103
104
    \Xmf\Yaml::save($app, $yamlFile);
105
106
    redirect_header('index.php', 0, '');
107
}
108
109
$op = \Xmf\Request::getString('op', 0, 'GET');
110
111
switch ($op) {
112
    case 'hide_buttons':
113
        hideButtons($yamlFile);
114
        break;
115
    case 'show_buttons':
116
        showButtons($yamlFile);
117
        break;
118
}
119
120
echo $utility::getServerStats();
121
122
require __DIR__ . '/admin_footer.php';
123