Passed
Pull Request — master (#81)
by Michael
02:51
created

brokenfile.php (2 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
require_once __DIR__ . '/header.php';
17
// template d'affichage
18
$moduleDirName = basename(__DIR__);
19
20
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_brokenfile.tpl';
21
require_once XOOPS_ROOT_PATH . '/header.php';
22
/** @var \xos_opal_Theme $xoTheme */
23
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
24
//On recupere la valeur de l'argument op dans l'URL$
25
$op  = \Xmf\Request::getString('op', 'list');
26
$lid = \Xmf\Request::getInt('lid', 0, 'REQUEST');
27
28
//redirection si pas de permission de vote
29
if (false === $perm_vote) {
30
    redirect_header('index.php', 2, _NOPERM);
31
}
32
33
$viewDownloads = $downloadsHandler->get($lid);
34
// redirection si le téléchargement n'existe pas ou n'est pas activ�
35
if (empty($viewDownloads) || 0 == $viewDownloads->getVar('status')) {
36
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT);
37
}
38
39
//redirection si pas de permission (cat)
40
$categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
41
if (!in_array($viewDownloads->getVar('cid'), $categories, true)) {
42
    redirect_header(XOOPS_URL, 2, _NOPERM);
43
}
44
45
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
46
switch ($op) {
47
    // Vue list
48
    case 'list':
49
        //tableau des catégories
50
        $criteria = new \CriteriaCompo();
51
        $criteria->setSort('cat_weight ASC, cat_title');
52
        $criteria->setOrder('ASC');
53
        $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
54
        $downloadscatArray = $categoryHandler->getAll($criteria);
55
        $mytree            = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
56
        //navigation
57
        $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC', true);
58
        $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>';
59
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ' . _MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN;
60
        $xoopsTpl->assign('navigation', $navigation);
61
        // référencement
62
        // titre de la page
63
        $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN . ' - ' . $viewDownloads->getVar('title') . ' - ';
64
        $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true);
65
        $xoopsTpl->assign('xoops_pagetitle', $pagetitle);
66
        //description
67
        $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_REPORTBROKEN . ' (' . $viewDownloads->getVar('title') . ')'));
68
        //Affichage du formulaire de fichier brisé*/
69
        /** @var \XoopsModules\Tdmdownloads\Broken $obj */
70
        $obj = $brokenHandler->create();
71
        /** @var \XoopsThemeForm $form */
72
        $form = $obj->getForm($lid);
73
        $xoopsTpl->assign('themeForm', $form->render());
74
        break;
75
    // save
76
    case 'save':
77
        /** @var \XoopsModules\Tdmdownloads\Broken $obj */
78
        $obj = $brokenHandler->create();
79
        if (empty($xoopsUser)) {
80
            $ratinguser = 0;
81
        } else {
82
            $ratinguser = $xoopsUser->getVar('uid');
83
        }
84
        if (0 !== $ratinguser) {
85
            // si c'est un membre on vérifie qu'il n'envoie pas 2 fois un rapport
86
            $criteria = new \CriteriaCompo();
87
            $criteria->add(new \Criteria('lid', $lid));
88
            $brokenArray = $brokenHandler->getAll($criteria);
89
            foreach (array_keys($brokenArray) as $i) {
90
                /** @var \XoopsModules\Tdmdownloads\Broken[] $brokenArray */
91
                if ($brokenArray[$i]->getVar('sender') == $ratinguser) {
92
                    redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED);
93
                }
94
            }
95
        } else {
96
            // si c'est un utilisateur anonyme on vérifie qu'il n'envoie pas 2 fois un rapport
97
            $criteria = new \CriteriaCompo();
98
            $criteria->add(new \Criteria('lid', $lid));
99
            $criteria->add(new \Criteria('sender', 0));
100
            $criteria->add(new \Criteria('ip', getenv('REMOTE_ADDR')));
101
            if ($brokenHandler->getCount($criteria) >= 1) {
102
                redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED);
103
            }
104
        }
105
        $erreur         = false;
106
        $errorMessage = '';
107
        // Test avant la validation
108
        xoops_load('captcha');
109
        $xoopsCaptcha = \XoopsCaptcha::getInstance();
110
        if (!$xoopsCaptcha->verify()) {
111
            $errorMessage .= $xoopsCaptcha->getMessage() . '<br>';
112
            $erreur         = true;
113
        }
114
        $obj->setVar('lid', $lid);
115
        $obj->setVar('sender', $ratinguser);
116
        $obj->setVar('ip', getenv('REMOTE_ADDR'));
117
        if (true === $erreur) {
118
            $xoopsTpl->assign('message_erreur', $errorMessage);
119
        } else {
120
            if ($brokenHandler->insert($obj)) {
121
                $tags                      = [];
122
                $tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/broken.php';
123
                /** @var \XoopsNotificationHandler $notificationHandler */
124
                $notificationHandler = xoops_getHandler('notification');
125
                $notificationHandler->triggerEvent('global', 0, 'file_broken', $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

125
                $notificationHandler->triggerEvent(/** @scrutinizer ignore-type */ 'global', 0, 'file_broken', $tags);
Loading history...
'file_broken' 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

125
                $notificationHandler->triggerEvent('global', 0, /** @scrutinizer ignore-type */ 'file_broken', $tags);
Loading history...
126
                redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_THANKSFORINFO);
127
            }
128
            echo $obj->getHtmlErrors();
129
        }
130
        //Affichage du formulaire de notation des téléchargements
131
132
        $form = $obj->getForm($lid);
133
        $xoopsTpl->assign('themeForm', $form->render());
134
135
        break;
136
}
137
require XOOPS_ROOT_PATH . '/footer.php';
138