Example #1
0
/**
 * Almacenamos la categoría en la base de datos
 */
function saveCatego($edit = 0)
{
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if ($edit && $id <= 0) {
        redirectMsg('cats.php', __('You must provide a category ID to edit!', 'qpages'), 1);
        die;
    }
    if ($nombre == '') {
        redirectMsg('cats.php?op=new', __('Please provide a name for this category!', 'qpages'), 1);
        die;
    }
    $nombre_amigo = TextCleaner::getInstance()->sweetstring($nombre);
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    # Verificamos que no exista la categoría
    $result = $db->query("SELECT COUNT(*) FROM " . $db->prefix("qpages_categos") . " WHERE parent='{$parent}'" . ($edit ? " AND id_cat<>{$id}" : '') . " AND (nombre='{$nombre}' OR nombre_amigo='{$nombre_amigo}')");
    list($num) = $db->fetchRow($result);
    if ($num > 0) {
        redirectMsg('cats.php?op=new', __('There is another category with same name!', 'qpages'), 1);
        die;
    }
    # Si todo esta bien guardamos la categoría
    $catego = new QPCategory($edit ? $id : null);
    $catego->setName($nombre);
    $catego->setFriendName($nombre_amigo);
    $catego->setDescription($descripcion);
    $catego->setParent($parent);
    if ($edit) {
        $result = $catego->update();
    } else {
        $result = $catego->save();
    }
    if ($result) {
        redirectMsg('cats.php', __('Database updated successfully!', 'qpages'), 0);
    } else {
        redirectMsg('cats.php?op=new', __('Errors ocurred while trying to update database') . "<br />" . $catego->errors(), 1);
    }
}