<?php 

	include("_dirinfo.php");
	include (PATH_TO_ROOT."init.php");
	include_once (PATH_TO_ROOT."/TGI/init.php");
	include_once (PATH_TO_ROOT."TGI/_class/class.ddfTable2warpit.php");
	include_once (PATH_TO_ROOT."TGI/_class/class.tgi.php");
	include_once (PATH_TO_ROOT."webcati/_ajax/buildQuestionare/class.buildQuestionnaire.php");
	
	set_time_limit(360);
	
	$db->LogWrite(DB_WARPIT_TGI,false,"database name for TGI");

	$db->ChangeDatabase(DB_WARPIT_TGI);

	
	$ddfQ = new ddf2warpit($db);
	
	// read all to array
	$idActiveProject = $ddfQ->getActiveProject();
	$ActiveProjectName = $ddfQ->getActiveProjectName($idActiveProject);
	
	if ($ddfQ->readDDF($idActiveProject)){
		// prepare tables
		
		$Warpit = new tgi($db);
		if ($Warpit->createWarpitTables($ddfQ->project, $ddfQ->storeAnswers, $ddfQ->storeQuestions, $ddfQ->language,$idActiveProject)) {
			echo "{success:true}";
		}
		else 
			echo "{success:false,response:'Napaka pri gradnji vprašalnika.'}";
	}
	else 
		echo "{success:false,response:'Napaka pri čitanju vprašalnika.'}";
	
?>