public function executeAction($parameters)
 {
     // check if feature is enabled
     if (!$this->_websoccer->getConfig("youth_enabled") && $this->_websoccer->getConfig("youth_scouting_enabled")) {
         return NULL;
     }
     $user = $this->_websoccer->getUser();
     $clubId = $user->getClubId($this->_websoccer, $this->_db);
     // check if user has a club
     if ($clubId < 1) {
         throw new Exception($this->_i18n->getMessage("error_action_required_team"));
     }
     // check if break is violated
     $lastExecutionTimestamp = YouthPlayersDataService::getLastScoutingExecutionTime($this->_websoccer, $this->_db, $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db));
     $nextPossibleExecutionTimestamp = $lastExecutionTimestamp + $this->_websoccer->getConfig("youth_scouting_break_hours") * 3600;
     $now = $this->_websoccer->getNowAsTimestamp();
     if ($now < $nextPossibleExecutionTimestamp) {
         throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_breakviolation", $this->_websoccer->getFormattedDatetime($nextPossibleExecutionTimestamp)));
     }
     // check if valid country (if name files exists)
     $namesFolder = NAMES_DIRECTORY . "/" . $parameters["country"];
     if (!file_exists($namesFolder . "/firstnames.txt") || !file_exists($namesFolder . "/lastnames.txt")) {
         throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_invalidcountry"));
     }
     // check if valid scout
     $scout = YouthPlayersDataService::getScoutById($this->_websoccer, $this->_db, $this->_i18n, $parameters["scoutid"]);
     // check if team can afford it.
     $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId);
     if ($team["team_budget"] <= $scout["fee"]) {
         throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_notenoughbudget"));
     }
     // deduct fee
     BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $clubId, $scout["fee"], "youthteam_scouting_fee_subject", $scout["name"]);
     // has scout found someone?
     $found = TRUE;
     $succesProbability = (int) $this->_websoccer->getConfig("youth_scouting_success_probability");
     if ($this->_websoccer->getConfig("youth_scouting_success_probability") < 100) {
         $found = SimulationHelper::selectItemFromProbabilities(array(TRUE => $succesProbability, FALSE => 100 - $succesProbability));
     }
     // he found someone, so create youth player
     if ($found) {
         $this->createYouthPlayer($clubId, $scout, $parameters["country"]);
         // create failure message
     } else {
         $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("youthteam_scouting_failure"), ""));
     }
     // update last execution time
     $this->_db->queryUpdate(array("scouting_last_execution" => $now), $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $clubId);
     return $found ? "youth-team" : "youth-scouting";
 }
 public function getTemplateParameters()
 {
     $lastExecutionTimestamp = YouthPlayersDataService::getLastScoutingExecutionTime($this->_websoccer, $this->_db, $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db));
     $nextPossibleExecutionTimestamp = $lastExecutionTimestamp + $this->_websoccer->getConfig("youth_scouting_break_hours") * 3600;
     $now = $this->_websoccer->getNowAsTimestamp();
     $scouts = array();
     $countries = array();
     $scoutingPossible = $nextPossibleExecutionTimestamp <= $now;
     if ($scoutingPossible) {
         $scoutId = (int) $this->_websoccer->getRequestParameter("scoutid");
         if ($scoutId > 0) {
             $countries = YouthPlayersDataService::getPossibleScoutingCountries();
         } else {
             $scouts = YouthPlayersDataService::getScouts($this->_websoccer, $this->_db);
         }
     }
     return array("lastExecutionTimestamp" => $lastExecutionTimestamp, "nextPossibleExecutionTimestamp" => $nextPossibleExecutionTimestamp, "scoutingPossible" => $scoutingPossible, "scouts" => $scouts, "countries" => $countries);
 }