root/downloadDatabase/files/lib/acp/form/DownloadDBKatAddForm.class.php @ 589

Revision 589, 6.5 kB (checked in by Tatzelwurm, 5 years ago)
Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/acp/form/WysiwygCacheloaderForm.class.php');
4require_once(WCF_DIR.'lib/data/downloadDB/DownloadDBKatEditor.class.php');
5
6/**
7 * Download Database Admin Control Panel.
8 * Insert a Category.
9 *
10 * @author      Robert "Tatzelwurm" Hempel
11 * @copyright   2007/2008 INSIDE das Hörspiel
12 * @license     GNU LGPL http://www.gnu.org/licenses/lgpl.txt
13 * @package             de.inside.wcf.downloaddb
14 */
15
16class DownloadDBKatAddForm extends WysiwygCacheloaderForm {
17        public $templateName = 'downloadDBKatAdd';
18        public $activeMenuItem = 'wcf.acp.menu.link.content.dldb';
19        public $neededPermissions = 'admin.dldb.canAddKat';
20       
21        // Kategorie Variablen
22        public $katID;
23        public $topID;
24        public $katOptions = array();
25        public $name = '';
26        public $description = '';
27        public $sortOrder = 1;
28        public $groupIDs = array(1);
29        public $uploadGroups = array();
30        public $languageID = '1';
31       
32        public $showSettings = true;
33        public $showSmilies = true;
34        public $canUseSmilies = true;
35        public $showSignatureSetting = false;
36               
37        public $action;
38        private $valid = false;
39       
40        /**
41         * @see Page::readParameters()
42         */
43        public function readParameters() {
44                parent::readParameters();
45                        // read Cache
46                WCF::getCache()->addResource('dldbKat',
47                        WCF_DIR.'cache/cache.dldbKat.php',
48                        WCF_DIR.'lib/system/cache/CacheBuilderDLDBKat.class.php');
49                $this->katCache = WCF::getCache()->get('dldbKat');
50        }
51
52        /**
53         * @see Form::readFormParameters()
54         */
55        public function readFormParameters() {
56                parent::readFormParameters();
57                               
58                if (isset($_POST['topID']))                     $this->topID            = intval($_POST['topID']);
59                if (isset($_POST['name']))                      $this->name                     = StringUtil::trim($_POST['name']);
60                if (isset($_POST['description']))       $this->description      = StringUtil::trim($_POST['description']);
61                if (isset($_POST['groupIDs']))          $this->groupIDs         = ArrayUtil::toIntegerArray($_POST['groupIDs']);
62                if (isset($_POST['uploadGroups']))      $this->uploadGroups     = ArrayUtil::toIntegerArray($_POST['uploadGroups']);
63                if (isset($_POST['sortOrder']))         $this->sortOrder        = intval($_POST['sortOrder']);
64                if (isset($_POST['action']))            $this->action           = escapeString($_POST['action']);
65                if (isset($_POST['languageID']))        $this->languageID       = intval($_POST['languageID']);
66        }
67       
68        /**
69         * @see Form::validate()
70         */
71        public function validate() {
72                // prÃŒfen ob ein Titel eingegeben wurde
73                if (empty($this->name)) {
74                        throw new UserInputException('name', 'empty');
75                }
76                // user gruppen prÃŒfen und array anpassen
77                if (count($this->groupIDs) > 0) {
78                        require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
79                        $sql = "SELECT  groupID
80                                FROM    wcf".WCF_N."_group
81                                WHERE   groupID IN (".implode(',', $this->groupIDs).")";
82                        $result = WCF::getDB()->sendQuery($sql);
83                        $this->groupIDs = array();
84                        while ($row = WCF::getDB()->fetchArray($result)) {
85                                if (Group::isAccessibleGroup($row['groupID'])) {
86                                        $this->groupIDs[] = $row['groupID'];
87                                }
88                        }
89                }
90                // user gruppen die Dateien hochladen dÃŒrfen prÃŒfen und array anpassen
91                if (count($this->uploadGroups) > 0) {
92                        require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
93                        $sql = "SELECT  groupID
94                                FROM    wcf".WCF_N."_group
95                                WHERE   groupID IN (".implode(',', $this->uploadGroups).")";
96                        $result = WCF::getDB()->sendQuery($sql);
97                        $this->uploadGroups = array();
98                        while ($row = WCF::getDB()->fetchArray($result)) {
99                                if (Group::isAccessibleGroup($row['groupID'])) {
100                                        $this->uploadGroups[] = $row['groupID'];
101                                }
102                        }
103                }
104                $this->valid = true;
105        }
106
107        /**
108         * Create the data of an new Category.
109         */
110        public function save() {
111                //Create new Category
112                if ($this->valid && !$this->katID && $this->action == 'add'){
113                        // Kategorie speichern 
114                        // Neues Kategorie Objekt
115                        $moreData = array(
116                                        'parseURL'              => intval($this->parseURL),
117                                        'enableBBCodes' => intval($this->enableBBCodes),
118                                        'enableHtml'    => intval($this->enableHtml),
119                                        'enableSmilies' => intval($this->enableSmilies),
120                                        'languageID'    => $this->languageID
121                        );
122                        $category = DownloadDBKatEditor::createCategory($this->topID, escapeString($this->name), escapeString($this->description), $this->groupIDs, $this->uploadGroups, intval($this->sortOrder), $moreData);
123                }
124                $this->saved();
125               
126                // forward to list page
127                header('Location: index.php?page=DownloadDBKatList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
128                exit;
129        }
130       
131        /**
132         * @see Page::readData()
133         */
134        public function readData() {
135                parent::readData();
136                $this->languageID = WCF::getUser()->languageID;
137                $this->readCategorys();
138        }
139
140        /**
141         * @see Page::assignVariables()
142         */
143        public function assignVariables() {
144                parent::assignVariables();
145
146                WCFACP::getMenu()->setActiveMenuItem($this->activeMenuItem);
147               
148                $languagesArray = WCF::getLanguage()->getAvailableLanguages();
149                       
150                for ($i = 0; $i < count($languagesArray); $i++) {
151                        $languageItems = $languagesArray[$i];
152                               
153                        $languageArray[] = array(
154                                        'languageID' => $languageItems['languageID'],
155                                        'languageName' => WCF::getLanguage()->get('wcf.global.language.'.$languageItems['languageCode']),
156                        );
157                }
158               
159                WCF::getTPL()->assign(array(
160                        'topID'                         => $this->topID,
161                        'katOptions'            => $this->katOptions,
162                        'name'                          => $this->name,
163                        'description'           => $this->description,
164                        'groupIDs'                      => $this->groupIDs,
165                        'availableGroups'       => $this->getGroups(),
166                        'uploadGroups'          => $this->uploadGroups,
167                        'sortOrder'                     => $this->sortOrder,
168                        'action'                        => 'add',
169                        'enableBBCodes'         => $this->enableBBCodes,
170                        'enableHtml'            => $this->enableHtml,
171                        'enableSmilies'         => $this->enableSmilies,
172                        'language'                      => $languageArray,
173                        'languageID'            => $this->languageID
174                ));
175        }
176
177        protected function readSubKat($katID) {
178                foreach ($this->katCache as $ID => $kategorie) {
179                        if ($kategorie['topID'] == $katID) {
180                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$kategorie['name'];
181                                // weitere Unterkategorien suchen
182                                $this->readSubKat($kategorie['katID']);
183                        }
184                }
185        }
186       
187        protected function readCategorys() {
188                // format options
189                foreach ($this->katCache as $ID => $kategorie) {
190                        if ($kategorie['topID'] == NULL) {
191                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;".$kategorie['name'];
192                                $this->readSubKat($kategorie['katID']);
193                        } 
194                }
195        }
196       
197        /**
198         * Returns a list of all available user groups.
199         *
200         * @return      array
201         */
202        private function getGroups() {
203                require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
204                return Group::getAccessibleGroups(array(), array());
205        }
206
207}
208?>
Note: See TracBrowser for help on using the browser.