<?php
/**
 * @version		$Id: view.html.php 132 2009-06-23 07:25:22Z eddieajau $
 * @copyright	Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
 * @license		GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
 * @link		http://www.theartofjoomla.com
 */

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

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

/**
 * @package		TAOJ.Quanta
 * @subpackage	com_quanta
 */
class QuantaViewRecord extends JView
{
	/**
	 * Display the view
	 *
	 * @access	public
	 */
	function display($tpl = null)
	{
		$state	= $this->get('State');
		$item	= $this->get('Item');

		$form 	= $this->get('Form');

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

		// Correct UTC dates
		$item->latest_time = JHtml::date($item->latest_time, '%Y-%m-%d %H:%M:%S');

		$form->setName('adminForm');
		$form->setAction(JRoute::_('index.php?option=com_quanta'));
		$form->loadObject($item);

		$this->assignRef('state',	$state);
		$this->assignRef('item',	$item);
		$this->assignRef('form',	$form);

		$this->_addToolbar();
		parent::display($tpl);
		JRequest::setVar('hidemainmenu', true);
	}

	/**
	 * Display the toolbar
	 *
	 * @access	private
	 */
	function _addToolbar()
	{
		$user = &JFactory::getUser();
		if (is_object($this->item)) {
			$isCheckedOut	= JTable::isCheckedOut($user->get('id'), $this->item->checked_out);
			$isNew			= ($this->item->id == 0);
		}
		else {
			$isCheckedOut	= false;
			$isNew			= true;
		}

		JToolBarHelper::title(JText::_('Quanta_'.($isCheckedOut ? 'View_Record_Title' : ($isNew ? 'Add_Record_Title' : 'Edit_Record_Title'))), 'logo');
		if (!$isNew) {
			JToolBarHelper::custom('record.save2copy', 'copy.png', 'copy_f2.png', 'Quanta_Toolbar_Save_To_Copy', false);
		}
		if (!$isCheckedOut) {
			JToolBarHelper::custom('record.save2new', 'new.png', 'new_f2.png', 'Quanta_Toolbar_Save_And_New', false);
			JToolBarHelper::save('record.save');
			JToolBarHelper::apply('record.apply');
		}
		JToolBarHelper::cancel('record.cancel');
	}
}