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

Revision 453, 5.4 kB (checked in by Tatzelwurm, 5 years ago)

Verarbeiteun der Dateien verbessert.
Verlinken von Dateien die bereits auf dem Server liegen überarbeitet.
Links in der Form /pfad/datei.ext hinzugefügt.
Neue Sprache (hr.xml).

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         = ArrayUtil::toIntegerArray($_POST['groupIDs']);
56                if (isset($_POST['uploadGroups']))      $this->uploadGroups     = ArrayUtil::toIntegerArray($_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               
112                // forward to list page
113                header('Location: index.php?page=DownloadDBKatList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
114                exit;
115        }
116       
117        /**
118         * @see Page::readData()
119         */
120        public function readData() {
121                parent::readData();
122                $this->readCategorys();
123        }
124
125        /**
126         * @see Page::assignVariables()
127         */
128        public function assignVariables() {
129                parent::assignVariables();
130
131                WCF::getTPL()->assign(array(
132                        'topID'                         => $this->topID,
133                        'katOptions'            => $this->katOptions,
134                        'name'                          => $this->name,
135                        'description'           => $this->description,
136                        'groupIDs'                      => $this->groupIDs,
137                        'availableGroups'       => $this->getGroups(),
138                        'uploadGroups'          => $this->uploadGroups,
139                        'sortOrder'                     => $this->sortOrder,
140                        'action'                        => 'add'
141                ));
142        }
143
144        protected function readSubKat($katID) {
145                foreach ($this->katCache as $ID => $kategorie) {
146                        if ($kategorie['topID'] == $katID) {
147                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
148                                // weitere Unterkategorien suchen
149                                $this->readSubKat($kategorie['katID']);
150                        }
151                }
152        }
153       
154        protected function readCategorys() {
155                // format options
156                foreach ($this->katCache as $ID => $kategorie) {
157                        if ($kategorie['topID'] == NULL) {
158                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
159                                $this->readSubKat($kategorie['katID']);
160                        } 
161                }
162        }
163       
164        /**
165         * Returns a list of all available user groups.
166         *
167         * @return      array
168         */
169        private function getGroups() {
170                require_once(WCF_DIR.'lib/data/user/group/Group.class.php');
171                return Group::getAccessibleGroups(array(), array());
172        }
173
174}
175?>
Note: See TracBrowser for help on using the browser.