| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/form/RacingLeagueForm.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Seite zum Erstellen, Editieren und Löschen von Renntagen |
|---|
| 7 | * |
|---|
| 8 | * @author Markus Gerdelmann |
|---|
| 9 | * @copyright 2008 MDMAN |
|---|
| 10 | * @license GNU |
|---|
| 11 | * @package de.mdman.racing.league |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | class RacingLeagueRacesForm extends RacingLeagueForm { |
|---|
| 15 | |
|---|
| 16 | public $templateName = 'racingLeagueRaces'; |
|---|
| 17 | public $saisonID = 0; |
|---|
| 18 | public $newRaces = 0; |
|---|
| 19 | public $edit = 0; |
|---|
| 20 | public $race = ''; |
|---|
| 21 | public $raceID = 0; |
|---|
| 22 | public $racename = ''; |
|---|
| 23 | public $races = array(); |
|---|
| 24 | public $anz = 0; |
|---|
| 25 | public $raceEditNo = 0; |
|---|
| 26 | public $raceNo = 0; |
|---|
| 27 | |
|---|
| 28 | public $redirect = 'RacingLeagueRaces'; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * @see Form::readParameters() |
|---|
| 32 | */ |
|---|
| 33 | public function readParameters() { |
|---|
| 34 | parent::readParameters(); |
|---|
| 35 | |
|---|
| 36 | if (isset($_REQUEST["saisonID"])) $this->saisonID = intval($_REQUEST["saisonID"]); |
|---|
| 37 | if (isset($_REQUEST["newRaces"])) $this->newRaces = intval($_REQUEST["newRaces"]); |
|---|
| 38 | if (isset($_REQUEST["edit"])) $this->edit = intval($_REQUEST["edit"]); |
|---|
| 39 | if (isset($_REQUEST["raceID"])) $this->raceID = intval($_REQUEST["raceID"]); |
|---|
| 40 | if (isset($_REQUEST["raceNo"])) $this->raceNo = intval($_REQUEST["raceNo"]); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * @see Form::readFormParameters() |
|---|
| 45 | */ |
|---|
| 46 | public function readFormParameters() { |
|---|
| 47 | parent::readFormParameters(); |
|---|
| 48 | |
|---|
| 49 | if (isset($_POST["race"])) $this->race = StringUtil::trim($_POST["race"]); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * @see Form::validate() |
|---|
| 54 | */ |
|---|
| 55 | public function validate() { |
|---|
| 56 | parent::validate(); |
|---|
| 57 | |
|---|
| 58 | // race bei newRaces |
|---|
| 59 | if ($this->newRaces == 1) { |
|---|
| 60 | if (empty($this->race)) { |
|---|
| 61 | $this->newRaces = '1'; |
|---|
| 62 | throw new UserInputException('race'); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | // race bei EDIT |
|---|
| 66 | if ($this->edit == 1) { |
|---|
| 67 | if (empty($this->race)) { |
|---|
| 68 | $this->edit = '1'; |
|---|
| 69 | throw new UserInputException('race'); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | // raceNo |
|---|
| 74 | if (empty($this->raceNo)) { |
|---|
| 75 | throw new UserInputException('raceNo'); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * @see Form::readData() |
|---|
| 81 | */ |
|---|
| 82 | public function readData() { |
|---|
| 83 | parent::readData(); |
|---|
| 84 | |
|---|
| 85 | // Hier wird die Anzahl der vorhandenen Renntage ermittelt |
|---|
| 86 | if ($this->newRaces == 1) { |
|---|
| 87 | |
|---|
| 88 | $sql = "SELECT * |
|---|
| 89 | FROM wcf".WCF_N."_racing_races |
|---|
| 90 | WHERE saisonID = '".$this->activeSaisonID."' |
|---|
| 91 | "; |
|---|
| 92 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 93 | $rows = WCF::getDB()->countRows($res); |
|---|
| 94 | $this->anz = intval($rows) + 1; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | // Hier wird ein Rennen geladen das editiert werden soll |
|---|
| 98 | if ($this->edit == 1) { |
|---|
| 99 | |
|---|
| 100 | $sql = "SELECT * |
|---|
| 101 | FROM wcf".WCF_N."_racing_races |
|---|
| 102 | WHERE raceID = '".$this->raceID."' |
|---|
| 103 | "; |
|---|
| 104 | |
|---|
| 105 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 106 | |
|---|
| 107 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 108 | $this->racename = $row["racename"]; |
|---|
| 109 | $this->raceEditNo = $row["raceNo"]; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | $sql = "SELECT * |
|---|
| 113 | FROM wcf".WCF_N."_racing_races |
|---|
| 114 | WHERE saisonID = '".$this->activeSaisonID."' |
|---|
| 115 | "; |
|---|
| 116 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 117 | $rows = WCF::getDB()->countRows($res); |
|---|
| 118 | $this->anz = intval($rows) + 1; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | //Hier werden alle Races geladen |
|---|
| 122 | if ($this->activeSaisonID != 0) { |
|---|
| 123 | $sql = "SELECT * |
|---|
| 124 | FROM wcf".WCF_N."_racing_races |
|---|
| 125 | WHERE saisonID = ".$this->activeSaisonID." |
|---|
| 126 | ORDER BY raceNo ASC |
|---|
| 127 | "; |
|---|
| 128 | |
|---|
| 129 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 130 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 131 | $this->races[] = $row; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * @see Form::save() |
|---|
| 138 | */ |
|---|
| 139 | public function save() { |
|---|
| 140 | parent::save(); |
|---|
| 141 | |
|---|
| 142 | // Hier wird ein neuer Renntag gespeichert |
|---|
| 143 | if ($this->race && $this->activeSaisonID != 0 && $this->newRaces == 1) { |
|---|
| 144 | |
|---|
| 145 | $sql = "INSERT INTO wcf".WCF_N."_racing_races (saisonID, raceID, raceNo, racename) |
|---|
| 146 | VALUES ('".escapeString($this->activeSaisonID)."', '', '".escapeString($this->raceNo)."', '".escapeString($this->race)."') |
|---|
| 147 | "; |
|---|
| 148 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 149 | |
|---|
| 150 | $row = 0; |
|---|
| 151 | $row = WCF::getDB()->getAffectedRows($res); |
|---|
| 152 | $this->newRaces = 0; |
|---|
| 153 | if ($row > 0) { |
|---|
| 154 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewSuccess')); |
|---|
| 155 | } |
|---|
| 156 | else { |
|---|
| 157 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewError')); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | // Hier wird ein Renntag bearbeitet |
|---|
| 162 | if ($this->race && $this->activeSaisonID != 0 && $this->edit == 1 && $this->raceID != 0) { |
|---|
| 163 | |
|---|
| 164 | $sql = "UPDATE wcf".WCF_N."_racing_races |
|---|
| 165 | SET racename = '".escapeString($this->race)."', |
|---|
| 166 | raceNo = '".escapeString($this->raceNo)."' |
|---|
| 167 | WHERE raceID = '".escapeString($this->raceID)."' |
|---|
| 168 | LIMIT 1 |
|---|
| 169 | "; |
|---|
| 170 | |
|---|
| 171 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 172 | |
|---|
| 173 | $row = 0; |
|---|
| 174 | $row = WCF::getDB()->getAffectedRows($res); |
|---|
| 175 | $this->edit = 0; |
|---|
| 176 | if ($row > 0) { |
|---|
| 177 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueEditSuccess')); |
|---|
| 178 | } |
|---|
| 179 | else { |
|---|
| 180 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueEditError')); |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * @see Page::assignVariables(); |
|---|
| 187 | */ |
|---|
| 188 | public function assignVariables() { |
|---|
| 189 | parent::assignVariables(); |
|---|
| 190 | |
|---|
| 191 | WCF::getTPL()->assign(array( |
|---|
| 192 | 'saisonID' => $this->saisonID, |
|---|
| 193 | 'newRaces' => $this->newRaces, |
|---|
| 194 | 'edit' => $this->edit, |
|---|
| 195 | 'race' => $this->race, |
|---|
| 196 | 'raceID' => $this->raceID, |
|---|
| 197 | 'racename' => $this->racename, |
|---|
| 198 | 'races' => $this->races, |
|---|
| 199 | 'anz' => $this->anz, |
|---|
| 200 | 'raceEditNo' => $this->raceEditNo, |
|---|
| 201 | 'redirect' => $this->redirect |
|---|
| 202 | )); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | /** |
|---|
| 206 | * @see Page::show() |
|---|
| 207 | */ |
|---|
| 208 | public function show() { |
|---|
| 209 | |
|---|
| 210 | // check permission |
|---|
| 211 | WCF::getUser()->checkPermission('admin.racing.league.caneditraces'); |
|---|
| 212 | require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php'); |
|---|
| 213 | HeaderMenu::setActiveMenuItem('wcf.header.menu.racing.league'); |
|---|
| 214 | parent::show(); |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | ?> |
|---|