<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include (PATH_TO_ROOT."webcati/init.php");
	
include_once(PATH_TO_ROOT."webcati/_class/buildQuestionare/class.bqClasses.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_form.php");


$tabId = $_POST['uniqueTabId'];


$projectId = $_POST['id_project'];
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
//let's get the default language of this project!
$res = $db->SQLexecute("SELECT proj_name,language FROM _Projects WHERE id = $projectId");


if(!$row = $db->fetchRow($res))
{
	//maybe the project was deleted ?
	echo "removeSession('$tabId');";
	return;
}

$tableName = $row[0];
$tableNameTree = $tableName.'_tree';

$telephoneTableCBId = "telNumberDatabaseCombo_".$tableName;


$defLng = $row[1];


$ajaxUrl = 'webcati/_ajax/buildQuestionare/ajax.buildQuestionnaire.php';



$hasDialer = false;
$db->ChangeDatabase(DB_WARPIT_WEBCATI);
if($rs = $db->SQLexecute("SELECT id from {$tableName} WHERE tip_sql = 7") )
{
if($db->fetchArray($rs))
{
$hasDialer = true;
}
}


	//we define all the components here so that we have the name references

	//the tree on the left that has all the questions structured in fodlers
	$treeWC = new makeWebcatiTree($tableName.'_tree');
	//the table name is same as the project name
	//the special ajax manipulator takes care of geting the _tree table
	$treeWC->setMainTable($tableName,DB_WARPIT_WEBCATI);
	//for easier access to the tree name
	$treeName = $treeWC->getName();
	
	echo "
	Ext.Ajax.request({
	url: 'webcati/_forms/_ajax/ajax.buildQpanels.php',
	params:{
	action: 'getView',
	id_user: '".$_SESSION['UserInfo']['id']."',
	},
	method:'POST',
	success: function(res, opts){
	//console.log('Tukaj sem!!'+res.responseText);
	res.responseText;

	}
	});
	
	";
echo "/*".$_SESSION['user_view']."*/";	

if ($_SESSION['user_view']==1)
{

include_once(PATH_TO_ROOT."webcati/_forms/buildQuestionare/forms.buildQuestionnaire_advanced.php");

}
if ($_SESSION['user_view']==2)
{

	include_once(PATH_TO_ROOT."webcati/_forms/buildQuestionare/forms.buildQuestionnaire_old.php");

} else {
	
	// dodal Soulskiner po cesko! Borut ze ve zakaj!
	include_once(PATH_TO_ROOT."webcati/_forms/buildQuestionare/forms.buildQuestionnaire_advanced.php");

}
?>
<?php 	
	// write a name of a component, ExtJS evaluate this object into tree on the screen
	//if multiple tabs are shown at once, the tab manager takes care that only one is shown by sending uniqueNotShow as params!
	//in this case we only add the panel
	if($_POST['uniqueNotShow'])
		echo "mainTabPanel.add($tabId);";
	else
		echo "mainTabPanel.add($tabId).show(); 
			  Ext.get('wcbqTabPanel_".$tableName."-xsplit').setStyle('border-bottom', '1px solid #99bbe8');
			  Ext.get('wcbqTabPanel_".$tableName."-xsplit').setStyle('border-top', '1px solid #99bbe8');";
?>