function getCategoryName() { if (!isset($this->_category)) { $this->_category = new ssCategory($this->getVar('categoryid')); } return $this->_category->name(); }
<?php /** * $Id: category.php,v 1.2 2005/08/02 03:47:51 mauriciodelima Exp $ * Module: SmartSection * Author: The SmartFactory <www.smartfactory.ca> * Licence: GNU */ include_once "header.php"; global $smartsection_category_handler, $smartsection_item_handler; $categoryid = isset($_GET['categoryid']) ? intval($_GET['categoryid']) : 0; // Creating the category object for the selected category $categoryObj = new ssCategory($categoryid); // If the selected category was not found, exit if ($categoryObj->notLoaded()) { redirect_header("javascript:history.go(-1)", 1, _MD_SS_NOCATEGORYSELECTED); exit; } // Check user permissions to access this category if (!$categoryObj->checkPermission()) { redirect_header("javascript:history.go(-1)", 1, _NOPERM); exit; } $item_page_id = isset($_GET['page']) ? intval($_GET['page']) : -1; $totalItem = $smartsection_category_handler->publishedItemsCount(); // If there is no Item under this categories or the sub-categories, exit if (!isset($totalItem[$categoryid]) || $totalItem[$categoryid] == 0) { //redirect_header("index.php", 1, _MD_SS_MAINNOFAQS); //exit; } $xoopsOption['template_main'] = 'smartsection_category.html';
function editcat($showmenu = false, $categoryid = 0, $nb_subcats = 4, $categoryObj = null) { global $xoopsDB, $smartsection_category_handler, $xoopsUser, $myts, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; // If there is a parameter, and the id exists, retrieve data: we're editing a category if ($categoryid != 0) { // Creating the category object for the selected category $categoryObj = new ssCategory($categoryid); if ($showmenu) { ss_adminMenu(1, _AM_SS_CATEGORIES . " > " . _AM_SS_EDITING); } echo "<br />\n"; if ($categoryObj->notLoaded()) { redirect_header("category.php", 1, _AM_SS_NOCOLTOEDIT); exit; } ss_collapsableBar('edittable', 'edittableicon', _AM_SS_EDITCOL, _AM_SS_CATEGORY_EDIT_INFO); } else { if (!$categoryObj) { $categoryObj = $smartsection_category_handler->create(); } if ($showmenu) { ss_adminMenu(1, _AM_SS_CATEGORIES . " > " . _AM_SS_CREATINGNEW); } //echo "<br />\n"; ss_collapsableBar('createtable', 'createtableicon', _AM_SS_CATEGORY_CREATE, _AM_SS_CATEGORY_CREATE_INFO); } // Start category form $mytree = new XoopsTree($xoopsDB->prefix("smartsection_categories"), "categoryid", "parentid"); $sform = new XoopsThemeForm(_AM_SS_CATEGORY, "op", xoops_getenv('PHP_SELF')); $sform->setExtra('enctype="multipart/form-data"'); // Name $sform->addElement(new XoopsFormText(_AM_SS_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true); // Decsription $sform->addElement(new XoopsFormTextArea(_AM_SS_COLDESCRIPT, 'description', $categoryObj->description('e'), 7, 60)); /* // IMAGE $image_array = & XoopsLists :: getImgListAsArray( ss_getImageDir('category') ); $image_select = new XoopsFormSelect( '', 'image', $categoryObj->image() ); $image_select -> addOption ('-1', '---------------'); $image_select -> addOptionArray( $image_array ); $image_select -> setExtra( "onchange='showImgSelected(\"image3\", \"image\", \"" . 'uploads/smartsection/images/category/' . "\", \"\", \"" . XOOPS_URL . "\")'" ); $image_tray = new XoopsFormElementTray( _AM_SS_IMAGE, ' ' ); $image_tray -> addElement( $image_select ); $image_tray -> addElement( new XoopsFormLabel( '', "<br /><br /><img src='" . ss_getImageDir('category', false) .$categoryObj->image() . "' name='image3' id='image3' alt='' />" ) ); $image_tray->setDescription(_AM_SS_IMAGE_DSC); $sform -> addElement( $image_tray ); // IMAGE UPLOAD $max_size = 5000000; $file_box = new XoopsFormFile(_AM_SS_IMAGE_UPLOAD, "image_file", $max_size); $file_box->setExtra( "size ='45'") ; $file_box->setDescription(_AM_SS_IMAGE_UPLOAD_DSC); $sform->addElement($file_box); */ // Weight $sform->addElement(new XoopsFormText(_AM_SS_COLPOSIT, 'weight', 4, 4, $categoryObj->weight())); // READ PERMISSIONS $member_handler =& xoops_gethandler('member'); $group_list =& $member_handler->getGroupList(); $groups_read_checkbox = new XoopsFormCheckBox(_AM_SS_PERMISSIONS_CAT_READ, 'groups_read[]', $categoryObj->getGroups_read()); foreach ($group_list as $group_id => $group_name) { if ($group_id != XOOPS_GROUP_ADMIN) { $groups_read_checkbox->addOption($group_id, $group_name); } } $sform->addElement($groups_read_checkbox); // Apply permissions on all items $apply = isset($_POST['applyall']) ? intval($_POST['applyall']) : 0; $addapplyall_radio = new XoopsFormRadioYN(_AM_SS_PERMISSIONS_APPLY_ON_ITEMS, 'applyall', $apply, ' ' . _AM_SS_YES . '', ' ' . _AM_SS_NO . ''); $sform->addElement($addapplyall_radio); // MODERATORS //$moderators_tray = new XoopsFormElementTray(_AM_SS_MODERATORS_DEF, ''); $module_id = $xoopsModule->getVar('mid'); // Parent Category ob_start(); $mytree->makeMySelBox("name", "weight", $categoryObj->parentid(), 1, 'parentid'); //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") $sform->addElement(new XoopsFormLabel(_AM_SS_PARENT_CATEGORY_EXP, ob_get_contents())); ob_end_clean(); // Added by fx2024 // sub Categories $cat_tray = new XoopsFormElementTray(_AM_SS_SCATEGORYNAME, '<br /><br />'); for ($i = 0; $i < $nb_subcats; $i++) { if ($i < (isset($_POST['scname']) ? sizeof($_POST['scname']) : 0)) { $subname = isset($_POST['scname']) ? $_POST['scname'][$i] : ''; } else { $subname = ''; } $cat_tray->addElement(new XoopsFormText('', 'scname[' . $i . ']', 50, 255, $subname), true); } $t = new XoopsFormText('', 'nb_subcats', 3, 2); $l = new XoopsFormLabel('', sprintf(_AM_SS_ADD_OPT, $t->render())); $b = new XoopsFormButton('', 'submit', _AM_SS_ADD_OPT_SUBMIT, 'submit'); if ($categoryid == 0) { $b->setExtra('onclick="this.form.elements.op.value=\'addsubcats\'"'); } else { $b->setExtra('onclick="this.form.elements.op.value=\'mod\'"'); } $r = new XoopsFormElementTray(''); $r->addElement($l); $r->addElement($b); $cat_tray->addElement($r); $sform->addElement($cat_tray); //End of fx2024 code /*$gperm_handler = &xoops_gethandler('groupperm'); $mod_perms = $gperm_handler->getGroupIds('category_moderation', $categoryid, $module_id); $moderators_select = new XoopsFormSelect('', 'moderators', $moderators, 5, true); $moderators_tray->addElement($moderators_select); $butt_mngmods = new XoopsFormButton('', '', 'Manage mods', 'button'); $butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"'); $moderators_tray->addElement($butt_mngmods); $butt_delmod = new XoopsFormButton('', '', 'Delete mod', 'button'); $butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"'); $moderators_tray->addElement($butt_delmod); $sform->addElement($moderators_tray); */ $sform->addElement(new XoopsFormHidden('categoryid', $categoryid)); //$parentid = $categoryObj->parentid('s'); //$sform -> addElement( new XoopsFormHidden( 'parentid', $parentid ) ); $sform->addElement(new XoopsFormHidden('nb_sub_yet', $nb_subcats)); // Action buttons tray $button_tray = new XoopsFormElementTray('', ''); /*for ($i = 0; $i < sizeof($moderators); $i++) { $allmods[] = $moderators[$i]; } $hiddenmods = new XoopsFormHidden('allmods', $allmods); $button_tray->addElement($hiddenmods); */ $hidden = new XoopsFormHidden('op', 'addcategory'); $button_tray->addElement($hidden); // No ID for category -- then it's new category, button says 'Create' if (!$categoryid) { $butt_create = new XoopsFormButton('', '', _AM_SS_CREATE, 'submit'); $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); $button_tray->addElement($butt_create); $butt_clear = new XoopsFormButton('', '', _AM_SS_CLEAR, 'reset'); $button_tray->addElement($butt_clear); $butt_cancel = new XoopsFormButton('', '', _AM_SS_CANCEL, 'button'); $butt_cancel->setExtra('onclick="history.go(-1)"'); $button_tray->addElement($butt_cancel); $sform->addElement($button_tray); $sform->display(); ss_close_collapsable('createtable', 'createtableicon'); } else { // button says 'Update' $butt_create = new XoopsFormButton('', '', _AM_SS_MODIFY, 'submit'); $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); $button_tray->addElement($butt_create); $butt_cancel = new XoopsFormButton('', '', _AM_SS_CANCEL, 'button'); $butt_cancel->setExtra('onclick="history.go(-1)"'); $button_tray->addElement($butt_cancel); $sform->addElement($button_tray); $sform->display(); ss_close_collapsable('edittable', 'edittableicon'); } //Added by fx2024 if ($categoryid) { include_once XOOPS_ROOT_PATH . "/modules/smartsection/include/displaysubcats.php"; include_once XOOPS_ROOT_PATH . "/modules/smartsection/include/displayitems.php"; } //end of fx2024 code unset($hidden); }
/** * retrieve categories from the database * * @param object $criteria {@link CriteriaElement} conditions to be met * @param bool $id_as_key use the categoryid as key for the array? * @return array array of {@link XoopsItem} objects */ function &getObjects($criteria = null, $id_as_key = false) { $ret = array(); $limit = $start = 0; $sql = 'SELECT * FROM ' . $this->db->prefix('smartsection_categories'); if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' ' . $criteria->renderWhere(); if ($criteria->getSort() != '') { $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); } $limit = $criteria->getLimit(); $start = $criteria->getStart(); } //echo "<br />" . $sql . "<br />"; $result = $this->db->query($sql, $limit, $start); if (!$result) { return $ret; } while ($myrow = $this->db->fetchArray($result)) { $category = new ssCategory(); $category->assignVars($myrow); $category->assignOtherProperties(); if (!$id_as_key) { $ret[] =& $category; } else { $ret[$myrow['categoryid']] =& $category; } unset($category); } return $ret; }