Completed
Pull Request — master (#3)
by Michael
01:28
created

submit.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
include_once 'header.php';
18
// template d'affichage
19
$xoopsOption['template_main'] = 'tdmdownloads_submit.html';
20
include_once XOOPS_ROOT_PATH.'/header.php';
21
$xoTheme->addStylesheet( XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/css/styles.css', null );
22
//On recupere la valeur de l'argument op dans l'URL$
23
$op = TDMDownloads_CleanVars($_REQUEST, 'op', 'list', 'string');
24
25
// redirection si pas de droit pour poster
26
if ($perm_submit == false) {
27
    redirect_header('index.php', 2, _NOPERM);
28
    exit();
29
}
30
31
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
32
switch ($op) {
33
    // Vue liste
34
    case "list":
35
        //navigation
36
        $navigation = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER;
37
        $xoopsTpl->assign('navigation', $navigation);
38
        // r�f�rencement
39
        // titre de la page
40
        $titre = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER . '&nbsp;-&nbsp;';
41
        $titre .= $xoopsModule->name();
42
        $xoopsTpl->assign('xoops_pagetitle', $titre);
43
        //description
44
        $xoTheme->addMeta( 'meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SUBMIT_PROPOSER));
45
46
        //Affichage du formulaire de notation des t�l�chargements
47
        $obj =& $downloads_Handler->create();
48
        $form = $obj->getForm($donnee = array(), false);
49
        $xoopsTpl->assign('themeForm', $form->render());
50
    break;
51
    // save
52
    case "save_downloads":
53
        include_once XOOPS_ROOT_PATH.'/class/uploader.php';
54
        $obj =& $downloads_Handler->create();
55
        $erreur = false;
56
        $message_erreur = '';
57
        $donnee = array();
58
        $obj->setVar('title', $_POST['title']);
59
        $donnee['title'] = $_POST['title'];
60
        $obj->setVar('cid', $_POST['cid']);
61
        $donnee['cid'] = $_POST['cid'];
62
        $obj->setVar('homepage', formatURL($_POST['homepage']));
63
        $obj->setVar('version', $_POST['version']);
64
        $obj->setVar('size', $_POST['size']);
65
        $donnee['type_size'] = $_POST['type_size'];
66
        $obj->setVar('paypal', $_POST['paypal']);
67
        if (isset($_POST['platform'])) {
68
            $obj->setVar('platform', implode('|',$_POST['platform']));
69
        }
70
        $obj->setVar('description', $_POST['description']);
71 View Code Duplication
        if (isset($_POST['submitter'])) {
72
            $obj->setVar('submitter', $_POST['submitter']);
73
            $donnee['submitter'] = $_POST['submitter'];
74
        } else {
75
            $obj->setVar('submitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0);
76
            $donnee['submitter'] = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
77
        }
78
        $obj->setVar('date', time());
79
        if ($perm_autoapprove == true) {
80
            $obj->setVar('status', 1);
81
        } else {
82
            $obj->setVar('status', 0);
83
        }
84
        if ($xoopsUser) {
85
            if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
86 View Code Duplication
                if (isset($_POST['status'])) {
87
                    $obj->setVar('status', $_POST['status']);
88
                    $donnee['status'] = $_POST['status'];
89
                } else {
90
                    $obj->setVar('status', 0);
91
                    $donnee['status'] = 0;
92
                }
93
            }
94
        }
95
        $donnee['date_update'] = 0;
96
        // erreur si la taille du fichier n'est pas un nombre
97 View Code Duplication
        if (intval($_REQUEST['size']) == 0) {
98
            if ($_REQUEST['size'] == '0' || $_REQUEST['size'] == '') {
99
                $erreur = false;
100
            } else {
101
                $erreur = true;
102
                $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>';
103
            }
104
        }
105
        // erreur si la cat�gorie est vide
106 View Code Duplication
        if (isset($_REQUEST['cid'])) {
107
            if ($_REQUEST['cid'] == 0) {
108
                $erreur=true;
109
                $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>';
110
            }
111
        }
112
        // erreur si le captcha est faux
113
        xoops_load("captcha");
114
        $xoopsCaptcha = XoopsCaptcha::getInstance();
115
        if ( !$xoopsCaptcha->verify() ) {
116
            $message_erreur .=$xoopsCaptcha->getMessage().'<br>';
117
            $erreur=true;
118
        }
119
        // pour enregistrer temporairement les valeur des champs sup
120
        $criteria = new CriteriaCompo();
121
        $criteria->setSort('weight ASC, title');
122
        $criteria->setOrder('ASC');
123
        $downloads_field = $downloadsfield_Handler->getall($criteria);
124 View Code Duplication
        foreach (array_keys($downloads_field) as $i) {
125
            if ($downloads_field[$i]->getVar('status_def') == 0) {
126
                $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid');
127
                $donnee[$nom_champ] = $_POST[$nom_champ];
128
            }
129
        }
130
        // enregistrement temporaire des tags
131 View Code Duplication
        if (($xoopsModuleConfig['usetag'] == 1) and (is_dir('../tag'))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
132
            $donnee['TAG'] = $_POST['tag'];
133
        }
134
        if ($erreur==true) {
135
            $xoopsTpl->assign('message_erreur', $message_erreur);
136
        } else {
137
            $obj->setVar('size', $_POST['size'] . ' ' . $_POST['type_size']);
138
            // Pour le fichier
139 View Code Duplication
            if (isset($_POST['xoops_upload_file'][0])) {
140
                $uploader = new XoopsMediaUploader($uploaddir_downloads, explode('|',$xoopsModuleConfig['mimetype']), $xoopsModuleConfig['maxuploadsize'], null, null);
141
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
142
                    if ($xoopsModuleConfig['newnamedownload']) {
143
                        $uploader->setPrefix($xoopsModuleConfig['prefixdownloads']) ;
144
                    }
145
                    $uploader->fetchMedia($_POST['xoops_upload_file'][0]);
146
                    if (!$uploader->upload()) {
147
                        $errors = $uploader->getErrors();
148
                        redirect_header("javascript:history.go(-1)",3, $errors);
149
                    } else {
150
                        $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName());
151
                    }
152
                } else {
153
                    $obj->setVar('url', $_REQUEST['url']);
154
                }
155
            }
156
            // Pour l'image
157 View Code Duplication
            if (isset($_POST['xoops_upload_file'][1])) {
158
                $uploader_2 = new XoopsMediaUploader($uploaddir_shots, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $xoopsModuleConfig['maxuploadsize'], null, null);
159
                if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) {
160
                    $uploader_2->setPrefix('downloads_') ;
161
                    $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]);
162
                    if (!$uploader_2->upload()) {
163
                        $errors = $uploader_2->getErrors();
164
                        redirect_header("javascript:history.go(-1)",3, $errors);
165
                    } else {
166
                        $obj->setVar('logourl', $uploader_2->getSavedFileName());
167
                    }
168
                } else {
169
                    $obj->setVar('logourl', $_REQUEST['logo_img']);
170
                }
171
            }
172
173
            if ($downloads_Handler->insert($obj)) {
174
                $lid_dowwnloads = $obj->get_new_enreg();
175
                //tags
176 View Code Duplication
                if (($xoopsModuleConfig['usetag'] == 1) and (is_dir('../tag'))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
177
                    $tag_handler = xoops_getmodulehandler('tag', 'tag');
178
                    $tag_handler->updateByItem($_POST['tag'], $lid_dowwnloads, $xoopsModule->getVar('dirname'), 0);
179
                }
180
                // R�cup�ration des champs suppl�mentaires:
181
                $criteria = new CriteriaCompo();
182
                $criteria->setSort('weight ASC, title');
183
                $criteria->setOrder('ASC');
184
                $downloads_field = $downloadsfield_Handler->getall($criteria);
185 View Code Duplication
                foreach (array_keys($downloads_field) as $i) {
186
                    if ($downloads_field[$i]->getVar('status_def') == 0) {
187
                        $objdata =& $downloadsfielddata_Handler->create();
188
                        $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid');
189
                        $objdata->setVar('data', $_POST[$nom_champ]);
190
                        $objdata->setVar('lid', $lid_dowwnloads);
191
                        $objdata->setVar('fid', $downloads_field[$i]->getVar('fid'));
192
                        $downloadsfielddata_Handler->insert($objdata) or $objdata->getHtmlErrors();
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
193
                    }
194
                }
195
                if ($xoopsUser) {
196 View Code Duplication
                    if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
197
                        //permission pour t�l�charger
198
                        if ($xoopsModuleConfig['permission_download'] == 1) {
199
                            $gperm_handler = &xoops_gethandler('groupperm');
200
                            $criteria = new CriteriaCompo();
201
                            $criteria->add(new Criteria('gperm_itemid', $lid_dowwnloads, '='));
202
                            $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'),'='));
203
                            $criteria->add(new Criteria('gperm_name', 'tdmdownloads_download_item', '='));
204
                            $gperm_handler->deleteAll($criteria);
205
                            if (isset($_POST['item_download'])) {
206
                                foreach ($_POST['item_download'] as $onegroup_id) {
207
                                    $gperm_handler->addRight('tdmdownloads_download_item', $lid_dowwnloads, $onegroup_id, $xoopsModule->getVar('mid'));
208
                                }
209
                            }
210
                        }
211
                    }
212
                }
213
                $notification_handler =& xoops_gethandler('notification');
214
                $tags = array();
215
                $tags['FILE_NAME'] = $donnee['title'];
216
                $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/singlefile.php?cid=' . $donnee['cid'] . '&lid=' . $lid_dowwnloads;
217
                $downloadscat_cat = $downloadscat_Handler->get($donnee['cid']);
218
                $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title');
219
                $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $donnee['cid'];
220
221
                if ($perm_autoapprove == true) {
222
                    $notification_handler->triggerEvent('global', 0, 'new_file', $tags);
223
                    $notification_handler->triggerEvent('category', $donnee['cid'], 'new_file', $tags);
224
                    redirect_header('index.php',2,_MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '<br />' . _MD_TDMDOWNLOADS_SUBMIT_ISAPPROVED . '');
225
                    exit;
226
                } else {
227
                    $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listNewDownloads';
228
                    $notification_handler->triggerEvent('global', 0, 'file_submit', $tags);
229
                    $notification_handler->triggerEvent('category', $donnee['cid'], 'file_submit', $tags);
230
                    redirect_header('index.php',2,_MD_TDMDOWNLOADS_SUBMIT_RECEIVED);
231
                    exit;
232
                }
233
            }
234
            echo $obj->getHtmlErrors();
235
        }
236
        $form =& $obj->getForm($donnee, true);
237
        $xoopsTpl->assign('themeForm', $form->render());
238
239
    break;
240
}
241
include XOOPS_ROOT_PATH.'/footer.php';
242