<?php
class ClassRoom
{
    public $connLink;
    function __construct($url="../manage/connection.php")
    {
        $this->connLink=$url;
    }

    function addClassRoom($section, $class_no, $teacher_id, $added_by, $added_on)
    {
        include $this->connLink;

        $add=$connect->query("INSERT INTO classroom (section, class_no, teacher_id, added_by, added_on)
        VALUES('$section', '$class_no', '$teacher_id', '$added_by', '$added_on')");
        if($add)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function getClassRoom($id)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM classroom WHERE id='$id'")->fetch_assoc();
        return $getT;
    }

    function getAllClasses()
    {
        include $this->connLink;
        $classrooms=array();
        $getS=$connect->query("SELECT * FROM classroom");
        while($classroom=$getS->fetch_assoc())
        {
            array_push($classrooms, $classroom);
        }
        return $classrooms;
    }

    function getClassesByTeacher($tid)
    {
        include $this->connLink;
        $classrooms=array();
        $getS=$connect->query("SELECT * FROM classroom WHERE teacher_id='$tid'");
        while($classroom=$getS->fetch_assoc())
        {
            array_push($classrooms, $classroom);
        }
        return $classrooms;
    }

    function getAllClassStudents($classRid)
    {
        include $this->connLink;
        $stud=array();
        $getS=$connect->query("SELECT * FROM students WHERE classroom_id='$classRid'");
        while($student=$getS->fetch_assoc())
        {
            $student['reg_no']="KBS/".substr(date('Y',$student['added_on']),2,3)."/".$student['id'];
            array_push($stud, $student);
        }
        return $stud;
    } 
    function findClassRoom($id)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM classroom WHERE id='$id'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    function findClass($class_no,$section, $class_group)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM classroom WHERE class_no='$class_no' AND section='$section' AND class_group='$class_group'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function findClassById($id)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM classroom WHERE id='$id'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function updateClassRoom($section, $class_no, $class_group, $teacher_id, $classroom_id)
    {
        include $this->connLink;
        $update=$connect->query("UPDATE classroom SET section='$section', class_no='$class_no', teacher_id='$teacher_id', class_group='$class_group' WHERE id='$classroom_id'");
        return $update;
        
    }
}
?>