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

$data = array();
$rangeXX = array(3);

$conX = $_REQUEST['conX'];
$condX = $_REQUEST['condX'];
$tblX = $_REQUEST['tblX'];
$spcX = "1=1";

if ($conX == 1) {
    $condX = "1=1";
}

$stats = new ConsumptionStats($conn, $quarter, $condX);
$stats2 = new CountryConsumptionStats($conn, $country4X, $condX);

$QuarterWiseCounterRecord = new QuarterWiseCounter($conn,$condX,$tblX,$spcX,$quarter);
$CounteryWiseCounterRecord = new CountryWiseCounter($conn,$condX,$tblX,$spcX,$country4X);
$CounteryWiseCounterRecordX = new CountryWiseCounterX($conn,$condX,$tblX,$spcX,$country4X);

$QuarterWiseCounterRecord2 = new QuarterWiseCounter2($conn,$condX,$tblX,$spcX,$quarter);
$CounteryWiseCounterRecord2 = new CountryWiseCounter2($conn,$condX,$tblX,$spcX,$country4X);

$QuarterWiseCounterRecord3 = new QuarterWiseCounter3($conn,$condX,$tblX,$spcX,$quarter);
$CounteryWiseCounterRecord3 = new CountryWiseCounter3($conn,$condX,$tblX,$spcX,$country4X);

// Consumption Funnel
$data['ConsumptionQuarter'] = $stats->calculate("S11_", $rangeXX);
$data['ConsumptionCountry'] = $stats2->calculate2("S11_", $rangeXX);

// Frequency of Consumption
$data['S13_3Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('S13_3', array(1,2,3,54,55));
$data['S13_3Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('S13_3', array(1,2,3,54,55));

// Sub-Categories
$data['CM_C2Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C2', array(1,2,3,4,99));
$data['CM_C2Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C2', array(1,2,3,4,99));

// How is it Consumed?
$data['CM_C5Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C5', array(1,60,4,5));
$data['CM_C5Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C5', array(1,60,4,5));

// Accompanied with…
$data['CM_C10Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C10', array(1,2,3,4));
$data['CM_C10Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C10', array(1,2,3,4));

// Temperature of Milk
$data['CM_C4bQuarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C4b', array(1,2));
$data['CM_C4bCountry'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C4b', array(1,2));

// Packaging Size
$data['CM_C7Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C7', array(1,2));
$data['CM_C7Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C7', array(1,2));

// Packaging Type
$data['CM_C6Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C6', array(1,2,3,4,5,6));
$data['CM_C6Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C6', array(1,2,3,4,5,6));

// Time of Consumption
$data['CM_C8Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C8', array(1,2,3,4,5));
$data['CM_C8Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C8', array(1,2,3,4,5));

// Place of Consumption
$data['CM_C9Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C9', array(1,2,3,4,5,6,7));
$data['CM_C9Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C9', array(1,2,3,4,5,6,7));

// Consumed Alone vs. with others
$data['CM_C11Quarter'] = $QuarterWiseCounterRecord2->QuarterWiseCounterRecords2('CM_C11', range(1,7));
$data['CM_C11Country'] = $CounteryWiseCounterRecord2->CountryWiseCounterRecords2('CM_C11', range(1,7));

// Reason for Consumption
$data['CM_C12Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C12', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));
$data['CM_C12Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C12', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));

// Change in personal Consumption
$data['CM_C15Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C15', array(1,2,3));
$data['CM_C15Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C15', array(1,2,3));

// Purchase in Household Role in purchasing
$data['CM_C17Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C17', range(1,3));
$data['CM_C17Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C17', range(1,3));


// Who Purchases
$data['CM_C18Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C18', array(1,2,3,4));
$data['CM_C18Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C18', array(1,2,3,4));

// Purchase Channel
$data['CM_C17_1Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C17_1', array(1));
$data['CM_C17_1Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C17_1', array(1));

$data['CM_C19Quarter'] = $QuarterWiseCounterRecord2->QuarterWiseCounterRecords2('CM_C19', array(5,6,1,3,10,9,7,4,8,2));
$data['CM_C19Country'] = $CounteryWiseCounterRecord2->CountryWiseCounterRecords2('CM_C19', array(5,6,1,3,10,9,7,4,8,2));

// Change in Household Consumption
$data['CM_C20Quarter'] = $QuarterWiseCounterRecord->QuarterWiseCounterRecords('CM_C20', array(1,2,3));
$data['CM_C20Country'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('CM_C20', array(1,2,3));

$data['CM_C16Quarter'] = $QuarterWiseCounterRecord3->QuarterWiseCounterRecords3('CM_C16', range(1,9));
$data['CM_C16Country'] = $CounteryWiseCounterRecord3->CountryWiseCounterRecords3('CM_C16', range(1,9));

// Age

$data['HAGE'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('HAGE', array(2,3,4,5,6));

// Education

$data['P4'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('P4', array(2,3,4,5,6));

// Dietry Restriction

$data['S10'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('S10', array(1,2,3));

// Occupation

$data['P5'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('P5', array(1,2,3,33,6,7,32));

// Income

$data['S7'] = $CounteryWiseCounterRecordX->CountryWiseCounterRecordsX('S7', array(91,92,93,94,95,96));

// Relationship

$data['P1'] = $CounteryWiseCounterRecord->CountryWiseCounterRecords('P1', array(1,2,3,4,5));

// People living in household

echo json_encode($data);
?>
