<?php
require_once 'ConnectionDao.php';
class Admission{
	  private $db = null;
    private $rows = null;
    private $success = false;

    public function __construct() {
        $this->db=ConnectionDao::getDb();
    }



     public function add_student(array $values) {
        $sql = "INSERT INTO student_detail ";
        $fields = array_keys($values);
        $vals = array_values($values);
        $sql .= '(' . implode(',', $fields) . ') ';
        $arr = array();
        foreach ($fields as $f) {
            $arr[] = '?';
        }
        $sql .= 'VALUES (' . implode(',', $arr) . ') ';
        $statement = $this->db->prepare($sql);
        foreach ($vals as $i => $v) {
            $statement->bindValue($i + 1, $v);
        }
        $this->success= $statement->execute();
        return $this->success;
    }

    public function import_students(array $values) {
        $sql = "INSERT INTO student_detail ";
        $fields = array_keys($values);
        $vals = array_values($values);
        $sql .= '(' . implode(',', $fields) . ') ';
        $arr = array();
        foreach ($fields as $f) {
            $arr[] = '?';
        }
        $sql .= 'VALUES (' . implode(',', $arr) . ') ';
        $statement = $this->db->prepare($sql);
        foreach ($vals as $i => $v) {
            $statement->bindValue($i + 1, $v);
        }
        $this->success= $statement->execute();
        return $this->success;
    }
    public function import_staffs(array $values) {
        $sql = "INSERT INTO staff_detail ";
        $fields = array_keys($values);
        $vals = array_values($values);
        $sql .= '(' . implode(',', $fields) . ') ';
        $arr = array();
        foreach ($fields as $f) {
            $arr[] = '?';
        }
        $sql .= 'VALUES (' . implode(',', $arr) . ') ';
        $statement = $this->db->prepare($sql);
        foreach ($vals as $i => $v) {
            $statement->bindValue($i + 1, $v);
        }
        $this->success= $statement->execute();
        return $this->success;
    }
    public function import_staffs_login(array $values) {
        $sql = "INSERT INTO staff_login ";
        $fields = array_keys($values);
        $vals = array_values($values);
        $sql .= '(' . implode(',', $fields) . ') ';
        $arr = array();
        foreach ($fields as $f) {
            $arr[] = '?';
        }
        $sql .= 'VALUES (' . implode(',', $arr) . ') ';
        $statement = $this->db->prepare($sql);
        foreach ($vals as $i => $v) {
            $statement->bindValue($i + 1, $v);
        }
        $this->success= $statement->execute();
        return $this->success;
    }

    public function attendance(array $values) {
        $sql = "INSERT INTO attendance ";
        $fields = array_keys($values);
        $vals = array_values($values);
        $sql .= '(' . implode(',', $fields) . ') ';
        $arr = array();
        foreach ($fields as $f) {
            $arr[] = '?';
        }
        $sql .= 'VALUES (' . implode(',', $arr) . ') ';
        $statement = $this->db->prepare($sql);
        foreach ($vals as $i => $v) {
            $statement->bindValue($i + 1, $v);
        }
        $this->success= $statement->execute();
        return $this->success;
    }

    //  public function add_parent(array $values) {
    //     $sql = "INSERT INTO student_detail ";
    //     $fields = array_keys($values);
    //     $vals = array_values($values);
    //     $sql .= '(' . implode(',', $fields) . ') ';
    //     $arr = array();
    //     foreach ($fields as $f) {
    //         $arr[] = '?';
    //     }
    //     $sql .= 'VALUES (' . implode(',', $arr) . ') ';
    //     $statement = $this->db->prepare($sql);
    //     foreach ($vals as $i => $v) {
    //         $statement->bindValue($i + 1, $v);
    //     }
    //     $this->success= $statement->execute();
    //     return $this->success;
    // }

    //  public function add_doc(array $values) {
    //     $sql = "INSERT INTO student_detail ";
    //     $fields = array_keys($values);
    //     $vals = array_values($values);
    //     $sql .= '(' . implode(',', $fields) . ') ';
    //     $arr = array();
    //     foreach ($fields as $f) {
    //         $arr[] = '?';
    //     }
    //     $sql .= 'VALUES (' . implode(',', $arr) . ') ';
    //     $statement = $this->db->prepare($sql);
    //     foreach ($vals as $i => $v) {
    //         $statement->bindValue($i + 1, $v);
    //     }
    //     $this->success= $statement->execute();
    //     return $this->success;
    // }


    public function update(array $values,$student_id) {
        
            $sql = "UPDATE student_detail SET ";
            $fields = array_keys($values);
            $vals = array_values($values);
            foreach ($fields as $i=>$f) {
            $fields[$i] .= ' = ? ';
            }
            $sql .= implode(',', $fields);
            $sql .= " WHERE student_id = '" .$student_id."' LIMIT 1 ";
            $statement = $this->db->prepare($sql);
            foreach ($vals as $i=>$v) {
            $statement->bindValue($i+1, $v);
            }
           $this->success= $statement->execute();
            return $this->success;

            }

            public function update_guardian(array $values,$student_id) {
        
            $sql = "UPDATE parent_detail SET ";
            $fields = array_keys($values);
            $vals = array_values($values);
            foreach ($fields as $i=>$f) {
            $fields[$i] .= ' = ? ';
            }
            $sql .= implode(',', $fields);
            $sql .= " WHERE student_id = '" .$student_id."' LIMIT 1 ";
            $statement = $this->db->prepare($sql);
            foreach ($vals as $i=>$v) {
            $statement->bindValue($i+1, $v);
            }
           $this->success= $statement->execute();
            return $this->success;

            }

             public function update_attendance(array $values,$attendance_id) {
        
            $sql = "UPDATE attendance SET ";
            $fields = array_keys($values);
            $vals = array_values($values);
            foreach ($fields as $i=>$f) {
            $fields[$i] .= ' = ? ';
            }
            $sql .= implode(',', $fields);
            $sql .= " WHERE attendance_id = '" .$attendance_id."' LIMIT 1 ";
            $statement = $this->db->prepare($sql);
            foreach ($vals as $i=>$v) {
            $statement->bindValue($i+1, $v);
            }
           $this->success= $statement->execute();
            return $this->success;

            }

            public function add_parent(array $values,$student_id) {
        
            $sql = "UPDATE parent_detail SET ";
            $fields = array_keys($values);
            $vals = array_values($values);
            foreach ($fields as $i=>$f) {
            $fields[$i] .= ' = ? ';
            }
            $sql .= implode(',', $fields);
            $sql .= " WHERE student_id = '" .$student_id."' LIMIT 1 ";
            $statement = $this->db->prepare($sql);
            foreach ($vals as $i=>$v) {
            $statement->bindValue($i+1, $v);
            }
           $this->success= $statement->execute();
            return $this->success;

            }


            public function add_doc(array $values,$student_id) {
        
            $sql = "UPDATE student_doc SET ";
            $fields = array_keys($values);
            $vals = array_values($values);
            foreach ($fields as $i=>$f) {
            $fields[$i] .= ' = ? ';
            }
            $sql .= implode(',', $fields);
            $sql .= " WHERE student_id = '" .$student_id."' LIMIT 1 ";
            $statement = $this->db->prepare($sql);
            foreach ($vals as $i=>$v) {
            $statement->bindValue($i+1, $v);
            }
           $this->success= $statement->execute();
            return $this->success;

            }


    public function get_student($student_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE student_id=:student_id LIMIT 1");
        $statement->bindParam(':student_id', $student_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_student_track($track_id) {
        $statement = $this->db->prepare("SELECT track_name FROM track WHERE track_id=:track_id LIMIT 1");
        $statement->bindParam(':track_id', $track_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }



public function get_a_year_name($a_year_id) {
        $statement = $this->db->prepare("SELECT a_year FROM academic_year WHERE a_year_id=:a_year_id LIMIT 1");
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

     public function get_attendance($student_id,$class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT * FROM attendance WHERE student_id=:student_id AND class=:class_id
                                        AND semester_id=:semester_id
                                         AND a_year_id=:a_year_id LIMIT 1");
        $statement->bindParam(':student_id', $student_id);
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_students() {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM student_detail a JOIN class b ON a.class=b.class_id WHERE alumini='no'");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_students_by_from($form_id) {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM student_detail a JOIN class b ON a.class=b.class_id WHERE alumini='no' and form_id=:form_id");
        $statement->bindParam(':form_id',$form_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_class_students($class_id) {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM student_detail a JOIN class b ON a.class=b.class_id WHERE alumini='no' AND a.class=:class_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_student_subjects($class_id) {
        $statement = $this->db->prepare("SELECT a.*,b.*,c.*,d.* FROM class_scheduler a JOIN subject b ON a.subject_id=b.subject_id JOIN core_elective c ON b.core_elective_id=c.core_elective_id JOIN staff_detail d ON a.staff_id=d.staff_id WHERE a.class_id=:class_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_past_students() {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM student_detail a JOIN class b ON a.class=b.class_id WHERE alumini='yes'");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_student_id() {
        $statement = $this->db->prepare("SELECT * FROM student_detail ORDER BY student_id DESC LIMIT 1");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_classes() {
        $statement = $this->db->prepare("SELECT * FROM class");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_detail($class_id) {
        $statement = $this->db->prepare("SELECT * FROM class WHERE class_id=:class_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_forms() {
        $statement = $this->db->prepare("SELECT * FROM form");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_service() {
        $statement = $this->db->prepare("SELECT * FROM service");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_session() {
        $statement = $this->db->prepare("SELECT * FROM track");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    //Accidentals
    public function if_isset($student_id,$class_id,$subject_id,$track_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT * FROM assessment WHERE student_id=:student_id AND class_id=:class_id
                                        AND subject_id=:subject_id AND track_id=:track_id AND semester_id=:semester_id
                                         AND a_year_id=:a_year_id LIMIT 1");
        $statement->bindParam(':student_id', $student_id);
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':subject_id', $subject_id);
        $statement->bindParam(':track_id', $track_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

     public function form_noOf_stds($form_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE form_id=:form_id");
        $statement->bindParam(":form_id",$form_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $statement->rowCount();            
        }
        return $this->success;
    }


    public function class_noOf_stds($class_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE class=:class_id");
        $statement->bindParam(":class_id",$class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $statement->rowCount();            
        }
        return $this->success;
    }



     public function fill_report($class_id,$track_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM assessment a JOIN student_detail b ON a.student_id=b.student_id WHERE a.class_id=:class_id AND a.track_id=:track_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id GROUP BY a.student_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':track_id', $track_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function subject_position($subject_id,$class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT sum(a.total_score) as total_score,a.student_id,a.class_score,a.exam_score,b.* FROM assessment a JOIN student_detail b ON a.student_id=b.student_id WHERE a.class_id=:class_id AND a.subject_id=:subject_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id GROUP BY a.student_id ORDER BY Sum(a.total_score) DESC");
        $statement->bindParam(':subject_id', $subject_id);
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function over_all_subject_position($subject_id,$form_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT sum(a.total_score) as total_score,a.student_id,b.* FROM assessment a JOIN student_detail b ON a.student_id=b.student_id WHERE b.form_id=:form_id AND a.subject_id=:subject_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id GROUP BY a.student_id ORDER BY Sum(a.total_score) DESC");
        $statement->bindParam(':subject_id', $subject_id);
        $statement->bindParam(':form_id', $form_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function overall_position($form_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT sum(a.total_score) as total_score,a.student_id,b.* FROM assessment a JOIN student_detail b ON a.student_id=b.student_id WHERE b.form_id=:form_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id GROUP BY a.student_id ORDER BY Sum(a.total_score) DESC");
        $statement->bindParam(':form_id', $form_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function postion_in_class($class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT sum(a.total_score) as total_score,a.student_id,b.* FROM assessment a JOIN student_detail b ON a.student_id=b.student_id WHERE a.class_id=:class_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id GROUP BY a.student_id ORDER BY Sum(a.total_score) DESC");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }



    public function student_report_core($student_id,$class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT DISTINCT a.*,b.*,c.* FROM assessment a JOIN subject b ON a.subject_id=b.subject_id JOIN core_elective c ON b.core_elective_id=c.core_elective_id  WHERE a.student_id=:student_id AND a.class_id=:class_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id AND c.core_elective_name='CORE'  GROUP BY a.subject_id ORDER BY b.subject_id ");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':student_id', $student_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function class_broad_sheet($class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT sum(a.total_score) as full_score, a.class_score,a.exams_score,a.student_id,b.*,c.* FROM assessment a JOIN subject b ON a.subject_id=b.subject_id JOIN core_elective c ON b.core_elective_id=c.core_elective_id  WHERE  a.class_id=:class_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id ORDER BY a.student_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }



    public function student_report_elective($student_id,$class_id,$semester_id,$a_year_id) {
        $statement = $this->db->prepare("SELECT a.*,b.*,c.* FROM assessment a JOIN subject b ON a.subject_id=b.subject_id JOIN core_elective c ON b.core_elective_id=c.core_elective_id  WHERE a.student_id=:student_id AND a.class_id=:class_id AND a.semester_id=:semester_id AND a.a_year_id=:a_year_id AND c.core_elective_name='ELECTIVE' ORDER BY b.subject_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':student_id', $student_id);
        $statement->bindParam(':semester_id', $semester_id);
        $statement->bindParam(':a_year_id', $a_year_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }




    public function get_subject($subject_id) {
        $statement = $this->db->prepare("SELECT * FROM subject WHERE subject_id=:subject_id LIMIT 1");
        $statement->bindParam(':subject_id', $subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

     public function get_student_house($student_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE student_id=:student_id LIMIT 1");
        $statement->bindParam(':student_id', $student_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

     public function get_house($house_id) {
        $statement = $this->db->prepare("SELECT * FROM house WHERE house_id=:house_id LIMIT 1");
        $statement->bindParam(':house_id', $house_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }



    public function get_teacher($subject_id,$class_id) {
        $statement = $this->db->prepare("SELECT a.*,b.* FROM subject a JOIN class_scheduler b ON a.subject_id=b.subject_id WHERE b.subject_id=:subject_id AND b.class_id=:class_id LIMIT 1");
        $statement->bindParam(':subject_id', $subject_id);
        $statement->bindParam(':class_id', $class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_teacher_details($staff_id) {
        $statement = $this->db->prepare("SELECT * FROM staff_detail WHERE staff_id=:staff_id");
        $statement->bindParam(':staff_id', $staff_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class($class_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE class=:class_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }


    public function search_student($search_term) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE student_name LIKE '%".$search_term."%'");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function student_report($class_id,$student_id) {
        $statement = $this->db->prepare("SELECT * FROM student_detail WHERE class=:class_id AND student_id=:student_id");
        $statement->bindParam(':class_id', $class_id);
        $statement->bindParam(':student_id', $student_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_guardian($student_id) {
        $statement = $this->db->prepare("SELECT * FROM parent_detail WHERE student_id=:student_id");
        $statement->bindParam(':student_id', $student_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_all_core_elective() {
        $statement = $this->db->prepare("SELECT * FROM core_elective");
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_core_elective($subject_id) {
        $statement = $this->db->prepare("SELECT * FROM core_elective subject_id=:subject_id");
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_name($class_id) {
        $statement = $this->db->prepare("SELECT * FROM class WHERE class_id=:class_id");
        $statement->bindParam(":class_id",$class_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_a1($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=80 ");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_b2($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=75 AND round(total_score)<80");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_b3($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=70 AND round(total_score)<75");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_c4($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score) >=65 AND round(total_score)<70");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_c5($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=60 AND round(total_score)<65");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_c6($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=55 AND round(total_score)<60");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_d7($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=50 AND round(total_score)<55");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_e8($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)>=40 AND round(total_score)<50");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_f9($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)<40");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }

    public function get_class_ic($class_id,$subject_id) {
        $statement = $this->db->prepare("SELECT count(subject_id) AS no_of_grades,subject_id FROM assessment WHERE class_id=:class_id AND subject_id=:subject_id AND round(total_score)=''");
        $statement->bindParam(":class_id",$class_id);
        $statement->bindParam(":subject_id",$subject_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }




    public function remove_student($student_id) {
        $statement = $this->db->prepare("DELETE FROM student_detail WHERE student_id=:student_id");
        $statement->bindParam(":student_id",$student_id);
        $statement->execute();
        if ($statement->rowCount() > 0) {
            $this->rows=$statement->fetchAll(\PDO::FETCH_ASSOC);
            return $this->rows;            
        }
        return $this->success;
    }


      }

$admission = new Admission;
?>