Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
ISSO - Blob - ViewGit - Blue Static
<?php
/*=====================================================================*\
|| ###################################################################
|| # Blue Static ISSO Framework
|| # Copyright (c)2005-2009 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

/**
 * Installer creator (Install.php)
 *
 * @package	ISSO
 */

/**
 * Installer
 *
 * Installer modules should extend this class. In the install module router,
 * instantiate the right module. Methods beginning with step*() will be executed
 * in numerical order.
 *
 * @author		Blue Static
 * @copyright	Copyright (c)2005 - 2009, Blue Static
 * @package		ISSO
 *
 */
abstract class BSInstaller
{
	/**
	 * All the method steps
	 * @var array
	 */
	private $steps = array();

	/**
	 * The file name of this module
	 * @var string
	 */
	protected $fileName;

	/**
	 * Constructor: set up the steps
	 *
	 * @param	string	The file name for this module
	 */
	public function __construct($fileName)
	{
		$this->fileName = $fileName;

		if (!BSApp::$input instanceof BSInput)
		{
			throw new Exception('BSApp::$input is not an instance of BSInput');
		}

		$methods = get_class_methods($this);
		foreach ($methods as $name)
		{
			if (preg_match('/step([0-9]+)/', $name))
			{
				$this->steps[] = $name;
			}
		}
		natsort($this->steps);

		$this->_runStep(BSApp::$input->inputClean('step', TYPE_UINT));
	}

	/**
	 * An abstract method that needs to be overridden by a subclass that
	 * populates the page title
	 *
	 * @return	string	Returns the page title
	 */
	protected abstract function _pageTitle();

	/**
	 * Abstract method that will return link to the page after all the
	 * steps are completed. This needs to provide it's own <a>
	 *
	 * @return	string	Final page link
	 */
	protected abstract function _finalLink();

	/**
	 * Abstract method that prints out the first welcome screen that the
	 * user sees when no step has been selected
	 */
	protected abstract function _welcomePage();

	/**
	 * Prints out the page header... you really don't do this more than
	 * once
	 */
	protected function _setUp()
	{
		?>
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title><?= $this->_pageTitle() ?></title>

	<style type="text/css">
	<!--
		body
		{
			font-family: Verdana, Arial, Helvetica, sans-serif;
			font-size: 12px;
		}

		body a
		{
			color: rgb(0, 0, 238);
		}

		h1
		{
			color: rgb(66, 137, 155);
		}

		.buttonlink
		{
			margin-top: 20px;
		}

		.buttonlink a
		{
			font-weight: bold;
			padding: 5px;
			border: 1px solid black;
			text-decoration: none;
			color: rgb(37, 37, 37);
			background-color: rgb(239, 239, 239);
			margin-top: 20px;
		}
	//-->
	</style>
</head>
<body>

		<?php
	}

	/**
	 * Runs the specific step method; if it does not exist, it will throw
	 * an error
	 *
	 * @param	integer	Step number
	 */
	protected function _runStep($step)
	{
		if ($step == 0)
		{
			$this->_setUp();
			$this->_welcomePage();
			$this->_setDown(0);
		}
		else if (in_array("step$step", $this->steps))
		{
			$this->_setUp();
			$this->{"step$step"}();
			$this->_setDown($step);
		}
		else
		{
			throw new Exception("step$step() does not exist in this module");
		}
	}

	/**
	 * Prints out the footer part of the page, and the appropriate forwarding
	 * action button
	 *
	 * @param	integer Step number
	 */
	protected function _setDown($step)
	{
		// this is the last step, print the final button
		if ($step == sizeof($this->steps))
		{
			echo '<div class="buttonlink">' . $this->_finalLink() . '</div>';
		}
		// just another step
		else
		{
			echo '<div class="buttonlink"><a href="' . $this->fileName . '?step=' . ++$step . '">' . _('Next Step') . '</a></div>';
		}

		echo '
</body>

</html>';
	}
}

?>