public function OnPreRender()
 {
     $by = $this->player->GetPlayerRole() == \Player::PLAYER ? ", " : " conceded by ";
     $this->AddControl('<h1><span property="schema:name">' . \Html::Encode($this->player->GetName()) . '</span>' . \Html::Encode($by . ' ' . $this->player->Team()->GetName() . $this->filter_description) . "</h1>");
     # When has this player played?
     $match_or_matches = $this->player->GetTotalMatches() == 1 ? " match" : " matches";
     $years = $this->player->GetPlayingYears();
     $filtered = "";
     if ($this->filter_description) {
         # If first played date is missing, the player came from PlayerManager because there were no statistics found
         if (!$this->filter_matched_nothing) {
             $filtered = " matching this filter";
         } else {
             $filtered = ", but none match this filter";
             $years = '';
         }
     }
     $team_name = '<span rel="schema:memberOf"><span about="' . \Html::Encode($this->player->Team()->GetLinkedDataUri()) . '" typeof="schema:SportsTeam"><a property="schema:name" rel="schema:url" href="' . \Html::Encode($this->player->Team()->GetNavigateUrl()) . "\">" . \Html::Encode($this->player->Team()->GetName()) . "</a></span></span>";
     if ($this->player->GetPlayerRole() == \Player::PLAYER) {
         if ($this->player->GetTotalMatches() == 0) {
             $played_total = " hasn't played any " . $match_or_matches;
         } else {
             $played_total = ' played <a href="/play/statistics/player-performances' . $this->filter_querystring . '">' . $this->player->GetTotalMatches() . $match_or_matches . '</a>';
         }
         $this->AddControl("<p>" . \Html::Encode($this->player->GetName()) . $played_total . " for {$team_name}{$filtered}{$years}.</p>");
         # Player of match
         if ($this->player->GetTotalPlayerOfTheMatchNominations() > 0) {
             $match_or_matches = $this->player->GetTotalPlayerOfTheMatchNominations() == 1 ? " match." : " matches.";
             $this->AddControl('<p>Nominated <a href="/play/statistics/player-of-match' . $this->filter_querystring . '">player of the match</a> in ' . $this->player->GetTotalPlayerOfTheMatchNominations() . $match_or_matches . "</p>");
         }
     } else {
         $this->AddControl("<p>{$team_name} recorded " . \Html::Encode($this->player->TotalRuns() . " " . strtolower($this->player->GetName()) . " in " . $this->player->GetTotalMatches() . $match_or_matches . "{$filtered}{$years}.") . "</p>");
     }
 }
 public function __construct(Player $player)
 {
     $this->searchable = new SearchItem("player", "player" . $player->GetId(), $player->GetPlayerUrl());
     $this->searchable->Description($player->GetPlayerDescription());
     $this->searchable->WeightOfType(20);
     if ($player->GetPlayerRole() == Player::PLAYER) {
         $this->searchable->Title($player->GetName() . ", " . $player->Team()->GetName());
         $this->searchable->WeightWithinType($player->GetTotalMatches());
     } else {
         $this->searchable->Title($player->GetName() . " conceded by " . $player->Team()->GetName());
     }
     $this->searchable->Keywords($this->searchable->Title());
 }
    public function OnPageLoad()
    {
        echo "<h1>" . htmlentities($this->GetPageTitle(), ENT_QUOTES, "UTF-8", false) . "</h1>";
        if ($this->add_player_already_exists) {
            ?>
            <p><a href="<?php 
            echo Html::Encode($this->player->GetPlayerUrl());
            ?>
"><?php 
            echo Html::Encode($this->player->GetName());
            ?>
</a> is already listed as a player.</p>
            <p>Return to <a href="<?php 
            echo Html::Encode($this->player->Team()->GetPlayersNavigateUrl());
            ?>
">players for <?php 
            echo Html::Encode($this->player->Team()->GetName());
            ?>
</a>.</p>
            <?php 
        } else {
            if ($this->player->GetPlayerRole() == Player::PLAYER) {
                $this->editor->SetDataObject($this->player);
                echo $this->editor;
            } else {
                ?>
Sorry, an extras player can't be renamed.<?php 
            }
        }
    }
 /**
  * @return void
  * @desc Re-build from data posted by this control the data object this control is editing
  */
 function BuildPostedDataObject()
 {
     $match = new Match($this->GetSettings());
     $match->SetId($this->GetDataObjectId());
     # Get match date
     $s_key = $this->GetNamingPrefix() . 'Date';
     if (isset($_POST[$s_key]) and strlen($_POST[$s_key]) and is_numeric($_POST[$s_key])) {
         $match->SetStartTime($_POST[$s_key]);
     }
     # Get team names
     $s_key = $this->GetNamingPrefix() . 'Home';
     if (isset($_POST[$s_key])) {
         $team_data = explode(MatchHighlightsEditControl::DATA_SEPARATOR, $_POST[$s_key], 2);
         if (count($team_data) == 2) {
             $o_home = new Team($this->GetSettings());
             $o_home->SetId($team_data[0]);
             $o_home->SetName($team_data[1]);
             $match->SetHomeTeam($o_home);
         }
     }
     $s_key = $this->GetNamingPrefix() . 'Away';
     if (isset($_POST[$s_key])) {
         $team_data = explode(MatchHighlightsEditControl::DATA_SEPARATOR, $_POST[$s_key], 2);
         if (count($team_data) == 2) {
             $o_away = new Team($this->GetSettings());
             $o_away->SetId($team_data[0]);
             $o_away->SetName($team_data[1]);
             $match->SetAwayTeam($o_away);
         }
     }
     # Get the result
     $s_key = $this->GetNamingPrefix() . 'Result';
     if (isset($_POST[$s_key])) {
         $s_result = $_POST[$s_key];
         if (strlen($s_result)) {
             $match->Result()->SetResultType($s_result);
         }
     }
     # Get players of the match. Fields to use depend on which radio button was selected.
     $s_key = $this->GetNamingPrefix() . 'POM';
     if (isset($_POST[$s_key])) {
         $pom_type = (int) $_POST[$s_key];
         if ($pom_type == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL) {
             $s_key = $this->GetNamingPrefix() . 'Player';
             if (isset($_POST[$s_key]) and $_POST[$s_key]) {
                 $player = new Player($this->GetSettings());
                 $player->SetName($_POST[$s_key]);
                 $s_key = $this->GetNamingPrefix() . 'PlayerTeam';
                 if (isset($_POST[$s_key])) {
                     $player->Team()->SetId($_POST[$s_key]);
                 }
                 $match->Result()->SetPlayerOfTheMatch($player);
             }
         } else {
             if ($pom_type == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY) {
                 $s_key = $this->GetNamingPrefix() . 'PlayerHome';
                 if (isset($_POST[$s_key]) and $_POST[$s_key]) {
                     $player = new Player($this->GetSettings());
                     $player->SetName($_POST[$s_key]);
                     $player->Team()->SetId($match->GetHomeTeamId());
                     $match->Result()->SetPlayerOfTheMatchHome($player);
                 }
                 $s_key = $this->GetNamingPrefix() . 'PlayerAway';
                 if (isset($_POST[$s_key]) and $_POST[$s_key]) {
                     $player = new Player($this->GetSettings());
                     $player->SetName($_POST[$s_key]);
                     $player->Team()->SetId($match->GetAwayTeamId());
                     $match->Result()->SetPlayerOfTheMatchAway($player);
                 }
             }
         }
     }
     $s_key = $this->GetNamingPrefix() . 'Comments';
     if (isset($_POST[$s_key])) {
         $match->SetNewComment($_POST[$s_key]);
     }
     $this->SetDataObject($match);
 }
 /**
  * @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);
 }
 /**
  * Helper to build basic info about a match from raw data
  *
  * @param Match $match
  * @param DataRow $row
  */
 private function BuildMatchSummary(Match $match, $row)
 {
     $match->SetId($row->match_id);
     if (isset($row->start_time)) {
         $match->SetStartTime($row->start_time);
     }
     if (isset($row->start_time_known)) {
         $match->SetIsStartTimeKnown($row->start_time_known);
     }
     if (isset($row->match_type)) {
         $match->SetMatchType($row->match_type);
     }
     if (isset($row->player_type_id)) {
         $match->SetPlayerType($row->player_type_id);
     }
     if (isset($row->qualification)) {
         $match->SetQualificationType($row->qualification);
     }
     if (isset($row->players_per_team)) {
         $match->SetMaximumPlayersPerTeam($row->players_per_team);
     }
     if (isset($row->max_tournament_teams)) {
         $match->SetMaximumTeamsInTournament($row->max_tournament_teams);
     }
     if (isset($row->tournament_spaces)) {
         $match->SetSpacesLeftInTournament($row->tournament_spaces);
     }
     if (isset($row->overs_per_innings)) {
         $match->SetOvers($row->overs_per_innings);
     }
     if (isset($row->match_title)) {
         $match->SetTitle($row->match_title);
     }
     if (isset($row->custom_title)) {
         $match->SetUseCustomTitle($row->custom_title);
     }
     if (isset($row->home_bat_first) and !is_null($row->home_bat_first)) {
         $match->Result()->SetHomeBattedFirst($row->home_bat_first);
     }
     if (isset($row->won_toss) and !is_null($row->won_toss)) {
         $match->Result()->SetTossWonBy($row->won_toss);
     }
     if (isset($row->home_runs)) {
         $match->Result()->SetHomeRuns($row->home_runs);
     }
     if (isset($row->home_wickets)) {
         $match->Result()->SetHomeWickets($row->home_wickets);
     }
     if (isset($row->away_runs)) {
         $match->Result()->SetAwayRuns($row->away_runs);
     }
     if (isset($row->away_wickets)) {
         $match->Result()->SetAwayWickets($row->away_wickets);
     }
     if (isset($row->home_points)) {
         $match->Result()->SetHomePoints($row->home_points);
     }
     if (isset($row->away_points)) {
         $match->Result()->SetAwayPoints($row->away_points);
     }
     if (isset($row->player_of_match_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_id);
         $player->SetName($row->player_of_match);
         $player->SetShortUrl($row->player_of_match_url);
         $player->Team()->SetId($row->player_of_match_team_id);
         $match->Result()->SetPlayerOfTheMatch($player);
     }
     if (isset($row->player_of_match_home_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_home_id);
         $player->SetName($row->player_of_match_home);
         $player->SetShortUrl($row->player_of_match_home_url);
         $player->Team()->SetId($row->player_of_match_home_team_id);
         $match->Result()->SetPlayerOfTheMatchHome($player);
     }
     if (isset($row->player_of_match_away_id)) {
         $player = new Player($this->GetSettings());
         $player->SetId($row->player_of_match_away_id);
         $player->SetName($row->player_of_match_away);
         $player->SetShortUrl($row->player_of_match_away_url);
         $player->Team()->SetId($row->player_of_match_away_team_id);
         $match->Result()->SetPlayerOfTheMatchAway($player);
     }
     if (isset($row->match_notes)) {
         $match->SetNotes($row->match_notes);
     }
     if (isset($row->short_url)) {
         $match->SetShortUrl($row->short_url);
     }
     if (isset($row->update_search) and $row->update_search == 1) {
         $match->SetSearchUpdateRequired();
     }
     if (isset($row->added_by) and is_numeric($row->added_by)) {
         $match->SetAddedBy(new User($row->added_by));
     }
     if (isset($row->match_result_id)) {
         $match->Result()->SetResultType($row->match_result_id);
     }
     if (isset($row->date_changed)) {
         $match->SetLastAudit(new AuditData($row->modified_by_id, $row->known_as, $row->date_changed));
     }
 }
    function OnPageLoad()
    {
        if (!$this->player instanceof Player) {
            echo new XhtmlElement('h1', 'Player already deleted');
            echo new XhtmlElement('p', "The player you're trying to delete does not exist or has already been deleted.");
            return;
        }
        echo new XhtmlElement('h1', 'Delete player: <cite>' . Html::Encode($this->player->GetName()) . '</cite>');
        if ($this->player->GetPlayerRole() != Player::PLAYER) {
            ?>
Sorry, an extras player can't be deleted.<?php 
            return;
        }
        if ($this->b_deleted) {
            echo "<p>" . Html::Encode($this->player->GetName()) . "'s information has been deleted.</p>\n\t\t\t<p><a href=\"" . Html::Encode($this->player->Team()->GetPlayersNavigateUrl()) . "\">List players for " . Html::Encode($this->player->Team()->GetName()) . "</a></p>";
        } else {
            $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
            if ($has_permission) {
                $s_detail = $this->player->GetName() . " has ";
                switch ($this->player->GetTotalMatches()) {
                    case 0:
                        $s_detail .= "not played any matches";
                        break;
                    case 1:
                        $s_detail .= "played one match";
                        break;
                    default:
                        $s_detail .= "played " . $this->player->GetTotalMatches() . " matches";
                        break;
                }
                $s_detail .= " for " . $this->player->Team()->GetName() . '. ';
                echo new XhtmlElement('p', Html::Encode($s_detail));
                ?>
<p>Deleting a player cannot be undone. Their scores and performances
will be removed from all match scorecards and statistics.</p>
<p>Are you sure you want to delete this player?</p>
<form action="<?php 
                echo Html::Encode($this->player->GetDeleteUrl());
                ?>
" method="post"
	class="deleteButtons">
<div><input type="submit" value="Delete player" name="delete" /> <input
	type="submit" value="Cancel" name="cancel" /></div>
</form>
				<?php 
                $this->AddSeparator();
                require_once 'stoolball/user-edit-panel.class.php';
                $panel = new UserEditPanel($this->GetSettings(), $this->player->GetName());
                $panel->AddLink("view this player", $this->player->GetPlayerUrl());
                $panel->AddLink("rename this player", $this->player->GetEditUrl());
                echo $panel;
            } else {
                ?>
<p>Sorry, you can't delete a player unless you're responsible for
updating their team.</p>
<p><a href="<?php 
                echo Html::Encode($this->player->GetPlayerUrl());
                ?>
">Go back to <?php 
                echo Html::Encode($this->player->GetName());
                ?>
's
profile</a></p>
				<?php 
            }
        }
    }
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => '', 'Bowling and fielding' => $this->player->GetPlayerUrl() . '/bowling');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     # Batting stats
     if ($this->player->TotalBattingInnings()) {
         //echo "<h2>Batting</h2>";
         # Overview table
         $batting_table = new XhtmlTable();
         $batting_table->SetCssClass("numeric");
         $batting_table->SetCaption("Batting");
         $batting_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', "Not out", "Runs", "50s", "100s", "Best", '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>'));
         $batting_heading_row->SetIsHeader(true);
         $batting_table->AddRow($batting_heading_row);
         $batting_table->AddRow(new XhtmlRow(array($this->player->TotalBattingInnings(), $this->player->NotOuts(), $this->player->TotalRuns(), $this->player->Fifties(), $this->player->Centuries(), $this->player->BestBatting(), is_null($this->player->BattingAverage()) ? "&#8211;" : $this->player->BattingAverage(), is_null($this->player->BattingStrikeRate()) ? "&#8211;" : $this->player->BattingStrikeRate())));
         echo $batting_table;
         if ($this->player->TotalBattingInnings()) {
             echo '<p class="statsViewAll"><a href="/play/statistics/individual-scores' . $querystring . '">Individual scores &#8211; view all and filter</a></p>';
         }
         ?>
         <span class="chart-js-template" id="score-spread-chart"></span>
         <span class="chart-js-template" id="batting-form-chart"></span>
         <span class="chart-js-template" id="dismissals-chart"></span>
         <?php 
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }
 /**
  * Read when and how often a player has played
  */
 public function ReadPlayerSummary()
 {
     $from = $this->FromFilteredPlayerStatistics() . " INNER JOIN nsa_team AS team ON nsa_player_match.team_id = team.team_id ";
     $where = "";
     $where = $this->ApplyFilters($where);
     if ($where) {
         $where = "WHERE " . substr($where, 3, strlen($where) - 3);
     }
     $sql = "SELECT player_id, player_name, player_role, player_url,\r\n\t\tteam.team_id, team.team_name, team.short_url AS team_short_url,\r\n\t\tCOUNT(nsa_player_match.match_id) AS total_matches, MIN(nsa_player_match.match_time) AS first_played, MAX(nsa_player_match.match_time) AS last_played\r\n\t\t{$from}\r\n\t\t{$where}\r\n\t\tGROUP BY nsa_player_match.player_id\r\n\t\tORDER BY player_name ASC";
     $data = array();
     $result = $this->GetDataConnection()->query($sql);
     if (!$this->GetDataConnection()->isError()) {
         while ($row = $result->fetch()) {
             $player = new Player($this->GetSettings());
             $player->SetId($row->player_id);
             $player->SetName($row->player_name);
             if (isset($row->total_matches)) {
                 $player->SetTotalMatches($row->total_matches);
             }
             if (isset($row->first_played)) {
                 $player->SetFirstPlayedDate($row->first_played);
             }
             if (isset($row->last_played)) {
                 $player->SetLastPlayedDate($row->last_played);
             }
             if (isset($row->player_role)) {
                 $player->SetPlayerRole($row->player_role);
             }
             if (isset($row->player_url)) {
                 $player->SetShortUrl($row->player_url);
             }
             $player->Team()->SetId($row->team_id);
             $player->Team()->SetName($row->team_name);
             if (isset($row->team_short_url)) {
                 $player->Team()->SetShortUrl($row->team_short_url);
             }
             $data[] = $player;
         }
     }
     $result->closeCursor();
     unset($result);
     return $data;
 }
 /**
  * Builds data posted on pages 2/3 back into a match object
  * @return Match
  */
 private function BuildPostedScorecard()
 {
     $match = new Match($this->GetSettings());
     $match->SetId($this->GetDataObjectId());
     # Must have data on which team is which, otherwise none of the rest makes sense
     # Team ids are essential for saving data, while team names and match title are
     # purely so they can be redisplayed if the page is invalid
     $key = "teams";
     if (!isset($_POST[$key]) or strpos($_POST[$key], ScorecardEditControl::DATA_SEPARATOR) === false) {
         return $match;
     }
     $teams = explode(ScorecardEditControl::DATA_SEPARATOR, $_POST[$key], 6);
     if (count($teams) != 6) {
         return $match;
     }
     switch ($teams[0]) {
         case "0":
             $match->Result()->SetHomeBattedFirst(false);
             $home_batting = $this->GetCurrentPage() == 3;
             break;
         case "1":
             $match->Result()->SetHomeBattedFirst(true);
             $home_batting = $this->GetCurrentPage() == 2;
             break;
         default:
             $home_batting = $this->GetCurrentPage() == 2;
     }
     $home_team = new Team($this->GetSettings());
     $home_team->SetId($teams[1]);
     $home_team->SetName($teams[2]);
     $match->SetHomeTeam($home_team);
     $away_team = new Team($this->GetSettings());
     $away_team->SetId($teams[3]);
     $away_team->SetName($teams[4]);
     $match->SetAwayTeam($away_team);
     $match->SetTitle($teams[5]);
     # Read posted batting data
     $key = "batRows";
     if (isset($_POST[$key])) {
         # This controls not only which fields are read, but also which are redisplayed on an invalid postback or for the next innings.
         $match->SetMaximumPlayersPerTeam(intval($_POST[$key]));
     }
     for ($i = 1; $i <= $match->GetMaximumPlayersPerTeam(); $i++) {
         $key = "batName{$i}";
         if (isset($_POST[$key])) {
             # The row exists - has it been filled in?
             if (trim($_POST[$key])) {
                 # Read the batter data in this row
                 $player = new Player($this->GetSettings());
                 $player->SetName($_POST[$key]);
                 $player->Team()->SetId($home_batting ? $home_team->GetId() : $away_team->GetId());
                 $key = "batHowOut{$i}";
                 $how_out = (isset($_POST[$key]) and is_numeric($_POST[$key])) ? (int) $_POST[$key] : null;
                 $key = "batOutBy{$i}";
                 $dismissed_by = null;
                 if (isset($_POST[$key]) and trim($_POST[$key])) {
                     $dismissed_by = new Player($this->GetSettings());
                     $dismissed_by->SetName($_POST[$key]);
                     $dismissed_by->Team()->SetId($home_batting ? $away_team->GetId() : $home_team->GetId());
                 }
                 $key = "batBowledBy{$i}";
                 $bowler = null;
                 if (isset($_POST[$key]) and trim($_POST[$key])) {
                     $bowler = new Player($this->GetSettings());
                     $bowler->SetName($_POST[$key]);
                     $bowler->Team()->SetId($home_batting ? $away_team->GetId() : $home_team->GetId());
                 }
                 # Correct caught and bowled if marked as caught
                 if ($how_out == Batting::CAUGHT and !is_null($dismissed_by) and !is_null($bowler) and trim($dismissed_by->GetName()) == trim($bowler->GetName())) {
                     $how_out = Batting::CAUGHT_AND_BOWLED;
                     $dismissed_by = null;
                 }
                 $key = "batRuns{$i}";
                 $runs = (isset($_POST[$key]) and is_numeric($_POST[$key])) ? (int) $_POST[$key] : null;
                 $key = "batBalls{$i}";
                 $balls = (isset($_POST[$key]) and is_numeric($_POST[$key])) ? (int) $_POST[$key] : null;
                 # Add that batting performance to the match result
                 $batting = new Batting($player, $how_out, $dismissed_by, $bowler, $runs, $balls);
                 if ($home_batting) {
                     $match->Result()->HomeBatting()->Add($batting);
                 } else {
                     $match->Result()->AwayBatting()->Add($batting);
                 }
             }
         }
     }
     $key = "batByes";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         $player = new Player($this->GetSettings());
         $player->SetPlayerRole(Player::BYES);
         $player->Team()->SetId($home_batting ? $home_team->GetId() : $away_team->GetId());
         $batting = new Batting($player, null, null, null, (int) $_POST[$key]);
         if ($home_batting) {
             $match->Result()->HomeBatting()->Add($batting);
         } else {
             $match->Result()->AwayBatting()->Add($batting);
         }
     }
     $key = "batWides";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         $player = new Player($this->GetSettings());
         $player->SetPlayerRole(Player::WIDES);
         $player->Team()->SetId($home_batting ? $home_team->GetId() : $away_team->GetId());
         $batting = new Batting($player, null, null, null, (int) $_POST[$key]);
         if ($home_batting) {
             $match->Result()->HomeBatting()->Add($batting);
         } else {
             $match->Result()->AwayBatting()->Add($batting);
         }
     }
     $key = "batNoBalls";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         $player = new Player($this->GetSettings());
         $player->SetPlayerRole(Player::NO_BALLS);
         $player->Team()->SetId($home_batting ? $home_team->GetId() : $away_team->GetId());
         $batting = new Batting($player, null, null, null, (int) $_POST[$key]);
         if ($home_batting) {
             $match->Result()->HomeBatting()->Add($batting);
         } else {
             $match->Result()->AwayBatting()->Add($batting);
         }
     }
     $key = "batBonus";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         $player = new Player($this->GetSettings());
         $player->SetPlayerRole(Player::BONUS_RUNS);
         $player->Team()->SetId($home_batting ? $home_team->GetId() : $away_team->GetId());
         $batting = new Batting($player, null, null, null, (int) $_POST[$key]);
         if ($home_batting) {
             $match->Result()->HomeBatting()->Add($batting);
         } else {
             $match->Result()->AwayBatting()->Add($batting);
         }
     }
     $key = "batTotal";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         if ($home_batting) {
             $match->Result()->SetHomeRuns($_POST[$key]);
         } else {
             $match->Result()->SetAwayRuns($_POST[$key]);
         }
     }
     $key = "batWickets";
     if (isset($_POST[$key]) and is_numeric($_POST[$key])) {
         if ($home_batting) {
             $match->Result()->SetHomeWickets($_POST[$key]);
         } else {
             $match->Result()->SetAwayWickets($_POST[$key]);
         }
     }
     # Read posted bowling data
     $key = "bowlerRows";
     if (isset($_POST[$key])) {
         # This controls not only which fields are read, but also which are redisplayed on an invalid postback or for the next innings.
         $match->SetOvers(intval($_POST[$key]));
     }
     for ($i = 1; $i <= $match->GetOvers(); $i++) {
         $key = "bowlerName{$i}";
         if (isset($_POST[$key])) {
             # The row exists - has it been filled in?
             if (trim($_POST[$key])) {
                 # Read the bowler data in this row
                 # strlen test allows 0 but not empty string, because is_numeric allows empty string
                 $player = new Player($this->GetSettings());
                 $player->SetName($_POST[$key]);
                 $player->Team()->SetId($home_batting ? $away_team->GetId() : $home_team->GetId());
                 $key = "bowlerBalls{$i}";
                 $balls = (isset($_POST[$key]) and is_numeric($_POST[$key]) and strlen(trim($_POST[$key]))) ? (int) $_POST[$key] : null;
                 $key = "bowlerNoBalls{$i}";
                 $no_balls = (isset($_POST[$key]) and is_numeric($_POST[$key]) and strlen(trim($_POST[$key]))) ? (int) $_POST[$key] : null;
                 $key = "bowlerWides{$i}";
                 $wides = (isset($_POST[$key]) and is_numeric($_POST[$key]) and strlen(trim($_POST[$key]))) ? (int) $_POST[$key] : null;
                 $key = "bowlerRuns{$i}";
                 $runs = (isset($_POST[$key]) and is_numeric($_POST[$key]) and strlen(trim($_POST[$key]))) ? (int) $_POST[$key] : null;
                 # Add that over to the match result
                 $bowling = new Over($player);
                 $bowling->SetBalls($balls);
                 $bowling->SetNoBalls($no_balls);
                 $bowling->SetWides($wides);
                 $bowling->SetRunsInOver($runs);
                 if ($home_batting) {
                     $match->Result()->AwayOvers()->Add($bowling);
                 } else {
                     $match->Result()->HomeOvers()->Add($bowling);
                 }
             }
         }
     }
     return $match;
 }
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => $this->player->GetPlayerUrl(), 'Bowling and fielding' => '');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     if ($this->player->Bowling()->GetCount()) {
         //			echo "<h2>Bowling</h2>";
         # Overview table
         $bowling_table = new XhtmlTable();
         $bowling_table->SetCssClass("numeric");
         $bowling_table->SetCaption("Bowling");
         $bowling_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', '<abbr title="Overs" class="small">Ov</abbr><span class="large">Overs</span>', '<abbr title="Maiden overs" class="small">Md</abbr><abbr title="Maiden overs" class="large">Mdns</abbr>', "Runs", '<abbr title="Wickets" class="small">Wk</abbr><abbr title="Wickets" class="large">Wkts</abbr>', "Best", '<abbr title="Economy" class="small">Econ</abbr><span class="large">Economy</span>', '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>', '<abbr title="5 wickets" class="small">5 wk</abbr><abbr title="5 wickets" class="large">5 wkts</abbr>'));
         $bowling_heading_row->SetIsHeader(true);
         $bowling_table->AddRow($bowling_heading_row);
         $bowling_table->AddRow(new XhtmlRow(array($this->player->BowlingInnings(), $this->player->Overs(), $this->player->MaidenOvers(), $this->player->RunsAgainst(), $this->player->WicketsTaken(), is_null($this->player->BestBowling()) ? "&#8211;" : $this->player->BestBowling(), is_null($this->player->BowlingEconomy()) ? "&#8211;" : $this->player->BowlingEconomy(), is_null($this->player->BowlingAverage()) ? "&#8211;" : $this->player->BowlingAverage(), is_null($this->player->BowlingStrikeRate()) ? "&#8211;" : $this->player->BowlingStrikeRate(), $this->player->FiveWicketHauls())));
         echo $bowling_table;
         echo '<p class="statsViewAll"><a href="/play/statistics/bowling-performances' . $querystring . '">Bowling performances &#8211; view all and filter</a></p>';
     }
     ?>
     <span class="chart-js-template" id="economy-chart"></span>
     <span class="chart-js-template" id="bowling-average-chart"></span>
     <span class="chart-js-template" id="wickets-chart"></span>
     <?php 
     # Fielding
     $catches = $this->player->GetCatches();
     $run_outs = $this->player->GetRunOuts();
     if ($catches or $run_outs) {
         $fielding_table = new XhtmlTable();
         $fielding_table->SetCssClass("numeric");
         $fielding_table->SetCaption("Fielding");
         $fielding_heading_row = new XhtmlRow(array('Catches', "Run-outs"));
         $fielding_heading_row->SetIsHeader(true);
         $fielding_table->AddRow($fielding_heading_row);
         $fielding_table->AddRow(new XhtmlRow(array($catches, $run_outs)));
         echo $fielding_table;
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }