/** * @return bool * @param string $s_input * @param string[] field names $a_keys * @desc Test whether a short URL is already taken by another page */ public function Test($s_input, $a_keys) { $short_url = new ShortUrl($s_input); $short_url->SetFormat($this->object_with_short_url->GetShortUrlFormat()); $short_url->SetParameterValuesFromObject($this->object_with_short_url); $manager = new ShortUrlManager($this->GetSiteSettings(), $this->GetDataConnection()); $taken = $manager->IsUrlTaken($short_url); unset($manager); return !$taken; }
private function RegenerateFormat(ShortUrlFormat $format, $process_id) { # KNOWN ISSUE: Only uses GetShortUrlForType which for a match means tournaments are wrong require_once "data/process-manager.class.php"; $this->process = new ProcessManager($process_id); if ($this->process->ReadyToDeleteAll()) { $this->GetDataConnection()->query('DELETE FROM nsa_short_url WHERE short_url_base IN ( SELECT ' . $format->GetShortUrlField() . ' FROM ' . $format->GetTable() . ')'); } require_once 'http/short-url-manager.class.php'; $short_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $short_url_manager->RegenerateCache(); # Use format info to get existing short URL and querystring data for each item from the data tables. $short_url_manager->ReadAllByFormat($format, $this->process->GetQueryLimit()); $a_short_urls = $short_url_manager->GetItems(); # For each short URL runs Save() to re-save records in short url table. Doesn't # recalculate whether URLs clash, just takes what was in the data table. foreach ($a_short_urls as $o_short_url) { $short_url_manager->Save($o_short_url); $this->process->OneMoreDone(); } unset($short_url_manager); }
/** * @access public * @return void * @param int[] $player_ids * @desc Delete from the database the players matching the supplied ids */ public function Delete($player_ids) { # check parameter $this->ValidateNumericArray($player_ids); # Get tables $players = $this->GetSettings()->GetTable('Player'); $matches = $this->GetSettings()->GetTable("Match"); $batting = $this->GetSettings()->GetTable("Batting"); $bowling = $this->GetSettings()->GetTable("Bowling"); $stats = $this->GetSettings()->GetTable('PlayerMatch'); $player_id_list = implode(', ', $player_ids); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $sql = "SELECT short_url FROM {$players} WHERE player_id IN ({$player_id_list})"; $result = $this->GetDataConnection()->query($sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); # remove player of the match awards $sql = "UPDATE {$matches} SET player_of_match_id = NULL WHERE player_of_match_id IN ({$player_id_list})"; $this->LoggedQuery($sql); $sql = "UPDATE {$matches} SET player_of_match_home_id = NULL WHERE player_of_match_home_id IN ({$player_id_list})"; $this->LoggedQuery($sql); $sql = "UPDATE {$matches} SET player_of_match_away_id = NULL WHERE player_of_match_away_id IN ({$player_id_list})"; $this->LoggedQuery($sql); # Reassign batting and bowling to 'unknown' player $unknown_player = new Player($this->GetSettings()); $unknown_player->SetName("Unknown"); foreach ($player_ids as $player_id) { $sql = "SELECT team_id FROM {$players} WHERE player_id = " . Sql::ProtectNumeric($player_id); $result = $this->GetDataConnection()->query($sql); $row = $result->fetch(); $unknown_player->Team()->SetId($row->team_id); $unknown_player->SetId($this->SaveOrMatchPlayer($unknown_player)); $player = new Player($this->GetSettings()); $player->SetId($player_id); $this->is_internal_delete = true; $this->MergePlayers($player, $unknown_player); $this->is_internal_delete = false; } # Delete statistics $sql = "DELETE FROM {$stats} WHERE player_id IN ({$player_id_list})"; $this->LoggedQuery($sql); # delete the player $sql = "DELETE FROM {$players} WHERE player_id IN ({$player_id_list})"; $this->LoggedQuery($sql); }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Grounds matching the supplied ids. */ function Delete($a_ids) { # check parameter if (!is_array($a_ids)) { die('No grounds to delete'); } # build query $s_ground = $this->GetSettings()->GetTable('Ground'); $s_match = $this->GetSettings()->GetTable('Match'); $statistics = $this->GetSettings()->GetTable('PlayerMatch'); $s_ids = join(', ', $a_ids); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_sql = "SELECT short_url FROM {$s_ground} WHERE ground_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); # delete relationships $s_sql = 'UPDATE nsa_team SET ground_id = NULL WHERE ground_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); $s_sql = 'UPDATE ' . $s_match . ' SET ground_id = NULL WHERE ground_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); $s_sql = 'UPDATE ' . $statistics . ' SET ground_id = NULL WHERE ground_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); # delete ground(s) $s_sql = 'DELETE FROM ' . $s_ground . ' WHERE ground_id IN (' . $s_ids . ') '; $o_result = $this->GetDataConnection()->query($s_sql); return $this->GetDataConnection()->GetAffectedRows(); }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Matches matching the supplied ids. */ public function DeleteMatch($a_ids) { # check parameter if (!is_array($a_ids)) { die('No matches to delete'); } # build query $delete_sql = array(); $s_match = $this->GetSettings()->GetTable('Match'); $s_season_match = $this->GetSettings()->GetTable('SeasonMatch'); $s_mt = $this->GetSettings()->GetTable('MatchTeam'); $batting = $this->GetSettings()->GetTable('Batting'); $bowling = $this->GetSettings()->GetTable('Bowling'); $stats = $this->GetSettings()->GetTable('PlayerMatch'); $s_ids = join(', ', $a_ids); # delete batting and bowling $match_team_ids = array(); $result = $this->GetDataConnection()->query("SELECT match_team_id FROM {$s_mt} WHERE match_id IN ({$s_ids})"); while ($row = $result->fetch()) { $match_team_ids[] = $row->match_team_id; } $result->closeCursor(); if (count($match_team_ids)) { $match_team_ids = join(",", $match_team_ids); $delete_sql[] = "DELETE FROM {$batting} WHERE match_team_id IN ({$match_team_ids})"; $delete_sql[] = "DELETE FROM {$bowling} WHERE match_team_id IN ({$match_team_ids})"; } $this->GetDataConnection()->query("DELETE FROM {$stats} WHERE match_id IN ({$s_ids})"); # delete teams $delete_sql[] = "DELETE FROM {$s_mt} WHERE match_id IN ({$s_ids})"; # delete seasons $delete_sql[] = "DELETE FROM {$s_season_match} WHERE match_id IN ({$s_ids})"; # if this is a tournament, delete the matches $tournament_match_ids = array(); $s_sql = 'SELECT match_id FROM ' . $s_match . ' WHERE tournament_match_id IN (' . $s_ids . ') '; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $tournament_match_ids[] = $row->match_id; } $result->closeCursor(); if (count($tournament_match_ids)) { $this->DeleteMatch($tournament_match_ids); } # delete comments thread $delete_sql[] = "DELETE FROM nsa_forum_message WHERE item_id IN ({$s_ids}) AND item_type = " . ContentType::STOOLBALL_MATCH; # delete match(es) $delete_sql[] = "DELETE FROM {$s_match} WHERE match_id IN ({$s_ids});"; # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_sql = "SELECT short_url FROM {$s_match} WHERE match_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); # get players involved in the match before it's deleted, so that player statistics can be updated require_once 'stoolball/player-manager.class.php'; $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection()); $player_ids = $player_manager->ReadPlayersInMatch($a_ids); unset($player_manager); # Run the collected delete commands foreach ($delete_sql as $sql) { $this->LoggedQuery($sql); } # update player stats, removing this match and any players who featured only in this match require_once 'stoolball/statistics/statistics-manager.class.php'; $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection()); if (count($player_ids)) { $statistics_manager->UpdatePlayerStatistics($player_ids); } unset($statistics_manager); return $this->GetDataConnection()->GetAffectedRows(); }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Teams matching the supplied ids */ public function Delete($a_ids) { # check parameter $this->ValidateNumericArray($a_ids); if (!count($a_ids)) { throw new Exception('No teams to delete'); } $s_ids = join(', ', $a_ids); # Get more information on the teams $teams = array(); $s_sql = "SELECT team_id, short_url, owner_role_id FROM nsa_team WHERE team_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $team = new Team($this->GetSettings()); $team->SetId($row->team_id); $team->SetShortUrl($row->short_url); $team->SetOwnerRoleId($row->owner_role_id); $teams[] = $team; } $result->closeCursor(); # Check that current user is an admin or a team owner require_once "authentication/authentication-manager.class.php"; $user = AuthenticationManager::GetUser(); foreach ($teams as $team) { /* @var $team Team */ if (!$user->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $team->GetLinkedDataUri())) { throw new Exception("Unauthorised"); } } # delete owner role $authentication_manager = new AuthenticationManager($this->GetSettings(), $this->GetDataConnection(), null); foreach ($teams as $team) { /* @var $team Team */ if ($team->GetOwnerRoleId()) { $authentication_manager->DeleteRole($team->GetOwnerRoleId()); } } unset($authentication_manager); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); foreach ($teams as $team) { /* @var $team Team */ $o_url_manager->Delete($team->GetShortUrl()); } unset($o_url_manager); # Delete relationships to matches $s_match_link = $this->GetSettings()->GetTable('MatchTeam'); $s_sql = 'DELETE FROM ' . $s_match_link . ' WHERE team_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); # Delete relationships to competitions $s_season_link = $this->GetSettings()->GetTable('TeamSeason'); $s_sql = 'DELETE FROM ' . $s_season_link . ' WHERE team_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); # Delete players require_once "player-manager.class.php"; $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection()); $player_manager->ReadPlayersInTeam($a_ids); $players = $player_manager->GetItems(); if (count($players)) { $player_ids = array(); foreach ($players as $player) { $player_ids[] = $player->GetId(); } $player_manager->Delete($player_ids); } unset($player_manager); # delete team(s) $s_sql = 'DELETE FROM nsa_team WHERE team_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); return $this->GetDataConnection()->GetAffectedRows(); }
/** * @return int * @param Club $school * @desc Update the supplied school in the database */ public function SaveSchool(Club $school) { if (!$school->GetId()) { throw new Exception("SaveSchool is for updates only. To save a new school, use Save()"); } # Set up short URL manager require_once 'http/short-url-manager.class.php'; $url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $new_short_url = $url_manager->EnsureShortUrl($school); $sql = 'UPDATE nsa_club SET ' . "club_name = " . Sql::ProtectString($this->GetDataConnection(), $school->GetName()) . ", \r\n club_type = " . Club::SCHOOL . ", \r\n short_url = " . Sql::ProtectString($this->GetDataConnection(), $school->GetShortUrl()) . ", \r\n date_changed = " . gmdate('U') . ' ' . 'WHERE club_id = ' . Sql::ProtectNumeric($school->GetId()); $this->GetDataConnection()->query($sql); # Regenerate short URLs if (is_object($new_short_url)) { $new_short_url->SetParameterValuesFromObject($school); $url_manager->Save($new_short_url); } unset($url_manager); }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the seasons matching the supplied ids */ function Delete($a_ids) { # check parameter $this->ValidateNumericArray($a_ids); # build query $s_season = $this->GetSettings()->GetTable('Season'); $s_season_link = $this->GetSettings()->GetTable('TeamSeason'); $s_rule = $this->GetSettings()->GetTable('SeasonRule'); $s_smt = $this->GetSettings()->GetTable('SeasonMatchType'); $s_points = $this->GetSettings()->GetTable('PointsAdjustment'); $s_match = $this->GetSettings()->GetTable('SeasonMatch'); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_ids = join(', ', $a_ids); $s_sql = "SELECT short_url FROM {$s_season} WHERE season_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); foreach ($a_ids as $i_season_id) { $i_season_id = Sql::ProtectNumeric($i_season_id); # Find out what competition we're dealing with $s_sql = 'SELECT competition_id FROM ' . $s_season . ' WHERE season_id = ' . $i_season_id; $o_result = $this->GetDataConnection()->query($s_sql); $o_row = $o_result->fetch(); if (is_object($o_row)) { $i_competition_id = $o_row->competition_id; # Delete matches $s_sql = 'DELETE FROM ' . $s_match . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # Delete match types $s_sql = 'DELETE FROM ' . $s_smt . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # Delete points adjustments $s_sql = 'DELETE FROM ' . $s_points . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # delete rules $s_sql = 'DELETE FROM ' . $s_rule . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # delete relationships to teams $s_sql = 'DELETE FROM ' . $s_season_link . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # delete season(s) $s_sql = 'DELETE FROM ' . $s_season . ' WHERE season_id = ' . $i_season_id; $this->GetDataConnection()->query($s_sql); # update latest season $this->UpdateLatestSeason($i_competition_id); } } unset($o_result); }
<?php ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../classes/' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . "/../"); require_once 'context/stoolball-settings.class.php'; require_once 'data/mysql-connection.class.php'; require_once 'http/short-url-manager.class.php'; $settings = new StoolballSettings(); $db = new MySqlConnection($settings->DatabaseHost(), $settings->DatabaseUser(), $settings->DatabasePassword(), $settings->DatabaseName()); $short_url_manager = new ShortUrlManager($settings, $db); $real_url = $short_url_manager->ParseRequestUrl(); $db->Disconnect(); if (is_array($real_url)) { $hidden_get_vars = array_combine($real_url['param_names'], $real_url['param_values']); $_GET = array_merge($_GET, $hidden_get_vars); $_SERVER['PHP_SELF'] = '/' . $real_url['script']; require $real_url['script']; } else { # Hard-coded URLs which redirect to WordPress and so can't be in .htaccess if (strtolower(trim($_SERVER['REQUEST_URI'], '/')) == "insurance") { header("Location: /manage/insurance/"); exit; } # If page requested starting with /news, make WordPress think it was /category/news if (substr(strtolower(trim($_SERVER['REQUEST_URI'], '/')), 0, 4) == "news") { if ($_SERVER['REQUEST_URI'] == "/news") { $_SERVER['REQUEST_URI'] = "/news/"; } # Keeps the /category bit invisible if just /news requested $_SERVER['REQUEST_URI'] = "/category" . $_SERVER['REQUEST_URI']; } # Does it look suspicious?
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Clubs matching the supplied ids. Teams will remain, unaffiliated with any Club. */ function Delete($a_ids) { # check parameter if (!is_array($a_ids)) { die('No Clubs to delete'); } # build query $s_club = $this->o_settings->GetTable('Club'); $s_ids = join(', ', $a_ids); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_sql = "SELECT short_url FROM {$s_club} WHERE club_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $url_manager->Delete($row->short_url); } $result->closeCursor(); unset($url_manager); # delete relationships to teams $s_sql = 'UPDATE nsa_team SET club_id = NULL WHERE club_id IN (' . $s_ids . ') '; $this->GetDataConnection()->query($s_sql); # delete club(s) $s_sql = 'DELETE FROM ' . $s_club . ' WHERE club_id IN (' . $s_ids . ') '; $result = $this->GetDataConnection()->query($s_sql); return $this->GetDataConnection()->GetAffectedRows(); }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Competitions matching the supplied ids */ function Delete($a_ids) { # check paramter if (!is_array($a_ids)) { die('No Competitions to delete'); } # build query $s_comp = $this->o_settings->GetTable('Competition'); $s_season = $this->o_settings->GetTable('Season'); $s_ids = join(', ', $a_ids); # get the seasons and use SeasonManager to deal with them $season_ids = array(); $s_sql = 'SELECT season_id FROM ' . $s_season . ' WHERE competition_id IN (' . $s_ids . ') '; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $season_ids[] = $row->season_id; } $result->closeCursor(); require_once 'stoolball/season-manager.class.php'; $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection()); $season_manager->Delete($season_ids); unset($season_manager); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_sql = "SELECT short_url FROM {$s_comp} WHERE competition_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); # delete competition(s) $s_sql = 'DELETE FROM ' . $s_comp . ' WHERE competition_id IN (' . $s_ids . ') '; $o_result = $this->GetDataConnection()->query($s_sql); return $this->GetDataConnection()->GetAffectedRows(); }