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