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

Revision 402, 5.4 kB (checked in by Tatzelwurm, 5 years ago)
Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/acp/form/ACPForm.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 ACPForm {
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       
31        public $action;
32        private $valid = false;
33       
34        /**
35         * @see Page::readParameters()
36         */
37        public function readParameters() {
38                parent::readParameters();
39                        // read Cache
40                WCF::getCache()->addResource('dldbKat',
41                        WCF_DIR.'cache/cache.dldbKat.php',
42                        WCF_DIR.'lib/system/cache/CacheBuilderDLDBKat.class.php');
43                $this->katCache = WCF::getCache()->get('dldbKat');
44        }
45
46        /**
47         * @see Form::readFormParameters()
48         */
49        public function readFormParameters() {
50                parent::readFormParameters();
51                               
52                if (isset($_POST['topID']))                     $this->topID            = intval($_REQUEST['topID']);
53                if (isset($_POST['name']))                      $this->name                     = escapeString(StringUtil::trim($_REQUEST['name']));
54                if (isset($_POST['description']))       $this->description      = escapeString(StringUtil::trim($_POST['description']));
55                if (isset($_POST['groupIDs']))          $this->groupIDs         = $_POST['groupIDs'];
56                if (isset($_POST['uploadGroups']))      $this->uploadGroups     = $_POST['uploadGroups'];
57                if (isset($_POST['sortOrder']))         $this->sortOrder        = intval($_POST['sortOrder']);
58                if (isset($_POST['action']))            $this->action           = escapeString($_POST['action']);
59        }
60       
61        /**
62         * @see Form::validate()
63         */
64        public function validate() {
65                // prÃŒfen ob ein Titel eingegeben wurde
66                if (empty($this->name)) {
67                        throw new UserInputException('name', 'empty');
68                }
69                // user gruppen prÃŒfen und array anpassen
70                if (count($this->groupIDs) > 0) {
71                        require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
72                        $sql = "SELECT  groupID
73                                FROM    wcf".WCF_N."_group
74                                WHERE   groupID IN (".implode(',', $this->groupIDs).")";
75                        $result = WCF::getDB()->sendQuery($sql);
76                        $this->groupIDs = array();
77                        while ($row = WCF::getDB()->fetchArray($result)) {
78                                if (Group::isAccessibleGroup($row['groupID'])) {
79                                        $this->groupIDs[] = $row['groupID'];
80                                }
81                        }
82                }
83                // user gruppen die Dateien hochladen dÃŒrfen prÃŒfen und array anpassen
84                if (count($this->uploadGroups) > 0) {
85                        require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
86                        $sql = "SELECT  groupID
87                                FROM    wcf".WCF_N."_group
88                                WHERE   groupID IN (".implode(',', $this->uploadGroups).")";
89                        $result = WCF::getDB()->sendQuery($sql);
90                        $this->uploadGroups = array();
91                        while ($row = WCF::getDB()->fetchArray($result)) {
92                                if (Group::isAccessibleGroup($row['groupID'])) {
93                                        $this->uploadGroups[] = $row['groupID'];
94                                }
95                        }
96                }
97                $this->valid = true;
98        }
99
100        /**
101         * Create the data of an new Category.
102         */
103        public function save() {
104                //Create new Category
105                if ($this->valid && !$this->katID && $this->action == 'add'){
106                        // Kategorie speichern 
107                        // Neues Kategorie Objekt
108                        $category = DownloadDBKatEditor::createCategory($this->topID, $this->name, $this->description, $this->groupIDs, $this->uploadGroups, intval($this->sortOrder));
109                }
110                $this->saved();
111//              // reset Category cache
112//              WCF::getCache()->clear(WCF_DIR.'cache', 'cache.dldbKat.php');
113               
114                // forward to list page
115                header('Location: index.php?page=DownloadDBKatList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
116                exit;
117        }
118       
119        /**
120         * @see Page::readData()
121         */
122        public function readData() {
123                parent::readData();
124                $this->readCategorys();
125        }
126
127        /**
128         * @see Page::assignVariables()
129         */
130        public function assignVariables() {
131                parent::assignVariables();
132
133                WCF::getTPL()->assign(array(
134                        'topID'                         => $this->topID,
135                        'katOptions'            => $this->katOptions,
136                        'name'                          => $this->name,
137                        'description'           => $this->description,
138                        'groupIDs'                      => $this->groupIDs,
139                        'availableGroups'       => $this->getGroups(),
140                        'uploadGroups'          => $this->uploadGroups,
141                        'sortOrder'                     => $this->sortOrder,
142                        'action'                        => 'add'
143                ));
144        }
145
146        protected function readSubKat($katID) {
147                foreach ($this->katCache as $ID => $kategorie) {
148                        if ($kategorie['topID'] == $katID) {
149                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
150                                // weitere Unterkategorien suchen
151                                $this->readSubKat($kategorie['katID']);
152                        }
153                }
154        }
155       
156        protected function readCategorys() {
157                // format options
158                foreach ($this->katCache as $ID => $kategorie) {
159                        if ($kategorie['topID'] == NULL) {
160                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
161                                $this->readSubKat($kategorie['katID']);
162                        } 
163                }
164        }
165       
166        /**
167         * Returns a list of all available user groups.
168         *
169         * @return      array
170         */
171        private function getGroups() {
172                require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
173                return Group::getAccessibleGroups(array(), array());
174        }
175
176}
177?>
Note: See TracBrowser for help on using the browser.