public function update($id=null) {
	
		//	make sure user has rights to edit
		self::__checkPermission('downloads_edit');
		
		//	check to make sure ID is set and valid
		if (is_null($id)) {
			$this->__log(__('error encountered updating download').'; '.__('ID not specified'),self::LOG_ERROR);
			Flash::set('error',__('No ID specified!'));
			redirect(get_url('plugin/downloads'));
		}
		if (!$download = Download::findById($id)) {
			$this->__log(__('error encountered updating download').'; '.__('could not find download by ID'),self::LOG_ERROR);
			Flash::set('error',__('Could not find record!'));
			redirect(get_url('plugin/downloads'));
		}
		
		//	retrieve the new values from $_POST
		//$_POST['name'] = $download->name;
		$input = $this->__validate($_POST);
		$input['updated'] = date('Y-m-d H:i:s');
		
		//	check for uploaded file
		if (is_uploaded_file($_FILES['download']['tmp_name'])) {
			
			//	determine the destination directory
			$dstdir = CMS_ROOT."/{$this->settings['download_path']}/";
			
			//	remove the old file
			if (file_exists($dstdir.$download->filename)) if (!@unlink($dstdir.$download->filename)) {
				$this->__log(__('error encountered removing old file'),self::LOG_ERROR);
				Flash::set('error',__('Could not remove old file!'));
				redirect(get_url('plugin/downloads/edit/'.$id));
			}
			
			//	clear the hash in case the user is uploading the same file again
			$download->hash = '';
			$download->save();
			
			//	upload the new file
			if (!$upload = $this->__upload('download',$input['name'])) {
				redirect(get_url('plugin/downloads/edit/'.$id));
			}
			$download->filename = $upload['filename'];
			$download->hash = $upload['hash'];
			$download->save();
		}
		//	no uploaded file, did the name change?
		elseif ($input['name'] != $download->name) {
			if (!$download->filename = $this->__rename($download->filename,$input['name'])) {
				redirect(get_url('plugin/downloads/edit/'.$id));
			}
			$download->save();
		}
		
		//	update the record with the new values
		$download->setFromData($input);
		if (!$download->save()) {
			$this->__log(__('error encountered updating download'),self::LOG_ERROR);
			Flash::set('error',__('Could not update the record in the database.'));
			redirect(get_url('plugin/downloads/edit/'.$id));
		}
		
		//	add the tags
		$this->__storetags($_POST['tags'],$download->id);
		
		$this->__log(__('updated download').' "'.$download->name.'"');
		Flash::set('success',__('Record updated!'));
		redirect(get_url('plugin/downloads/edit/'.$id));
	}//*/
Пример #2
0
function downloadPlayerById($download_id,$text=null) {
	
	//	get download
	if (!$download = Download::findById($download_id)) return "<span class=\"download-broken\" title=\"broken download link\">[".(!empty($text) ? $text : 'file not found')."]</span>";
	
	//	return download link
	return downloadBoxFormat($download,true);
}