root/downloadDatabase/files/lib/acp/form/DownloadDBDataAddForm.class.php @ 537

Revision 537, 14.2 kB (checked in by Tatzelwurm, 5 years ago)

Verbesserte hr.xml
Style Anpassung für die Kategorie Ansicht
"Ungültiger Link" Fehler beim bearbeiten im ACP beseitigt

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/acp/form/WysiwygCacheloaderForm.class.php');
4require_once(WCF_DIR.'lib/data/downloadDB/DownloadDBDataEditor.class.php');
5require_once(WCF_DIR.'lib/system/io/Tar.class.php');
6
7
8/**
9 * Download Database Admin Control Panel.
10 * Hinzufgen eines Datensatzes.
11 *
12 * @author              Robert "Tatzelwurm" Hempel
13 * @copyright   2007/2008 INSIDE das Hörspiel
14 * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package             de.inside.wcf.downloaddb
16 */
17
18class DownloadDBDataAddForm extends WysiwygCacheloaderForm {
19        public $templateName = 'downloadDBDataAdd';
20        public $activeMenuItem = 'wcf.acp.menu.link.content.dldb';
21        public $neededPermissions = 'admin.dldb.canAddData';
22       
23        // Datensatz Variablen
24        public $dataID;
25        public $katID = 0;
26        public $katOptions = array();
27        public $name = '';
28        public $description = '';
29        public $previewIMG = NULL;
30        public $previewFile = NULL;
31        public $previewArray = array();
32        public $fileName = NULL;
33        public $fileExtension = NULL;
34        public $mimeType = NULL;
35        public $link = '';
36        public $groesse = 0;
37        public $downloads = 0;
38        public $dldbUserID;
39        public $datum;
40        public $sortOrder = 1;
41        public $supportThread = '';
42        public $activ = 0;
43        public $isExtern = false;
44        public $languageID = '1';
45       
46        public $showSettings = true;
47        public $showSmilies = true;
48        public $canUseSmilies = true;
49        public $showSignatureSetting = false;
50       
51        public $action;
52        public $upload;
53       
54        private $valid = false;
55       
56        /**
57         * @see Form::readFormParameters()
58         */
59        public function readFormParameters() {
60                parent::readFormParameters();
61                               
62                if (isset($_POST['katID']))                     $this->katID            = intval($_REQUEST['katID']);
63                if (isset($_POST['name']))                      $this->name                     = StringUtil::trim($_REQUEST['name']);
64                if (isset($_POST['description']))       $this->description      = StringUtil::trim($_POST['description']);
65                if (isset($_POST['previewIMG']))        $this->previewIMG       = StringUtil::encodeHTML($_POST['previewIMG']);
66                if (isset($_POST['previewFile']))       $this->previewFile      = StringUtil::encodeHTML($_POST['previewFile']);
67                if (isset($_POST['link']))                      $this->link                     = escapeString($_POST['link']);
68                if (isset($_POST['groesse']))           $this->groesse          = intval($_POST['groesse']);
69                if (isset($_POST['downloads']))         $this->downloads        = intval($_POST['downloads']);
70                if (isset($_POST['dldbUserID']))        $this->dldbUserID       = intval($_POST['dldbUserID']);
71                if (isset($_POST['dldbUserName']))      $this->dldbUserName     = escapeString($_POST['dldbUserName']);
72                if (isset($_POST['datum']))             $this->datum            = intval($_POST['datum']);
73                if (isset($_POST['sortOrder']))         $this->sortOrder        = intval($_POST['sortOrder']);
74                if (isset($_POST['supportThread']))     $this->supportThread = escapeString($_POST['supportThread']);
75                if (isset($_POST['activ']))                     $this->activ            = intval($_POST['activ']);
76                if (isset($_POST['languageID']))        $this->languageID       = intval($_POST['languageID']);
77                // for File Upload
78                if (isset($_FILES['upload']))           $this->upload           = $_FILES['upload'];
79                // for Preview Upload
80                if (isset($_FILES['previewArray']))     $this->previewArray = $_FILES['previewArray'];
81                // Action
82                if (isset($_POST['action']))            $this->action           = StringUtil::toLowerCase(escapeString($_POST['action']));
83        }
84       
85        /**
86         * @see Form::validate()
87         */
88        public function validate() {
89                // prÃŒfen ob ein Titel eingegeben wurde
90                if (empty($this->name)) {
91                        throw new UserInputException('name', 'empty');
92                }
93                // prÃŒfen ob eine Kategorie eingegeben wurde
94                if (empty($this->katID)) {
95                        throw new UserInputException('katID', 'invalid');
96                }
97                // prÃŒfen ob ein Link eingegeben wurde
98                if (empty($this->upload) && empty($this->link)) {
99                        throw new UserInputException('link', 'empty');
100                }
101                // prÃŒfen ob ein relativer Pfad eingegeben wurde
102                if ($this->link && (FileUtil::isURL($this->link) == false)) {
103                        if ($this->link{0} == "/"){
104                                if (@fopen($_SERVER['DOCUMENT_ROOT'].$this->link,'rb') == false) {
105                                        throw new UserInputException('link', 'badFile');
106                                }
107                        }
108                } 
109                // Only if Action = add
110                if ($this->action == 'add') {
111                        // prÃŒfen ob ein Link UND File angegeben wurden
112                        if ($this->link && ($this->upload && $this->upload['error'] != 4)) {
113                                throw new UserInputException('link', 'invalid');
114                        }
115                }
116                $this->valid = true;
117        }
118
119        /**
120         * Create an new data set.
121         */
122        public function save() {
123                //Create new Dataset with FileUpload
124                if ($this->valid && $this->action == 'add'){
125                        // upload file if given
126                        if (!$this->link) {
127                                if ($this->upload && $this->upload['error'] != 4) {
128                                        if ($this->upload['error'] != 0) {
129                                                throw new UserInputException('upload', 'uploadFailed');
130                                        }
131                                        // import file
132                                        $this->dataID = DownloadDBDataEditor::createFile($this->upload['tmp_name'], $this->upload['name'], $this->upload['type'], 'upload');
133                                        $this->groesse = intval($this->upload['size']);
134                                } else {
135                                        throw new UserInputException('upload');
136                                }
137                        } else {
138                                if (FileUtil::isURL($this->link) == false) {
139                                        if ($this->link{0} == "/"){
140                                                if (FileUtil::isURL($_SERVER['DOCUMENT_ROOT'].$this->link) == false) {
141                                                        if (StringUtil::indexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') !== false) {
142                                                                $this->fileName = StringUtil::substring($_SERVER['DOCUMENT_ROOT'].$this->link, StringUtil::lastIndexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') + 1);
143                                                        }
144                                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
145                                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
146                                                        }
147                                                        $this->groesse = @filesize($_SERVER['DOCUMENT_ROOT'].$this->link);
148// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
149//                                                      $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
150//                                                      $this->mimeType = @finfo_file($finfo, $_SERVER['DOCUMENT_ROOT'].$this->link);
151                                                        $this->mimeType = ''; /*#### Entfernen wenn fileinfo aktiv ist ###*/
152// daher ist $mimeType = '';
153                                                }
154                                        } else {
155                                                if (FileUtil::isURL($this->link) == false) {
156                                                        if (StringUtil::indexOf($this->link, '/') !== false) {
157                                                                $this->fileName = StringUtil::substring($this->link, StringUtil::lastIndexOf($this->link, '/') + 1);
158                                                        }
159                                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
160                                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
161                                                        }
162                                                        $this->groesse  = @filesize($this->link);
163                                                        $this->mimeType = '';
164// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
165//                                                      $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
166//                                                      $this->mimeType = @finfo_file($finfo, $_SERVER['DOCUMENT_ROOT'].$this->link);
167                                                        $this->mimeType = ''; /*#### Entfernen wenn fileinfo aktiv ist ###*/
168// daher ist $mimeType = '';
169                                                }
170                                        }
171                                } else {
172                                        $this->fileName = $this->fileExtension = NULL;
173                                }
174                        }
175                        // check for Preview File
176                        if ($this->previewArray && $this->previewArray['error'] != 4) {
177                                if ($this->previewArray['error'] != 0) {
178                                        throw new UserInputException('previewIMG', 'uploadFailed');
179                                }
180                        } else {
181                                $this->previewFile = $this->previewIMG = NULL;
182                        }
183                        if ($this->dataID ) { //DataID durch File Upload erhalten
184                                $this->dldbUserID = WCF::getUser()->userID;
185                                $this->datum = TIME_NOW;
186                                $dataset = new downloadDBDataEditor($this->dataID);
187                                if ($this->previewArray && ($this->previewArray['error'] == 0)) {
188                                        // Vorschaubild anlegen und Variablen setzen
189                                        $this->previewIMG = $dataset->createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG');
190                                        $this->previewFile = $this->previewArray['name'];
191                                }
192                                if ($this->upload['error'] != 4) {
193                                        // File Upload: File anlegen und in DB schreiben
194                                        $this->fileName = $this->upload['name'];
195                                        $this->mimeType = $this->upload['type'];
196                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
197                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
198                                        }
199                                        // Link anlegen
200                                        $this->link = $dataset->getURL();
201                                        // Datensatz speichern  mit File
202                                        $dataset->updateDataset(array(
203                                                        'katID'                 => intval($this->katID),
204                                                        'name'                  => escapeString($this->name),
205                                                        'description'   => escapeString($this->description),
206                                                        'previewIMG'    => escapeString($this->previewIMG),
207                                                        'previewFile'   => StringUtil::encodeHTML($this->previewFile),
208                                                        'fileName'              => escapeString($this->fileName),
209                                                        'fileExtension' => escapeString($this->fileExtension),
210                                                        'mimeType'              => escapeString($this->mimeType),
211                                                        'link'                  => StringUtil::encodeHTML($this->link),
212                                                        'groesse'               => intval($this->groesse),
213                                                        'downloads'             => intval($this->downloads),
214                                                        'userID'                => intval($this->dldbUserID),
215                                                        'datum'                 => $this->datum,
216                                                        'sortOrder'             => intval($this->sortOrder),
217                                                        'thread'                => $this->supportThread,
218                                                        'activ'                 => true,
219                                                        'parseURL'              => intval($this->parseURL),
220                                                        'enableBBCodes' => intval($this->enableBBCodes),
221                                                        'enableHtml'    => intval($this->enableHtml),
222                                                        'enableSmilies' => intval($this->enableSmilies),
223                                                        'languageID'    => intval($this->languageID)));
224                                }
225                        } else {
226                                // dataID = NULL
227                                //Create new Dataset if no file is given
228                                $dataset = DownloadDBDataEditor::createDataset(intval($this->katID), escapeString($this->name), escapeString($this->description) ,array(
229                                                        'link'                  => $this->link,
230                                                        'fileName'              => escapeString($this->fileName),
231                                                        'fileExtension' => escapeString($this->fileExtension),
232                                                        'mimeType'              => escapeString($this->mimeType),
233                                                        'groesse'               => intval($this->groesse),
234                                                        'downloads'             => intval($this->downloads),
235                                                        'userID'                => WCF::getUser()->userID,
236                                                        'datum'                 => TIME_NOW,
237                                                        'sortOrder'             => intval($this->sortOrder),
238                                                        'thread'                => $this->supportThread,
239                                                        'activ'                 => true,
240                                                        'parseURL'              => intval($this->parseURL),
241                                                        'enableBBCodes' => intval($this->enableBBCodes),
242                                                        'enableHtml'    => intval($this->enableHtml),
243                                                        'enableSmilies' => intval($this->enableSmilies),
244                                                        'languageID'    => intval($this->languageID)));
245                                // Vorschaubild anlegen und Variablen setzen
246                                if ($this->previewArray && ($this->previewArray['error'] == 0)) {
247                                        // Vorschaubild anlegen und Variablen setzen
248                                        $this->previewIMG  = StringUtil::encodeHTML(DownloadDBDataEditor::createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG'));
249                                        $this->previewFile = StringUtil::encodeHTML($this->previewArray['name']);
250                                        $dataset->updateDataset(array('previewIMG' => $this->previewIMG, 'previewFile' => $this->previewFile));
251                                }
252                        }
253                }
254                parent::save();
255                // reset values
256                $this->name = $this->description = $this->link = $this->supportThread = NULL;
257                $this->fileName = $this->fileExtension = $this->mimeType = NULL;
258                $this->previewFile = $this->previewIMG = NULL;
259                $this->groesse = $this->downloads = $this->katID = 0;
260                $this->sortOrder = $this->languageID = 1;
261                // reset cache
262                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbKat.php');
263                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php');
264                $this->saved();
265                // show success message
266                WCF::getTPL()->assign('success', true);
267        }
268       
269        /**
270         * @see Page::readData()
271         */
272        public function readData() {
273                parent::readData();
274                $this->languageID = WCF::getUser()->languageID;
275                // read Category Cache
276                WCF::getCache()->addResource('dldbKat',
277                        WCF_DIR.'cache/cache.dldbKat.php',
278                        WCF_DIR.'lib/system/cache/CacheBuilderDLDBKat.class.php');
279                $this->katCache = WCF::getCache()->get('dldbKat');
280                $this->readCategorys();
281        }
282
283        /**
284         * @see Page::assignVariables()
285         */
286        public function assignVariables() {
287                parent::assignVariables();
288
289                WCFACP::getMenu()->setActiveMenuItem($this->activeMenuItem);
290               
291                $languagesArray = WCF::getLanguage()->getAvailableLanguages();
292                       
293                for ($i = 0; $i < count($languagesArray); $i++) {
294                        $languageItems = $languagesArray[$i];
295                               
296                        $languageArray[] = array(
297                                        'languageID' => $languageItems['languageID'],
298                                        'languageName' => WCF::getLanguage()->get('wcf.global.language.'.$languageItems['languageCode']),
299                        );
300                }
301               
302                $maxFileSize = WCF::getUser()->getPermission('user.dldb.maxFileSize');
303               
304                WCF::getTPL()->assign(array(
305                        'katOptions'    => $this->katOptions,
306                        'katID'                 => $this->katID,
307                        'name'                  => $this->name,
308                        'description'   => $this->description,
309                        'previewIMG'    => $this->previewIMG,
310                        'previewFile'   => $this->previewFile,
311                        'previewArray'  => $this->previewArray,
312                        'fileName'              => $this->fileName,
313                        'fileExtension' => $this->fileExtension,
314                        'mimeType'              => $this->mimeType,
315                        'link'                  => $this->link,
316                        'groesse'               => $this->groesse,
317                        'downloads'             => $this->downloads,
318                        'dldbUserID'    => $this->dldbUserID,
319                        'datum'                 => $this->datum,
320                        'sortOrder'             => $this->sortOrder,
321                        'supportThread' => $this->supportThread,
322                        'activ'                 => $this->activ,
323                        'action'                => 'add',
324                        'previewExtensions' => DOWNLOADDB_ALLOWED_PREVIEW_EXT,
325                        'fileExtensions' => DOWNLOADDB_ALLOWED_FILE_EXT,
326                        'maxFileSize'   => $maxFileSize,
327                        'isExtern'              => $this->isExtern,
328                        'languageID'    => $this->languageID,
329                        'language'              => $languageArray
330                ));
331        }
332
333        /**
334         * Liste mglicher Unterkategorien. (erste Ebene)
335         */
336        protected function readSubKat($katID) {
337                foreach ($this->katCache as $ID => $kategorie) {
338                        if ($kategorie['topID'] == $katID) {
339                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
340                                // weitere Unterkategorien suchen
341                                $this->readSubKat($kategorie['katID']);
342                        }
343                }
344        }
345       
346        protected function readCategorys() {
347                // format options
348                foreach ($this->katCache as $ID => $kategorie) {
349                        if ($kategorie['topID'] == NULL) {
350                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
351                                $this->readSubKat($kategorie['katID']);
352                        } 
353                }
354        }
355}
356?>
Note: See TracBrowser for help on using the browser.