$SUBJECT = 0;
    $STUDENT_ID = 1;
    $NAME = 2;
    $GRADE = 3;
    //SUBJECT
    $subject_code = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0, 2)->getValue();
    $subject = Subject::get_by_sql("SELECT * FROM tbl_subjects WHERE code = '" . $subject_code . "'")[0];
    if ($subject) {
        $subject_id = Subject::get_by_sql("SELECT * FROM tbl_subjects WHERE code = '" . $subject_code . "'")[0]->id;
        for ($row = 2; $row <= $highestRow; $row++) {
            $student_id = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($STUDENT_ID, $row)->getValue();
            $grade = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($GRADE, $row)->getValue();
            $student = Student::get_by_id($student_id);
            if ($student) {
                $grades = Grade::get_by_sql("SELECT * FROM tbl_student_grades WHERE subject_id = '" . $subject_id . "' AND student_id = " . $student_id)[0];
                if ($grades) {
                    $grades->grade = $grade;
                    $grades->update();
                } else {
                    $newgrades = new Grade();
                    $newgrades->grade = $grade;
                    $newgrades->student_id = $student_id;
                    $newgrades->subject_id = $subject_id;
                    $newgrades->create();
                }
            }
        }
    } else {
        echo "*********SUBJECT CODE NOT FOUND*********";
    }
}
    array_push($student_subjects, Subject::get_by_id($student_subject->subject_id));
}
$warnings = "";
foreach ($subject_ids as $id) {
    $thestudent = Student::get_by_id($student_id);
    $thestudent->semester = Subject::get_by_id($id)->semester;
    $thestudent->update();
    if (Grade::exists($id, $student_id)) {
        $newgrade = Grade::get_by_subj_stud($id, $student_id);
        $newgrade->delete();
    }
    $newgrade = new Grade();
    $newgrade->subject_id = $id;
    $newgrade->student_id = $student_id;
    $newgrade->grade = 0;
    $newgrade->create();
    $pre_subject = Subject::get_by_id($id);
    if (!EvaluatedSubject::exists($id, $student_id)) {
        $grade = Grade::get_by_subj_stud($pre_subject->id, $student_id);
        $gradepre = Grade::get_by_subj_stud($pre_subject->prereq_subject_id, $student_id);
        if (has_prerequisite($pre_subject->prereq_subject_id, $student_subjects)) {
            if ($gradepre != null) {
                if (Grade::get_by_subj_stud($pre_subject->prereq_subject_id, $student_id)->grade <= 74) {
                    $warnings .= "Cannot add " . $pre_subject->code . " because it's previous subject:" . Subject::get_by_id($pre_subject->prereq_subject_id)->code . " is failed\n\n";
                } else {
                    $eval_subject = new EvaluatedSubject();
                    $eval_subject->student_id = $student_id;
                    $eval_subject->subject_id = $id;
                    $eval_subject->create();
                }
            }
if (!$session->is_logged_in()) {
    redirect_to("index.php");
}
$id = $_POST['id'];
$subject_id = $_POST['subject_id'];
$student_id = $_POST['student_id'];
$grades = $_POST['grade'];
$operator = $_POST['oper'];
if ($operator == 'add') {
    $rows = Grade::get_by_sql("SELECT * FROM " . T_STUDENT_GRADES . " WHERE " . C_GRADE_SUBJECT_ID . "=" . $subject_id . " AND " . C_GRADE_STUDENT_ID . "=" . $student_id);
    if (count($rows) > 0) {
        die("exists");
    }
    $grade = new Grade();
    $grade->grade = $grades;
    $grade->subject_id = $subject_id;
    $grade->student_id = $student_id;
    $grade->create();
} else {
    if ($operator == 'edit') {
        $grade = Grade::get_by_id($id);
        $grade->grade = $grades;
        $grade->subject_id = $subject_id;
        $grade->student_id = $student_id;
        $grade->update();
    } else {
        if ($operator == 'del') {
            Grade::get_by_id($id)->delete();
        }
    }
}