<?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'];
	

	$grid = new MakeGrid($tabId );
	$gridName = $grid->getName();
	//$grid->setGridName('skupina')
	
//	$selectSQL = "SELECT id_project as project_id, IF(pointType = 2,	(SELECT CONCAT(' Redirect - ',idLab) FROM ".DB_WARPIT_USERSPOOL."._RedirectProjects  WHERE id = a.id_project),	(SELECT proj_name FROM  ".DB_WARPIT_WEBCATI_BASE."._Projects WHERE id = a.id_project) ) as project_name, SUM(`webPoints`) as  project_points  FROM ".DB_WARPIT_WEBCATI_BASE."._wwwPoints as a WHERE a.id_project > 0 GROUP BY CONCAT(a.id_project,'-',a.pointType)";
//	$selectSQL =  "SELECT id_project as project_id,SUM(webPoints) as project_points, proj_name as project_name FROM " . DB_WARPIT_WEBCATI_BASE . " .`_wwwPoints` a LEFT JOIN ".DB_WARPIT_WEBCATI_BASE . "._Projects b ON a.id_project = b.id WHERE id_project IS NOT NULL GROUP BY id_project";
	$selectSQL = "SELECT b.id as project_id,proj_name as project_name, SUM(webPoints) as project_points FROM " . DB_WARPIT_WEBCATI_BASE . "._wwwPoints as a RIGHT JOIN " . DB_WARPIT_WEBCATI_BASE . "._Projects as b ON a.id_project = b.id  AND id_purpose = 6 AND id_project IS NOT NULL GROUP BY id_project UNION ALL SELECT b.id as project_id,CONCAT('Redirect - ', idLab) as project_name, SUM(webPoints) as project_points FROM " . DB_WARPIT_WEBCATI_BASE . "._wwwPoints as a RIGHT JOIN " . DB_WARPIT_USERSPOOL . "._RedirectProjects as b  ON a.id_project = b.id  AND id_purpose = 24 AND id_project IS NOT NULL GROUP BY id_project";
	$grid->setTitle("Projects statistics");
	$grid->selectSQL = $selectSQL;
	$grid->setReqUrl('webuserspool/_ajax/cati/ajax.cati-project-statistics.php');
	//$grid->baseParams = $baseParams;
	
	$grid->addColumn('project_id','Id');
	$grid->addColumn('project_name','Project name');
	$grid->addColumn('project_points','Total points');
	$grid->addExportButton('Export',null,array('title' => "Export Projects Points statistics" ));
 	//echo $grid->createStore();
	echo $grid->createGrid();
	
	echo "
		
		$gridName.on('afterrender',function(gr){ 
			
		/*	gr.RMdd = new Ext.dd.DragSource(gr.getTopToolbar().find('dragCopy',true)[0].getEl(),{ddGroup:'wupGrouplink',onStartDrag:function(){
				this.dragData = {caGrid : $gridName , isWebcati: ".($isWebcati ? 'true': 'false') ." };
			}} );*/
			
				$gridName.on('show',function(gr){ 
				gr.getStore().reload();
				});
		});
		$gridName.on('beforedestroy',function(gr){
			if(gr.RMdd) gr.RMdd.destroy();
		});
		
	
	
	mainTabPanel.add( Ext.getCmp( '".$grid->getGridName()."')).show();"; ?>