public function OnPostback()
 {
     # If there's no id, ensure no match object is created. Page will then display a "match not found" message.
     # There's a separate page for adding matches, even for admins.
     if (!$this->editor->GetDataObjectId()) {
         return;
     }
     # Get the submitted match
     $this->match = $this->editor->GetDataObject();
     $check_match = $this->match;
     # Because this is a new request, if the user isn't admin we need to reverify whether this is the match owner
     # before letting anything happen. Can't trust that info from a postback so MUST go to the database to check it.
     if (!$this->b_user_is_match_admin) {
         $this->match_manager->ReadByMatchId(array($this->editor->GetDataObjectId()));
         $check_match = $this->match_manager->GetFirst();
         $this->b_user_is_match_owner = ($check_match instanceof Match and AuthenticationManager::GetUser()->GetId() == $check_match->GetAddedBy()->GetId());
         if ($this->b_user_is_match_owner) {
             # Set the owner of the match. This means the edit control knows who the owner is and therefore
             # whether to display the fixture editor on an invalid postback
             $this->match->SetAddedBy(AuthenticationManager::GetUser());
         } else {
             # If user is neither admin nor owner, they won't have the team info. Get it from the $check_match so
             # that the match title can be updated correctly with a changed result.
             $this->match->SetHomeTeam($check_match->GetHomeTeam());
             $this->match->SetAwayTeam($check_match->GetAwayTeam());
         }
     }
     # Don't wan't to edit tournaments on this page, so even as admin make sure we're not trying to save one.
     # If user's not admin, can't change the match type, so find out what that is from the db too. For admin,
     # $check_match is the submitted one as the match type might've been changed.
     $this->b_is_tournament = $check_match->GetMatchType() == MatchType::TOURNAMENT;
     # Check whether cancel was clicked
     if ($this->editor->CancelClicked()) {
         # If so, get the match's short URL and redirect
         $this->match_manager->ExpandMatchUrl($this->match);
         $this->Redirect($this->match->GetNavigateUrl());
     }
     # save data if valid
     if ($this->IsValid() and !$this->b_is_tournament) {
         # Check whether the user has permission to update the fixture as well as the result
         if ($this->b_user_is_match_admin or $this->b_user_is_match_owner) {
             # Get the ground name from the database. This is used when compiling an email about the updated match result.
             if ($this->match->GetGround() instanceof Ground and $this->match->GetGround()->GetId() and !$this->match->GetGround()->GetName()) {
                 require_once 'stoolball/ground-manager.class.php';
                 $ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
                 $ground_manager->ReadById(array($this->match->GetGround()->GetId()));
                 if ($ground_manager->GetCount()) {
                     $this->match->SetGround($ground_manager->GetFirst());
                 }
                 unset($ground_manager);
             }
             $this->match_manager->SaveFixture($this->match);
             if ($this->b_user_is_match_admin) {
                 $this->match_manager->SaveSeasons($this->match, false);
             }
             $this->editor->SetNavigateUrl($this->match->GetEditNavigateUrl());
             # because edit URL may have changed
         }
         # Save the result
         $this->match_manager->SaveIfPlayed($this->match);
         $this->match_manager->SaveWhoWonTheToss($this->match);
         $this->match_manager->SaveWhoBattedFirst($this->match);
         # If match didn't happen or the teams aren't known yet, save and finish, otherwise go to next page
         $result = $this->match->Result()->GetResultType();
         if ($result == MatchResult::HOME_WIN_BY_FORFEIT or $result == MatchResult::AWAY_WIN_BY_FORFEIT or $result == MatchResult::CANCELLED or $result == MatchResult::POSTPONED or $check_match->GetStartTime() > gmdate('U') or $this->b_user_is_match_admin and (!$this->match->GetHomeTeamId() or !$this->match->GetAwayTeamId())) {
             # Match may have been updated so, first, send an email
             $this->match_manager->NotifyMatchModerator($this->match->GetId());
             http_response_code(303);
             $this->Redirect($this->match->GetNavigateUrl());
         } else {
             http_response_code(303);
             $this->Redirect($this->match->EditScorecardUrl());
         }
     }
 }
    /**
     * 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
        }
    }
 /**
  * Finds an existing team or saves a new team and returns the id
  * @param Match $tournament
  * @param Team $team
  * @return int
  */
 public function SaveOrMatchTournamentTeam(Match $tournament, Team $team)
 {
     if (is_null($team->GetPlayerType())) {
         $team->SetPlayerType($tournament->GetPlayerType());
     }
     $team = $this->MatchExistingTeam($team);
     if (!$team->GetId()) {
         $team->SetShortUrlPrefix($tournament->GetShortUrl());
         $team = $this->MatchExistingTeam($team);
     }
     if (!$team->GetId()) {
         $team->SetTeamType(Team::ONCE);
         $team->SetGround($tournament->GetGround());
         $this->SaveTeam($team);
     }
     return $team->GetId();
 }
 protected function OnPreRender()
 {
     /* @var $o_home Team */
     /* @var $o_away Team */
     /* @var $o_tourney Match */
     # Date and tournament
     $o_date_para = new XhtmlElement('p');
     $o_date = new XhtmlElement('abbr', htmlentities($this->o_match->GetStartTimeFormatted(), ENT_QUOTES, "UTF-8", false));
     $o_date->SetTitle(Date::Microformat($this->o_match->GetStartTime()));
     # hCalendar
     $o_date->SetCssClass('dtstart');
     # hCalendar
     $o_date->AddAttribute("property", "schema:startDate");
     $o_date->AddAttribute("datatype", "xsd:date");
     $o_date->AddAttribute("content", Date::Microformat($this->o_match->GetStartTime()));
     $o_date_para->AddControl('When: ');
     $o_date_para->AddControl($o_date);
     # hCalendar end date
     if ($this->o_match->GetIsStartTimeKnown()) {
         $i_end_time = $this->o_match->GetStartTime() + 60 * 90;
         $o_hcal_end = new XhtmlElement('abbr', ' until around ' . htmlentities(Date::Time($i_end_time), ENT_QUOTES, "UTF-8", false));
         $o_hcal_end->SetTitle(Date::Microformat($i_end_time));
         $o_hcal_end->SetCssClass('metadata dtend');
         $o_date_para->AddControl($o_hcal_end);
     }
     # If we know the time and place, show when the sun sets
     # TODO: Assumes UK
     if ($this->o_match->GetGround() instanceof Ground and $this->o_match->GetGround()->GetAddress()->GetLatitude() and $this->o_match->GetGround()->GetAddress()->GetLongitude()) {
         $o_date_para->AddControl(' <span class="sunset">sunset ' . htmlentities(Date::Time(date_sunset($this->o_match->GetStartTime(), SUNFUNCS_RET_TIMESTAMP, $this->o_match->GetGround()->GetAddress()->GetLatitude(), $this->o_match->GetGround()->GetAddress()->GetLongitude())), ENT_QUOTES, "UTF-8", false) . '</span>');
     }
     # Display match type/season/tournament
     if ($this->o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         $o_date_para->SetCssClass('description');
         # hCal
         $o_tourney = $this->o_match->GetTournament();
         if (is_object($o_tourney)) {
             $tournament_link = new XhtmlAnchor(htmlentities($o_tourney->GetTitle(), ENT_QUOTES, "UTF-8", false), $o_tourney->GetNavigateUrl());
             $tournament_link->AddAttribute("typeof", "schema:SportsEvent");
             $tournament_link->AddAttribute("about", $o_tourney->GetLinkedDataUri());
             $tournament_link->AddAttribute("rel", "schema:url");
             $tournament_link->AddAttribute("property", "schema:name");
             $tournament_container = new XhtmlElement("span", $tournament_link);
             $tournament_container->AddAttribute("rel", "schema:superEvent");
             # Check for 'the' to get the grammar right
             $s_title = strtolower($o_tourney->GetTitle());
             if (strlen($s_title) >= 4 and substr($s_title, 0, 4) == 'the ') {
                 $o_date_para->AddControl(', in ');
             } else {
                 $o_date_para->AddControl(', in the ');
             }
             $o_date_para->AddControl($tournament_container);
             $o_date_para->AddControl('.');
         } else {
             $o_date_para->AddControl(', in a tournament.');
         }
     } else {
         # hCalendar desc, built up at the same time as the date and league/tournament
         $hcal_desc = new XhtmlElement('div', null, 'description');
         $this->AddControl($hcal_desc);
         $s_detail_xhtml = ucfirst(MatchType::Text($this->o_match->GetMatchType()));
         $season_list_xhtml = null;
         if ($this->o_match->Seasons()->GetCount() == 1) {
             $season = $this->o_match->Seasons()->GetFirst();
             $season_name = new XhtmlAnchor(htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false), $season->GetNavigateUrl());
             $b_the = !(stristr($season->GetCompetitionName(), 'the ') === 0);
             $s_detail_xhtml .= ' in ' . ($b_the ? 'the ' : '') . $season_name->__toString() . '.';
         } elseif ($this->o_match->Seasons()->GetCount() > 1) {
             $s_detail_xhtml .= ' in the following seasons: ';
             $season_list_xhtml = new XhtmlElement('ul');
             $seasons = $this->o_match->Seasons()->GetItems();
             $total_seasons = count($seasons);
             for ($i = 0; $i < $total_seasons; $i++) {
                 $season = $seasons[$i];
                 /* @var $season Season */
                 $season_name = new XhtmlAnchor(htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false), $season->GetNavigateUrl());
                 $li = new XhtmlElement('li', $season_name);
                 if ($i < $total_seasons - 2) {
                     $li->AddControl(new XhtmlElement('span', ', ', 'metadata'));
                 } else {
                     if ($i < $total_seasons - 1) {
                         $li->AddControl(new XhtmlElement('span', ' and ', 'metadata'));
                     }
                 }
                 $season_list_xhtml->AddControl($li);
             }
         } else {
             $s_detail_xhtml .= '.';
         }
         $hcal_desc->AddControl(new XhtmlElement('p', $s_detail_xhtml));
         if (!is_null($season_list_xhtml)) {
             $hcal_desc->AddControl($season_list_xhtml);
         }
     }
     # Who
     $o_home = $this->o_match->GetHomeTeam();
     $o_away = $this->o_match->GetAwayTeam();
     $has_home = $o_home instanceof Team;
     $has_away = $o_away instanceof Team;
     if ($has_home or $has_away) {
         $who = new XhtmlElement("p", "Who: ");
         if ($has_home) {
             $who->AddControl($this->CreateTeamLink($o_home));
         }
         if ($has_home and $has_away) {
             $who->AddControl(" and ");
         }
         if ($has_away) {
             $who->AddControl($this->CreateTeamLink($o_away));
         }
         $this->AddControl($who);
     }
     # When
     $this->AddControl($o_date_para);
     # Ground
     $o_ground = $this->o_match->GetGround();
     if (is_object($o_ground)) {
         $o_ground_link = new XhtmlElement('a', htmlentities($o_ground->GetNameAndTown(), ENT_QUOTES, "UTF-8", false));
         $o_ground_link->AddAttribute('href', $o_ground->GetNavigateUrl());
         $o_ground_link->SetCssClass('location');
         # hCalendar
         $o_ground_link->AddAttribute("typeof", "schema:Place");
         $o_ground_link->AddAttribute("about", $o_ground->GetLinkedDataUri());
         $o_ground_link->AddAttribute("rel", "schema:url");
         $o_ground_link->AddAttribute("property", "schema:name");
         $o_ground_control = new XhtmlElement('p', 'Where: ');
         $o_ground_control->AddAttribute("rel", "schema:location");
         $o_ground_control->AddControl($o_ground_link);
         $this->AddControl($o_ground_control);
     }
     # Add result
     $o_result = $this->o_match->Result();
     $b_result_known = !$o_result->GetResultType() == MatchResult::UNKNOWN;
     $toss_known = !is_null($this->o_match->Result()->GetTossWonBy());
     $b_batting_order_known = !is_null($this->o_match->Result()->GetHomeBattedFirst());
     $has_scorecard_data = ($o_result->HomeBatting()->GetCount() or $o_result->HomeBowling()->GetCount() or $o_result->AwayBatting()->GetCount() or $o_result->AwayBowling()->GetCount() or $o_result->GetHomeRuns() or $o_result->GetHomeWickets() or $o_result->GetAwayRuns() or $o_result->GetAwayWickets());
     $has_player_of_match = $this->o_match->Result()->GetPlayerOfTheMatch() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatch()->GetName();
     $has_player_of_match_home = $this->o_match->Result()->GetPlayerOfTheMatchHome() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatchHome()->GetName();
     $has_player_of_match_away = $this->o_match->Result()->GetPlayerOfTheMatchAway() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatchAway()->GetName();
     if ($b_result_known or $b_batting_order_known or $has_scorecard_data) {
         # Put result in header, so long as we have something to put after it. Otherwise put the result after it.
         $result_header = "Result";
         if ($b_result_known and ($b_batting_order_known or $has_scorecard_data)) {
             $result_header .= ": " . $this->o_match->GetResultDescription();
         }
         $result_header = new XhtmlElement('h2', htmlentities($result_header, ENT_QUOTES, "UTF-8", false));
         if ($has_scorecard_data) {
             $result_header->AddCssClass("hasScorecard");
         }
         $this->AddControl($result_header);
     }
     if ($toss_known) {
         $toss_team = $this->o_match->Result()->GetTossWonBy() === TeamRole::Home() ? $this->o_match->GetHomeTeam() : $this->o_match->GetAwayTeam();
         if ($toss_team instanceof Team) {
             $toss_text = $toss_team->GetName() . " won the toss";
             if ($b_batting_order_known) {
                 $chose_to = ($this->o_match->Result()->GetTossWonBy() === TeamRole::Home()) == $this->o_match->Result()->GetHomeBattedFirst() ? "bat" : "bowl";
                 $toss_text .= " and chose to " . $chose_to;
             }
             $this->AddControl("<p>" . Html::Encode($toss_text) . '.</p>');
         }
     }
     # If at least one player recorded, create a container for the schema.org metadata
     if ($has_scorecard_data or $has_player_of_match or $has_player_of_match_home or $has_player_of_match_away) {
         $this->AddControl('<div rel="schema:performers">');
     }
     if ($has_scorecard_data) {
         $this->CreateScorecard($this->o_match);
     } else {
         # Got to be just result and batting order now. Only include result if batting order's not there, otherwise result will already be in header.
         if ($b_result_known and !$b_batting_order_known) {
             $this->AddControl(new XhtmlElement('p', htmlentities($this->o_match->GetResultDescription(), ENT_QUOTES, "UTF-8", false) . '.'));
         }
         if ($b_batting_order_known) {
             $this->AddControl(new XhtmlElement('p', htmlentities(($this->o_match->Result()->GetHomeBattedFirst() ? $o_home->GetName() : $o_away->GetName()) . ' batted first.'), ENT_QUOTES, "UTF-8", false));
         }
     }
     # Player of the match
     if ($has_player_of_match) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatch();
         $team = $player->Team()->GetId() == $o_home->GetId() ? $o_home->GetName() : $o_away->GetName();
         $player_of_match = new XhtmlElement('p', 'Player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a> ({$team})");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     if ($has_player_of_match_home) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatchHome();
         $player_of_match = new XhtmlElement('p', $o_home->GetName() . ' player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a>");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     if ($has_player_of_match_away) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatchAway();
         $player_of_match = new XhtmlElement('p', $o_away->GetName() . ' player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a>");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     # End container for the schema.org metadata
     if ($has_scorecard_data or $has_player_of_match or $has_player_of_match_home or $has_player_of_match_away) {
         $this->AddControl('</div>');
     }
     # Add notes
     if ($this->o_match->GetNotes()) {
         $this->AddControl(new XhtmlElement('h2', 'Notes'));
         $s_notes = htmlentities($this->o_match->GetNotes(), ENT_QUOTES, "UTF-8", false);
         $s_notes = XhtmlMarkup::ApplyCharacterEntities($s_notes);
         require_once 'email/email-address-protector.class.php';
         $protector = new EmailAddressProtector($this->o_settings);
         $s_notes = $protector->ApplyEmailProtection($s_notes, AuthenticationManager::GetUser()->IsSignedIn());
         $s_notes = XhtmlMarkup::ApplyHeadings($s_notes);
         $s_notes = XhtmlMarkup::ApplyParagraphs($s_notes);
         $s_notes = XhtmlMarkup::ApplyLists($s_notes);
         $s_notes = XhtmlMarkup::ApplySimpleTags($s_notes);
         $s_notes = XhtmlMarkup::ApplyLinks($s_notes);
         if (strpos($s_notes, '<p>') > -1) {
             $this->AddControl($s_notes);
         } else {
             $this->AddControl(new XhtmlElement('p', $s_notes));
         }
     }
     # hCalendar metadata
     $o_hcal_para = new XhtmlElement('p');
     $o_hcal_para->SetCssClass('metadata');
     $this->AddControl($o_hcal_para);
     # hCalendar timestamp
     $o_hcal_para->AddControl('Status: At ');
     $o_hcal_stamp = new XhtmlElement('abbr', htmlentities(Date::Time(gmdate('U')), ENT_QUOTES, "UTF-8", false));
     $o_hcal_stamp->SetTitle(Date::Microformat());
     $o_hcal_stamp->SetCssClass('dtstamp');
     $o_hcal_para->AddControl($o_hcal_stamp);
     # hCalendar GUID
     $o_hcal_para->AddControl(' match ');
     $o_hcal_guid = new XhtmlElement('span', htmlentities($this->o_match->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false));
     $o_hcal_guid->SetCssClass('uid');
     $o_hcal_para->AddControl($o_hcal_guid);
     # work out hCalendar status
     $s_status = 'CONFIRMED';
     switch ($this->o_match->Result()->GetResultType()) {
         case MatchResult::CANCELLED:
         case MatchResult::POSTPONED:
         case MatchResult::AWAY_WIN_BY_FORFEIT:
         case MatchResult::HOME_WIN_BY_FORFEIT:
             $s_status = 'CANCELLED';
     }
     # hCalendar URL and status
     $o_hcal_para->AddControl(' is ');
     $o_hcal_url = new XhtmlAnchor($s_status, 'http://' . $_SERVER['HTTP_HOST'] . $this->o_match->GetNavigateUrl());
     $o_hcal_url->SetCssClass('url status');
     $o_hcal_para->AddControl($o_hcal_url);
 }