<?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'];
		$projectId = $_POST['id_project'];
		$projName = $_POST['projName'];

		
	    $reqUrl = 'webcati/_forms/_ajax/ajax.questionStatistic.php';
	   $gridQuestion = new MakeGrid( $tabId."_cati");

	   $gridQuestion->setMainTable($projName."___EngineLog",DB_WARPIT_WEBCATI_BASE)->setTitle('Question - details')
	   ->baseParams="prvik:'{$_POST['prvik']}',projName:'{$_POST['projName']}'";
	   $gridQuestion->selectSQL = "SELECT id, suspect, questStart, questEnd, betwen, firstk, clicks, qcharts, acharts, lcharts, nvisits, isti_odgovor  FROM " .DB_WARPIT_WEBCATI_BASE.".QDetails_".$_SESSION['UserInfo']['id'];	   
	   $klik=false;
       $gridQuestion->setReqUrl($reqUrl)->dateSQL = 'U';  
       $gridQuestion->dateDisplay = 'Y.m.d H:i:s';
       $gridQuestion->addColumn('id', 'Id')->width(40);
       $gridQuestion->addColumn('suspect','Suspect')->width('55')->renderer("function(val) {
			if (val == true) return '<img src=_img/deleteMultiAppointments.gif width=\'12\' height=\'12\'>';
			else  return '<img src=_img/reactivateMultiAppointments.gif width=\'12\' height=\'12\' >';
			return '';
			}"  );  
       $gridQuestion->addColumn('questStart', 'Start Time')->width(120)->type('date')->renderer("function(v) {
                 													 return Ext.util.Format.date(v, 'Y.m.d H:i:s');
            													}"); 
        $gridQuestion->addColumn('questEnd', 'End Time')->width(120)->type('date')->renderer("function(v) {
                 												 return Ext.util.Format.date(v, 'Y.m.d H:i:s');
            													}"); 
        $gridQuestion->addColumn('betwen', 'Betwen')->width(60);
        $gridQuestion->addColumn('firstk', 'Prvi klik')->width(120);// čas do prvega klika 
	    $gridQuestion->addColumn('clicks', 'All clicks')->type('int')->width(60); // vsi kliki na vprašanju
        $gridQuestion->addColumn('qcharts', 'Question chars')->width(100); 
        $gridQuestion->addColumn('acharts', 'Answer chars')->width(100); 
        $gridQuestion->addColumn('lcharts', 'Legend chars')->width(80); 
        $gridQuestion->addColumn('nvisits', 'Number of visits')->type('int')->width(100); // št. obiskov vprašanja
        $gridQuestion->addColumn('isti_odgovor', 'Same anwser')->width(100); // ali je večkrat kliknjen isti odgovor (true=DA)
         
        

        //details
        $gridQuestion->addtBarItem("{text:'Details',iconCls:'RMicon_view_details',handler:function()
        {
        		var q = $gridQuestion.selModel.getSelections();
        		if(q.length)
        		for(var i=0;i<q.length;i++)
        		{
        		CallScript('webcati/_forms/statistics/forms.questionStatisticsDetails.php',{projectId:$projectId,tabId:'$tabId', idQuestion:q[i].id, projectName:'$projName' } );
        }
        
        }}");
        
        $gridQuestion->addTbarItem("'&nbsp;&nbsp;','-','&nbsp;&nbsp;','Time interval:', new Ext.form.ComboBox({
        		typeAhead: true,
        		triggerAction: 'all',
        		mode: 'local',
        		store: new Ext.data.ArrayStore({
        		fields: [
        		'filID',
        		'displayText'
        		],
        		data: [
        		[1,' 1s'],
        		[2,' 2s'],
        		[3,' 3s'],
         		[4,' 4s'],
        		[5,' 5s'],
        		[6,' 6s'],
        		[7,' 7s'],
        		[8,' 8s'],
         		[9,' 9s']       		       
        		]
        }),
        		valueField: 'filID',
        		value: '2',
        		displayField: 'displayText',
        		listeners: {
        		select : function(combo,rec) {
        		 callAjax();
        		 $gridQuestion.getStore().baseParams.Cas = rec.get('filID');
	   	 		 $gridQuestion.getStore().reload();
				 }
        		
        }
        }) ");


        
        
       $gridQuestion->setPaging()
       ->region('center')
       ->flex(1)
		->setCheckBoxSelectionModel()
        ->setFiltering()
        ->setRemoteSort();
        
         echo $gridQuestion->createGrid();       

				        
        echo "mainTabPanel.add({ 
		id:'$tabId',
		closable:true,
		title: 'Question details - $projName ',
                RMreopen : function(p){ 
			$gridQuestion.getStore().reload( );
		},
		listeners: {
  		 beforeclose : function () {
		 callAjax();
   												 }
 						  },
		iconCls: 'RMicon_view_details',
		layout:'vbox',
        items:[$gridQuestion]}).show();
        
        function callAjax()
        {
        	Ext.Ajax.request({
    		url: 'webcati/_forms/_ajax/dropTableQuestionStatistics.php',
       		async: false,
       		success: function(res,opt) {
       		}
       		});
		}
		

        ";
        

?>
