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

$condX = $_REQUEST['condX'];
$conX = $_REQUEST['conX'];
$tblX = $_REQUEST['tblX'];
$trendStatus = $_REQUEST['trendStatus'];
$trendcondX = $_REQUEST['trendcondX'];

$spcX = "1=1";
$spcX2 = "1=1";

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

if($trendStatus=='false')
{
    $trendsValue = [];
    
    $recordCounter1 = new RecordCounter1($conn,$condX,$tblX,$spcX,$spcX2);
    $recordCounter2 = new RecordCounter2($conn,$condX,$tblX,$spcX,$spcX2);
    $recordCounter3 = new RecordCounter3($conn,$condX,$tblX,$spcX,$spcX2);
    
    $recordCounter1_1 = new RecordCounter1_1(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );

    $recordCounter2_1 = new RecordCounter2_1(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );

    $recordCounter2_2 = new RecordCounterCH_R2_OR(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );

    $data['CH_R1'] = $recordCounter1->countRecords1('CH_R1', range(1,2));
    $data['CH_RF1'] = $recordCounter1->countRecords1('CH_RF1', range(1,3));
    $data['CH_R2'] = $recordCounter2_2->countCH_R2('CH_R2', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,98));
    $data['CH_R4'] = $recordCounter1->countRecords1('CH_R4', range(1,3));
    
    $data['CH_R3'] = $recordCounter1->countRecords1('CH_R3a', array(1,2,3,4,5,6,7,98,99));
    $data['CH_R5'] = $recordCounter1->countRecords1('CH_R5a', array(1,2,3,4,5,6,7,8,9,10,11,12,13,97,98));



    $data['CH_R6'] = $recordCounter1->countRecords1('CH_R6', array(1,2,99));
    $data['CH_R7'] = $recordCounter1->countRecords1('CH_R7', array(1,2,3,4,5,6,7,8,9,99));
    $data['CH_R8'] = $recordCounter1->countRecords1('CH_R8', array(1,2,3,99));
    $data['CH_R_C8'] = $recordCounter1->countRecords1('CH_R_C8', array(1,2,3,4,5,99));


    $data['CH_R_C11'] = $recordCounter2->countRecords2('CH_R_C11', range(1,7));
    $data['CH_R_C12'] = $recordCounter1->countRecords1('CH_R_C12', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,98));
    $data['CH_R_C15'] = $recordCounter1->countRecords1('CH_R_C15', array(1,2,3));
    
    $data['CH_C16'] = $recordCounter3->countRecords3('CH_C16', range(1,9));
    $data['CH_C17'] = $recordCounter1->countRecords1('CH_C17', range(1,3));
    $data['CH_C18'] = $recordCounter1->countRecords1('CH_C18', array(1,2,3,4,98,99));
    $data['CH_C19'] = $recordCounter2->countRecords2('CH_C19', array(1,2,3,4,5,6,7,8,9,10,98,99));
    $data['CH_C20'] = $recordCounter1->countRecords1('CH_C20', array(1,2,3));
    
    $data['S13_1'] = $recordCounter1->countRecords1('S13_1', array(1,2,3,4,5,6,7));    
    
}

else
{
    $trendsValue = [1,2,3,4,90,91];
    $recordCounter1 = new RecordCounter1($conn,$trendcondX,$tblX,$spcX,$spcX2,$trendStatus,$trendsValue);
    $recordCounter2 = new RecordCounter2($conn,$trendcondX,$tblX,$spcX,$spcX2,$trendStatus,$trendsValue);
    $recordCounter3 = new RecordCounter3($conn,$trendcondX,$tblX,$spcX,$spcX2,$trendStatus,$trendsValue);
    $recordCounter1_1 = new RecordCounter1_1(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );
    $recordCounter2_1 = new RecordCounter2_1(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );

    $recordCounter2_2 = new RecordCounterCH_R2_OR(
        $conn,
        $trendcondX,
        $tblX,
        $spcX,
        $spcX2,
        $trendStatus,
        $trendsValue
    );
    
    $data['CH_R1'] = $recordCounter1->countRecords1('CH_R1', range(1,2));
    $data['CH_RF1'] = $recordCounter1->countRecords1('CH_RF1', range(1,3));
    $data['CH_R2'] = $recordCounter2_2->countCH_R2('CH_R2', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,98));
    $data['CH_R4'] = $recordCounter1->countRecords1('CH_R4', range(1,3));
    
    $data['CH_R3'] = $recordCounter1->countRecords1('CH_R3a', array(1,2,3,4,5,6,7,98,99));
    $data['CH_R5'] = $recordCounter1->countRecords1('CH_R5a', array(1,2,3,4,5,6,7,8,9,10,11,12,13,97,98));



    $data['CH_R6'] = $recordCounter1->countRecords1('CH_R6', array(1,2,99));
    $data['CH_R7'] = $recordCounter1->countRecords1('CH_R7', array(1,2,3,4,5,6,7,8,9,99));
    $data['CH_R8'] = $recordCounter1->countRecords1('CH_R8', array(1,2,3,99));
    $data['CH_R_C8'] = $recordCounter1->countRecords1('CH_R_C8', array(1,2,3,4,5,99));

    
    $data['CH_R_C11'] = $recordCounter2->countRecords2('CH_R_C11', range(1,7));
    $data['CH_R_C12'] = $recordCounter1->countRecords1('CH_R_C12', array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,98));
    $data['CH_R_C15'] = $recordCounter1->countRecords1('CH_R_C15', array(1,2,3));
    
    $data['CH_C16'] = $recordCounter3->countRecords3('CH_C16', range(1,9));
    $data['CH_C17'] = $recordCounter1->countRecords1('CH_C17', range(1,3));
    $data['CH_C18'] = $recordCounter1->countRecords1('CH_C18', array(1,2,3,4,98,99));
    $data['CH_C19'] = $recordCounter2->countRecords2('CH_C19', array(1,2,3,4,5,6,7,8,9,10,98,99));
    $data['CH_C20'] = $recordCounter1->countRecords1('CH_C20', array(1,2,3));
    
    $data['S13_1'] = $recordCounter1->countRecords1('S13_1', array(1,2,3,4,5,6,7));
}


echo json_encode($data);

?>