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

    function addSession($term, $year, $end_year, $begin, $end, $added_by, $added_on)
    {
        include $this->connLink;

        $add=$connect->query("INSERT INTO session (term, year, end_year, begin, end, added_by, added_on)
        VALUES('$term', '$year', '$end_year,', '$begin', '$end', '$added_by', '$added_on')");
        if($add)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

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

    function getAllSession()
    {
        include $this->connLink;
        $sessions=array();
        $getS=$connect->query("SELECT * FROM session ORDER BY id DESC");
        while($session=$getS->fetch_assoc())
        {
            array_push($sessions, $session);
        }
        return $sessions;
    }
    function findSession($year, $term)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM session WHERE year='$year' AND term='$term'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    function findSessionById($id)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM session WHERE id='$id'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    function updateSession($term, $year, $end_year, $begin, $end, $session_id)
    {
        include $this->connLink;
        $update=$connect->query("UPDATE session SET term='$term', year='$year', end_year='$end_year', begin='$begin', end='$end' WHERE id='$session_id'");
        return $update;
        
    }
}
?>