<?php
/**
 * @version		3.0.0
 * @package		JomLand TicketCenter
 * @copyright	Copyright (C) 2010 JomLand.com. All rights reserved.
 * @link 		www.jomland.com
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

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

jimport( 'joomla.application.component.view' );
jimport( 'joomla.html.html.list');

class JLTicketCenterViewPerformer extends JViewLegacy
{
	function display($tpl = null)
	{
		$mainframe = JFactory::getApplication();

		$task =  JRequest::getVar('task');

		if ($task=='add' ||$task=='edit' ){
			$this->edit($tpl);
			return;
		}

		JToolBarHelper::title(JText::_( 'Performers - JomLand TicketCenter' ), 'generic.png' );

		JLTicketCenterController::displayToolBar();

		$context			= 'com_jlticketcenter.performer.list.';
		$filter_order		= $mainframe->getUserStateFromRequest( $context.'filter_order',	'filter_order',	'p.title',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $context.'filter_order_Dir','filter_order_Dir','','word' );
		$filter_category	= $mainframe->getUserStateFromRequest( $context.'category',	'filter_category',	'p.cat_id',	'Int');
		$filter_state		= $mainframe->getUserStateFromRequest( $context.'filter_state',	'filter_state',	'',	'word');
		$search				= $mainframe->getUserStateFromRequest( $context.'search','search',	'',	'string');
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);


		$filter['category']	= $filter_category;
		$filter['state']	= $filter_state;
		$filter['search']	= $search;

		JRequest::setVar( 'filter', $filter);

		// Get data from the model
		$items		= $this->get('Data');
		$pagination = $this->get('Pagination');

		$lists['state']	= JHTML::_('grid.state', $filter_state);
		$lists['search']	= $search;

		// build list of categories
		$javascript		= 'onchange="document.adminForm.submit();"';
		//$lists['catid'] = JHTML::_('list.category','filter_category', 'com_jlticketcenter', (int) $filter_category, $javascript );


		/* Call the state object */
		$state = $this->get('state');
		$lists['order_Dir'] = $state->get('filter_order_Dir');
		$lists['order'] 	= $state->get('filter_order' );

		// push data into the template
		$this->assignRef('items',$items);
		$this->assignRef('lists',$lists);
		$this->assignRef('pagination', $pagination);

		parent::display($tpl);

		JLTicketCenterController::renderinfo();
	}

	function edit($tpl = null){

		$user	= JFactory::getUser();

		$task = JRequest::getVar( 'task', '', 'method', 'string');

		JToolBarHelper::title( $task == 'add' ? JText::_( 'Performer' ) . ': <small><small>[ '. JText::_( 'New' ) .' ]</small></small>' : JText::_( 'Performer' ) . ': <small><small>[ '. JText::_( 'Edit' ) .' ]</small></small>', 'generic.png' );

		JToolBarHelper::apply('apply');
		JToolBarHelper::save('save');
		JToolBarHelper::cancel('cancel');


		$row = JTable::getInstance('performer', 'Table');
		if ($task == 'edit') {
			$cid	= JRequest::getVar( 'cid', array(), 'get', 'array' );
				
			if (!$cid){
				$cid	= JRequest::getVar( 'cid', array(), 'post', 'array' );
			}
				
			JArrayHelper::toInteger($cid);
			$cids = implode(',',$cid);

			$row->load( $cid[0] );
		}


		if (!empty($cid[0])){
			$row->checkout($user->get('id') );
		} else {
			$row->load(0);
			$row->published =1;
		}


		$published =  JHTML::_('select.genericlist', array(0=>JText::_('JNO'),1=>JText::_('JYES')), 'published', null, $optKey = 'value', $optText = 'text',$row->published);
        $category  =  JHTML::_('select.genericlist', JHtmlCategory::categories('com_jlticketcenter'),  'cat_id', null, $optKey = 'value', $optText = 'text',(int)$row->cat_id);
		//$category  = JHTML::_('list.category',  'cat_id', 'com_jlticketcenter', (int)$row->cat_id);

		$this->assignRef('published',$published);
		$this->assignRef('category',$category);
		$this->assignRef('performer',$row);


		parent::display($tpl);

		JLTicketCenterController::renderinfo();
	} //EOF edit
}//EOC