Ejemplo n.º 1
0
/**
* @desc Formulario de creación/edición de categorías
**/
function formCategos($edit = 0)
{
    global $xoopsModule, $db;
    $id = rmc_server_var($_GET, 'id', 0);
    if ($edit) {
        //Verificamos si categoría es válida
        if ($id <= 0) {
            redirectMsg('categories.php', __('Specified category is not valid!', 'dtransport'), 1);
        }
        //Verificamos si la categoría existe
        $cat = new DTCategory($id);
        if ($cat->isNew()) {
            redirectMsg('categories.php', __('Specified category does not exists!', 'dtransport'), 1);
        }
    }
    DTFunctions::toolbar();
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; " . ($edit ? __('Edit category', 'dtransport') : __('New category', 'dtransport')));
    xoops_cp_header();
    $form = new RMForm($edit ? __('Edit Category', 'dtransport') : __('New Category', 'dtransport'), 'frmcat', 'categories.php');
    $form->addElement(new RMFormText(__('Category name', 'dtransport'), 'name', 50, 150, $edit ? $cat->name() : ''), true);
    if ($edit) {
        $form->addElement(new RMFormText(__('Category short name', 'dtransport'), 'nameid', 50, 150, $edit ? $cat->nameId() : ''));
    }
    $form->addElement(new RMFormTextArea(__('Description', 'dtransport'), 'desc', 5, 40, $edit ? $cat->desc('e') : ''));
    //Lista de categorías
    $ele = new RMFormSelect(__('Root category', 'dtransport'), 'parent');
    $ele->addOption(0, __('Select category...', 'dtransport'));
    $categos = array();
    DTFunctions::getCategos($categos, 0, 0, $edit ? $cat->id() : array());
    foreach ($categos as $catego) {
        $ele->addOption($catego['id_cat'], str_repeat('--', $catego['jumps']) . ' ' . $catego['name'], $edit ? $catego['id_cat'] == $cat->parent() ? 1 : 0 : 0);
    }
    $form->addElement($ele);
    $form->addElement(new RMFormYesno(__('Active category', 'dtransport'), 'active', $edit ? $cat->active() : 1));
    $form->addElement(new RMFormHidden('action', $edit ? 'saveedit' : 'save'));
    $form->addElement(new RMFormHidden('id', $id));
    $buttons = new RMFormButtonGroup();
    $buttons->addButton('sbt', __('Submit', 'dtransport'), 'submit');
    $buttons->addButton('cancel', __('Cancel', 'dtransport'), 'button', 'onclick="window.location=\'categories.php\';"');
    $form->addElement($buttons);
    $form->display();
    xoops_cp_footer();
}
Ejemplo n.º 2
0
 /**
  * Get the path for a category
  */
 public function category_path($id)
 {
     if ($id <= 0) {
         return false;
     }
     $cat = new DTCategory($id);
     $path[] = $cat->nameId();
     if ($cat->parent() <= 0) {
         return $path;
     }
     $path = array_merge($path, $this->category_path($cat->parent()));
     return $path;
 }