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_modfile.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_modif == false) { |
||
27 | redirect_header('index.php', 2, _NOPERM); |
||
28 | exit(); |
||
29 | } |
||
30 | |||
31 | $lid = TDMDownloads_CleanVars($_REQUEST, 'lid', 0, 'int'); |
||
32 | |||
33 | //information du téléchargement |
||
34 | $view_downloads = $downloads_Handler->get($lid); |
||
35 | |||
36 | // redirection si le téléchargement n'existe pas ou n'est pas activé |
||
37 | View Code Duplication | if (count($view_downloads) == 0 || $view_downloads->getVar('status') == 0) { |
|
38 | redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT); |
||
39 | exit(); |
||
40 | } |
||
41 | |||
42 | //Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page |
||
43 | switch ($op) { |
||
44 | // Vue liste |
||
45 | case "list": |
||
46 | //navigation |
||
47 | $view_categorie = $downloadscat_Handler->get($view_downloads->getVar('cid')); |
||
48 | $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads'); |
||
49 | if (!in_array($view_downloads->getVar('cid'), $categories)) { |
||
50 | redirect_header('index.php', 2, _NOPERM); |
||
51 | exit(); |
||
52 | } |
||
53 | //tableau des catégories |
||
54 | $criteria = new CriteriaCompo(); |
||
55 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
56 | $criteria->setOrder('ASC'); |
||
57 | $criteria->add(new Criteria('cat_cid', '(' . implode(',', $categories) . ')','IN')); |
||
58 | $downloadscat_arr = $downloadscat_Handler->getall($criteria); |
||
59 | $mytree = new XoopsObjectTree($downloadscat_arr, 'cat_cid', 'cat_pid'); |
||
60 | //navigation |
||
61 | $navigation = TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' <img src="images/deco/arrow.gif" alt="arrow" /> ', true, 'ASC', true); |
||
62 | $navigation .= ' <img src="images/deco/arrow.gif" alt="arrow" /> <a title="' . $view_downloads->getVar('title') . '" href="singlefile.php?lid=' . $view_downloads->getVar('lid') . '">' . $view_downloads->getVar('title') . '</a>'; |
||
63 | $navigation .= ' <img src="images/deco/arrow.gif" alt="arrow" /> ' . _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY; |
||
64 | $xoopsTpl->assign('navigation', $navigation); |
||
65 | // référencement |
||
66 | // titre de la page |
||
67 | $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' - ' . $view_downloads->getVar('title') . ' - '; |
||
68 | $pagetitle .= TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' - ', false, 'DESC', true); |
||
69 | $xoopsTpl->assign('xoops_pagetitle', $pagetitle); |
||
70 | //description |
||
71 | $xoTheme->addMeta( 'meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' (' . $view_downloads->getVar('title') . ')')); |
||
72 | |||
73 | //Affichage du formulaire de notation des téléchargements |
||
74 | $obj =& $downloadsmod_Handler->create(); |
||
75 | $form = $obj->getForm($lid, false, $donnee = array()); |
||
76 | $xoopsTpl->assign('themeForm', $form->render()); |
||
77 | break; |
||
78 | // save |
||
79 | case "save": |
||
80 | include_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
||
81 | $obj =& $downloadsmod_Handler->create(); |
||
82 | $erreur = false; |
||
83 | $message_erreur = ''; |
||
84 | $donnee = array(); |
||
85 | $obj->setVar('title', $_POST['title']); |
||
86 | $donnee['title'] = $_POST['title']; |
||
87 | $obj->setVar('cid', $_POST['cid']); |
||
88 | $donnee['cid'] = $_POST['cid']; |
||
89 | $obj->setVar('lid', $_POST['lid']); |
||
90 | $obj->setVar('homepage', formatURL($_POST["homepage"])); |
||
91 | $donnee['homepage'] = formatURL($_POST["homepage"]); |
||
92 | $obj->setVar('version', $_POST["version"]); |
||
93 | $donnee['version'] = $_POST["version"]; |
||
94 | $obj->setVar('size', $_POST["size"]); |
||
95 | $donnee['size'] = $_POST["size"]; |
||
96 | $donnee['type_size'] = $_POST['type_size']; |
||
97 | if (isset($_POST['platform'])) { |
||
98 | $obj->setVar('platform', implode('|',$_POST['platform'])); |
||
99 | $donnee['platform'] = implode('|',$_POST["platform"]); |
||
100 | } else { |
||
101 | $donnee['platform'] = ''; |
||
102 | } |
||
103 | $obj->setVar('description', $_POST["description"]); |
||
104 | $donnee['description'] = $_POST["description"]; |
||
105 | $obj->setVar('modifysubmitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); |
||
106 | |||
107 | // erreur si la taille du fichier n'est pas un nombre |
||
108 | View Code Duplication | if (intval($_REQUEST['size']) == 0) { |
|
109 | if ($_REQUEST['size'] == '0' || $_REQUEST['size'] == '') { |
||
110 | $erreur = false; |
||
111 | } else { |
||
112 | $erreur = true; |
||
113 | $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>'; |
||
114 | } |
||
115 | } |
||
116 | // erreur si la catégorie est vide |
||
117 | View Code Duplication | if (isset($_REQUEST['cid'])) { |
|
118 | if ($_REQUEST['cid'] == 0) { |
||
119 | $erreur=true; |
||
120 | $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>'; |
||
121 | } |
||
122 | } |
||
123 | // erreur si le captcha est faux |
||
124 | xoops_load("captcha"); |
||
125 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
126 | if ( !$xoopsCaptcha->verify() ) { |
||
127 | $message_erreur .=$xoopsCaptcha->getMessage().'<br>'; |
||
128 | $erreur=true; |
||
129 | } |
||
130 | // pour enregistrer temporairement les valeur des champs sup |
||
131 | $criteria = new CriteriaCompo(); |
||
132 | $criteria->setSort('weight ASC, title'); |
||
133 | $criteria->setOrder('ASC'); |
||
134 | $downloads_field = $downloadsfield_Handler->getall($criteria); |
||
135 | View Code Duplication | foreach (array_keys($downloads_field) as $i) { |
|
136 | if ($downloads_field[$i]->getVar('status_def') == 0) { |
||
137 | $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid'); |
||
138 | $donnee[$nom_champ] = $_POST[$nom_champ]; |
||
139 | } |
||
140 | } |
||
141 | if ($erreur==true) { |
||
142 | $xoopsTpl->assign('message_erreur', $message_erreur); |
||
143 | } else { |
||
144 | $obj->setVar('size', $_POST['size'] . ' ' . $_POST['type_size']); |
||
145 | // Pour le fichier |
||
146 | View Code Duplication | if (isset($_POST['xoops_upload_file'][0])) { |
|
147 | $uploader = new XoopsMediaUploader($uploaddir_downloads, explode('|',$xoopsModuleConfig['mimetype']), $xoopsModuleConfig['maxuploadsize'], null, null); |
||
148 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||
149 | if ($xoopsModuleConfig['newnamedownload']) { |
||
150 | $uploader->setPrefix($xoopsModuleConfig['prefixdownloads']) ; |
||
151 | } |
||
152 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||
153 | if (!$uploader->upload()) { |
||
154 | $errors = $uploader->getErrors(); |
||
155 | redirect_header("javascript:history.go(-1)",3, $errors); |
||
156 | } else { |
||
157 | $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); |
||
158 | } |
||
159 | } else { |
||
160 | $obj->setVar('url', $_REQUEST['url']); |
||
161 | } |
||
162 | } |
||
163 | // Pour l'image |
||
164 | View Code Duplication | if (isset($_POST['xoops_upload_file'][1])) { |
|
165 | $uploader_2 = new XoopsMediaUploader($uploaddir_shots, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $xoopsModuleConfig['maxuploadsize'], null, null); |
||
166 | if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { |
||
167 | $uploader_2->setPrefix('downloads_') ; |
||
168 | $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); |
||
169 | if (!$uploader_2->upload()) { |
||
170 | $errors = $uploader_2->getErrors(); |
||
171 | redirect_header("javascript:history.go(-1)",3, $errors); |
||
172 | } else { |
||
173 | $obj->setVar('logourl', $uploader_2->getSavedFileName()); |
||
174 | } |
||
175 | } else { |
||
176 | $obj->setVar('logourl', $_REQUEST['logo_img']); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | if ($downloadsmod_Handler->insert($obj)) { |
||
181 | $lid_dowwnloads = $obj->get_new_enreg(); |
||
182 | // Récupération des champs supplémentaires: |
||
183 | $criteria = new CriteriaCompo(); |
||
184 | $criteria->setSort('weight ASC, title'); |
||
185 | $criteria->setOrder('ASC'); |
||
186 | $downloads_field = $downloadsfield_Handler->getall($criteria); |
||
187 | View Code Duplication | foreach (array_keys($downloads_field) as $i) { |
|
188 | if ($downloads_field[$i]->getVar('status_def') == 0) { |
||
189 | $objdata =& $downloadsfieldmoddata_Handler->create(); |
||
190 | $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid'); |
||
191 | $objdata->setVar('moddata', $_POST[$nom_champ]); |
||
192 | $objdata->setVar('lid', $lid_dowwnloads); |
||
193 | $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); |
||
194 | $downloadsfieldmoddata_Handler->insert($objdata) or $objdata->getHtmlErrors(); |
||
0 ignored issues
–
show
|
|||
195 | } |
||
196 | } |
||
197 | $tags = array(); |
||
198 | $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/modified.php'; |
||
199 | $notification_handler =& xoops_gethandler('notification'); |
||
200 | $notification_handler->triggerEvent('global', 0, 'file_modify', $tags); |
||
201 | redirect_header('singlefile.php?lid=' . intval($_REQUEST['lid']), 1, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO); |
||
202 | } |
||
203 | echo $obj->getHtmlErrors(); |
||
204 | } |
||
205 | //Affichage du formulaire de notation des téléchargements |
||
206 | $form =& $obj->getForm(intval($_REQUEST['lid']), true, $donnee); |
||
207 | $xoopsTpl->assign('themeForm', $form->render()); |
||
208 | |||
209 | break; |
||
210 | } |
||
211 | include XOOPS_ROOT_PATH.'/footer.php'; |
||
212 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
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 are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
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 withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.