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

Revision 524, 14.1 kB (checked in by Tatzelwurm, 5 years ago)

WYSIWYG Adaption

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 Hrspiel
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                     = escapeString(StringUtil::trim($_REQUEST['name']));
64                if (isset($_POST['description']))       $this->description      = escapeString(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           = 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                        } else {
108                                if (@fopen($this->link,'rb') == false) {
109                                        throw new UserInputException('link', 'badFile');
110                                }
111                        }
112                } 
113                // Only if Action = add
114                if ($this->action == 'add') {
115                        // prÃŒfen ob ein Link UND File angegeben wurden
116                        if ($this->link && ($this->upload && $this->upload['error'] != 4)) {
117                                throw new UserInputException('link', 'invalid');
118                        }
119                }
120                $this->valid = true;
121        }
122
123        /**
124         * Create an new data set.
125         */
126        public function save() {
127                //Create new Dataset with FileUpload
128                if ($this->valid && $this->action == 'add'){
129                        // upload file if given
130                        if (!$this->link) {
131                                if ($this->upload && $this->upload['error'] != 4) {
132                                        if ($this->upload['error'] != 0) {
133                                                throw new UserInputException('upload', 'uploadFailed');
134                                        }
135                                        // import file
136                                        $this->dataID = DownloadDBDataEditor::createFile($this->upload['tmp_name'], $this->upload['name'], $this->upload['type'], 'upload');
137                                        $this->groesse = $this->upload['size'];
138                                } else {
139                                        throw new UserInputException('upload');
140                                }
141                        } else {
142                                if (FileUtil::isURL($this->link) == false) {
143                                        if ($this->link{0} == "/"){
144                                                if (FileUtil::isURL($_SERVER['DOCUMENT_ROOT'].$this->link) == false) {
145                                                        if (StringUtil::indexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') !== false) {
146                                                                $this->fileName = StringUtil::substring($_SERVER['DOCUMENT_ROOT'].$this->link, StringUtil::lastIndexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') + 1);
147                                                        }
148                                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
149                                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
150                                                        }
151                                                        $this->groesse = @filesize($_SERVER['DOCUMENT_ROOT'].$this->link);
152                                                        $this->mimeType = '';
153// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
154//                                                      $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
155//                                                      $this->mimeType = @finfo_file($finfo, $_SERVER['DOCUMENT_ROOT'].$this->link);
156// daher ist $mimeType = '';
157                                                }
158                                        } else {
159                                                if (FileUtil::isURL($this->link) == false) {
160                                                        if (StringUtil::indexOf($this->link, '/') !== false) {
161                                                                $this->fileName = StringUtil::substring($this->link, StringUtil::lastIndexOf($this->link, '/') + 1);
162                                                        }
163                                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
164                                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
165                                                        }
166                                                        $this->groesse  = @filesize($this->link);
167                                                        $this->mimeType = '';
168// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
169//                                                      $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
170//                                                      $this->mimeType = finfo_file($finfo, $this->link);
171// daher ist $mimeType = '';
172                                                }
173                                        }
174                                } else {
175                                        $this->fileName = $this->fileExtension = NULL;
176                                }
177                        }
178                        // check for Preview File
179                        if ($this->previewArray && $this->previewArray['error'] != 4) {
180                                if ($this->previewArray['error'] != 0) {
181                                        throw new UserInputException('previewIMG', 'uploadFailed');
182                                }
183                        } else {
184                                $this->previewFile = $this->previewIMG = NULL;
185                        }
186                        if ($this->dataID ) { //DataID durch File Upload erhalten
187                                $this->dldbUserID = WCF::getUser()->userID;
188                                $this->datum = TIME_NOW;
189                                $dataset = new downloadDBDataEditor($this->dataID);
190                                if ($this->previewArray && ($this->previewArray['error'] == 0)) {
191                                        // Vorschaubild anlegen und Variablen setzen
192                                        $this->previewIMG = $dataset->createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG');
193                                        $this->previewFile = $this->previewArray['name'];
194                                }
195                                if ($this->upload['error'] != 4) {
196                                        // File Upload: File anlegen und in DB schreiben
197                                        $this->fileName = $this->upload['name'];
198                                        $this->mimeType = $this->upload['type'];
199                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
200                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
201                                        }
202                                        // Link anlegen
203                                        $this->link = $dataset->getURL();
204                                        // Datensatz speichern  mit File
205                                        $dataset->updateDataset(array(
206                                                        'katID'                 => intval($this->katID),
207                                                        'name'                  => $this->name,
208                                                        'description'   => $this->description,
209                                                        'previewIMG'    => escapeString($this->previewIMG),
210                                                        'previewFile'   => StringUtil::encodeHTML($this->previewFile),
211                                                        'fileName'              => escapeString($this->fileName),
212                                                        'fileExtension' => escapeString($this->fileExtension),
213                                                        'mimeType'              => escapeString($this->mimeType),
214                                                        'link'                  => StringUtil::encodeHTML($this->link),
215                                                        'groesse'               => intval($this->groesse),
216                                                        'downloads'             => intval($this->downloads),
217                                                        'userID'                => intval($this->dldbUserID),
218                                                        'datum'                 => $this->datum,
219                                                        'sortOrder'             => intval($this->sortOrder),
220                                                        'thread'                => $this->supportThread,
221                                                        'activ'                 => true,
222                                                        'parseURL'              => intval($this->parseURL),
223                                                        'enableBBCodes' => intval($this->enableBBCodes),
224                                                        'enableHtml'    => intval($this->enableHtml),
225                                                        'enableSmilies' => intval($this->enableSmilies),
226                                                        'languageID'    => intval($this->languageID)));
227                                }
228                        } else {
229                                // dataID = NULL
230                                //Create new Dataset if no file is given
231                                $dataset = DownloadDBDataEditor::createDataset(intval($this->katID), $this->name, $this->description ,array(
232                                                        'link'                  => $this->link,
233                                                        'fileName'              => escapeString($this->fileName),
234                                                        'fileExtension' => escapeString($this->fileExtension),
235                                                        'mimeType'              => escapeString($this->mimeType),
236                                                        'groesse'               => intval($this->groesse),
237                                                        'downloads'             => intval($this->downloads),
238                                                        'userID'                => WCF::getUser()->userID,
239                                                        'datum'                 => TIME_NOW,
240                                                        'sortOrder'             => intval($this->sortOrder),
241                                                        'thread'                => $this->supportThread,
242                                                        'activ'                 => true,
243                                                        'parseURL'              => intval($this->parseURL),
244                                                        'enableBBCodes' => intval($this->enableBBCodes),
245                                                        'enableHtml'    => intval($this->enableHtml),
246                                                        'enableSmilies' => intval($this->enableSmilies),
247                                                        'languageID'    => intval($this->languageID)));
248                                // Vorschaubild anlegen und Variablen setzen
249                                if ($this->previewArray && ($this->previewArray['error'] == 0)) {
250                                        // Vorschaubild anlegen und Variablen setzen
251                                        $this->previewIMG  = StringUtil::encodeHTML(DownloadDBDataEditor::createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG'));
252                                        $this->previewFile = StringUtil::encodeHTML($this->previewArray['name']);
253                                        $dataset->updateDataset(array('previewIMG' => $this->previewIMG, 'previewFile' => $this->previewFile));
254                                }
255                        }
256                }
257                parent::save();
258                // reset values
259                $this->name = $this->description = $this->link = $this->supportThread = NULL;
260                $this->fileName = $this->fileExtension = $this->mimeType = NULL;
261                $this->previewFile = $this->previewIMG = NULL;
262                $this->groesse = $this->downloads = $this->katID = 0;
263                $this->sortOrder = $this->languageID = 1;
264                // reset cache
265                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbKat.php');
266                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php');
267                $this->saved();
268                // show success message
269                WCF::getTPL()->assign('success', true);
270        }
271       
272        /**
273         * @see Page::readData()
274         */
275        public function readData() {
276                parent::readData();
277                $this->languageID = WCF::getUser()->languageID;
278                // read Category Cache
279                WCF::getCache()->addResource('dldbKat',
280                        WCF_DIR.'cache/cache.dldbKat.php',
281                        WCF_DIR.'lib/system/cache/CacheBuilderDLDBKat.class.php');
282                $this->katCache = WCF::getCache()->get('dldbKat');
283                $this->readCategorys();
284        }
285
286        /**
287         * @see Page::assignVariables()
288         */
289        public function assignVariables() {
290                parent::assignVariables();
291
292                WCFACP::getMenu()->setActiveMenuItem($this->activeMenuItem);
293               
294                $languagesArray = WCF::getLanguage()->getAvailableLanguages();
295                       
296                for ($i = 0; $i < count($languagesArray); $i++) {
297                        $languageItems = $languagesArray[$i];
298                               
299                        $languageArray[] = array(
300                                        'languageID' => $languageItems['languageID'],
301                                        'languageName' => WCF::getLanguage()->get('wcf.global.language.'.$languageItems['languageCode']),
302                        );
303                }
304               
305                $maxFileSize = WCF::getUser()->getPermission('user.dldb.maxFileSize');
306               
307                WCF::getTPL()->assign(array(
308                        'katOptions'    => $this->katOptions,
309                        'katID'                 => $this->katID,
310                        'name'                  => stripslashes($this->name),
311                        'description'   => stripslashes($this->description),
312                        'previewIMG'    => $this->previewIMG,
313                        'previewFile'   => $this->previewFile,
314                        'previewArray'  => $this->previewArray,
315                        'fileName'              => $this->fileName,
316                        'fileExtension' => $this->fileExtension,
317                        'mimeType'              => $this->mimeType,
318                        'link'                  => $this->link,
319                        'groesse'               => $this->groesse,
320                        'downloads'             => $this->downloads,
321                        'dldbUserID'    => $this->dldbUserID,
322                        'datum'                 => $this->datum,
323                        'sortOrder'             => $this->sortOrder,
324                        'supportThread' => $this->supportThread,
325                        'activ'                 => $this->activ,
326                        'action'                => 'add',
327                        'previewExtensions' => DOWNLOADDB_ALLOWED_PREVIEW_EXT,
328                        'fileExtensions' => DOWNLOADDB_ALLOWED_FILE_EXT,
329                        'maxFileSize'   => $maxFileSize,
330                        'isExtern'              => $this->isExtern,
331                        'languageID'    => $this->languageID,
332                        'language'              => $languageArray
333                ));
334        }
335
336        /**
337         * Liste mglicher Unterkategorien. (erste Ebene)
338         */
339        protected function readSubKat($katID) {
340                foreach ($this->katCache as $ID => $kategorie) {
341                        if ($kategorie['topID'] == $katID) {
342                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
343                                // weitere Unterkategorien suchen
344                                $this->readSubKat($kategorie['katID']);
345                        }
346                }
347        }
348       
349        protected function readCategorys() {
350                // format options
351                foreach ($this->katCache as $ID => $kategorie) {
352                        if ($kategorie['topID'] == NULL) {
353                                $this->katOptions[$kategorie['katID']] = "&nbsp;&nbsp;&nbsp;&nbsp;".StringUtil::unescape($kategorie['name']);
354                                $this->readSubKat($kategorie['katID']);
355                        } 
356                }
357        }
358}
359?>
Note: See TracBrowser for help on using the browser.