<?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');
jimport( 'joomla.application.component.model' );
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_rsevents'.DS.'models'.DS.'events.php');
class rseventsViewRepeat extends JView
{
	function display($tpl = null)
	{
		global $mainframe , $option;

				$cid = JRequest::getVar('cid','0','request');
				$db = & JFactory::getDBO();
				
				$event = rseventsModelEvents::getEvent();
				
				
				JToolBarHelper::title(JText::_('RSE_REPEAT_FOR').' '.$event->EventName,'generic.png');
				JToolBarHelper::save();
				JToolBarHelper::apply();
				JToolBarHelper::cancel();
				JToolBarHelper::custom('main','preview.png','preview_f2.png',JText::_('RSE_RS_PRODUCT'),false);
				
				$repeat = array();
				$repeat[] = JHTML::_('select.option', '0', JText::_( 'RSE_SELECT_TYPE' ) );
				$repeat[] = JHTML::_('select.option', '1', JText::_( 'RSE_REPEAT_DAYS' ) );
				$repeat[] = JHTML::_('select.option', '2', JText::_( 'RSE_REPEAT_WEEKS' ) );
				$repeat[] = JHTML::_('select.option', '3', JText::_( 'RSE_REPEAT_MONTHS' ) );
				$repeat[] = JHTML::_('select.option', '4', JText::_( 'RSE_REPEAT_YEARS' ) );
				
				$lists['repeat'] = JHTML::_('select.genericlist', $repeat, 'EventRepeatType', 'size="1" class="inputbox"', 'value', 'text', $event->EventRepeatType );
				
				$db->setQuery("SELECT EventRepeatAlso FROM #__rsevents_events WHERE IdEvent='".$cid."'");
				
				if($event->IdParent != 0 || $event->IdParent == '' ) $mainframe->redirect('index.php?option=com_rsevents&task=listevents',JText::_('RSE_REPEAT_ERROR1'));
		
				
				$res = $db->loadResult();
				$repeatAlso = array();
				$getSelected = array();
				
				if (!empty($res))
				{
					$dates = explode(',',$db->loadResult());

					foreach($dates as $date)
					{
						$date = date('Y-m-d',$date);
						$repeatAlso[] = JHTML::_('select.option', $date, $date);
						$getSelected[] = $date;
					}
				}
				
				$lists['repeatalso'] = JHTML::_('select.genericlist', $repeatAlso, 'EventRepeatAlso[]', 'size="10" class="inputbox" multiple="multiple"', 'value', 'text', $getSelected );
				
				$this->assignRef('lists',$lists);			
				$this->assignRef('data',$event);
			
		
		parent::display($tpl);
	}
}