Passed
Push — master ( 2e770c...1b7b2e )
by Goffy
03:52
created

admin/releases.php (7 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
/**
13
 * wgGitHub module for xoops
14
 *
15
 * @copyright      2020 XOOPS Project (https://xooops.org)
16
 * @license        GPL 2.0 or later
17
 * @package        wggithub
18
 * @since          1.0
19
 * @min_xoops      2.5.10
20
 * @author         Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
21
 */
22
23
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...
24
use XoopsModules\Wggithub;
25
use XoopsModules\Wggithub\Constants;
26
use XoopsModules\Wggithub\Common;
27
28
require __DIR__ . '/header.php';
29
// It recovered the value of argument op in URL$
30
$op    = Request::getCmd('op', 'list');
31
$relId = Request::getInt('rel_id');
32
$start = Request::getInt('start', 0);
33
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
34
$GLOBALS['xoopsTpl']->assign('start', $start);
35
$GLOBALS['xoopsTpl']->assign('limit', $limit);
36
37
switch ($op) {
38
    case 'list':
39
    default:
40
        // Define Stylesheet
41
        $GLOBALS['xoTheme']->addStylesheet($style, null);
42
        $templateMain = 'wggithub_admin_releases.tpl';
43
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('releases.php'));
44
        $adminObject->addItemButton(\_AM_WGGITHUB_ADD_RELEASE, 'releases.php?op=new', 'add');
45
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
46
47
        $filterValue = '';
48
        $crReleases = 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...
49
        if ('filter' == $op) {
50
            $operand = Request::getInt('filter_operand', 0);
51
            $filterField = Request::getString('filter_field', '');
52
            $filterValue = Request::getString('filter_value', 'none');
53
            if (Constants::FILTER_OPERAND_EQUAL == $operand) {
54
                $crReleases->add(new Criteria($filterField, $filterValue));
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...
55
            } elseif (Constants::FILTER_OPERAND_LIKE == $operand) {
56
                $crReleases->add(new Criteria($filterField, "%$filterValue%", 'LIKE'));
57
            }
58
        }
59
        $crReleases->setStart($start);
60
        $crReleases->setLimit($limit);
61
        $releasesCount = $releasesHandler->getCount($crReleases);
62
        $releasesAll = $releasesHandler->getAll($crReleases);
63
        $GLOBALS['xoopsTpl']->assign('releases_count', $releasesCount);
64
        $GLOBALS['xoopsTpl']->assign('wggithub_url', WGGITHUB_URL);
65
        $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', WGGITHUB_UPLOAD_URL);
66
        // Table view releases
67
        if ($releasesCount > 0) {
68
            foreach (\array_keys($releasesAll) as $i) {
69
                $release = $releasesAll[$i]->getValuesReleases();
70
                $GLOBALS['xoopsTpl']->append('releases_list', $release);
71
                unset($release);
72
            }
73
            // Display Navigation
74
            if ($releasesCount > $limit) {
75
                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...
76
                $pagenav = new \XoopsPageNav($releasesCount, $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...
77
                $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
78
            }
79
        } else {
80
            if ('filter' == $op) {
81
                $GLOBALS['xoopsTpl']->assign('noData', \_AM_WGGITHUB_THEREARENT_RELEASES_FILTER);
82
            } else {
83
                $GLOBALS['xoopsTpl']->assign('noData', \_AM_WGGITHUB_THEREARENT_RELEASES);
84
            }
85
        }
86
        $form = $releasesHandler->getFormFilterReleases(false, $start, $limit, $filterValue);
87
        $GLOBALS['xoopsTpl']->assign('formFilter', $form->render());
88
        break;
89
    case 'new':
90
        $templateMain = 'wggithub_admin_releases.tpl';
91
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('releases.php'));
92
        $adminObject->addItemButton(\_AM_WGGITHUB_RELEASES_LIST, 'releases.php', 'list');
93
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
94
        // Form Create
95
        $releasesObj = $releasesHandler->create();
96
        $form = $releasesObj->getFormReleases(false, $start, $limit);
97
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
98
        break;
99
    case 'save':
100
        // Security Check
101
        if (!$GLOBALS['xoopsSecurity']->check()) {
102
            \redirect_header('releases.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

102
            /** @scrutinizer ignore-call */ \redirect_header('releases.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
Loading history...
103
        }
104
        if ($relId > 0) {
105
            $releasesObj = $releasesHandler->get($relId);
106
        } else {
107
            $releasesObj = $releasesHandler->create();
108
        }
109
        // Set Vars
110
        $releasesObj->setVar('rel_repoid', Request::getInt('rel_repoid', 0));
111
        $releasesObj->setVar('rel_type', Request::getInt('rel_type', 0));
112
        $releasesObj->setVar('rel_name', Request::getString('rel_name', ''));
113
        $releasePublishedatObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('rel_publishedat'));
0 ignored issues
show
The constant _SHORTDATESTRING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
114
        $releasesObj->setVar('rel_publishedat', $releasePublishedatObj->getTimestamp());
115
        $releasesObj->setVar('rel_tarballurl', Request::getString('rel_tarballurl', ''));
116
        $releasesObj->setVar('rel_zipballurl', Request::getString('rel_zipballurl', ''));
117
        $releaseDatecreatedObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('rel_datecreated'));
118
        $releasesObj->setVar('rel_datecreated', $releaseDatecreatedObj->getTimestamp());
119
        $releasesObj->setVar('rel_submitter', Request::getInt('rel_submitter', 0));
120
        // Insert Data
121
        if ($releasesHandler->insert($releasesObj)) {
122
            \redirect_header('releases.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_AM_WGGITHUB_FORM_OK);
123
        }
124
        // Get Form
125
        $GLOBALS['xoopsTpl']->assign('error', $releasesObj->getHtmlErrors());
126
        $form = $releasesObj->getFormReleases(false, $start, $limit);
127
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
128
        break;
129
    case 'edit':
130
        $templateMain = 'wggithub_admin_releases.tpl';
131
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('releases.php'));
132
        $adminObject->addItemButton(\_AM_WGGITHUB_ADD_RELEASE, 'releases.php?op=new', 'add');
133
        $adminObject->addItemButton(\_AM_WGGITHUB_RELEASES_LIST, 'releases.php', 'list');
134
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
135
        // Get Form
136
        $releasesObj = $releasesHandler->get($relId);
137
        $form = $releasesObj->getFormReleases(false, $start, $limit);
138
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
139
        break;
140
    case 'delete':
141
        $templateMain = 'wggithub_admin_releases.tpl';
142
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('releases.php'));
143
        $releasesObj = $releasesHandler->get($relId);
144
        $relName = $releasesObj->getVar('rel_name');
145
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
146
            if (!$GLOBALS['xoopsSecurity']->check()) {
147
                \redirect_header('releases.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
148
            }
149
            if ($releasesHandler->delete($releasesObj)) {
150
                \redirect_header('releases.php', 3, \_AM_WGGITHUB_FORM_DELETE_OK);
151
            } else {
152
                $GLOBALS['xoopsTpl']->assign('error', $releasesObj->getHtmlErrors());
153
            }
154
        } else {
155
            $xoopsconfirm = new Common\XoopsConfirm(
156
                ['ok' => 1, 'rel_id' => $relId, 'op' => 'delete'],
157
                $_SERVER['REQUEST_URI'],
158
                \sprintf(\_AM_WGGITHUB_FORM_SURE_DELETE, $releasesObj->getVar('rel_name')));
159
            $form = $xoopsconfirm->getFormXoopsConfirm();
160
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
161
        }
162
        break;
163
}
164
require __DIR__ . '/footer.php';
165