XoopsModules25x /
oledrion
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * oledrion |
||
| 14 | * |
||
| 15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 17 | * @author Hervé Thouzard (http://www.herve-thouzard.com/) |
||
| 18 | */ |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Liste des listes de l'utilisateur |
||
| 22 | */ |
||
| 23 | require_once __DIR__ . '/header.php'; |
||
| 24 | $GLOBALS['current_category'] = -1; |
||
| 25 | $GLOBALS['xoopsOption']['template_main'] = 'oledrion_mylists.tpl'; |
||
| 26 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 27 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 28 | |||
| 29 | $uid = OledrionUtility::getCurrentUserID(); |
||
| 30 | if ($uid == 0) { |
||
| 31 | OledrionUtility::redirect(_OLEDRION_ERROR23, XOOPS_URL . '/register.php', 4); |
||
| 32 | } |
||
| 33 | |||
| 34 | $baseurl = OLEDRION_URL . basename(__FILE__); // URL de ce script |
||
| 35 | $handlers = OledrionHandler::getInstance(); |
||
| 36 | if (isset($_GET['op'])) { |
||
| 37 | $op = $_GET['op']; |
||
| 38 | } elseif (isset($_POST['op'])) { |
||
| 39 | $op = $_POST['op']; |
||
| 40 | } else { |
||
| 41 | $op = 'default'; |
||
| 42 | } |
||
| 43 | $xoopsTpl->assign('baseurl', $baseurl); |
||
| 44 | OledrionUtility::loadLanguageFile('modinfo.php'); |
||
| 45 | OledrionUtility::loadLanguageFile('admin.php'); |
||
| 46 | $breadcrumb = ''; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $op |
||
| 50 | * @param int $product_id |
||
| 51 | * @return object|XoopsThemeForm |
||
| 52 | */ |
||
| 53 | function listForm($op, $product_id = 0) |
||
| 54 | { |
||
| 55 | global $handlers, $baseurl; |
||
| 56 | if ($op === 'edit') { |
||
| 57 | $title = _OLEDRION_EDIT_LIST; |
||
| 58 | $label_submit = _AM_OLEDRION_MODIFY; |
||
| 59 | $list_id = isset($_GET['list_id']) ? (int)$_GET['list_id'] : 0; |
||
| 60 | if (empty($list_id)) { |
||
| 61 | OledrionUtility::redirect(_AM_OLEDRION_ERROR_21, $baseurl, 5); |
||
| 62 | } |
||
| 63 | $item = null; |
||
| 64 | $item = $handlers->h_oledrion_lists->get($list_id); |
||
| 65 | if (!is_object($item)) { |
||
| 66 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 67 | } |
||
| 68 | // Vérification, est-ce que l'utilisateur courant est bien le propriétaire de cette liste ? |
||
| 69 | if (!$handlers->h_oledrion_lists->isThisMyList($list_id)) { |
||
| 70 | OledrionUtility::redirect(_OLEDRION_ERROR25, $baseurl, 8); |
||
| 71 | } |
||
| 72 | $edit = true; |
||
| 73 | $label_submit = _AM_OLEDRION_MODIFY; |
||
| 74 | } else { |
||
| 75 | $title = _OLEDRION_ADD_LIST; |
||
| 76 | $label_submit = _AM_OLEDRION_ADD; |
||
| 77 | $item = $handlers->h_oledrion_lists->create(true); |
||
| 78 | $edit = false; |
||
| 79 | } |
||
| 80 | |||
| 81 | $sform = new XoopsThemeForm($title, 'frmList', $baseurl); |
||
| 82 | $sform->addElement(new XoopsFormHidden('op', 'save')); |
||
| 83 | $sform->addElement(new XoopsFormHidden('list_id', $item->getVar('list_id'))); |
||
| 84 | $sform->addElement(new XoopsFormText(_AM_OLEDRION_TITLE, 'list_title', 50, 255, $item->getVar('list_title', 'e')), true); |
||
| 85 | //$sform->addElement(new XoopsFormText(_OLEDRION_LIST_PASSWORD, 'list_password', 50, 50, $item->getVar('list_password','e')), false); |
||
| 86 | $selectTypes = Oledrion_lists::getTypesArray(); |
||
| 87 | $selectType = new XoopsFormSelect(_OLEDRION_LIST_TYPE, 'list_type', $item->getVar('list_type', 'e')); |
||
| 88 | $selectType->addOptionArray($selectTypes); |
||
| 89 | $sform->addElement($selectType, true); |
||
| 90 | $sform->addElement(new XoopsFormTextArea(_OLEDRION_DESCRIPTION, 'list_description', $item->getVar('list_description', 'e'), 7, 60), false); |
||
| 91 | $listProducts = array(); |
||
| 92 | if ($edit) { |
||
| 93 | $listProducts = $handlers->h_oledrion_lists->getListProducts($item); |
||
| 94 | if (count($listProducts) > 0) { |
||
| 95 | $productsTray = new XoopsFormElementTray(_OLEDRION_PROD_IN_THIS_LIST, '<br>'); |
||
| 96 | $productsTray->addElement(new XoopsFormLabel(_OLEDRION_CHECK_PRODUCTS), false); |
||
| 97 | foreach ($listProducts as $product) { |
||
| 98 | $caption = "<a target='_blank' href='" . $product->getLink() . "'>" . $product->getVar('product_title') . '</a>'; |
||
| 99 | $checkbox = new XoopsFormCheckBox($caption, 'productsList[]'); |
||
| 100 | $checkbox->addOption($product->getVar('product_id'), _DELETE); |
||
| 101 | $productsTray->addElement($checkbox); |
||
| 102 | unset($caption, $checkbox); |
||
| 103 | } |
||
| 104 | $sform->addElement($productsTray, false); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | if ($product_id > 0) { |
||
| 108 | $product = null; |
||
| 109 | $product = $handlers->h_oledrion_products->get($product_id); |
||
| 110 | if (is_object($product) && $product->isProductVisible()) { |
||
| 111 | $content = "<a target='_blank' href='" . $product->getLink() . "'>" . $product->getVar('product_title') . '</a>'; |
||
| 112 | $sform->addElement(new XoopsFormLabel(_OLEDRION_PRODUCT_DO_ADD, $content)); |
||
| 113 | $sform->addElement(new XoopsFormHidden('product_id', $product_id)); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $button_tray = new XoopsFormElementTray('', ''); |
||
| 117 | $submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
||
| 118 | $button_tray->addElement($submit_btn); |
||
| 119 | $sform->addElement($button_tray); |
||
| 120 | |||
| 121 | $sform =& OledrionUtility::formMarkRequiredFields($sform); |
||
| 122 | |||
| 123 | return $sform; |
||
| 124 | } |
||
| 125 | |||
| 126 | switch ($op) { |
||
| 127 | // ************************************************************************ |
||
| 128 | case 'default': // Liste de toutes les listes de l'utilisateur ************ |
||
| 129 | // ************************************************************************ |
||
| 130 | $xoopsTpl->assign('op', $op); |
||
| 131 | $lists = array(); |
||
| 132 | $start = $limit = 0; |
||
| 133 | $idAsKey = true; |
||
| 134 | $lists = $handlers->h_oledrion_lists->getRecentLists(new Oledrion_parameters(array( |
||
| 135 | 'start' => $start, |
||
| 136 | 'limit' => $limit, |
||
| 137 | 'sort' => 'list_title', |
||
| 138 | 'order' => 'ASC', |
||
| 139 | 'idAsKey' => $idAsKey, |
||
| 140 | 'listType' => OLEDRION_LISTS_ALL, |
||
| 141 | 'list_uid' => $uid |
||
| 142 | ))); |
||
| 143 | if (count($lists) > 0) { |
||
| 144 | foreach ($lists as $list) { |
||
| 145 | $xoopsTpl->append('lists', $list->toArray()); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | $breadcrumb = array( |
||
| 149 | OLEDRION_URL . 'all-lists.php' => _MI_OLEDRION_SMNAME11, |
||
| 150 | OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME10 |
||
| 151 | ); |
||
| 152 | break; |
||
| 153 | |||
| 154 | // ************************************************************************ |
||
| 155 | case 'addProduct': // Ajout d'un produit à une liste ********************* |
||
| 156 | // ************************************************************************ |
||
| 157 | $xoopsTpl->assign('op', $op); |
||
| 158 | $product_id = isset($_GET['product_id']) ? (int)$_GET['product_id'] : 0; |
||
| 159 | if ($product_id == 0) { |
||
| 160 | OledrionUtility::redirect(_OLEDRION_ERROR14, $baseurl, 4); |
||
| 161 | } |
||
| 162 | $userListsCount = $handlers->h_oledrion_lists->getRecentListsCount(OLEDRION_LISTS_ALL, $uid); |
||
| 163 | $xoopsTpl->assign('userListsCount', $userListsCount); |
||
| 164 | $xoopsTpl->assign('product_id', $product_id); |
||
| 165 | if ($userListsCount > 0) { |
||
| 166 | $userLists = $handlers->h_oledrion_lists->getRecentLists(new Oledrion_parameters(array( |
||
| 167 | 'start' => 0, |
||
| 168 | 'limit' => 0, |
||
| 169 | 'sort' => 'list_title', |
||
| 170 | 'order' => 'ASC', |
||
| 171 | 'idAsKey' => true, |
||
| 172 | 'listType' => OLEDRION_LISTS_ALL, |
||
| 173 | 'list_uid' => $uid |
||
| 174 | ))); |
||
| 175 | foreach ($userLists as $list) { |
||
| 176 | $xoopsTpl->append('lists', $list->toArray()); |
||
| 177 | } |
||
| 178 | $breadcrumb = array( |
||
| 179 | OLEDRION_URL . 'all-lists.php' => _MI_OLEDRION_SMNAME11, |
||
| 180 | OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME10, |
||
| 181 | OLEDRION_URL => _OLEDRION_ADD_PRODUCT_LIST |
||
| 182 | ); |
||
| 183 | $product = null; |
||
| 184 | $product = $handlers->h_oledrion_products->get($product_id); |
||
| 185 | View Code Duplication | if (is_object($product) && $product->isProductVisible()) { |
|
| 186 | $xoopsTpl->assign('product', $product->toArray()); |
||
| 187 | } else { |
||
| 188 | OledrionUtility::redirect(_OLEDRION_ERROR1, $baseurl, 4); |
||
| 189 | } |
||
| 190 | } else { |
||
| 191 | $sform = listForm('addList', $product_id); |
||
| 192 | $title = _OLEDRION_ADD_LIST; |
||
| 193 | $breadcrumb = array( |
||
| 194 | OLEDRION_URL . 'all-lists.php' => _MI_OLEDRION_SMNAME11, |
||
| 195 | OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME10, |
||
| 196 | OLEDRION_URL => $title |
||
| 197 | ); |
||
| 198 | $xoopsTpl->assign('form', $sform->render()); |
||
| 199 | } |
||
| 200 | break; |
||
| 201 | |||
| 202 | // ************************************************************************ |
||
| 203 | case 'addProductToList': // Ajout d'un produit à une liste, sélection de la liste |
||
| 204 | // ************************************************************************ |
||
| 205 | $xoopsTpl->assign('op', $op); |
||
| 206 | $product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : 0; |
||
| 207 | if ($product_id == 0) { |
||
| 208 | OledrionUtility::redirect(_OLEDRION_ERROR14, $baseurl, 4); |
||
| 209 | } |
||
| 210 | $product = null; |
||
| 211 | $product = $handlers->h_oledrion_products->get($product_id); |
||
| 212 | View Code Duplication | if (is_object($product) && $product->isProductVisible()) { |
|
| 213 | $xoopsTpl->assign('product', $product->toArray()); |
||
| 214 | } else { |
||
| 215 | OledrionUtility::redirect(_OLEDRION_ERROR1, $baseurl, 4); |
||
| 216 | } |
||
| 217 | |||
| 218 | $list_id = isset($_POST['list_id']) ? (int)$_POST['list_id'] : 0; |
||
| 219 | if ($list_id == 0) { // Ajouter à une nouvelle liste |
||
| 220 | $sform = listForm('addList', $product_id); |
||
| 221 | $title = _OLEDRION_ADD_LIST; |
||
| 222 | $breadcrumb = array( |
||
| 223 | OLEDRION_URL . 'all-lists.php' => _MI_OLEDRION_SMNAME11, |
||
| 224 | OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME10, |
||
| 225 | OLEDRION_URL => $title |
||
| 226 | ); |
||
| 227 | $xoopsTpl->assign('form', $sform->render()); |
||
| 228 | $xoopsTpl->assign('op', 'addList'); |
||
| 229 | } else { // Ajouter à une liste existante |
||
| 230 | if (!$handlers->h_oledrion_lists->isThisMyList($list_id)) { |
||
| 231 | OledrionUtility::redirect(_OLEDRION_ERROR25, $baseurl, 8); |
||
| 232 | } |
||
| 233 | if ($handlers->h_oledrion_products_list->isProductAlreadyInList($list_id, $product_id)) { |
||
| 234 | OledrionUtility::redirect(_OLEDRION_ERROR26, $baseurl . '?op=addProduct&product_id=' . $product_id, 4); |
||
| 235 | } else { |
||
| 236 | $res = $handlers->h_oledrion_products_list->addProductToUserList($list_id, $product_id); |
||
| 237 | if ($res) { |
||
| 238 | $list = null; |
||
| 239 | $list = $handlers->h_oledrion_lists->get($list_id); |
||
| 240 | if (is_object($list)) { |
||
| 241 | $handlers->h_oledrion_lists->incrementListProductsCount($list); |
||
| 242 | } |
||
| 243 | OledrionUtility::updateCache(); |
||
| 244 | OledrionUtility::redirect(_OLEDRION_PRODUCT_LIST_ADD_OK, $product->getLink(), 2); |
||
| 245 | } else { |
||
| 246 | OledrionUtility::redirect(_OLEDRION_ERROR27, $product->getLink(), 4); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | break; |
||
| 251 | |||
| 252 | // ************************************************************************ |
||
| 253 | case 'delete': // Suppression d'une liste ******************************** |
||
| 254 | // ************************************************************************ |
||
| 255 | $xoopsTpl->assign('op', $op); |
||
| 256 | $list_id = isset($_GET['list_id']) ? (int)$_GET['list_id'] : 0; |
||
| 257 | if ($list_id == 0) { |
||
| 258 | OledrionUtility::redirect(_OLEDRION_ERROR21, $baseurl, 4); |
||
| 259 | } |
||
| 260 | // Vérification, est-ce que l'utilisateur courant est bien le propriétaire de cette liste ? |
||
| 261 | if (!$handlers->h_oledrion_lists->isThisMyList($list_id)) { |
||
| 262 | OledrionUtility::redirect(_OLEDRION_ERROR25, $baseurl, 8); |
||
| 263 | } |
||
| 264 | $item = $handlers->h_oledrion_lists->get($list_id); |
||
| 265 | if (!is_object($item)) { |
||
| 266 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 267 | } |
||
| 268 | xoops_confirm(array('op' => 'reallyDelete', 'list_id' => $list_id), $baseurl, _OLEDRION_DELETE_LIST . '<br>' . $item->getVar('list_title')); |
||
| 269 | break; |
||
| 270 | |||
| 271 | // ************************************************************************ |
||
| 272 | case 'reallyDelete': // Suppression effective d'une liste ************** |
||
| 273 | // ************************************************************************ |
||
| 274 | $list_id = isset($_POST['list_id']) ? (int)$_POST['list_id'] : 0; |
||
| 275 | if ($list_id == 0) { |
||
| 276 | OledrionUtility::redirect(_OLEDRION_ERROR21, $baseurl, 4); |
||
| 277 | } |
||
| 278 | // Vérification, est-ce que l'utilisateur courant est bien le propriétaire de cette liste ? |
||
| 279 | if (!$handlers->h_oledrion_lists->isThisMyList($list_id)) { |
||
| 280 | OledrionUtility::redirect(_OLEDRION_ERROR25, $baseurl, 8); |
||
| 281 | } |
||
| 282 | $item = $handlers->h_oledrion_lists->get($list_id); |
||
| 283 | if (!is_object($item)) { |
||
| 284 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 285 | } |
||
| 286 | if ($handlers->h_oledrion_lists->deleteList($item)) { |
||
| 287 | OledrionUtility::updateCache(); |
||
| 288 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl, 2); |
||
| 289 | } else { |
||
| 290 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl, 5); |
||
| 291 | } |
||
| 292 | break; |
||
| 293 | |||
| 294 | // ************************************************************************ |
||
| 295 | case 'save': // Sauvegarde d'une liste ********************************* |
||
| 296 | // ************************************************************************ |
||
| 297 | $list_id = isset($_POST['list_id']) ? (int)$_POST['list_id'] : 0; |
||
| 298 | if (!empty($list_id)) { |
||
| 299 | // Vérification, est-ce que l'utilisateur courant est bien le propriétaire de cette liste ? |
||
| 300 | if (!$handlers->h_oledrion_lists->isThisMyList($list_id)) { |
||
| 301 | OledrionUtility::redirect(_OLEDRION_ERROR25, $baseurl, 8); |
||
| 302 | } |
||
| 303 | $edit = true; |
||
| 304 | $item = $handlers->h_oledrion_lists->get($list_id); |
||
| 305 | if (!is_object($item)) { |
||
| 306 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 307 | } |
||
| 308 | $item->unsetNew(); |
||
| 309 | $edit = true; |
||
| 310 | } else { |
||
| 311 | $item = $handlers->h_oledrion_lists->create(true); |
||
| 312 | $edit = false; |
||
| 313 | } |
||
| 314 | // Contrôle sur le titre |
||
| 315 | if (!isset($_POST['list_title']) || (isset($_POST['list_title']) && xoops_trim($_POST['list_title']) == '')) { |
||
| 316 | OledrionUtility::redirect(_OLEDRION_ERROR24, $baseurl, 5); |
||
| 317 | } |
||
| 318 | $item->setVars($_POST); |
||
| 319 | if (!$edit) { |
||
| 320 | $item->setVar('list_date', time()); |
||
| 321 | $item->setVar('list_uid', $uid); |
||
| 322 | } |
||
| 323 | if (isset($_POST['productsList'])) { |
||
| 324 | $productsDeletedCount = 0; |
||
| 325 | foreach ($_POST['productsList'] as $productId) { |
||
| 326 | $res = $handlers->h_oledrion_products_list->deleteProductFromList($list_id, (int)$productId); |
||
| 327 | if ($res) { |
||
| 328 | ++$productsDeletedCount; |
||
| 329 | } |
||
| 330 | } |
||
| 331 | if ($productsDeletedCount > 0) { |
||
| 332 | $handlers->h_oledrion_products_list->decrementListProductsCount($productsDeletedCount); |
||
| 333 | } |
||
| 334 | } |
||
| 335 | $res = $handlers->h_oledrion_lists->insert($item); |
||
| 336 | if ($res) { |
||
| 337 | if (isset($_POST['product_id'])) { |
||
| 338 | $product_id = (int)$_POST['product_id']; |
||
| 339 | if ($product_id > 0) { |
||
| 340 | $product = null; |
||
| 341 | $product = $handlers->h_oledrion_products->get($product_id); |
||
| 342 | if (is_object($product) |
||
| 343 | && $product->isProductVisible()) { // On peut ajouter le produit à cette nouvelle liste |
||
| 344 | $res = $handlers->h_oledrion_products_list->addProductToUserList($item->getVar('list_id'), $product_id); |
||
| 345 | if ($res) { // Mise à jour du nombre de produits de la liste |
||
| 346 | $handlers->h_oledrion_lists->incrementListProductsCount($item); |
||
| 347 | OledrionUtility::updateCache(); |
||
| 348 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $product->getLink(), 2); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
||
| 352 | } |
||
| 353 | OledrionUtility::updateCache(); |
||
| 354 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl, 2); |
||
| 355 | } else { |
||
| 356 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl, 5); |
||
| 357 | } |
||
| 358 | break; |
||
| 359 | |||
| 360 | // ************************************************************************ |
||
| 361 | case 'edit': // Edition d'une liste *************************************** |
||
| 362 | case 'addList': // Ajout d'une liste ************************************** |
||
| 363 | // ************************************************************************ |
||
| 364 | $xoopsTpl->assign('op', $op); |
||
| 365 | $sform = listForm($op, 0); |
||
| 366 | if ($op === 'edit') { |
||
| 367 | $title = _OLEDRION_EDIT_LIST; |
||
| 368 | } else { |
||
| 369 | $title = _OLEDRION_ADD_LIST; |
||
| 370 | } |
||
| 371 | $breadcrumb = array( |
||
| 372 | OLEDRION_URL . 'all-lists.php' => _MI_OLEDRION_SMNAME11, |
||
| 373 | OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME10, |
||
| 374 | OLEDRION_URL => $title |
||
| 375 | ); |
||
| 376 | |||
| 377 | $xoopsTpl->assign('form', $sform->render()); |
||
| 378 | break; |
||
| 379 | } |
||
| 380 | |||
| 381 | OledrionUtility::setCSS(); |
||
| 382 | OledrionUtility::setLocalCSS($xoopsConfig['language']); |
||
| 383 | |||
| 384 | $xoopsTpl->assign('mod_pref', $mod_pref); |
||
| 385 | $xoopsTpl->assign('breadcrumb', OledrionUtility::breadcrumb($breadcrumb)); |
||
|
0 ignored issues
–
show
|
|||
| 386 | |||
| 387 | $title = _MI_OLEDRION_SMNAME10 . ' - ' . OledrionUtility::getModuleName(); |
||
| 388 | OledrionUtility::setMetas($title, $title); |
||
| 389 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 390 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.