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


$condX = $_POST['condX'];
$state  = "(".$condX.")";
$conX = $_POST['conX'];
$time = $_POST['timeX'];
$tablecondX = $_POST['tablecondX'];
$timeZ = "('".implode("','",$time)."')";

    /*digiSSI script start*/
    $columnS=array("record","Q9g","Q11a_n1","State");
    $mq=query_marge($time,$columnS);
    $digiSSI=mysqli_query($conn,"SELECT avg(`Q11a_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state AND Q11a_n1 != ''");
    $digiSSIV=mysqli_fetch_array($digiSSI); 
    $data['digiSSI'] = round($digiSSIV[0]);
    /*digiSSI script end*/

    /*dfSSI script start*/
     $columnS=array("record","Q9g","Q17_n1","State");
    $mq=query_marge($time,$columnS);
    $dfSSI=mysqli_query($conn,"SELECT avg(`Q17_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state");
    $dfSSIV=mysqli_fetch_array($dfSSI); 
    $data['dfSSI'] = round($dfSSIV[0]);
    /*dfSSI script end*/

    /*scSSI script start*/
    $columnS=array("record","Q9g","Q19_n1","State");
    $mq=query_marge($time,$columnS);
    $scSSI=mysqli_query($conn,"SELECT avg(`Q19_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state");
    $scSSIV=mysqli_fetch_array($scSSI); 
    $data['scSSI'] = round($scSSIV[0]);
    /*scSSI script end*/

    /*dSSI script start*/
     $columnS=array("record","Q9g","Q24_n1","State");
    $mq=query_marge($time,$columnS);
    $dSSI=mysqli_query($conn,"SELECT avg(`Q24_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state");
    $dSSIV=mysqli_fetch_array($dSSI); 
    $data['dSSI'] = round($dSSIV[0]);
    /*dSSI script end*/

    /*paperSSI script start*/
     $columnS=array("record","Q9g","Q26_n1","State");
    $mq=query_marge($time,$columnS);
    $paperSSI=mysqli_query($conn,"SELECT avg(`Q26_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state");
    $paperSSIV=mysqli_fetch_array($paperSSI); 
    $data['paperSSI'] = round($paperSSIV[0]);
    /*paperSSI script end*/

    /*deSSI script start*/
     $columnS=array("record","Q9g","Q27_n1","State");
    $mq=query_marge($time,$columnS);
    $deSSI=mysqli_query($conn,"SELECT avg(`Q27_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN $timeZ AND t.`State` IN $state");
    $deSSIV=mysqli_fetch_array($deSSI); 
    $data['deSSI'] = round($deSSIV[0]);
    /*deSSI script end*/

    echo json_encode($data);


?>