<?php
session_start();
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");

$svaTool = new svaTool();


$errorCode = 0;

$password = NULL;
$confPasswd = NULL;

$startDateTime = addslashes($_REQUEST['startDateTime']);
$endDateTime = addslashes($_REQUEST['endDateTime']);
$userId = addslashes($_REQUEST['userId']);
$status = addslashes($_REQUEST['status']);
$granularity = $_REQUEST['granularity'];

//print_r($_REQUEST);
/*
$startDateTime = "2019-04-01 00:00:00";
$endDateTime =  "2019-05-01 00:00:00";
$userId = 66;
$status =-1;
*/

$res =  $dba->getCallReasonGlobalStats( $startDateTime, $endDateTime, $granularity,$_SESSION['cfg']['max.sql.results.elements']) ; 
$data = "";

 $cmpt = 1;
					 $total = count($res) ;
					 for ($i = 0; $i < $total; $i++) {
						$data = $data.
						        '{
									"Date": "'.$svaTool->escapeJsonString($res[$i]['eventDate']).'",
									"Qualification": "'.$res[$i]['motif_name_v'].'",
									"Total": "'.$res[$i]['total'].'"
	
								 }
					         	';
						 
						 if($i+1 <  $total ) $data = $data.",";
						 
					 }
					 
			echo "[$data]";

?>

