<?php

require_once 'func.tpl.inc';

$page_start = exec_time();
$fieldsets = array(array("legend1", "text for field1"), 
	array("legend2", "text for field2"), array("legend3", "text for field3"));
$index = query_value('index', 'index4');

//version1 template vars
//these vars start with the name tpl_1_ 
set_vartag('V_version', 'JFTM v7, final version');
set_vartag('V_time', date("h:i:s"));
set_vartag('V_date', date("d m Y"));
set_vartag('V_page_title', "N.A.F. - JFTM testversion");
set_vartag('V_fs_legend', '$fieldsets[$j][0]');
set_vartag('V_fs_text', '$fieldsets[$j][1]');
set_vartag('V_err_number', '$i');
/* ********** START PAGE CODE ********** */







print(get_template('header'));

set_vartag('V_page_title', 'No vars set ...');
print(get_template('title'));
print(get_template($index));



set_vartag('V_page_title', 'Vars set to normal values ...');
print(get_template('title'));
print(get_template($index));



set_vartag('V_section', '_info');
set_vartag('V_sub_section', '_register');
print(get_template($index));



set_vartag('V_section', '_info');
set_vartag('V_sub_section', '_login');
print(get_template($index));

set_vartag('V_section', '_error');
set_vartag('V_sub_section', '_1');
print(get_template($index));

set_vartag('V_section', '_error');
set_vartag('V_sub_section', '');
for($i=0; $i<3; $i++)
{
	print(get_template('index4'));
}


for($j=0; $j<count($fieldsets); $j++)
{
	print(get_template('fieldset'));
}

set_vartag('V_page_title', 'Vars set to special values ...');
print(get_template('title'));

print(get_template('nested'));

set_vartag('V_section', '_unknwon1');
set_vartag('V_sub_section', '_unknown2');
print(get_template($index));

set_vartag('V_page_gen_time', 'round(exec_time() - $page_start, 3)');

print("<a href='time.php'>Calculate mean gen page time</a>");
print("<br /><a href='index.php?index=index4_long'>Test tpl with big file</a>");
print("<br /><a href='index.php?index=index4'>Test tpl with normal file</a>");
print(get_template('footer'));












/* @return microtime (in seconds)
 * @desc calculates microtime (for runtime) */
function exec_time()
{
	$mtime = explode( " ", microtime());
	$msec = (double)$mtime[0];
	$sec = (double)$mtime[1];

	return $sec + $msec;
}


/*get value of an argument in the url
	$arg			argument to get value for
	$default		use this value, when $arg is not found
	return			value of $arg (or $default) when $arg exist; else return false
	*/
function query_value($arg, $default = '') {
	  $ret = $default;
	  
	  parse_str(rawurldecode($_SERVER['QUERY_STRING']), $vars);
	  
	  
	  if ($arg !== '') {
		if (isset($vars[$arg]))		$ret = urldecode($vars[$arg]);
	  }
	  else
		$ret = $vars;
	
	
	  return $ret;
	}

?>