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

	$session=$_REQUEST['session'];
	$class=$_REQUEST['class'];
	$section=$_REQUEST['section'];

	$array = array();
	$status=0;

    $classTeacherArray=array();

    $where = "session='".$session."' ";
    if($class!=""){
        $where .= "and class='$class' ";
    }
    if($section!=""){
        $where .= " and section='$section' ";
    }

    $staff = $db->getRows("select * from staff where session='".$session."' and status=1 order by name");
    if(count($staff) > 0){
        if($class!="" || $section!=""){
            foreach($staff as $teacher){
                $roles = $db->getRows("select * from assign_teacher where $where and teacher_id=$teacher[idno] and school_id=1 and is_class_teacher=1 order by section ASC ");
             $classarray = "";
             if(count($roles)>0){
                  $status = 1;
            foreach($roles as $role){
            $classarray .= "$role[class] - "."$role[section], ";
            }
            array_push($classTeacherArray,["name"=>"$teacher[name]","mobile"=>"$teacher[mobile]","designation"=>"$teacher[designation]","class"=>"$classarray","subject"=>"$teacher[experience]","image"=>"$teacher[photo]"]);

              }
            }
        }

    }

    $array['status'] = $status;
    $array['class_teacher'] = $classTeacherArray;

    echo json_encode($array);
?>