<?php
include("../../db.php");
header('Content-Type: application/json');

$status = 0;
$class = array();
$sec = array();
$fee = array();
$msg = "Unable to get data..!";

if (isset($_GET['session']) && $_GET['session'] != '') {

    $cls_arr = $db->getRows("select class from class");
    $sec_arr = $db->getRows("select name from section");

    $session = $_GET['session'];

    if ($cls_arr) {
        $status = 1;
        $msg = "Data found";

        foreach ($cls_arr as $item) {
            $class[] = $item['class'];
        }
    }

    if ($sec_arr) {
        $status = 1;
        $msg = "Data found";

        foreach ($sec_arr as $row) {
            $sec[] = $row['name'];
        }
    }

    $fee[0] = "Tuition";
    $fee[1] = "Transport";
    $fee[2] = "Hostel";
    $fee[3] = "Back_dues";

    $feehead = $db->getRows("SELECT DISTINCT name FROM `otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='" . $session . "' ");

    $i = 3;
    foreach ($feehead as $cls) {
        $i++;
        $fee[$i] = $cls['name'];
    }

    $extrafeetype = $db->getRows("select distinct(type) from extrafee_type where school_id='1' and session='" . $session . "'  order by type");
    foreach ($extrafeetype as $ftype) {
        $i++;
        $fee[$i] = $ftype['type'];
    }


    $hostelextra = $db->getRows("SELECT DISTINCT name FROM `hostel_otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='" . $session . "' ");
    foreach ($hostelextra as $cls) {
        $i++;
        $fee[$i] = $cls['name'];
    }

}

$fee_month = $db->getVal("SELECT fee_month FROM tbl_info WHERE id = '1' ");

echo json_encode(array("status" => $status, "data" => array("class" => $class, "section" => $sec, "fee_type" => $fee, "fee_head" => getFeeHead($fee_month)), "msg" => $msg));

/////////////////

function getFeeHead($fee_month){

    $fee_title = array();

    switch ($fee_month) {
        case 1:
        case 9:
            $fee_title = array("Please choose month","April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February", "March");
            break;
        case 2:
            $fee_title = array("Please choose month", "July", "August", "September", "October", "November", "December", "January", "February", "March", "April", "May", "June");
            break;
        case 5:
            $fee_title = array("Please choose instalment", "Instalment-1", "Instalment-2", "Instalment-3", "Instalment-4");
            break;
        case 6:
            $fee_title = array("Please choose instalment", "Instalment-1", "Instalment-2", "Instalment-3", "Instalment-4", "Instalment-5", "Instalment-6", "Instalment-7", "Instalment-8", "Instalment-9", "Instalment-10", "Instalment-11", "Instalment-12");
            break;
        case 7:
            $fee_title = array("Please choose quarter", "Quarter-1", "Quarter-2", "Quarter-3", "Quarter-4");
            break;
        case 8:
            $fee_title = array("Please choose month", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February");
            break;
        default:
    }

    return $fee_title;

}