<?php 
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");	
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");


$id_project = $_POST['id_project'];

//$vars = $db->get('_Projects',$id_project,'addOnVariables',DB_WARPIT_WEBCATI_BASE);

$grid = new MakeGrid();
$grid->setMainTable('_ProjectExtraVariables',DB_WARPIT_WEBCATI_BASE)
->setReqUrl('webcati/_ajax/buildQuestionare/ajax.extraVariables.php');
$grid->baseParams = "SQLwhere : 'id_project = $id_project'";

$grid->addColumn('id_project')->defaultValue($id_project);
$grid->addColumn('var_name','Name',"new Ext.form.TextField()");

include_once(PATH_TO_ROOT."config.php");
	$comboArray = $configCombo['DataType'][$_SESSION['UserInfo']['lng_admin'] ]; 
	for ($i=0;$i< count($comboArray);$i++ )
	{
		$comboStr[] = "['$i','".$comboArray[$i]."']";
	}
	$storeDataType = 'StoreBaseType_'.$tableName;
	
	echo "var $storeDataType = new Ext.data.ArrayStore({
        fields: [
            'myId',
            'displayText'
        ],
        data: [".implode(',',$comboStr).  "]
	});";

$grid->addColumn('var_type',"Type")->defaultValue(0)
->type('combo')->comboStore($storeDataType)->comboValue('myId')->comboDisplay('displayText');

$grid->activateAdd()->activateRemove();

echo $grid->createGrid();


echo "var win = new Ext.Window({
	title:'Project variables',
	height: 300,
	width: 240,
	layout:'fit',
	modal:true,
	items : $grid,
	
	buttons: [{
		text: 'Finish',
		handler : function(){
			var allRecs =  $grid.store.getRange();
			allNames = new Array();
			for(var i=0;i<allRecs.length;i++)
			{
				allNames.push( allRecs[i].data.var_name	);
			}
			Ext.getCmp( '{$_POST['id_label']}' ).setText( allNames.join() );
			win.close();
		}
	}]
}).show()";

?>