<?php
include '_dirinfo.php';
//include("../motorcek/class.Engine.php");
define("DB_WARPIT_WEBCATI", "WarpitDevel_Webcati");
define("DB_WARPIT_WEBCATI_BASE", "WarpitDevel_Webcati_base");

?>
<head>
  <title>Designer test</title>
  <style type="text/css">
  td {
    vertical-align: top;
     }
  </style>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php 

include_once(PATH_TO_ROOT."designerTest/class.Display.php");
include_once(PATH_TO_ROOT."_support/class.db.php");

/*$mofa = new Engine($db);

if ($_POST['questSubmit']) {

	$mofa->SaveQuestions($_POST['answers']);
	$nextQuestion = $mofa->searchingNextQuestion();

} elseif ($mofa->isInitialization()) $nextQuestion = $mofa->searchingNextQuestion();
  else $nextQuestion = $mofa->BrowserBackButton();

if ($mofa->isFinished()) {
	echo "<br><Br>Konec vprasalnika";
	exit;
}
*/
$id = $_GET['questionId'];
$projectId = $_GET['projectId'];
$project = $_GET['tableName'];

if(!isset($id))
	$id = 6;
if(!isset($project))
{
	$projectId = 25;
	$project = 'Bostjan_motorcek';
}


$db = new db;
$db->SetDatabaseConnection(test,test,localhost);
//test write to file!


$display = new Display($db);

$db->ChangeDatabase('WarpitDevel_Webcati');
$sql = "SELECT * FROM $project WHERE id=$id";
if(!$rs = $db->SQLexecute($sql)) echo $db->GetError();
	$qVar = $db->fetchArray($rs);
	

	$curXML = $display->readXML($id,$projectId);
	if($curXML)
	{
		
		echo "<body style=\"height:100%;border: 0 none;margin:0;padding:0;overflow:auto; \"><FORM METHOD='POST' height=100%>";
		$xml = simplexml_load_string( $curXML );
		$html = "<table cellpadding=0px cellspacing=0px style=\"width:100%;height:100%\">";
		 foreach($xml->children() as $child) {
		  $chAttr = $child->attributes();
		  if($chAttr['type'] == 5)
		  {
		  	$windows .= $display->displayChilds($child,0,false);
		  }
		  else
		  	$html .=  $display->displayChilds($child,0,false); 
		  }
		 $html .= "</table>";
		echo $html;
		//echo $windows;
		echo "</FORM>";
	}
	
	

//ob_end_flush();
	
	
?>
</body>
