<html>
<head>
<title>PhpGedView Environment Check</title>
<link rel="stylesheet" href="themes/standard/style.css" type="text/css"
	media="all"></link>
<style type="text/css">
.error {
	font-weight: bold;
	color: red;
}

.warning {
	font-weight: bold;
	color: orange;
}

.pass {
	font-weight: bold;
	color: green;
}
</style>
</head>
<body>
<h2>PhpGedView Environment Sanity Check</h2>
<?php
$last_error = "";
function errorHandler($errno, $errstr, $errfile, $errline) {
	global $last_error;
	$last_error = "PHP Error $errno : $errstr ";
}
function printError() {
	global $last_error;
	print "<span class=\"error\">".$last_error."</span><br />";
	$last_error = "";
}
print "<table border=\"1\">";
print "<tr><td colspan=\"2\">Checking for errors...<br />If any of the error tests do not pass you will NOT be able to run PhpGedView.</td></tr>";
print "<tr><td>";
print "Checking required PHP version:";
print "</td><td>";
//-- errors
if (version_compare(phpversion(), '4.3.5')<0)
{
	print "<span class=\"error\">Failed</span><br />PhpGedView requires PHP version 4.3.5 or higher.<br />";
}
if (!empty($last_error)) printError();
else print "<span class=\"pass\">Passed</span><br />";
print "You are using PHP version ".phpversion();
print "</td></tr>";

//session
print "<tr><td>";
print "Checking required for session support:";
print "</td><td>";
session_start();
if (!empty($last_error)) printError();
else print "<span class=\"pass\">Passed</span><br />";
print "</td></tr>";

//database extension mssql,mysql,mysqli,pgsql,sqlite
print "<tr><td>";
print "Checking for minimum database support:";
print "</td><td>";
$has_mysql = extension_loaded("mysql");
$has_pgsql = extension_loaded("pgsql");
$has_mysqli = extension_loaded("mysqli");
$has_mssql = extension_loaded("mssql");
$has_sqlite = extension_loaded("sqlite");
if (!$has_mysql&&!$has_pgsql&&!$has_mysqli&&!$has_mssql&&!$has_sqlite) {
	print "<span class=\"error\">You do not have any of the support database extensions.</span><br />";
}
if (!empty($last_error)) printError();
else print "<span class=\"pass\">Passed</span><br />";
if ($has_mssql) print "You have mssql support<br />";
if ($has_mysql) print "You have mysql support<br />";
if ($has_mysqli) print "You have mysqli support<br />";
if ($has_pgsql) print "You have pgsql support<br />";
if ($has_sqlite) print "You have sqlite support<br />";
print "</td></tr>";
print "</table><br /><br />";

print "<table border=\"1\">";
//-- warnings
print "<tr><td colspan=\"2\">Checking for warnings...<br />If any of the warnings do not pass you may still be able to run PhpGedView on this server, but some functionality may be disabled or you may experience poor performance.</td></tr>";
//set timelimit
print "<tr><td>";
print "Checking for ability to change timelimit:";
print "</td><td>";
@set_time_limit(300);
$newtimelimit = @ini_get("max_execution_time");
if ($newtimelimit!=300) {
	print "<span class=\"warning\">Unable to change time limit.</span><br />You may not be able to run all functions on large GEDCOMs with more than 3000 individuals.<br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "Your maximum time limit is ".$newtimelimit;
print "</td></tr>";

//set memory limit
print "<tr><td>";
print "Checking for ability to change memory limit:";
print "</td><td>";
@ini_set('memory_limit', "38M");
$memorylimit = @ini_get('memory_limit');
if ($memorylimit!="38M") {
	print "<span class=\"warning\">Unable to change memory limit.</span>You may not be able to run all functions on large GEDCOMs with more than 3000 individuals.<br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "Your current memory limit is ".$memorylimit;
print "</td></tr>";

//file uploads
print "<tr><td>";
print "Checking for ability to upload files:";
print "</td><td>";
$uploads = @ini_get("file_uploads");
if ($uploads=="on" || $uploads=="On" || $uploads==="1" || $uploads===1) {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
	print "Your maximum upload file size is: ".ini_get("upload_max_filesize")."<br />";
}
else {
	print "<span class=\"warning\">You cannot upload files with this configuration of PHP.</span><br />You will still be able to use PhpGedView, but you will have to upload all GEDCOM and media files using FTP.<br />";
}
print "</td></tr>";

// gd library
print "<tr><td>";
print "Checking for GD image library:";
print "</td><td>";
if (!function_exists('imagecreatefromjpeg'))
{
	print "<span class=\"warning\">You do not have the GD image library.  You will not be able to automatically create image thumbnails.</span><br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "</td></tr>";

//-- xml sax library
print "<tr><td>";
print "Checking for SAX XML library:";
print "</td><td>";
if (!function_exists('xml_parser_create'))
{
	print "<span class=\"warning\">You do not have the SAX XML library.  You will not be able to run PDF reports or some other auxillary functions.</span><br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "</td></tr>";

print "<tr><td>";
print "Checking for DOM XML library:";
print "</td><td>";
if (!class_exists('DomDocument'))
{
	print "<span class=\"warning\">You do not have the DOM XML library.  You will not be able to export XML.</span><br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "</td></tr>";

print "<tr><td>";
print "Checking for Advanced Calendar library:";
print "</td><td>";
if (!function_exists('GregorianToJD'))
{
	print "<span class=\"warning\">You do not have the advanced calendar support.</span><br />You will not be able to run some advanced calendar functions.<br />";
}
else {
	if (!empty($last_error)) printError();
	else print "<span class=\"pass\">Passed</span><br />";
}
print "</td></tr>";

print "</table>";
print "</body>";
print "</html>";

//-- if php runs then we won't get to the html below this exit
exit;
?>
<h2>PHP has not been configured properly</h2>
</body>
</html>
