<?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 count(*) as n, a.date_queue as landingDate, IF (mail_status = 3, 'SENT', IF(mail_status = 1,'WAITING','ERROR')) as mailStatus, id_project,project_type,id_template, id_group, numSend, mail_set, c.idLab as MailTemplate, d.idLab as GroupName, ";
$selectSQL .="		IF (project_type = 2,";
$selectSQL .="				(SELECT idLab FROM `".DB_WARPIT_USERSPOOL."`.`_RedirectProjects` WHERE id = a.id_project),";
$selectSQL .="				(SELECT proj_name FROM `".DB_WARPIT_WEBCATI_BASE."`.`_Projects` WHERE id = a.id_project)";
$selectSQL .="			) as projectName";
					 
$selectSQL .="	FROM `".DB_WARPIT_USERSPOOL."`.`_SendMailSet` as a";
$selectSQL .="		LEFT JOIN `".DB_WARPIT_USERSPOOL."`.`_MailStatistic` as b ON a.id = b.mail_set";
$selectSQL .="		LEFT JOIN `".DB_WARPIT_USERSPOOL."`.`_Emails` as c ON a.id_template = c.id";
$selectSQL .="		LEFT JOIN `".DB_WARPIT_USERSPOOL."`.`_groups` as d ON a.id_group = d.id";
$selectSQL .="	GROUP BY a.id,mail_status ORDER BY date_queue DESC";
	
/*
echo $selectSQL;
exit;
*/
$grid->setTitle("Sending statistics");
$grid->selectSQL = $selectSQL;
$grid->setReqUrl('webuserspool/_ajax/mails/ajax.mail-set-statistics.php');
//$grid->baseParams = $baseParams;

$grid->addColumn('landingDate','Sending Date');
$grid->addColumn('projectName','Project Name');
$grid->addColumn('GroupName','Group name');
$grid->addColumn('MailTemplate','Mail Template');
$grid->addColumn('numSend','Number of All mails');
$grid->addColumn('n','Status number');
$grid->addColumn('mailStatus','Status');

	//$grid->addExportButton('Export',null,array('title' => "Export Projects Points statistics" ));
 	//echo $grid->createStore();
echo $grid->createGrid();
	
	
	
echo "mainTabPanel.add( Ext.getCmp( '".$grid->getGridName()."')).show();"; ?>