hideButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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
 * tdmcreate module.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.0
20
 *
21
 * @author          Txmod Xoops http://www.txmodxoops.org
22
 *
23
 */
24
$GLOBALS['xoopsOption']['template_main'] = 'tdmcreate_index.tpl';
25
26
include __DIR__ . '/header.php';
27
$countSettings = $helper->getHandler('Settings')->getCount();
28
$countModules  = $helper->getHandler('Modules')->getCount();
29
$countTables   = $helper->getHandler('Tables')->getCount();
30
$countFields   = $helper->getHandler('Fields')->getCount();
31
$countFiles    = $helper->getHandler('Morefiles')->getCount();
32
unset($criteria);
33
34
//$templateMain = 'tdmcreate_index.tpl';
35
$adminObject->addInfoBox(_AM_TDMCREATE_ADMIN_NUMMODULES);
36
$adminObject->addInfoBoxLine(sprintf('<label>' . _AM_TDMCREATE_THEREARE_NUMSETTINGS . '</label>', $countSettings), 'Blue');
37
$adminObject->addInfoBoxLine(sprintf('<label>' . _AM_TDMCREATE_THEREARE_NUMMODULES . '</label>', $countModules), 'Green');
38
$adminObject->addInfoBoxLine(sprintf('<label>' . _AM_TDMCREATE_THEREARE_NUMTABLES . '</label>', $countTables), 'Orange');
39
$adminObject->addInfoBoxLine(sprintf('<label>' . _AM_TDMCREATE_THEREARE_NUMFIELDS . '</label>', $countFields), 'Gray');
40
$adminObject->addInfoBoxLine(sprintf('<label>' . _AM_TDMCREATE_THEREARE_NUMFILES . '</label>', $countFiles), 'Red');
41
// Upload Folders
42
$folder = [
43
    TDMC_UPLOAD_PATH,
44
    TDMC_UPLOAD_REPOSITORY_PATH,
45
    TDMC_UPLOAD_IMGMOD_PATH,
46
    TDMC_UPLOAD_IMGTAB_PATH,
47
];
48
49
// Uploads Folders Created
50
foreach (array_keys($folder) as $i) {
51
    $adminObject->addConfigBoxLine($folder[$i], 'folder');
52
    $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
53
}
54
55
56
$adminObject->displayNavigation(basename(__FILE__));
57
58
//------------- Test Data ----------------------------
59
60
if ($helper->getConfig('displaySampleButton')) {
61
    $yamlFile            = dirname(__DIR__) . '/config/admin.yml';
62
    $config              = loadAdminConfig($yamlFile);
63
    $displaySampleButton = $config['displaySampleButton'];
64
65
    if (1 == $displaySampleButton) {
66
        xoops_loadLanguage('admin/modulesadmin', 'system');
67
        require __DIR__ . '/../testdata/index.php';
68
69
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add');
70
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add');
71
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add');
72
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
73
    } else {
74
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
75
        $displaySampleButton = $config['displaySampleButton'];
76
    }
77
    $adminObject->displayButton('left', '');
78
}
79
80
//------------- End Test Data ----------------------------
81
82
$adminObject->displayIndex();
83
84
/**
85
 * @param $yamlFile
86
 * @return array|bool
87
 */
88
function loadAdminConfig($yamlFile)
89
{
90
    $config = \Xmf\Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
91
    return $config;
92
}
93
94
/**
95
 * @param $yamlFile
96
 */
97
function hideButtons($yamlFile)
98
{
99
    $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...
100
    \Xmf\Yaml::save($app, $yamlFile);
101
    redirect_header('index.php', 0, '');
102
}
103
104
/**
105
 * @param $yamlFile
106
 */
107
function showButtons($yamlFile)
108
{
109
    $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...
110
    \Xmf\Yaml::save($app, $yamlFile);
111
    redirect_header('index.php', 0, '');
112
}
113
114
$op = \Xmf\Request::getString('op', 0, 'GET');
115
116
switch ($op) {
117
    case 'hide_buttons':
118
        hideButtons($yamlFile);
119
        break;
120
    case 'show_buttons':
121
        showButtons($yamlFile);
122
        break;
123
}
124
125
echo $utility::getServerStats();
126
127
128
129
130
131
//$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('index.php'));
132
//$GLOBALS['xoopsTpl']->assign('index', $adminObject->displayIndex());
133
134
include __DIR__ . '/footer.php';
135