root/downloadDatabase/files/lib/form/DownloadDBEditDataForm.class.php @ 668

Revision 668, 10.2 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/form/DownloadDBAddDataForm.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 DownloadDBEditDataForm extends DownloadDBAddDataForm {
16        public $templateName = 'downloadDBUserUploadData';
17        public $neededPermissions = 'user.dldb.canUploadFile';
18               
19        public $dataID = 0;
20
21        private $downloadsAkt = 0;
22        private $datumAkt = 0;
23        private $fileNameAlt ='';
24        private $delPreview = 0;
25        private $dldbUserName;
26       
27        /**
28         * @see Page::readParameters()
29         */
30        public function readParameters() {
31                parent::readParameters();
32                // get data id
33                if(isset($_REQUEST['dataID']))  $this->dataID   = intval($_REQUEST['dataID']);
34                if (!$this->dataID){
35                        require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php');
36                        throw new NamedUserException(WCF::getLanguage()->get('wcf.dldb.wrongid'));
37                        exit;
38                }
39        }
40
41        /**
42         * @see Form::readFormParameters()
43         */
44        public function readFormParameters() {
45                parent::readFormParameters();
46                               
47                if (isset($_POST['datumAkt']))          $this->datumAkt         = intval($_POST['datumAkt']);
48                if (isset($_POST['downloadsAkt']))      $this->downloadsAkt     = intval($_POST['downloadsAkt']);
49                if (isset($_POST['delPreview']))        $this->delPreview       = intval($_POST['delPreview']);
50                if (isset($_POST['fileName']))          $this->fileName         = $_POST['fileName'];
51                if (isset($_POST['fileNameAlt']))       $this->fileNameAlt      = $_POST['fileNameAlt'];
52                if (isset($_POST['fileExtension'])) $this->fileExtension = escapeString($_POST['fileExtension']);
53                if (isset($_POST['mimeType']))          $this->mimeType         = escapeString($_POST['mimeType']);
54        }
55       
56        /**
57         * @see Page::readData()
58         */
59        public function readData() {
60                parent::readData();
61                if (!count($_POST)) {
62                        // get data
63                        $this->readDaten();
64                }
65        }
66
67        /**
68         * @see Page::assignVariables()
69         */
70        public function assignVariables() {
71                parent::assignVariables();
72
73                WCF::getTPL()->assign(array(
74                        'action'                => 'edit',
75                        'dataID'                => $this->dataID,
76                        'fileNameAlt'   => $this->fileNameAlt,
77                        'downloadsAkt'  => $this->downloadsAkt,
78                        'datumAkt'              => $this->datumAkt,
79                        'delPreview'    => $this->delPreview,
80                        'dldbUserName'  => $this->dldbUserName,
81                        ));
82        }
83
84        /**
85         * @see Page::show()
86         */
87        public function show() {
88                parent::show();
89        }
90       
91        /**
92         * @see Form::validate()
93         */
94        public function validate() {
95                parent::validate();
96               
97                $this->valid = true;
98        }
99               
100        /**
101         * Updates the data of an existing File/Link.
102         */
103        public function save() {
104                if ($this->valid && $this->dataID) {
105                        $dataset = new DownloadDBDataEditor($this->dataID);
106                        if ($this->downloadsAkt)        $this->downloads = 0;           else $this->downloads   = $dataset->downloads;
107                        if ($this->datumAkt)            $this->datum = TIME_NOW;        else $this->datum               = $dataset->datum;
108                        $this->dldbUserID = $dataset->userID;
109                        $this->activ = false;
110                        if(WCF::getUser()->getPermission('user.dldb.canUploadFilewithoutAdmin')) {
111                                $this->activ = true;
112                        }
113                        // Bei neuem Prewiew Upload den alten file löschen und den neuen anlegen
114                        if ($this->previewArray && $this->previewArray['error'] != 4) {
115                                // auf Fehler beim Upload prÃŒfen
116                                if ($this->previewArray['error'] != 0) {
117                                        throw new UserInputException('previewIMG', 'uploadFailed');
118                                }
119                                if ($this->previewFile != $this->previewArray['name']) {
120                                        // alten File löschen wenn neuer angegeben wurde
121                                        $dataset->deletePreview($this->previewFile);
122                                }
123                                // neuen File anlegen
124                                $this->previewFile = $this->previewArray['name'];
125                                $this->previewIMG = $dataset->createPreview($this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG');
126                        } else {
127                                $this->previewFile      = $dataset->previewFile;
128                                $this->previewIMG       = $dataset->previewIMG;
129                        }
130                        // Delete preview?
131                        if ($this->delPreview) {
132                                $dataset->deletePreview($this->previewFile);
133                                $this->previewFile = $this->previewIMG = NULL;
134                        } 
135                        // Bei neuem Upload den alten file löschen und den neuen anlegen
136                        $upld = false;
137                        if ($this->upload && $this->upload['error'] != 4) {
138                                $upld = true;
139                                // auf Fehler beim Upload prÃŒfen
140                                if ($this->upload['error'] != 0) {
141                                        throw new UserInputException('upload', 'uploadFailed');
142                                }
143                                // alten File löschen und neuen anlegen
144                                DownloadDBDataEditor::updateFile($this->fileNameAlt, $this->upload['tmp_name'], $this->upload['name'], $this->upload['type'], 'upload');
145                                //Variablen anpassen
146                                $this->fileName = $this->upload['name'];
147                                $this->mimeType = $this->upload['type'];
148                                $this->groesse  = $this->upload['size'];
149                                if (StringUtil::indexOf($this->fileName, '.') !== false) {
150                                        $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
151                                }
152                                $this->link = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR.'Upload-'.intval($dataset->dataID).'.'.$this->fileExtension);
153                        }
154//                      if (!$upld && $this->link && ($this->link != escapeString($dataset->link))) {
155//                                      if (StringUtil::indexOf($this->link, '/') !== false) {
156//                                              $this->fileName = StringUtil::substring($this->link, StringUtil::lastIndexOf($this->link, '/') + 1);
157//                                      }
158//                                      if (StringUtil::indexOf($this->fileName, '.') !== false) {
159//                                              $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
160//                                      }
161//                                      $this->groesse = @filesize($this->link);
162//                      }
163                        // Daten endgÃŒltig speichern
164                        $dataset->updateDataset(array_merge($this->additionalFields, array(
165                                'katID'                 => intval($this->katID),
166                                'name'                  => escapeString($this->name),
167                                'description'   => escapeString($this->description),
168                                'previewIMG'    => escapeString($this->previewIMG),
169                                'previewFile'   => StringUtil::encodeHTML($this->previewFile),
170                                'fileName'              => escapeString($this->fileName),
171                                'fileExtension' => escapeString($this->fileExtension),
172                                'mimeType'              => escapeString($this->mimeType),
173                                'link'                  => $this->link,
174                                'groesse'               => intval($this->groesse),
175                                'downloads'             => intval($this->downloads),
176                                'userID'                => intval($this->dldbUserID),
177                                'datum'                 => $this->datum,
178                                'sortOrder'             => intval($this->sortOrder),
179                                'thread'                => $this->supportThread,
180                                'activ'                 => $this->activ,
181                                'parseURL'              => intval($this->parseURL),
182                                'enableBBCodes' => intval($this->enableBBCodes),
183                                'enableHtml'    => intval($this->enableHtml),
184                                'enableSmilies' => intval($this->enableSmilies),
185                                'languageID'    => intval($this->languageID)
186                        )));
187                       
188                        if ($this->activ == false) {
189                                // E-Mail an Admin senden !!
190                                $dldbAdmin = new UserSession(DOWNLOADDB_INFORM_USER);
191                                $empfaenger     = $dldbAdmin->email;
192                                $languages = array(0 => WCF::getLanguage(), WCF::getLanguage()->getLanguageID() => WCF::getLanguage());
193                                require_once(WCF_DIR.'lib/data/mail/Mail.class.php');
194                                require_once(WCF_DIR.'lib/data/user/User.class.php');
195                                // get language
196                                // enable language
197                                $languages[WCF::getLanguage()->getLanguageID()]->setLocale();
198                                $subjectData = array();
199                                $messageData = array(
200                                        'PAGE_TITLE' => PAGE_TITLE,
201                                        '$dldbUserName' => WCF::getUser()->username,
202                                        '$name' => $this->name,
203                                        '$description' => $this->description
204                                );
205                                // Mail an den Admin
206                                $mail = new Mail(       $empfaenger,
207                                                                        $languages[WCF::getLanguage()->getLanguageID()]->get('wcf.dldb.email.edit.subject', $subjectData),
208                                                                        $languages[WCF::getLanguage()->getLanguageID()]->get('wcf.dldb.email.edit.message', $messageData)
209                                );
210                                $mail->send();
211                        }
212                        // reset cache
213                        WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbKat.php');
214                        $this->saved();
215                        // forward to Cat-View page
216                        WCF::getTPL()->assign(array(
217                                'url'           => 'index.php?page=DownloadDBView&katID='.$this->katID.SID_ARG_1ST,
218                                'message'       => WCF::getLanguage()->get('wcf.acp.dldb.edit.success')
219                        ));
220                        WCF::getTPL()->display('redirect');
221                        exit;
222                }
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->katName                  = $data['katName'];
235                                        $this->name                             = $data['name'];
236                                        $this->description              = $data['description'];
237                                        $this->previewFile              = $data['previewFile'];
238                                        if ($this->previewFile) {
239                                                if (@fopen(FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.'thumbnail-'.$this->dataID.'_'.$this->previewFile),'rb') == false) {
240                                                        $this->previewIMG = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.$this->dataID.'_'.$this->previewFile);
241                                                } else {
242                                                        $this->previewIMG       = FileUtil::getRealPath(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR.'thumbnail-'.$this->dataID.'_'.$data['previewFile']);
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->noUpload = 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?>
Note: See TracBrowser for help on using the browser.