/** * Almacenamos la categoría en la base de datos */ function saveCatego($edit = 0) { global $xoopsSecurity, $db; if (!$xoopsSecurity->check()) { redirectMsg('categories.php', __('Sorry, session token expired!', 'mywords'), 1); die; } $query = ''; foreach ($_POST as $k => $v) { ${$k} = $v; if ($k == 'op' || $k == 'XOOPS_TOKEN_REQUEST') { continue; } $query .= $query == '' ? "{$k}=" . urlencode($v) : '&' . $k . '=' . urlencode($v); } $query = $edit ? '&op=edit' : ''; if ($edit) { if ($id <= 0) { redirectMsg('categories.php', __('You must specify a valid category', 'mywords'), 1); die; } $catego = new MWCategory($id); if ($catego->isNew()) { redirectMsg('categories.php', __('Specified category not exists!', 'mywords'), 1); die; } } else { $catego = new MWCategory(); } if ($name == '') { redirectMsg('categories.php?' . $query, __('Please specify a name for this category!', 'mywords'), 1); die; } $shortname = $shortname == '' ? TextCleaner::sweetstring($name) : $shortname; # Verificamos que no exista la categoría $result = $db->query("SELECT COUNT(*) FROM " . $db->prefix("mw_categories") . " WHERE parent='{$parent}'" . ($edit ? " AND id_cat<>{$id}" : '') . " AND (name='{$name}' OR shortname='{$shortname}')"); list($num) = $db->fetchRow($result); if ($num > 0) { redirectMsg('categories.php?' . $query, __('There is already a category with the same name!', 'mywords'), 1); die; } # Si todo esta bien guardamos la categoría $catego->setVar('name', $name); $catego->setVar('shortname', $shortname); $catego->setVar('description', $desc); $catego->setVar('parent', $parent); if (!$edit) { $catego->setVar('posts', 0); } $result = $catego->save(); if ($result) { redirectMsg('categories.php', __('Category created succesfully!', 'mywords'), 0); } else { redirectMsg('categories.php?' . $query, __('There was an error!', 'mywords') . "<br />" . $catego->errors(), 1); } }