root/downloadDatabase/files/lib/acp/form/DownloadDBDataEditForm.class.php @ 668

Revision 668, 10.7 kB (checked in by Tatzelwurm, 5 years ago)

New Filenames for Uploads.
Some Eventlistener Points added.

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/acp/form/DownloadDBDataAddForm.class.php');
4
5/**
6 * Download Database Admin Control Panel.
7 * Bearbeiten eines Datensatzes.
8 *
9 * @author              Robert "Tatzelwurm" Hempel
10 * @copyright   2007/2008 INSIDE das Hörspiel
11 * @license     GNU LGPL http://www.gnu.org/licenses/lgpl.txt
12 * @package             de.inside.wcf.DownloadDatabase
13 */
14
15class DownloadDBDataEditForm extends DownloadDBDataAddForm {
16        public $templateName = 'downloadDBDataAdd';
17        public $activeMenuItem = 'wcf.acp.menu.link.content.dldb';
18        public $neededPermissions = 'admin.dldb.canAddData';
19       
20        public $dataID = 0;
21
22        private $downloadsAkt = 0;
23        private $userIDAkt = 0;
24        private $datumAkt = 0;
25        private $delPreview = 0;
26        private $fileNameAlt ='';
27        public  $dldbUserName;
28       
29        /**
30         * @see Page::readParameters()
31         */
32        public function readParameters() {
33                parent::readParameters();
34                // get data id
35                if(isset($_REQUEST['dataID']))  $this->dataID   = intval($_REQUEST['dataID']);
36                if (!$this->dataID){
37                        require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php');
38                        throw new NamedUserException(WCF::getLanguage()->get('wcf.dldb.wrongid'));
39                        exit;
40                }
41        }
42
43        /**
44         * @see Form::readFormParameters()
45         */
46        public function readFormParameters() {
47                parent::readFormParameters();
48                               
49                if (isset($_POST['UserIDAkt']))         $this->userIDAkt        = intval($_POST['UserIDAkt']);
50                if (isset($_POST['datumAkt']))          $this->datumAkt         = intval($_POST['datumAkt']);
51                if (isset($_POST['downloadsAkt']))      $this->downloadsAkt     = intval($_POST['downloadsAkt']);
52                if (isset($_POST['delPreview']))        $this->delPreview       = intval($_POST['delPreview']);
53                if (isset($_POST['fileName']))          $this->fileName         = $_POST['fileName'];
54                if (isset($_POST['fileNameAlt']))       $this->fileNameAlt      = $_POST['fileNameAlt'];
55                if (isset($_POST['fileExtension'])) $this->fileExtension = escapeString($_POST['fileExtension']);
56                if (isset($_POST['mimeType']))          $this->mimeType         = escapeString($_POST['mimeType']);
57        }
58       
59        /**
60         * @see Page::readData()
61         */
62        public function readData() {
63                parent::readData();
64                // Daten einlesen
65                if (!count($_POST)) {
66                        $this->readDaten();
67                }
68        }
69
70        /**
71         * @see Page::assignVariables()
72         */
73        public function assignVariables() {
74                parent::assignVariables();
75
76                WCF::getTPL()->assign(array(
77                        'action'                => 'edit',
78                        'dataID'                => $this->dataID,
79                        'fileNameAlt'   => $this->fileNameAlt,
80                        'downloadsAkt'  => $this->downloadsAkt,
81                        'datumAkt'              => $this->datumAkt,
82                        'UserIDAkt'     => $this->userIDAkt,
83                        'delPreview'    => $this->delPreview,
84                        'dldbUserName'  => $this->dldbUserName,
85                        ));
86        }
87
88        /**
89         * @see Form::validate()
90         */
91        public function validate() {
92                parent::validate();
93               
94                $this->valid = true;
95        }
96               
97        /**
98         * Updates the data of an existing File/Link.
99         */
100        public function save() {
101                if ($this->valid && $this->dataID) {
102                        $dataset = new DownloadDBDataEditor($this->dataID);
103                        if ($this->downloadsAkt)        $this->downloads = 0; else $this->downloads = $dataset->downloads;
104                        if ($this->datumAkt)            $this->datum = TIME_NOW; else $this->datum      = $dataset->datum;
105                        if ($this->userIDAkt)           $this->dldbUserID = WCF::getUser()->userID;
106
107                        // Bei neuem Prewiew Upload den alten file löschen und den neuen anlegen
108                        if ($this->previewArray && $this->previewArray['error'] != 4) {
109                                // auf Fehler beim Upload prÃŒfen
110                                if ($this->previewArray['error'] != 0) {
111                                        throw new UserInputException('previewIMG', 'uploadFailed');
112                                }
113                                if ($this->previewFile != $this->previewArray['name']) {
114                                        // alten File löschen wenn neuer angegeben wurde
115                                        $dataset->deletePreview($this->previewFile);
116                                }
117                                // neuen File anlegen
118                                $this->previewFile = $this->previewArray['name'];
119                                $this->previewIMG = DownloadDBDataEditor::createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG');
120                        } else {
121                                $this->previewFile      = $dataset->previewFile;
122                                $this->previewIMG       = $dataset->previewIMG;
123                        }
124
125                        // Delete preview?
126                        if ($this->delPreview) {
127                                $dataset->deletePreview($this->previewFile);
128                                $this->previewFile = $this->previewIMG = NULL;
129                        } 
130
131                        // Bei neuem Upload den alten file löschen und den neuen anlegen
132                        $upld = false;
133                        if ($this->upload && $this->upload['error'] != 4) {
134                                $upld = true;
135                                // auf Fehler beim Upload prÃŒfen
136                                if ($this->upload['error'] != 0) {
137                                        throw new UserInputException('upload', 'uploadFailed');
138                                }
139                                // alten File löschen und neuen anlegen
140                                DownloadDBDataEditor::updateFile($this->fileNameAlt, $this->upload['tmp_name'], $this->upload['name'], $this->upload['type'], 'upload');
141                                //Variablen anpassen
142                                $this->fileName = $this->upload['name'];
143                                $this->mimeType = $this->upload['type'];
144                                $this->groesse  = $this->upload['size'];
145                                if (StringUtil::indexOf($this->fileName, '.') !== false) {
146                                        $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
147                                }
148                                $this->link = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR.intval($dataset->dataID).'_'.StringUtil::encodeHTML($this->fileName));
149                        }
150                        if (!$upld && $this->link && ($this->link != escapeString($dataset->link))) {
151                                if (FileUtil::isURL($this->link) == false) {
152                                        if ($this->link{0} == "/"){
153                                                if (StringUtil::indexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') !== false) {
154                                                        $this->fileName = StringUtil::substring($_SERVER['DOCUMENT_ROOT'].$this->link, StringUtil::lastIndexOf($_SERVER['DOCUMENT_ROOT'].$this->link, '/') + 1);
155                                                }
156                                                if (StringUtil::indexOf($this->fileName, '.') !== false) {
157                                                        $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
158                                                }
159                                                $this->groesse = @filesize($_SERVER['DOCUMENT_ROOT'].$this->link);
160                                                $this->mimeType = '';
161// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
162//                                              $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
163//                                              $this->mimeType = finfo_file($finfo, $_SERVER['DOCUMENT_ROOT'].$this->link);
164// daher ist $mimeType = '';
165                                        } else {
166                                                if (StringUtil::indexOf($this->link, '/') !== false) {
167                                                        $this->fileName = StringUtil::substring($this->link, StringUtil::lastIndexOf($this->link, '/') + 1);
168                                                }
169                                                if (StringUtil::indexOf($this->fileName, '.') !== false) {
170                                                        $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
171                                                }
172                                                $this->groesse = @filesize($this->link);
173                                                $this->mimeType = '';
174// Funktioniert nur wenn "fileinfo" in php aktiviert ist!!
175//                                              $finfo = @finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension
176//                                              $this->mimeType = finfo_file($finfo, $this->link);
177// daher ist $mimeType = '';
178                                        }
179                                } else {
180                                        $this->fileName = $this->fileExtension = $this->mimeType = NULL;
181                                }
182                        } else {
183                                $this->link                     = $dataset->link;
184                                $this->fileName                 = $dataset->fileName;
185                                $this->fileExtension    = $dataset->fileExtension;
186                                $this->mimeType                 = $dataset->mimeType;
187                        }
188                        // Daten endgltig speichern
189                        $dataset->updateDataset(array_merge($this->additionalFields, array(
190                                                        'katID'                 => intval($this->katID),
191                                                        'name'                  => escapeString($this->name),
192                                                        'description'   => escapeString($this->description),
193                                                        'previewIMG'    => escapeString($this->previewIMG),
194                                                        'previewFile'   => StringUtil::encodeHTML($this->previewFile),
195                                                        'fileName'              => escapeString($this->fileName),
196                                                        'fileExtension' => escapeString($this->fileExtension),
197                                                        'mimeType'              => escapeString($this->mimeType),
198                                                        'link'                  => $this->link,
199                                                        'groesse'               => intval($this->groesse),
200                                                        'downloads'             => intval($this->downloads),
201                                                        'userID'                => intval($this->dldbUserID),
202                                                        'datum'                 => $this->datum,
203                                                        'sortOrder'             => intval($this->sortOrder),
204                                                        'thread'                => $this->supportThread,
205                                                        'activ'                 => true,
206                                                        'parseURL'              => intval($this->parseURL),
207                                                        'enableBBCodes' => intval($this->enableBBCodes),
208                                                        'enableHtml'    => intval($this->enableHtml),
209                                                        'enableSmilies' => intval($this->enableSmilies),
210                                                        'languageID'    => intval($this->languageID)
211                        )));
212                }
213                // show success message
214                WCF::getTPL()->assign('success', true);
215               
216                // delete category cache
217                WCF::getCache()->clear(WCF_DIR.'cache', 'cache.dldbKat.php');
218
219                $this->saved();
220                // forward to list page
221                header('Location: index.php?page=DownloadDBDataList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
222                exit;
223        }
224
225        protected function readDaten() {
226                WCF::getCache()->addResource('dldbData',
227                                WCF_DIR.'cache/cache.dldbData.php',
228                                WCF_DIR.'lib/system/cache/CacheBuilderDLDBData.class.php');
229                $this->dataCache = WCF::getCache()->get('dldbData');
230                // get data
231                foreach ($this->dataCache as $ID => $data) {
232                        if ($data['dataID'] == $this->dataID) {
233                                $this->katID                    = $data['katID'];
234                                $this->name                             = $data['name'];
235                                $this->description              = $data['description'];
236                                $this->previewFile              = $data['previewFile'];
237                                if ($this->previewFile) {
238                                        $ext = StringUtil::toLowerCase(StringUtil::substring($data['previewFile'], StringUtil::lastIndexOf($data['previewFile'], '.') + 1));
239                                        if (@fopen(FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.'thumbnail-'.$this->dataID.'.'.$ext),'rb') == false) {
240                                                $this->previewIMG = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.'Preview-'.$this->dataID.'.'.$ext);
241                                        } else {
242                                                $this->previewIMG       = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.'thumbnail-'.$this->dataID.'.'.$ext);
243                                        }
244                                } else {
245                                        $this->previewIMG       = '';
246                                }
247                                $this->fileName                 = $this->fileNameAlt = $data['fileName'];
248                                $this->fileExtension    = $data['fileExtension'];
249                                $this->mimeType                 = $data['mimeType'];
250                                $this->link                             = StringUtil::decodeHTML($data['link']);
251                                if (FileUtil::isURL($this->link) == true || $this->link{0} == "/") $this->isExtern = true;
252                                $this->groesse                  = $data['groesse'];
253                                $this->downloads                = $data['downloads'];
254                                $this->dldbUserID               = $data['dldbUserID'];
255                                $this->dldbUserName             = $data['dldbUsername'];
256                                $this->datum                    = $data['datum'];
257                                $this->sortOrder                = $data['sortOrder'];
258                                $this->supportThread    = StringUtil::decodeHTML($data['thread']);
259                                $this->activ                    = $data['activ'];
260                                $this->parseURL                 = $data['parseURL'];
261                                $this->enableSmilies    = $data['enableSmilies'];
262                                $this->enableHtml               = $data['enableHtml'];
263                                $this->enableBBCodes    = $data['enableBBCodes'];
264                                $this->languageID               = $data['languageID'];
265                        }
266                WCF::getCache()->clearResource('dldbData');
267                }
268        }
269
270}
271?>
Note: See TracBrowser for help on using the browser.