Location: PHPKode > projects > synType CMS > setup/wizards/cmssetup/page.chkreq.php
<?php
/**
 *  synType CMS Setup
 *  Module: Wizard Page Check Requirements
 *
 *  Copyright © 2004-2009 V. Puttrich, MindArray
 *
 *  http://www.mindarray.eu
 *
 *  Author: V. Puttrich, MindArray
 * ----------------------------------------------------------------------------
 *  $Id$
 * ----------------------------------------------------------------------------
 *
 *  This file is part of synType CMS.
 *
 *  synType CMS 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, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  synType CMS 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 libMail. If not, see <http://www.gnu.org/licenses/>.
 *
 * ----------------------------------------------------------------------------
 **/


include_once(LIBDIR .'/lib.chkphp.php');


class wizPageChkreq extends wizardPage
{

	public function __construct($oWizard, &$in)
	{
		parent::__construct($oWizard, $in);
	}

	public function __destruct()
	{
		parent::__destruct();
	}

	protected function onPrepare()
	{
		$nErrCount = 0;

		// No action if we stepped back
		if($this->_nWizStep == wizWizard::PAGE_BACK)
			return 0;

		// Start testing ...
		$this->_aResults = array();
		$oChk = new checkPHP('./setup.ini');
		$aData = $oChk->getResults();

		$this->_oWizard->setProperty('meta', $aData);

		// We shouldn't report an error here
		return 0;
	}

	protected function onPage($nErr)
	{
		if($nErr == 1)
			return $this->getContents();

		$this->setTextTop("Requirements");

		if(($aData = $this->_oWizard->getProperty('meta')) === null)
			throw new wizException("Persistent data not found!");

		// PHP extensions
		// Format and Order by 'required' and 'optional'
		$aExtReq = $aExtOpt = $aDBMSReq = $aDBMSOpt = array();
		$nErrCnt  = $this->_parseExtensions($aData['ext'], $aExtReq, $aExtOpt);
		$nErrCnt += $this->_parseExtensions($aData['extdb'], $aDBMSReq, $aDBMSOpt);
		$aExtDBMS = array_merge($aDBMSReq, $aDBMSOpt);

		// Errors?
		if($nErrCnt > 0)
			$this->setErrorTitle("One or more of the required PHP extensions are not available!<br />Please install and enable them.");

		// Assemble output
		$this->addText($this->_getDescription());

		$this->addText("<div>\n");

		$sHtml = '';
		foreach($aExtReq as $sRows){
			$sHtml .= "{$sRows}";
		}
		$this->addText(
			 "<div style=\"float:left;\">\n"
			."<u>Required PHP extensions</u><br />\n"
			. nl2br($sHtml)
			."</div>\n"
		);

		$this->addText("<div style=\"float:left; width:30px;\" />&nbsp;&nbsp;&nbsp;</div>\n");

		$sHtml = '';
		foreach($aExtOpt as $sRows){
			$sHtml .= "{$sRows}";
		}
		$this->addText(
			 "<div style=\"float:left;\">\n"
			."<u>Optional PHP extensions</u><br />\n"
			. nl2br($sHtml)
			."</div>\n"
		);

		$this->addText("<div style=\"float:left; width:30px;\" />&nbsp;&nbsp;&nbsp;</div>\n");

		$sHtml = '';
		foreach($aExtDBMS as $sRows){
			$sHtml .= "{$sRows}";
		}
		$this->addText(
			 "<div style=\"float:left;\">\n"
			."<u>PHP DBMS extensions</u><br />\n"
			. nl2br($sHtml)
			."</div>\n"
		);

		$this->addText("<div style=\"clear:both;\"></div>\n</div>\n");

		return $this->getContents();
	}

	private function _parseExtensions($aData, &$aReq, &$aOpt)
	{
		$nErrCnt  = 0;
		$sImgDir  = IMGDIR;
		$sChkBox_ = "<img src=\"{$sImgDir}/blank.gif\" width=\"16\" height=\"16\" alt=\"\" />";
		$sChkBoxX = "<img src=\"{$sImgDir}/check_yes.png\" width=\"16\" height=\"16\" alt=\"\" />";
		$sChkBoxO = "<img src=\"{$sImgDir}/check_no.png\" width=\"16\" height=\"16\" alt=\"\" />";
		$sChkBoxF = "<img src=\"{$sImgDir}/check_failed.png\" width=\"16\" height=\"16\" alt=\"\" />";

		foreach($aData as $sExt => $mVal){
			// Required
			if((is_array($mVal) && $mVal['module'] === 1) || $mVal === 1){
				$aReq[] = "{$sChkBoxX}&nbsp;{$sExt}\n";
				if(is_array($mVal)){
					foreach($mVal['features'] as $sFeature => $aVal){
						$n = count($aReq);
						$aReq[$n] = "{$sChkBox_}&nbsp;";
						if($aVal['nSupported'] === 0)
							$aReq[$n] .= "{$sChkBoxO}&nbsp;";
						else if($aVal['nSupported'] === -1){
							$nErrCnt++;
							$aReq[$n] .= "{$sChkBoxF}&nbsp;";
						}
						else
							$aReq[$n] .= "{$sChkBoxX}&nbsp;";
						$aReq[$n] .= "{$saVal['text']}\n";
					}
				}
			}
			else if((is_array($mVal) && $mVal['module'] === -1) || $mVal === -1){
				$nErrCnt++;
				$aReq[] = "{$sChkBoxF}&nbsp;{$sExt}\n";
			}
			else if((is_array($mVal) && $mVal['module'] === 2) || $mVal === 2){
				$aOpt[] = "{$sChkBoxX}&nbsp;{$sExt}\n";
				if(is_array($mVal)){
					foreach($mVal['features'] as $sFeature => $aVal){
						$n = count($aOpt);
						$aOpt[$n] = "{$sChkBox_}&nbsp;";
						if($aVal['nSupported'] === 0)
							$aOpt[$n] .= "{$sChkBoxO}&nbsp;";
						else if($aVal['nSupported'] === -1)
							$aOpt[$n] .= "{$sChkBoxF}&nbsp;";
						else
							$aOpt[$n] .= "{$sChkBoxX}&nbsp;";
						$aOpt[$n] .= "{$aVal['text']}\n";
					}
				}
			}
			else if((is_array($mVal) && $mVal['module'] === 0) || $mVal === 0){
				$aOpt[] = "{$sChkBoxO}&nbsp;{$sExt}\n";
			}
		}

		return $nErrCnt;
	}

	private function _getDescription()
	{
		 return <<<TEXT
This page shows lists of PHP extensions that are required or optional.
<br /><br />
Extensions that are marked as checked, are available. Optional Extensions will either be used by the core of the CMS,
if available, or may be required by applications plugged into the CMS.
<br />
At least one extension for the DBMS you want to use with synType CMS must be available. Also make sure the server
of the DBMS is up and running.
<br /><br />
You may now install missing modules and then reload this page to see the changes.
TEXT;
	}

}

?>
Return current item: synType CMS