<?
/* welcome message*/
function welcome() {

	echo "<td>Checking 'firstinstall'</td>";
	if(file_exists("misc/firstinstall")) {
		echo "<td class='resok'>OK</td><td></td>";
		return 0;
	} else {
		echo "<td class='resko'>ERROR</td><td>File 'misc/firstinstall not present!</td>";
		return 1;
	}


}

/* test write permission */
function misc_writeable() {
	
	echo "<td>Checking dir 'misc' write permission</td>";

	$fp = @fopen("misc/deleteme","w+");
	if($fp != null) {
		fclose($fp);
		unlink("misc/deleteme");
		echo "<td class='resok'>OK</td><td></td>";
		return 0;
	} else {
		echo "<td class='resko'>ERROR</td><td>Set write permission for 'misc/'!</td>";
		return 1;
	}
	
}

/* test write permission */
function news_writeable() {
	
	echo "<td>Checking dir 'news' write permission</td>";

	$fp = @fopen("news/deleteme","w+");
	if($fp != null) {
		fclose($fp);
		unlink("news/deleteme");
		echo "<td class='resok'>OK</td><td></td>";
		return 0;
	} else {
		echo "<td class='resko'>ERROR</td><td>Set write permission for 'news/'!</td>";
		return 1;
	}
	
}




/* TEST ARRAY */
$test_f = array(
		'welcome',
		'misc_writeable',
		'news_writeable',
		); 


?>		
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Flatnuke setup utility</title>
<style type="text/css">
body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
a, a:visited, a:active { color:#1E74FF; }
a:hover { color:#FF541F; }
div.page_header { padding:8px; font-size:28px; font-weight:bold; background-color:#d9d8d1; }
div.page_header a:visited { color:#0000cc; }
div.page_header a:hover { color:#880000; }
div.page_nav { padding:8px; }
div.page_nav a:visited { color:#0000cc; }
div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
div.page_footer_text { float:left; color:#555555; font-style:italic; }
div.page_body { padding:8px; }
div.title, a.title {
	display:block; padding:6px 8px;
	font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
}
a.title:hover { background-color: #d9d8d1; }
div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
div.log_body { padding:8px 8px 8px 150px; }
span.age { position:relative; float:left; width:142px; font-style:italic; }
div.log_link {
	padding:0px 8px;
	font-size:10px; font-family:sans-serif; font-style:normal;
	position:relative; float:left; width:136px;
}
div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
a.list { text-decoration:none; color:#000000; }
a.list:hover { text-decoration:underline; color:#880000; }
table { padding:8px 4px; }
th { padding:2px 5px; font-size:12px; text-align:left; border-bottom: 1px solid black;}
tr.light:hover { background-color:#edece6;}
tr.dark { background-color:#f6f6f0;}
tr.dark:hover { background-color:#edece6; }
td { padding:2px 5px; font-size:12px; vertical-align:top; border-bottom: 1px dotted black;}
td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
div.pre { font-family:monospace; font-size:12px; white-space:pre; }
div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
a.rss_logo {
	float:right; padding:3px 0px; width:35px; line-height:10px;
	border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
	color:#ffffff; background-color:#ff6600;
	font-weight:bold; font-family:sans-serif; font-size:10px;
	text-align:center; text-decoration:none;
}
.resok { background-color: #00ff00; border-left: 1px solid black; border-right: 1px solid black; text-align: center;}
.resko { background-color: #ff0000; border-left: 1px solid black; border-right: 1px solid black; text-align: center;}
a.rss_logo:hover { background-color:#ee5500; }
h2 {margin-left: 10px;}
</style>

</head>
<body>
<div align="center" class="page_header">Flatnuke setup utility</div>
<h2>Installation tests:</h2>
<div style="margin-left: 10px; margin-bottom: 10px; width: 500px;">This is the "s bla bla bla</div>
<table cellspacing="0" style="margin-left: 10px; border: 1px dashed; width: 600px">
	<tr class="dark">
		<th>Test</th>
		<th>Result</th>
		<th>Notes</th>
	</tr>

<?

$sum = 0;

for($i = 0; $i < count($test_f); $i++) {
	if(($i%2) == 0)
		echo "<tr class=\"light\">";
	else
		echo "<tr class=\"dark\">";

	$sum += $test_f[$i]();
	
	echo "</tr>";
}

?>
</table>
<br />
<br />
<h2>Test result:</h2>
<?
if($sum==0) {
	echo "<h1 class='resok'>OK</h1><br />";
	echo "<h1 style=\"text-align: center;\"><a href='index.php?mod=none_Login&amp;action=visreg'>Register the first user! &gt;&gt;</a></h1>";
}
else {
	echo "<h1 class='resko'>ERROR</h1>";
}
?>
<br />
<br />
</body>
</html>

