<?php
/* $Id: step_2.inc.php,v 1.13 2003/11/26 13:33:59 k-fish Exp $ */
if(!defined("SETUP_RUNNING")) die('Use index.php for running setup!');

/***************************************************************************
 * what to check
 ***************************************************************************/

// just the minimum version needed
$neededPHPVersion = '4.1.0'; // jpgraph says it needs 4.3.0, but...

// list all required extensions with their PHP name
// 0-must, 1-optional
$neededExtensions = array('xml' => 0,
			  'gd' => 0,
			  'pcre' => 0,
			  'session' => 0,
			  'curl' => 1
			  );

// the first number in the array is the value we expect,
// the second is the type of check 0-must, 1-should, 2-info
$neededSettings = array('session.auto_start' => array(0,0),
			'safe_mode' => array(0,1),
			'magic_quotes_runtime' => array(0,0),
			'file_uploads' => array(1,1),
			'display_errors' => array(0,1),
			'allow_call_time_pass_reference' => array(1,1),
			'register_globals' => array(0,2),
			'magic_quotes_gpc' => array(0,2)
			);

/***************************************************************************
 ***************************************************************************/

/* save posted data */
if (isset($_POST["lang_charset"])) {
    $lc = explode(";", $_POST["lang_charset"]);
    $_SESSION["SETUP"]["lang"] = $lc[0];
    $_SESSION["SETUP"]["charset"] = $lc[1];
}	

$_SESSION["SETUP"]["system"] = true;

// uninstall?
if($_SESSION["SETUP"]['uninstall'] === true){
    $smarty->assign('uninstall', true);
} // end uninstall
else{
    $smarty->assign('uninstall', false);
    $report = array();

    // check PHP version
    if (PHP_VERSION < $neededPHPVersion){
	$_SESSION["SETUP"]["system"] = false;
	$report[] = array('status' => 'error',
			  'title' => Lang::getParmLang(Lang::getLanguageString('phpreq'), array($neededPHPVersion)),
			  'desc' => Lang::getParmLang(Lang::getLanguageString('phpreqdesc'), array($neededPHPVersion)));
    }
    else{
	$report[] = array('status' => 'ok',
			  'title' => Lang::getParmLang(Lang::getLanguageString('phpreq'), array($neededPHPVersion)),
			  'desc' => '');
    }

    /* we must be able to write the configfile */
    clearstatcache();
    if(!is_writeable(ROOTPATH)){
	$_SESSION["SETUP"]["system"] = false;
	$report[] = array('status' => 'error',
			  'title' => Lang::getParmLang(Lang::getLanguageString('writereq'), array(ROOTPATH)),
			  'desc' => Lang::getParmLang(Lang::getLanguageString('writereqdesc'), array(ROOTPATH)));
    }
    else{
	$report[] = array('status' => 'ok',
			  'title' => Lang::getParmLang(Lang::getLanguageString('writereq'), array(ROOTPATH)),
			  'desc' => '');
    }

    // check needed PHP extensions
    $extensions = get_loaded_extensions();
    foreach($neededExtensions as $ext => $v){
	if(!in_array($ext, $extensions)){
	    if($v == 0){
		$_SESSION["SETUP"]["system"] = false;
		$report[] = array('status' => 'error',
				  'title' => Lang::getParmLang(Lang::getLanguageString('extreq0'), array($ext)),
				  'desc' => Lang::getParmLang(Lang::getLanguageString('extreqdesc0'), array($ext)));
	    }
	    else{
		$report[] = array('status' => 'note',
				  'title' => Lang::getParmLang(Lang::getLanguageString('extreq1'), array($ext)),
				  'desc' => Lang::getParmLang(Lang::getLanguageString('extreqdesc1'), array($ext)));
	    }
	}
	else{
	    $report[] = array('status' => 'ok',
			      'title' => Lang::getParmLang(Lang::getLanguageString('extreq'), array($ext)),
			      'desc' => '');
	}
    }

    // check include_path
    $incPaths = explode((PHP_OS == 'WIN32' || PHP_OS == 'WINNT') ? ";" : ":", ini_get("include_path"));
    if (! (in_array(".",$incPaths) || in_array("./",$incPaths) || in_array(".\\",$incPaths))){
	$_SESSION["SETUP"]["system"] = false;
	$report[] = array('status' => 'error',
			  'title' => Lang::getLanguageString('incpathreq'),
			  'desc' => Lang::getLanguageString('incpathreqdesc'));
    }
    else{
	$report[] = array('status' => 'ok',
			  'title' => Lang::getLanguageString('incpathreq'),
			  'desc' => '');
    }

    // check PHP settings requirements
    foreach($neededSettings as $set => $v){
	if(!ini_get($set) == $v[0]){
	    if($v[1] == 0){
		$_SESSION["SETUP"]["system"] = false;
		$report[] = array('status' => 'error',
				  'title' => Lang::getParmLang(Lang::getLanguageString('setreq0'), array($set, $v[0])),
				  'desc' => Lang::getParmLang(Lang::getLanguageString('setreqdesc0'), array($set, $v[0])));
	    }
	    elseif($v[1] == 1){
		$report[] = array('status' => 'warning',
				  'title' => Lang::getParmLang(Lang::getLanguageString('setreq1'), array($set, $v[0])),
				  'desc' => Lang::getParmLang(Lang::getLanguageString('setreqdesc1'), array($set, $v[0])));
	    }
	    elseif($v[1] == 2){
		$report[] = array('status' => 'note',
				  'title' => Lang::getParmLang(Lang::getLanguageString('setreq2'), array($set, (int)ini_get($set))),
				  'desc' => Lang::getParmLang(Lang::getLanguageString('setreqdesc2'), array($set, $v[0])));
	    }
	}
	else{
	    $report[] = array('status' => 'ok',
			      'title' => Lang::getParmLang(Lang::getLanguageString('setreq2'), array($set, $v[0])),
			      'desc' => '');
	}
    }

    // assign results to Smarty
    $smarty->assign('report', $report);
    $smarty->assign('status', $_SESSION["SETUP"]['system']);
} // end install

/* append navigation */
$nav = true;
$smarty->append("nav", array(0=>"prev",1=>Lang::getLanguageString("prev"),2=>1));
if($_SESSION["SETUP"]['uninstall'] !== true)
     $smarty->append("subnav", array(0=>"refresh",1=>Lang::getLanguageString("refresh"),2=>1));
if ($_SESSION["SETUP"]["system"] === false)
    $smarty->append("nav", array(0=>"next",1=>Lang::getLanguageString("next"),2=>0));
else
    $smarty->append("nav", array(0=>"next",1=>Lang::getLanguageString("next"),2=>1));

?>