Exemple #1
0
function m_delete_championships()
{
    global $xoopsModule, $xoopsSecurity;
    $ids = rmc_server_var($_POST, 'ids', array());
    //Verificamos que nos hayan proporcionado una categoría para eliminar
    if (empty($ids)) {
        redirectMsg('./champ.php', __('No championships selected!', 'match'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./champ.php', __('Session token expired!', 'match'), 1);
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si la categoría es válida
        if ($k <= 0) {
            $errors .= sprintf(__('Championship id "%s" is not valid!', 'match'), $k);
            continue;
        }
        //Verificamos si la categoría existe
        $champ = new MCHChampionship($k);
        if ($champ->isNew()) {
            $errors .= sprintf(__('Championship "%s" does not exists!', 'match'), $k);
            continue;
        }
        RMEvents::get()->run_event('match.delete.championship', $cat);
        if (!$champ->delete()) {
            $errors .= sprintf(__('Championship "%s" could not be deleted!', 'match'), $champ->getVar('name'));
        }
    }
    if ($errors != '') {
        redirectMsg('./champ.php', __('Errors ocurred while trying to delete championships', 'match') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('./champ.php', __('Database updated successfully!', 'match'), 0);
        die;
    }
}