<?php

//get php configuration settings.  requires elaborate parsing of phpinfo() output
ob_start();
phpinfo(INFO_GENERAL);
$string = ob_get_contents();
ob_end_clean();

$pieces = explode("<h2", $string);
$settings = array();
foreach($pieces as $val)
{
	preg_match("/<a name=\"module_([^<>]*)\">/", $val, $sub_key);
	preg_match_all("/<tr[^>]*>
									   <td[^>]*>(.*)<\/td>
									   <td[^>]*>(.*)<\/td>/Ux", $val, $sub);
	preg_match_all("/<tr[^>]*>
									   <td[^>]*>(.*)<\/td>
									   <td[^>]*>(.*)<\/td>
									   <td[^>]*>(.*)<\/td>/Ux", $val, $sub_ext);
	foreach($sub[0] as $key => $val) {
		if (preg_match("/Configuration File \(php.ini\) Path /", $val)) {
	   		$val = preg_replace("/Configuration File \(php.ini\) Path /", '', $val);
			$phpini = strip_tags($val);
	   	}
   }
}

$gd_info_alternate = 'function gd_info() {
	$array = Array(
		"GD Version" => "",
		"FreeType Support" => 0,
		"FreeType Support" => 0,
		"FreeType Linkage" => "",
		"T1Lib Support" => 0,
		"GIF Read Support" => 0,
		"GIF Create Support" => 0,
		"JPG Support" => 0,
		"PNG Support" => 0,
		"WBMP Support" => 0,
		"XBM Support" => 0
	);

       $gif_support = 0;

	ob_start();
	eval("phpinfo();");
	$info = ob_get_contents();
	ob_end_clean();

	foreach(explode("\n", $info) as $line) {
		if(strpos($line, "GD Version")!==false)
			$array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));
		if(strpos($line, "FreeType Support")!==false)
			$array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));
		if(strpos($line, "FreeType Linkage")!==false)
			$array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));
		if(strpos($line, "T1Lib Support")!==false)
			$array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));
		if(strpos($line, "GIF Read Support")!==false)
			$array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));
		if(strpos($line, "GIF Create Support")!==false)
			$array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));
		if(strpos($line, "GIF Support")!==false)
			$gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
		if(strpos($line, "JPG Support")!==false)
			$array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));
		if(strpos($line, "PNG Support")!==false)
			$array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));
		if(strpos($line, "WBMP Support")!==false)
			$array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));
		if(strpos($line, "XBM Support")!==false)
			$array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));
	}

	if($gif_support==="enabled") {
		$array["GIF Read Support"]  = 1;
		$array["GIF Create Support"] = 1;
	}

	if($array["FreeType Support"]==="enabled")
		$array["FreeType Support"] = 1;

	if($array["T1Lib Support"]==="enabled")
		$array["T1Lib Support"] = 1;

	if($array["GIF Read Support"]==="enabled")
		$array["GIF Read Support"] = 1;

	if($array["GIF Create Support"]==="enabled")
		$array["GIF Create Support"] = 1;

	if($array["JPG Support"]==="enabled")
		$array["JPG Support"] = 1;

	if($array["PNG Support"]==="enabled")
		$array["PNG Support"] = 1;

	if($array["WBMP Support"]==="enabled")
		$array["WBMP Support"] = 1;

	if($array["XBM Support"]==="enabled")
	$array["XBM Support"] = 1;

	return $array;

}';

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Miniclick 5  Installer: Step 1</title>
<link rel="stylesheet" href="../css/login.css" type="text/css" />
</head>
<body>
<table>
  <tbody>
	<tr>
		<td><img src="../img/logo_miniclick.png" alt="logo_miniclick"/>
		</td>
	</tr>
	<tr>
		<td ><strong>Step 1 of 5 : System Check</strong>
		</td>
	</tr>

	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>PHP version 5.x.</strong></td>
	</tr>
	<tr>
		<td ><?php $php_version = phpversion(); echo (str_replace(".", "", $php_version) < "500") ? "<strong><font color=\"#FF0000\">Invalid version ($php_version) Installed</font></strong>" : "<strong><font style=\"color:#0066CC;\">Version $php_version Installed</font></strong>"; ?></td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>Database</strong></td>
	</tr>
	<tr>
        	<td ><?php echo function_exists('mysql_connect')?"<strong><font style=\"color:#0066CC;\">Available</font></strong>":"<strong><font color=\"#FF0000\">Not Available</font></strong>";?></td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>config.php</strong></td>
	</tr>
	<tr>
		<td ><?php echo (is_writable('../includes/config.php') || is_writable('.'))?"<strong><font style=\"color:#0066CC;\">Writeable</font></strong>":"<strong><font color=\"#FF0000\">Not Writeable</font></strong>"; ?></td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>Cache Directory (cache/)</strong></td>
	</tr>
	<tr>
		<td ><?php
				if(is_dir('../cache/')){
					if(is_writable('../cache/')){
						echo "<strong><font style=\"color:#0066CC;\">Writeable</font></strong>";
					}else{
						echo "<strong><font color=\"#FF0000\">Not Writeable</font></strong>";
					}
				}else{
					echo "<strong><font color=\"#FF0000\">Not Exist</font></strong>";
				}
				?>
		</td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>Template Directory (templates_c/)</strong></td>
	</tr>
	<tr>
		<td ><?php if(is_dir('../templates_c/')){
					if(is_writable('../templates_c/')){
						echo "<strong><font style=\"color:#0066CC;\">Writeable</font></strong>";
					}else{
						echo "<strong><font color=\"#FF0000\">Not Writeable</font></strong>";
					}
				}else{
					echo "<strong><font color=\"#FF0000\">Not Exist</font></strong>";
				}
				?>
		</td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>Uploads Directory (documents/)</strong></td>
		
	</tr>
	<tr>
		<td ><?php if(is_dir('../documents/')){
					if(is_writable('../documents/')){
						echo "<strong><font style=\"color:#0066CC;\">Writeable</font></strong>";
					}else{
						echo "<strong><font color=\"#FF0000\">Not Writeable</font></strong>";
					}
				}else{
					echo "<strong><font color=\"#FF0000\">Not Exist</font></strong>";
				} 
				?>
		</td>
	</tr>
	<tr>
		<td style="background-image:url('../img/cellule.jpg');"><strong>GD library v 2.0 or later</strong></td>
	</tr>
	<tr>
		<td ><?php
					if (!extension_loaded('gd')) {
						echo "<strong><font size=-1 color=\"#FF0000\">GD Library not configured in your PHP installation.<br>Check out our <a href='http://www.libgd.org/'>online documentation</a> for tips on enabling this library. </font></strong>";
					}else{
						if (!function_exists('gd_info')){
							eval($gd_info_alternate);
						}
						$gd_info = gd_info();
						if (isset($gd_info['GD Version'])) {
							$gd_version = $gd_info['GD Version'];
							$gd_version=preg_replace('%[^0-9.]%', '', $gd_version);
							if ($gd_version > "2.0") {
								echo "<strong><font style=\"color:#0066CC;\">Version $gd_version Installed</font></strong>";
							}else{
								echo "<strong><font style=\"color:#0066CC;\">Version $gd_version Installed.</font></strong>";
							}
						}else{
							echo "<strong><font size=-1 color=\"#FF0000\">GD Library available, but not properly configured in your PHP installation.<br>You can ignore this error and continue your installation, however the chart images simply won't work.</font></strong>";
						}
					}
				?>
		</td>
	</tr>
	<tr>
		<td><form action="index.php" method="post" name="form" id="form">
		<input type="hidden" name="file" value="step2.php" />
		<br />
		<button type="submit" name="next" value="Next >" />
		</form>
		</td>
	</tr>
	</tbody>
</table>

</body>
</html>
