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

Revision 415, 7.4 kB (checked in by Tatzelwurm, 5 years ago)

Downloads, Verarbeitung von relativen Links, Datei Add und Edit verbessert, Vorschaubilder änderbar

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 Hrspiel
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 $fileNameAlt ='';
26        public $dldbUserName;
27       
28        /**
29         * @see Page::readParameters()
30         */
31        public function readParameters() {
32                parent::readParameters();
33                // get data id
34                if(isset($_REQUEST['dataID']))  $this->dataID   = intval($_REQUEST['dataID']);
35        }
36
37        /**
38         * @see Form::readFormParameters()
39         */
40        public function readFormParameters() {
41                parent::readFormParameters();
42                               
43                if (isset($_POST['UserIDAkt']))         $this->userIDAkt        = intval($_POST['UserIDAkt']);
44                if (isset($_POST['datumAkt']))          $this->datumAkt         = intval($_POST['datumAkt']);
45                if (isset($_POST['downloadsAkt']))      $this->downloadsAkt     = intval($_POST['downloadsAkt']);
46                if (isset($_POST['fileName']))          $this->fileName         = escapeString($_POST['fileName']);
47                if (isset($_POST['fileNameAlt']))       $this->fileNameAlt      = escapeString($_POST['fileNameAlt']);
48                if (isset($_POST['fileExtension'])) $this->fileExtension = escapeString($_POST['fileExtension']);
49                if (isset($_POST['mimeType']))          $this->mimeType         = escapeString($_POST['mimeType']);
50        }
51       
52        /**
53         * @see Page::readData()
54         */
55        public function readData() {
56                parent::readData();
57                // Daten einlesen
58                if (!count($_POST)) {
59                        $this->readDaten();
60                }
61        }
62
63        /**
64         * @see Page::assignVariables()
65         */
66        public function assignVariables() {
67                parent::assignVariables();
68
69                WCF::getTPL()->assign(array(
70                        'dataID'                => $this->dataID,
71                        'action'                => 'edit',
72                        'fileNameAlt'   => $this->fileNameAlt,
73                        'downloadsAkt'  => $this->downloadsAkt,
74                        'datumAkt'              => $this->datumAkt,
75                        'UserIDAkt'     => $this->userIDAkt,
76                        'dldbUserName'  => $this->dldbUserName,
77                        ));
78        }
79
80        /**
81         * @see Form::validate()
82         */
83        public function validate() {
84                parent::validate();
85               
86                $this->valid = true;
87        }
88               
89        /**
90         * Updates the data of an existing File/Link.
91         */
92        public function save() {
93                if ($this->valid && $this->dataID) {
94                        if ($this->downloadsAkt)        $this->downloads = 0;
95                        if ($this->userIDAkt)           $this->dldbUserID = WCF::getUser()->userID;
96                        if ($this->datumAkt)            $this->datum = TIME_NOW;
97                        $dataset = new DownloadDBDataEditor($this->dataID);
98                        // Bei neuem Prewiew Upload den alten file löschen und den neuen anlegen
99                        if ($this->previewArray && $this->previewArray['error'] != 4) {
100                                // auf Fehler beim Upload prÃŒfen
101                                if ($this->previewArray['error'] != 0) {
102                                        throw new UserInputException('previewIMG', 'uploadFailed');
103                                }
104                                if ($this->previewFile != $this->previewArray['name']) {
105                                        // alten File löschen wenn neuer angegeben wurde
106                                        $dataset->deletePreview($this->previewFile);
107                                }
108                                // neuen File anlegen
109                                $this->previewFile = $this->previewArray['name'];
110                                $this->previewIMG = DownloadDBDataEditor::createPreview($this->previewArray['tmp_name'],        $this->previewArray['name'], $this->previewArray['type'], 'previewIMG');
111                        }
112                        // Bei neuem Upload den alten file löschen und den neuen anlegen
113                        if ($this->upload && $this->upload['error'] != 4) {
114                                // auf Fehler beim Upload prfen
115                                if ($this->upload['error'] != 0) {
116                                        throw new UserInputException('upload', 'uploadFailed');
117                                }
118                                // alten File löschen und neuen anlegen
119                                DownloadDBDataEditor::updateFile($this->fileNameAlt, $this->upload['tmp_name'], $this->upload['name'], $this->upload['type'], 'upload');
120                                //Variablen anpassen
121                                $this->fileName = $this->upload['name'];
122                                $this->mimeType = $this->upload['type'];
123                                $this->groesse  = $this->upload['size'];
124                                if (StringUtil::indexOf($this->fileName, '.') !== false) {
125                                        $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
126                                }
127                                $this->link = FileUtil::addTrailingSlash(PAGE_URL).FileUtil::getRealPath('wcf/'.RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR.intval($dataset->dataID).'_'.StringUtil::encodeHTML($this->fileName));
128                        }
129                        if (!$this->upload && (FileUtil::isURL($this->link) == false)) {
130                                        if (StringUtil::indexOf($this->link, '/') !== false) {
131                                                $this->fileName = StringUtil::substring($this->link, StringUtil::lastIndexOf($this->link, '/') + 1);
132                                        }
133                                        if (StringUtil::indexOf($this->fileName, '.') !== false) {
134                                                $this->fileExtension = StringUtil::toLowerCase(StringUtil::substring($this->fileName, StringUtil::lastIndexOf($this->fileName, '.') + 1));
135                                        }
136                                        $this->groesse = filesize($this->link);
137                               
138                        }
139                        // Daten endgltig speichern
140                        $dataset->updateDataset(array(
141                                                        'katID'                 => intval($this->katID),
142                                                        'name'                  => $this->name,
143                                                        'description'   => $this->description,
144                                                        'previewIMG'    => escapeString($this->previewIMG),
145                                                        'previewFile'   => StringUtil::encodeHTML($this->previewFile),
146                                                        'fileName'              => StringUtil::encodeHTML($this->fileName),
147                                                        'fileExtension' => StringUtil::encodeHTML($this->fileExtension),
148                                                        'mimeType'              => StringUtil::encodeHTML($this->mimeType),
149                                                        'link'                  => $this->link,
150                                                        'groesse'               => intval($this->groesse),
151                                                        'downloads'             => intval($this->downloads),
152                                                        'userID'                => intval($this->dldbUserID),
153                                                        'datum'                 => $this->datum,
154                                                        'sortOrder'             => intval($this->sortOrder),
155                                                        'thread'                => $this->supportThread,
156                                                        'activ'                 => true
157                                                ));
158                }
159                // show success message
160                WCF::getTPL()->assign('success', true);
161               
162                // delete category cache
163                WCF::getCache()->clear(WCF_DIR.'cache', 'cache.dldbKat.php');
164
165                $this->saved();
166                // forward to list page
167                header('Location: index.php?page=DownloadDBDataList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
168                exit;
169        }
170
171        protected function readDaten() {
172                WCF::getCache()->addResource('dldbData',
173                                WCF_DIR.'cache/cache.dldbData.php',
174                                WCF_DIR.'lib/system/cache/CacheBuilderDLDBData.class.php');
175                $this->dataCache = WCF::getCache()->get('dldbData');
176                // get data
177                foreach ($this->dataCache as $ID => $data) {
178                        if ($data['dataID'] == $this->dataID) {
179                                $this->katID                    = $data['katID'];
180                                $this->name                             = $data['name'];
181                                $this->description              = StringUtil::decodeHTML($data['description']);
182                                $this->previewIMG               = $data['previewIMG'];
183                                $this->previewFile              = $data['previewFile'];
184                                $this->fileName                 = $this->fileNameAlt = $data['fileName'];
185                                $this->fileExtension    = $data['fileExtension'];
186                                $this->mimeType                 = $data['mimeType'];
187                                $this->link                             = StringUtil::decodeHTML($data['link']);
188                                $this->groesse                  = $data['groesse'];
189                                $this->downloads                = $data['downloads'];
190                                $this->dldbUserID               = $data['dldbUserID'];
191                                $this->dldbUserName             = $data['dldbUsername'];
192                                $this->datum                    = $data['datum'];
193                                $this->sortOrder                = $data['sortOrder'];
194                                $this->supportThread    = StringUtil::decodeHTML($data['thread']);
195                                $this->activ                    = $data['activ'];
196                        }
197                WCF::getCache()->clearResource('dldbData');
198                }
199        }
200
201}
202?>
Note: See TracBrowser for help on using the browser.