Passed
Push — master ( 22941e...65c0e8 )
by Goffy
38s queued 11s
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 (0 == count($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
        $obj  = $brokenHandler->create();
70
        $form = $obj->getForm($lid);
71
        $xoopsTpl->assign('themeForm', $form->render());
72
        break;
73
    // save
74
    case 'save':
75
        $obj = $brokenHandler->create();
76
        if (empty($xoopsUser)) {
77
            $ratinguser = 0;
78
        } else {
79
            $ratinguser = $xoopsUser->getVar('uid');
80
        }
81
        if (0 !== $ratinguser) {
82
            // si c'est un membre on vérifie qu'il n'envoie pas 2 fois un rapport
83
            $criteria = new \CriteriaCompo();
84
            $criteria->add(new \Criteria('lid', $lid));
85
            $brokenArray = $brokenHandler->getAll($criteria);
86
            foreach (array_keys($brokenArray) as $i) {
87
                if ($brokenArray[$i]->getVar('sender') == $ratinguser) {
88
                    redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED);
89
                }
90
            }
91
        } else {
92
            // si c'est un utilisateur anonyme on vérifie qu'il n'envoie pas 2 fois un rapport
93
            $criteria = new \CriteriaCompo();
94
            $criteria->add(new \Criteria('lid', $lid));
95
            $criteria->add(new \Criteria('sender', 0));
96
            $criteria->add(new \Criteria('ip', getenv('REMOTE_ADDR')));
97
            if ($brokenHandler->getCount($criteria) >= 1) {
98
                redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_BROKENFILE_ALREADYREPORTED);
99
            }
100
        }
101
        $erreur         = false;
102
        $errorMessage = '';
103
        // Test avant la validation
104
        xoops_load('captcha');
105
        $xoopsCaptcha = \XoopsCaptcha::getInstance();
106
        if (!$xoopsCaptcha->verify()) {
107
            $errorMessage .= $xoopsCaptcha->getMessage() . '<br>';
108
            $erreur         = true;
109
        }
110
        $obj->setVar('lid', $lid);
111
        $obj->setVar('sender', $ratinguser);
112
        $obj->setVar('ip', getenv('REMOTE_ADDR'));
113
        if (true === $erreur) {
114
            $xoopsTpl->assign('message_erreur', $errorMessage);
115
        } else {
116
            if ($brokenHandler->insert($obj)) {
117
                $tags                      = [];
118
                $tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/broken.php';
119
                /** @var \XoopsNotificationHandler $notificationHandler */
120
                $notificationHandler = xoops_getHandler('notification');
121
                $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

121
                $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

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