<?php
include "../config.php";
include "classes.php";

$data = array();
$finalNPS = array();
$condX = $_REQUEST['condX'];
$conX = $_REQUEST['conX'];
$normalmonthX = $_REQUEST['normalmonthX'];
$vocMonth = $_REQUEST['vocMonth'];

$category = array();

$domainDropC3valX = $_REQUEST['domainDropC3valX'];
$domainLabelX = $_REQUEST['domainLabelX'];

if($domainDropC3valX == "2")
{
    $column_name = 'Q20aN_';
    $range_arr = array(1);
}
else if($domainDropC3valX == "3")
{
    $column_name = 'Q20aN_';
    $range_arr = array(2);
}
else if($domainDropC3valX == "4")
{
    $column_name = 'Q20aN_';
    $range_arr = array(3);
}
else if($domainDropC3valX == "5")
{
    $column_name = 'Q20aN_';
    $range_arr = array(4);
}
else if($domainDropC3valX == "6")
{
    $column_name = 'Q20aN_';
    $range_arr = array(5);
}
else if($domainDropC3valX == "7")
{
    $column_name = 'Q20aN_';
    $range_arr = array(6);
}
else if($domainDropC3valX == "8")
{
    $column_name = 'Q20aN_';
    $range_arr = array(7);
}
else if($domainDropC3valX == "9")
{
    $column_name = 'Q20aN_';
    $range_arr = array(8);
}
else if($domainDropC3valX == "10")
{
    $column_name = 'Q20aN_';
    $range_arr = array(9);
}
else if($domainDropC3valX == "11")
{
    $column_name = 'Q20aN_';
    $range_arr = array(10);
}
else if($domainDropC3valX == "12")
{
    $column_name = 'Q20aN_';
    $range_arr = array(11);
}

$brandX2L = ["FK","AZ","MS"];
$nps_cx = ["A","P","N","D"];
$nps3 = new NPS3($conn,$condX);
$data['CurrentNPS'] = $nps3->npsCalculate3('Q20aN_',$range_arr,$brandX2,$vocMonth);

foreach($brandX2L as $key => $value)
{
    $category2 = array();
    foreach($nps_cx as $key2 => $value2)
    {
        $category3 = array();
        if($value2 == "A")
        {
            $npsV = "(1,2,3,4,5,9)";
        }
        else if($value2 == "P")
        {
            $npsV = "(4,5)";
        }
        else if($value2 == "N")
        {
            $npsV = "(3,9)";
        }
        else
        {
            $npsV = "(1,2)";
        }
        $q = mysqli_query($conn,"SELECT `category` FROM voc WHERE `domain` = '$domainLabelX' AND `Month` = '$vocMonth' AND `market` = '$value' AND `nps_score` IN $npsV AND $condX ");
        if(mysqli_num_rows($q) > 0){
            while($row = mysqli_fetch_array($q)){
                $var1 = $row['category']; 
                array_push($category3,$var1);
            }
        }
        else
        {
            $category3 = array();
        }
        array_push($category2,$category3);
    }
    array_push($category,$category2);
}
$data['wordcloud'] = $category;

echo json_encode($data);


?>