<?php

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_tree.php");

$tabId = 'wupWindowSelectFields';
$id_project = $_POST['id_project'];
$reqUrl = 'webuserspool/_ajax/ajax.projectUsers.php';

$interFields = new MakeTree($tabId.'_inter');
$interFields->setMainTable('_InterviewerStructure',DB_WARPIT_USERSPOOL)
	->setReqUrl($reqUrl)
	->setTitle('Interviewer fields')
	->flex(1)
	->baseParams = 'id_project:'.$id_project;

echo $interFields->CreateTree();

$projFields = new MakeTree($tabId.'_proj');
$projFields->setMainTable($_POST['projName'],DB_WARPIT_WEBCATI)
->setReqUrl($reqUrl)
->setTitle('Structure fields')
->flex(1)
->baseParams = 'id_project:'.$id_project;

echo $projFields->CreateTree();
?>

var win1 = new Ext.Window({
        modal:true,
 		title: 'File Upload Form',
        width:400,
        height:500,
        layout:'hbox',
        layoutConfig:{ align:'stretch' },
        closeAction:'close',
        plain: true,
		items: [ <?php echo "$interFields,$projFields";?> ],
		buttons:[{
			text:'Save',
			handler:function(){
			<?php 
				echo "$interFields.RMconn.request({params:{
					action:'saveFields',
					id_project:$id_project,
					interFields: $interFields.getChecked('id').join(),
					questFields : $projFields.getChecked('text').join()
				},
				success:function(resp)
				{
					var r = Ext.decode(resp.responseText);
					var grid = Ext.getCmp('{$_POST['compId']}');
					r.columns.unshift(grid.selModel);
					r.columns[3].renderer = r.columns[4].renderer = function(val){
	if(val)
	return Date.parseDate(val,'U').format('d.m.Y H:i:s');
};
					r.columns[5].renderer = function(val){
	if(val)
	return Date.parseDate(val-3600,'U').format('H:i:s');
};
					grid.colModel.setConfig(r.columns);
					var reader = grid.getStore().reader;
					reader.meta.fields = r.fields;
					reader.recordType = Ext.data.Record.create(r.fields);
					delete reader.ef;
					reader.buildExtractors();
					grid.getStore().reload();
					
				}	
				});";
			?>
			win1.close();
			}
			}
		]

    }).show();