<?php

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_tree.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");
include_once(PATH_TO_ROOT."_support/class.UserSession.php");
include_once(PATH_TO_ROOT."_support/class.Permissions.php");
include (PATH_TO_ROOT."/_support/repository.php");

loadPlugin($_repository,'fileUpload');



$db->ChangeDatabase(DB_WARPIT_MAIN);


// here we define first tree with webcati options
	$treeWC = new MakeTree($_POST['treeName']);
	$treeWC->SetTable($_POST[tree],DB_WARPIT_WEBCATI_BASE)
			->setReqUrl('webcati/_ajax/ajax.groups.php');
	$treeWC->SetRootVisible("false")
		->addConfig('region',"'south'")
		// ->setTitle("Webcati"); // this is not used because we combine in one tab two trees and title is set in combined panel
		->setLinesVisible(false)
		->setContAddItem('New',"!(node.id == 2 || node.id.substring(0,6) == 'design' || "
					   . "node.id == 33 || node.id.substring(0,9) == 'interview' || "
					   . "node.id == 70 || node.id.substring(0,10) == 'userDefine' || "
					   . "node.id == 65 || node.id.substring(0,4) == 'mask')",'icon-add-record',null,0)
		->setContAddGroup('New folder',"!(node.id == 2 || node.id.substring(0,6) == 'design' || "
						. "node.id == 33 || node.id.substring(0,9) == 'interview' || "
						. "node.id == 70 || node.id.substring(0,10) == 'userDefine' || "
						. "node.id == 65 || node.id.substring(0,4) == 'mask')",'icon-add-folder',0)
		->setContDelete('Delete',"node.hasChildNodes() || !(node.id.substring(0,6) == 'design' || "
					  . "node.id.substring(0,9) == 'interview' || node.id.substring(0,10) == 'userDefine' || node.id.substring(0,4) == 'mask') ",'icon_red_delete',0)
		->addContItem('Copy template',"function(item){
	 	var n = item.parentMenu.contextNode;
	 	Ext.Msg.prompt('Copy template '+n.text,'New template name:',function(btn,text){ if(btn == 'ok' ){
		var n = item.parentMenu.contextNode; 
		var par;
		//the group gets added after the clicked group (if a q is clicked its parent is used)
		par = n.parentNode; 
		$treeWC.RMconn.request({params:{
		action:'copyItem',nodeText:text,parId:par.id,isLeaf:1,
		nodeId:n.id,addLeaf:n.attributes.leaf },success:function(resp){
		if(Ext.decode(resp.responseText).success){ $treeWC.getLoader().load(par,function(){ par.expand();});  }
		 }  }); }  } ); 
	 }","!(node.id.substring(0,6) == 'design') || node.attributes.leaf==false",'RMicon_copy')
		->addContItem('Copy mask',"function(item){
	 	var n = item.parentMenu.contextNode;
	 	Ext.Msg.prompt('Copy mask '+n.text,'New mask name:',function(btn,text){ if(btn == 'ok' ){
		var n = item.parentMenu.contextNode; 
		var par;
		//the group gets added after the clicked group (if a q is clicked its parent is used)
		par = n.parentNode; 
		$treeWC.RMconn.request({params:{
		action:'copyItem',nodeText:text,parId:par.id,isLeaf:1,
		nodeId:n.id,addLeaf:n.attributes.leaf },success:function(resp){
		if(Ext.decode(resp.responseText).success){ $treeWC.getLoader().load(par,function(){ par.expand();});  }
		 }  }); }  } ); 
	 }","!(node.id.substring(0,4) == 'mask') || node.attributes.leaf==false",'RMicon_copy')
		->setBoldRoots()
		->setFontMedium()
		->addConfig('updateNode',"function(){}")
		->activateDD('wupGrouplink')
		->setTextPadding('1px')
		->setHeight(350)
		
	;
	
// here we define projects tree	
	$treeWCprojects = new MakeTree('WCprojects');
	$treeName = $treeWCprojects->getName();
	$treeWCprojects->SetTable('_Projects',DB_WARPIT_WEBCATI_BASE);
	$treeWCprojects->SetRootVisible('true','Projects')
	//  ->setTitle('Help'); // this is not used because we combine in one tab two trees and title is set in combined panel
	  ->setSort('idLab ASC')
	  ->setReqUrl('webcati/_forms/_ajax/ajax.groups.php')
	 /* ->setContDelete('Delete')
	  ->setContAdd('Add child')
	  ->setContAddMain('Add sibling')*/
	  //we create data for the language combobox
	  ;

       	$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
		$res = $db->SQLexecute("SELECT id,country_code,cp_comment FROM  _LanguageCodepage WHERE enable = 1");
			while ($row = $db->fetchRow($res))
			$sel[] = '['. $row[0].',"'.$row[1].' - '.$row[2].'"]';

//$nfieldProjects = [];

$NfieldConfig = configLoader::loadConfig('Nfield');
if ( $NfieldConfig['enable'] ) {
	$AddWindowNfieldControl['buttons'] = "  
		,
        {
			xtype:'combo',
            id:'webCatiNfieldProjectCombo',
            width: 140,
            fieldLabel: 'Nfield project',
            mode: 'local',
            editable: false,
            triggerAction:'all',
			store:  nfieldProjectsStore,
			valueField: 'SurveyId',
			displayField: 'SurveyName'
        } ";

	$AddWindowNfieldControl['buttonAction'] = "  
		 Ext.Ajax.request({url:'nfield/surveys/NfieldSurveyManager.php',
			        params:{
			            action:'createSamplePointsByProject',projectName:projectNameText,nfieldSurveyName:selectedNfieldProjectName, nfieldSurveyId:selectedNfieldProject,projectId:r.insertId
			        },
                    success: function(resp){
                        if(resp.responseText){

                                Ext.MessageBox.show({
                                    title: 'Saving data was success',
                                    msg: resp.error,
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.INFO
                                 });
                        }
                        else{
                            Ext.MessageBox.show({
                                    title: 'Saving data was unsuccess',
                                    msg: resp.error,
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.INFO
                                 });
                        }
                    },
                    failure:function(){
                        alert('Failed');
                    }
          })";
          
      $AddWindowNfieldControl['buttonGetData'] = "  
		
      	var comboNfieldProject = Ext.getCmp('webCatiNfieldProjectCombo');
		var selectedNfieldProject = comboNfieldProject.getValue();
		var selectedNfieldProjectName = comboNfieldProject.getRawValue();
		var projectNameText = Ext.getCmp('wcbqAddPrompt').getValue();
		
	  ";
	
	
	
} else unset($AddWindowNfieldControl);


if($_SESSION['UserRights'][15])
	  $treeWCprojects  ->addtBarItem("{iconCls:'icon-add-record',tooltip:'New'  ,handler: function(){ $treeWCprojects.addProjectHandler(); }  }")
	->addConfig('addProjectHandler',"function(item) {

	    //Get projects from NField API
        var nfieldProjectsStore =  new Ext.data.JsonStore({
            url: 'nfield/Helpers/projectsData.php',
            root: 'rows',
            autoLoad:true,
            totalProperty: 'results',
            fields:[{name: 'SurveyId'},{name: 'SurveyName'}]
        });

	    var n;
	    if(item)
			n = item.parentMenu.contextNode;
		else
			{
				n = ".$treeWCprojects.".getSelectionModel().getSelectedNode();
				if(!n)
					n = ".$treeWCprojects.".getRootNode();
			}
		//we open a window to get question name and question type
		new Ext.Window({title:'New Project',modal:true,width:'380px',height:'500px',
		items:{
		xtype:'form', buttonAlign:'center',
		frame:true,
		items: [
		//textfield with filter for questions (start with letter, only numbers and letters )
		{xtype:'textfield',id:'wcbqAddPrompt' , fieldLabel:'Project name',width: 140,allowBlank:false,vtype:'fieldName'},
		{
                    xtype:'combo',
                    width: 140,
                    fieldLabel: 'Language',
                    id:'wcbqComboPrompt',
                    mode: 'local',
                    editable: false,
                    triggerAction:'all',
                    value: '".$_SESSION['UserInfo']['language']."', 
				    store: new Ext.data.ArrayStore({
				        fields: [
				            'id',
				            'LanguageText'
				        ],
				        data:  [ ".implode(',',$sel)."]
				        	
				    }),
				    valueField: 'id',
				    displayField: 'LanguageText'
        }
        
       ".$AddWindowNfieldControl['buttons']."
        
        
		]//eof form items
		 ,
		keys: [{
               key: [Ext.EventObject.ENTER], fn: function(){
                   Ext.getCmp('promptOKBtn').fireEvent('click');
               }
      		 }],
		buttons:[{text:'Ok',id:'promptOKBtn',listeners:{
		click: function(){
		
		".$AddWindowNfieldControl['buttonGetData']."

		var cb = Ext.getCmp('wcbqComboPrompt');
		var text = Ext.getCmp('wcbqAddPrompt').getValue();
		var selLng = cb.getValue();
			var par;
			//if we clicked on a question or a closed group we add it to its parent one position lower otherwise to the clicked group
			var closed = !n.isExpanded();
			if(Ext.getCmp('wcbqAddPrompt').isValid())
			{
			if(n.attributes.isQuestion==true || (closed && n.id != 0))
			{par = n.parentNode; }
			 else {par = n;}
			 //we make a server requst to handle insertProject
			 //we send the parent node ID the text and a template if selected
	         $treeName.RMconn.request({params:{
	         action:'insertProject',
	         parId:par.id,
	         nodeText:text,
	         projectLanguage: selLng,
	         nodeId:n.attributes.id } 
			,success:function(resp){
			var r = Ext.decode(resp.responseText);
			if(r.success){
			    
				//NFIELD PROCESS START

			    ".$AddWindowNfieldControl['buttonAction']."


			    //NFIELD PROCESS END



				//if adding was succesful we refresh the tree and open on the added question
				//NOTE: all other groups get closed
				var p = par.getPath()+'/'+Ext.decode(resp.responseText).insertId;
				$treeName.getLoader().load($treeName.getRootNode(),function(){ $treeName.selectPath(p); } );
				Ext.getCmp('wcbqAddPrompt').findParentByType('window').close();
				//lets start composing this project
				addTabAuto('buildQuestionnaire_'+ text,'webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{ id_project:r.insertId }); 
				
			} else{//else we display a warning and focus on the name field
			Ext.Msg.alert('Warning!',Ext.decode(resp.responseText).error );
			Ext.getCmp('wcbqAddPrompt').focus()}},
				
			failure:function(){alert('failed');}	});    
			}	
			
		}
	}
			  },
		{
		text:'Cancel',handler:function(){ 
		this.findParentByType('window').close();
	
		 }
		 }
			  ] },
	defaultButton:'wcbqAddPrompt'
			   } ).show(n); 
					   
	/*  Ext.Msg.prompt('Add Project','Project name:',function(btn,text){ if(btn == 'ok' ){
		var n = item.parentMenu.contextNode;
		var par,pos,ord;
		if(n.attributes.isProject==true)
		{par = n.parentNode;  } else {par = n;}
         $treeName.RMconn.request({params:{action:'insertProject',parId:par.id,nodeText:text,nodeId:n.id} 
		,success:function(resp){
		if(Ext.decode(resp.responseText).success){
			//var newNode = new Ext.tree.TreeNode({id: Ext.decode(resp.responseText).insertId,q_pos:pos,position:ord, text: 'Novi', leaf: true});
			//par.appendChild(newNode);
			//par.reload();
			var p = par.getPath()+'/'+Ext.decode(resp.responseText).insertId;
			$treeName.getLoader().load($treeName.getRootNode(),function(){ $treeName.selectPath(p); } );
			
		} else{ }},
			failure:function(){alert('failed');}	}); }});*/ }")
	  ->addContItem('New',"function(item){ $treeWCprojects.addProjectHandler(item); }",'false','icon-add-record' )
	  ->addConfig('addGroupHandler',"function(item){
		Ext.Msg.prompt('Add Folder','Folder name:',function(btn,text){ if(btn == 'ok' ){
		var n;
	    if(item)
			n = item.parentMenu.contextNode;
		else
			{
				n = $treeWCprojects.getSelectionModel().getSelectedNode();
				if(!n)
					n = $treeWCprojects.getRootNode();
			}
		var par;
		//the group gets added after the clicked group (if a q is clicked its parent is used)
		
		if(n.attributes.isProject == 1)
			{par = n.parentNode; } 
		else{ par = n;   }
		$treeName.RMconn.request({params:{
		action:'insertGroup',nodeText:text,
		nodeId:par.id
		,isTargetQ:par.attributes.isQuestion },success:function(resp){
		if(Ext.decode(resp.responseText).success){ $treeName.getLoader().load(par,function(){ par.expand();});  }
		 }  }); }  } );   }")
	->addtBarItem("{iconCls:'icon-add-folder',tooltip:'Add folder',handler: function(){ $treeWCprojects.addGroupHandler(); }}")	 
	->addContItem('Add folder',"function(item){ $treeWCprojects.addGroupHandler(item) }",'false','icon-add-folder')
	->addContSeparator()
	->addContItem('Rename',"function(item){ if(item)
			n = item.parentMenu.contextNode;
		else
			{
				n = $treeWCprojects.getSelectionModel().getSelectedNode();
				if(!n)
					return;
				
			}
			$treeWCprojects.treeEditor.triggerEdit(n);
			}",'false','RMicon_edit_record',2)
	 ->addContItem('Delete',"function(item){
	 	if(item)
			n = item.parentMenu.contextNode;
		else
			{
				n = $treeWCprojects.getSelectionModel().getSelectedNode();
				if(!n || !n.isLeaf())
					return;
				
			}
			var confirmText = RMrandomString();		
		Ext.Msg.prompt('Delete project '+n.text,
			'This will delete the project <b>'+n.text+'</b> and all it`s data!'+
			'<br>Enter following code and confirm<br>'+confirmText,function(btn,text){
				if(btn=='ok')
				{
					if(text == confirmText )
					{
					 $treeName.RMconn.request({ params: {action:'deleteProject',id:n.id,name:n.attributes.text},
					 success:function(resp,opt){ 
							if(Ext.decode(resp.responseText).success)
							{
								var bq = Ext.getCmp('buildQuestionnaire_'+n.text);
								if(bq) mainTabPanel.remove(bq);
								n.remove();
							}
					    } });     
			    }
				else return false;
		 }} );
	 }","node.attributes.isProject!=true",'icon-delete-record',2)
	  ->addContItem('Delete Folder',"function(item){
	 	var n = item.parentMenu.contextNode;
	 	Ext.Msg.show({ title:'Remove folder',buttons: Ext.MessageBox.YESNO,msg:'Are you sure?',
		fn: function(btn){if(btn == 'yes'){
		 $treeName.RMconn.request({ params: {action:'delete',nodeId:n.id,name:n.attributes.text},
		 success:function(resp,opt){ 
				if(Ext.decode(resp.responseText).success)
				{
					n.remove();
				}
		    } });     
		 }} });
	 }","node.attributes.isProject==true || node.hasChildNodes()",'icon-delete-folder')
	 //copy projects!!!
	   ->addContItem('Copy',"function(item){
	 	if(item)
			n = item.parentMenu.contextNode;
		else
		{
			n = $treeWCprojects.getSelectionModel().getSelectedNode();
			if(!n || !n.isLeaf())
				return;
			
		}
        
        var win = new Ext.Window(
        {
            width:350,
            height:210,
            modal: true,
            title: 'Copy project '+n.text,
            items: [
            {
                xtype: 'form',
                flex: 1,                
                bodyStyle: 'padding: 5px',
                id:'new_project_form',
                items: [
                {
                    xtype:'textfield',
                    anchor: '95%',
                    labelAlign: 'top',
                    id: 'new_project_text',
                    fieldLabel: 'New project  name'
                }, 
                {
                    xtype: 'checkbox',
                //    id: 'new_project_copy_styles',
                    fieldLabel:'Copy styles',
                    id: 'copy_styles'
                },
                {
                    xtype: 'checkbox',
               //     id: 'new_project_copy_plugin',
                    fieldLabel:'Copy plugin',
                    id: 'copy_plugin',
                    checked: true
                    
                },
                {
                    xtype: 'checkbox',
               //     id: 'new_project_copy_plugin',
                    fieldLabel:'Copy phone table',
                    id: 'copy_phone_table',
                }
                ]
            }
            ],
            buttons:[
                {
                    text: 'Copy',
                    handler: function()
                    {
                        var par;
                          //the group gets added after the clicked group (if a q is clicked its parent is used)
                          if(n.attributes.isProject == 1)
                          {
                              par = n.parentNode; 
                          } 
                          else
                          {
                              par = n;   
                          }
                                $treeName.RMconn.request({params:{
                              action:'copyProject',
                              data: Ext.encode(Ext.getCmp('new_project_form').getForm().getValues()),
                              nodeText:Ext.getCmp('new_project_text').getValue(),
                              nodeId:par.id,id_project:n.id,
                              isTargetQ:par.attributes.isQuestion 
                            },
                            success:function(resp)
                            {
                              
                              if(Ext.decode(resp.responseText).success)
                              {
                                  $treeName.getLoader().load(par,function()
                                  {
                                      par.expand();
                                  });
                                  
                                  win.close();
                              }
                              else 
                              {
                                Ext.Msg.alert('Error',Ext.decode(resp.responseText).error);      
                              } 
                            }  
                       });
                    }
                },
                {
                    text: 'Cancle',
                    handler: function()
                    {
                        win.close();
                    }
                }
                
            ]
        }).show();/*
	 	Ext.Msg.prompt('Copy project '+n.text,'New project name:',function(btn,text){
            if(btn == 'ok' )
	 	    {
		          var par;
		          //the group gets added after the clicked group (if a q is clicked its parent is used)
		          if(n.attributes.isProject == 1)
		          {
		              par = n.parentNode; 
                  } 
		          else
		          {
		              par = n;   
                  }
		          $treeName.RMconn.request({params:{
		              action:'copyProject',
		              nodeText:text,
		              nodeId:par.id,id_project:n.id,
		              isTargetQ:par.attributes.isQuestion 
                    },
                    success:function(resp)
                    {
		              if(Ext.decode(resp.responseText).success)
		              {
		                  $treeName.getLoader().load(par,function()
		                  {
		                      par.expand();
                          });  
                      }
		            }  
               }); 
            }  } ); */
	 }","node.attributes.isProject==false || node.id == 0",'RMicon_copy',2);
	 
	 //grid with old webcati projects (available only if specific config is set)
	 
	 $oldProjGrid = new MakeGrid();
	 $oldProjGrid->setMainTable('projects');
	 $oldProjGrid->addColumn('id','Id');
	 $oldProjGrid->addColumn('proj_name','Name');
	 $oldProjGrid->addColumn('naziv_proj','Description');
	 
	 $oldProjGrid->setPaging(50)
	 ->setSearchField()
	 ->setCheckBoxSelectionModel()
	 ->setAutoExpand('naziv_proj',100)
	 ->addConfig('closable','false')
	 ->setTitle('Old projects')
	 ->setReqUrl('webcati/_ajax/buildQuestionare/ajax.importOldProject.php')
	 ->addButton('Import',"function(){
	 	$oldProjGrid.RMconn.request({params:
	 		{
			action: 'importOld',
			projects: $oldProjGrid.getSelectedIds().join()
			},
	 	 success: function(resp){
	 	 	$treeWCprojects.getRootNode().reload();
	 	 	var r = Ext.decode(resp.responseText);
	 	 	if(r.success)
	 	 		Ext.Msg.alert('','Import successful');
	 	 	else 
	 	 		Ext.Msg.alert('Error','Some errors occured:<br>'+r.errors);
	 	 }
	 	 }
	 	 );
	 }");
	 $oldProjCrete= $oldProjGrid->createGrid();
	 
  if($_SESSION['UserRights'][15])
	 $treeWCprojects->addContItem('Import',"function(item){
	 
	 if(item)
			n = item.parentMenu.contextNode;
		else
			{
				n = $treeWCprojects.getSelectionModel().getSelectedNode();
				if(!n || !n.isLeaf())
					return;
				
			}
	 var par;
		//the group gets added after the clicked group (if a q is clicked its parent is used)
		if(n.attributes.isProject == 1)
			{par = n.parentNode; } 
		else{ par = n;   }
		
var fp = new Ext.FormPanel({
      
		enctype:'multipart/form-data',
        fileUpload: true,
        width: 285,
        frame: false,
       // autoHeight: true,
        title:'XML upload',
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 80,
        defaults: {
            anchor: '90%',
            allowBlank: false,
            msgTarget: 'side'
        },
        uploadSuccess: function(fp, o){
	                      var respStatus = Ext.decode(o.response.responseText);
	                      $treeName.getLoader().load(par,function(){ par.expand();});
	                      win1.close();
	                    },
	    uploadFailure: function(fp,o){
	    						if(o.response)
	                    			Ext.Msg.alert('Error!', Ext.decode(o.response.responseText).error);
	                    		//win1.close();
	                    	},
        items: [{
        	 xtype: 'fileuploadfield',
            id: 'form-file',
            emptyText: 'Select file',
            fieldLabel: 'File',
            name: 'csvfilepath',
            buttonText: '',
            buttonCfg: {
                iconCls: 'upload-icon'
            }
            
        },
        //extra options
        	{xtype:'textfield',
        	anchor:'90%',
        	fieldLabel: 'Name',
        	allowEmpty:false,
        	name:'nodeText'
        	
        	},
        	
        	//20150609 Tanis
            {
                xtype:'checkbox',
                id: 'manualCheckbox',
                anchor: '70%',
                fieldLabel: 'Set&nbspproject&nbspid manually',
                labelWidth: 150,
                listeners: {
                    check: function(btn, value)
                    {
                        var idField = Ext.getCmp('projectIDField');
                        if(value) idField.enable();
                        else {
                            idField.setValue('');
                            idField.disable();
                        }
                    }
                }
                
            },{
                xtype:'textfield',
                fieldLabel: 'Project ID',
                disabled: true,
                id: 'projectIDField',
                allowBlank: true
                
            }
            //20150609 Tanis END
    	],
        buttons: [{
            text: 'Import',
            handler: function(){
                //20150609 Tanis added check box for manual id entry
                var idField = Ext.getCmp('manualCheckbox');
                var projectIDField = Ext.getCmp('projectIDField');
                if(idField.getValue() == 1)
                {
                   new RMajax().request({
                            url:'webcati/_forms/_ajax/ajax.groups.php',
                            params:{
                                database: '".DB_WARPIT_WEBCATI_BASE."',
                                action:'checkId',
                                id_project: projectIDField.getValue(),
                            },
                            success: function(r )
                            {
                                var res = Ext.decode(r.responseText);
                                if(res.success)
                                {
                                    fp.getForm().submit({
                                        url: 'webcati/_forms/_ajax/ajax.groups.php',
                                        method : 'post',
                                        params:{
                                            action: 'importProject',
                                        
                                        nodeId:par.id,id_project:n.id,
                                        manualId: projectIDField.getValue(),
                                        RMtable: '_Projects'
                                    },
                                    waitMsg: 'Importing project...',
                                    success: fp.uploadSuccess,
                                        failure:fp.uploadFailure
                                });
                                }
                                else
                                {
                                    Ext.Msg.alert('Error',res.msg);   
                                }
                                /*
                                */
                                
                            }  
                   }  
                        ); 
                }
                else 
                {
                    fp.getForm().submit({
                        url: 'webcati/_forms/_ajax/ajax.groups.php',
                        method : 'post',
                        params:{
                            action: 'importProject',
                            
                        nodeId:par.id,id_project:n.id,
                        RMtable: '_Projects'
                        },
                        waitMsg: 'Importing project...',
                        success: fp.uploadSuccess,
                            failure:fp.uploadFailure
                    });
                }
                
                //20150609 Tanis END
	                
              
            }
        },{
            text: 'Reset',
            handler: function(){
                fp.getForm().reset();
            }
        }]
    });
	//a grid that will load old projects

	$oldProjCrete
	
	var win1 = new Ext.Window({
        modal:true,
        //layout:'tabpanel',
 		title: 'Import project',
        width:450,
       
        closeAction:'close',
        plain: true,
		items: { xtype:'tabpanel', height:230,activeTab:0,
		listeners:{
			beforetabchange:function(tp,newP)
			{
				if(newP.id == $oldProjGrid.id)
				{
					this.setHeight(300);
					//win1.setWidth(450);
				}
				else 
					this.setHeight(200);
					//win1.setWidth(300);
			}
		}
        ,items:  [fp,$oldProjGrid] }

    }).show();

    
	 
	 
	 }",'false','icon_import_database')
	 ->addContSeparator()
	 ->addContItem('Print',"function(item){ 
			n = item.parentMenu.contextNode;
			CallScript('webcati/_forms/buildQuestionare/forms.printQuestion.php',{projectId:n.id,tableName:n.text} );
			}
			",'!node.isLeaf()','RMicon_printer')
	  ->setEditable("{vtype:'fieldName'}") ;
	  $treeWCprojects->addtBarItem("'->'")
	  ->setSearchField('','top',100)
	 // ->addtBarItem("{text:'Expand All',handler:function(){WCprojects.expandAll();}} ")
	  ->addConfig('region',"'center'")
	 ;
	 
	$treeWCprojects->activateDD('wupGrouplink');
	 
	echo $treeWC->CreateTree();
	
	echo "$treeWC.on('afterrender',function(){
		$treeWC.dropZone.onNodeOver = function(n, dd, e, data){
			if(dd.tree)
			{
				//return this.onNodeOverOrig(n,dd,e,data);
				if(( n.node.id.substring(0,6) == 'design' && dd.dragData.node. id.substring(0,6) == 'design' ) || (n.node.id.substring(0,9) == 'interview' && dd.dragData.node. id.substring(0,9) == 'interview') || (n.node.id.substring(0,10) == 'userDefine' && dd.dragData.node. id.substring(0,10) == 'userDefine') || ( n.node.id.substring(0,4) == 'mask' && dd.dragData.node. id.substring(0,4) == 'mask' ))
					return Ext.tree.TreeDropZone.prototype.onNodeOver.call(this,n,dd,e,data);
			}
			else if( (dd.dragData.caGrid && dd.dragData.isWebcati) || (dd.dragData.grid && dd.dragData.grid.isWebcati ) )
			{
				return (n.node.isLeaf() &&  n.node.id.substring(0,9) == 'interview') ? 'x-tree-drop-ok-append' : this.dropNotAllowed;
			}
			return this.dropNotAllowed;
    	}
    	$treeWC.dropZone.notifyDrop = function(dd, e, data){
	    	var n = this.getTargetFromEvent(e);
	    	if(!n) return false;
			if(dd.tree)
			{ 
				//return this.onNodeOverOrig(n,dd,e,data);
				if(( n.node.id.substring(0,6) == 'design' && dd.dragData.node. id.substring(0,6) == 'design' ) || (n.node.id.substring(0,9) == 'interview' && dd.dragData.node. id.substring(0,9) == 'interview') || (n.node.id.substring(0,10) == 'userDefine' && dd.dragData.node. id.substring(0,10) == 'userDefine') || ( n.node.id.substring(0,4) == 'mask' && dd.dragData.node. id.substring(0,4) == 'mask' ))
									
					return Ext.tree.TreeDropZone.prototype.notifyDrop.call(this,dd, e, data);
			}
			else 
			{  
				if(!n || n.node.id.substring(0,9) != 'interview' || !n.node.isLeaf()) return false;
				if(dd.dragData.grid && dd.dragData.grid.isWebcati )
					{
						var arr = new Array();
						for(var i=0;i<dd.dragData.selections.length;i++)
						{
							arr.push( dd.dragData.selections[i].data.id); 
						}
						
						new RMajax().request({
							url:'webuserspool/_ajax/ajax.showgroup.php',
							params:{database: '".DB_WARPIT_WEBCATI_BASE."',
							action:'gridDrop',sel:Ext.encode(arr),toGroup:n.node.id.substring(10),isWebcati: dd.dragData.grid.isWebcati  },
							success: function(r ){alert( Ext.decode( r.responseText).msg  ); }  }  
						);
						
					}
					else if(dd.dragData.caGrid && dd.dragData.isWebcati )
					{
						var sr = dd.dragData.caGrid.getStore();
						sr.reload({params:{addOn:'copy',toGroup:n.node.id.substring(10) }
						,callback:function(r,opt,s){ if(s) Ext.Msg.alert('Success','Copy succesful');
						 }
						});
						return true;
					}
				return true;
			}
	    }
    
	});";
	
	// webcati_tree as first parameter in addTab function (extended addTab function from ExtJS), is meant for title of the tab
	// in this case where click on each node transfer different text, this text is used for title
	// and first argument is not used at all 
	$treeProjName = $treeWCprojects->getName();
	$noprojSelMSG = "Ext.Msg.alert('Warning!','Please select project(s)!');";
	echo $_POST['treeName'].".on('click',function(node) {
	var url;
	//we changed it that only checked projects count as selected!
	var nodeProj = null;
	var checkedProj = $treeProjName.getChecked();
	var menuNodeID = node.attributes.id;
	var menuNodeIDorig = node.attributes.id;
	if (menuNodeID.substring(0,10) == 'userDefine') {
		var userDefineNodeID = menuNodeID.substring(11);
		menuNodeID = 'userDefine';
	}
	
	switch(menuNodeID)
	{	
		case 'userDefine':
			var selectedMenuNode = $treeWC.getSelectionModel().getSelectedNode();
			if (menuNodeIDorig == selectedMenuNode) {
				
			} else if(!node.isLeaf()) {
				node.toggle();
			}

			break;
			
		//temporarly makesample to show appointmets
		case '3':
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_appointmentManager' , 'webcati/_forms/telNumberManagment/forms.appointmentMan.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project} ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_appointmentManager' , 'webcati/_forms/telNumberManagment/forms.appointmentMan.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		break;
		
		//basic statistics
		case '7' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/statistics/forms.statistics.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'statistic_'+item.text , 'webcati/_forms/statistics/forms.statistics.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('statistic_'+ nodeProj.text,'webcati/_forms/statistics/forms.statistics.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
		break;
	
		//build questionnaire
		case '32' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'buildQuestionnaire_'+item.text , 'webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('buildQuestionnaire_'+ nodeProj.text,'webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		
		//temporarly questionRotation
		case '20' : 
				
				var url = 'webcati/_forms/buildQuestionare/forms.questionRotation.php'
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript(url,{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'questionRotation_'+item.text ,url,{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('questionRotation_'+ nodeProj.text,url,{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		
		//telephone managment
		case '16':
				addTabAuto('telNumberManagment','webcati/_forms/telNumberManagment/forms.telNumberManagment.php',{}); 
				
		break; 
		case '46':
				if(checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ 'telNumberSampler'+item.text , 'webcati/_forms/sampler/forms.sampler.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				
				}	
				else { $noprojSelMSG; }	
				
		break; 
		case '18':
				if(checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ 'capiFieldSampler'+item.text , 'webcati/_forms/capiManagment/forms.capiSampler.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				
				}	
				else { $noprojSelMSG; }	
				
		break; 
		//live update
		case '57':
					addTabAuto('liveUpdate','webcati/_forms/liveUpdate/forms.liveUpdateServer.php',{}); 
				
		break; 
		case '58':
					addTabAuto('liveUpdate','webcati/_forms/liveUpdate/forms.liveUpdate.php',{}); 
				
		break; 
		
		case '22': //project properties
			
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'questionnaireProperties_'+item.text , 'webcati/_forms/buildQuestionare/forms.questionnaireProperties.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('questionnaireProperties_'+ nodeProj.text,'webcati/_forms/buildQuestionare/forms.questionnaireProperties.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
		break;
		//export DATA
		case '44' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'extImportData_'+item.text , 'webcati/_forms/ExImportData/forms.ExImportData.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('extImportData_'+ nodeProj.text,'webcati/_forms/ExImportData/forms.ExImportData.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		//export SCRIPTS
		case '45' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'exportScripts_'+item.text , 'webcati/_forms/ExImportData/forms.ExImportData.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project,scriptExport:true } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('extImportData_'+ nodeProj.text,'webcati/_forms/ExImportData/forms.ExImportData.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		//Quotas
		case '5' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ item.text+'_quotas_unique_panel' , 'webcati/_forms/forms.quotas.php',{proj_name: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_quotas_unique_panel','webcati/_forms/forms.quotas.php',{proj_name: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '25' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ item.text+'_telStatistics' , 'webcati/_forms/telNumberManagment/forms.telStatistics.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_telStatistics' , 'webcati/_forms/telNumberManagment/forms.telStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '26' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ item.text+'_quotaStatistics' , 'webcati/_forms/quotas/forms.quotaStatistics.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_quotaStatistics' , 'webcati/_forms/quotas/forms.quotaStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '27' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ item.text+'_interviewerStatistics' , 'webcati/_forms/telNumberManagment/forms.interviewerStatistics.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_interviewerStatistics' , 'webcati/_forms/telNumberManagment/forms.interviewerStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
				
		case '48' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ item.text+'_timeStatistics' , 'webcati/_forms/statistics/forms.timeStatistics.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_timeStatistics' , 'webcati/_forms/telNumberManagment/forms.timeStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '49' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_sampleStatistics' , 'webcati/_forms/telNumberManagment/forms.sampleStatistics.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_sampleStatistics' , 'webcati/_forms/telNumberManagment/forms.sampleStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '50' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_telNumbersLog' , 'webcati/_forms/telNumberManagment/forms.telNumbersLog.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_telNumbersLog' , 'webcati/_forms/telNumberManagment/forms.telNumbersLog.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '51' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_manageSamples' , 'webcati/_forms/sampler/forms.manageSamples.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_manageSamples' , 'webcati/_forms/sampler/forms.manageSamples.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
				
				break;
		case '59' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_capiUserOverview' , 'webcati/_forms/liveUpdate/forms.overview.php',{projName: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_capiUserOverview' , 'webcati/_forms/liveUpdate/forms.overview.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { 
				
					addTabAuto('Monitor_capiUserOverview' , 'webcati/_forms/liveUpdate/forms.overview.php',{ id_project:0, id_node: 0});
				
				}
				
				break;
		case '61' : 
				
				if (checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ item.text+'_questionStatistics' , 'webcati/_forms/statistics/forms.questionStatistics.php',{prvik:\"prvi\", projName: item.text, id_node: item.id, id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto(nodeProj.text+'_questionStatistics' , 'webcati/_forms/statistics/forms.questionStatistics.php',{projName: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
                
				}
				else { $noprojSelMSG; }
				
				break;    
		case '67' : 

					    var storeParameters = new Ext.data.Store({
						    proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.dinamicTableStatistics.php?action=fillRow'}),
						    reader: new Ext.data.JsonReader({
							    root:'rows'},
							    [{name:'Id'},{name:'Name'}])
					    });	
					    
					       var storeColumnParameters = new Ext.data.Store({
						    proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.dinamicTableStatistics.php?action=fillColumn'}),
						    reader: new Ext.data.JsonReader({
							    root:'rows'},
							    [{name:'Id'},{name:'Name'}])
					    });			    

					    var selectRow = new Ext.form.ComboBox({  
						    fieldLabel:'Row',  
						    id:'selectRow',  
						    forceSelection: true,  
						    store: storeParameters,  
						    emptyText:'Select parameter ...',  
						    triggerAction: 'all',  
						    editable:false,  
						    displayField:'Name',  
					        valueField:'Name',
							width:220,
							mode:'local'
						});  
						
						   var selectColumn = new Ext.form.ComboBox({  
						    fieldLabel:'Column',  
						    id:'selectColumn',  
						    forceSelection: true,  
						    store: storeColumnParameters,  
						    emptyText:'Select parameter ...',  
						    triggerAction: 'all',  
						    editable:false,  
						    displayField:'Name',  
					        valueField:'Name',
							width:220,
							mode:'local'
						});  
						
						var textLabel = new Ext.form.Label({  
							name: 'label_name',
                  			id: 'label_id',
                   			text: 'Select column and row properties!', 
						});  
						textLabel.setVisible(false);	

						 var myCheckboxGroup=null;

				    var StatPanel = new Ext.FormPanel({
				        bodyStyle:'padding:15px 15px 0',
				        width: 370,
				        items: [selectRow,selectColumn,textLabel ],
				        buttons: [
				        	{
				            text: 'OK'
				            ,handler:function(){
				            
				            var ele = myCheckboxGroup.getValue();
				            var gridParam='';
				            for (var i=0; i<ele.length;i++)
				            {
				            	gridParam+=ele[i].boxLabel+',';
							}
				            
				            
												if (selectColumn.getValue()=='')
														{
															textLabel.setVisible(true);
														}
												else
													{		
														addTabAuto( 'DynamicTableStatistics' , 'webcati/_forms/statistics/forms.dinamicTableStatistics.php',{ row:selectRow.getValue(), column:selectColumn.getValue(), gridOptions:gridParam });
														StatisticWin.close();
													}
											CallMultiScripts(tmpArr);  
												
				        		}
				        	},{
						        text: 'Cancel'
					    	    ,handler:function(){
					        	   	StatisticWin.close();
					            }
					   		}
					   	]
				    });
				    
					var 	StatisticWin =	new Ext.Window({
							title: 'Dinamic Table Positioning',
							height: 220,
							width: 400,
							layout: 'fit',
							modal: true,
							closeAction:'close',
        					plain: true,
							items: StatPanel
							});		

							//napolni drugi select
							selectRow.store.load();		
								selectRow.on('select', function(o) {
									storeColumnParameters.removeAll();
									storeColumnParameters.proxy= new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.dinamicTableStatistics.php?action=fillColumn&element='+selectRow.getValue()});
									storeColumnParameters.load();
									
									selectColumn.reset();
									StatPanel.remove('checkboxGrid',true);
									StatPanel.doLayout();
							    });
							    
							  selectColumn.on('select', function(o) {
									StatPanel.remove('checkboxGrid',true);
									StatPanel.doLayout();
									
									Ext.Ajax.request({
									    		url: 'webcati/_forms/_ajax/ajax.dinamicTableStatistics.php?action=comboBox&row='+selectRow.getValue()+'&column='+selectColumn.getValue(),
									       		async: false,
									       		success: function(res,opt) {
									       		
									 				 var result= Ext.decode(res.responseText).rows;	
													 myCheckboxGroup = new Ext.form.CheckboxGroup({
														        fieldLabel: 'Grid options',
														        id:'checkboxGrid',
														        columns: 1,
														       	displayField:'Name',
														       	allowBlank: true,
														       items:     [
																	            { boxLabel: result[0].Name, name: 'rb', inputValue: '1',id:1 },
																	            { boxLabel: result[1].Name, name: 'rb', inputValue: '2',id:2 },
								       										 ]
														    });     
													StatPanel.add(myCheckboxGroup);
													StatPanel.doLayout();								         		
									       		}
									       	});
									textLabel.setVisible(false);
							    });
							StatisticWin.show();
				break; 			
					
		case '28':
			addTabAuto('multiLanguageSettings' , 'webcati/_forms/buildQuestionare/forms.multiLanguage.php',{}); 
				
		break;
		case '30':
			var checkedIds = $treeWCprojects.getChecked('id_project');
            var names = $treeWCprojects.getChecked('text');
			addTabAuto('webPointsManager' + checkedIds.join('_'),'webcati/_forms/webPoints/forms.webPoints.php',{proj_ids: checkedIds.join(), name: names.join() });
		break;
		//show users that are working on this projects
		case '31' : 
				
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						//tmpArr.push([ 'buildQuestionnaire_'+item.text , 'webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
						tmpArr.push([ 'wupProjectUsers_'+item.id,'webuserspool/_forms/forms.projectUsers.php',{id: item.id,name:item.text}]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					//addTabAuto('buildQuestionnaire_'+ nodeProj.text,'webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project});
					addTabAuto('wupProjectUsers_'+nodeProj.id,'webuserspool/_forms/forms.projectUsers.php',{id: nodeProj.id,name:nodeProj.text}); 
				}
				else { $noprojSelMSG; }
				
		break;
        case '85' : 
        
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    tmpArr.push([ 'wupProjectUsers_'+item.id,'/webcati/_forms/webLinkStatistic/forms.webLinkStatistic.php',{id: item.id,name:item.text}]);
                });
                CallMultiScripts(tmpArr);
            }
            else if(nodeProj && nodeProj.isLeaf() )
            {
                addTabAuto('wupProjectUsers_'+nodeProj.id,'/webcati/_forms/webLinkStatistic/forms.webLinkStatistic.php',{id: nodeProj.id,name:nodeProj.text}); 
            }
            else { $noprojSelMSG; }
                    
        break;
		/*case '33' :
			addTabAuto('catiShowGroup_'+node.id,'webuserspool/_forms/forms.showgroup.php',{group_id:0,name:node.text,userGroup:'webcati'});
			
			
		break; */
		case '36' :
			var projs;
			if (checkedProj.length > 0){
				var tmpArr = [];
				Ext.each(checkedProj,function(item)
				{
					
					tmpArr.push( item.id  );
				});
				projs = tmpArr.join();
			}
			else 
			if(nodeProj && nodeProj.isLeaf() ){
				projs = nodeProj.id;
			}
			else{ 
				$noprojSelMSG; 
				break; 
			}
				
			addTabAuto('permissionProjUsers_'+ node.id   ,'_forms/Permissions/forms.projectUsers.php',{id:projs,name:'neki test' }); 
	
		break; 
		case '37' :
			addTabAuto('catiShowGroup_'+node.id,'webuserspool/_forms/forms.showgroup.php',{group_id: 0,name:'All',userGroup:'webcati'});
		break;
		case '42':
			
			//recreate data structure
			if (checkedProj.length > 0)
				{
				var tmpArr = [];
				var nameArr = [];
					Ext.each(checkedProj,function(item)
					{
						nameArr.push( item.text);	
						tmpArr.push( item.id  );
					});
			var confirmText = RMrandomString();		
			Ext.Msg.prompt('Recreate data structure',
			'This will delete data for projects: '+nameArr.join(', ')+
			'<br>Enter following code and confirm<br>'+confirmText,function(btn,text){
				if(btn=='ok')
					if( text == confirmText)
						new RMajax().request({
						url: 'webcati/_ajax/buildQuestionare/ajax.buildQuestionnaire.php',
						params:{action:'createStructure',
						id_project: tmpArr.join(),deleteConfirm:true
						},success:function(rsp){
							var r = Ext.decode(rsp.responseText);
							if(r.success) Ext.Msg.alert('Success','Structure successfuly created!');
							else {  
									}
								}	});
						else 
							Ext.Msg.alert('Error','Wrong code!');
						});
			}
			else { $noprojSelMSG; break; }
			
		break; 
			
		case '17':
			addTabAuto('userSampling','webuserspool/_forms/sampling/forms.userSampling.php' );
			addTabAuto('webUserspoolUniqePanel','webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'});
		            	
		break;
		 
		case '43':
				if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'wbcq_scripts_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.scripts.php',{ id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else if(nodeProj && nodeProj.isLeaf() )
				{
					addTabAuto('wbcq_scripts_'+ item.attributes.id_project ,'webcati/_forms/buildQuestionare/forms.scripts.php',{project: nodeProj.text, id_node: nodeProj.id,id_project:nodeProj.attributes.id_project}); 
				}
				else { $noprojSelMSG; }
		break; 
		case '54':
			 if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'wbcq_mysteryShopping_'+item.attributes.id_project , 'webcati/_forms/mysteryShopping/forms.mysteryShopping.php',{ id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break; 
		case '53':
			 if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{ id_project:item.attributes.id_project });
						tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.testQuestionnaire.php',{ id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break; 
		case '55':
			 if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'wbcq_mysteryPrint_'+item.attributes.id_project , 'webcati/_forms/mysteryShopping/forms.printConfirmed.php',{ id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break; 
		case '56':
			 if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//CallScript('webcati/_forms/buildQuestionare/forms.buildQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
						tmpArr.push([ 'wbcq_mysteryStatistic_'+item.attributes.id_project , 'webcati/_forms/mysteryShopping/forms.statisticConfirmed.php',{ id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break; 
		//telephone managment
		case '60':
				addTabAuto('telNumberManagment_CAPI','webcati/_forms/capiManagment/forms.capiAdressManagment.php',{capi:true}); 
				
		break; 
		
		case '58':
				if(checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ 'capiSampler'+item.text , 'webcati/_forms/sampler/forms.sampler.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project,capi:true } ]);
					});
					CallMultiScripts(tmpArr);
				
				}	
				else { $noprojSelMSG; }	
				
		break; 
		case '64':
				if(checkedProj.length > 0)
				{
					var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ 'manageSamples_'+item.id , 'webcati/_forms/capiManagment/forms.manageCapiSamples.php',{projName: item.text, id_project:item.id } ]);
					});
					CallMultiScripts(tmpArr);
				
				}	
				else { $noprojSelMSG; }	
				
		break; 
		
		case '69' :
			addTabAuto('userDefineModules_'+ node.id,'webcati/_forms/userDefine/forms.userDefine.php',{}); 
		break;
		case '84' :
			if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						tmpArr.push([ 'localdataentry'+item.attributes.id_project , 'webcati/_forms/ExImportData/forms.localdataentry.php',{projName: item.text, id_proj: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break;
		
		/* Call Center -> Statistics -> Calls */
		case '73' : 				
			var tmpArr = [];									
			//CallScript('webcati/_forms/forms.quotas.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });
			tmpArr.push(['Statistics_callStatistics' , 'call_center/_forms/statistics/callStatistics/forms.callStatistics.php',{} ]);				
			CallMultiScripts(tmpArr);	
		break;
		
		/* Call Center -> Statistics -> Agents */
		case '81' : 
			if (checkedProj.length > 0)
			{
				var tmpArr = [];
				var projs = [];
				//var proj = {id:0,name:''};
				var proj = [];
				Ext.each(checkedProj,function(item)
				{
					//CallScript('call_center/_forms/statistics/forms.agents.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });					
					//proj.id = item.attributes.id_project;
					//proj.name = item.text;
					proj[0] = item.attributes.id_project;
					proj[1] = item.text;
					projs.push(proj);
					proj = [];
					//proj = {id:0,name:''};
				});
				
				var jsonencoded = Ext.util.JSON.encode(projs);					
				tmpArr.push(['_agentStatistics' , 'call_center/_forms/statistics/forms.agents.php',{projects:jsonencoded}]);
				CallMultiScripts(tmpArr);				
			}
			else if(nodeProj && nodeProj.isLeaf() )
			{				
				addTabAuto('_agentStatistics' , 'call_center/_forms/statistics/forms.agents.php',{projects:Ext.encode(nodeProj.attributes.id_project)}); 
			}
			else { $noprojSelMSG; }
		break;
		
		/* Call Center -> Statistics -> Inbound calls -> Call list - Live */
		case '82' : 
			
				var tmpArr = [];
				var projs = [];
				//var proj = {id:0,name:''};
				var proj = [];
				Ext.each(checkedProj,function(item)
				{
					//CallScript('call_center/_forms/statistics/forms.callList.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project });					
					//proj.id = item.attributes.id_project;
					//proj.name = item.text;
					proj[0] = item.attributes.id_project;
					proj[1] = item.text;
					projs.push(proj);
					proj = [];
					//proj = {id:0,name:''};
				});
				
				var jsonencoded = Ext.util.JSON.encode(projs);					
				tmpArr.push(['_callListInbound' , 'call_center/_forms/statistics/forms.callList.php',{projects:jsonencoded}]);
				CallMultiScripts(tmpArr);				
			
		break;
		
		case '83':
			 if (checkedProj.length > 0)
				{
				var tmpArr = [];
					Ext.each(checkedProj,function(item)
					{
						//tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
						tmpArr.push([ 'wbcq_randomFillQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/randomDataFill/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
					});
					CallMultiScripts(tmpArr);
				}
				else 
				{
				  $noprojSelMSG;
				}
		break; 
        
        case '87':
             if (checkedProj.length > 0)
                {
                var tmpArr = [];
                    Ext.each(checkedProj,function(item)
                    {
                        //tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
                        tmpArr.push([ 'wbcq_randomFillQuestionnaireReport_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/randomDataFill/forms.randomDataFillReport.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
                    });
                    CallMultiScripts(tmpArr);
                }
                else 
                {
                  $noprojSelMSG;
                }
        break;
        
        case '89':
        {
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    //tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
                    tmpArr.push([item.text+'_panel','webcati/_forms/forms.webrecode.php',{id_project:item.attributes.id_project, proj_name:item.text}]);
                    
                });
                CallMultiScripts(tmpArr);
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
        
        case '94':
        {
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    new RMajax().request({
                        url: 'webrecode/_ajax/ajax.autoRecode.php',
                        params:{
                            id_project: item.id
                        }
                    
                    }); 
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
        
        case '95':
        {
            if(checkedProj.length == 1)
            {
                Ext.Msg.confirm('Delete recode for '+checkedProj[0].text,'Are you sure?',function(btn){
                    if(btn == 'yes')
                        new RMajax().request({
                            url: 'webrecode/_ajax/ajax.autoRecode.php',
                            params:{
                                id_project: checkedProj[0].id,
                                resetRecode:true
                            }
                        });
                  });
            }
            else if(checkedProj.length > 1)
            {
                Ext.Msg.confirm('Delete multiple recodes','Are you sure?',function(btn){
                    if(btn == 'yes')
                    {
                        Ext.each(checkedProj, function(item)
                        {
                            new RMajax().request({
                            url: 'webrecode/_ajax/ajax.autoRecode.php',
                            params:{
                                id_project: item.id,
                                resetRecode:true
                            }
                            });
                        });
                    }
                        
                  });
            }
            else 
            {
                $noprojSelMSG;    
            }       
            break;    
        }
        case '96':
        {
            if (checkedProj.length > 0)
            {
                Ext.each(checkedProj,function(item)
                {
                    mainTabPanel.add( 
                        new Ext.Panel({
                            title: 'Export - Labels by category [' + item.text + ']', 
                            closable: true, 
                            id: 'Recode_tab_docs_catlab',
                            items: new Ext.ux.IFrameComponent({                             
                                        width: '100%',
                                        height: '100%',
                                        id: 'Export_docs_catlab', 
                                        url: 'webcati/_forms/forms.webrecode.export.php?documents_mode=1&id_project='+item.attributes.id_project+'&proj_name='+item.text,
                                    })
                        })
                    ).show();
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;    
        }
        case '97':
        {
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    mainTabPanel.add( 
                        new Ext.Panel({
                            title: 'Export - categories [' + item.text + ']', 
                            closable: true, 
                            id: 'Recode_tab_docs_categories',
                            items: new Ext.ux.IFrameComponent({                             
                                        width: '100%',
                                        height: '100%',
                                        id: 'Export_docs_categories', 
                                        url: 'webcati/_forms/forms.webrecode.export.php?id_project='+item.attributes.id_project+'&proj_name='+item.text,
                                    })
                        })
                    ).show();
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;    
        }
        case '98':
        {
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    //tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
                    tmpArr.push(['stats_'+item.text+'_0','webcati/_forms/forms.webrecode.statistics.php',{statistics_mode:0, id_project:item.attributes.id_project, proj_name:item.text}]);
                    
                });
                CallMultiScripts(tmpArr);
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
		
        case '99':
        {
            if (checkedProj.length > 0)
            {
                var tmpArr = [];
                Ext.each(checkedProj,function(item)
                {
                    //tmpArr.push([ 'wbcq_testQuestionnaire_'+item.attributes.id_project , 'webcati/_forms/buildQuestionare/forms.fillQuestionnaire.php',{project: item.text, id_node: item.id,id_project:item.attributes.id_project } ]);
                    tmpArr.push(['stats_'+item.text+'_1','webcati/_forms/forms.webrecode.statistics.php',{statistics_mode:1, id_project:item.attributes.id_project, proj_name:item.text}]);
                    
                });
                CallMultiScripts(tmpArr);
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
        case '100':
        {
            if (checkedProj.length > 0)
            {
                Ext.each(checkedProj,function(item)
                {
                    mainTabPanel.add( 
                        new Ext.Panel({
                            title: 'Documents - categories [' + item.text +']' , 
                            closable: true, 
                            id: 'Recode_tab_docs_categories' + item.attributes.id_project,
                            items: new Ext.ux.IFrameComponent({                             
                                        width: '100%',
                                        height: '100%',
                                        id: 'Recode_docs_categories' + item.attributes.id_project, 
                                        url: 'webcati/_forms/forms.webrecode.documents.php?id_project='+item.attributes.id_project+'&proj_name='+item.text,
                                    })
                        })
                    ).show();
                    
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
        case '101':
        {
            if (checkedProj.length > 0)
            {
                Ext.each(checkedProj,function(item)
                {
                    mainTabPanel.add( 
                        new Ext.Panel({
                            title: 'Documents - Labels by category [' + item.text + ']', 
                            closable: true, 
                            id: 'Recode_tab_docs_catlab' + item.attributes.id_project,
                            items: new Ext.ux.IFrameComponent({                             
                                        width: '100%',
                                        height: '100%',
                                        id: 'Recode_docs_catlab' + item.attributes.id_project, 
                                        url: 'webcati/_forms/forms.webrecode.documents.php?documents_mode=1&id_project='+item.attributes.id_project+'&proj_name='+item.text,
                                    })
                        })
                    ).show();
                    
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }

        case '102':
        {
            if (checkedProj.length > 0)
            {
                Ext.each(checkedProj,function(item)
                {
                    addTabAuto('catiShowGroup_'+ item.attributes.id_project,'capi_manager_common/_forms/assign_sample_point/forms.main_interviewers_samplepoints.php',{
                        group_id:0,
                        project_id:item.attributes.id_project,
                        project_text:item.text,
                        name:'All',
                        userGroup:'webcati'
                    });
                });
            }
            else 
            {
              $noprojSelMSG;
            }
            break;
        }
        
		default:
			//Ext.Msg.alert('Warning!','This feature is not supported yet!');
			//alert(node.attributes.id +' is not defined yet!!!');
			//we open the node if possible
			if(!node.isLeaf())
				node.toggle();
			break;
	}
	 });
	 $treeWC.on('dblclick',function(node){
	 	//we click on one of the design templates!!!
	 	var checkedProj = $treeProjName.getChecked();
		if(node.attributes.id.substring(0,6) == 'design' && node.isLeaf())
			{
				var designId = node.attributes.id.substring(7)
				addTabAuto('webDesignUniqeWindow_'+ designId,'webcati/_forms/designerPanel/forms.questionnaireDesignerPanel.php',
				{id:designId,name:node.text });
				var csPanel = Ext.getCmp('webDesignCssPanel')
				if(!csPanel)
					addTabAuto('webDesignCssPanel','webcati/_forms/designerPanel/forms.cssPanel.php',{});
				
			}
	 	else if(node.attributes.id.substring(0,9) == 'interview')
			{
				var designId = node.attributes.id.substring(10)
				addTabAuto('catiShowGroup_'+node.id,'webuserspool/_forms/forms.showgroup.php',{group_id:designId,name:node.text,userGroup:'webcati'});	
			}
	 	else if(node.attributes.id.substring(0,10) == 'userDefine')
			{
				var designId = node.attributes.id.substring(11);
				
				Ext.Ajax.request({
				   url: 'webcati/_ajax/userDefine/ajax.userDefine.php',
				   params: {action:'getModulesProperty',nodeId:designId,database:'".DB_WARPIT_WEBCATI_BASE."'},
				   success: function(response, opts) {
				      var dataUserDefine = Ext.decode(response.responseText);
				      if (dataUserDefine.module_type == 1) {
				      
				      
				      if (checkedProj.length > 0)
						{
							var tmpArr = [];
							Ext.each(checkedProj,function(item)
								{
									tmpArr.push([ 'userDefineModules_' + node.id + '_' + item.attributes.id_project , 'webcati/_forms/userDefine/forms.userDefineModules.php',{file_name:dataUserDefine.file_name, project: item.text, id_project:item.attributes.id_project } ]);
								});
							CallMultiScripts(tmpArr);
						}
						else 
						{
						      		addTabAuto('userDefineModules_'+node.id,'webcati/_forms/userDefine/forms.userDefineModules.php',{file_name:dataUserDefine.file_name});
						}
				      
				      
				      
				       } else {
			             	mainTabPanel.add(new Ext.ux.IFrameComponent({ 
								             	closable: true, 
								             	iconCls:'RMicon_userDefine',
								             	title: 'User define modules', 
								             	id: 'userDefineModules_'+node.id, 
								             	url: 'webcati/_forms/userDefine/forms.userDefineModules.php?file_name='+dataUserDefine.file_name+'&type=2' 
								             })
				            ).show(); 
				      }
				   },
				   failure: function(response, opts) {
				      console.log('server-side failure with status code ' + response.status);
				   }
				});

			}
		else if(node.attributes.id.substring(0,4) == 'mask' && node.isLeaf())
			{
				var maskId = node.attributes.id.substring(5)
				addTabAuto('webMaskUniqeWindow_'+ maskId,'webcati/_forms/maskPanel/forms.questionnaireMaskPanel.php',
				{id:maskId,name:node.text });
				var csPanel = Ext.getCmp('webMaskCssPanel')
				if(!csPanel)
					addTabAuto('webMaskCssPanel','webcati/_forms/maskPanel/forms.cssPanel.php',{});
				
			}
	 });
	 ";

	echo $treeWCprojects->CreateTree();
	
	echo "$treeWCprojects.on('afterrender',function(){
		$treeWCprojects.dropZone.onNodeOver = function(n, dd, e, data){
      
		if(dd.tree && dd.tree.id == '$treeWCprojects')
		{
			//return this.onNodeOverOrig(n,dd,e,data);
			return Ext.tree.TreeDropZone.prototype.onNodeOver.call(this,n,dd,e,data);
		}
		else if( dd.dragData.node && dd.dragData.node.id.substring(0,9) == 'interview' )
		{
					
			return ( n.node.isLeaf() ) ? 'x-tree-drop-ok-append' : this.dropNotAllowed;
		}
		else if( (dd.dragData.grid && dd.dragData.grid.isWebcati ) )
			{
						
				return (n.node.isLeaf() ) ? 'x-tree-drop-ok-append' : this.dropNotAllowed;
			}	
		return this.dropNotAllowed;
    }
    $treeWCprojects.dropZone.notifyDrop = function(dd, e, data){
    	var n = this.getTargetFromEvent(e);
    	if(!n) return false;
		if(dd.tree && dd.tree.id == '$treeWCprojects')
		{ 
			return Ext.tree.TreeDropZone.prototype.notifyDrop.call(this,dd, e, data);
		}
		else if( dd.dragData.node && dd.dragData.node.id.substring(0,9) == 'interview' )
		{  
			if(!n || !n.node.isLeaf()) return false;
			
			new RMajax().request({
				url:'webcati/_ajax/generateWwwIds/ajax.generateWwwIds.php',
				params:{
				defineCatiGroup: dd.dragData.node.id.substring(10),
				id_project: n.node.id
				  },
				success: function(r ){Ext.Msg.alert('Success' , Ext.decode( r.responseText).msg  ); }  }  
			);
			
				
			return true;
		}
		else if(dd.dragData.grid && dd.dragData.grid.isWebcati )
				{
					var arr = new Array();
					for(var i=0;i<dd.dragData.selections.length;i++)
					{
						arr.push( dd.dragData.selections[i].data.id); 
					}
					
					new RMajax().request({
						url:'webcati/_ajax/generateWwwIds/ajax.generateWwwIds.php',
						params:{
						defineCatiUser:arr.join() , id_project: n.node.id ,isWebcati: dd.dragData.grid.isWebcati  },
						success: function(r ){alert( Ext.decode( r.responseText).msg  ); }  }  
					);
					
				}
    }
    
	});";
	
//	echo $treeProjName.".getRootNode().expand();";
		
// we add JS code to define a new panel which has two trees combined in one tab
//this tab we dan add to the western tabpanel with id = 'west-panel'	
?>
	var webCatiUniqePanel = new Ext.Panel({
		id:'webCatiUniqePanel',
		title:'Project manager',
		defaults:{split:true,border:false},
		iconCls:'icon-webcati-tab',
		layout:'border',
		border: false,
		closable:true,
		items:[<?php echo $treeWC->getName().','.$treeWCprojects->getName();   ?>  ]
		
				
	});
	Ext.getCmp('west-panel').add( webCatiUniqePanel)
	<?php 
	if(true || !$_POST['uniqueNotShow'])
		echo  ".show();";
	?>
