示例#1
0
/**
* @desc Permite aprobar o no una publicación
**/
function approved_resources($app = 0)
{
    global $xoopsSecurity, $xoopsConfig, $xoopsModuleConfig;
    $resources = rmc_server_var($_POST, 'ids', array());
    $page = rmc_server_var($_POST, 'page', 1);
    if (!$xoopsSecurity->check()) {
        redirectMsg('./resources.php?page=' . $page, __('Session token expired!', 'docs'), 1);
        die;
    }
    //Verifica que se haya proporcionado una publicación
    if (!is_array($resources) || empty($resources)) {
        redirectMsg('./resources.php?page=' . $page, __('Select at least a Document!', 'docs'), 1);
        die;
    }
    $errors = '';
    foreach ($resources as $k) {
        //Comprueba si la publicación es válida
        if ($k <= 0) {
            $errors .= sprintf(__('Document ID "%s" is not valid!', 'docs'), $k);
            continue;
        }
        //Comprueba si la publicación existe
        $res = new RDResource($k);
        if ($res->isNew()) {
            $errors .= sprintf(__('Document with ID "%s" does not exists!', 'docs'), $k);
            continue;
        }
        $approved = $res->getVar('approved');
        $res->setVar('approved', $app);
        if (!$res->save()) {
            $errors .= sprintf(__('Resoource "%s" could not be saved!', 'docs'), $k);
        } else {
            if ($app && !$approved) {
                $errors .= RDFunctions::mail_approved($res) != true ? __('Notification email could not be sent!', 'docs') . '<br />' : '';
            }
        }
    }
    if ($errors != '') {
        redirectMsg('./resources.php?page=' . $page, __('Errors ocurred while trying to update resources.') . '<br />' . $errors, 1);
    } else {
        redirectMsg('./resources.php?page=' . $page, __('Documents updated successfully!', 'docs'), 0);
    }
}