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

    function addAttendance($student_id, $added_by, $added_uid, $sessionId, $attendance, $reason, $attendance_date, $time)
    {
        include $this->connLink;

        $add=$connect->query("INSERT INTO attendance (student_id, added_by, added_uid, session_id, attendance, reason, attendance_date, time)
        VALUES('$student_id', '$added_by', '$added_uid', '$sessionId', '$attendance', '$reason', '$attendance_date', '$time')");
        return $add;
    }

    function getAttendance($student_id,$date)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM attendance WHERE student_id='$student_id' AND attendance_date='$date'")->fetch_assoc();
        return $getT;
    }

    function getAllAttendance()
    {
        include $this->connLink;
        $attendances=array();
        $getS=$connect->query("SELECT * FROM attendance");
        while($attendance=$getS->fetch_assoc())
        {
            array_push($attendances, $attendance);
        }
        return $attendances;
    }
    function findAttendance($student_id, $date)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM attendance WHERE student_id='$student_id' AND attendance_date='$date'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
    function updateAttendance($student_id, $attendance, $reason, $attendance_date)
    {
        include $this->connLink;
        $update=$connect->query("UPDATE attendance SET attendance='$attendance', reason='$reason' WHERE student_id='$student_id' AND attendance_date='$attendance_date'");
        return $update;
    }
}
?>