Example #1
0
/**
* @desc Almacena toda la información referente a la sección
**/
function saveSection($edit = 0, $ret = 0)
{
    global $xoopsUser, $xoopsModuleConfig;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    //Verifica si se proporcionó una publicación para la sección
    if ($res <= 0) {
        redirect_header(RDURL, 1, __('Operation not allowed!', 'docs'));
        die;
    }
    //Verifica si la publicación existe
    $res = new RDResource($res);
    if ($res->isNew()) {
        redirect_header(RDURL, 1, __('Operation not allowed!', 'docs'));
        die;
    }
    //Verificamos si es una publicación aprobada
    if (!$res->getVar('approved')) {
        redirect_header(RDURL, 2, __('This Document has not been approved yet!', 'docs'));
        die;
    }
    // TODO: Crear el link correcto de retorno
    if ($xoopsModuleConfig['permalinks']) {
        $retlink = RDFunctions::url() . '/list/' . $res->getVar('nameid') . '/';
    } else {
        $retlink = RDFunctions::url() . '?page=edit&action=list&res=' . $res->id();
    }
    //Verificamos si el usuario tiene permisos de edicion
    if (!$xoopsUser->uid() == $res->getVar('owner') && !$res->isEditor($xoopsUser->uid()) && !$xoopsUser->isAdmin()) {
        redirect_header(RDURL, 2, __('You can not edit this content!', 'docs'));
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verifica si la sección es válida
        if ($id == '') {
            redirect_header($retlink, 1, __('Specified section is not valid!', 'docs'));
            die;
        }
        //Comprueba si la sección es existente
        $sec = new RDSection($id);
        if ($sec->isNew()) {
            redirect_header($retlink, 1, __('Specified section does not exists!', 'docs'));
            die;
        }
        //Comprueba que el título de la sección no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='{$res}' AND id_sec<>" . $sec->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header($sec->editlink(), 1, __('Already exists another section with same title!', 'docs'));
            die;
        }
        /**
         * Comprobamos si debemos almacenar las ediciones en la
         * tabla temporal o directamente en la tabla de secciones
         */
        if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin()) {
            $sec = new RDEdit(null, $id_sec);
        }
    } else {
        //Comprueba que el título de la sección no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='" . $res->id() . "'";
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(ah_make_link('publish/' . $res->nameId() . '/'), 1, _MS_AH_ERRTITLE);
            die;
        }
        $sec = new RDSection();
    }
    //Genera $nameid Nombre identificador
    if ($title != $sec->getVar('title')) {
        $found = false;
        $i = 0;
        do {
            $nameid = TextCleaner::getInstance()->sweetstring($title) . ($found ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE nameid = '{$nameid}'";
            list($num) = $db->fetchRow($db->queryF($sql));
            if ($num > 0) {
                $found = true;
                $i++;
            } else {
                $found = false;
            }
        } while ($found == true);
    }
    if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin() && !($res->getVar('owner') == $xoopsUser->uid())) {
        $sec->setVar('id_sec', $id);
    }
    $sec->setVar('title', $title);
    $sec->setVar('content', $content);
    $sec->setVar('order', $order);
    $sec->setVar('id_res', $res->id());
    isset($nameid) ? $sec->setVar('nameid', $nameid) : '';
    $sec->setVar('parent', $parent);
    $sec->setVar('uid', $xoopsUser->uid());
    $sec->setVar('uname', $xoopsUser->uname());
    if ($edit) {
        $sec->setVar('modified', time());
    } else {
        $sec->setVar('created', time());
        $sec->setVar('modified', time());
    }
    // Metas
    if ($edit) {
        $sec->clear_metas();
    }
    // Clear all metas
    // Initialize metas array if not exists
    if (!isset($metas)) {
        $metas = array();
    }
    // Get meta key if "select" is visible
    if (isset($meta_name_sel) && $meta_name_sel != '') {
        $meta_name = $meta_name_sel;
    }
    // Add meta to metas array
    if (isset($meta_name) && $meta_name != '') {
        array_push($metas, array('key' => $meta_name, 'value' => $meta_value));
    }
    // Assign metas
    foreach ($metas as $value) {
        $sec->add_meta($value['key'], $value['value']);
    }
    RMEvents::get()->run_event('docs.saving.section', $sec);
    if (!$sec->save()) {
        redirect_header($sec->editlink(), 3, __('Section could not be saved!', 'docs'));
    } else {
        if ($edit) {
            $sec = new RDSection($sec->getVar('id_sec'));
        }
        if ($return == 1) {
            redirect_header($sec->permalink(), 1, __('Database updated successfully!', 'docs'));
        } elseif ($return == 2) {
            redirect_header($sec->editlink(), 1, __('Database updated successfully!', 'docs'));
        } else {
            redirect_header($retlink, 1, __('Database updated successfully!', 'docs'));
        }
    }
}
Example #2
0
define('AH_LOCATION', 'rate');
include '../../mainfile.php';
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$rate = isset($_GET['rate']) ? intval($_GET['rate']) : 0;
$ret = isset($_GET['ret']) ? $_GET['ret'] : '';
$mc =& $xoopsModuleConfig;
if ($id <= 0) {
    redirect_header(XOOPS_URL . '/modules/ahelp/', 2, _MS_AH_NOID);
    die;
}
$res = new RDResource($id);
if ($res->isNew()) {
    redirect_header(XOOPS_URL . '/modules/ahelp/', 2, _MS_AH_NOID);
    die;
}
$retlink = $ret != '' ? urldecode($ret) : XOOPS_URL . '/modules/ahelp/' . ($mc['access'] ? 'content/' . $res->id() . '/' . $res->nameId() : 'content.php?id=' . $res->id());
if ($rate <= 0 || $rate > 5) {
    redirect_header($retlink, 2, _MS_AH_NORATE);
    die;
}
$db->queryF("DELETE FROM " . $db->prefix("pa_votedata") . " WHERE date<'" . (time() - 86400) . "'");
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT COUNT(*) FROM " . $db->prefix("pa_votedata") . " WHERE ";
if ($xoopsUser) {
    $sql .= "uid='" . $xoopsUser->uid() . "' AND date>'" . (time() - 86400) . "' AND res='" . $res->id() . "'";
} else {
    $sql .= "ip='{$ip}' AND date>'" . (time() - 86400) . "' AND res='" . $res->id() . "'";
}
list($num) = $db->fetchRow($db->query($sql));
if ($num > 0) {
    redirect_header($retlink, 2, _MS_AH_NODAY);