Exemple #1
0
/**
* @desc Elimina la(s) imagen(es) especificada(s)
**/
function deleteImages()
{
    global $xoopsSecurity, $xoopsModule, $db;
    $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
    $ok = isset($_POST['ok']) ? $_POST['ok'] : 0;
    $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    $limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 15;
    $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
    $owner = isset($_REQUEST['owner']) ? intval($_REQUEST['owner']) : '';
    $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'created';
    $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 0;
    $ruta = "page={$page}&limit={$limit}&search={$search}&owner={$owner}&sort={$sort}&mode={$mode}";
    //Verificamos si nos proporcionaron al menos un imagen para eliminar
    if (!is_array($ids)) {
        redirectMsg('./images.php?' . $ruta, __('No images has been selected!', 'galleries'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./images.php?' . $ruta, __('Session token expired!', 'galleries'), 1);
        die;
    }
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si la imagen es válida
        if ($k <= 0) {
            $errors .= sprintf(__('Image ID "%s" not valid', 'galleries'), $k);
            continue;
        }
        //Verificamos si la imagen existe
        $img = new GSImage($k);
        if ($img->isNew()) {
            $errors .= sprintf(__('Image "%s" does not exists!', 'galleries'), $k);
            continue;
        }
        $sets = $img->sets();
        if (!$img->delete()) {
            $errors .= sprintf(__('Image "%s" could not be deleted!', 'galleries'), $k);
        } else {
            //Decrementamos el número de imágenes de los albumes
            foreach ($sets as $k => $set) {
                $set->quitPic($img->id());
            }
        }
    }
    if ($erros != '') {
        redirectMsg('./images.php?' . $ruta, __('Errors ocurred while trying to delete images', 'galleries') . $errors, 1);
        die;
    } else {
        redirectMsg('./images.php?' . $ruta, __('Images deleted successfully!', 'galleries'), 0);
        die;
    }
}
/**
* @desc Elimina las imágenes especificadas
**/
function deleteImages()
{
    global $db, $ids, $page, $referer, $xoopsModuleConfig;
    if (!$referer) {
        $referer = GSFunctions::get_url() . ($xoopsModuleConfig['urlmode'] ? 'cp/images/page/' . $page : '?cp=images&amp;pag=' . $page);
    } else {
        $referer = base64_decode($referer);
    }
    if (!is_array($ids) && $ids <= 0) {
        $ids = rmc_server_var($_REQUEST, 'ids', array());
    }
    //Verificamos si nos proporcionaron al menos un imagen para eliminar
    if (!is_array($ids) && $ids <= 0) {
        redirect_header($referer, 2, __('You must specify one picture at least!', 'galleries'));
        die;
    }
    if (!is_array($ids)) {
        $ids = array($ids);
    }
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si la imagen es válida
        if ($k <= 0) {
            $errors .= sprintf(__('Picture with id %u is not valid!', 'galleries'), $k);
            continue;
        }
        //Verificamos si la imagen existe
        $img = new GSImage($k);
        if ($img->isNew()) {
            $errors .= sprintf(__('Picture with id %u does not exists!', 'galleries'), $k);
            continue;
        }
        $sets = $img->sets();
        if (!$img->delete()) {
            $errors .= sprintf(__('Picture "%s" could not be deleted!', 'galleries'), $k);
        } else {
            //Decrementamos el número de imágenes de los albumes
            foreach ($sets as $k => $set) {
                $set->quitPic($img->id());
            }
        }
    }
    if ($errors != '') {
        redirect_header($referer, 2, __('Errors ocurred while trying to delete pictures', 'galleries') . $errors);
        die;
    } else {
        redirect_header($referer, 1, __('Pictures deleted succesfully!', 'galleries'));
        die;
    }
}