<?php
/**
 * JE GroupBuy package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2011 - 2012 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

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

jimport('joomla.application.component.controller');

class jegroupbuyController extends JControllerLegacy
{

	/**
	 * @var		string	The default view.
	 */
	protected $default_view = 'products';

	/**
	 * Method to display a view.
	 *
	 * @param	boolean			If true, the view output will be cached
	 * @param	array			An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
	 *
	 * @return	JController		This object to support chaining.
	 * @since	1.5
	 */
	public function display($cachable = false, $urlparams = false)
	{
		require_once(JPATH_COMPONENT.DS.'helpers'.DS.'jegroupbuy.php');

		//Load the submenu.
		jegroupbuyHelper::addSubmenu($this->input->get('view', 'products'));

    	// set default view if not set
        $view	= $this->input->get('view', 'products');
        $layout = $this->input->get('layout', 'default');
		$id		= $this->input->getInt('id');

		// Check for edit form.
			if($view == 'product' && $layout == 'edit' && !$this->checkEditId('com_jegroupbuy.edit.product', $id)) {
				// Somehow the person just went to the form - we don't allow that.
					$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
					$this->setMessage($this->getError(), 'error');
					$this->setRedirect(JRoute::_('index.php?option=com_jegroupbuy&view=products', false));
				return false;
			}
 		// call parent behavior
        parent::display();

		return $this;
	}
}
