root/racing.league/files/lib/form/RacingLeagueUserToTeamForm.class.php @ 652

Revision 652, 6.1 kB (checked in by MDMAN, 5 years ago)

racing.league modified

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/form/RacingLeagueTeamsForm.class.php');
4
5/**
6 * Seite fÃŒr die Zuweisung der User an ein Team.
7 *
8 * @author      Markus Gerdelmann
9 * @copyright   2008 MDMAN
10 * @license GNU
11 * @package     de.mdman.racing.league
12 */
13
14class RacingLeagueUserToTeamForm extends RacingLeagueTeamsForm {
15 
16        public $templateName = 'racingLeagueUserToTeam';
17        public $groupID = 0;   
18        public $driverInTeam = array();
19        public $driverNoTeam = array();
20        public $driversTeamID = array();
21        public $newUser = 0;
22        public $userID = 0;
23        public $username = '';
24        public $team = '';
25               
26        public $redirect = 'RacingLeagueUserToTeam';   
27               
28        /**
29         * @see Form::readParameters()
30         */
31        public function readParameters() {
32                parent::readParameters();
33               
34                if (isset($_REQUEST["newUser"]))        $this->newUser = intval($_REQUEST["newUser"]);
35                if (isset($_REQUEST["userID"])) $this->userID = intval($_REQUEST["userID"]);
36        }
37       
38        /**
39         * @see Form::readFormParameters()
40         */
41        public function readFormParameters() {
42                parent::readFormParameters();
43               
44                if (isset($_POST["team"]))              $this->team = StringUtil::trim($_POST["team"]);
45        }
46       
47        /**
48         * @see Form::validate()
49         */
50        public function validate() {
51                parent::validate();
52
53                // team bei NEWUSER
54                if ($this->newUser == 1) {
55                        if (empty($this->team)) {
56                                $this->newUser = '1';
57                                throw new UserInputException('team');
58                        }
59                }               
60        }
61
62        /**
63         * @see Form::readData()
64         */
65        public function readData() {
66                parent::readData();
67
68                if ($this->newUser == 1 && $this->userID > 0 && $this->activSaisonID > 0) {
69                        // Hier wird der Username geladen fÃŒr die Teamzuweisung
70                        $sql = "SELECT userID, username
71                                        FROM wcf".WCF_N."_user
72                                        WHERE userID = ".$this->userID;
73                        $res = WCF::getDB()->sendQuery($sql);
74
75                        while ($row = WCF::getDB()->fetchArray($res)) {
76                                $this->username = $row["username"];
77                        }                       
78                }
79
80                if ($this->activSaisonID > 0) {
81       
82                        // Hier wird die aktive Benutzergruppe ermittelt
83                        $sql = "SELECT *
84                                        FROM wcf".WCF_N."_racing_group
85                                        WHERE saisonID = '".$this->activSaisonID."'
86                                        ";
87                        $res = WCF::getDB()->sendQuery($sql);
88
89                        while ($row = WCF::getDB()->fetchArray($res)) {
90                                $this->groupID = $row["groupID"];
91                        }
92
93                        if ($this->groupID > 0) {
94                       
95                        // Hier werden alle Fahrer die in einem Team sind geladen, inklusive allen Informationen
96                                $sql = "SELECT  `a`.`userID`,
97                                                                `a`.`username`,
98                                                                `b`.`groupID`,
99                                                                `b`.`saisonID`,
100                                                                `c`.`saisonID`,
101                                                                `c`.`usertoteamID`,
102                                                                `c`.`teamID`,
103                                                                `c`.`userID`
104                                                FROM    `wcf".WCF_N."_user` AS `a`
105                                                LEFT OUTER JOIN `wcf".WCF_N."_racing_group` AS `b`
106                                                ON              (`b`.`groupID` = '".$this->groupID."')
107                                                LEFT OUTER JOIN `wcf".WCF_N."_racing_user_to_team` AS `c`
108                                                ON              (`c`.`userID` = `a`.`userID`)
109                                                WHERE   `a`.`userID` = `c`.`userID`
110                                                AND             `b`.`groupID` = '".$this->groupID."'
111                                                AND             `b`.saisonID = '".$this->activSaisonID."'
112                                                AND             `c`.saisonID = '".$this->activSaisonID."'
113                                                ORDER BY `a`.`username` ASC";
114
115                                $res = WCF::getDB()->sendQuery($sql);
116                                $driverTeamIDs = array();
117                                while ($row = WCF::getDB()->fetchArray($res)) {
118                                        $this->driverInTeam[] = $row;
119                                        $driverTeamIDs[] = $row["userID"];
120                                }
121                               
122                                // Hier werden alle Fahrer der aktiven Benutzergruppe ermittelt
123                                $sql = "SELECT  `a`.`userID`
124                                                FROM    `wcf".WCF_N."_user_to_groups` AS `a`
125                                                LEFT OUTER JOIN `wcf".WCF_N."_racing_group` AS `b`
126                                                ON              (`b`.`groupID` = '".$this->groupID."')
127                                                WHERE `a`.`groupID` = `b`.`groupID`
128                                                AND `b`.`saisonID` = '".$this->activSaisonID."'
129                                                ";
130
131                                $res = WCF::getDB()->sendQuery($sql);
132                                $driverIDs = array();
133                                while ($row = WCF::getDB()->fetchArray($res)) {
134                                        $driverIDs[] = $row["userID"];
135                                }
136
137                                // Hier werden nur die Fahrer ohne Team geladen.
138                                $driverTeamIDString = 0;
139                                $driverIDString = implode(',', $driverIDs);
140                                $driverTeamIDString = implode(',', $driverTeamIDs);
141
142                                if ($driverTeamIDString != 0) {
143                                        $sql = "SELECT userID, username
144                                                        FROM wcf".WCF_N."_user
145                                                        WHERE userID IN ($driverIDString)
146                                                        AND userID NOT IN ($driverTeamIDString)
147                                                        ORDER BY username ASC
148                                                        ";
149                                }
150                                else {
151                                        $sql = "SELECT userID, username
152                                                        FROM wcf".WCF_N."_user
153                                                        WHERE userID IN ($driverIDString)
154                                                        ORDER BY username ASC
155                                                        ";
156                                }
157
158                                $res = WCF::getDB()->sendQuery($sql);
159
160                                while ($row = WCF::getDB()->fetchArray($res)) {
161                                        $this->driverNoTeam[] = $row;
162                                }
163                        }                       
164                }               
165        }
166       
167        /**
168         * @see Form::save()
169         */
170        public function save() {
171                parent::save();
172
173                // Hier wird einem Fahrer ein Team zugewiesen und gespeichert
174                if ($this->newUser == 1 && $this->userID > 0 && $this->activSaisonID > 0) {
175
176                        $sql = "INSERT INTO wcf".WCF_N."_racing_user_to_team
177                                        (saisonID, usertoteamID ,teamID, userID)
178                                        VALUES ('".escapeString($this->activSaisonID)."', '', '".escapeString($this->team)."', '".escapeString($this->userID)."')
179                                        ";
180
181                        $res = WCF::getDB()->sendQuery($sql);
182                        $row = 0;
183                        $row = WCF::getDB()->getAffectedRows($res);
184                        $this->newUser = 0;
185                        if ($row > 0) {                         
186                                WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewSuccess'));
187                        }
188                        else {
189                                WCF::getTPL()->append('userMessages', WCF::getTPL()->fetch('racingLeagueNewError'));
190                        }
191                }               
192        }
193       
194        /**
195         * @see Page::assignVariables();
196         */
197        public function assignVariables() {
198                parent::assignVariables();
199               
200                WCF::getTPL()->assign(array(
201                        'groupID' => $this->groupID,                   
202                        'driverNoTeam' => $this->driverNoTeam,
203                        'driverInTeam' => $this->driverInTeam,
204                        'newUser' => $this->newUser,
205                        'teams' => $this->teams,
206                        'username' => $this->username,
207                        'userID' => $this->userID,                     
208                        'redirect' => $this->redirect           
209                        ));
210        }
211       
212        /**
213         * @see Page::show()
214         */
215        public function show() {
216
217                // check permission
218                WCF::getUser()->checkPermission('admin.racing.league.caneditteams');
219                require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php');
220                HeaderMenu::setActiveMenuItem('wcf.header.menu.racing.league');
221                parent::show();                 
222    }
223}
224?>
Note: See TracBrowser for help on using the browser.