Passed
Push — master ( 638320...9a22a9 )
by Michael
03:46
created

admin/location.php (3 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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal;
21
22
// Include xoops admin header
23
require_once __DIR__ . '/admin_header.php';
24
// require_once  dirname(__DIR__) . '/class/ExtcalPersistableObjectHandler.php';
25
require_once dirname(dirname(dirname(__DIR__))) . '/kernel/module.php';
26
require_once dirname(dirname(dirname(__DIR__))) . '/class/xoopsformloader.php';
27
require_once dirname(dirname(dirname(__DIR__))) . '/class/tree.php';
28
require_once dirname(dirname(dirname(__DIR__))) . '/class/xoopslists.php';
29
require_once dirname(dirname(dirname(__DIR__))) . '/class/pagenav.php';
30
require_once dirname(dirname(dirname(__DIR__))) . '/class/xoopsform/grouppermform.php';
31
require_once dirname(dirname(dirname(__DIR__))) . '/class/uploader.php';
32
require_once dirname(__DIR__) . '/include/constantes.php';
33
34
require_once __DIR__ . '/admin_header.php';
35
36
//require("functions.php");
37
//require("../include/functions.php");
38
39
if ($xoopsUser) {
40
    $xoopsModule = \XoopsModule::getByDirname('extcal');
41
    if (!$xoopsUser->isAdmin($xoopsModule->mid())) {
42
        redirect_header(XOOPS_URL . '/', 3, _NOPERM);
43
    }
44
} else {
45
    redirect_header(XOOPS_URL . '/', 3, _NOPERM);
46
}
47
48
// Include language file
49
xoops_loadLanguage('admin', 'system');
50
Extcal\Helper::getInstance()->loadLanguage('admin');
51
Extcal\Helper::getInstance()->loadLanguage('modinfo');
52
$myts = \MyTextSanitizer::getInstance();
53
54
//appel des class
55
$locationHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_LOCATION);
56
57
xoops_cp_header();
58
59
$op = 'liste';
60
if (\Xmf\Request::hasVar('op', 'REQUEST')) {
61
    $op = $_REQUEST['op'];
62
}
63
64
//appel du menu admin
65
// if ( !is_readable(XOOPS_ROOT_PATH . "/Frameworks/art/functions.admin.php")) {
66
// adminmenu(4, _MI_EXTCAL_LOCATION);
67
// } else {
68
// require_once XOOPS_ROOT_PATH.'/Frameworks/art/functions.admin.php';
69
// loadModuleAdminMenu (4, _MI_EXTCAL_LOCATION);
70
// }
71
72
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
73
switch ($op) {
74
    // Vue liste
75
    case 'liste':
76
        // @author   JJDAI
77
        //***************************************************************************************
78
        $adminObject = \Xmf\Module\Admin::getInstance();
79
        $adminObject->displayNavigation(basename(__FILE__));
80
        //***************************************************************************************
81
82
        $criteria = new \CriteriaCompo();
83
        if (\Xmf\Request::hasVar('limit', 'REQUEST')) {
84
            $criteria->setLimit($_REQUEST['limit']);
85
            $limit = $_REQUEST['limit'];
86
        } else {
87
            $criteria->setLimit(10);
88
            $limit = 10;
89
        }
90
        if (\Xmf\Request::hasVar('start', 'REQUEST')) {
91
            $criteria->setStart($_REQUEST['start']);
92
            $start = $_REQUEST['start'];
93
        } else {
94
            $criteria->setStart(0);
95
            $start = 0;
96
        }
97
        $criteria->setSort('nom');
98
        $criteria->setOrder('ASC');
99
        $location_arr = $locationHandler->getObjects($criteria);
0 ignored issues
show
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

99
        /** @scrutinizer ignore-call */ 
100
        $location_arr = $locationHandler->getObjects($criteria);
Loading history...
100
        $numrows      = $locationHandler->getCount($criteria);
0 ignored issues
show
The method getCount() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsGroupHandler or XoopsConfigCategoryHandler or XoopsRankHandler or XoopsConfigOptionHandler or XoopsBlockHandler or XoopsImagesetHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

100
        /** @scrutinizer ignore-call */ 
101
        $numrows      = $locationHandler->getCount($criteria);
Loading history...
101
        if ($numrows > $limit) {
102
            $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'op=liste&limit=' . $limit);
103
            $pagenav = $pagenav->renderNav(4);
104
        } else {
105
            $pagenav = '';
106
        }
107
        //Affichage du tableau des téléchargements brisés
108
        if ($numrows > 0) {
109
            echo '<table width="100%" cellspacing="1" class="outer">';
110
            echo '<tr>';
111
            echo '<th align="center">' . _AM_EXTCAL_LOCATION_FORM_NOM . '</th>';
112
            echo '<th align="center" width="20%">' . _AM_EXTCAL_LOCATION_FORM_ADRESSE . '</th>';
113
            echo '<th align="center" width="20%">' . _AM_EXTCAL_LOCATION_FORM_CITY . '</th>';
114
            echo '<th align="center" width="15%">' . _AM_EXTCAL_LOCATION_FORM_TELEPHONE . '</th>';
115
            echo '<th align="center" width="15%">' . _AM_EXTCAL_LOCATION_FORM_ACTION . '</th>';
116
            echo '</tr>';
117
            $class = 'odd';
118
            foreach (array_keys($location_arr) as $i) {
119
                $class              = ('even' === $class) ? 'odd' : 'even';
120
                $location_id        = $location_arr[$i]->getVar('id');
121
                $location_nom       = $location_arr[$i]->getVar('nom');
122
                $location_adresse   = $location_arr[$i]->getVar('adresse');
123
                $location_city      = $location_arr[$i]->getVar('ville');
124
                $location_telephone = $location_arr[$i]->getVar('tel_fixe');
125
                echo '<tr class="' . $class . '">';
126
                echo '<td align="left">' . '<a href="location.php?op=edit_location&location_id=' . $location_id . '">' . $location_nom . '</a>' . '</td>';
127
128
                echo '<td align="center"><b>' . $location_adresse . '</td>';
129
                echo '<td align="center"><b>' . $location_city . '</td>';
130
                echo '<td align="center"><b>' . $location_telephone . '</td>';
131
                echo '<td align="center" width="15%">';
132
                echo '<a href="location.php?op=edit_location&location_id=' . $location_id . '"><img src=' . $pathIcon16 . '/edit.png alt="' . _AM_EXTCAL_LOCATION_FORM_EDIT . '" title="' . _AM_EXTCAL_LOCATION_FORM_EDIT . '"></a> ';
133
                echo '<a href="location.php?op=delete_location&location_id=' . $location_id . '"><img src=' . $pathIcon16 . '/delete.png alt="' . _AM_EXTCAL_LOCATION_FORM_DELETE . '" title="' . _AM_EXTCAL_LOCATION_FORM_DELETE . '"></a> ';
134
                echo '</td>';
135
            }
136
            echo '</table><br>';
137
            echo '<br><div align=right>' . $pagenav . '</div><br>';
138
        } else {
139
            echo '<div class="errorMsg" style="text-align: center;">' . _AM_EXTCAL_ERREUR_NO_LOCATION . '</div>';
140
        }
141
142
        // Affichage du formulaire
143
        $obj  = $locationHandler->create();
144
        $form = $obj->getForm(false);
0 ignored issues
show
The method getForm() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as SystemSmilies or SystemBanner or SystemBannerclient or ProfileCategory or SystemUserrank or XoopsModules\Extcal\Location or SystemGroup or SystemBlock or SystemAvatar or SystemUsers. ( Ignorable by Annotation )

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

144
        /** @scrutinizer ignore-call */ 
145
        $form = $obj->getForm(false);
Loading history...
145
        break;
146
    // permet de suprimmer le rapport de téléchargment brisé
147
    case 'delete_location':
148
        $obj = $locationHandler->get($_REQUEST['location_id']);
149
        if (\Xmf\Request::hasVar('ok', 'REQUEST') && 1 == $_REQUEST['ok']) {
150
            if (!$GLOBALS['xoopsSecurity']->check()) {
151
                redirect_header('location.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
152
            }
153
            if ($locationHandler->delete($obj)) {
154
                redirect_header('location.php', 1, _AM_EXTCAL_REDIRECT_DELOK);
155
            }
156
        } else {
157
            xoops_confirm([
158
                    'ok'          => 1,
159
                    'location_id' => $_REQUEST['location_id'],
160
                    'op'          => 'delete_location',
161
                          ], $_SERVER['REQUEST_URI'], _AM_EXTCAL_LOCATION_SURDEL . '<br>');
162
        }
163
        break;
164
    case 'edit_location':
165
        // @author   JJDAI
166
        //***************************************************************************************
167
        $adminObject = \Xmf\Module\Admin::getInstance();
168
        $adminObject->displayNavigation(basename(__FILE__));
169
        //***************************************************************************************
170
        //Affichage du formulaire de création des téléchargements
171
        $obj  = $locationHandler->get($_REQUEST['location_id']);
172
        $form = $obj->getForm(false);
173
        break;
174
    case 'save_location':
175
        if (!$GLOBALS['xoopsSecurity']->check()) {
176
            redirect_header('location.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
177
        }
178
        if (\Xmf\Request::hasVar('location_id', 'REQUEST')) {
179
            $obj = $locationHandler->get($_REQUEST['location_id']);
180
        } else {
181
            $obj = $locationHandler->create();
182
        }
183
184
        $obj->setVar('nom', $_REQUEST['nom']);
185
        $obj->setVar('description', $_REQUEST['description']);
186
        $obj->setVar('categorie', $_REQUEST['categorie']);
187
        $obj->setVar('adresse', $_REQUEST['adresse']);
188
        $obj->setVar('adresse2', $_REQUEST['adresse2']);
189
        $obj->setVar('cp', $_REQUEST['cp']);
190
        $obj->setVar('ville', $_REQUEST['ville']);
191
        $obj->setVar('tel_fixe', $_REQUEST['tel_fixe']);
192
        $obj->setVar('tel_portable', $_REQUEST['tel_portable']);
193
        $obj->setVar('mail', $_REQUEST['mail']);
194
        $obj->setVar('site', $_REQUEST['site']);
195
        $obj->setVar('horaires', $_REQUEST['horaires']);
196
        $obj->setVar('divers', $_REQUEST['divers']);
197
        $obj->setVar('tarifs', $_REQUEST['tarifs']);
198
        $obj->setVar('map', $_REQUEST['map']);
199
200
        //Logo
201
        $uploaddir_location = XOOPS_ROOT_PATH . '/uploads/extcal/location/';
202
        $uploadurl_location = XOOPS_URL . '/uploads/extcal/location/';
203
204
        $delimg = @$_REQUEST['delimg'];
205
        $delimg = isset($delimg) ? (int)$delimg : 0;
206
        if (0 == $delimg && !empty($_REQUEST['xoops_upload_file'][0])) {
207
            $upload = new \XoopsMediaUploader($uploaddir_location, [
208
                'image/gif',
209
                'image/jpeg',
210
                'image/pjpeg',
211
                'image/x-png',
212
                'image/png',
213
            ], 3145728, null, null);
214
            if ($upload->fetchMedia($_REQUEST['xoops_upload_file'][0])) {
215
                $upload->setPrefix('location_');
216
                $upload->fetchMedia($_REQUEST['xoops_upload_file'][0]);
217
                if (!$upload->upload()) {
218
                    $errors = $upload->getErrors();
219
                    redirect_header('<script>javascript:history.go(-1)</script>', 3, $errors);
220
                } else {
221
                    $logo = $upload->getSavedFileName();
222
                }
223
            } elseif (!empty($_REQUEST['file'])) {
224
                $logo = \Xmf\Request::getString('file', '');
225
            }
226
        } else {
227
            $logo         = '';
228
            $url_location = XOOPS_ROOT_PATH . '/uploads/extcal/location/' . \Xmf\Request::getString('file', '');
229
            if (is_file($url_location)) {
230
                chmod($url_location, 0777);
231
                unlink($url_location);
232
            }
233
        }
234
        $obj->setVar('logo', $logo);
235
236
        if ($locationHandler->insert($obj)) {
237
        }
238
239
        //require_once  dirname(__DIR__) . "/include/forms.php";
240
        echo $obj->getHtmlErrors();
241
        $form = $obj->getForm(false, 0);
242
        //echo "<hr>exit <<<<<<<<<<<<<<<<<<<<";exit;
243
        redirect_header('location.php', 2, _AM_EXTCAL_FORMOK);
244
245
        break;
246
}
247
248
require_once __DIR__ . '/admin_footer.php';
249