<?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.view');

class rseventsViewSettings extends JView
{
	function display($tpl = null)
	{
		global $mainframe;
		$task=JRequest::getVar('task','','request');
		$document 	= & JFactory::getDocument();
		switch($task)
		{
			
			case 'map':
				$ConfigList=$this->get('data');
				$this->assignRef('data',$ConfigList);
			break;
			
			case 'editsettings':
			{
				$db =& JFactory::getDBO();
				//Build submenu
				$contents = '';
				ob_start();
					require_once(dirname(__FILE__).DS.'tmpl'.DS.'navigation.php');
				$contents = ob_get_contents();
				ob_end_clean();
				
				$document->setBuffer($contents, 'modules', 'submenu');
				
				
				JToolBarHelper::title(JText::_('RSE_SETTINGS'),'generic.png');
				JToolBarHelper::apply();
				JToolBarHelper::save();
				JToolBarHelper::cancel();
				JToolBarHelper::custom('main','preview.png','preview_f2.png',JText::_('RSE_RS_PRODUCT'),false);
				
				$ConfigList=$this->get('data');
				
				$jcomment 	= file_exists(JPATH_SITE.DS.'components'.DS.'com_jcomments'.DS.'jcomments.php');
				$jomcomment= file_exists(JPATH_SITE.DS.'plugins'.DS.'content'.DS.'jom_comment_bot.php');
				
				$commentsystem = array();
				$commentsystem[] = JHTML::_('select.option', '0', JText::_( 'RSE_NO_COMMENTS' ) );
					
				if ( $jcomment )
				{
					$commentsystem[] = JHTML::_('select.option', '1', JText::_( 'JComments' ) );
				}
				if ( $jomcomment )
				{
					$commentsystem[] = JHTML::_('select.option', '2', JText::_( 'Jom Comments' ) );
				}
				
				$commentoptions = JHTML::_('select.genericlist', $commentsystem, 'rseventsConfig[events.commenting]', 'size="1" class="inputbox"', 'value', 'text', $ConfigList['events.commenting'] );
				
				$this->assignRef('commentoptions',$commentoptions);
				
				$cb = file_exists(JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'comprofiler.php');
				$jm = file_exists(JPATH_SITE.DS.'components'.DS.'com_joomunity'.DS.'joomunity.php');
				$js = file_exists(JPATH_SITE.DS.'components'.DS.'com_community'.DS.'community.php');
				
				$redirection =array();
				$redirection[] = JHTML::_('select.option', '0', JText::_( 'RSE_JOOMLA_DEFAULT' ) );
				
				$profile = array();
				$profile[] = JHTML::_('select.option', '0', JText::_( 'RSE_NO_PROFILE' ) );
					
				if ( $cb )
				{
					$profile[] = JHTML::_('select.option', '1', JText::_( 'Comunity Builder' ) );
					$redirection[] = JHTML::_('select.option', '1', JText::_( 'RSE_CB_LINK' ) );
				}
				if ( $jm )
				{
					$profile[] = JHTML::_('select.option', '2', JText::_( 'Joomunity' ) );
				}
				if ( $js )
				{
					$profile[] = JHTML::_('select.option', '3', JText::_( 'JoomSocial' ) );
				}
				
				$lists['profile'] = JHTML::_('select.genericlist', $profile, 'rseventsConfig[subscribers.link]', 'size="1" class="inputbox"', 'value', 'text', $ConfigList['subscribers.link'] );
				$lists['redirection'] = JHTML::_('select.genericlist', $redirection, 'rseventsConfig[cb.redirect]', 'size="1" class="inputbox"', 'value', 'text', $ConfigList['cb.redirect'] );
				
				
				
				$lists['flash'] = JHTML::_('select.booleanlist', 'rseventsConfig[events.extras.flash]' , '' , $ConfigList['events.extras.flash']);
				$lists['youtube'] = JHTML::_('select.booleanlist', 'rseventsConfig[events.extras.youtube]' , '' , $ConfigList['events.extras.youtube']);
				$lists['mp3'] = JHTML::_('select.booleanlist', 'rseventsConfig[events.extras.mp3]' , '' , $ConfigList['events.extras.mp3']);
				$lists['meebo'] = JHTML::_('select.booleanlist', 'rseventsConfig[events.extras.meebo]' , '' , $ConfigList['events.extras.meebo']);
				$lists['gMaps'] = JHTML::_('select.booleanlist', 'rseventsConfig[locations.gmaps]' , '' , $ConfigList['locations.gmaps']);
				$lists['flickr'] = JHTML::_('select.booleanlist', 'rseventsConfig[events.extras.flickr]' , '' , $ConfigList['events.extras.flickr']);
				
				$payment_methods[] = JHTML::_('select.option', 'none', JText::_( 'RSE_NO_PAYMENT' ) );
				if(defined('RSEVENTS_PAYPAL'))$payment_methods[] = JHTML::_('select.option', 'paypal', JText::_( 'RSE_PAYMENT_PAYPAL' ) );
				if(defined('RSEVENTS_WIRE'))$payment_methods[] = JHTML::_('select.option', 'wire', JText::_( 'RSE_PAYMENT_WIRED' ) );
				if(defined('RSEVENTS_2CO'))$payment_methods[] = JHTML::_('select.option', '2co', JText::_( 'RSE_2CO_METHOD' ) );
				
				$lists['payment'] = JHTML::_('select.genericlist', $payment_methods, 'rseventsConfig[payment.default]', 'size="1" class="inputbox"', 'value', 'text', $ConfigList['payment.default'] );
				
				
				$maps = array();
				
				$maps[] = JHTML::_('select.option', 'G_NORMAL_MAP', JText::_( 'RSE_MAP_NORMAL' ) );
				$maps[] = JHTML::_('select.option', 'G_HYBRID_MAP', JText::_( 'RSE_MAP_HYBRID' ) );
				$maps[] = JHTML::_('select.option', 'G_SATELLITE_MAP', JText::_( 'RSE_MAP_SATELLITE' ) );
				
				$lists['maps'] = JHTML::_('select.genericlist', $maps, 'rseventsConfig[google.map]', 'size="1" class="inputbox"', 'value', 'text', $ConfigList['google.map'] );
				
				$layouts = array();
				
				$layouts[] = JHTML::_('select.option', '0', JText::_( 'RSE_SELECT_LAYOUT' ) );
				$layouts[] = JHTML::_('select.option', '1', JText::_( 'RSE_DEFAULT_LAYOUT' ) );
				$layouts[] = JHTML::_('select.option', '2', JText::_( 'RSE_TABLE_LAYOUT' ) );
				
				$lists['layout'] = JHTML::_('select.genericlist', $layouts, 'rseventsConfig[events.layout]', 'onchange="changeLayout(this.value);" size="1" class="inputbox"', 'value', 'text', $ConfigList['events.layout'] );
				
				//do we have payment on this event?
				$db->setQuery("SELECT SUM(TicketPrice) as Price, COUNT(*) as Cnt FROM `#__rsevents_tickets`");
				$ticketProperties = $db->loadObject();
			
				$pieces = array(16=>16,17=>17,18=>18,19=>19,20=>20,26=>26);
				if(!$ticketProperties->Price) 
				{
					unset($pieces[20]);
					unset($pieces[26]);
					if($ticketProperties->Cnt == 1) unset($pieces[19]);
				}
						
				$db->setQuery("SELECT DISTINCT f.FormId ,f.FormName FROM #__rsform_forms f WHERE f.Published = 1 ORDER BY FormId DESC");
				$forms = $db->loadObjectList();
				
				$flist[]         = JHTML::_('select.option',  '0', JText::_( 'RSE_DEFAULT_FORM' ), 'FormId', 'FormName' );
				if(!empty($forms))
					foreach($forms as $i=>$form)
					{
						//Check what items does it have
						$db->setQuery("SELECT COUNT(*) Cnt FROM #__rsform_components WHERE FormId = '".$form->FormId."' AND Published=1 AND ComponentTypeId IN ('".implode("','",$pieces)."')");
						
						if(count($pieces)!=$db->loadResult()) 
						{
							$forms[$i]->disable = true;
							$forms[$i]->FormName .= ' ('.JText::_('RSE_ADD_RSEVENTS_COMPONENTS').')';
						}
						
					}
					
				if(!empty($forms))
				$flist = array_merge($flist , $forms);
				
				$lists['forms']      = JHTML::_('select.genericlist', $flist, 'rseventsConfig[event.registration.form]', 'class="inputbox" size="1"','FormId', 'FormName', $ConfigList['event.registration.form'] );
				
				
				$this->assignRef('lists',$lists);
				$this->assignRef('data',$ConfigList);

			} break;
			
		}
		
		
		parent::display($tpl);
	}
}