<?php
include '../config.php';
$data = array();
$sql_base;
$Q25 = array();
$Q25V = array();

//$circle = $_POST['circle'];
$condX = $_POST['condX'];
$conX = $_POST['conX'];
$time = $_POST['timeX'];
$tablecondX = $_POST['tablecondX'];
$timeZ = "('".implode("','",$time)."')";
$columnS=array("record","Q9g",$tablecondX);
$mq=query_marge($time,$columnS);

if($conX==1){    
	
   $condX="";   
	$q=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ");
	//echo "SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ";
	$baseX=mysqli_fetch_array($q);   
	$base = $baseX[0];
}

if($conX==2){
   $q=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX 1=1");
   $baseX=mysqli_fetch_array($q);   
   $base = $baseX[0];
}

$poor="1,2,3,4";
$average="5,6";
$Outstanding="7,8,9,10";

	/*Base script start*/
	
	$sql_base=$base;
	$data['base'] = $sql_base;
	/*Base script End*/
    if($sql_base==0) 
	{
        $data['Q24'] = 0;
		array_push($Q25,0,0,0,0);
        $data['Q25'] = $Q25;
	}
	else
	{
	    $columnS=array("record","Q9g","Q24",$tablecondX);
        $mq=query_marge($time,$columnS);
        /*Q24 script start*/
        $Baseq24 = mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q24 != '' ");
        $baseq24=mysqli_fetch_array ($Baseq24);
        $q24=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q24 IN (1,2,3,4,5,6,7,8) ");
        $Q24=mysqli_fetch_array ($q24); 
        $data['Q24'] = round(($Q24[0] / $sql_base ) * 100,1);
        $data['Q24V'] = $Q24[0];
        /*Q24 script end*/

        /*Q25b script start*/
        $columnS=array("record","Q9g","Q25b",$tablecondX);
        $mq=query_marge($time,$columnS);
        $Baseq25b = mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25b != '' ");
        $baseq25b=mysqli_fetch_array ($Baseq25b);
        $q25b=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25b = '1' ");
        $Q25b=mysqli_fetch_array ($q25b); 
        $Q25B = round(($Q25b[0] / $sql_base ) * 100,1);
        $data['Q25BV'] = $Q25b[0];
        /*Q25b script end*/

        /*Q25c script start*/
        $columnS=array("record","Q9g","Q25c",$tablecondX);
        $mq=query_marge($time,$columnS);
        $Baseq25c = mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25c != '' ");
        $baseq25c=mysqli_fetch_array ($Baseq25c);
        $q25c=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25c = '1' ");
        $Q25c=mysqli_fetch_array ($q25c); 
        $Q25C = round(($Q25c[0] / $sql_base ) * 100,1);
        /*Q19b script end*/

        /*Q25d script start*/
        $columnS=array("record","Q9g","Q25d",$tablecondX);
        $mq=query_marge($time,$columnS);
        $Baseq25d = mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25d != '' ");
        $baseq25d=mysqli_fetch_array ($Baseq25d);
        $q25d=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25d = '1' ");
        $Q25d=mysqli_fetch_array ($q25d); 
        $Q25D = round(($Q25d[0] / $sql_base ) * 100,1);
        $data['Q25DV'] = $Q25d;
        /*Q25d script end*/

        /*Q25e script start*/
        $columnS=array("record","Q9g","Q25e",$tablecondX);
        $mq=query_marge($time,$columnS);
        $Baseq25e = mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25e != '' ");
        $baseq25e=mysqli_fetch_array ($Baseq25e);
        $q25e=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q25e = '1' ");
        $Q25e=mysqli_fetch_array ($q25e); 
        $Q25E = round(($Q25e[0] / $sql_base ) * 100,1);
        /*Q25e script end*/
        array_push($Q25,$Q25B,$Q25C,$Q25D,$Q25E);
        array_push($Q25V,$Q25b[0],$Q25c[0],$Q25d[0],$Q25e[0]);
        $data['Q25'] = $Q25;
        $data['Q25V'] = $Q25V;

    }

    
	echo json_encode($data);
?>