<?php include ("$_SERVER[DOCUMENT_ROOT]/../include/stdphp.inc"); 

// Are we cookied?  What are we completing??
////////////////////////////////////////////

if (is_string($_COOKIE[myid])) {
		// Not a brand new visitor
	$completing = 1;
} else {
	$completing = 0;
	$myid = uniqid("my");
	setcookie("myid",$myid,time()+3600*24*365*5,"/");
			// To add for live site - domain
}

// Do the completion action
////////////////////////////////////////////

switch ($completing) {

	case 0:
		$fill[greeting] = 'Welcome to "My Wellho"';
		$next = 1;
		break;

	case 1:
		$fill[greeting] = "Welcome to login, $myid";
		$next = 2;
		break;

	default:
		$fill[greeting] = 'The impossible has happened';
		break;
}


// Work that is done for every page, e.g. logging
////////////////////////////////////////////


// Prepare next page
////////////////////////////////////////////

switch ($next) {

	case 1:
		$fill[template] = "login";
		break;

	case 2:
		$fill[template] = "newuser";
		break;

	default:
		$fill[template] = "error";
		break;
}

// spit it out.
////////////////////////////////////////////

$sourcedir =  "../../include/template";

$boiler = "$sourcedir/boilerplate.htp";
$fh = fopen($boiler,"r");
$html = fread($fh,filesize($boiler));

$changing = "$sourcedir/$fill[template].htp";
$fh = fopen($changing,"r");
$stuff = fread($fh,filesize($changing));

$page = ereg_replace("%stuff%",$stuff,$html);

$page = ereg_replace("%greeting%",$fill[greeting],$page);

print ($page);
?>
