mambax7 /
smartfaq
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: SmartFAQ |
||
| 5 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 6 | * Licence: GNU |
||
| 7 | */ |
||
| 8 | |||
| 9 | include_once __DIR__ . '/admin_header.php'; |
||
| 10 | |||
| 11 | // Creating the category handler object |
||
| 12 | $categoryHandler = sf_gethandler('category'); |
||
| 13 | |||
| 14 | $op = ''; |
||
| 15 | |||
| 16 | if (isset($_GET['op'])) { |
||
| 17 | $op = $_GET['op']; |
||
| 18 | } |
||
| 19 | if (isset($_POST['op'])) { |
||
| 20 | $op = $_POST['op']; |
||
| 21 | } |
||
| 22 | |||
| 23 | // Where do we start? |
||
| 24 | $startcategory = isset($_GET['startcategory']) ? (int)$_GET['startcategory'] : 0; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param $categoryObj |
||
| 28 | * @param int $level |
||
| 29 | */ |
||
| 30 | function displayCategory($categoryObj, $level = 0) |
||
| 31 | { |
||
| 32 | global $xoopsModule, $categoryHandler, $pathIcon16; |
||
| 33 | $description = $categoryObj->description(); |
||
| 34 | View Code Duplication | if (!XOOPS_USE_MULTIBYTES) { |
|
| 35 | if (strlen($description) >= 100) { |
||
| 36 | $description = substr($description, 0, 100 - 1) . '...'; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | $modify = "<a href='category.php?op=mod&categoryid=" . $categoryObj->categoryid() . "'><img src='" . $pathIcon16 . '/edit.png' . "' title='" . _AM_SF_EDITCOL . "' alt='" . _AM_SF_EDITCOL . "' /></a>"; |
||
| 40 | $delete = "<a href='category.php?op=del&categoryid=" . $categoryObj->categoryid() . "'><img src='" . $pathIcon16 . '/delete.png' . "' title='" . _AM_SF_DELETECOL . "' alt='" . _AM_SF_DELETECOL . "' /></a>"; |
||
| 41 | |||
| 42 | $spaces = ''; |
||
| 43 | for ($j = 0; $j < $level; ++$j) { |
||
| 44 | $spaces .= ' '; |
||
| 45 | } |
||
| 46 | |||
| 47 | echo '<tr>'; |
||
| 48 | echo "<td class='even' align='lefet'>" . $spaces . "<a href='" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/category.php?categoryid=' . $categoryObj->categoryid() . "'><img src='" . XOOPS_URL . "/modules/smartfaq/assets/images/icon/subcat.gif' alt='' /> " . $categoryObj->name() . '</a></td>'; |
||
| 49 | echo "<td class='even' align='left'>" . $description . '</td>'; |
||
| 50 | echo "<td class='even' align='center'>" . $categoryObj->weight() . '</td>'; |
||
| 51 | echo "<td class='even' align='center'> $modify $delete </td>"; |
||
| 52 | echo '</tr>'; |
||
| 53 | $subCategoriesObj = $categoryHandler->getCategories(0, 0, $categoryObj->categoryid()); |
||
| 54 | if (count($subCategoriesObj) > 0) { |
||
| 55 | ++$level; |
||
| 56 | foreach ($subCategoriesObj as $key => $thiscat) { |
||
| 57 | displayCategory($thiscat, $level); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | unset($categoryObj); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param bool $showmenu |
||
| 65 | * @param int $categoryid |
||
| 66 | */ |
||
| 67 | function editcat($showmenu = false, $categoryid = 0) |
||
| 68 | { |
||
| 69 | //$moderators = array(); // just to define the variable |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 70 | //$allmods = array(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 71 | $startfaq = isset($_GET['startfaq']) ? (int)$_GET['startfaq'] : 0; |
||
| 72 | global $categoryHandler, $xoopsUser, $xoopsUser, $myts, $xoopsConfig, $xoopsDB, $modify, $xoopsModuleConfig, $xoopsModule, $_GET; |
||
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 73 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 74 | |||
| 75 | // Creating the faq handler object |
||
| 76 | $faqHandler = sf_gethandler('faq'); |
||
|
0 ignored issues
–
show
$faqHandler is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 77 | |||
| 78 | echo "<script type=\"text/javascript\" src=\"funcs.js\"></script>"; |
||
| 79 | echo '<style>'; |
||
| 80 | echo '<!-- '; |
||
| 81 | echo 'select { width: 130px; }'; |
||
| 82 | echo '-->'; |
||
| 83 | echo '</style>'; |
||
| 84 | // If there is a parameter, and the id exists, retrieve data: we're editing a category |
||
| 85 | if ($categoryid != 0) { |
||
| 86 | |||
| 87 | // Creating the category object for the selected category |
||
| 88 | $categoryObj = new sfCategory($categoryid); |
||
| 89 | |||
| 90 | echo "<br />\n"; |
||
| 91 | if ($categoryObj->notLoaded()) { |
||
| 92 | redirect_header('category.php', 1, _AM_SF_NOCOLTOEDIT); |
||
| 93 | } |
||
| 94 | sf_collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 95 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . _AM_SF_EDITCOL . '</h3>'; |
||
| 96 | echo "<div id='bottomtable'>"; |
||
| 97 | } else { |
||
| 98 | $categoryObj = $categoryHandler->create(); |
||
| 99 | echo "<br />\n"; |
||
| 100 | sf_collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 101 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . _AM_SF_CATEGORY_CREATE . '</h3>'; |
||
| 102 | echo "<div id='bottomtable'>"; |
||
| 103 | } |
||
| 104 | // Start category form |
||
| 105 | $sform = new XoopsThemeForm(_AM_SF_CATEGORY, 'op', xoops_getenv('PHP_SELF')); |
||
| 106 | $sform->setExtra('enctype="multipart/form-data"'); |
||
| 107 | |||
| 108 | // Name |
||
| 109 | $sform->addElement(new XoopsFormText(_AM_SF_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true); |
||
| 110 | |||
| 111 | // Parent Category |
||
| 112 | $mytree = new XoopsTree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid'); |
||
| 113 | ob_start(); |
||
| 114 | $mytree->makeMySelBox('name', 'weight', $categoryObj->parentid(), 1, 'parentid'); |
||
| 115 | |||
| 116 | //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 117 | $sform->addElement(new XoopsFormLabel(_AM_SF_PARENT_CATEGORY_EXP, ob_get_contents())); |
||
| 118 | ob_end_clean(); |
||
| 119 | |||
| 120 | /* $mytree = new XoopsTree($xoopsDB->prefix("smartfaq_categories"), "categoryid" , "parentid"); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 121 | ob_start(); |
||
| 122 | $sform->addElement(new XoopsFormHidden('categoryid', $categoryObj->categoryid())); |
||
| 123 | $mytree->makeMySelBox("name", "weight", $categoryObj->categoryid()); |
||
| 124 | $sform->addElement(new XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents())); |
||
| 125 | ob_end_clean(); |
||
| 126 | */ |
||
| 127 | |||
| 128 | // Decsription |
||
| 129 | $sform->addElement(new XoopsFormTextArea(_AM_SF_COLDESCRIPT, 'description', $categoryObj->description('e'), 7, 60)); |
||
| 130 | |||
| 131 | // Weight |
||
| 132 | $sform->addElement(new XoopsFormText(_AM_SF_COLPOSIT, 'weight', 4, 4, $categoryObj->weight())); |
||
| 133 | |||
| 134 | // READ PERMISSIONS |
||
| 135 | $memberHandler = xoops_getHandler('member'); |
||
| 136 | $group_list = $memberHandler->getGroupList(); |
||
| 137 | |||
| 138 | $groups_read_checkbox = new XoopsFormCheckBox(_AM_SF_PERMISSIONS_CAT_READ, 'groups_read[]', $categoryObj->getGroups_read()); |
||
| 139 | foreach ($group_list as $group_id => $group_name) { |
||
| 140 | if ($group_id != XOOPS_GROUP_ADMIN) { |
||
| 141 | $groups_read_checkbox->addOption($group_id, $group_name); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | $sform->addElement($groups_read_checkbox); |
||
| 145 | // Apply permissions on all faqs |
||
| 146 | $addapplyall_radio = new XoopsFormRadioYN(_AM_SF_PERMISSIONS_APPLY_ON_FAQS, 'applyall', 0, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . ''); |
||
| 147 | $sform->addElement($addapplyall_radio); |
||
| 148 | // MODERATORS |
||
| 149 | //$moderators_tray = new XoopsFormElementTray(_AM_SF_MODERATORS_DEF, ''); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 150 | |||
| 151 | $module_id = $xoopsModule->getVar('mid'); |
||
| 152 | |||
| 153 | /*$gpermHandler = xoops_getHandler('groupperm'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 154 | $mod_perms = $gpermHandler->getGroupIds('category_moderation', $categoryid, $module_id); |
||
| 155 | |||
| 156 | $moderators_select = new XoopsFormSelect('', 'moderators', $moderators, 5, true); |
||
| 157 | $moderators_tray->addElement($moderators_select); |
||
| 158 | |||
| 159 | $butt_mngmods = new XoopsFormButton('', '', 'Manage mods', 'button'); |
||
| 160 | $butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"'); |
||
| 161 | $moderators_tray->addElement($butt_mngmods); |
||
| 162 | |||
| 163 | $butt_delmod = new XoopsFormButton('', '', 'Delete mod', 'button'); |
||
| 164 | $butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"'); |
||
| 165 | $moderators_tray->addElement($butt_delmod); |
||
| 166 | |||
| 167 | $sform->addElement($moderators_tray); |
||
| 168 | */ |
||
| 169 | $sform->addElement(new XoopsFormHidden('categoryid', $categoryid)); |
||
| 170 | |||
| 171 | // Action buttons tray |
||
| 172 | $button_tray = new XoopsFormElementTray('', ''); |
||
| 173 | |||
| 174 | /*for ($i = 0; $i < count($moderators); ++$i) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 175 | $allmods[] = $moderators[$i]; |
||
| 176 | } |
||
| 177 | |||
| 178 | $hiddenmods = new XoopsFormHidden('allmods', $allmods); |
||
| 179 | $button_tray->addElement($hiddenmods); |
||
| 180 | */ |
||
| 181 | $hidden = new XoopsFormHidden('op', 'addcategory'); |
||
| 182 | $button_tray->addElement($hidden); |
||
| 183 | // No ID for category -- then it's new category, button says 'Create' |
||
| 184 | View Code Duplication | if (!$categoryid) { |
|
| 185 | $butt_create = new XoopsFormButton('', '', _AM_SF_CREATE, 'submit'); |
||
| 186 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
||
| 187 | $button_tray->addElement($butt_create); |
||
| 188 | |||
| 189 | $butt_clear = new XoopsFormButton('', '', _AM_SF_CLEAR, 'reset'); |
||
| 190 | $button_tray->addElement($butt_clear); |
||
| 191 | |||
| 192 | $butt_cancel = new XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||
| 193 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 194 | $button_tray->addElement($butt_cancel); |
||
| 195 | } else { |
||
| 196 | // button says 'Update' |
||
| 197 | $butt_create = new XoopsFormButton('', '', _AM_SF_MODIFY, 'submit'); |
||
| 198 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
||
| 199 | $button_tray->addElement($butt_create); |
||
| 200 | |||
| 201 | $butt_cancel = new XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||
| 202 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 203 | $button_tray->addElement($butt_cancel); |
||
| 204 | } |
||
| 205 | |||
| 206 | $sform->addElement($button_tray); |
||
| 207 | $sform->display(); |
||
| 208 | echo '</div>'; |
||
| 209 | |||
| 210 | if ($categoryid) { |
||
| 211 | include_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php'; |
||
| 212 | } |
||
| 213 | |||
| 214 | unset($hidden); |
||
| 215 | } |
||
| 216 | |||
| 217 | switch ($op) { |
||
| 218 | case 'mod': |
||
| 219 | $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0; |
||
| 220 | $destList = isset($_POST['destList']) ? $_POST['destList'] : ''; |
||
| 221 | $indexAdmin = new ModuleAdmin(); |
||
| 222 | xoops_cp_header(); |
||
| 223 | |||
| 224 | echo $indexAdmin->addNavigation(basename(__FILE__)); |
||
| 225 | editcat(true, $categoryid); |
||
| 226 | break; |
||
| 227 | |||
| 228 | case 'addcategory': |
||
| 229 | global $_POST, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $modify, $myts, $categoryid; |
||
| 230 | |||
| 231 | $categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0; |
||
| 232 | |||
| 233 | if ($categoryid != 0) { |
||
| 234 | $categoryObj = new sfCategory($categoryid); |
||
| 235 | } else { |
||
| 236 | $categoryObj = $categoryHandler->create(); |
||
| 237 | } |
||
| 238 | |||
| 239 | //if (isset($_POST['allmods'])) $allmods = $_POST['allmods']; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 240 | //if (isset($_POST['moderators'])) $moderators = $_POST['moderators']; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 241 | |||
| 242 | $categoryObj->setVar('parentid', isset($_POST['parentid']) ? (int)$_POST['parentid'] : 0); |
||
| 243 | $applyall = isset($_POST['applyall']) ? (int)$_POST['applyall'] : 0; |
||
| 244 | $categoryObj->setVar('weight', isset($_POST['weight']) ? (int)$_POST['weight'] : 1); |
||
| 245 | |||
| 246 | // Groups and permissions |
||
| 247 | if (isset($_POST['groups_read'])) { |
||
| 248 | $categoryObj->setGroups_read($_POST['groups_read']); |
||
| 249 | } else { |
||
| 250 | $categoryObj->setGroups_read(); |
||
| 251 | } |
||
| 252 | // $groups_admin = isset($_POST['groups_admin'])? $_POST['groups_admin'] : array(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 253 | // $mod_perms = isset($_POST['mod_perms'])? $_POST['mod_perms'] : array(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 254 | |||
| 255 | $categoryObj->setVar('name', $_POST['name']); |
||
| 256 | |||
| 257 | $categoryObj->setVar('description', $_POST['description']); |
||
| 258 | if ($categoryObj->isNew()) { |
||
| 259 | $redirect_msg = _AM_SF_CATCREATED; |
||
| 260 | $redirect_to = 'category.php?op=mod'; |
||
| 261 | } else { |
||
| 262 | $redirect_msg = _AM_SF_COLMODIFIED; |
||
| 263 | $redirect_to = 'category.php'; |
||
| 264 | } |
||
| 265 | |||
| 266 | if (!$categoryObj->store()) { |
||
| 267 | redirect_header('javascript:history.go(-1)', 3, _AM_SF_CATEGORY_SAVE_ERROR . sf_formatErrors($categoryObj->getErrors())); |
||
| 268 | } |
||
| 269 | // TODO : put this function in the category class |
||
| 270 | sf_saveCategory_Permissions($categoryObj->getGroups_read(), $categoryObj->categoryid(), 'category_read'); |
||
| 271 | //sf_saveCategory_Permissions($groups_admin, $categoriesObj->categoryid(), 'category_admin'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
74% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 272 | |||
| 273 | if ($applyall) { |
||
| 274 | // TODO : put this function in the category class |
||
| 275 | sf_overrideFaqsPermissions($categoryObj->getGroups_read(), $categoryObj->categoryid()); |
||
| 276 | } |
||
| 277 | |||
| 278 | redirect_header($redirect_to, 2, $redirect_msg); |
||
| 279 | break; |
||
| 280 | |||
| 281 | View Code Duplication | case 'del': |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 282 | global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET; |
||
| 283 | |||
| 284 | $module_id = $xoopsModule->getVar('mid'); |
||
| 285 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 286 | |||
| 287 | $categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0; |
||
| 288 | $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : $categoryid; |
||
| 289 | |||
| 290 | $categoryObj = new sfCategory($categoryid); |
||
| 291 | |||
| 292 | $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
||
| 293 | $name = isset($_POST['name']) ? $_POST['name'] : ''; |
||
| 294 | |||
| 295 | if ($confirm) { |
||
| 296 | if (!$categoryHandler->delete($categoryObj)) { |
||
| 297 | redirect_header('category.php', 1, _AM_SF_DELETE_CAT_ERROR); |
||
| 298 | } |
||
| 299 | redirect_header('category.php', 1, sprintf(_AM_SF_COLISDELETED, $name)); |
||
| 300 | } else { |
||
| 301 | // no confirm: show deletion condition |
||
| 302 | $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0; |
||
| 303 | xoops_cp_header(); |
||
| 304 | xoops_confirm(array('op' => 'del', 'categoryid' => $categoryObj->categoryid(), 'confirm' => 1, 'name' => $categoryObj->name()), 'category.php', _AM_SF_DELETECOL . " '" . $categoryObj->name() . "'. <br /> <br />" . _AM_SF_DELETE_CAT_CONFIRM, _AM_SF_DELETE); |
||
| 305 | xoops_cp_footer(); |
||
| 306 | } |
||
| 307 | exit(); |
||
| 308 | break; |
||
| 309 | |||
| 310 | case 'cancel': |
||
| 311 | redirect_header('category.php', 1, sprintf(_AM_SF_BACK2IDX, '')); |
||
| 312 | break; |
||
| 313 | case 'default': |
||
| 314 | default: |
||
| 315 | $indexAdmin = new ModuleAdmin(); |
||
| 316 | xoops_cp_header(); |
||
| 317 | |||
| 318 | echo $indexAdmin->addNavigation(basename(__FILE__)); |
||
| 319 | echo "<br />\n"; |
||
| 320 | |||
| 321 | // Creating the objects for top categories |
||
| 322 | $categoriesObj = $categoryHandler->getCategories($xoopsModuleConfig['perpage'], $startcategory, 0); |
||
| 323 | |||
| 324 | sf_collapsableBar('toptable', 'toptableicon'); |
||
| 325 | echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . _AM_SF_CATEGORIES_TITLE . '</h3>'; |
||
| 326 | echo "<div id='toptable'>"; |
||
| 327 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . _AM_SF_CATEGORIES_DSC . '</span>'; |
||
| 328 | |||
| 329 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
| 330 | echo '<tr>'; |
||
| 331 | echo "<th width='35%' class='bg3' align='left'><b>" . _AM_SF_ARTCOLNAME . '</b></td>'; |
||
| 332 | echo "<th class='bg3' align='left'><b>" . _AM_SF_DESCRIP . '</b></td>'; |
||
| 333 | echo "<th class='bg3' width='65' align='center'><b>" . _AM_SF_WEIGHT . '</b></td>'; |
||
| 334 | echo "<th width='60' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>'; |
||
| 335 | echo '</tr>'; |
||
| 336 | $totalCategories = $categoryHandler->getCategoriesCount(0); |
||
| 337 | if (count($categoriesObj) > 0) { |
||
| 338 | foreach ($categoriesObj as $key => $thiscat) { |
||
| 339 | displayCategory($thiscat); |
||
| 340 | } |
||
| 341 | } else { |
||
| 342 | echo '<tr>'; |
||
| 343 | echo "<td class='head' align='center' colspan= '7'>" . _AM_SF_NOCAT . '</td>'; |
||
| 344 | echo '</tr>'; |
||
| 345 | $categoryid = '0'; |
||
| 346 | } |
||
| 347 | echo "</table>\n"; |
||
| 348 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 349 | $pagenav = new XoopsPageNav($totalCategories, $xoopsModuleConfig['perpage'], $startcategory, 'startcategory'); |
||
| 350 | echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
||
| 351 | echo '</div>'; |
||
| 352 | |||
| 353 | editcat(false); |
||
| 354 | |||
| 355 | break; |
||
| 356 | } |
||
| 357 | |||
| 358 | include_once __DIR__ . '/admin_footer.php'; |
||
| 359 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.