<?php
require_once "vendor/autoload.php";
require_once ("include/functions_stats.php");
session_start();
$loader = new \Twig\Loader\FilesystemLoader('layouts/');
$twig = new \Twig\Environment($loader);
 
 if((isset($_SESSION['Username']) && $_SESSION['Username'] != '')){
	//if($_SESSION['UL_id'] == 1 || $_SESSION['UL_id'] == 2 ||  $_SESSION['UL_id'] == 4){

		$date =Date("Y-m-d");
		$totalFarmers =total_subscribers();
		$totalProfiledFarmers=farmers_profile_count($date);
		$todayFarmers=total_subscribers($date);
		$todayProfiledFarmers=fp_count($date);
		$countDistrictWith = count_districts("with");
		$countDistrictWithout = count_districts("without");
		$notifyOn=countNotify("on");
		$notifyOff=countNotify("off");
		$tillDate = Date("M Y");
		$getLanguage= languageChart();
		$getSubscription= subscriptionChart();
		$getLatestUsers= latestUsers();
		$IVR=statsIVR("IVR");
		$uniqueIVR = statsIVR("uniqueIVR");
		$callCenter = statsIVR("callCenter");
		$uniqueCallCenter = statsIVR("uniqueCallCenter");
		$callCenterBlock = statsIVR("callCenterBlock");
		
			$template = $twig->load('index.html');
			echo $template->render(['name'=>$_SESSION['name'], 'UL_id'=>$_SESSION['Username'],'tillDate'=> $tillDate, 
			'totalFarmers'=>$totalFarmers, 'totalProfiledFarmers'=>$totalProfiledFarmers,
			'todayFarmers'=>$todayFarmers, 'todayProfiledFarmers'=>$todayProfiledFarmers,
			'CDWith' => $countDistrictWith, 'CDWithout' => $countDistrictWithout,
			'notifyOn' => $notifyOn, 'notifyOff' => $notifyOff,
			'getLanguage'=>$getLanguage ,"getSubscription" => $getSubscription,"getLatestUsers" => $getLatestUsers,
			'IVR'=>$IVR, "uniqueIVR"=>$uniqueIVR,
			'callCenter'=>$callCenter, 'uniqueCallCenter'=>$uniqueCallCenter, 'callCenterBlock'=>$callCenterBlock]);
	/*}else{
		$template = $twig->load('call_status.html');
		echo $template->render();
	}*/
}else{
		$template = $twig->load('login.html');
		echo $template->render();
}