<?php
	if (!$UserSession or !$UserSession->IsLoggedIn()) { echo "attack!"; exit; } 
	unset($_SESSION['loadedPlugin']);
	unset($_SESSION['addedTabs']);
?>
<html>
<head>
  <title>Warpit</title>
  
  	<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
    <link rel="stylesheet" type="text/css" href="_css/mainWarpit.css" />
	
	<link rel="stylesheet" type="text/css" href="webhelp/_css/_help.css" />
    
	
    <!-- GC -->
    <!-- LIBS -->
    <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
    <?php if ($_SESSION[UserInfo][debugMode] == 1) { ?>
    <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
    <? } else { ?>
    <script type="text/javascript" src="extjs/ext-all.js"></script>
	<?php } ?>
    <!-- <script type="text/javascript" src="_include/_ExtjsUploader.js"></script> -->
  	 <!-- extensions -->
  	 <!-- WARNING: the CheckColumn.js was edited! the onMouseDown event fires now afterEdit!
  	 	source: http://www.extjs.com/forum/showthread.php?t=27161&page=3 
  	 	if at any point this stops working, check if it wasn't replaced-reeditet! 
     <script type="text/javascript" src="extjs/examples/ux/CheckColumn.js"></script>-->	
     <script type="text/javascript" src="_plugins/uxFixes/CheckColumn.js"></script>
  	 <script type="text/javascript" src="extjs/examples/ux/RowExpander.js"></script>
  	 
  	 
  	 <!-- for grid filtering! -->
  	<link rel="stylesheet" type="text/css" href="extjs/examples/ux/gridfilters/css/GridFilters.css" />
  	<link rel="stylesheet" type="text/css" href="extjs/examples/ux/gridfilters/css/RangeMenu.css" />
  	
  	<!-- WARNING: ListMenu vas edited (versiont ext303), for combobox filtering... 
  	<script type="text/javascript" src="extjs/examples/ux/gridfilters/menu/ListMenu.js"></script>-->
  	<script type="text/javascript" src="_plugins/uxFixes/ListMenu.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/menu/RangeMenu.js"></script>
	
  	<script type="text/javascript" src="extjs/examples/ux/gridfilters/GridFilters.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/Filter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/StringFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/DateFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/ListFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/NumericFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/BooleanFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/RowLayout.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/CenterLayout.js"></script>
	
	
	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.grid.RowActions.css">
	<script type="text/javascript" src="_plugins/Ext.ux.util.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.Search.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.RowActions.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.RecordForm.js"></script>
	
	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.grid.CellActions.css">
	<script type="text/javascript" src="_plugins/Ext.ux.grid.CellActions.js"></script>
	
	<script type="text/javascript" src="_plugins/Ext.ux.forms.OOSubmit.js"></script>
	<!--  calculator wanabe -->
	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.calc.css">
	<script type="text/javascript" src="_plugins/Ext.ux.calc.js"></script>
	
	<!-- webcati Build questionare specific functions!!! -->
	<script type="text/javascript" src="_plugins/Ext.wc.BuildQuest.js"></script>
	
	<!--  SAKI's FILE TREE -->
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/icons.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/webpage.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/filetree.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/filetype.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/famflag.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/Ext.ux.IconCombo.css">
	  <script type="text/javascript" src="_plugins/fileTree/js/WebPage.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.BrowseButton.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileUploader.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.UploadPanel.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileTreeMenu.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileTreePanel.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.ThemeCombo.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.IconCombo.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.LangSelectCombo.js"></script>
	<!-- Tree Grid -->
		
		<link rel="stylesheet" type="text/css" href="extjs/examples/ux/treegrid/treegrid.css" rel="stylesheet" /> 
        
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridSorter.js"></script> 
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridColumnResizer.js"></script> 
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridNodeUI.js"></script> 
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridLoader.js"></script> 
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridColumns.js"></script> 
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGrid.js"></script> 
	
	<!-- grid drag n drop reorder! -->
	<script type="text/javascript" src="_plugins/Ext.ux.dd.GridDragDropRowOrder.js"></script>
	
	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.form.LovCombo.css">
	
	<script type="text/javascript" src="_plugins/Ext.ux.MultiSelectField.js"></script>
	
	
	<!-- TINY MCE!!!! -->
	
	<script type="text/javascript" src="_plugins/tinyMCE/jscripts/tiny_mce/tiny_mce.js"></script>
	<script type="text/javascript" src="_plugins/tinyMCE/Ext.ux.TinyMCE.min.js"></script>
	
	<script type="text/javascript" src="_plugins/tinyMCE/imagemanager/js/mcimagemanager.js"></script>
	<script type="text/javascript" src="_plugins/tinyMCE/filemanager/js/mcfilemanager.js"></script>
	

	<!-- this functions are required for propert grid -->
	<script type="text/javascript" src="property-grid.js"></script>


	<!--  Some main function used in global scale -->
	<script type="text/javascript" src="_plugins/Ext.RMmain.js"></script>
	

	<script type="text/javascript">

	
    Ext.onReady(function(){

     


        
    	 Ext.QuickTips.init(); 
			
		var viewPort = new Ext.Viewport({
			layout:'fit',
			
			items:
			
	       new Ext.Panel({
            layout: 'border',
         	border: false,

            title: ' <table border=0 width="100%" height="20" cellpadding=0 cellspacing=0 class="headerFont"><tr><td width=400>&nbsp;&nbsp;<b>EN</b>&nbsp;<img src="_img/flags_2.png">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Login user:</b> <?php echo $_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']; ?></td><td align=center><img src=_img/znakec.png>&nbsp;&nbsp;<b>WARP-IT</b></td><td width=400 align=right><small><b>Login time:</b> <?php echo $_SESSION['UserInfo']['LastLogin']; ?></small></td><td width=40 align=right><a href=?logOut=1><img id=btn1-ct src=_img/logOut.png></a>&nbsp;&nbsp;</td></tr></table>',
		       // unstyled : true,
		        tbar: [
		         {
		         	
		             xtype:'button',
		             text: 'Webuserspool',
		             iconCls: 'iconWebuserspool',
					 
		             scale: 'large',
		             width: 85,
		             iconAlign: 'top',
		             style: 'padding-left:5px',
	            	 handler : function() {
		             	//addTab('WebUserspool','webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'},Ext.getCmp('west-panel'));
		        	 //CallScript('webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'});
		        	 	addTabAuto('webUserspoolUniqePanel','webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'});
		            	}  
		            },
		        {
		             xtype:'button',
		             text: 'Webcati',
		             iconCls: 'iconWebcati',
		             scale: 'large',
		             width: 85,
		             iconAlign: 'top',
		             style: 'padding-left:5px',
		             handler : function() {
		             	addTabAuto('webCatiUniqePanel','webcati/_forms/tree.groups.php',{treeName:'CatiMenu', tree:'_ProgramMenu'}, Ext.getCmp('west-panel')); 
		             }
		                
		            },
		            
		        {
		             xtype:'button',
		             text: 'Webrecode',
		             width: 85,
		             iconCls: 'iconWebrecode',
		             scale: 'large',
		             iconAlign: 'top',
		            style: 'padding-left:5px',
		             handler : function() {
		             	//addTab('Quotas','_forms/forms.quotas.php',{},mainTabPanel);
		             	addTab('Dolznosti','webcati/_forms/forms.quotas.php',{},mainTabPanel); 
		             	
		              //	Ext.destroy(DinamikaTree,DinamikaTree_Loader, DinamikaTree_Root, DinamikaTree_editor, DinamikaTree_contextMenu);
		             //	Ext.getCmp('west-panel').;
		             }
		                
		            },
		            {
		             xtype:'button',
		             text: 'Webtables',
		             iconCls: 'iconWebtables',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 85,
		             style: 'padding-left:5px'
		             ,
		             handler : function() {
		             	var par = Ext.getCmp('panelW2grids');
		             	if(typeof par != 'undefined')
		             	{
			             	if(typeof par.getComponent(progGrid) == 'undefined'  )
			             	{
		             			par.add(progGrid);
		             			par.doLayout();
			             	} 
			             	/*else
			             	{
			             		par.remove(progGrid,false);
		             			par.doLayout();
			             	}*/
		             	}
		             	else
		             	{
		             		
		             	}
		             }
		                
		            },
		           
		            {
		             xtype:'button',
		             text: 'Webgraphs',
		             iconCls: 'iconWebgraphs',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 85,
		             style: 'padding-left:5px'
	            	
		            },
		            {
		             xtype:'button',
		             text: 'Webreport',
		             iconCls: 'iconWebreport',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 85,
		             style: 'padding-left:5px'
	            	
		            },
		            {
		             xtype:'button',
		             text: 'Webportal',
		             iconCls: 'iconWebportal',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 85,
		             style: 'padding-left:5px'
	            	
		            },'->'
		            ,
		            {
		             xtype:'button',
		             text: 'Tools',
		             iconCls: 'iconTools',
		             scale: 'large',
		             width: 70,
		             iconAlign: 'top',
		            // style: 'padding-right:10px',
		            menu:[
		            {
			             text:'Permission',    
		            	 handler : function() {
			             	    	 CallScript('_forms/forms.permissions.php'); 
			             }  
		            }, {
		                text:'Logger',    
		            	 handler : function() {
			             	    	 CallScript('_forms/forms.logger.php'); 
			             }   
		            }]},
		            {
		             
		             text: 'Options',
		             iconCls: 'iconPropreties',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 70,
		             menu:[
		                   {
			            text:'Opravki',       
	            	 	handler : function() {
		             	//addTab('Dolznosti','_forms/_examples/forms.opravki.php');
				        CallScript('_forms/_examples/forms.opravki.php');
		            	}  
		                 },
		                 {
					            text:'Opravki test',       
			            	 	handler : function() {
				             	//addTab('Dolznosti','_forms/_examples/forms.opravki.php');
						        CallScript('_forms/_examples/forms.opravkiDIP.php');
				            	}  
				                 },
		                 {
			            text:'mcImageManager',       
	            	 	handler : function() {
		               	//addTab('nima veze','_forms/_examples/forms.treeTEST.php',{},Ext.getCmp('west-panel'));
				          mcImageManager.open();
			            		
		            	}  
		                 }
		                 ,
		                 {
			            text:'formTest',       
	            	 	handler : function() {
		               	addTab('nima veze','_forms/_examples/forms.formTest.php');
			            		
		            	} 
		                 },
		                 {
			             text: 'gridArrayText',
			             handler: function(){
						CallScript('webcati/_forms/buildQuestionare/forms.scriptGrid.php',{'name':'test','data':"[[1,'bla' ],[2,'haha']  ]"  }   );
		                 }
		                 }
		                 ,
		                 {
			            text:'Web Help',       
	            	 	handler : function() {
		                	 //addTab('WEBHelp - Admin','webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel')); 
		                	 CallScript('webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'}); 
				             					
		            			}  
		                 }

		                 ,
		                 {
			            text:'Questionnaire Designer Panel',       
	            	 	handler : function() {
		                	 CallScript('webhelp/_forms/forms.questionnaireDesignerPanel.php',{tree:'_HelpMenu'}); 
				             					
		            			}  
		                 }
		                 
		                 ,
		                 {
			            text:'BQ test',       
	            	 	handler : function() {
		                	 //addTab('WEBHelp - Admin','webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel')); 
		                	 CallScript('webcati/_forms/forms.buildQuestionnaire.php',{project: 'testIG1', id_node: 70} );
				             					
		            			}  
		                 }
	            	]
		            },
		            {
		             xtype:'button',
		             text: 'Help',
		             iconCls: 'iconHelp',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 70,
		             style: 'padding-right:10px',
	            	 handler : function() {
		             	//addTab('WEBHelp','webhelp/_forms/forms.treeHelp.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel')); 
		            	CallScript('webhelp/_forms/forms.treeHelp.php',{treeName:'HelpMenu', tree:'_HelpMenu'}); 
	                	 
		            	}  
		            }
		            
		            ],
            items: [
            // create instance immediately
           
            { 
			       
            	region: 'center',
                id: 'north2', // see Ext.getCmp() below
              	border: true,
               // margins: '0 0 0 0',
                layout:'border',
				defaults: {
			  //  collapsible: true,
			    split: true
			    //bodyStyle: 'padding:15px'
				}
				,
			items: [
		
			
			{
			    title: 'Aditional information',
			   layout:'fit',
			    region: 'south',
			    border: false,
			     collapsible: true,
			    collapsed:true,
			    height: 150,
			    items: xmlTabPanel = new Ext.TabPanel({
					 
				   
				    border: false,
				    id : 'xmlTabPanel',				    
				    activeTab: 0     // first tab initially active	
				  
				  })
			   
				}			
				,
				   // title: 'Main Content',
				   mainTabPanel = new Ext.TabPanel({
					 
				   	collapsible: false,
				    border: false,
				    id : 'mainTabPanel',
				    region:'center',
				   // activeTab: 0 ,    // first tab initially active	
				    listeners: {
							remove : function(tpan,pan){
								removeSession(pan.id);
							}
					    }
				  
				  })
		
           ]},
          
           		new Ext.TabPanel({
           		//{
                region: 'east',
                id: 'west-panel', 
                split: true,
                minSize: 200,
                width:300,
               	collapseMode: 'mini',
                border: true,
                listeners: {
					remove : function(tpan,pan){
						removeSession(pan.id);
					}
			    },
             //	margins: '2 0 0 0',
             	 

                xtype           : 'tabpanel',
    			//activeTab       : 0,
	    		enableTabScroll : true,
		    	resizeTabs      : false,
				minTabWidth     : 75,
			
	               items: [
	                /*{
	                	contentEl: 'poolFields',
	                	iconCls: 'TabHelp',
	                	title: 'WEBHelp',
	                	closable: true	            						   			    
	                }*/
	                ]
            })
           
           ]
        }) });
     
        
          addTabBCK = function(naslov,loadData,parameters){
		        mainTabPanel.add({
		            title		: 	naslov,
		            autoLoad	:  	{
                                		url    : loadData,
                                		params: parameters,
                                		scripts: true
                           			},		           
		            closable	:	true
		        }).show(); //show the tab
		  }
		
          addTab = function(naslov,loadData,parameters,tabName,callBack){

			  if(tabName == null)
			  {
				  tabName = mainTabPanel
			  }
			  var tmp = Ext.get('tabTemporary');
			  tmp.load({
            		url    : loadData,
              		params: parameters,
              		scripts: true,
              		callback:function(el,success,response){ 
						
              		var elem = Ext.util.Format.trim(document.getElementById('tabTemporary').innerHTML) ;
          			tabName.add(eval(elem)).show(); //show the tab
          			if(callBack!= null)
             		{
                 		callBack();
             		}
              		//alert(Ext.util.Format.trim( document.getElementById('tabTemporary').innerHTML ));
              		}
         			});
           
		  }
		  addTabAuto = function(tabId,url,parameters,tabName,callBack)
		  {
			  Ext.apply(parameters,{action:'add',uniqueTabId : tabId ,uniqueTabUrl : url } );
			  		Ext.Ajax.request({
	         		 url    : '_support/tabManager.php',
	           		params: parameters,
	           		async: false,
	           		success: function(res,opt)
	           		{
	             		eval(res.responseText);
	             		if(callBack!= null)
	             		{
	                 		callBack();
	             		}
	             		
	           		}
	           		});
	           		
		  }
		  
		  CallScript = function(loadData,parameters,callBack){
         	  Ext.Ajax.request({
         		 url    : loadData,
           		params: parameters,
           		async: false,
           		success: function(res,opt)
           		{
             		eval(res.responseText);
             		if(callBack!= null)
             		{
                 		callBack();
             		}
           		}
           		});
           
		  }
		  CallMultiScripts = function(arr)
		  {
			  var len = arr.length;
			  if(len == 0)
				  return;
			  var count = 0;
			  var fn = function(){
					//the call back function
					count++;
					if(count < len)
					{
						 addTabAuto( arr[count][0] , arr[count][1],arr[count][2],'',fn );
					}
				};
			  addTabAuto( arr[count][0] , arr[count][1],arr[count][2],'',fn );
		  }
		  function removeSession(sessId)
		  {
			  Ext.Ajax.request({
					url : '_support/tabManager.php',
					params:{action:'remove',sessId:sessId}
				  });
		  }
        
 
			var tmpArr = [];
			addTab('','_forms/forms.userpropreties.php',{},Ext.getCmp('west-panel'));
	 		//tmpArr.push([ addTab, '','_forms/forms.userpropreties.php',{},Ext.getCmp('west-panel')  ]);
			
		
			//tmpArr.push(['panelTipOfTheDay', 'webhelp/_forms/forms.tipOfTheDay.php',{table:'_HelpMenu'} ] );
			<?php 
				$sql = "SELECT * FROM ".DB_WARPIT_MAIN."._user_tab_state WHERE user_id = ".$_SESSION['UserInfo']['id'] ." ORDER BY id";
				$res = $db->SQLexecute($sql);
				//echo $db->GetError();
				
				while ($row = $db->fetchAssoc($res))
				{
					echo "tmpArr.push( ['".$row['tab_id']."', '".$row['url']."',".$row['params']." ] ); ";
					//echo "CallScript('".$row['url']."',".$row['params'].",function(){console.log('aaa');});";
				}
				
				echo "CallScript('webhelp/_forms/forms.tipOfTheDay.php',{table:'_HelpMenu'}, function() {
					 	CallMultiScripts(tmpArr);
					 	 tmpArr = null;
					 } );
					";
			?>
		
    });
    </script>
</head>
<body>
	<div id="tabTemporary" class="x-hide-display" >
	</div>
</body>
</html>