<?php
/**
 * @version		$Id: setup.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.controller');

/**
 * The Setup Controller
 *
 * @package		TAOJ.Quanta
 * @subpackage	com_quanta
 */
class QuantaControllerSetup extends JController
{
	/**
	 * Method to manually install the component.
	 *
	 * @return	void
	 */
	public function install()
	{
		// Get the setup model.
		$model = &$this->getModel('Setup');

		// Attempt to run the manual install routine.
		if (!$model->install()) {
			$this->setMessage(JText::sprintf('TAOJ_Setup_Install_failed', $model->getError()), 'notice');
		}
		else {
			$this->setMessage(JText::_('TAOJ_Setup_install_success'));
		}

		// Set the redirect.
		$this->setRedirect('index.php?option=com_quanta');
	}

	/**
	 * Method to process any available database upgrades.
	 *
	 * @return	void
	 */
	public function upgrade()
	{
		// Check for request forgeries
		JRequest::checkToken('request') or jexit(JText::_('JInvalid_Token'));

		// Get the upgrades.
		$version	= new QuantaVersion();
		$upgrades	= $version->getUpgrades();

		// Get the setup model.
		$model = &$this->getModel('Setup');

		// Attempt to run the upgrade routine.
		if ($model->upgrade()) {
			$this->setMessage(JText::_('TAOJ_Setup_database_upgrade_success'));
		}
		else {
			$this->setMessage(JText::sprintf('TAOJ_Setup_database_upgrade_failed', $model->getError()), 'notice');
		}
		$this->setRedirect('index.php?option=com_quanta');
	}
}