| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/form/RacingLeagueForm.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Seite um Strafen bzw. Strafpunkte zu erfassen |
|---|
| 7 | * |
|---|
| 8 | * @author Markus Gerdelmann |
|---|
| 9 | * @copyright 2008 MDMAN |
|---|
| 10 | * @license GNU |
|---|
| 11 | * @package de.mdman.racing.league |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | class RacingLeaguePunishForm extends RacingLeagueForm { |
|---|
| 15 | |
|---|
| 16 | public $templateName = 'racingLeaguePunish'; |
|---|
| 17 | public $saisonID = 0; |
|---|
| 18 | public $editPunishID = 0; |
|---|
| 19 | public $newPunish = 0; |
|---|
| 20 | public $punish = array(); |
|---|
| 21 | public $addPunish = 0; |
|---|
| 22 | public $raceID = 0; |
|---|
| 23 | public $driver = ''; |
|---|
| 24 | public $minusPoints = ''; |
|---|
| 25 | public $punishReason = ''; |
|---|
| 26 | |
|---|
| 27 | public $drivedRaces = array(); |
|---|
| 28 | |
|---|
| 29 | public $redirect = 'RacingLeaguePunish'; |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * @see Form::readParameters() |
|---|
| 33 | */ |
|---|
| 34 | public function readParameters() { |
|---|
| 35 | parent::readParameters(); |
|---|
| 36 | |
|---|
| 37 | if (isset($_REQUEST["saisonID"])) $this->saisonID = intval($_REQUEST["saisonID"]); |
|---|
| 38 | if (isset($_REQUEST["editPunishID"])) $this->editPunishID = intval($_REQUEST["editPunishID"]); |
|---|
| 39 | if (isset($_REQUEST["addPunish"])) $this->addPunish = intval($_REQUEST["addPunish"]); |
|---|
| 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 | |
|---|
| 50 | if (isset($_POST["raceID"])) $this->raceID = intval($_POST["raceID"]); |
|---|
| 51 | if (isset($_POST["driver"])) $this->driver = intval($_POST["driver"]); |
|---|
| 52 | if (isset($_POST["minusPoints"])) $this->minusPoints = intval($_POST["minusPoints"]); |
|---|
| 53 | if (isset($_POST["punishReason"])) $this->punishReason = StringUtil::trim($_POST["punishReason"]); |
|---|
| 54 | |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * @see Form::validate() |
|---|
| 59 | */ |
|---|
| 60 | public function validate() { |
|---|
| 61 | parent::validate(); |
|---|
| 62 | |
|---|
| 63 | // driver |
|---|
| 64 | if (empty($this->driver) && $this->addPunish == 3) { |
|---|
| 65 | throw new UserInputException('driver'); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | // punishReason |
|---|
| 69 | if (empty($this->punishReason) && $this->addPunish == 3) { |
|---|
| 70 | throw new UserInputException('punishReason'); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * @see Form::readData() |
|---|
| 76 | */ |
|---|
| 77 | public function readData() { |
|---|
| 78 | parent::readData(); |
|---|
| 79 | |
|---|
| 80 | // Hier werden alle Rennen inklusive Strafen geladen |
|---|
| 81 | if ($this->activeSaisonID != 0) { |
|---|
| 82 | $sql = "SELECT `a`.*, |
|---|
| 83 | `b`.`username`, |
|---|
| 84 | `b`.`userID`, |
|---|
| 85 | `c`.`raceName`, |
|---|
| 86 | `c`.`raceNo` |
|---|
| 87 | FROM `wcf".WCF_N."_racing_punish` AS `a` |
|---|
| 88 | LEFT JOIN `wcf".WCF_N."_user` AS `b` |
|---|
| 89 | ON (`b`.`userID` = `a`.`userID`) |
|---|
| 90 | LEFT JOIN `wcf".WCF_N."_racing_races` AS `c` |
|---|
| 91 | ON (`a`.`raceID` = `c`.`raceID`) |
|---|
| 92 | WHERE `a`.`saisonID` = '".$this->activeSaisonID."' |
|---|
| 93 | AND `c`.`saisonID` = '".$this->activeSaisonID."' |
|---|
| 94 | ORDER BY `raceNo` ASC |
|---|
| 95 | "; |
|---|
| 96 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 97 | |
|---|
| 98 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 99 | $this->punish[] = $row; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if ($this->activeSaisonID != 0 && $this->addPunish == 1) { |
|---|
| 104 | // Hier werden alle gefahrenen Rennen geladen (drived = 1) |
|---|
| 105 | $sql = "SELECT raceID, raceName |
|---|
| 106 | FROM `wcf".WCF_N."_racing_races` |
|---|
| 107 | WHERE `saisonID` = '".$this->activeSaisonID."' |
|---|
| 108 | AND `drived` = '1' |
|---|
| 109 | ORDER BY `raceNO` ASC |
|---|
| 110 | "; |
|---|
| 111 | |
|---|
| 112 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 113 | |
|---|
| 114 | while ($row = WCF::getDB()->fetchArray($res)) { |
|---|
| 115 | $this->drivedRaces[] = $row; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | if ($this->activeSaisonID != 0 && $this->raceID > 0) { |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * @see Form::save() |
|---|
| 128 | */ |
|---|
| 129 | public function save() { |
|---|
| 130 | parent::save(); |
|---|
| 131 | |
|---|
| 132 | if ($this->addPunish == 3 && isset($this->driver) && isset($this->minusPoints) && isset($this->punishReason) && $this->raceID > 0 && $this->activeSaisonID != 0) { |
|---|
| 133 | |
|---|
| 134 | $sql = "INSERT INTO `wcf".WCF_N."_racing_punish` |
|---|
| 135 | (`saisonID`, `raceID`, `userID`, `minusPoints`, `punishReason`) |
|---|
| 136 | VALUES ('".escapeString($this->activeSaisonID)."', '".escapeString($this->raceID)."', '".escapeString($this->driver)."', '".escapeString($this->minusPoints)."', '".escapeString($this->punishReason)."') |
|---|
| 137 | "; |
|---|
| 138 | |
|---|
| 139 | $res = WCF::getDB()->sendQuery($sql); |
|---|
| 140 | |
|---|
| 141 | $row = 0; |
|---|
| 142 | $row = WCF::getDB()->getAffectedRows($res); |
|---|
| 143 | $this->addPunish = 0; |
|---|
| 144 | $this->raceID = 0; |
|---|
| 145 | if ($row > 0) { |
|---|
| 146 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewSuccess')); |
|---|
| 147 | } |
|---|
| 148 | else { |
|---|
| 149 | WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewError')); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * @see Page::assignVariables(); |
|---|
| 157 | */ |
|---|
| 158 | public function assignVariables() { |
|---|
| 159 | parent::assignVariables(); |
|---|
| 160 | |
|---|
| 161 | WCF::getTPL()->assign(array( |
|---|
| 162 | 'saisonID' => $this->saisonID, |
|---|
| 163 | 'editPunishID' => $this->editPunishID, |
|---|
| 164 | 'punish' => $this->punish, |
|---|
| 165 | 'addPunish' => $this->addPunish, |
|---|
| 166 | 'drivedRaces' => $this->drivedRaces, |
|---|
| 167 | 'raceID' => $this->raceID, |
|---|
| 168 | 'driver' => $this->driver, |
|---|
| 169 | |
|---|
| 170 | 'redirect' => $this->redirect |
|---|
| 171 | )); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * @see Page::show() |
|---|
| 176 | */ |
|---|
| 177 | public function show() { |
|---|
| 178 | |
|---|
| 179 | // check permission |
|---|
| 180 | WCF::getUser()->checkPermission('admin.racing.league.caneditresults'); |
|---|
| 181 | require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php'); |
|---|
| 182 | HeaderMenu::setActiveMenuItem('wcf.header.menu.racing.league'); |
|---|
| 183 | parent::show(); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | ?> |
|---|