<?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
*/

defined( '_JEXEC' ) or die( 'Restricted access' ); 
jimport('joomla.application.component.controller');

class rseventsController extends JController
{

	var $_db;
	var $_params;
	function __construct()
	{
		global $mainframe;
		parent::__construct();
		$this->_db=& JFactory::getDBO();
		$this->_params=& JComponentHelper::getParams('com_rsevents');
		
		$this->_db->setQuery("SELECT * FROM `#__rsevents_config`");
		$rseventsConfigDb = $this->_db->loadObjectList();
		$rseventsConfig = array();
		foreach ($rseventsConfigDb as $rowConfig)
		{
		$rseventsConfig[$rowConfig->ConfigName] = $rowConfig->ConfigValue;
		}
		$mainframe->setuserState('rseventsConfig',$rseventsConfig);
		
		
	}
	
	function saveRegistration()
	{
		$rseventsConfigPost = JRequest::getVar('rseventsConfig','post');
		if(!isset($rseventsConfigPost['global.register.code']))$rseventsConfigPost['global.register.code']='';

		if($rseventsConfigPost['global.register.code']=='')
		{
		$msg=JText::_('RSE_REGISTRATION_CODE');
		$this->setRedirect('index.php?option=com_rsevents',$msg);
		return;
		}

		$this->_db->setQuery("UPDATE `#__rsevents_config` SET ConfigValue = '". trim( $rseventsConfigPost['global.register.code'] ). "' WHERE ConfigName = 'global.register.code'");
		$this->_db->query();

		$msg=JText::_('RSE_REGISTRATION_SAVED');
		$this->setRedirect('index.php?option=com_rsevents&task=updatesManage',$msg);
	}
	
	function main()
	{

		JRequest::setVar('view','main');
		JRequest::setVar('layout','default');
		
		parent::display();
	}
// Events
	
	function listevents()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function editevent()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','edit');
		parent::display();
	}
	function eventrepeat()
	{
		JRequest::setVar('view','repeat');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function listcategories()
	{
		JRequest::setVar('view','categories');
		JRequest::setVar('layout','default');
		parent::display();
		
	}
	
	function editcategories()
	{
		JRequest::setVar('view','categories');
		JRequest::setVar('layout','edit');
		parent::display();
		
	}
	
	function listlocations()
	{
		JRequest::setVar('view','locations');
		JRequest::setVar('layout','default');
		parent::display();
		
	}
	
	function editlocation()
	{
		JRequest::setVar('view','locations');
		JRequest::setVar('layout','edit');
		parent::display();
		
	}

	function import()
	{
		JRequest::setVar('view','import');
		JRequest::setVar('layout','default');
		parent::display();
		
	}
	
	function archive()
	{
		JRequest::setVar('view','archive');
		JRequest::setVar('layout','default');
		parent::display();
		
	}

	/*Designs*/
	
	function listdesigns()
	{
		JRequest::setVar('view','designs');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function editdesign()
	{
		JRequest::setVar('view','designs');
		JRequest::setVar('layout','edit');
		parent::display();
	}
	
	/*Settings*/
	
	function editsettings()
	{
		JRequest::setVar('view','settings');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function listgroups()
	{
		JRequest::setVar('view','groups');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function editgroups()
	{
		JRequest::setVar('view','groups');
		JRequest::setVar('layout','edit');
		parent::display();
	}
	
	function editfile()
	{
		JRequest::setVar('view','files');
		JRequest::setVar('layout','default');
		JRequest::setVar('tmpl','component');
		parent::display();
	}
	
	function listsubscriptions()
	{
		JRequest::setVar('view','subscriptions');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function editsubscription()
	{
		JRequest::setVar('view','subscriptions');
		JRequest::setVar('layout','edit');
		parent::display();
	}
	
	function showtransaction()
	{
		JRequest::setVar('view','subscriptions');
		JRequest::setVar('layout','transaction');
		parent::display();
	}
	
	function listtickets()
	{
		JRequest::setVar('view','tickets');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function editticket()
	{
		JRequest::setVar('view','tickets');
		JRequest::setVar('layout','edit');
		parent::display();
	}
	
	function edityoutube()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','youtube');
		parent::display();
	}
	
	function editflash()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','flash');
		parent::display();
	}
	
	function editmp3()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','mp3');
		parent::display();
	}
	
	function editmeebo()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','chat');
		parent::display();
	}
	
	function categorieselement()
	{
		JRequest::setVar('view','categorieselement');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function eventelement()
	{
		JRequest::setVar('view','eventelement');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function locationselement()
	{
		JRequest::setVar('view','locationselement');
		JRequest::setVar('layout','default');
		parent::display();
	}
	
	function update()
	{
		JRequest::setVar('view','main');
		JRequest::setVar('layout','update');
		parent::display();
	}
	
	function editflickr()
	{
		JRequest::setVar('view','events');
		JRequest::setVar('layout','flickr');
		parent::display();
	}

	function map()
	{
		JRequest::setVar('view','settings');
		JRequest::setVar('layout','map');
		parent::display();
	}
	
	function rsform()
	{
		JRequest::setVar('view','events');
		parent::display();
		exit();
	}
	
	function location_filter()
	{
		$db = &JFactory::getDBO();
		$string = JRequest::getVar('string');
		$return = '';
		
		
		$db->setQuery("SELECT IdLocation,LocationName FROM #__rsevents_locations WHERE LocationName LIKE '%".$db->getEscaped($string)."%' ");
		$locations = $db->loadObjectList();
		$return .= '<select id="IdLocation" class="inputbox" size="1" name="IdLocation">'; 
		$return .= '<option value="0">'.JText::_('RSE_EVENT_SELECT_LOCATION').'</option>';
		foreach($locations as $location)
			$return .= '<option value="'.$location->IdLocation.'">'.$location->LocationName.'</option>'; 
		$return .= '</select>';
		
		echo $return;
		exit();
	}

}
?>