function OnPostback() { if ($this->editor->GetDataObjectId()) { # Because this is a new request we need to reverify that 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. $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()); # This page is only for tournaments, so check that against the db too $this->b_is_tournament = $check_match->GetMatchType() == MatchType::TOURNAMENT; } else { # Not an entirely correct error for there being no match id on postback, # but no match = not the owner, and most importantly it will prevent the # match being saved or the edit form being shown. $this->b_user_is_match_owner = false; } # get object $this->tournament = $this->editor->GetDataObject(); # Check whether cancel was clicked if ($this->editor->CancelClicked()) { $this->match_manager->ExpandMatchUrl($this->tournament); if ($this->adding) { http_response_code(303); $this->Redirect($this->tournament->GetDeleteNavigateUrl()); } else { # Show the tournament $this->Redirect($this->tournament->GetNavigateUrl()); } } # save data if valid if ($this->IsValid()) { # Confirm match is being saved as a tournament $this->b_is_tournament = $this->b_is_tournament and $this->tournament->GetMatchType() == MatchType::TOURNAMENT; # Check that the requester has permission to update this match if (($this->b_user_is_match_admin or $this->b_user_is_match_owner) and $this->b_is_tournament) { # Save the teams in the tournament $this->match_manager->SaveTeams($this->tournament); $this->match_manager->NotifyMatchModerator($this->tournament->GetId()); $this->match_manager->ExpandMatchUrl($this->tournament); http_response_code(303); if ($this->adding) { $this->Redirect($this->tournament->AddTournamentCompetitionsUrl()); } else { $this->Redirect($this->tournament->GetNavigateUrl()); } } } }