Пример #1
0
/**
* Deleting a category
*/
function m_delete_teams()
{
    global $xoopsModule, $xoopsSecurity;
    $ids = rmc_server_var($_POST, 'ids', array());
    //Verificamos que nos hayan proporcionado una categoría para eliminar
    if (empty($ids)) {
        redirectMsg('./teams.php', __('No teams selected!', 'match'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./teams.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(__('Team id "%s" is not valid!', 'match'), $k);
            continue;
        }
        //Verificamos si la categoría existe
        $team = new MCHTeam($k);
        if ($team->isNew()) {
            $errors .= sprintf(__('Team "%s" does not exists!', 'match'), $k);
            continue;
        }
        RMEvents::get()->run_event('match.delete.team', $cat);
        $file = MCH_UP_PATH . '/' . $team->getVar('logo');
        if (!$team->delete()) {
            $errors .= sprintf(__('Team "%s" could not be deleted!', 'match'), $k);
        } else {
            if (is_file($file)) {
                unlink($file);
            }
        }
    }
    if ($errors != '') {
        redirectMsg('./teams.php', __('Errors ocurred while trying to delete teams', 'match') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('./teams.php', __('Database updated successfully!', 'match'), 0);
        die;
    }
}