/**
* @desc Almacena toda la información referente a la referencia
**/
function saveReferences($edit = 0)
{
    global $xoopsSecurity;
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = '?id=' . $id . '&page=' . $page . '&limit=' . $limit . '&search=' . $search;
    if (!$xoopsSecurity->check()) {
        redirectMsg('./references.php' . $ruta, __('Session token expired!', 'docs'), 1);
        die;
    }
    //Comprobar publicacion valida
    if ($id <= 0) {
        redirectMsg('./references.php' . $ruta, __('Document ID not provided!', 'docs'), 1);
        die;
    }
    //Comprobar publicación existente existente
    $res = new RDResource($id);
    if ($res->isNew()) {
        redirectMsg('./references.php' . $ruta, __('Specified Document does not exists!', 'docs'), 1);
        die;
    }
    if ($edit) {
        if ($id_ref <= 0) {
            redirectMsg('./references.php' . $ruta, __('Note id not provided!', 'docs'), 1);
            die;
        }
        $ref = new RDReference($id_ref);
        if ($ref->isNew()) {
            redirectMsg('./references.php' . $ruta, __('Specified note does not exists!', 'docs'), 1);
            die;
        }
        //Comprobar si el título de la referencia en esa publicación existe
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_references') . " WHERE title='{$title}' AND id_res='{$id}' AND id_ref<>'{$id_ref}'";
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirectMsg('./references.php' . $ruta, __('Another note with same title already exists', 'docs'), 1);
            die;
        }
    } else {
        //Comprobar si el título de la referencia en esa publicación existe
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_references') . " WHERE title='{$title}' AND id_res='{$id}'";
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirectMsg('./references.php' . $ruta, __('Another note with same title already exists', 'docs'), 1);
            die;
        }
        $ref = new RDReference();
    }
    $ref->setVar('id_res', $id);
    $ref->setVar('title', $title);
    $ref->setVar('text', $reference);
    if ($ref->save()) {
        redirectMsg('./references.php' . $ruta, __('Note saved successfully', 'docs'), 0);
    } else {
        redirectMsg('./references.php' . $ruta, __('Errors ocurred while trying to save note', 'docs'), 1);
    }
}
Exemple #2
0
/**
* @desc Almacena información perteneciente a referencia
**/
function rd_save_note($edit = 0)
{
    global $xoopsSecurity;
    $id = 0;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "?res={$res}";
    if (!$xoopsSecurity->validateToken()) {
        redirectMsg('./notes.php' . $ruta, __('Session token expired!', 'docs'), 1);
        die;
    }
    if ($edit) {
        //Verifica que referencia sea válida
        if ($id <= 0) {
            redirectMsg('./notes.php' . $ruta, __('Note id not specified!', 'docs'), 1);
            die;
        }
        //Verifica que referencia exista
        $ref = new RDReference($id);
        if ($ref->isNew()) {
            redirectMsg('./notes.php' . $ruta, __('Specified note does not exists!', 'docs'), 1);
            die;
        }
    } else {
        $ref = new RDReference();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    //Comprobar si el título de la referencia en esa publicación existe
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_references') . " WHERE title='{$title}' AND id_res='{$res}' AND id_ref<>'{$id}'";
    list($num) = $db->fetchRow($db->queryF($sql));
    if ($num > 0) {
        redirectMsg('./notes.php' . $ruta, __('Already exists a note with same title', 'docs'), 1);
        die;
    }
    $ref->setVar('title', $title);
    $ref->setVar('text', $reference);
    $ref->setVar('id_res', $res);
    if ($ref->save()) {
        redirectMsg('./notes.php?action=locate&res=' . $res . '&id=' . $ref->id(), __('Note saved successfully!', 'docs'), 0);
        die;
    } else {
        redirectMsg('./notes.php?res=' . $res, __('Note could not be saved!', 'docs') . '<br />' . $ref->errors(), 1);
        die;
    }
}