/** * Presenta un formulario para la creación de una nueva * categoría para los artículos */ function show_new_form($edit = 1) { global $xoopsModule; $id = rmc_server_var($_GET, 'id', 0); if ($id <= 0) { redirectMsg('categories.php', __('You must specify a valid category', 'shop'), 1); die; } // Cargamos la categoría $catego = new ShopCategory($id); // Si no existe entonces devolvemos un error if ($catego->isNew()) { redirectMsg('categories.php', __('Specified category not exists!', 'shop'), 1); die; } ShopFunctions::include_required_files(); xoops_cp_location('<a href="./">' . $xoopsModule->name() . '</a> » ' . __('Edit Category', 'shop')); xoops_cp_header(); $cats = array(); ShopFunctions::categos_list($cats, 0, 0, true, $id); $form = new RMForm($edit ? __('Edit Category', 'shop') : __('New Category', 'shop'), 'frmNew', 'categories.php'); $form->styles('width: 30%;', 'odd'); $form->addElement(new RMFormText(__('Category name', 'shop'), 'name', 50, 150, $catego->getVar('name')), true); $form->addElement(new RMFormText(__('Category slug', 'shop'), 'shortname', '', '150', $catego->getVar('shortname', 'n'))); $form->addElement(new RMFormTextArea(__('Category description', 'shop'), 'desc', 5, 45, $catego->getVar('description', 'e'))); $ele = new RMFormSelect(__('Category Parent', 'shop'), 'parent'); $ele->addOption(0, _SELECT, $catego->getVar('parent') == 0 ? 1 : 0); foreach ($cats as $k) { $ele->addOption($k['id_cat'], str_repeat("-", $k['indent']) . ' ' . $k['name'], $catego->getVar('parent') == $k['id_cat'] ? 1 : 0); } $form->addElement($ele); $form->addElement(new RMFormHidden('action', 'saveedit')); $form->addElement(new RMFormHidden('id', $id)); $ele = new RMFormButtonGroup('', ' '); $ele->addButton('sbt', __('Update Category', 'shop'), 'submit'); $ele->addButton('cancel', __('Cancel', 'shop'), 'button'); $ele->setExtra('cancel', "onclick='history.go(-1);'"); $form->addElement($ele); $form->display(); xoops_cp_footer(); }
} $sql = "SELECT id_cat FROM {$tbl1} WHERE shortname='{$k}' AND parent='{$idp}'"; $result = $db->query($sql); if ($db->getRowsNum($result) > 0) { list($idp) = $db->fetchRow($result); } } $category = $idp; } $catego = new ShopCategory($category); if ($catego->isNew()) { redirect_header(ShopFunctions::get_url(), 1, __('Specified category could not be found', 'shop')); die; } // Category data $xoopsTpl->assign('category', array('id' => $catego->id(), 'name' => $catego->getVar('name'))); $xoopsTpl->assign('lang_prodsincat', sprintf(__('Products in ‘%s’ Category', 'shop'), $catego->getVar('name'))); $limit = $xoopsModuleConfig['numxpage']; list($num) = $db->fetchRow($db->query("SELECT COUNT({$tbl2}.product) FROM {$tbl2}, {$tbl3} WHERE {$tbl2}.cat='{$category}' \n AND {$tbl3}.id_product={$tbl2}.product")); $page = isset($page) && $page > 0 ? $page : 1; $tpages = ceil($num / $limit); $page = $page > $tpages ? $tpages : $page; $p = $page > 0 ? $page - 1 : $page; $start = $num <= 0 ? 0 : $p * $limit; $xoopsTpl->assign('page', $page); $nav = new RMPageNav($num, $limit, $page, 5); $nav->target_url($catego->permalink() . ($xoopsModuleConfig['urlmode'] ? 'page/{PAGE_NUM}/' : '&page={PAGE_NUM}')); $xoopsTpl->assign('pagenav', $nav->render(false)); $result = $db->query("SELECT {$tbl3}.* FROM {$tbl2}, {$tbl3} WHERE {$tbl2}.cat='{$category}' \n AND {$tbl3}.id_product={$tbl2}.product ORDER BY " . ($xoopsModuleConfig['sort'] ? " {$tbl3}.`name`" : " {$tbl3}.id_product DESC") . " LIMIT {$start},{$limit}"); include 'include/product-data.php'; $categories = array();