public function OnPostback()
 {
     # Get the player info and store it
     $id = $this->player_manager->GetItemId($this->player);
     $this->player_manager->ReadPlayerById($id);
     $this->player = $this->player_manager->GetFirst();
     if (!$this->player instanceof Player) {
         # This can be the case if the back button is used to go back to the "player has been deleted" page.
         $this->b_deleted = true;
         return;
     }
     if ($this->player->GetPlayerRole() != Player::PLAYER) {
         http_response_code(401);
         return;
     }
     # Check whether cancel was clicked
     if (isset($_POST['cancel'])) {
         $this->Redirect($this->player->GetPlayerUrl());
     }
     # Check whether delete was clicked
     if (isset($_POST['delete'])) {
         # Check again that the requester has permission to delete this player
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             # Delete the player
             $this->player_manager->Delete(array($id));
             # Delete player's entry in the search engine
             $this->SearchIndexer()->DeleteFromIndexById("player" . $id);
             $this->SearchIndexer()->CommitChanges();
             # Note success
             $this->b_deleted = true;
         }
     }
 }
 /**
  * @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();
 }