| [647] | 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| [648] | 3 | require_once(WCF_DIR.'lib/form/RacingLeagueForm.class.php'); |
|---|
| [647] | 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Seite um Ergebnisse zu erfassen |
|---|
| 7 | * |
|---|
| 8 | * @author Markus Gerdelmann |
|---|
| 9 | * @copyright 2008 MDMAN |
|---|
| 10 | * @license GNU |
|---|
| 11 | * @package de.mdman.racing.league |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| [648] | 14 | class RacingLeagueResultsForm extends RacingLeagueForm { |
|---|
| [647] | 15 | |
|---|
| 16 | public $templateName = 'racingLeagueResults'; |
|---|
| 17 | public $saisonID = 0; |
|---|
| 18 | public $new = 0; |
|---|
| 19 | public $edit = 0; |
|---|
| 20 | public $results = array(); |
|---|
| 21 | public $result = array(); |
|---|
| 22 | public $groupID = 0; |
|---|
| 23 | public $userIDs = array(); |
|---|
| 24 | public $places = array(); |
|---|
| 25 | public $race = array(); |
|---|
| [648] | 26 | public $raceID = 0; |
|---|
| [647] | 27 | |
|---|
| 28 | public $redirect = 'RacingLeagueResults'; |
|---|
| 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["new"])) $this->new = intval($_REQUEST["new"]); |
|---|
| 38 | if (isset($_REQUEST["edit"])) $this->edit = intval($_REQUEST["edit"]); |
|---|
| 39 | if (isset($_REQUEST["resultsID"])) $this->resultsID = intval($_REQUEST["resultsID"]); |
|---|
| 40 | if (isset($_REQUEST["raceID"])) $this->raceID = intval($_REQUEST["raceID"]); |
|---|
| 41 | |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * @see Form::readFormParameters() |
|---|
| 46 | */ |
|---|
| 47 | public function readFormParameters() { |
|---|
| 48 | parent::readFormParameters(); |
|---|
| 49 | |
|---|
| [656] | 50 | var_dump($_POST["result"]); |
|---|
| 51 | if (isset($_POST["result"])) $this->result = $_POST["result"]; |
|---|
| [647] | 52 | } |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * @see Form::validate() |
|---|
| 56 | */ |
|---|
| 57 | public function validate() { |
|---|
| 58 | parent::validate(); |
|---|
| 59 | |
|---|
| 60 | // point bei NEW |
|---|
| 61 | if ($this->new == 1) { |
|---|
| 62 | if (empty($this->result)) { |
|---|
| 63 | $this->new = '1'; |
|---|
| 64 | throw new UserInputException('result'); |
|---|
| 65 | } |
|---|
| [648] | 66 | } |
|---|
| [647] | 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * @see Form::readData() |
|---|
| 71 | */ |
|---|
| 72 | public function readData() { |
|---|
| 73 | parent::readData(); |
|---|
| 74 | |
|---|
| [656] | 75 | if ($this->activeSaisonID != 0) { |
|---|
| [647] | 76 | // Hier wird das aktuelle Rennen ermittelt |
|---|
| 77 | $sql = "SELECT * |
|---|
| [648] | 78 | FROM wcf".WCF_N."_racing_races |
|---|
| [656] | 79 | WHERE saisonID = '".$this->activeSaisonID."' |
|---|
| [648] | 80 | AND drived = '0' |
|---|
| 81 | ORDER BY raceNo ASC |
|---|
| 82 | LIMIT 1"; |
|---|
| [647] | 83 | |
|---|
| 84 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 85 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 86 | $this->race[] = $row; |
|---|
| 87 | $this->raceID = $row["raceID"]; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | if (!$this->race) { |
|---|
| 92 | header("Location: index.php?form=RacingLeagueRaces".SID_ARG_2ND_NOT_ENCODED); |
|---|
| 93 | exit; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | // Hier wird die groupID der Saison ermittelt |
|---|
| 98 | $sql = "SELECT * |
|---|
| [656] | 99 | FROM wcf".WCF_N."_racing_group |
|---|
| 100 | WHERE saisonID = '".$this->activeSaisonID."' |
|---|
| [647] | 101 | "; |
|---|
| 102 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 103 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 104 | $this->groupID = $row["groupID"]; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| [656] | 109 | if ($this->new == 1 && $this->activeSaisonID != 0 && $this->groupID != 0) { |
|---|
| [647] | 110 | |
|---|
| [656] | 111 | // Hier werden alle verfÃÂŒgbaren PlÀtze ermittelt |
|---|
| [647] | 112 | $sql = "SELECT * |
|---|
| [656] | 113 | FROM wcf".WCF_N."_racing_points |
|---|
| 114 | WHERE saisonID = '".$this->activeSaisonID."' |
|---|
| 115 | ORDER BY place asc"; |
|---|
| [647] | 116 | |
|---|
| 117 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 118 | |
|---|
| 119 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| [656] | 120 | $this->places[$row['place']] = $row; |
|---|
| [647] | 121 | } |
|---|
| [656] | 122 | |
|---|
| [647] | 123 | if (!$this->places) { |
|---|
| 124 | header("Location: index.php?form=RacingLeaguePoints".SID_ARG_2ND_NOT_ENCODED); |
|---|
| 125 | exit; |
|---|
| [656] | 126 | } |
|---|
| [647] | 127 | } |
|---|
| 128 | |
|---|
| 129 | // Hier wird ein Ergebnis geladen was editiert werden soll |
|---|
| 130 | if ($this->edit == 1) { |
|---|
| 131 | |
|---|
| 132 | $sql = "SELECT * |
|---|
| 133 | FROM wcf".WCF_N."_racing_results |
|---|
| 134 | WHERE resultID = '".$this->resultID."' |
|---|
| 135 | "; |
|---|
| 136 | |
|---|
| 137 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 138 | |
|---|
| 139 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 140 | |
|---|
| [648] | 141 | } |
|---|
| [656] | 142 | } |
|---|
| [647] | 143 | |
|---|
| 144 | //Hier werden alle Ergebnisse geladen |
|---|
| [656] | 145 | if ($this->activeSaisonID != 0) { |
|---|
| [647] | 146 | $sql = "SELECT * |
|---|
| 147 | FROM wcf".WCF_N."_racing_results |
|---|
| [656] | 148 | WHERE saisonID = ".$this->activeSaisonID." |
|---|
| [647] | 149 | ORDER BY place ASC |
|---|
| 150 | "; |
|---|
| 151 | |
|---|
| 152 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 153 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 154 | $this->results[] = $row; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * @see Form::save() |
|---|
| 161 | */ |
|---|
| 162 | public function save() { |
|---|
| 163 | parent::save(); |
|---|
| 164 | |
|---|
| 165 | // Hier wird ein neues Ergebnis gespeichert |
|---|
| [656] | 166 | if ($this->result && $this->activeSaisonID != 0 && $this->new == 1 && $this->edit == 1) { |
|---|
| [647] | 167 | |
|---|
| 168 | $sql = "INSERT INTO wcf".WCF_N."_racing_results (saisonID, resultID, userID, place, points) |
|---|
| [656] | 169 | VALUES ('".escapeString($this->activeSaisonID)."', '', '".escapeString($this->result["userID"])."', '', '".escapeString($this->result["points"])."') |
|---|
| [647] | 170 | "; |
|---|
| 171 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 172 | |
|---|
| 173 | $row = 0; |
|---|
| 174 | $row = WCF::getDB()->getAffectedRows($res); |
|---|
| 175 | $this->new = 0; |
|---|
| 176 | if ($row > 0) { |
|---|
| 177 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewSuccess')); |
|---|
| 178 | } |
|---|
| 179 | else { |
|---|
| 180 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewError')); |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | // Hier wird ein Ergebnis bearbeitet |
|---|
| [656] | 185 | if ($this->result && $this->activeSaisonID != 0 && $this->edit == 1 && $this->pointsID != 0) { |
|---|
| [647] | 186 | |
|---|
| 187 | $sql = "UPDATE wcf".WCF_N."_racing_points |
|---|
| 188 | SET points = '".escapeString($this->point)."', |
|---|
| 189 | place = '".escapeString($this->place)."' |
|---|
| [656] | 190 | WHERE pointsID = '".escapeString($this->pointsID)."' |
|---|
| [647] | 191 | LIMIT 1 |
|---|
| 192 | "; |
|---|
| 193 | |
|---|
| 194 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 195 | |
|---|
| 196 | $row = 0; |
|---|
| 197 | $row = WCF::getDB()->getAffectedRows($res); |
|---|
| 198 | $this->edit = 0; |
|---|
| 199 | if ($row > 0) { |
|---|
| 200 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueEditSuccess')); |
|---|
| 201 | } |
|---|
| 202 | else { |
|---|
| 203 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueEditError')); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | /** |
|---|
| 209 | * @see Page::assignVariables(); |
|---|
| 210 | */ |
|---|
| 211 | public function assignVariables() { |
|---|
| 212 | parent::assignVariables(); |
|---|
| 213 | |
|---|
| 214 | WCF::getTPL()->assign(array( |
|---|
| 215 | 'saisonID' => $this->saisonID, |
|---|
| 216 | 'new' => $this->new, |
|---|
| 217 | 'edit' => $this->edit, |
|---|
| 218 | 'results' => $this->results, |
|---|
| 219 | 'groupID' => $this->groupID, |
|---|
| 220 | 'places' => $this->places, |
|---|
| 221 | 'race' => $this->race, |
|---|
| [648] | 222 | 'raceID' => $this->raceID, |
|---|
| [647] | 223 | |
|---|
| 224 | 'redirect' => $this->redirect |
|---|
| 225 | )); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | /** |
|---|
| 229 | * @see Page::show() |
|---|
| 230 | */ |
|---|
| 231 | public function show() { |
|---|
| 232 | |
|---|
| 233 | // check permission |
|---|
| 234 | WCF::getUser()->checkPermission('admin.racing.league.caneditresults'); |
|---|
| 235 | require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php'); |
|---|
| 236 | HeaderMenu::setActiveMenuItem('wcf.header.menu.racing.league'); |
|---|
| 237 | parent::show(); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | ?> |
|---|