Issues (525)

admin/versions.php (9 issues)

Labels
Severity
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * wgSitenotice module for xoops
13
 *
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         wgsitenotice
17
 * @since           1.0
18
 * @min_xoops       2.5.11
19
 * @author          Goffy (xoops.wedega.com) - Email:<[email protected]> - Website:<https://xoops.wedega.com>
20
 */
21
22
use Xmf\Request;
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
24
include_once __DIR__ . '/header.php';
25
26
// the value of arguments in URL$
27
$op         = Request::getString('op', 'list');
28
$version_id = Request::getInt('version_id');
29
$start      = Request::getInt('start');
30
31
$img_yes = "<img src='../".$modPathIcon16."/on.png' >";
32
$img_no  = "<img src='../".$modPathIcon16."/off.png' >";
33
// Switch options
34
switch ($op)
35
{
36
    case 'list':
37
    default:
38
        $GLOBALS['xoTheme']->addScript(\WGSITENOTICE_URL . '/assets/js/sortable-versions.js');
39
        $GLOBALS['xoopsTpl']->assign('start', $start);
40
        $limit = XoopsRequest::getInt('limit', $helper->getConfig('adminpager'));
0 ignored issues
show
The type XoopsRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
        $template_main = 'wgsitenotice_admin_versions.tpl';
42
        $GLOBALS['xoopsTpl']->assign('navigation', $adminMenu->addNavigation(\basename(__FILE__)));
43
        $adminMenu->addItemButton(\_AM_WGSITENOTICE_VERSION_ADD, 'versions.php?op=new');
44
        $GLOBALS['xoopsTpl']->assign('buttons', $adminMenu->renderButton());
45
        $version_crit = new \CriteriaCompo();
0 ignored issues
show
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
        $version_crit->setSort('version_weight ASC, version_id');
47
        $version_crit->setOrder('ASC');
48
        $versions_rows = $versionsHandler->getCount($version_crit);
49
        $version_crit->setStart($start);
50
        $version_crit->setLimit($limit);
51
        $versions_arr = $versionsHandler->getAll($version_crit);
52
        unset($version_crit);
53
        // Table view
54
        if ($versions_rows > 0)
55
        {
56
            foreach (\array_keys($versions_arr) as $i)
57
            {
58
                // Get Var version_id
59
                $version['id'] = $versions_arr[$i]->getVar('version_id');
60
                // Get Var version_name
61
                $version['name'] = $versions_arr[$i]->getVar('version_name');
62
                // Get Var version_lang
63
                $version['lang'] = $versions_arr[$i]->getVar('version_lang');
64
                // Get Var version_descr
65
                $version['descr'] = $versions_arr[$i]->getVar('version_descr', 'n');
66
                // Get Var version_author
67
                $version['author'] = $versions_arr[$i]->getVar('version_author');
68
                // Get Var version_weight
69
                $version['weight'] = $versions_arr[$i]->getVar('version_weight');
70
                // Get Var version_current
71
                $version['current'] = (1 == $versions_arr[$i]->getVar('version_current')) ? $img_yes : $img_no;
72
                // Get Var version_online
73
                $version['online'] = (1 == $versions_arr[$i]->getVar('version_online')) ? $img_yes : $img_no;
74
                // Get Var version_date
75
                $version['date'] = \formatTimestamp($versions_arr[$i]->getVar('version_date'));
0 ignored issues
show
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
                $version['date'] = /** @scrutinizer ignore-call */ \formatTimestamp($versions_arr[$i]->getVar('version_date'));
Loading history...
76
                $GLOBALS['xoopsTpl']->append('versions_list', $version);
77
                unset($version);
78
            }
79
            if ( $versions_rows > $limit ) {
80
                include_once \XOOPS_ROOT_PATH . '/class/pagenav.php';
0 ignored issues
show
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
81
                $pagenav = new \XoopsPageNav($versions_rows, $limit, $start, 'start', 'op=list&limit=' . $limit);
0 ignored issues
show
The type XoopsPageNav was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
82
                $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
83
            }
84
        } else {
85
            $GLOBALS['xoopsTpl']->assign('error', \_AM_WGSITENOTICE_THEREARENT_VERSIONS);
86
        }
87
        $GLOBALS['xoopsTpl']->assign('wgsitenotice_url', \WGSITENOTICE_URL);
88
        $GLOBALS['xoopsTpl']->assign('wgsitenotice_upload_url', \WGSITENOTICE_UPLOAD_URL);
89
        $GLOBALS['xoopsTpl']->assign('wgsitenotice_icons_url', \WGSITENOTICE_ICONS_URL);
90
    break;
91
    case 'new':
92
        $template_main = 'wgsitenotice_admin_versions.tpl';
93
        $adminMenu->addItemButton(\_AM_WGSITENOTICE_VERSIONS_LIST, 'versions.php', 'list');
94
        $GLOBALS['xoopsTpl']->assign('navigation', $adminMenu->addNavigation(\basename(__FILE__)));
95
        $GLOBALS['xoopsTpl']->assign('buttons', $adminMenu->renderButton());
96
        // Get Form
97
        $versionsObj = $versionsHandler->create();
98
        $form = $versionsObj->getForm();
99
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
100
    break;
101
    case 'save':
102
        if ( !$GLOBALS['xoopsSecurity']->check() ) {
103
           \redirect_header('versions.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
0 ignored issues
show
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
           /** @scrutinizer ignore-call */ 
104
           \redirect_header('versions.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
Loading history...
104
        }
105
        if (isset($version_id)) {
106
           $versionsObj = $versionsHandler->get($version_id);
107
        } else {
108
           $versionsObj = $versionsHandler->create();
109
        }
110
        // Set Vars
111
        // Set Var version_name
112
        $versionsObj->setVar('version_name', Request::getString('version_name'));
113
        // Set Var version_lang
114
        $versionsObj->setVar('version_lang', Request::getString('version_lang'));
115
        // Set Var version_descr
116
        $versionsObj->setVar('version_descr', Request::getString('version_descr'));
117
        // Set Var version_author
118
        $versionsObj->setVar('version_author', Request::getString('version_author'));
119
        // Set Var version_weight
120
        $versionsObj->setVar('version_weight', Request::getInt('version_weight'));
121
        // Set Var version_current
122
        $versionsObj->setVar('version_current', Request::getInt('version_current'));
123
        // Set Var version_online
124
        $versionsObj->setVar('version_online', Request::getInt('version_online'));
125
        // Set Var version_date
126
        $versionsObj->setVar('version_date', \time());
127
        // Insert Data
128
        if ($versionsHandler->insert($versionsObj)) {
129
            \redirect_header('versions.php?op=list', 2, \_AM_WGSITENOTICE_FORMOK);
130
        }
131
        // Get Form
132
        $GLOBALS['xoopsTpl']->assign('error', $versionsObj->getHtmlErrors());
133
        $form = $versionsObj->getForm();
134
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
135
    break;
136
    case 'change_current':
137
        if (isset($version_id)) {
138
            $versionsObj = $versionsHandler->get($version_id);
139
            // get Vars
140
            $version_current = (1 == $versionsObj->getVar('version_current')) ? '0' : '1';
141
            // Set Var version_current
142
            $versionsObj->setVar('version_current', $version_current);
143
            // Insert Data
144
            if ($versionsHandler->insert($versionsObj)) {
145
               \redirect_header('versions.php?op=list&start='.$start, 2, \_AM_WGSITENOTICE_FORMOK);
146
            }
147
        }
148
    break;
149
    case 'change_online':
150
        if (isset($version_id)) {
151
            $versionsObj = $versionsHandler->get($version_id);
152
            // get Vars
153
            $version_online = (1 == $versionsObj->getVar('version_online')) ? '0' : '1';
154
            // Set Var version_online
155
            $versionsObj->setVar('version_online', $version_online);
156
            // Insert Data
157
            if ($versionsHandler->insert($versionsObj)) {
158
               \redirect_header('versions.php?op=list&start='.$start, 2, \_AM_WGSITENOTICE_FORMOK);
159
            }
160
        }
161
    break;
162
    case 'edit':
163
        $template_main = 'wgsitenotice_admin_versions.tpl';
164
        $adminMenu->addItemButton(\_AM_WGSITENOTICE_VERSION_ADD, 'versions.php?op=new');
165
        $adminMenu->addItemButton(\_AM_WGSITENOTICE_VERSIONS_LIST, 'versions.php', 'list');
166
        $GLOBALS['xoopsTpl']->assign('navigation', $adminMenu->addNavigation(\basename(__FILE__)));
167
        $GLOBALS['xoopsTpl']->assign('buttons', $adminMenu->renderButton());
168
        // Get Form
169
        $versionsObj = $versionsHandler->get($version_id);
170
        $form = $versionsObj->getForm();
171
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
172
    break;
173
    case 'delete':
174
        $versionsObj = $versionsHandler->get($version_id);
175
        if (isset($_REQUEST['ok']) && 1 == (int)$_REQUEST['ok']) {
176
            if ( !$GLOBALS['xoopsSecurity']->check() ) {
177
                \redirect_header('versions.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
178
            }
179
180
            //delete items in mod_wdsitenotice_contents
181
            $content_crit = new \CriteriaCompo();
182
            $content_crit->add(new \Criteria('cont_version_id', $version_id));
0 ignored issues
show
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
183
            $contentsHandler->deleteAll($content_crit);
184
185
            //delete item in mod_wdsitenotice_versions
186
            if ($versionsHandler->delete($versionsObj)) {
187
                \redirect_header('versions.php', 3, \_AM_WGSITENOTICE_FORMDELOK);
188
            } else {
189
                echo $versionsObj->getHtmlErrors();
190
            }
191
        } else {
192
            xoops_confirm(['ok' => 1, 'version_id' => $version_id, 'op' => 'delete'], $_SERVER['REQUEST_URI'], \sprintf(\_AM_WGSITENOTICE_FORMSUREDEL, $versionsObj->getVar('version_name')));
0 ignored issues
show
The function xoops_confirm was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

192
            /** @scrutinizer ignore-call */ 
193
            xoops_confirm(['ok' => 1, 'version_id' => $version_id, 'op' => 'delete'], $_SERVER['REQUEST_URI'], \sprintf(\_AM_WGSITENOTICE_FORMSUREDEL, $versionsObj->getVar('version_name')));
Loading history...
193
        }
194
    break;
195
196
    case 'order':
197
        $vorder = Request::getArray('vorder');
198
        for ($i = 0, $iMax = \count($vorder); $i < $iMax; $i++){
199
            $versionsObj = $versionsHandler->get($vorder[$i]);
200
            $versionsObj->setVar('version_weight',$i+1);
201
            $versionsHandler->insert($versionsObj);
202
        }
203
        break;
204
}
205
include_once __DIR__ . '/footer.php';
206