| 152 | | |
| 153 | | function getFileUrl() |
| 154 | | { |
| 155 | | //TODO: build local url + file generator |
| 156 | | if(!isLocalFile()) |
| 157 | | return $this->files_row['url']; |
| 158 | | else |
| 159 | | return "http://"; |
| 160 | | } |
| 161 | | |
| 162 | | function setURL($url) |
| 163 | | { |
| 164 | | $url = $this->mBd->EscapeString($url); |
| 165 | | $this->mBd->execSqlUpdate("UPDATE files SET url = '$url' WHERE files_id='".$this->getId()."'", false); |
| 166 | | $this->refresh(); |
| 167 | | } |
| 168 | | |
| 169 | | function isLocalFile() |
| 170 | | { |
| 171 | | return !empty($this->files_row['url']); |
| 172 | | } |
| | 169 | |
| | 170 | function getFileUrl() |
| | 171 | { |
| | 172 | if (!$this->isLocalFile()) |
| | 173 | return $this->files_row['url']; |
| | 174 | else |
| | 175 | return BASE_SSL_PATH."file_download.php?file_id=".$this->getId(); |
| | 176 | } |
| | 177 | |
| | 178 | function setURL($url) |
| | 179 | { |
| | 180 | if($url == null) |
| | 181 | $url = "NULL"; |
| | 182 | else |
| | 183 | $url = "'".$this->mBd->EscapeString($url)."'"; |
| | 184 | $this->mBd->execSqlUpdate("UPDATE files SET url = $url WHERE files_id='".$this->getId()."'", false); |
| | 185 | $this->refresh(); |
| | 186 | } |
| | 187 | |
| | 188 | function isLocalFile() |
| | 189 | { |
| | 190 | return is_null($this->files_row['url']); |
| | 191 | } |
| | 198 | |
| | 199 | $html .= "<div class='admin_section_container'>\n"; |
| | 200 | $html .= "<div class='admin_section_title'>"; |
| | 201 | $html .= "<input type='radio' name='file_mode".$this->getId()."' value='by_upload' ". ($this->isLocalFile() ? "CHECKED" : "").">"; |
| | 202 | $html .= _("Upload a new file (Uploading a new one will replace any existing file)")." : </div>\n"; |
| | 203 | $html .= "<div class='admin_section_data'>\n"; |
| | 204 | $html .= '<input type="hidden" name="MAX_FILE_SIZE" value="1073741824" />'; |
| | 205 | $html .= '<input name="file_file_upload'.$this->getId().'" type="file" />'; |
| | 206 | $html .= "</div>\n"; |
| | 207 | $html .= "</div>\n"; |
| | 208 | |
| | 209 | $html .= "<div class='admin_section_container'>\n"; |
| | 210 | $html .= "<div class='admin_section_title'>"; |
| | 211 | $html .= "<input type='radio' name='file_mode".$this->getId()."' value='remote' ". (!$this->isLocalFile() ? "CHECKED" : "").">"; |
| | 212 | $html .= _("Remote file via URL")." : </div>\n"; |
| | 213 | $html .= "<div class='admin_section_data'>\n"; |
| | 214 | if($this->isLocalFile()) |
| | 215 | $html .= "<input name='file_url".$this->getId()."' type='text' size='50'/>"; |
| | 216 | else |
| | 217 | $html .= "<input name='file_url".$this->getId()."' type='text' size='50' value='".$this->getFileUrl()."'/>"; |
| | 218 | $html .= "</div>\n"; |
| | 219 | $html .= "</div>\n"; |
| 180 | | $html .= "<div class='admin_section_container'>\n"; |
| 181 | | $html .= "<div class='admin_section_title'>"; |
| 182 | | $html .= "<input type='radio' name='file_by_upload".$this->getId()."' value='true' ".(!$this->isLocalFile()?"CHECKED":"").">"; |
| 183 | | $html .= _("Upload a new file (This will replace any existing file)")." : </div>\n"; |
| 184 | | $html .= "<div class='admin_section_data'>\n"; |
| 185 | | $html .= '<input type="hidden" name="MAX_FILE_SIZE" value="1073741824" />'; |
| 186 | | $html .= '<input name="file_file_upload'.$this->getId().'" type="file" />'; |
| 187 | | $html .= "</div>\n"; |
| 188 | | $html .= "</div>\n"; |
| | 221 | if (!$this->isLocalFile()) |
| | 222 | { |
| | 223 | $html .= "<div class='admin_section_container'>\n"; |
| | 224 | $html .= "<div class='admin_section_title'>"._("File URL")." : </div>\n"; |
| | 225 | $html .= "<div class='admin_section_data'>\n"; |
| | 226 | $html .= $this->getFileUrl(); |
| | 227 | $html .= "</div>\n"; |
| | 228 | $html .= "</div>\n"; |
| | 229 | } |
| | 230 | |
| | 231 | $html .= "<div class='admin_section_container'>\n"; |
| | 232 | $html .= "<div class='admin_section_title'>"._("Filename to display")." : </div>\n"; |
| | 233 | $html .= "<div class='admin_section_data'>\n"; |
| | 234 | $html .= '<input type="text" name="file_file_name'.$this->getId().'" value="'.$this->getFilename().'" />'; |
| | 235 | $html .= "</div>\n"; |
| | 236 | $html .= "</div>\n"; |
| | 237 | |
| | 238 | if ($this->isLocalFile()) |
| | 239 | { |
| | 240 | $html .= "<div class='admin_section_container'>\n"; |
| | 241 | $html .= "<div class='admin_section_title'>"._("MIME type")." : </div>\n"; |
| | 242 | $html .= "<div class='admin_section_data'>\n"; |
| | 243 | $html .= '<input type="text" name="file_mime_type'.$this->getId().'" value="'.$this->getMimeType().'" />'; |
| | 244 | $html .= "</div>\n"; |
| | 245 | $html .= "</div>\n"; |
| | 246 | |
| | 247 | $html .= "<div class='admin_section_container'>\n"; |
| | 248 | $html .= "<div class='admin_section_title'>"._("Locally stored file size")." : </div>\n"; |
| | 249 | $html .= "<div class='admin_section_data'>\n"; |
| | 250 | $html .= $this->getFileSize(self :: UNIT_KILOBYTES)." "._("KB"); |
| | 251 | $html .= "</div>\n"; |
| | 252 | $html .= "</div>\n"; |
| | 253 | } |
| | 254 | else |
| | 255 | { |
| | 256 | $html .= "<div class='admin_section_container'>\n"; |
| | 257 | $html .= "<div class='admin_section_title'>"._("Remote file size")." : </div>\n"; |
| | 258 | $html .= "<div class='admin_section_data'>\n"; |
| | 259 | // The hidden field contains old value to determine if we have to update ( this prevents unwanted successive floating point evaluation ) |
| | 260 | $html .= '<input type="hidden" name="file_old_remote_size'.$this->getId().'" value="'.$this->getFileSize().'" />'; |
| | 261 | $html .= '<input type="text" name="file_remote_size'.$this->getId().'" value="'.$this->getFileSize().'" />'; |
| | 262 | $html .= "</div>\n"; |
| | 263 | $html .= "</div>\n"; |
| | 264 | } |
| 199 | | $html .= "<div class='admin_section_container'>\n"; |
| 200 | | $html .= "<div class='admin_section_title'>"._("Filename")." : </div>\n"; |
| 201 | | $html .= "<div class='admin_section_data'>\n"; |
| 202 | | $html .= '<input type="text" name="file_file_name'.$this->getId().'" value="'.$this->getFilename().'" />'; |
| 203 | | $html .= "</div>\n"; |
| 204 | | $html .= "</div>\n"; |
| 205 | | |
| 206 | | $html .= "<div class='admin_section_container'>\n"; |
| 207 | | $html .= "<div class='admin_section_title'>"._("MIME type")." : </div>\n"; |
| 208 | | $html .= "<div class='admin_section_data'>\n"; |
| 209 | | $html .= '<input type="text" name="file_mime_type'.$this->getId().'" value="'.$this->getMimeType().'" />'; |
| 210 | | $html .= "</div>\n"; |
| 211 | | $html .= "</div>\n"; |
| 212 | | |
| 213 | | if($this->isLocalFile()) |
| | 272 | $html .= $subclass_admin_interface; |
| | 273 | return parent :: getAdminUI($html); |
| | 274 | } |
| | 275 | |
| | 276 | function processAdminUI() |
| | 277 | { |
| | 278 | parent :: processAdminUI(); |
| | 279 | // If no file was uploaded, update filename and mime type |
| | 280 | if(!empty($_REQUEST["file_mode".$this->getId()])) |
| 215 | | $html .= "<div class='admin_section_container'>\n"; |
| 216 | | $html .= "<div class='admin_section_title'>"._("File size")." : </div>\n"; |
| 217 | | $html .= "<div class='admin_section_data'>\n"; |
| 218 | | $html .= $this->getFileSize(self::UNIT_KILOBYTES)." "._("KB"); |
| 219 | | $html .= "</div>\n"; |
| 220 | | $html .= "</div>\n"; |
| | 282 | $file_mode = $_REQUEST["file_mode".$this->getId()]; |
| | 283 | if ($file_mode == "by_upload") |
| | 284 | { |
| | 285 | $this->setBinaryDataFromPostVar("file_file_upload".$this->getId()); |
| | 286 | $this->setURL(null); |
| | 287 | // Reset the remote file size ( not used ) |
| | 288 | $this->setRemoteFileSize(0); |
| | 289 | } |
| | 290 | else |
| | 291 | { |
| | 292 | if ($file_mode == "remote") |
| | 293 | { |
| | 294 | $this->setURL($_REQUEST["file_url".$this->getId()]); |
| | 295 | $this->setBinaryData(null); |
| | 296 | // When switching from local to remote, this field does not exist yet |
| | 297 | if(!empty($_REQUEST["file_old_remote_size".$this->getId()])) |
| | 298 | { |
| | 299 | if($_REQUEST["file_remote_size".$this->getId()] != $_REQUEST["file_old_remote_size".$this->getId()]) |
| | 300 | $this->setRemoteFileSize($_REQUEST["file_remote_size".$this->getId()]); |
| | 301 | } |
| | 302 | else |
| | 303 | $this->setRemoteFileSize(0); |
| | 304 | } |
| | 305 | $this->setFilename($_REQUEST["file_file_name".$this->getId()]); |
| | 306 | } |
| 222 | | else |
| 223 | | { |
| 224 | | //TODO: implement user defined size |
| 225 | | } |
| 226 | | |
| 227 | | return parent :: getAdminUI($html); |
| 228 | | } |
| 229 | | |
| 230 | | function processAdminUI() |
| 231 | | { |
| 232 | | parent :: processAdminUI(); |
| 233 | | |
| 234 | | // If no file was uploaded, update filename and mime type |
| 235 | | if(!empty($_REQUEST["file_by_upload".$this->getId()])) |
| 236 | | { |
| 237 | | $this->setBinaryDataFromPostVar("file_file_upload".$this->getId()); |
| 238 | | } |
| 239 | | else |
| 240 | | if(!empty($_REQUEST["file_url".$this->getId()])) |
| 241 | | { |
| 242 | | $this->setURL($_REQUEST["file_url".$this->getId()]); |
| 243 | | } |
| 244 | | $this->setMimeType($_REQUEST["file_mime_type".$this->getId()]); |
| 245 | | $this->setFilename($_REQUEST["file_file_name".$this->getId()]); |
| 246 | | } |
| 247 | | |
| 248 | | /**Affiche l'interface usager de l'objet |
| 249 | | */ |
| | 308 | } |