<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_form.php");
include_once(PATH_TO_ROOT."webcati/_class/class.webrecode.statistics.php");
	
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
?>

<?php
	// ----------------------------------------------------------------------------------------
	
	$qtip="function(val, cell, record) {
        // return markup
        return '<div qtip=\"'+ val + '\">' + val + '</div>';
    }";
	
	
	
	$params="";
	$proj_name=$_POST["proj_name"];
	$proj_name_stat_mode=$proj_name."_".$_POST["statistics_mode"];
	
	if(isset($_POST["statistics_mode"]))
	{
		$params.=", statistics_mode:".$_POST["statistics_mode"];
	}
	else
	{ 
		$params.=", statistics_mode:0";
	}
	
	if(isset($_POST["id_project"]))
	{
		$params.=", id_project:".$_POST["id_project"];
		$q=new webrecode_statistics($_POST["id_project"], $db);
		//$proj_name.=" - " . $q->table_name;
		if($_POST["statistics_mode"]==1)
			$proj_name.=' - with categories';
	}
	else 
		$params.=", id_project:0";
		
	
		
	
		
	$statistics = new MakeGrid();
	
	$statistics->setGridName($proj_name_stat_mode.'_statistics')
	->setMainTable('opravki','Warpit_delo')
	->setTitle('Statistics'.$stat);
	
	$statistics->reqUrl = 'webcati/_forms/_ajax/ajax.webrecode.statistics.php';
	
	
	
		
	$statistics->baseParams='grid_action:"general_statistics"'.$params;
	
	$statistics->addColumn('var_name', 'var_name');
	$statistics->addColumn('rec_def', 'rec_def');
					  
	$statistics->addColumn('total', 'Total labels');
	$statistics->addColumn('recoded', 'Recoded labels');
	$statistics->addColumn('recodation_method', 'Recodation method');
	
	$statistics->setAutoExpand('rec_def');
	
	echo $statistics->createGrid();
	
?>


var stats_<?php echo $proj_name_stat_mode ?> = new Ext.Panel({
 title:'Statistics <?php echo $proj_name; ?>'
 ,id:'stats_<?php echo $proj_name_stat_mode ?>'
 ,closable:true
 ,layout:'border'
 ,items:[{
 region:'center'
 ,layout:{
				type:'vbox',
				padding:'0',
				align:'stretch'
		},
		items:[
		
			web_recode_panelW2grids = new Ext.Panel({id:'web_recode_panelW2grids',defaults:{margins:'0 0'},flex:1, width:'100%', layout:'hbox',layoutConfig:{align:'stretch'},
			items:[ 
			
			<?php echo $statistics; ?>
					]
				})
			]
 ,frame:true
 ,border:false
 }]
 });

	
	mainTabPanel.add(stats_<?php echo $proj_name_stat_mode ?>).show();
	