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


		$tabId = $_POST['uniqueTabId'];
		$row = $_POST['row'];
		$column = $_POST['column'];
		$gridOptions=$_POST['gridOptions'];
		$options = explode(",", $gridOptions);
			        
        echo "
        //dodan toolbar na pivotgrid
        var tb = new Ext.Toolbar({
			    renderTo: document.body,
			    items: [ ]
			});
			
			
		 var storeProject = new Ext.data.Store({
						  proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.fillPivotGrid.php?action=getProjects'}),
						  reader: new Ext.data.JsonReader({
							  root:'rows'},
							   [{name:'id'},{name:'proj_name'}])
					    });		
					    
		 var storeInterviewer = new Ext.data.Store({
						  proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.fillPivotGrid.php?action=getInterwievers'}),
						  reader: new Ext.data.JsonReader({
							  root:'rows'},
							   [{name:'id'},{name:'user'}])
					    });	
		 var storeCallStatus = new Ext.data.Store({
						  proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.fillPivotGrid.php?action=getCallStatus'}),
						  reader: new Ext.data.JsonReader({
							  root:'rows'},
							   [{name:'id'},{name:'opis'}])
					    });							    						    

		var projectG=new Ext.ux.form.LovCombo({  
						    id:'selectProject',  
						    forceSelection: true,  
						    store:  storeProject,  
						    emptyText:'Select parameter ...',  
						    triggerAction: 'all',  
						    editable:false,  
						    displayField:'proj_name',  
					        valueField:'id',
							width:110,
							mode:'local'
						});	
								
			var interviewerG=new Ext.ux.form.LovCombo({  
						    id:'selectInterwiever',  
						    multiSelect: true,
						    forceSelection: true,  
						    store:  storeInterviewer,  
						    emptyText:'Select parameter ...',  
						    triggerAction: 'all',  
						    editable:false,  
						    displayField:'user',  
					        valueField:'id',
							width:110,
							mode:'local'
						});	
							
		var callStatusG=new Ext.ux.form.LovCombo({  
						    id:'selectCall',  
						    multiSelect: true,  
						    store:  storeCallStatus,  
						    emptyText:'Select parameter ...',  
						    triggerAction: 'all',  
						    editable:false,  
						    displayField:'opis',  
					        valueField:'id',
							width:220,
							mode:'local'
						});		
						

		";

		for ($i=0;$i<count($options)-1;$i++)
		{
			if ($options [$i]=='Project')
			{
				echo "storeProject.load();
				tb.add('Projects:  ',projectG,'&nbsp;&nbsp;','-','&nbsp;&nbsp;'); 
				";
			
			}
			if ($options [$i]=='Interviewers')
			{
				echo "storeInterviewer.load();
				tb.add('Interviewers:  ',interviewerG,'&nbsp;&nbsp;','-','&nbsp;&nbsp;');";
			}		
			if ($options [$i]=='Call status')
			{
				echo "storeCallStatus.load();
				tb.add('Call status:  ',callStatusG,'&nbsp;&nbsp;','-','&nbsp;&nbsp;');";
			}
			if ($options [$i]=='Time')
			{
				//echo "tb.add(pd);";
			}
			
			
		}
	 

	   echo"     var SaleRecord = Ext.data.Record.create([
        {name: 'person',   type: 'string'},
        {name: 'product',  type: 'string'},
        {name: 'city',     type: 'string'},
        {name: 'state',    type: 'string'},
        {name: 'month',    type: 'int'},
        {name: 'quarter',  type: 'int'},
        {name: 'year',     type: 'string'},
        {name: 'quantity', type: 'int'},
        {name: 'value',    type: 'int'}
    ]);
    
	     var pivotStore = new Ext.data.Store({
						    proxy: new Ext.data.HttpProxy({url: 'webcati/_forms/_ajax/ajax.fillPivotGrid.php?action=fillPivot'}),
						    reader: new Ext.data.JsonReader({
							    root:'rows'}, SaleRecord)
					    });	
					    
			pivotStore.load();		    
	    
	    var pivotGrid = new Ext.grid.PivotGrid({
	        title     : 'PivotGrid example',
		    layout:'fit',
	        store     : pivotStore,
	        aggregator: 'sum',
	        measure   : 'value',
	        viewConfig: {
	            title: 'TABLE'
	        },
	        
	        leftAxis: [
	            {
	                width: 80,
	                dataIndex: 'person'
	            },
	            {
	                width: 90,
	                dataIndex: 'product'
	            }
	        ],
	        
	        topAxis: [
	            {
	           		 width: 90,
	                dataIndex: 'year'
	            }
	        ]
	    });
	    
	    pivotGrid.add(tb);
	    
	 var combo1=   new Ext.form.ComboBox({
	 					width:40,
		       			typeAhead: true,
		       			triggerAction: 'all',
		       			mode: 'local',
		       			store: new Ext.data.ArrayStore({
		       			fields: [
		       			'filID',
		       			'displayText'
		       			],
		       			data: [
		       			[1,' aa'],
		       			[2,' bb'],
		       			[3,' cc'],
		       			[4,' dd'],
		       			[5,' ee'],
		       			[9,' ff']
		       			]
		       	}),
		       			valueField: 'filID',
		       			value: '2',
		       			displayField: 'displayText',
		       			listeners: {
		       			select : function(combo,rec) {
		       			//		$gridQuestion.getStore().baseParams.Cas = rec.get('filID');
		       			// 		$gridQuestion.getStore().reload();
		       	}
		       	}
		       	}) 
		       	
		     
       
        mainTabPanel.add({ 
		id:'$tabId',
		closable:true,
		title: 'Complete pivot tables statistics',
                RMreopen : function(p){ 
			pivotGrid.getStore().reload( );
		},

		iconCls: 'RMicon_view_details',
		layout:'vbox',
        items:[pivotGrid]}).show();";
		
		
        

?>
