function OnPageLoad()
 {
     if ($this->page_not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     echo "<h1>" . Html::Encode($this->GetPageTitle()) . "</h1>";
     require_once 'xhtml/navigation/tabs.class.php';
     $tabs = array('Summary' => $this->tournament->GetNavigateUrl(), 'Tournament statistics' => '');
     echo new Tabs($tabs);
     ?>
     <div class="box tab-box">
         <div class="dataFilter"></div>
         <div class="box-content">
     <?php 
     # See what stats we've got available
     require_once "_summary-data-found.php";
     if (!$has_player_stats) {
         echo "<p>There aren't any statistics for the " . htmlentities($this->tournament->GetTitle(), ENT_QUOTES, "UTF-8", false) . ' yet.</p>
         <p>To find out how to add them, see <a href="/play/manage/website/matches-and-results-why-you-should-add-yours/">Matches and results - why you should add yours</a>.</p>';
     } else {
         require_once "_summary-controls.php";
     }
     ?>
     </div>
     </div>
     <?php 
 }
 function OnPageLoad()
 {
     # Matches this page shouldn't edit are page not found
     if ($this->page_not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     echo "<h1>" . Html::Encode($this->GetPageTitle()) . "</h1>";
     require_once 'xhtml/navigation/tabs.class.php';
     $tabs = array('Summary' => $this->match->GetNavigateUrl());
     if ($this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         $tabs['Match statistics'] = '';
         $tabs['Tournament statistics'] = $this->match->GetTournament()->GetNavigateUrl() . '/statistics';
     } else {
         $tabs['Statistics'] = '';
     }
     echo new Tabs($tabs);
     ?>
     <div class="box tab-box">
         <div class="dataFilter"></div>
         <div class="box-content">
     <?php 
     if (!$this->has_statistics) {
         echo "<p>There aren't any statistics for " . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . ' yet.</p>
         <p>To find out how to add them, see <a href="/play/manage/website/matches-and-results-why-you-should-add-yours/">Matches and results - why you should add yours</a>.</p>';
     } else {
         ?>
         <div class="statsColumns">
             <div class="statsColumn">
         <div class="chart-js-template" id="worm-chart"></div>
         </div>
             <div class="statsColumn">
         <div class="chart-js-template" id="run-rate-chart"></div>
         </div>
         </div>
         <div class="statsColumns manhattan">
         <h2>Scores in each over</h2>
             <div class="statsColumn">
                 <div class="chart-js-template" id="manhattan-chart-first-innings"></div>
             </div>
             <div class="statsColumn">
                 <div class="chart-js-template" id="manhattan-chart-second-innings"></div>
             </div>
         </div>
         <?php 
     }
     ?>
     </div>
     </div>
     <?php 
 }
 public function OnPageLoad()
 {
     # Matches this page shouldn't edit are page not found
     if ($this->page_not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     $edit_or_update = ($this->b_user_is_match_admin or $this->b_user_is_match_owner) ? "Edit" : "Update";
     $step = " &#8211; step " . $this->editor->GetCurrentPage() . " of 4";
     echo new XhtmlElement('h1', "{$edit_or_update} " . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . $step);
     if ($this->IsValid()) {
         /* Create instruction panel */
         $panel = new XhtmlElement('div');
         $panel->SetCssClass('panel instructionPanel');
         $title_inner1 = new XhtmlElement('div', 'Fill in scorecards quickly:');
         $title = new XhtmlElement('h2', $title_inner1, "large");
         $panel->AddControl($title);
         $tab_tip = new XhtmlElement('ul');
         $tab_tip->AddControl(new XhtmlElement('li', 'Use the <span class="tab">tab</span> and up and down keys to move through the form', "large"));
         $tab_tip->AddControl(new XhtmlElement('li', 'Use the <span class="tab">tab</span> key to select a player\'s name from the suggestions', "large"));
         $tab_tip->AddControl(new XhtmlElement('li', "List everyone on the batting card, even if they didn't bat, so we know who played."));
         $tab_tip->AddControl(new XhtmlElement('li', 'Don\'t worry if you don\'t know &#8211; fill in what you can and leave the rest blank.'));
         $panel->AddControl($tab_tip);
         echo $panel;
     }
     # OK to edit the match
     $this->editor->SetDataObject($this->match);
     echo $this->editor;
 }
 public function OnPageLoad()
 {
     # Matches this page shouldn't edit are page not found
     if ($this->page_not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     $edit_or_update = ($this->b_user_is_match_admin or $this->b_user_is_match_owner) ? "Edit" : "Update";
     if ($this->match->GetStartTime() > gmdate('U') and !$this->b_user_is_match_admin and !$this->b_user_is_match_owner) {
         $step = "";
         # definitely only this step because match in future and can't change date
     } else {
         $step = " &#8211; step 1 of 4";
     }
     echo new XhtmlElement('h1', "{$edit_or_update} " . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . $step);
     # If result only there's room for a little help
     if (!$this->b_user_is_match_admin and !$this->b_user_is_match_owner) {
         /* Create instruction panel */
         $o_panel = new XhtmlElement('div');
         $o_panel->SetCssClass('panel instructionPanel');
         $o_title_inner1 = new XhtmlElement('div', 'Add your matches quickly:');
         $o_title = new XhtmlElement('h2', $o_title_inner1);
         $o_panel->AddControl($o_title);
         $o_tab_tip = new XhtmlElement('ul');
         $o_tab_tip->AddControl(new XhtmlElement('li', 'You can add runs, wickets and the winning team on the next few pages'));
         $o_tab_tip->AddControl(new XhtmlElement('li', 'Don\'t worry if you don\'t know &#8211; fill in what you can and leave the rest blank.'));
         $o_panel->AddControl($o_tab_tip);
         echo $o_panel;
     }
     # OK to edit the match
     $this->editor->SetDataObject($this->match);
     echo $this->editor;
 }
 public function __construct(Match $match)
 {
     $this->match = $match;
     $this->searchable = new SearchItem("match", "match" . $match->GetId(), $match->GetNavigateUrl());
     $this->searchable->Title($match->GetTitle() . ", " . $match->GetStartTimeFormatted(true, false));
     $this->searchable->Description($this->GetSearchDescription());
     $this->searchable->FullText($match->GetNotes());
     $this->searchable->RelatedLinksHtml('<ul>' . '<li><a href="' . $match->GetNavigateUrl() . '/statistics">Statistics</a></li>' . '<li><a href="' . $match->GetCalendarNavigateUrl() . '">Add to calendar</a></li>' . '<li><a href="' . $match->GetEditNavigateUrl() . '">Update result</a></li>' . '</ul>');
     # Assign more weight to newer matches
     $weight = $match->GetStartTime() / 60 / 60 / 24 / 365;
     $this->searchable->WeightWithinType($weight);
 }
 function OnPrePageLoad()
 {
     /* @var $match Match */
     # set page title
     if ($this->tournament instanceof Match) {
         $action = "Edit ";
         $this->SetPageTitle($action . $this->tournament->GetTitle() . ', ' . Date::BritishDate($this->tournament->GetStartTime()));
     } else {
         $this->SetPageTitle('Page not found');
     }
     $this->SetContentCssClass('matchEdit');
     $this->SetContentConstraint(StoolballPage::ConstrainText());
 }
 public function OnPageLoad()
 {
     # Matches this page shouldn't edit are page not found
     if ($this->page_not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     $edit_or_update = ($this->b_user_is_match_admin or $this->b_user_is_match_owner) ? "Edit" : "Update";
     echo new XhtmlElement('h1', "{$edit_or_update} " . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . " &#8211; step 4 of 4");
     # OK to edit the match
     $this->editor->SetDataObject($this->match);
     echo $this->editor;
 }
 function OnPrePageLoad()
 {
     /* @var $match Match */
     # set page title
     if ($this->tournament instanceof Match) {
         $this->SetPageTitle('Edit ' . $this->tournament->GetTitle() . ', ' . Date::BritishDate($this->tournament->GetStartTime()));
     } else {
         $this->SetPageTitle('Page not found');
     }
     $this->SetContentCssClass('matchEdit');
     $this->SetContentConstraint(StoolballPage::ConstrainText());
     $this->LoadClientScript('/scripts/tournament-edit-control-3.js');
 }
 function OnPrePageLoad()
 {
     if (!is_null($this->team)) {
         $this->SetPageTitle('Match results for ' . $this->team->GetName());
     } else {
         if (!is_null($this->season)) {
             $this->SetPageTitle('Match results for ' . $this->season->GetCompetitionName());
         } else {
             if (!is_null($this->tournament)) {
                 $this->SetPageTitle('Match results for ' . $this->tournament->GetTitle());
             }
         }
     }
     $this->LoadClientScript('/scripts/match-results-3.js');
     $this->LoadClientScript("/scripts/tiny_mce/jquery.tinymce.js");
     $this->LoadClientScript("/scripts/tinymce.js");
 }
 function OnPrePageLoad()
 {
     /* @var $match Match */
     # set page title
     if ($this->tournament instanceof Match) {
         $action = $this->adding ? "Add " : "Edit ";
         $this->SetPageTitle($action . $this->tournament->GetTitle() . ', ' . Date::BritishDate($this->tournament->GetStartTime()));
     } else {
         $this->SetPageTitle('Page not found');
     }
     $this->SetContentCssClass('matchEdit');
     $this->SetContentConstraint(StoolballPage::ConstrainText());
     $except = array();
     if ($this->tournament instanceof Match) {
         foreach ($this->tournament->GetAwayTeams() as $team) {
             $except[] = $team->GetId();
         }
     }
     $this->LoadClientScript("/scripts/lib/jquery-ui-1.8.11.custom.min.js");
     $this->LoadClientScript("/play/teams/suggest-teams.js.php?except=" . trim(implode(",", $except), ","));
     ?>
     <link rel="stylesheet" type="text/css" href="/css/custom-theme/jquery-ui-1.8.11.custom.css" media="all" />
     <?php 
 }
 /**
  * Creates the controls when the editor is in its season view
  *
  */
 private function CreateSeasonControls(Match $match, XhtmlElement $match_box)
 {
     /* @var $season Season */
     $css_class = 'TournamentEdit checkBoxList';
     if ($this->GetCssClass()) {
         $css_class .= ' ' . $this->GetCssClass();
     }
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass($css_class);
     $this->SetCssClass('');
     $match_outer_1->SetXhtmlId($this->GetNamingPrefix());
     $match_outer_2 = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     $heading = 'Select seasons';
     if ($this->show_step_number) {
         $heading .= ' &#8211; step 3 of 3';
     }
     $o_title_inner_1 = new XhtmlElement('span', $heading);
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "large"));
     # Preserve match title, because we need it to send the email when the seasons are saved
     $title = new TextBox($this->GetNamingPrefix() . 'Title', $match->GetTitle(), $this->IsValidSubmit());
     $title->SetMode(TextBoxMode::Hidden());
     $match_box->AddControl($title);
     # If the list of seasons includes ones in which the only match type is tournament, then
     # they're annual tournaments like Expo and Seaford. Although those tournaments can be listed
     # in other seasons (they're of interest to the league teams), we don't want other tournaments
     # listed on pages which are supposed to be just about those annual tournaments. So exclude them
     # from the collection of possible seasons. Next bit of code will add them back in for any
     # tournaments which actually are meant to be in those seasons.
     $seasons = $this->seasons->GetItems();
     $len = count($seasons);
     for ($i = 0; $i < $len; $i++) {
         # Make sure only seasons which contain tournaments are listed. Necessary to include all match types
         # in the Seasons() collection from the database so that we can test what other match types seasons support.
         if (!$seasons[$i]->MatchTypes()->Contains(MatchType::TOURNAMENT)) {
             unset($seasons[$i]);
             continue;
         }
         if ($seasons[$i]->MatchTypes()->GetCount() == 1 and $seasons[$i]->MatchTypes()->GetFirst() == MatchType::TOURNAMENT) {
             unset($seasons[$i]);
         }
     }
     $this->seasons->SetItems($seasons);
     # If the list of possible seasons doesn't include the one(s) the match is already in,
     # or the ones the context team plays in, add those to the list of possibles
     $a_season_ids = array();
     foreach ($this->seasons as $season) {
         $a_season_ids[] = $season->GetId();
     }
     foreach ($match->Seasons() as $season) {
         if (!in_array($season->GetId(), $a_season_ids, true)) {
             $this->seasons->Insert($season);
             $a_season_ids[] = $season->GetId();
         }
     }
     if (isset($this->context_team)) {
         $match_year = Date::Year($match->GetStartTime());
         foreach ($this->context_team->Seasons() as $team_in_season) {
             /* @var $team_in_season TeamInSeason */
             if (!in_array($team_in_season->GetSeasonId(), $a_season_ids, true) and ($team_in_season->GetSeason()->GetStartYear() == $match_year or $team_in_season->GetSeason()->GetEndYear() == $match_year)) {
                 $this->seasons->Insert($team_in_season->GetSeason());
                 $a_season_ids[] = $team_in_season->GetSeasonId();
             }
         }
     }
     require_once 'xhtml/forms/checkbox.class.php';
     $seasons_list = '';
     if ($this->seasons->GetCount()) {
         # Sort the seasons by name, because they've been messed up by the code above
         $this->seasons->SortByProperty('GetCompetitionName');
         $match_box->AddControl(new XhtmlElement('p', 'Tick all the places we should list your tournament:'));
         $match_box->AddControl('<div class="radioButtonList">');
         foreach ($this->seasons as $season) {
             # Select season if it's one of the seasons the match is already in
             $b_season_selected = false;
             foreach ($match->Seasons() as $match_season) {
                 $b_season_selected = ($b_season_selected or $match_season->GetId() == $season->GetId());
             }
             /* @var $season Season */
             $box = new CheckBox($this->GetNamingPrefix() . 'Season' . $season->GetId(), $season->GetCompetitionName(), $season->GetId(), $b_season_selected, $this->IsValidSubmit());
             $seasons_list .= $season->GetId() . ';';
             $match_box->AddControl($box);
         }
         $match_box->AddControl('</div>');
         # Remember all the season ids to make it much easier to find the data on postback
         $seasons = new TextBox($this->GetNamingPrefix() . 'Seasons', $seasons_list, $this->IsValidSubmit());
         $seasons->SetMode(TextBoxMode::Hidden());
         $match_box->AddControl($seasons);
     } else {
         $match_month = 'in ' . Date::MonthAndYear($match->GetStartTime());
         $type = strtolower(PlayerType::Text($match->GetPlayerType()));
         $match_box->AddControl(new XhtmlElement('p', "Unfortunately we don't have details of any {$type} competitions {$match_month} to list your tournament in."));
         $match_box->AddControl(new XhtmlElement('p', 'Please click \'Save tournament\' to continue.'));
     }
 }
 /**
  * Creates the controls to edit the matches
  *
  */
 private function CreateMatchControls(Match $tournament, XhtmlElement $box)
 {
     $css_class = 'TournamentEdit';
     $box->SetCssClass($css_class);
     $this->SetCssClass('');
     $box->SetXhtmlId($this->GetNamingPrefix());
     $this->AddControl($box);
     # Preserve tournament title and date, because we need them for the page title when "add" is clicked
     $title = new TextBox($this->GetNamingPrefix() . 'Title', $tournament->GetTitle(), $this->IsValidSubmit());
     $title->SetMode(TextBoxMode::Hidden());
     $box->AddControl($title);
     $date = new TextBox($this->GetNamingPrefix() . 'Start', $tournament->GetStartTime(), $this->IsValidSubmit());
     $date->SetMode(TextBoxMode::Hidden());
     $box->AddControl($date);
     # Matches editor
     $this->EnsureAggregatedEditors();
     $this->matches_editor->DataObjects()->SetItems($tournament->GetMatchesInTournament());
     $this->matches_editor->SetTeams($tournament->GetAwayTeams());
     $box->AddControl($this->matches_editor);
 }
 /**
  * Creates the controls when the editor is in its fixture view
  *
  */
 private function CreateFixtureControls(Match $match, XhtmlElement $match_box)
 {
     $css_class = 'TournamentEdit';
     if ($this->GetCssClass()) {
         $css_class .= ' ' . $this->GetCssClass();
     }
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass($css_class);
     $this->SetCssClass('');
     $match_outer_1->SetXhtmlId($this->GetNamingPrefix());
     $match_outer_2 = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     if ($match->GetId()) {
         $heading = "Edit tournament";
     } else {
         $heading = "Add your tournament";
     }
     if ($this->show_step_number) {
         $heading .= ' &#8211; step 1 of 3';
     }
     $o_title_inner_1 = new XhtmlElement('span', $heading);
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "large"));
     # Tournament title
     $suggested_title = $match->GetTitle();
     if (isset($this->context_season)) {
         $suggested_title = $this->GetContextSeason()->GetCompetition()->GetName();
         if (strpos(strtolower($suggested_title), 'tournament') === false) {
             $suggested_title .= ' tournament';
         }
     } else {
         if (isset($this->context_team)) {
             $suggested_title = $this->GetContextTeam()->GetName();
             if (strpos(strtolower($suggested_title), 'tournament') === false) {
                 $suggested_title .= ' tournament';
             }
         }
     }
     if ($suggested_title == "To be confirmed tournament") {
         $suggested_title = "";
     }
     if ($suggested_title == "To be confirmed v To be confirmed") {
         $suggested_title = "";
     }
     $title = new TextBox($this->GetNamingPrefix() . 'Title', $suggested_title, $this->IsValidSubmit());
     $title->SetMaxLength(200);
     $match_box->AddControl(new FormPart('Tournament name', $title));
     # Open or invite?
     require_once 'xhtml/forms/radio-button.class.php';
     $qualify_set = new XhtmlElement('fieldset');
     $qualify_set->SetCssClass('formPart radioButtonList');
     $qualify_set->AddControl(new XhtmlElement('legend', 'Who can play?', 'formLabel'));
     $qualify_radios = new XhtmlElement('div', null, 'formControl');
     $qualify_set->AddControl($qualify_radios);
     $qualify_radios->AddControl(new RadioButton($this->GetNamingPrefix() . 'Open', $this->GetNamingPrefix() . 'Qualify', 'any team may enter', MatchQualification::OPEN_TOURNAMENT, $match->GetQualificationType() === MatchQualification::OPEN_TOURNAMENT or !$match->GetId(), $this->IsValidSubmit()));
     $qualify_radios->AddControl(new RadioButton($this->GetNamingPrefix() . 'Qualify', $this->GetNamingPrefix() . 'Qualify', 'only invited or qualifying teams can enter', MatchQualification::CLOSED_TOURNAMENT, $match->GetQualificationType() === MatchQualification::CLOSED_TOURNAMENT, $this->IsValidSubmit()));
     $match_box->AddControl($qualify_set);
     # Player type
     $suggested_type = 2;
     if (isset($this->context_season)) {
         $suggested_type = $this->context_season->GetCompetition()->GetPlayerType();
     } elseif (isset($this->context_team)) {
         $suggested_type = $this->context_team->GetPlayerType();
     }
     if (!is_null($match->GetPlayerType())) {
         $suggested_type = $match->GetPlayerType();
     }
     # Saved value overrides suggestion
     $player_set = new XhtmlElement('fieldset');
     $player_set->SetCssClass('formPart radioButtonList');
     $player_set->AddControl(new XhtmlElement('legend', 'Type of teams', 'formLabel'));
     $player_radios = new XhtmlElement('div', null, 'formControl');
     $player_set->AddControl($player_radios);
     $player_radios_1 = new XhtmlElement('div', null, 'column');
     $player_radios_2 = new XhtmlElement('div', null, 'column');
     $player_radios->AddControl($player_radios_1);
     $player_radios->AddControl($player_radios_2);
     $player_radios_1->AddControl(new RadioButton($this->GetNamingPrefix() . 'Ladies', $this->GetNamingPrefix() . 'PlayerType', 'Ladies', 2, $suggested_type === 2, $this->IsValidSubmit()));
     $player_radios_1->AddControl(new RadioButton($this->GetNamingPrefix() . 'Mixed', $this->GetNamingPrefix() . 'PlayerType', 'Mixed', 1, $suggested_type === 1, $this->IsValidSubmit()));
     $player_radios_2->AddControl(new RadioButton($this->GetNamingPrefix() . 'Girls', $this->GetNamingPrefix() . 'PlayerType', 'Junior girls', 5, $suggested_type === 5, $this->IsValidSubmit()));
     $player_radios_2->AddControl(new RadioButton($this->GetNamingPrefix() . 'Children', $this->GetNamingPrefix() . 'PlayerType', 'Junior mixed', 4, $suggested_type === 6, $this->IsValidSubmit()));
     $match_box->AddControl($player_set);
     # How many?
     $per_side_box = new XhtmlSelect($this->GetNamingPrefix() . "Players", null, $this->IsValid());
     $per_side_box->SetBlankFirst(true);
     for ($i = 6; $i <= 16; $i++) {
         $per_side_box->AddControl(new XhtmlOption($i));
     }
     if ($match->GetIsMaximumPlayersPerTeamKnown()) {
         $per_side_box->SelectOption($match->GetMaximumPlayersPerTeam());
     } else {
         if (!$match->GetId()) {
             # Use eight as sensible default for new tournaments
             $per_side_box->SelectOption(8);
         }
     }
     $players_per_team = new XhtmlElement("label", $per_side_box);
     $players_per_team->AddAttribute("for", $this->GetNamingPrefix() . "Players");
     $players_per_team->AddControl(" players per team");
     $players_part = new FormPart("How many players?", $players_per_team);
     $players_part->AddCssClass("playersPerTeam");
     $match_box->AddControl($players_part);
     # Overs
     $overs_box = new XhtmlSelect($this->GetNamingPrefix() . "Overs", null, $this->IsValid());
     $overs_box->SetBlankFirst(true);
     for ($i = 2; $i <= 8; $i++) {
         $overs_box->AddControl(new XhtmlOption($i));
     }
     if ($match->GetIsOversKnown()) {
         $overs_box->SelectOption($match->GetOvers());
     }
     $overs_label = new XhtmlElement("label", "Overs per innings");
     $overs_label->AddAttribute("for", $overs_box->GetXhtmlId());
     $overs_part = new FormPart($overs_label, new XhtmlElement("div", $overs_box));
     $overs_part->AddCssClass("overs");
     $match_box->AddControl($overs_part);
     # Start date and time
     if (!$match->GetStartTime()) {
         # if no date set, use specified default
         if ($this->i_default_time) {
             $match->SetStartTime($this->i_default_time);
         } else {
             # if no date set and no default, default to today at 10.30am BST
             # NOTE that if this is a new tournament in an old season, this date won't be selected because the available
             # dates will be limited below and won't include today. It'll be the same day in the relevant year though.
             $i_now = gmdate('U');
             $match->SetStartTime(gmmktime(9, 30, 00, (int) gmdate('n', $i_now), (int) gmdate('d', $i_now), (int) gmdate('Y', $i_now)));
             $match->SetIsStartTimeKnown(true);
         }
     }
     $o_date = new DateControl($this->GetNamingPrefix() . 'Start', $match->GetStartTime(), $match->GetIsStartTimeKnown(), $this->IsValidSubmit());
     $o_date->SetShowTime(true);
     $o_date->SetRequireTime(false);
     $o_date->SetMinuteInterval(5);
     # if only one season to choose from, limit available dates to the length of that season
     if ($this->context_season instanceof Season) {
         if ($this->context_season->GetStartYear() == $this->context_season->GetEndYear()) {
             $i_mid_season = gmmktime(0, 0, 0, 6, 30, $this->context_season->GetStartYear());
         } else {
             $i_mid_season = gmmktime(0, 0, 0, 12, 31, $this->context_season->GetStartYear());
         }
         $season_dates = Season::SeasonDates($i_mid_season);
         $season_start_month = gmdate('n', $season_dates[0]);
         $season_end_month = gmdate('n', $season_dates[1]);
         if ($season_start_month) {
             $o_date->SetMonthStart($season_start_month);
         }
         if ($season_end_month) {
             $o_date->SetMonthEnd($season_end_month);
         }
         $season_start_year = $this->context_season->GetStartYear();
         $season_end_year = $this->context_season->GetEndYear();
         if ($season_start_year) {
             $o_date->SetYearStart($season_start_year);
         }
         if ($season_end_year) {
             $o_date->SetYearEnd($season_end_year);
         }
     }
     $o_date_part = new FormPart('When?', $o_date);
     $o_date_part->SetIsFieldset(true);
     $match_box->AddControl($o_date_part);
     # Where?
     $o_ground_list = new XhtmlSelect($this->GetNamingPrefix() . 'Ground');
     $o_ground_list->AddControl(new XhtmlOption("Don't know", -1));
     $o_ground_list->AddControl(new XhtmlOption('Not listed (type the address in the notes field)', -2));
     # Promote the most likely grounds to the top of the list
     $likely_ground_ids = array();
     if ($match->GetGroundId()) {
         $likely_ground_ids[] = $match->GetGroundId();
     }
     foreach ($this->probable_teams as $o_team) {
         $likely_ground_ids[] = $o_team->GetGround()->GetId();
     }
     if (isset($this->context_season)) {
         foreach ($this->context_season->GetTeams() as $o_team) {
             $likely_ground_ids[] = $o_team->GetGround()->GetId();
         }
     }
     if (isset($this->context_team) and is_object($this->context_team->GetGround())) {
         $likely_ground_ids[] = $this->context_team->GetGround()->GetId();
     }
     $likely_grounds = array();
     $a_other_grounds = array();
     /* @var $o_ground Ground */
     foreach ($this->grounds->GetItems() as $o_ground) {
         if (array_search($o_ground->GetId(), $likely_ground_ids) > -1) {
             $likely_grounds[] = $o_ground;
         } else {
             $a_other_grounds[] = $o_ground;
         }
     }
     # Add home grounds
     foreach ($likely_grounds as $o_ground) {
         $option = new XhtmlOption($o_ground->GetNameAndTown(), $o_ground->GetId());
         $option->SetGroupName('Likely grounds');
         $o_ground_list->AddControl($option);
     }
     # Add away grounds
     foreach ($a_other_grounds as $o_ground) {
         $option = new XhtmlOption($o_ground->GetNameAndTown(), $o_ground->GetId());
         $option->SetGroupName('Other grounds');
         $o_ground_list->AddControl($option);
     }
     # Select ground
     if ($match->GetGroundId()) {
         $o_ground_list->SelectOption($match->GetGroundId());
     } elseif (isset($this->context_team)) {
         $o_ground_list->SelectOption($this->context_team->GetGround()->GetId());
     }
     $o_ground_part = new FormPart('Where?', $o_ground_list);
     $match_box->AddControl($o_ground_part);
     # Notes
     $o_notes = new TextBox($this->GetNamingPrefix() . 'Notes', $match->GetNotes());
     $o_notes->SetMode(TextBoxMode::MultiLine());
     $o_notes_part = new FormPart('Notes<br />(remember to include contact details)', $o_notes);
     $match_box->AddControl($o_notes_part);
     # Remember short URL
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $match->GetShortUrl());
     $o_short_url->SetMode(TextBoxMode::Hidden());
     $match_box->AddControl($o_short_url);
     # Note the context team to be added to the tournament by default
     if (isset($this->context_team)) {
         $context_team_box = new TextBox($this->GetNamingPrefix() . 'ContextTeam', $this->context_team->GetId());
         $context_team_box->SetMode(TextBoxMode::Hidden());
         $match_box->AddControl($context_team_box);
     }
     # Change Save button to "Next" button
     if ($this->show_step_number) {
         $this->SetButtonText('Next &raquo;');
     }
 }
    /**
     * @return void
     * @param Match $o_match
     * @desc Save the result and player(s) of the match to the database
     */
    public function SaveHighlights(Match $o_match)
    {
        # To add a result there must always already be a match to update
        if (!$o_match->GetId()) {
            return;
        }
        require_once "stoolball/player-manager.class.php";
        $player_manager = new PlayerManager($this->GetSettings(), $this->GetDataConnection());
        # build query
        $s_match = $this->GetSettings()->GetTable('Match');
        $statistics = $this->GetSettings()->GetTable('PlayerMatch');
        $i_result = $o_match->Result()->GetResultType() <= 0 ? null : $o_match->Result()->GetResultType();
        $player_of_match = $player_manager->SaveOrMatchPlayer($o_match->Result()->GetPlayerOfTheMatch());
        $player_of_match_home = $player_manager->SaveOrMatchPlayer($o_match->Result()->GetPlayerOfTheMatchHome());
        $player_of_match_away = $player_manager->SaveOrMatchPlayer($o_match->Result()->GetPlayerOfTheMatchAway());
        # Check whether anything's changed and don't re-save if not
        $s_sql = 'SELECT match_id FROM ' . $s_match . ' ';
        $s_where = $this->SqlAddCondition("", 'match_result_id' . Sql::ProtectNumeric($i_result, true, true));
        $s_where = $this->SqlAddCondition($s_where, 'player_of_match_id ' . Sql::ProtectNumeric($player_of_match, true, true));
        $s_where = $this->SqlAddCondition($s_where, 'player_of_match_home_id ' . Sql::ProtectNumeric($player_of_match_home, true, true));
        $s_where = $this->SqlAddCondition($s_where, 'player_of_match_away_id ' . Sql::ProtectNumeric($player_of_match_away, true, true));
        $s_where = $this->SqlAddCondition($s_where, 'match_id = ' . Sql::ProtectNumeric($o_match->GetId()));
        $s_sql = $this->SqlAddWhereClause($s_sql, $s_where);
        $o_result = $this->GetDataConnection()->query($s_sql);
        if ($o_result->fetch()) {
            return;
        }
        # Should the match_title be regenerated?
        $s_sql = "SELECT custom_title FROM {$s_match} WHERE {$s_match}.match_id = " . Sql::ProtectNumeric($o_match->GetId());
        $o_result = $this->GetDataConnection()->query($s_sql);
        $o_row = $o_result->fetch();
        if (!is_null($o_row)) {
            $o_match->SetUseCustomTitle($o_row->custom_title);
        }
        # Save IDs of players affected by any change
        $affected_players = array();
        if (!is_null($player_of_match)) {
            $affected_players[] = $player_of_match;
        }
        if (!is_null($player_of_match_home)) {
            $affected_players[] = $player_of_match_home;
        }
        if (!is_null($player_of_match_away)) {
            $affected_players[] = $player_of_match_away;
        }
        $s_sql = "SELECT player_of_match_id, player_of_match_home_id, player_of_match_away_id FROM {$s_match} WHERE {$s_match}.match_id = " . Sql::ProtectNumeric($o_match->GetId());
        $o_result = $this->GetDataConnection()->query($s_sql);
        $row = $o_result->fetch();
        if (!is_null($row)) {
            if (!is_null($row->player_of_match_id)) {
                $affected_players[] = $row->player_of_match_id;
            }
            if (!is_null($row->player_of_match_home_id)) {
                $affected_players[] = $row->player_of_match_home_id;
            }
            if (!is_null($row->player_of_match_away_id)) {
                $affected_players[] = $row->player_of_match_away_id;
            }
        }
        # Update the main match record
        # All changes from here to master data are logged, because this method can be called from the public interface
        $sql = "UPDATE {$s_match} SET ";
        if (!$o_match->GetUseCustomTitle()) {
            $sql .= "match_title = " . Sql::ProtectString($this->GetDataConnection(), $o_match->GetTitle()) . ", ";
        }
        $sql .= 'match_result_id = ' . Sql::ProtectNumeric($i_result, true) . ",\r\n\t\t\tplayer_of_match_id = " . Sql::ProtectNumeric($player_of_match, true) . ', ' . "player_of_match_home_id = " . Sql::ProtectNumeric($player_of_match_home, true) . ', ' . "player_of_match_away_id = " . Sql::ProtectNumeric($player_of_match_away, true) . ', 
			update_search = 1,  
            date_changed = ' . gmdate('U') . ", \r\n            modified_by_id = " . Sql::ProtectNumeric(AuthenticationManager::GetUser()->GetId()) . ' ' . 'WHERE match_id = ' . Sql::ProtectNumeric($o_match->GetId());
        $this->LoggedQuery($sql);
        # Copy updated match to statistics
        require_once 'stoolball/statistics/statistics-manager.class.php';
        $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
        $statistics_manager->UpdateMatchDataInStatistics($this, $o_match->GetId());
        # Save IDs of players affected by any change
        if (count($affected_players)) {
            $statistics_manager->UpdatePlayerOfTheMatchStatistics($o_match->GetId());
            $statistics_manager->DeleteObsoleteStatistics($o_match->GetId());
            $statistics_manager->UpdatePlayerStatistics($affected_players);
        }
        unset($statistics_manager);
        # Match data has changed so notify moderator
        $this->QueueForNotification($o_match->GetId(), false);
    }
    /**
     * Helper to build and send the email when a match has been added by a public user
     *
     * @param Match $o_match
     * @param User $o_user
     * @param bool $b_is_new_match
     * @param bool $b_is_deleted_match
     * @param string $s_email
     * @param Season[] $seasons
     */
    private function SendMatchUpdatedEmail(Match $o_match, User $o_user, $b_is_new_match, $b_is_deleted_match, $s_email, $seasons = null)
    {
        # text of email
        $s_season_list = '';
        if (is_array($seasons)) {
            $i_total_seasons = count($seasons);
            for ($i = 0; $i < $i_total_seasons; $i++) {
                if ($i == 0) {
                    $s_season_list = "'" . $seasons[$i]->GetCompetitionName() . "'";
                } else {
                    if ($i == $i_total_seasons - 1) {
                        $s_season_list .= " and '" . $seasons[$i]->GetCompetitionName() . "'";
                    } else {
                        $s_season_list .= ", '" . $seasons[$i]->GetCompetitionName() . "'";
                    }
                }
            }
        }
        $s_season = $s_season_list ? " in the {$s_season_list}" : '';
        $s_why = $s_season_list ? $s_season_list : 'matches';
        $new = $b_is_new_match ? 'new ' : '';
        $verb = $b_is_new_match ? 'added' : 'updated';
        if ($b_is_deleted_match) {
            $verb = 'deleted';
        }
        $match_text = $o_match->GetMatchType() == MatchType::TOURNAMENT ? 'tournament' : 'match';
        $s_title = html_entity_decode($o_match->GetTitle());
        $s_date = ucfirst($o_match->GetStartTimeFormatted());
        $s_ground = is_object($o_match->GetGround()) ? $o_match->GetGround()->GetNameAndTown() : '';
        $s_notes = $o_match->GetNotes();
        $s_domain = $this->settings->GetDomain();
        $s_url = 'https://' . $s_domain . $o_match->GetNavigateUrl();
        $s_contact_url = 'https://' . $s_domain . $this->settings->GetFolder('Contact');
        $s_home_name = $o_match->GetMatchType() == MatchType::TOURNAMENT ? '' : html_entity_decode($o_match->GetHomeTeam()->GetName());
        $s_away_name = $o_match->GetMatchType() == MatchType::TOURNAMENT ? '' : html_entity_decode($o_match->GetAwayTeam()->GetName());
        $s_bat_first = is_null($o_match->Result()->GetHomeBattedFirst()) ? 'Not known which team batted first' : ($o_match->Result()->GetHomeBattedFirst() ? $s_home_name : $s_away_name) . ' batted first';
        $s_home_runs = is_null($o_match->Result()->GetHomeRuns()) ? '(not known)' : $o_match->Result()->GetHomeRuns();
        $s_home_wickets = is_null($o_match->Result()->GetHomeWickets()) ? '(not known)' : $o_match->Result()->GetHomeWickets();
        if ($s_home_wickets == -1) {
            $s_home_wickets = 'all out';
        } else {
            $s_home_wickets = 'for ' . $s_home_wickets . ' wickets';
        }
        $s_away_runs = is_null($o_match->Result()->GetAwayRuns()) ? '(not known)' : $o_match->Result()->GetAwayRuns();
        $s_away_wickets = is_null($o_match->Result()->GetAwayWickets()) ? '(not known)' : $o_match->Result()->GetAwayWickets();
        if ($s_away_wickets == -1) {
            $s_away_wickets = 'all out';
        } else {
            $s_away_wickets = 'for ' . $s_away_wickets . ' wickets';
        }
        $s_user = $o_user->GetName();
        $s_body = wordwrap("A {$new}{$match_text} has been {$verb} on the Stoolball England website at {$s_domain}{$s_season}.\n\n" . "The {$match_text} was {$verb} by {$s_user}.\n\n" . "The {$match_text} details are as follows:\n\n" . "    {$s_title}\n" . "    {$s_date}\n" . "    {$s_ground}");
        if ($s_notes) {
            $s_notes = "\n\n" . wordwrap($s_notes, 70);
            $s_notes = str_replace("\n", "\n    ", $s_notes);
            $s_body .= $s_notes;
        }
        if ($o_match->GetStartTime() <= gmdate('U') and !$b_is_new_match and $o_match->GetMatchType() != MatchType::TOURNAMENT) {
            $s_body .= <<<EMAILBODY


\t{$s_bat_first}
EMAILBODY;
            if ($o_match->Result()->GetHomeBattedFirst() === false) {
                $s_body .= <<<EMAILBODY

\t{$s_away_name} score: {$s_away_runs} runs {$s_away_wickets}
\t{$s_home_name} score: {$s_home_runs} runs {$s_home_wickets}
EMAILBODY;
            } else {
                $s_body .= <<<EMAILBODY

\t{$s_home_name} score: {$s_home_runs} runs {$s_home_wickets}
\t{$s_away_name} score: {$s_away_runs} runs {$s_away_wickets}
EMAILBODY;
            }
        }
        $s_body .= "\n\n";
        if (!$b_is_deleted_match) {
            $s_body .= wordwrap("You can view the {$match_text} at {$s_url}\n\n");
        }
        $s_body .= wordwrap("You have received this email because you are the administrative contact for {$s_why} on {$s_domain}.\n\n" . "We let you know when a {$match_text} is {$verb} by a member of the public, so that you can check there's nothing wrong.\n\n" . "If this email has been sent to the wrong address, or if the {$match_text} details are wrong, please let us know using the contact form at {$s_contact_url}.\n\n");
        # send email, copy to me
        require_once 'Zend/Mail.php';
        $o_email = new Zend_Mail('UTF-8');
        $o_email->addTo($s_email);
        $o_email->setFrom('*****@*****.**', 'Stoolball England alerts');
        $o_email->setSubject(ucfirst($match_text) . " {$verb}: {$s_title}, {$s_date}");
        $o_email->setBodyText($s_body);
        try {
            $o_email->send();
        } catch (Zend_Mail_Transport_Exception $e) {
            # Do nothing - failure to send this email should not be a fatal error
        }
    }
 private function CreateLinkToMatch(Match $match)
 {
     $text = $match->GetTitle();
     # Add player type for tournaments
     if ($match->GetPlayerType() and $match->GetMatchType() === MatchType::TOURNAMENT and strpos(strtolower($match->GetTitle()), strtolower(PlayerType::Text($match->GetPlayerType()))) === false) {
         $text .= ' (' . htmlentities(PlayerType::Text($match->GetPlayerType()), ENT_QUOTES, "UTF-8", false) . ')';
     }
     $link = new XhtmlAnchor();
     $link->AddControl(htmlentities($text, ENT_QUOTES, "UTF-8", false));
     $link->SetNavigateUrl($match->GetNavigateUrl());
     if ($this->b_microformats) {
         $link->SetCssClass('summary url');
         # hCalendar
         $link->AddAttribute("rel", "schema:url");
         $link->AddAttribute("property", "schema:name");
         $title_meta = new XhtmlElement('span', ' (stoolball)');
         $title_meta->SetCssClass('metadata');
         $link->AddControl($title_meta);
     }
     return $link;
 }
    function OnPageLoad()
    {
        if (!$this->match instanceof Match) {
            echo new XhtmlElement('h1', ucfirst($this->match_or_tournament) . ' already deleted');
            echo new XhtmlElement('p', "The " . $this->match_or_tournament . " you're trying to delete does not exist or has already been deleted.");
            return;
        }
        echo new XhtmlElement('h1', 'Delete ' . $this->match_or_tournament . ': <cite>' . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . '</cite>');
        if ($this->b_deleted) {
            ?>
			<p>The <?php 
            echo $this->match_or_tournament;
            ?>
 has been deleted.</p>
			<?php 
            if ($this->match->GetTournament() instanceof Match) {
                echo '<p><a href="' . htmlentities($this->match->GetTournament()->GetNavigateUrl(), ENT_QUOTES, "UTF-8", false) . '">Go to ' . htmlentities($this->match->GetTournament()->GetTitle(), ENT_QUOTES, "UTF-8", false) . '</a></p>';
            } else {
                if ($this->match->Seasons()->GetCount()) {
                    foreach ($this->match->Seasons() as $season) {
                        echo '<p><a href="' . htmlentities($season->GetNavigateUrl(), ENT_QUOTES, "UTF-8", false) . '">Go to ' . htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false) . '</a></p>';
                    }
                } else {
                    echo '<p><a href="/matches/">View all matches</a></p>';
                }
            }
        } else {
            $has_permission = (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES) or AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId());
            if ($has_permission) {
                $s_detail = 'This is a ' . MatchType::Text($this->match->GetMatchType());
                $s_detail .= $this->match->GetIsStartTimeKnown() ? ' starting at ' : ' on ';
                $s_detail .= $this->match->GetStartTimeFormatted() . '. ';
                $s_context = '';
                if ($this->match->GetTournament() instanceof Match) {
                    $s_context = "It's in the " . $this->match->GetTournament()->GetTitle();
                }
                if ($this->match->Seasons()->GetCount()) {
                    $season = $this->match->Seasons()->GetFirst();
                    $b_the = !(stristr($season->GetCompetitionName(), 'the ') === 0);
                    $s_context .= $s_context ? ', in ' : 'It\'s in ';
                    $s_context .= $b_the ? 'the ' : '';
                    if ($this->match->Seasons()->GetCount() == 1) {
                        $s_context .= $season->GetCompetitionName() . '.';
                    } else {
                        $s_context .= 'following seasons: ';
                    }
                }
                $s_detail .= $s_context;
                echo new XhtmlElement('p', htmlentities($s_detail, ENT_QUOTES, "UTF-8", false));
                if ($this->match->Seasons()->GetCount() > 1) {
                    $seasons = new XhtmlElement('ul');
                    foreach ($this->match->Seasons() as $season) {
                        $seasons->AddControl(new XhtmlElement('li', htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false)));
                    }
                    echo $seasons;
                }
                if ($this->match->GetMatchType() == MatchType::TOURNAMENT) {
                    ?>
					<p>Deleting a tournament cannot be undone.</p>
					<?php 
                } else {
                    ?>
					<p>Deleting a match cannot be undone. The match will be removed from all league tables and statistics.</p>
					<?php 
                }
                ?>
				<p>Are you sure you want to delete this <?php 
                echo $this->match_or_tournament;
                ?>
?</p>
				<form action="<?php 
                echo htmlentities($this->match->GetDeleteNavigateUrl(), ENT_QUOTES, "UTF-8", false);
                ?>
" method="post" class="deleteButtons">
				<div>
				<input type="submit" value="Delete <?php 
                echo $this->match_or_tournament;
                ?>
" 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 ' . $this->match_or_tournament);
                $panel->AddLink('view this ' . $this->match_or_tournament, $this->match->GetNavigateUrl());
                $panel->AddLink('edit this ' . $this->match_or_tournament, $this->match->GetEditNavigateUrl());
                echo $panel;
            } else {
                ?>
				<p>Sorry, you can't delete a <?php 
                echo $this->match_or_tournament;
                ?>
 unless you added it.</p>
				<p><a href="<?php 
                echo htmlentities($this->match->GetNavigateUrl(), ENT_QUOTES, "UTF-8", false);
                ?>
">Go back to <?php 
                echo $this->match_or_tournament;
                ?>
</a></p>
				<?php 
            }
        }
    }
    /**
     * Creates the controls when the editor is in its team view
     *
     */
    private function CreateTeamControls(Match $match, XhtmlElement $match_box)
    {
        $css_class = 'TournamentEdit';
        $match_box->SetCssClass($css_class);
        $this->SetCssClass('');
        $match_box->SetXhtmlId($this->GetNamingPrefix());
        $this->AddControl($match_box);
        # Preserve match title and date, because we need them for the page title when "add" is clicked
        $title = new TextBox($this->GetNamingPrefix() . 'Title', $match->GetTitle(), $this->IsValidSubmit());
        $title->SetMode(TextBoxMode::Hidden());
        $match_box->AddControl($title);
        $date = new TextBox($this->GetNamingPrefix() . 'Start', $match->GetStartTime(), $this->IsValidSubmit());
        $date->SetMode(TextBoxMode::Hidden());
        $match_box->AddControl($date);
        $match_box->AddControl(<<<HTML
        
        <div class="panel"><div><div>
            <h2 class="large"><span><span><span>How many teams do you have room for?</span></span></span></h2>
            <p>Tell us how many teams you have room for and who's coming, and we'll list your tournament with how many spaces are left.</p>
HTML
);
        $max = new TextBox($this->GetNamingPrefix() . 'MaxTeams', $match->GetMaximumTeamsInTournament(), $this->IsValidSubmit());
        $max->SetMode(TextBoxMode::Number());
        $max->SetCssClass('max-teams numeric');
        $match_box->AddControl(new FormPart("Maximum teams", new XhtmlElement('div', $max)));
        $match_box->AddControl("</div></div></div>");
        # Teams editor
        $this->EnsureAggregatedEditors();
        $this->teams_editor->DataObjects()->SetItems($match->GetAwayTeams());
        $match_box->AddControl($this->teams_editor);
        # Change Save button to "Next" button
        if ($this->show_step_number) {
            $this->SetButtonText('Next &raquo;');
        }
    }
    function OnPageLoad()
    {
        $is_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT;
        $class = $is_tournament ? "match" : "match vevent";
        ?>
        <div class="$class" typeof="schema:SportsEvent" about="<?php 
        echo Html::Encode($this->match->GetLinkedDataUri());
        ?>
">
        <?php 
        require_once 'xhtml/navigation/tabs.class.php';
        $tabs = array('Summary' => '');
        if ($is_tournament) {
            $tabs['Tournament statistics'] = $this->match->GetNavigateUrl() . '/statistics';
            # Make sure the reader knows this is a tournament, and the player type
            $says_tournament = strpos(strtolower($this->match->GetTitle()), 'tournament') !== false;
            $player_type = PlayerType::Text($this->match->GetPlayerType());
            $says_player_type = strpos(strtolower($this->match->GetTitle()), strtolower(rtrim($player_type, '\''))) !== false;
            $page_title = $this->match->GetTitle() . ", " . Date::BritishDate($this->match->GetStartTime(), false);
            if (!$says_tournament and !$says_player_type) {
                $page_title .= ' (' . $player_type . ' stoolball tournament)';
            } else {
                if (!$says_tournament) {
                    $page_title .= ' stoolball tournament';
                } else {
                    if (!$says_player_type) {
                        $page_title .= ' (' . $player_type . ')';
                    }
                }
            }
            $heading = new XhtmlElement('h1', $page_title);
            $heading->AddAttribute("property", "schema:name");
            echo $heading;
        } else {
            if ($this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
                $tabs['Match statistics'] = $this->match->GetNavigateUrl() . '/statistics';
                $tabs['Tournament statistics'] = $this->match->GetTournament()->GetNavigateUrl() . '/statistics';
                $page_title = $this->match->GetTitle() . " in the " . $this->match->GetTournament()->GetTitle();
            } else {
                $tabs['Statistics'] = $this->match->GetNavigateUrl() . '/statistics';
                $page_title = $this->match->GetTitle();
            }
            $o_title = new XhtmlElement('h1', Html::Encode($page_title));
            $o_title->AddAttribute("property", "schema:name");
            # hCalendar
            $o_title->SetCssClass('summary');
            $o_title_meta = new XhtmlElement('span', ' (stoolball)');
            $o_title_meta->SetCssClass('metadata');
            $o_title->AddControl($o_title_meta);
            if ($this->match->GetMatchType() !== MatchType::TOURNAMENT_MATCH) {
                $o_title->AddControl(", " . Date::BritishDate($this->match->GetStartTime(), false));
            }
            echo $o_title;
        }
        echo new Tabs($tabs);
        ?>
        <div class="box tab-box">
            <div class="dataFilter"></div>
            <div class="box-content">
        <?php 
        if ($is_tournament) {
            require_once 'stoolball/tournaments/tournament-control.class.php';
            echo new TournamentControl($this->GetSettings(), $this->match);
        } else {
            require_once 'stoolball/matches/match-control.class.php';
            echo new MatchControl($this->GetSettings(), $this->match);
        }
        $this->DisplayComments();
        $this->ShowSocial();
        ?>
            </div>
        </div>
        </div>
        <?php 
        $this->AddSeparator();
        # add/edit/delete options
        $user_is_admin = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES);
        $user_is_owner = AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId();
        $panel = new UserEditPanel($this->GetSettings(), 'this match');
        $panel->AddCssClass("with-tabs");
        if ($user_is_admin or $user_is_owner) {
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink('edit this ' . $link_text, $this->match->GetEditNavigateUrl());
        } else {
            if ($this->match->GetMatchType() != MatchType::PRACTICE and !$is_tournament) {
                $panel->AddLink('update result', $this->match->GetEditNavigateUrl());
            }
        }
        if ($is_tournament) {
            $panel->AddCssClass("with-tabs");
            if ($user_is_admin or $user_is_owner) {
                $panel->AddLink('add or remove teams', $this->match->EditTournamentTeamsUrl());
            }
            $panel->AddLink('add or remove matches', $this->match->GetEditTournamentMatchesUrl());
            if (count($this->match->GetMatchesInTournament())) {
                $panel->AddLink('update results', $this->match->GetNavigateUrl() . "/matches/results");
            }
        }
        if ($user_is_admin or $user_is_owner) {
            if ($is_tournament) {
                $panel->AddLink('edit where to list this tournament', $this->match->EditTournamentCompetitionsUrl());
            }
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink('delete this ' . $link_text, $this->match->GetDeleteNavigateUrl());
        }
        if ($this->match->GetMatchType() != MatchType::TOURNAMENT_MATCH and $this->match->GetStartTime() > time()) {
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink("add {$link_text} to your calendar", $this->match->GetCalendarNavigateUrl());
        }
        echo $panel;
        if ($this->has_player_stats) {
            $tournament = $is_tournament ? $this->match : $this->match->GetTournament();
            require_once 'stoolball/statistics-highlight-table.class.php';
            echo new StatisticsHighlightTable($this->best_batting, $this->most_runs, $this->best_bowling, $this->most_wickets, $this->most_catches, "tournament");
            echo '<p class="playerSummaryMore"><a href="' . $tournament->GetNavigateUrl() . '/statistics">Tournament statistics</a></p>';
        }
    }