<?php
/**
* @version 1.0.0
* @package RSEvents! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

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

class rseventsControllerLocations extends rseventsController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();
	}

	/**
	 * save a record
	 * @return void
	 */
	function save()
	{
		//get variables
		
		$db = & JFactory::getDBO();
		$model = $this->getModel('locations');
		$post=JRequest::get('post',JREQUEST_ALLOWHTML);
		$user =& JFactory::getUser();
		$gid = $user->gid;
		
		//get the itemId
		$Itemid = intval(JRequest::getVar('Itemid','','request'));
		$itemId = ($Itemid == '') ? '' : '&Itemid='.$Itemid;
		
		//verify if the location requires moderation
		
		$db->setQuery("SELECT gp.PermissionValue FROM #__rsevents_groups g LEFT JOIN #__rsevents_groups_acl ga ON g.IdGroup = ga.IdGroup "
					."LEFT JOIN #__rsevents_group_permissions gp ON g.IdGroup = gp.IdGroup WHERE ga.GroupAcl = '".$gid."' AND gp.PermissionName = 'enableLocationModeration'");
		$res = $db->loadResult();
		
		
		$row= & JTable::getInstance('Rsevents_Locations','Table');
		
		if($res == '0' || $user->usertype == "Super Administrator") $row->published = '1';
		else $row->published = '0';
		
		//rseventsHelper::RSstripjavaVar
		
		if(!$row->bind($post)) {
			return JError::raiseWarning(500, $row->getError());
		}
		if ($row->store()) {
			$msg = JText::_( 'RSE_LOCATION_SAVE' );
		} else {
			JError::raiseWarning(500, $row->getError());

			$msg = JText::_( 'RSE_LOCATION_SAVE_ERROR' );
		}
		$link = html_entity_decode(JRoute::_('index.php?option=com_rsevents&view=locations'.$itemId));
		$this->setRedirect($link, $msg);
	}
	

	
}