Passed
Push — master ( 2547bd...11d707 )
by Goffy
01:53 queued 01:35
created

modfile.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
use Xmf\Request;
18
19
require_once __DIR__ . '/header.php';
20
21
/** @var \XoopsModules\Tdmdownloads\Helper $helper */
22
$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
23
24
// template d'affichage
25
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_modfile.tpl';
26
require_once XOOPS_ROOT_PATH . '/header.php';
27
$moduleDirName = basename(__DIR__);
28
29
/** @var \xos_opal_Theme $xoTheme */
30
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
31
32
//On recupere la valeur de l'argument op dans l'URL$
33
$op = \Xmf\Request::getString('op', 'list');
34
35
// redirection si pas de droit pour poster
36
if (false === $perm_modif) {
37
    redirect_header('index.php', 2, _NOPERM);
38
}
39
40
$lid = \Xmf\Request::getInt('lid', 0, 'REQUEST');
41
42
//information du téléchargement
43
$viewDownloads = $downloadsHandler->get($lid);
44
45
// redirection si le téléchargement n'existe pas ou n'est pas activé
46
if (!is_object($viewDownloads) || 0 == $viewDownloads->getVar('status')) {
47
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT);
48
}
49
50
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
51
switch ($op) {
52
    // Vue liste
53
    case 'list':
54
        //navigation
55
        $view_category = $categoryHandler->get($viewDownloads->getVar('cid'));
56
        $categories    = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
57
        if (!in_array($viewDownloads->getVar('cid'), $categories, true)) {
58
            redirect_header('index.php', 2, _NOPERM);
59
        }
60
        //tableau des catégories
61
        $criteria = new \CriteriaCompo();
62
        $criteria->setSort('cat_weight ASC, cat_title');
63
        $criteria->setOrder('ASC');
64
        $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
65
        $downloadscatArray = $categoryHandler->getAll($criteria);
66
        $mytree            = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
67
        //navigation
68
        $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC', true);
69
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> <a title="' . $viewDownloads->getVar('title') . '" href="singlefile.php?lid=' . $viewDownloads->getVar('lid') . '">' . $viewDownloads->getVar('title') . '</a>';
70
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ' . _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY;
71
        $xoopsTpl->assign('navigation', $navigation);
72
        // référencement
73
        // titre de la page
74
        $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' - ' . $viewDownloads->getVar('title') . ' - ';
75
        $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true);
76
        $xoopsTpl->assign('xoops_pagetitle', $pagetitle);
77
        //description
78
        $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' (' . $viewDownloads->getVar('title') . ')'));
79
80
        //Affichage du formulaire de notation des téléchargements
81
        $obj  = $modifiedHandler->create();
82
        $form = $obj->getForm($lid, false, $donnee = []);
83
        $xoopsTpl->assign('themeForm', $form->render());
84
        break;
85
    // save
86
    case 'save':
87
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
88
        $obj            = $modifiedHandler->create();
89
        $erreur         = false;
90
        $errorMessage = '';
91
        $donnee         = [];
92
        $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); //$_POST['title']);
93
        $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); //$_POST['title'];
94
        $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); //$_POST['cid']);
95
        $donnee['cid'] = \Xmf\Request::getInt('cid', 0, 'POST'); //$_POST['cid'];
96
        $obj->setVar('lid', \Xmf\Request::getInt('lid', 0, 'POST')); //$_POST['lid']);
97
        $obj->setVar('homepage', \Xmf\Request::getString('homepage', '', 'POST')); //formatURL($_POST["homepage"]));
98
        $donnee['homepage'] = \Xmf\Request::getString('homepage', '', 'POST'); //formatURL($_POST["homepage"]);
99
        $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); //$_POST["version"]);
100
        $donnee['version'] = \Xmf\Request::getString('version', '', 'POST'); //$_POST["version"];
101
        $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST')); //$_POST["size"]);
102
        $donnee['size']      = \Xmf\Request::getString('size', '', 'POST'); //$_POST["size"];
103
        $donnee['type_size'] = \Xmf\Request::getString('type_size', '', 'POST'); //$_POST['type_size'];
104
        if (\Xmf\Request::hasVar('platform', 'POST')) {
105
            $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); //$_POST['platform']));
0 ignored issues
show
Xmf\Request::getString('platform', '', 'POST') of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

105
            $obj->setVar('platform', implode('|', /** @scrutinizer ignore-type */ \Xmf\Request::getString('platform', '', 'POST'))); //$_POST['platform']));
Loading history...
106
            $donnee['platform'] = implode('|', \Xmf\Request::getString('platform', '', 'POST')); //$_POST["platform"]);
107
        } else {
108
            $donnee['platform'] = '';
109
        }
110
        $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); //$_POST["description"]);
111
        $donnee['description'] = \Xmf\Request::getString('description', '', 'POST'); //$_POST["description"];
112
        $obj->setVar('modifysubmitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0);
113
		// if (true === $perm_autoapprove) {
114
            // $obj->setVar('status', 1);
115
        // } else {
116
            // $obj->setVar('status', 0);
117
        // }
118
119
        // erreur si la taille du fichier n'est pas un nombre
120
        if (\Xmf\Request::hasVar('size') && 0 == \Xmf\Request::getInt('size')) {
121
            if ('0' == \Xmf\Request::getString('size', '', 'POST')
122
                || '' === \Xmf\Request::getString('size', '', 'POST')) {
123
                $erreur = false;
124
            } else {
125
                $erreur         = true;
126
                $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>';
127
            }
128
        }
129
        // erreur si la catégorie est vide
130
        if (\Xmf\Request::hasVar('cid')) {
131
            if (0 == \Xmf\Request::getInt('cid', 0, 'POST')) {
132
                $erreur         = true;
133
                $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>';
134
            }
135
        }
136
		// get captcha (members are skipped in class/download.php getForm
137
        if (!$xoopsUser) {
138
            // erreur si le captcha est faux
139
            xoops_load('xoopscaptcha');
140
            $xoopsCaptcha = \XoopsCaptcha::getInstance();
141
            if (!$xoopsCaptcha->verify()) {
142
                $errorMessage .= $xoopsCaptcha->getMessage() . '<br>';
143
                $erreur         = true;
144
            }
145
        }
146
        // pour enregistrer temporairement les valeur des champs sup
147
        $criteria = new \CriteriaCompo();
148
        $criteria->setSort('weight ASC, title');
149
        $criteria->setOrder('ASC');
150
        $downloads_field = $fieldHandler->getAll($criteria);
151
        foreach (array_keys($downloads_field) as $i) {
152
            if (0 == $downloads_field[$i]->getVar('status_def')) {
153
                $fieldName          = 'champ' . $downloads_field[$i]->getVar('fid');
154
                $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST');
155
            }
156
        }
157
        if (true === $erreur) {
158
            $xoopsTpl->assign('message_erreur', $errorMessage);
159
        } else {
160
            $obj->setVar('size', \Xmf\Request::getInt('size', 0, 'POST') . ' ' . \Xmf\Request::getString('type_size', '', 'POST'));
161
            // Pour le fichier
162
            if (isset($_POST['xoops_upload_file'][0])) {
163
                $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null);
164
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
165
                    if ($helper->getConfig('newnamedownload')) {
166
                        $uploader->setPrefix($helper->getConfig('prefixdownloads'));
167
                    }
168
                    $uploader->fetchMedia($_POST['xoops_upload_file'][0]);
169
                    if (!$uploader->upload()) {
170
                        $errors = $uploader->getErrors();
171
                        redirect_header('javascript:history.go(-1)', 3, $errors);
172
                    } else {
173
                        $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName());
174
                    }
175
                } else {
176
					if ( '' < $_FILES['attachedfile']['name'] ) { 
177
                        // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize
178
                        $errorMessage .= $uploader->getErrors() . '<br>';
179
                        $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage);
180
                        $form = $obj->getForm($donnee, true);
181
                        $GLOBALS['xoopsTpl']->assign('themeForm', $form->render());
182
                        break;
183
                    }
184
                    $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST'));
185
                }
186
            }
187
            // Pour l'image
188
            if (isset($_POST['xoops_upload_file'][1])) {
189
                $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [
190
                    'image/gif',
191
                    'image/jpeg',
192
                    'image/pjpeg',
193
                    'image/x-png',
194
                    'image/png',
195
                ], $helper->getConfig('maxuploadsize'), null, null);
196
                if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) {
197
                    $uploader_2->setPrefix('downloads_');
198
                    $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]);
199
                    if (!$uploader_2->upload()) {
200
                        $errors = $uploader_2->getErrors();
201
                        redirect_header('javascript:history.go(-1)', 3, $errors);
202
                    } else {
203
                        $obj->setVar('logourl', $uploader_2->getSavedFileName());
204
                    }
205
                } else {
206
                    if ( '' < $_FILES['attachedimage']['name'] ) { 
207
                        // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize
208
                        $errorMessage .= $uploader_2->getErrors() . '<br>';
209
                        $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage);
210
                        $form = $obj->getForm($donnee, true);
211
                        $GLOBALS['xoopsTpl']->assign('themeForm', $form->render());
212
                        break;
213
                    }
214
					$obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST'));
215
                }
216
            }
217
218
            if ($modifiedHandler->insert($obj)) {
219
                $lidDownloads = $obj->getNewEnreg($db);
220
                // Récupération des champs supplémentaires:
221
                $criteria = new \CriteriaCompo();
222
                $criteria->setSort('weight ASC, title');
223
                $criteria->setOrder('ASC');
224
                $downloads_field = $fieldHandler->getAll($criteria);
225
                foreach (array_keys($downloads_field) as $i) {
226
                    if (0 == $downloads_field[$i]->getVar('status_def')) {
227
                        //$objdata = $modifiedfielddataHandler->create();
228
                        $objdata   = $modifieddataHandler->create();
229
                        $fieldName = 'champ' . $downloads_field[$i]->getVar('fid');
230
                        $objdata->setVar('moddata', \Xmf\Request::getString($fieldName, '', 'POST'));
231
                        $objdata->setVar('lid', $lidDownloads);
232
                        $objdata->setVar('fid', $downloads_field[$i]->getVar('fid'));
233
                        //$modifiedfielddataHandler->insert($objdata) || $objdata->getHtmlErrors();
234
                        $modifieddataHandler->insert($objdata) || $objdata->getHtmlErrors();
235
                    }
236
                }
237
                $tags                      = [];
238
                $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/modified.php';
239
                /** @var \XoopsNotificationHandler $notificationHandler */
240
                $notificationHandler = xoops_getHandler('notification');
241
                $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags);
0 ignored issues
show
'global' of type string is incompatible with the type integer expected by parameter $category of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

241
                $notificationHandler->triggerEvent(/** @scrutinizer ignore-type */ 'global', 0, 'file_modify', $tags);
Loading history...
'file_modify' of type string is incompatible with the type integer expected by parameter $event of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

241
                $notificationHandler->triggerEvent('global', 0, /** @scrutinizer ignore-type */ 'file_modify', $tags);
Loading history...
242
                redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST'), 1, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO);
243
            }
244
            echo $obj->getHtmlErrors();
245
        }
246
        //Affichage du formulaire de notation des téléchargements
247
        $form = $obj->getForm(\Xmf\Request::getInt('lid', 0, 'REQUEST'), true, $donnee);
248
        $xoopsTpl->assign('themeForm', $form->render());
249
250
        break;
251
}
252
require XOOPS_ROOT_PATH . '/footer.php';
253