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

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.view' );

class jegroupbuyVieworders extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $option;

		// Get data from the model
		$items 			= $this->get('Items');
		$pagination 	= $this->get('Pagination');
		$this->state	= $this->get('State');
		$this->user		= JFactory::getUser();

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}

		// Assign data to the view
		$this->items = $items;
		$this->pagination = $pagination;
			// Preprocess the list of items to find ordering divisions.
			// TODO: Complete the ordering stuff with nested sets
				foreach ($this->items as &$item)
				{
					$item->order_up = true;
					$item->order_dn = true;
				}
		// Set the toolbar
		$this->addToolBar();
		parent::display($tpl);


		// Set the document
		$this->setDocument();
	}
	/**
	 * Setting the toolbar
	 */
	protected function addToolBar()
	{
		$canDo = jegroupbuyHelper::getActions();
		JToolBarHelper::title(JText::_('JE_COMPONENT_TITLE')." - "."<small><small>".JText::_('JE_SHOPS')."</small></small>", 'jegroupbuy.png');
		if ($canDo->get('core.create'))
		{
			JToolBarHelper::addNew('order.add', 'JTOOLBAR_NEW');
		}
		if ($canDo->get('core.edit'))
		{
			JToolBarHelper::editList('order.edit', 'JTOOLBAR_EDIT');
		}
		if ($canDo->get('core.delete'))
		{
			JToolBarHelper::deleteList("COM_JEGROUPBUY_STORES_DEL_MSG",'orders.delete', 'JTOOLBAR_DELETE');
		}

		if ($canDo->get('core.edit.state')) {
			if ($this->state->get('filter.state') != 2){
				JToolBarHelper::divider();
				JToolBarHelper::custom('orders.status', 'publish.png', 'publish_f2.png','JTOOLBAR_PUBLISH', true);
				JToolBarHelper::custom('orders.unstatus', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
			}
		}

		if ($canDo->get('core.admin')) {
			JToolBarHelper::preferences('com_jegroupbuy');
		}

	}
	/**
	 * Method to set up the document properties
	 *
	 * @return void
	 */
	protected function setDocument()
	{
		$document = JFactory::getDocument();
		$document->setTitle(JText::_('JE_COMPONENT_TITLE'));
	}
}

