root/racing.league/files/lib/form/RacingLeagueResultsForm.class.php @ 660

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