XoopsModules25x /
tdmdownloads
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | use Xmf\Module\Admin; |
||||
| 4 | use XoopsModules\Tag\Helper as TagHelper; |
||||
| 5 | use XoopsModules\Tag\LinkHandler; |
||||
| 6 | use XoopsModules\Tdmdownloads\{ |
||||
| 7 | Helper, |
||||
| 8 | Tree |
||||
| 9 | }; |
||||
| 10 | |||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * TDMDownload |
||||
| 14 | * |
||||
| 15 | * You may not change or alter any portion of this comment or credits |
||||
| 16 | * of supporting developers from this source code or any supporting source code |
||||
| 17 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||
| 18 | * This program is distributed in the hope that it will be useful, |
||||
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
| 21 | * |
||||
| 22 | * @copyright Gregory Mage (Aka Mage) |
||||
| 23 | * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||||
| 24 | * @author Gregory Mage (Aka Mage) |
||||
| 25 | */ |
||||
| 26 | require __DIR__ . '/admin_header.php'; |
||||
| 27 | // Template |
||||
| 28 | $templateMain = 'tdmdownloads_admin_category.tpl'; |
||||
| 29 | |||||
| 30 | /** @var \Helper $helper */ |
||||
| 31 | $helper = Helper::getInstance(); |
||||
| 32 | //On recupere la valeur de l'argument op dans l'URL$ |
||||
| 33 | $op = \Xmf\Request::getCmd('op', 'list'); |
||||
| 34 | |||||
| 35 | //Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page |
||||
| 36 | switch ($op) { |
||||
| 37 | // Vue liste |
||||
| 38 | case 'list': |
||||
| 39 | //Affichage de la partie haute de l'administration de Xoops |
||||
| 40 | xoops_cp_header(); |
||||
| 41 | |||||
| 42 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 43 | $adminObject = Admin::getInstance(); |
||||
| 44 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); |
||||
| 45 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); |
||||
| 46 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
||||
| 47 | $GLOBALS['xoopsTpl']->assign('tdmdownloads_url', TDMDOWNLOADS_URL); |
||||
| 48 | |||||
| 49 | $criteria = new \CriteriaCompo(); |
||||
| 50 | $criteria->setSort('cat_weight ASC, cat_title'); |
||||
| 51 | $criteria->setOrder('ASC'); |
||||
| 52 | $downloads_cat = $categoryHandler->getAll($criteria); |
||||
| 53 | //Affichage du tableau |
||||
| 54 | |||||
| 55 | // if (count($downloads_cat) > 0) { |
||||
| 56 | if (count($downloads_cat) > 0) { |
||||
| 57 | $GLOBALS['xoopsTpl']->assign('categories_count', count($downloads_cat)); |
||||
| 58 | |||||
| 59 | $mytree = new Tree($downloads_cat, 'cat_cid', 'cat_pid'); |
||||
| 60 | |||||
| 61 | $category_ArrayTree = $mytree->makeArrayTree('cat_title', '<img src="../assets/images/deco/arrow.gif">'); |
||||
| 62 | |||||
| 63 | $category = []; |
||||
| 64 | |||||
| 65 | foreach (array_keys($category_ArrayTree) as $i) { |
||||
| 66 | /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_cat */ |
||||
| 67 | |||||
| 68 | $category = [ |
||||
| 69 | 'cid' => $i, |
||||
| 70 | 'title' => $downloads_cat[$i]->getVar('cat_title'), |
||||
| 71 | 'category' => $category_ArrayTree[$i], |
||||
| 72 | 'cat_imgurl' => $uploadurl . $downloads_cat[$i]->getVar('cat_imgurl'), |
||||
| 73 | 'cat_description_main' => $downloads_cat[$i]->getVar('cat_description_main'), |
||||
| 74 | 'cat_weight' => $downloads_cat[$i]->getVar('cat_weight'), |
||||
| 75 | ]; |
||||
| 76 | |||||
| 77 | $GLOBALS['xoopsTpl']->append('categories_list', $category); |
||||
| 78 | |||||
| 79 | unset($category); |
||||
| 80 | } |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | break; |
||||
| 84 | // vue création |
||||
| 85 | case 'new_cat': |
||||
| 86 | //Affichage de la partie haute de l'administration de Xoops |
||||
| 87 | xoops_cp_header(); |
||||
| 88 | $adminObject = Admin::getInstance(); |
||||
| 89 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); |
||||
| 90 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); |
||||
| 91 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
||||
| 92 | |||||
| 93 | //Affichage du formulaire de création des catégories |
||||
| 94 | /** @var \XoopsModules\Tdmdownloads\Category $obj */ |
||||
| 95 | $obj = $categoryHandler->create(); |
||||
| 96 | /** @var \XoopsThemeForm $form */ |
||||
| 97 | $form = $obj->getForm(); |
||||
| 98 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||
| 99 | break; |
||||
| 100 | // Pour éditer une catégorie |
||||
| 101 | case 'edit_cat': |
||||
| 102 | //Affichage de la partie haute de l'administration de Xoops |
||||
| 103 | xoops_cp_header(); |
||||
| 104 | $adminObject = Admin::getInstance(); |
||||
| 105 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); |
||||
| 106 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); |
||||
| 107 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); |
||||
| 108 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
||||
| 109 | |||||
| 110 | //Affichage du formulaire de création des catégories |
||||
| 111 | $categoryId = \Xmf\Request::getInt('downloadscat_cid', 0, 'GET'); |
||||
| 112 | /** @var \XoopsModules\Tdmdownloads\Category $obj */ |
||||
| 113 | $obj = $categoryHandler->get($categoryId); |
||||
| 114 | $form = $obj->getForm(); |
||||
| 115 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||
| 116 | break; |
||||
| 117 | // Pour supprimer une catégorie |
||||
| 118 | case 'del_cat': |
||||
| 119 | global $xoopsModule; |
||||
| 120 | $categoryId = \Xmf\Request::getInt('downloadscat_cid', 0, 'GET'); |
||||
| 121 | /** @var \XoopsModules\Tdmdownloads\Category $obj */ |
||||
| 122 | $obj = $categoryHandler->get($categoryId); |
||||
| 123 | if (\Xmf\Request::hasVar('ok', 'REQUEST') && 1 == \Xmf\Request::getInt('ok', 0, 'REQUEST')) { |
||||
| 124 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
| 125 | redirect_header('category.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||
| 126 | } |
||||
| 127 | |||||
| 128 | // supression des téléchargements de la catégorie |
||||
| 129 | |||||
| 130 | $criteria = new \CriteriaCompo(); |
||||
| 131 | |||||
| 132 | $criteria->add(new \Criteria('cid', $categoryId)); |
||||
| 133 | |||||
| 134 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||||
| 135 | |||||
| 136 | foreach (array_keys($downloadsArray) as $i) { |
||||
| 137 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ |
||||
| 138 | |||||
| 139 | // supression des votes |
||||
| 140 | |||||
| 141 | $criteria_1 = new \CriteriaCompo(); |
||||
| 142 | |||||
| 143 | $criteria_1->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); |
||||
| 144 | |||||
| 145 | $votedata = $ratingHandler->getAll($criteria_1); |
||||
| 146 | |||||
| 147 | foreach (array_keys($votedata) as $j) { |
||||
| 148 | /** @var \XoopsModules\Tdmdownloads\Rating[] $votedata */ |
||||
| 149 | |||||
| 150 | $objvotedata = $ratingHandler->get($votedata[$j]->getVar('ratingid')); |
||||
| 151 | |||||
| 152 | $ratingHandler->delete($objvotedata) || $objvotedata->getHtmlErrors(); |
||||
| 153 | } |
||||
| 154 | |||||
| 155 | // supression des rapports de fichier brisé |
||||
| 156 | |||||
| 157 | $criteria_2 = new \CriteriaCompo(); |
||||
| 158 | |||||
| 159 | $criteria_2->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); |
||||
| 160 | |||||
| 161 | $downloads_broken = $brokenHandler->getAll($criteria_2); |
||||
| 162 | |||||
| 163 | foreach (array_keys($downloads_broken) as $j) { |
||||
| 164 | /** @var \XoopsModules\Tdmdownloads\Broken[] $downloads_broken */ |
||||
| 165 | |||||
| 166 | $objbroken = $brokenHandler->get($downloads_broken[$j]->getVar('reportid')); |
||||
| 167 | |||||
| 168 | $brokenHandler->delete($objbroken) || $objbroken->getHtmlErrors(); |
||||
| 169 | } |
||||
| 170 | |||||
| 171 | // supression des data des champs sup. |
||||
| 172 | |||||
| 173 | $criteria_3 = new \CriteriaCompo(); |
||||
| 174 | |||||
| 175 | $criteria_3->add(new \Criteria('lid', $downloadsArray[$i]->getVar('lid'))); |
||||
| 176 | |||||
| 177 | $downloads_fielddata = $fielddataHandler->getAll($criteria_3); |
||||
| 178 | |||||
| 179 | if ($fielddataHandler->getCount($criteria_3) > 0) { |
||||
| 180 | foreach (array_keys($downloads_fielddata) as $j) { |
||||
| 181 | /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloads_fielddata */ |
||||
| 182 | |||||
| 183 | $objfielddata = $fielddataHandler->get($downloads_fielddata[$j]->getVar('iddata')); |
||||
| 184 | |||||
| 185 | $fielddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); |
||||
| 186 | } |
||||
| 187 | } |
||||
| 188 | |||||
| 189 | // supression des commentaires |
||||
| 190 | |||||
| 191 | if ($downloadsArray[$i]->getVar('comments') > 0) { |
||||
| 192 | xoops_comment_delete($xoopsModule->getVar('mid'), $downloadsArray[$i]->getVar('lid')); |
||||
| 193 | } |
||||
| 194 | |||||
| 195 | //supression des tags |
||||
| 196 | |||||
| 197 | if (1 == $helper->getConfig('usetag') && class_exists(LinkHandler::class)) { |
||||
| 198 | /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ |
||||
| 199 | |||||
| 200 | $linkHandler = TagHelper::getInstance()->getHandler('Link'); |
||||
| 201 | |||||
| 202 | $criteria = new \CriteriaCompo(); |
||||
| 203 | |||||
| 204 | $criteria->add(new \Criteria('tag_itemid', $downloadsArray[$i]->getVar('lid'))); |
||||
| 205 | |||||
| 206 | $downloadsTags = $linkHandler->getAll($criteria); |
||||
| 207 | |||||
| 208 | if (count($downloadsTags) > 0) { |
||||
| 209 | foreach (array_keys($downloadsTags) as $j) { |
||||
| 210 | /** @var \XoopsModules\Tag\Link[] $downloadsTags */ |
||||
| 211 | |||||
| 212 | $objtags = $linkHandler->get($downloadsTags[$j]->getVar('tl_id')); |
||||
| 213 | |||||
| 214 | $linkHandler->delete($objtags) || $objtags->getHtmlErrors(); |
||||
| 215 | } |
||||
| 216 | } |
||||
| 217 | } |
||||
| 218 | |||||
| 219 | // supression du fichier |
||||
| 220 | |||||
| 221 | // pour extraire le nom du fichier |
||||
| 222 | |||||
| 223 | $urlfile = substr_replace($downloadsArray[$i]->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 224 | |||||
| 225 | // chemin du fichier |
||||
| 226 | |||||
| 227 | $urlfile = $uploaddir_downloads . $urlfile; |
||||
|
0 ignored issues
–
show
Are you sure
$urlfile of type array|string can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 228 | |||||
| 229 | if (is_file($urlfile)) { |
||||
| 230 | chmod($urlfile, 0777); |
||||
| 231 | |||||
| 232 | unlink($urlfile); |
||||
| 233 | } |
||||
| 234 | |||||
| 235 | // supression du téléchargment |
||||
| 236 | |||||
| 237 | $objdownloads = $downloadsHandler->get($downloadsArray[$i]->getVar('lid')); |
||||
| 238 | |||||
| 239 | $downloadsHandler->delete($objdownloads) || $objdownloads->getHtmlErrors(); |
||||
| 240 | } |
||||
| 241 | |||||
| 242 | // supression des sous catégories avec leurs téléchargements |
||||
| 243 | |||||
| 244 | $downloadscatArray = $categoryHandler->getAll(); |
||||
| 245 | |||||
| 246 | $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
||||
| 247 | |||||
| 248 | $downloads_childcat = $mytree->getAllChild($categoryId); |
||||
| 249 | |||||
| 250 | foreach (array_keys($downloads_childcat) as $i) { |
||||
| 251 | /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_childcat */ |
||||
| 252 | |||||
| 253 | // supression de la catégorie |
||||
| 254 | |||||
| 255 | $objchild = $categoryHandler->get($downloads_childcat[$i]->getVar('cat_cid')); |
||||
| 256 | |||||
| 257 | $categoryHandler->delete($objchild) || $objchild->getHtmlErrors(); |
||||
| 258 | |||||
| 259 | // supression des téléchargements associés |
||||
| 260 | |||||
| 261 | $criteria = new \CriteriaCompo(); |
||||
| 262 | |||||
| 263 | $criteria->add(new \Criteria('cid', $downloads_childcat[$i]->getVar('cat_cid'))); |
||||
| 264 | |||||
| 265 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||||
| 266 | |||||
| 267 | foreach (array_keys($downloadsArray) as $j) { |
||||
| 268 | // supression des votes |
||||
| 269 | |||||
| 270 | $criteria = new \CriteriaCompo(); |
||||
| 271 | |||||
| 272 | $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); |
||||
| 273 | |||||
| 274 | $votedata = $ratingHandler->getAll($criteria); |
||||
| 275 | |||||
| 276 | foreach (array_keys($votedata) as $k) { |
||||
| 277 | $objvotedata = $ratingHandler->get($votedata[$k]->getVar('ratingid')); |
||||
| 278 | |||||
| 279 | $ratingHandler->delete($objvotedata) || $objvotedata->getHtmlErrors(); |
||||
| 280 | } |
||||
| 281 | |||||
| 282 | // supression des rapports de fichier brisé |
||||
| 283 | |||||
| 284 | $criteria = new \CriteriaCompo(); |
||||
| 285 | |||||
| 286 | $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); |
||||
| 287 | |||||
| 288 | $downloads_broken = $brokenHandler->getAll($criteria); |
||||
| 289 | |||||
| 290 | foreach (array_keys($downloads_broken) as $k) { |
||||
| 291 | $objbroken = $brokenHandler->get($downloads_broken[$k]->getVar('reportid')); |
||||
| 292 | |||||
| 293 | $brokenHandler->delete($objbroken) || $objbroken->getHtmlErrors(); |
||||
| 294 | } |
||||
| 295 | |||||
| 296 | // supression des data des champs sup. |
||||
| 297 | |||||
| 298 | $criteria = new \CriteriaCompo(); |
||||
| 299 | |||||
| 300 | $criteria->add(new \Criteria('lid', $downloadsArray[$j]->getVar('lid'))); |
||||
| 301 | |||||
| 302 | $downloads_fielddata = $fielddataHandler->getAll($criteria); |
||||
| 303 | |||||
| 304 | foreach (array_keys($downloads_fielddata) as $k) { |
||||
| 305 | $objfielddata = $fielddataHandler->get($downloads_fielddata[$k]->getVar('iddata')); |
||||
| 306 | |||||
| 307 | $fielddataHandler->delete($objfielddata) || $objvfielddata->getHtmlErrors(); |
||||
| 308 | } |
||||
| 309 | |||||
| 310 | // supression des commentaires |
||||
| 311 | |||||
| 312 | if ($downloadsArray[$j]->getVar('comments') > 0) { |
||||
| 313 | xoops_comment_delete($xoopsModule->getVar('mid'), $downloadsArray[$j]->getVar('lid')); |
||||
| 314 | } |
||||
| 315 | |||||
| 316 | //supression des tags |
||||
| 317 | |||||
| 318 | if (1 == $helper->getConfig('usetag') && class_exists(LinkHandler::class)) { |
||||
| 319 | /** @var \XoopsModules\Tag\LinkHandler $linkHandler */ |
||||
| 320 | |||||
| 321 | $linkHandler = TagHelper::getInstance()->getHandler('Link'); |
||||
| 322 | |||||
| 323 | $criteria = new \CriteriaCompo(); |
||||
| 324 | |||||
| 325 | $criteria->add(new \Criteria('tag_itemid', $downloadsArray[$j]->getVar('lid'))); |
||||
| 326 | |||||
| 327 | $downloadsTags = $linkHandler->getAll($criteria); |
||||
| 328 | |||||
| 329 | if (count($downloadsTags) > 0) { |
||||
| 330 | foreach (array_keys($downloadsTags) as $k) { |
||||
| 331 | $objtags = $linkHandler->get($downloadsTags[$k]->getVar('tl_id')); |
||||
| 332 | |||||
| 333 | $linkHandler->delete($objtags) || $objtags->getHtmlErrors(); |
||||
| 334 | } |
||||
| 335 | } |
||||
| 336 | } |
||||
| 337 | |||||
| 338 | // supression du fichier |
||||
| 339 | $urlfile = substr_replace($downloadsArray[$j]->getVar('url'), '', 0, mb_strlen($uploadurl_downloads)); // pour extraire le nom du fichier |
||||
| 340 | $urlfile = $uploaddir_downloads . $urlfile; // chemin du fichier |
||||
| 341 | if (is_file($urlfile)) { |
||||
| 342 | chmod($urlfile, 0777); |
||||
| 343 | |||||
| 344 | unlink($urlfile); |
||||
| 345 | } |
||||
| 346 | |||||
| 347 | // supression du téléchargment |
||||
| 348 | |||||
| 349 | $objdownloads = $downloadsHandler->get($downloadsArray[$j]->getVar('lid')); |
||||
| 350 | |||||
| 351 | $downloadsHandler->delete($objdownloads) || $objdownloads->getHtmlErrors(); |
||||
| 352 | } |
||||
| 353 | } |
||||
| 354 | |||||
| 355 | if ($categoryHandler->delete($obj)) { |
||||
| 356 | redirect_header('category.php', 1, _AM_TDMDOWNLOADS_REDIRECT_DELOK); |
||||
| 357 | } else { |
||||
| 358 | $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); |
||||
| 359 | } |
||||
| 360 | } else { |
||||
| 361 | $message = ''; |
||||
| 362 | |||||
| 363 | $criteria = new \CriteriaCompo(); |
||||
| 364 | |||||
| 365 | $criteria->add(new \Criteria('cid', $categoryId)); |
||||
| 366 | |||||
| 367 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||||
| 368 | |||||
| 369 | if (count($downloadsArray) > 0) { |
||||
| 370 | $message .= _AM_TDMDOWNLOADS_DELDOWNLOADS . '<br>'; |
||||
| 371 | |||||
| 372 | foreach (array_keys($downloadsArray) as $i) { |
||||
| 373 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ |
||||
| 374 | |||||
| 375 | $message .= '<span style="color : #ff0000">' . $downloadsArray[$i]->getVar('title') . '</span><br>'; |
||||
| 376 | } |
||||
| 377 | } |
||||
| 378 | |||||
| 379 | $downloadscatArray = $categoryHandler->getAll(); |
||||
| 380 | |||||
| 381 | $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
||||
| 382 | |||||
| 383 | $downloads_childcat = $mytree->getAllChild($categoryId); |
||||
| 384 | |||||
| 385 | if (count($downloads_childcat) > 0) { |
||||
| 386 | $message .= _AM_TDMDOWNLOADS_DELSOUSCAT . ' <br><br>'; |
||||
| 387 | |||||
| 388 | foreach (array_keys($downloads_childcat) as $i) { |
||||
| 389 | /** @var \XoopsModules\Tdmdownloads\Category[] $downloads_childcat */ |
||||
| 390 | |||||
| 391 | $message .= '<b><span style="color : #ff0000">' . $downloads_childcat[$i]->getVar('cat_title') . '</span></b><br>'; |
||||
| 392 | |||||
| 393 | $criteria = new \CriteriaCompo(); |
||||
| 394 | |||||
| 395 | $criteria->add(new \Criteria('cid', $downloads_childcat[$i]->getVar('cat_cid'))); |
||||
| 396 | |||||
| 397 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||||
| 398 | |||||
| 399 | if (count($downloadsArray) > 0) { |
||||
| 400 | $message .= _AM_TDMDOWNLOADS_DELDOWNLOADS . '<br>'; |
||||
| 401 | |||||
| 402 | foreach (array_keys($downloadsArray) as $k) { |
||||
| 403 | $message .= '<span style="color: #ff0000;">' . $downloadsArray[$k]->getVar('title') . '</span><br>'; |
||||
| 404 | } |
||||
| 405 | } |
||||
| 406 | } |
||||
| 407 | } else { |
||||
| 408 | $message .= ''; |
||||
| 409 | } |
||||
| 410 | |||||
| 411 | //Affichage de la partie haute de l'administration de Xoops |
||||
| 412 | |||||
| 413 | xoops_cp_header(); |
||||
| 414 | |||||
| 415 | $adminObject = Admin::getInstance(); |
||||
| 416 | |||||
| 417 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__))); |
||||
| 418 | |||||
| 419 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_LIST, 'category.php?op=list', 'list'); |
||||
| 420 | |||||
| 421 | $adminObject->addItemButton(_AM_TDMDOWNLOADS_CAT_NEW, 'category.php?op=new_cat', 'add'); |
||||
| 422 | |||||
| 423 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
||||
| 424 | |||||
| 425 | xoops_confirm( |
||||
| 426 | [ |
||||
| 427 | 'ok' => 1, |
||||
| 428 | 'downloadscat_cid' => $categoryId, |
||||
| 429 | 'op' => 'del_cat', |
||||
| 430 | ], |
||||
| 431 | $_SERVER['REQUEST_URI'], |
||||
| 432 | sprintf(_AM_TDMDOWNLOADS_FORMSUREDEL, $obj->getVar('cat_title')) . '<br><br>' . $message |
||||
|
0 ignored issues
–
show
It seems like
$obj->getVar('cat_title') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 433 | ); |
||||
| 434 | } |
||||
| 435 | |||||
| 436 | break; |
||||
| 437 | // Pour sauver une catégorie |
||||
| 438 | case 'save_cat': |
||||
| 439 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
| 440 | redirect_header('category.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||
| 441 | } |
||||
| 442 | xoops_cp_header(); |
||||
| 443 | $cat_cid = \Xmf\Request::getInt('cat_cid', 0, 'POST'); |
||||
| 444 | if (0 !== $cat_cid) { |
||||
| 445 | $obj = $categoryHandler->get($cat_cid); |
||||
| 446 | } else { |
||||
| 447 | $obj = $categoryHandler->create(); |
||||
| 448 | } |
||||
| 449 | $erreur = false; |
||||
| 450 | $errorMessage = ''; |
||||
| 451 | // Récupération des variables: |
||||
| 452 | // Pour l'image |
||||
| 453 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||||
| 454 | $uploader = new \XoopsMediaUploader( |
||||
| 455 | $uploaddir, [ |
||||
| 456 | 'image/gif', |
||||
| 457 | 'image/jpeg', |
||||
| 458 | 'image/pjpeg', |
||||
| 459 | 'image/x-png', |
||||
| 460 | 'image/png', |
||||
| 461 | ], $helper->getConfig('maxuploadsize'), null, null |
||||
| 462 | ); |
||||
| 463 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||||
| 464 | $uploader->setPrefix('downloads_'); |
||||
| 465 | |||||
| 466 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||||
| 467 | |||||
| 468 | if (!$uploader->upload()) { |
||||
| 469 | $errors = $uploader->getErrors(); |
||||
| 470 | |||||
| 471 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||
| 472 | } else { |
||||
| 473 | $obj->setVar('cat_imgurl', $uploader->getSavedFileName()); |
||||
| 474 | } |
||||
| 475 | } else { |
||||
| 476 | $obj->setVar('cat_imgurl', \Xmf\Request::getString('downloadscat_img', '', 'REQUEST')); |
||||
| 477 | } |
||||
| 478 | // Pour les autres variables |
||||
| 479 | $obj->setVar('cat_pid', \Xmf\Request::getInt('cat_pid', 0, 'POST')); //$_POST['cat_pid']); |
||||
| 480 | $obj->setVar('cat_title', \Xmf\Request::getString('cat_title', '', 'POST')); //$_POST['cat_title']); |
||||
| 481 | $obj->setVar('cat_description_main', \Xmf\Request::getString('cat_description_main', '', 'POST')); //$_POST['cat_description_main']); |
||||
| 482 | $obj->setVar('cat_weight', \Xmf\Request::getInt('cat_weight', 0, 'POST')); |
||||
| 483 | |||||
| 484 | if (\Xmf\Request::hasVar('cat_cid', 'REQUEST')) { |
||||
| 485 | if ($cat_cid === \Xmf\Request::getInt('cat_pid', 0, 'POST')) { |
||||
| 486 | $erreur = true; |
||||
| 487 | |||||
| 488 | $errorMessage .= _AM_TDMDOWNLOADS_ERREUR_CAT; |
||||
| 489 | } |
||||
| 490 | } |
||||
| 491 | if (true === $erreur) { |
||||
| 492 | $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); |
||||
| 493 | } else { |
||||
| 494 | if ($categoryHandler->insert($obj)) { |
||||
| 495 | /** @var \XoopsModules\Tdmdownloads\Category $obj */ |
||||
| 496 | |||||
| 497 | $newcat_cid = $obj->getNewEnreg($db); |
||||
| 498 | |||||
| 499 | //permission pour voir |
||||
| 500 | |||||
| 501 | $perm_id = \Xmf\Request::hasVar('cat_cid', 'POST') ? $cat_cid : $newcat_cid; |
||||
| 502 | |||||
| 503 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
| 504 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||
| 505 | |||||
| 506 | $criteria = new \CriteriaCompo(); |
||||
| 507 | |||||
| 508 | $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); |
||||
| 509 | |||||
| 510 | $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); |
||||
| 511 | |||||
| 512 | $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_view', '=')); |
||||
| 513 | |||||
| 514 | $grouppermHandler->deleteAll($criteria); |
||||
| 515 | |||||
| 516 | if (\Xmf\Request::hasVar('groups_view', 'POST')) { |
||||
| 517 | foreach ($_POST['groups_view'] as $onegroup_id) { |
||||
| 518 | $grouppermHandler->addRight('tdmdownloads_view', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); |
||||
|
0 ignored issues
–
show
It seems like
$perm_id can also be of type string; however, parameter $gperm_itemid of XoopsGroupPermHandler::addRight() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 519 | } |
||||
| 520 | } |
||||
| 521 | |||||
| 522 | //permission pour editer |
||||
| 523 | |||||
| 524 | $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); |
||||
|
0 ignored issues
–
show
It seems like
$newcat_cid can also be of type string; however, parameter $default of Xmf\Request::getInt() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 525 | |||||
| 526 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
| 527 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||
| 528 | |||||
| 529 | $criteria = new \CriteriaCompo(); |
||||
| 530 | |||||
| 531 | $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); |
||||
| 532 | |||||
| 533 | $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); |
||||
| 534 | |||||
| 535 | $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_submit', '=')); |
||||
| 536 | |||||
| 537 | $grouppermHandler->deleteAll($criteria); |
||||
| 538 | |||||
| 539 | if (\Xmf\Request::hasVar('groups_submit', 'POST')) { |
||||
| 540 | foreach ($_POST['groups_submit'] as $onegroup_id) { |
||||
| 541 | $grouppermHandler->addRight('tdmdownloads_submit', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); |
||||
| 542 | } |
||||
| 543 | } |
||||
| 544 | |||||
| 545 | //permission pour télécharger |
||||
| 546 | |||||
| 547 | if (1 == $helper->getConfig('permission_download')) { |
||||
| 548 | $perm_id = \Xmf\Request::getInt('cat_cid', $newcat_cid, 'POST'); |
||||
| 549 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
| 550 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||
| 551 | |||||
| 552 | $criteria = new \CriteriaCompo(); |
||||
| 553 | |||||
| 554 | $criteria->add(new \Criteria('gperm_itemid', $perm_id, '=')); |
||||
| 555 | |||||
| 556 | $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); |
||||
| 557 | |||||
| 558 | $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download', '=')); |
||||
| 559 | |||||
| 560 | $grouppermHandler->deleteAll($criteria); |
||||
| 561 | |||||
| 562 | if (\Xmf\Request::hasVar('groups_download', 'POST')) { |
||||
| 563 | foreach ($_POST['groups_download'] as $onegroup_id) { |
||||
| 564 | $grouppermHandler->addRight('tdmdownloads_download', $perm_id, $onegroup_id, $xoopsModule->getVar('mid')); |
||||
| 565 | } |
||||
| 566 | } |
||||
| 567 | } |
||||
| 568 | |||||
| 569 | //notification |
||||
| 570 | |||||
| 571 | if (!\Xmf\Request::hasVar('categorie_modified', 'POST')) { |
||||
| 572 | $tags = []; |
||||
| 573 | |||||
| 574 | $tags['CATEGORY_NAME'] = \Xmf\Request::getString('cat_title', '', 'POST'); |
||||
| 575 | |||||
| 576 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $newcat_cid; |
||||
| 577 | |||||
| 578 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||
| 579 | |||||
| 580 | $notificationHandler = xoops_getHandler('notification'); |
||||
| 581 | |||||
| 582 | $notificationHandler->triggerEvent('global', 0, 'new_category', $tags); |
||||
| 583 | } |
||||
| 584 | |||||
| 585 | redirect_header('category.php?op=list', 1, _AM_TDMDOWNLOADS_REDIRECT_SAVE); |
||||
| 586 | } |
||||
| 587 | |||||
| 588 | $GLOBALS['xoopsTpl']->assign('message_erreur', $obj->getHtmlErrors()); |
||||
| 589 | } |
||||
| 590 | $form = $obj->getForm(); |
||||
| 591 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||
| 592 | break; |
||||
| 593 | } |
||||
| 594 | |||||
| 595 | // Local icons path |
||||
| 596 | if (is_object($helper->getModule())) { |
||||
| 597 | $pathModIcon16 = $helper->getModule()->getInfo('modicons16'); |
||||
| 598 | |||||
| 599 | $pathModIcon32 = $helper->getModule()->getInfo('modicons32'); |
||||
| 600 | |||||
| 601 | $GLOBALS['xoopsTpl']->assign('pathModIcon16', XOOPS_URL . '/modules/' . $moduleDirName . '/' . $pathModIcon16); |
||||
| 602 | |||||
| 603 | $GLOBALS['xoopsTpl']->assign('pathModIcon32', $pathModIcon32); |
||||
| 604 | } |
||||
| 605 | |||||
| 606 | //Affichage de la partie basse de l'administration de Xoops |
||||
| 607 | require_once __DIR__ . '/admin_footer.php'; |
||||
| 608 |