mambax7 /
adslight
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | /* |
||||
| 6 | You may not change or alter any portion of this comment or credits |
||||
| 7 | of supporting developers from this source code or any supporting source code |
||||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||
| 9 | |||||
| 10 | This program is distributed in the hope that it will be useful, |
||||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
| 13 | */ |
||||
| 14 | |||||
| 15 | /** |
||||
| 16 | * Module: Adslight |
||||
| 17 | * |
||||
| 18 | * @category Module |
||||
| 19 | * @author XOOPS Development Team <https://xoops.org> |
||||
| 20 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||||
| 21 | * @license GPL 2.0 or later |
||||
| 22 | */ |
||||
| 23 | |||||
| 24 | use Xmf\Module\Admin; |
||||
| 25 | use Xmf\Request; |
||||
| 26 | use XoopsModules\Adslight\{ |
||||
| 27 | Helper, |
||||
| 28 | Utility |
||||
| 29 | }; |
||||
| 30 | |||||
| 31 | global $xoopsModule, $xoopsDB, $xoopsConfig, $xoTheme; |
||||
| 32 | |||||
| 33 | require __DIR__ . '/admin_header.php'; |
||||
| 34 | xoops_cp_header(); |
||||
| 35 | //It recovered the value of argument op in URL$ |
||||
| 36 | /** @var XoopsModules\Adslight\Helper $helper */ |
||||
| 37 | $helper = Helper::getInstance(); |
||||
| 38 | /** @var \XoopsModules\Adslight\Utility $utility */ |
||||
| 39 | $utility = new Utility(); |
||||
| 40 | /** @var Xmf\Module\Admin $adminObject */ |
||||
| 41 | $adminObject = Admin::getInstance(); |
||||
| 42 | $op = Request::getString('op', 'list'); |
||||
| 43 | $order = Request::getString('order', 'desc'); |
||||
| 44 | $sort = Request::getString('sort', ''); |
||||
| 45 | |||||
| 46 | $moduleDirName = \basename(\dirname(__DIR__)); |
||||
| 47 | $GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName); |
||||
| 48 | $xoTheme->addStylesheet($helper->url('assets/js/tablesorter/css/theme.blue.css')); |
||||
| 49 | |||||
| 50 | $adminObject->displayNavigation(basename(__FILE__)); |
||||
| 51 | $permHelper = new \Xmf\Module\Helper\Permission(); |
||||
| 52 | $uploadDir = XOOPS_UPLOAD_PATH . "/$moduleDirName/categories/"; |
||||
| 53 | $uploadUrl = XOOPS_UPLOAD_URL . "/$moduleDirName/categories/"; |
||||
| 54 | /** @var \XoopsPersistableObjectHandler $categoriesHandler */ |
||||
| 55 | $categoriesHandler = $helper->getHandler('Categories'); |
||||
| 56 | |||||
| 57 | switch ($op) { |
||||
| 58 | case 'new': |
||||
| 59 | $adminObject->addItemButton(AM_ADSLIGHT_CATEGORIES_LIST, 'categories.php', 'list'); |
||||
| 60 | $adminObject->displayButton('left'); |
||||
| 61 | |||||
| 62 | /** @var \XoopsModules\Adslight\Categories $categoriesObject */ |
||||
| 63 | $categoriesObject = $categoriesHandler->create(); |
||||
| 64 | $form = $categoriesObject->getForm(); |
||||
| 65 | $form->display(); |
||||
| 66 | break; |
||||
| 67 | |||||
| 68 | case 'save': |
||||
| 69 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
| 70 | redirect_header('categories.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||
| 71 | } |
||||
| 72 | if (0 !== Request::getInt('cid', 0)) { |
||||
| 73 | $categoriesObject = $categoriesHandler->get(Request::getInt('cid', 0)); |
||||
| 74 | } else { |
||||
| 75 | $categoriesObject = $categoriesHandler->create(); |
||||
| 76 | } |
||||
| 77 | // Form save fields |
||||
| 78 | $categoriesObject->setVar('pid', Request::getVar('pid', '')); |
||||
| 79 | $categoriesObject->setVar('title', Request::getVar('title', '')); |
||||
| 80 | $categoriesObject->setVar('cat_desc', Request::getText('cat_desc', '')); |
||||
| 81 | $categoriesObject->setVar('cat_keywords', Request::getVar('cat_keywords', '')); |
||||
| 82 | |||||
| 83 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||||
| 84 | $uploadDir = XOOPS_UPLOAD_PATH . '/adslight/categories/'; |
||||
| 85 | $uploader = new \XoopsMediaUploader( |
||||
| 86 | $uploadDir, $helper->getConfig('mimetypes'), $helper->getConfig('maxsize'), null, null |
||||
| 87 | ); |
||||
| 88 | if ($uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0])) { |
||||
| 89 | //$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , $_FILES['attachedfile']['name']); |
||||
| 90 | //$imgName = str_replace(' ', '', $_POST['img']).'.'.$extension; |
||||
| 91 | |||||
| 92 | $uploader->setPrefix('img_'); |
||||
| 93 | $uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0]); |
||||
| 94 | if (!$uploader->upload()) { |
||||
| 95 | $errors = $uploader->getErrors(); |
||||
| 96 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||
| 97 | } else { |
||||
| 98 | $categoriesObject->setVar('img', $uploader->getSavedFileName()); |
||||
| 99 | } |
||||
| 100 | } else { |
||||
| 101 | $categoriesObject->setVar('img', Request::getVar('img', '')); |
||||
| 102 | } |
||||
| 103 | |||||
| 104 | $categoriesObject->setVar('cat_order', Request::getVar('cat_order', '')); |
||||
| 105 | $categoriesObject->setVar('affprice', Request::getVar('affprice', '')); |
||||
| 106 | $categoriesObject->setVar('cat_moderate', Request::getVar('cat_moderate', '')); |
||||
| 107 | $categoriesObject->setVar('moderate_subcat', Request::getVar('moderate_subcat', '')); |
||||
| 108 | if ($categoriesHandler->insert($categoriesObject)) { |
||||
| 109 | redirect_header('categories.php?op=list', 2, AM_ADSLIGHT_FORMOK); |
||||
| 110 | } |
||||
| 111 | |||||
| 112 | echo $categoriesObject->getHtmlErrors(); |
||||
| 113 | $form = $categoriesObject->getForm(); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 114 | $form->display(); |
||||
| 115 | break; |
||||
| 116 | |||||
| 117 | case 'edit': |
||||
| 118 | $adminObject->addItemButton(AM_ADSLIGHT_ADD_CATEGORIES, 'categories.php?op=new', 'add'); |
||||
| 119 | $adminObject->addItemButton(AM_ADSLIGHT_CATEGORIES_LIST, 'categories.php', 'list'); |
||||
| 120 | $adminObject->displayButton('left'); |
||||
| 121 | $categoriesObject = $categoriesHandler->get(Request::getString('cid', '')); |
||||
| 122 | $form = $categoriesObject->getForm(); |
||||
| 123 | $form->display(); |
||||
| 124 | break; |
||||
| 125 | |||||
| 126 | case 'delete': |
||||
| 127 | $categoriesObject = $categoriesHandler->get(Request::getString('cid', '')); |
||||
| 128 | if (1 == Request::getInt('ok', 0)) { |
||||
| 129 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
| 130 | redirect_header('categories.php', 3, implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
||||
| 131 | } |
||||
| 132 | if ($categoriesHandler->delete($categoriesObject)) { |
||||
| 133 | redirect_header('categories.php', 3, AM_ADSLIGHT_FORMDELOK); |
||||
| 134 | } else { |
||||
| 135 | echo $categoriesObject->getHtmlErrors(); |
||||
| 136 | } |
||||
| 137 | } else { |
||||
| 138 | xoops_confirm(['ok' => 1, 'cid' => Request::getString('cid', ''), 'op' => 'delete',], Request::getUrl('REQUEST_URI', '', 'SERVER'), sprintf(AM_ADSLIGHT_FORMSUREDEL, $categoriesObject->getVar('title'))); |
||||
|
0 ignored issues
–
show
It seems like
$categoriesObject->getVar('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...
|
|||||
| 139 | } |
||||
| 140 | break; |
||||
| 141 | |||||
| 142 | case 'clone': |
||||
| 143 | |||||
| 144 | $id_field = Request::getString('cid', ''); |
||||
| 145 | |||||
| 146 | if ($utility::cloneRecord('adslight_categories', 'cid', $id_field)) { |
||||
|
0 ignored issues
–
show
$id_field of type string is incompatible with the type integer expected by parameter $id of XoopsModules\Adslight\Co...sUtility::cloneRecord().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 147 | redirect_header('categories.php', 3, AM_ADSLIGHT_CLONED_OK); |
||||
| 148 | } else { |
||||
| 149 | redirect_header('categories.php', 3, AM_ADSLIGHT_CLONED_FAILED); |
||||
| 150 | } |
||||
| 151 | |||||
| 152 | break; |
||||
| 153 | case 'list': |
||||
| 154 | default: |
||||
| 155 | $adminObject->addItemButton(AM_ADSLIGHT_ADD_CATEGORIES, 'categories.php?op=new', 'add'); |
||||
| 156 | $adminObject->displayButton('left'); |
||||
| 157 | $start = Request::getInt('start', 0); |
||||
| 158 | $categoriesPaginationLimit = $helper->getConfig('userpager'); |
||||
| 159 | |||||
| 160 | $criteria = new \CriteriaCompo(); |
||||
| 161 | $criteria->setSort('cid ASC, title'); |
||||
| 162 | $criteria->setOrder('ASC'); |
||||
| 163 | $criteria->setLimit($categoriesPaginationLimit); |
||||
| 164 | $criteria->setStart($start); |
||||
| 165 | $categoriesTempRows = $categoriesHandler->getCount(); |
||||
| 166 | $categoriesTempArray = $categoriesHandler->getAll($criteria); |
||||
| 167 | /* |
||||
| 168 | // |
||||
| 169 | // |
||||
| 170 | <th class='center width5'>".AM_ADSLIGHT_FORM_ACTION."</th> |
||||
| 171 | // </tr>"; |
||||
| 172 | // $class = "odd"; |
||||
| 173 | */ |
||||
| 174 | |||||
| 175 | // // Creating the objects for top categories |
||||
| 176 | // $categoriesObj = $helper->getHandler('Categories')->getCategories($helper->getConfig('idxcat_perpage'), $startcategory, 0); |
||||
| 177 | // |
||||
| 178 | // echo '</tr>'; |
||||
| 179 | // /** @var \XoopsPersistableObjectHandler $categoriesHandler */ |
||||
| 180 | // $totalCategories = $categoriesHandler->getCount(); |
||||
| 181 | // |
||||
| 182 | //// $totalCategories2 = $helper->getHandler('Categories')->getCategoriesCount(0); |
||||
| 183 | // |
||||
| 184 | // if (is_array($categoriesObject) && count($categoriesObject) > 0) { |
||||
| 185 | // foreach ($categoriesObject as $key => $thiscat) { |
||||
| 186 | // Utility::displayCategory($thiscat); |
||||
| 187 | // } |
||||
| 188 | // unset($key); |
||||
| 189 | // } else { |
||||
| 190 | // echo '<tr>'; |
||||
| 191 | // echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOCAT . '</td>'; |
||||
| 192 | // echo '</tr>'; |
||||
| 193 | // $categoryId = '0'; |
||||
| 194 | // } |
||||
| 195 | |||||
| 196 | // Display Page Navigation |
||||
| 197 | if ($categoriesTempRows > $categoriesPaginationLimit) { |
||||
| 198 | xoops_load('XoopsPageNav'); |
||||
| 199 | |||||
| 200 | $pagenav = new \XoopsPageNav( |
||||
| 201 | $categoriesTempRows, $categoriesPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . '' |
||||
| 202 | ); |
||||
| 203 | $GLOBALS['xoopsTpl']->assign('pagenav', null === $pagenav ? $pagenav->renderNav() : ''); |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | $GLOBALS['xoopsTpl']->assign('categoriesRows', $categoriesTempRows); |
||||
| 207 | $categoriesArray = []; |
||||
| 208 | |||||
| 209 | // $fields = explode('|', cid:int:11::NOT NULL::primary:ID:0|pid:int:5:unsigned:NOT NULL:0::Parent:1|title:varchar:50::NOT NULL:::Title:2|cat_desc:text:200::NOT NULL:::Desc:3|cat_keywords:varchar:1000::NOT NULL:::Keywords:4|img:varchar:150::NOT NULL:default.png::Image:5|cat_order:int:5::NOT NULL:0::Order:6|affprice:int:5::NOT NULL:1::Price:7|cat_moderate:int:5::NOT NULL:1::CatModerator:8|moderate_subcat:int:5::NOT NULL:1::SubcatModerator:9); |
||||
| 210 | // $fieldsCount = count($fields); |
||||
| 211 | |||||
| 212 | $criteria = new \CriteriaCompo(); |
||||
| 213 | |||||
| 214 | //$criteria->setOrder('DESC'); |
||||
| 215 | $criteria->setSort($sort); |
||||
| 216 | $criteria->setOrder($order); |
||||
| 217 | $criteria->setLimit($categoriesPaginationLimit); |
||||
| 218 | $criteria->setStart($start); |
||||
| 219 | |||||
| 220 | $categoriesCount = $categoriesHandler->getCount($criteria); |
||||
| 221 | $categoriesTempArray = $categoriesHandler->getAll($criteria); |
||||
| 222 | |||||
| 223 | // for ($i = 0; $i < $fieldsCount; ++$i) { |
||||
| 224 | if ($categoriesCount > 0) { |
||||
| 225 | foreach (array_keys($categoriesTempArray) as $i) { |
||||
| 226 | // $field = explode(':', $fields[$i]); |
||||
| 227 | |||||
| 228 | $GLOBALS['xoopsTpl']->assign('selectorcid', AM_ADSLIGHT_CATEGORIES_CID); |
||||
| 229 | $categoriesArray['cid'] = $categoriesTempArray[$i]->getVar('cid'); |
||||
| 230 | |||||
| 231 | $GLOBALS['xoopsTpl']->assign('selectorpid', AM_ADSLIGHT_CATEGORIES_PID); |
||||
| 232 | $categoriesArray['pid'] = $categoriesTempArray[$i]->getVar('pid'); |
||||
| 233 | |||||
| 234 | $GLOBALS['xoopsTpl']->assign('selectortitle', AM_ADSLIGHT_CATEGORIES_TITLE); |
||||
| 235 | $categoriesArray['title'] = $categoriesTempArray[$i]->getVar('title'); |
||||
| 236 | |||||
| 237 | $GLOBALS['xoopsTpl']->assign('selectorcat_desc', AM_ADSLIGHT_CATEGORIES_CAT_DESC); |
||||
| 238 | $categoriesArray['cat_desc'] = $categoriesTempArray[$i]->getVar('cat_desc'); |
||||
| 239 | |||||
| 240 | $GLOBALS['xoopsTpl']->assign('selectorcat_keywords', AM_ADSLIGHT_CATEGORIES_CAT_KEYWORDS); |
||||
| 241 | $categoriesArray['cat_keywords'] = $categoriesTempArray[$i]->getVar('cat_keywords'); |
||||
| 242 | |||||
| 243 | $GLOBALS['xoopsTpl']->assign('selectorimg', AM_ADSLIGHT_CATEGORIES_IMG); |
||||
| 244 | $categoriesArray['img'] = "<img src='" . $uploadUrl . $categoriesTempArray[$i]->getVar('img') . "' name='" . 'name' . "' id=" . 'id' . " alt='' style='max-width:100px'>"; |
||||
| 245 | |||||
| 246 | $GLOBALS['xoopsTpl']->assign('selectorcat_order', AM_ADSLIGHT_CATEGORIES_CAT_ORDER); |
||||
| 247 | $categoriesArray['cat_order'] = $categoriesTempArray[$i]->getVar('cat_order'); |
||||
| 248 | |||||
| 249 | $GLOBALS['xoopsTpl']->assign('selectoraffprice', AM_ADSLIGHT_CATEGORIES_AFFPRICE); |
||||
| 250 | $categoriesArray['affprice'] = $categoriesTempArray[$i]->getVar('affprice'); |
||||
| 251 | |||||
| 252 | $GLOBALS['xoopsTpl']->assign('selectorcat_moderate', AM_ADSLIGHT_CATEGORIES_CAT_MODERATE); |
||||
| 253 | $categoriesArray['cat_moderate'] = strip_tags(\XoopsUser::getUnameFromId($categoriesTempArray[$i]->getVar('cat_moderate'))); |
||||
| 254 | |||||
| 255 | $pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16'); |
||||
| 256 | $GLOBALS['xoopsTpl']->assign('selectormoderate_subcat', AM_ADSLIGHT_CATEGORIES_MODERATE_SUBCAT); |
||||
| 257 | $categoriesArray['moderate_subcat'] = strip_tags(\XoopsUser::getUnameFromId($categoriesTempArray[$i]->getVar('moderate_subcat'))); |
||||
| 258 | $categoriesArray['edit_delete'] = "<a href='categories.php?op=edit&cid=" . $i . "'><img src=" . $pathIcon16 . "/edit.png alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
||||
| 259 | <a href='categories.php?op=delete&cid=" . $i . "'><img src=" . $pathIcon16 . "/delete.png alt='" . _DELETE . "' title='" . _DELETE . "'></a> |
||||
| 260 | <a href='categories.php?op=clone&cid=" . $i . "'><img src=" . $pathIcon16 . "/editcopy.png alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
||||
| 261 | |||||
| 262 | $GLOBALS['xoopsTpl']->append_by_ref('categoriesArrays', $categoriesArray); |
||||
| 263 | unset($categoriesArray); |
||||
| 264 | } |
||||
| 265 | unset($categoriesTempArray); |
||||
| 266 | // Display Navigation |
||||
| 267 | if ($categoriesCount > $categoriesPaginationLimit) { |
||||
| 268 | xoops_load('XoopsPageNav'); |
||||
| 269 | $pagenav = new \XoopsPageNav( |
||||
| 270 | $categoriesCount, $categoriesPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . '' |
||||
| 271 | ); |
||||
| 272 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
||||
| 273 | } |
||||
| 274 | |||||
| 275 | // echo "<td class='center width5'> |
||||
| 276 | |||||
| 277 | // <a href='categories.php?op=edit&cid=".$i."'><img src=".$pathIcon16."/edit.png alt='"._EDIT."' title='"._EDIT."'></a> |
||||
| 278 | // <a href='categories.php?op=delete&cid=".$i."'><img src=".$pathIcon16."/delete.png alt='"._DELETE."' title='"._DELETE."'></a> |
||||
| 279 | // </td>"; |
||||
| 280 | |||||
| 281 | // echo "</tr>"; |
||||
| 282 | |||||
| 283 | // } |
||||
| 284 | |||||
| 285 | // echo "</table><br><br>"; |
||||
| 286 | |||||
| 287 | // } else { |
||||
| 288 | |||||
| 289 | // echo "<table width='100%' cellspacing='1' class='outer'> |
||||
| 290 | |||||
| 291 | // <tr> |
||||
| 292 | |||||
| 293 | // <th class='center width5'>".AM_ADSLIGHT_FORM_ACTION."XXX</th> |
||||
| 294 | // </tr><tr><td class='errorMsg' colspan='11'>There are noXXX categories</td></tr>"; |
||||
| 295 | // echo "</table><br><br>"; |
||||
| 296 | |||||
| 297 | //------------------------------------------- |
||||
| 298 | |||||
| 299 | echo $GLOBALS['xoopsTpl']->fetch( |
||||
| 300 | XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . '/templates/admin/adslight_admin_categories.tpl' |
||||
| 301 | ); |
||||
| 302 | } |
||||
| 303 | |||||
| 304 | break; |
||||
| 305 | } |
||||
| 306 | |||||
| 307 | require __DIR__ . '/admin_footer.php'; |
||||
| 308 |