root/racing.league/files/lib/form/RacingLeaguePunishForm.class.php @ 706

Revision 706, 4.4 kB (checked in by MDMAN, 5 years ago)

racing-league modified

Line 
1<?php
2// wcf imports
3require_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
14class 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 = 0;
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)) {
65                        throw new UserInputException('driver');
66                }
67
68                // punishReason
69                if (empty($this->punishReason)) {
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                       
83                }
84
85                if ($this->activeSaisonID != 0 && $this->addPunish == 1) {
86                        // Hier werden alle gefahrenen Rennen geladen (drived = 1)
87                        $sql = "SELECT *
88                                FROM `wcf".WCF_N."_racing_races`
89                                WHERE `saisonID` = '".$this->activeSaisonID."'
90                                AND `drived` = '1'
91                                ORDER BY `raceNO` ASC
92                                ";             
93                       
94                        $res = WCF::getDB()->sendQuery($sql);
95
96                        while ($row = WCF::getDB()->fetchArray($res)) {
97                                $this->drivedRaces[] = $row;
98                        }                       
99                }
100               
101                if ($this->activeSaisonID != 0 && $this->raceID > 0) {
102
103                       
104                }                       
105               
106        }
107       
108        /**
109         * @see Form::save()
110         */
111        public function save() {
112                parent::save();
113
114                if ($this->addPunish == 1 && isset($this->driver) && isset($this->minusPoints) && isset($this->punishReason) && $this->raceID > 0 && $this->activeSaisonID != 0) {
115               
116                        $sql = "INSERT INTO `wcf".WCF_N."_racing_punish`
117                                (`saisonID`, `raceID`, `userID`, `minusPoints`, `punishReason`)
118                                VALUES ('".escapeString($this->activeSaisonID)."', '".escapeString($this->raceID)."', '".escapeString($this->driver)."', '".escapeString($this->minusPoints)."', '".escapeString($this->punishReason)."')
119                                ";
120
121                        $res = WCF::getDB()->sendQuery($sql);
122
123                        $row = 0;
124                        $row = WCF::getDB()->getAffectedRows($res);
125                        $this->addPunish = 0;
126                        $this->raceID = 0;
127                        if ($row > 0) {                         
128                                WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewSuccess'));
129                        }
130                        else {
131                                WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewError'));
132                        }
133                       
134                }       
135        }       
136       
137        /**
138         * @see Page::assignVariables();
139         */
140        public function assignVariables() {
141                parent::assignVariables();
142
143                WCF::getTPL()->assign(array(
144                        'saisonID' => $this->saisonID,
145                        'editPunishID' => $this->editPunishID,
146                        'punish' => $this->punish,
147                        'addPunish' => $this->addPunish,
148                        'drivedRaces' => $this->drivedRaces,
149                        'raceID' => $this->raceID,
150                        'driver' => $this->driver,
151                                                                       
152                        'redirect' => $this->redirect
153                        ));
154        }
155       
156        /**
157         * @see Page::show()
158         */
159        public function show() {
160               
161                // check permission
162                WCF::getUser()->checkPermission('admin.racing.league.caneditresults');
163                require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php');
164                HeaderMenu::setActiveMenuItem('wcf.header.menu.racing.league');
165                parent::show();         
166    }
167}
168?>
Note: See TracBrowser for help on using the browser.