<?php
include '../config.php';
$data = array();
$sql_base;
$Q26a = array();
$Q26b = array();
$Q26 = array();
$Q26aV = array();
$Q26bV = array();
$Q26V = array();
//$circle = $_POST['circle'];
$condX =$_REQUEST['condX']; // $_REQUEST['condX'];
$conX = $_REQUEST['conX'];
$time = $_POST['timeX'];

$timeZ = "('".implode("','",$time)."')";
$tablecondX = $_POST['tablecondX'];
$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");
   //echo "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,5,7,8,9";
$average="8,9";
$Outstanding="10,11";

	/*Base script start*/
	
	$sql_base=$base;
	$data['base'] = $sql_base;
	/*Base script End*/

	if($sql_base==0) 
	{
		array_push($Q26a,0,0,0);
		array_push($Q26b,0,0,0);
		array_push($Q26,0,0,0);
		$data['Q26N'] = 0;
		$data['Q26a'] = $Q26a;
		$data['Q26b'] = $Q26b;
		$data['Q26'] = $Q26;
	}
	else
	{
	    $columnS=array("record","Q9g","Q26",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26N=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26 in (1,2,3,4,5,6,7,8) ");
		$Q26N=mysqli_fetch_array($q26N); 
		$data['Q26N'] = round(($Q26N[0]/$sql_base )* 100,1);
		$data['Q26NV'] = $Q26N[0];
		
		/*Q26a script start*/
		$columnS=array("record","Q9g","Q26a",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26a_1=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26a in (1) ");
		$Q26a_1=mysqli_fetch_array($q26a_1); 
		$Q26A_1 = round(($Q26a_1[0] / $sql_base ) * 100,1);

		$q26a_2=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26a in (2) ");
		$Q26a_2=mysqli_fetch_array($q26a_2); 
		$Q26A_2 = round(($Q26a_2[0] / $sql_base ) * 100,1);

		$q26a_3=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26a in (3) ");
		$Q26a_3=mysqli_fetch_array($q26a_3); 
		$Q26A_3 = round(($Q26a_3[0] / $sql_base ) * 100,1);

		array_push($Q26a,$Q26A_1,$Q26A_2,$Q26A_3);
		array_push($Q26aV,$Q26a_1[0],$Q26a_2[0],$Q26a_3[0]);
		
		/*Q26a script end*/
		
		
		
		
		/*Q26b script start*/
		$columnS=array("record","Q9g","Q26b","Q26",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26b_base=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26 in (1,2,3,4,5,6,7,8) ");
		$Q26b_base=mysqli_fetch_array($q26b_base); 
		$data['Q26b_base'] = $Q26b_base;
		
		$q26b_1=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26b in (1) ");
		$Q26b_1=mysqli_fetch_array($q26b_1); 
		$Q26B_1 = round(($Q26b_1[0] / $sql_base ) * 100,1);

		$q26b_2=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26b in (2) ");
		$Q26b_2=mysqli_fetch_array($q26b_2); 
		$Q26B_2 = round(($Q26b_2[0] / $sql_base ) * 100,1);

		$q26b_3=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26b in (3) ");
		$Q26b_3=mysqli_fetch_array($q26b_3); 
		$Q26B_3 = round(($Q26b_3[0] / $sql_base ) * 100,1);

		array_push($Q26b,$Q26B_1,$Q26B_2,$Q26B_3);
		array_push($Q26bV,$Q26b_1[0],$Q26b_2[0],$Q26b_3[0]);
		/*Q26a script end*/
		
		
		
		/*Q26c script start*/
		$columnS=array("record","Q9g","Q26c",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26c=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26c in (1) ");
		$Q26c=mysqli_fetch_array($q26c); 
		$Q26C = round(($Q26c[0] / $sql_base ) * 100,1);
		/*Q26c script end*/
		
		
		
		/*Q26d script start*/
		$columnS=array("record","Q9g","Q26d",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26d=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26d in (1) ");
		$Q26d=mysqli_fetch_array($q26d); 
		$Q26D = round(($Q26d[0] / $sql_base ) * 100,1);
		/*Q26d script end*/
		
		
		
		/*Q26e script start*/
		$columnS=array("record","Q9g","Q26e",$tablecondX);
        $mq=query_marge($time,$columnS);
		$q26e=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND $condX Q26e in (1) ");
		$Q26e=mysqli_fetch_array($q26e); 
		$Q26E = round(($Q26e[0] / $sql_base ) * 100,1);
		/*Q26e script end*/
		
		array_push($Q26,$Q26C,$Q26D,$Q26E);
		array_push($Q26V,$Q26c[0],$Q26d[0],$Q26e[0]);

		$data['Q26a'] = $Q26a;
		$data['Q26b'] = $Q26b;
		$data['Q26'] = $Q26;
		
		$data['Q26aV'] = $Q26aV;
		$data['Q26bV'] = $Q26bV;
		$data['Q26V'] = $Q26V;

	}
	
	
	
	echo json_encode($data);
?>