| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_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 | |
|---|
| 15 | class 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->previewIMG = DownloadDBDataEditor::createPreview($dataset->dataID, $this->previewArray['tmp_name'], $this->previewArray['name'], $this->previewArray['type'], 'previewIMG'); |
|---|
| 110 | $this->previewFile = $this->previewArray['name']; |
|---|
| 111 | } |
|---|
| 112 | // Bei neuem Upload den alten file lschen 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($dataset->dataID, $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 | // Daten endgltig speichern |
|---|
| 130 | $dataset->updateDataset(array( |
|---|
| 131 | 'katID' => intval($this->katID), |
|---|
| 132 | 'name' => $this->name, |
|---|
| 133 | 'description' => $this->description, |
|---|
| 134 | 'previewIMG' => escapeString($this->previewIMG), |
|---|
| 135 | 'previewFile' => StringUtil::encodeHTML($this->previewFile), |
|---|
| 136 | 'fileName' => StringUtil::encodeHTML($this->fileName), |
|---|
| 137 | 'fileExtension' => StringUtil::encodeHTML($this->fileExtension), |
|---|
| 138 | 'mimeType' => StringUtil::encodeHTML($this->mimeType), |
|---|
| 139 | 'link' => $this->link, |
|---|
| 140 | 'groesse' => intval($this->groesse), |
|---|
| 141 | 'downloads' => intval($this->downloads), |
|---|
| 142 | 'userID' => intval($this->dldbUserID), |
|---|
| 143 | 'datum' => $this->datum, |
|---|
| 144 | 'sortOrder' => intval($this->sortOrder), |
|---|
| 145 | 'thread' => $this->supportThread, |
|---|
| 146 | 'activ' => true |
|---|
| 147 | )); |
|---|
| 148 | } |
|---|
| 149 | // show success message |
|---|
| 150 | WCF::getTPL()->assign('success', true); |
|---|
| 151 | |
|---|
| 152 | // delete category cache |
|---|
| 153 | WCF::getCache()->clear(WCF_DIR.'cache', 'cache.dldbKat.php'); |
|---|
| 154 | |
|---|
| 155 | $this->saved(); |
|---|
| 156 | // forward to list page |
|---|
| 157 | header('Location: index.php?page=DownloadDBDataList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED); |
|---|
| 158 | exit; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | protected function readDaten() { |
|---|
| 162 | WCF::getCache()->addResource('dldbData', |
|---|
| 163 | WCF_DIR.'cache/cache.dldbData.php', |
|---|
| 164 | WCF_DIR.'lib/system/cache/CacheBuilderDLDBData.class.php'); |
|---|
| 165 | $this->dataCache = WCF::getCache()->get('dldbData'); |
|---|
| 166 | // get data |
|---|
| 167 | foreach ($this->dataCache as $ID => $data) { |
|---|
| 168 | if ($data['dataID'] == $this->dataID) { |
|---|
| 169 | $this->katID = $data['katID']; |
|---|
| 170 | $this->name = $data['name']; |
|---|
| 171 | $this->description = StringUtil::decodeHTML($data['description']); |
|---|
| 172 | $this->previewIMG = $data['previewIMG']; |
|---|
| 173 | $this->previewFile = $data['previewFile']; |
|---|
| 174 | $this->fileName = $this->fileNameAlt = $data['fileName']; |
|---|
| 175 | $this->fileExtension = $data['fileExtension']; |
|---|
| 176 | $this->mimeType = $data['mimeType']; |
|---|
| 177 | $this->link = StringUtil::decodeHTML($data['link']); |
|---|
| 178 | $this->groesse = $data['groesse']; |
|---|
| 179 | $this->downloads = $data['downloads']; |
|---|
| 180 | $this->dldbUserID = $data['dldbUserID']; |
|---|
| 181 | $this->dldbUserName = $data['dldbUsername']; |
|---|
| 182 | $this->datum = $data['datum']; |
|---|
| 183 | $this->sortOrder = $data['sortOrder']; |
|---|
| 184 | $this->supportThread = StringUtil::decodeHTML($data['thread']); |
|---|
| 185 | $this->activ = $data['activ']; |
|---|
| 186 | } |
|---|
| 187 | WCF::getCache()->clearResource('dldbData'); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | } |
|---|
| 192 | ?> |
|---|