<?php
include("../../db.php");
//header("Access-Control-Allow-Origin: * ");
header('Content-Type: application/json');

$session = $_REQUEST['session'];
$teacher_id = $_REQUEST['teacher_id'];
$array = array();
$status = 0;

$classArray = array();
$sectionArray = array();
$cls_secArray = array();

$tableinfo = $db->getRow("select * from tbl_info");

if ($tableinfo[remarks_role_ctr] == 1) {

    $allClasses = $db->getRows("select * from class where school_id=1 ");
    if (count($allClasses) > 0) {
        $status = 1;

        foreach ($allClasses as $class) {
            $classArray[] = $class['class'];
        }
    }

    $allSection = $db->getRows("select * from section where school_id=1 ");
    if (count($allSection) > 0) {
        $status = 1;
        foreach ($allSection as $section) {
            $sectionArray[] = $section['name'];
        }
    }

}


if ($tableinfo[remarks_role_ctr] == 2) {
    $allClasses = $db->getRows("select * from remarks_role where teacher_id=$teacher_id group by class ");
    if (count($allClasses) > 0) {
        $status = 1;
        foreach ($allClasses as $class) {
            $classArray[] = $class['class'];
        }
    }

    $allSection = $db->getRows("select * from section where school_id=1 ");
    if (count($allSection) > 0) {
        $status = 1;
        foreach ($allSection as $section) {
            $sectionArray[] = $section['name'];
        }
    }

    $allClasses1 = $db->getRows("select id,class,section from remarks_role where teacher_id=$teacher_id and school_id=1 order by class ");
    if (count($allClasses) > 0) {
        $status = 1;
        foreach ($allClasses1 as $class) {
            array_push($cls_secArray, ["id" => $class['id'], "class" => $class['class'], "section" => $class['section']]);
        }
    }

}


$exam_name_array = array();
$exam_name = $db->getRows("SELECT name FROM examname");
foreach ($exam_name as $item_data) {
    $exam_name_array[] = $item_data['name'];
}


$array['class'] = $classArray;
$array['section'] = $sectionArray;
$array['class_section'] = $cls_secArray;

$array['exam_name'] = $exam_name_array;

$array['remark_list'] = array('Please select remark', 'Excellent', 'Good', 'Average', 'Can do better', 'Needs improvement');

echo json_encode(array("status" => "$status", "remarks_ctrl" => $tableinfo[remarks_role_ctr], "data" => $array));
