root/de.wbb-security.database.autojoingroup/files/lib/acp/form/DatabaseAutoJoinGroupForm.class.php @ 940

Revision 940, 4.8 kB (checked in by MDMAN, 4 years ago)

Webdisk AutoJoinGroup?; neue Version --> Benutzergruppenrechte werden nun beachtet im ACP während der Einstellungen

Line 
1<?php
2require_once(WCF_DIR.'lib/acp/form/ACPForm.class.php');
3
4/**
5 * @author              Markus Gerdelmann
6 * @copyright   2005-2009
7 * @package             de.wbb-security.database.autojoingroup
8 */
9class DatabaseAutoJoinGroupForm extends ACPForm {
10
11        public $templateName = 'databaseAutoJoinGroup';
12        public $activeMenuItem = 'wcf.acp.menu.link.content.database.autojoingroup.view';
13        public $neededPermissions = 'admin.database.canViewAutoJoinGroup';
14       
15        private $groups = array();
16        private $joins = array();
17        private $joinID = '';
18        private $edit = 0;
19        private $groupID = 0;
20        private $uploads = '';
21        private $groupName = '';
22               
23        /**
24         * @see Form::readFormParameters()
25         */
26        public function readFormParameters() {
27                parent::readFormParameters();
28
29                if (isset($_POST['groupID']))   $this->groupID = intval($_POST['groupID']);
30                if (isset($_POST['uploads']))   $this->uploads = intval($_POST['uploads']);
31                if (isset($_POST['joinID']))    $this->joinID = intval($_POST['joinID']);
32        }
33       
34        /**
35         * @see Page::readParameters()
36         */
37        public function readParameters() {
38                parent::readParameters();
39               
40                if (isset($_REQUEST['joinID'])) $this->joinID = intval($_REQUEST['joinID']);
41                if (isset($_REQUEST['edit']))   $this->edit = intval($_REQUEST['edit']);
42       
43        }
44       
45        /**
46         * @see Form::validate()
47         */
48        public function validate() {
49                parent::validate();
50               
51                if ($this->groupID == 0){
52                        throw new UserInputException('groupID');
53                }
54               
55                if (empty($this->uploads) || $this->uploads != intval($this->uploads) || intval($this->uploads) < 0) {
56                        throw new UserInputException('uploads');
57                }               
58        }
59       
60        /**
61         * @see Page::readData()
62         */
63        public function readData() {
64                parent::readData();
65               
66                // Hier werden alle Benutzergruppen geladen.
67                $sql = "SELECT groupID, groupName, groupType
68                                FROM `wcf".WCF_N."_group`
69                                ";
70               
71                $res = WCF::getDB()->sendQuery($sql);
72               
73                while ($row = WCF::getDB()->fetchArray($res)) {
74                       
75                        if($row['groupType'] == Group::EVERYONE || $row['groupType'] == Group::GUESTS || $row['groupType'] == Group::USERS) { continue; };
76                       
77                        if (Group::isAccessibleGroup($row['groupID'])) {
78                                $this->groups[] = $row;
79                        }
80                }
81               
82                if ($this->edit == 0) {
83                        // Hier werden die schon vorhandenen AutoJoinGroups geladen.
84                        $sql = "SELECT `a`.*, `b`.`groupName`, `b`.`groupType`
85                                        FROM `wcf".WCF_N."_database_autojoingroup` AS `a`
86                                        LEFT JOIN `wcf".WCF_N."_group` AS `b`
87                                                ON ( `a`.`groupID` = `b`.`groupID`)
88                                        ORDER BY `uploads` ASC
89                                        ";
90               
91                        $res = WCF::getDB()->sendQuery($sql);
92                       
93                        while ($row = WCF::getDB()->fetchArray($res)) {
94                               
95                                if($row['groupType'] == Group::EVERYONE || $row['groupType'] == Group::GUESTS || $row['groupType'] == Group::USERS) { continue; };
96                               
97                                $row['editable'] = '0';
98                               
99                                if (Group::isAccessibleGroup($row['groupID'])) {
100                                        $row['editable'] = '1';
101                                }
102                               
103                                $this->joins[] = $row;
104                        }
105                }
106               
107                if ($this->edit == 1) {
108                       
109                        $sql = "SELECT `a`.*, `b`.`groupName`
110                                        FROM `wcf".WCF_N."_database_autojoingroup` AS `a`
111                                        LEFT JOIN `wcf".WCF_N."_group` AS `b`
112                                                ON ( `a`.`groupID` = `b`.`groupID`)
113                                        WHERE `a`.`joinID` = '".$this->joinID."'
114                                        ";
115                       
116                        $res = WCF::getDB()->sendQuery($sql);
117               
118                        while ($row = WCF::getDB()->fetchArray($res)) {
119                                $this->joins[] = $row;
120                                $this->uploads = $row['uploads'];
121                                $this->groupName = $row['groupName'];
122                        }
123                }               
124        }
125       
126        /**
127         * @see Form::save()
128         */
129        public function save() {
130                parent::save();
131               
132                if ($this->edit == 0 && Group::isAccessibleGroup($this->groupID)) {             
133                        $sql = "INSERT INTO `wcf".WCF_N."_database_autojoingroup` (`joinID`, `groupID`, `uploads`)
134                        VALUES ('', '".escapeString($this->groupID)."', '".escapeString($this->uploads)."')
135                        ";
136                       
137                        WCF::getDB()->sendQuery($sql);
138                               
139                        // show success.
140                        WCF::getTPL()->assign(array(
141                                'success' => true
142                        ));             
143                }
144               
145                if ($this->joinID > 0 && $this->edit == 2 && Group::isAccessibleGroup($this->groupID)) {
146                        $sql = "UPDATE `wcf".WCF_N."_database_autojoingroup`
147                                        SET `groupID` = '".escapeString($this->groupID)."',
148                                                `uploads` = '".escapeString($this->uploads)."'
149                                        WHERE `joinID` = '".escapeString($this->joinID)."'
150                                        ";
151                       
152                        WCF::getDB()->sendQuery($sql);
153                       
154                        $this->edit = 0;
155                       
156                        // show success.
157                        WCF::getTPL()->assign(array(
158                                'success' => true
159                        ));                             
160                }       
161        }
162       
163        /**
164         * @see Page::show()
165         */
166        public function show() {
167                parent::show();
168               
169        }
170       
171        /**
172         * @see Page::assignVariables()
173         */
174        public function assignVariables() {
175                parent::assignVariables();
176               
177                WCF::getTPL()->assign(array(
178               
179                        'groups' => $this->groups,
180                        'joins' => $this->joins,
181                        'edit' => $this->edit,
182                        'uploads' => $this->uploads,
183                        'groupName' => $this->groupName,
184                        'joinID' => $this->joinID,
185                ));
186               
187        }
188}
189?>
Note: See TracBrowser for help on using the browser.