Location: PHPKode > projects > injooosm > components/com_injooosm/controllers/files.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: files.php 2010-02-09 13:08:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );

class injooosmControllerFiles extends injooosmController {
	
 function __construct()
 {
		 parent::__construct();
 }

	function save() {
		jimport('joomla.filesystem.file');
		
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		$file =& JRequest::getVar('file', null, 'files', 'array');
		$images =& $_FILES['images'];
		$model = $this->getModel('files');

		$ext = JFile::getExt($file['name']);
		if($ext == 'kml' || $ext == 'gpx' || $ext == 'tcx') {
			if(!$model->saveFile()) {
				echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
			}
			$this->setRedirect( JRoute::_('index.php?option=com_injooosm'), false );

		} else {
			echo "<script> alert('".JText::_('OSM_FILE_ERROR')."'); window.history.go(-1); </script>\n";
			exit;
		}
	}

	function vote() {

		$id =& JRequest::getInt('id');
		$rate =& JRequest::getInt('rate');
		$model = $this->getModel('files');
		$model->vote($id, $rate);

		$msg = JText::_('OSM_VOTED');
		$this->setRedirect( JRoute::_('index.php?option=com_injooosm&view=files&layout=file&id='.$id, false ));
	}

	function delete() {
		$user		=& JFactory::getUser();

		if(!$user->get('id')):
			$this->setRedirect( JRoute::_('index.php?option=com_injooosm'), false );
		endif;

		$id =& JRequest::getInt('id');
		$model = $this->getModel('files');

		if(!$model->deleteFile($id)) {
			echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
		} else {
			$this->setRedirect( JRoute::_('index.php?option=com_injooosm&view=files&layout=user'), false);
		}
	}

	function update() {
		jimport('joomla.filesystem.file');
		$user		=& JFactory::getUser();

		if(!$user->get('id')):
			$this->setRedirect( JRoute::_('index.php?option=com_injooosm'), false );
		endif;

		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		$id =& JRequest::getInt('id');
		$model = $this->getModel('files');

			if(!$model->updateFile($id)) {
				echo "<script> alert('Error'); window.history.go(-1); </script>\n";
			}else
			$this->setRedirect( JRoute::_('index.php?option=com_injooosm'), false );

	}

	function addcomment() {

		$model = $this->getModel('files');
		$model->addcomment();
	}

	function savecomment() {
		global $mainframe;
		
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		$cfg = injooosmHelper::getConfig();
		$id = JRequest::getInt('id');
		
		if($cfg->captcha == 1) {
			$return = false;
			$word = JRequest::getVar('word', false, '', 'CMD');
			$mainframe->triggerEvent('onCaptcha_confirm', array($word, &$return));
			 if (!$return) {
					echo "<script> alert('".JText::_('OSM_CAPTCHA_WRONG')."'); window.history.go(-1); </script>\n";
			 } else {
					$model = $this->getModel('files');
					if(!$model->savecomment($id, $cfg)) {
						echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
					}

					$msg = JText::_('OSM_COMMENT_SAVED');
					$this->setRedirect( JRoute::_('index.php?option=com_injooosm&view=files&layout=file&id='.$id), $msg );
			 }
		} else {
			 $model = $this->getModel('files');
				if(!$model->savecomment($id, $cfg)) {
					echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
				}

				$msg = JText::_('OSM_COMMENT_SAVED');
				$this->setRedirect( JRoute::_('index.php?option=com_injooosm&view=files&layout=file&id='.$id), $msg );
		}

	}

}
Return current item: injooosm