$grades = Grade::get_by_sql("SELECT * FROM " . T_STUDENT_GRADES . " WHERE " . C_GRADE_STUDENT_ID . " = " . $student_id . " ORDER BY {$sidx} {$sord} LIMIT {$start} , {$limit}");
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
foreach ($grades as $grade) {
    if (Subject::get_by_id($grade->subject_id)->course_id != $student->course_id) {
        continue;
    }
    if (Subject::get_by_id($grade->subject_id)->semester != $student->semester) {
        //continue;
    }
    $s .= "<row id='" . $grade->id . "'>";
    $s .= "<cell>" . $grade->id . "</cell>";
    $s .= "<cell>" . Subject::get_by_id($grade->subject_id)->code . "</cell>";
    $s .= "<cell>" . Subject::get_by_id($grade->subject_id)->description . "</cell>";
    $s .= "<cell>" . $grade->grade . "</cell>";
    $s .= "<cell>" . Subject::get_by_id($grade->subject_id)->units . "</cell>";
    $s .= "<cell>" . Subject::get_by_id($grade->subject_id)->year . "</cell>";
    if ($grade->grade >= 75) {
        $remarks = "PASSED";
    } else {
        $remarks = "FAILED";
    }
    $s .= "<cell>" . $remarks . "</cell>";
    $s .= "</row>";
}
$s .= "</rows>";
echo $s;
        $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();
                }
            }
        } else {
            $eval_subject = new EvaluatedSubject();
            $eval_subject->student_id = $student_id;
            $eval_subject->subject_id = $id;
            $eval_subject->create();
        }
    }
}
<?php

require_once "../includes/initialize.php";
global $session;
if (!$session->is_logged_in()) {
    //     redirect_to("index.php");
    // }else{
    //     if(isset($session->student_id)){
    redirect_to("index.php");
    //}
}
$subject = Subject::get_by_id($_GET['subject_id']);
?>
<!DOCTYPE HTML>
<html>
<head>

    <meta charset="UTF-8" />
    <title>LasalTech Subject Advising System</title>

    <link href="css/fonts.css" rel="stylesheet"/>
    <link href="css/app.css" rel="stylesheet"/>
    <link href="css/bundledfun-ui/jquery-ui-1.8.23.custom.css" rel="stylesheet" media="screen" />
    <link href="css/ui.jqgrid.css" rel="stylesheet" media="screen" />
    <!-- <link href="css/bootstrap.min.css" rel="stylesheet"/> -->
</head>

<body style="background:#235c88;">

    <div id="main_container">
}
$course_id = Course::get_by_sql("SELECT * FROM " . T_COURSES . " WHERE " . C_COURSE_CODE . "='" . trim($_POST['course_code']) . "'")[0]->id;
$rows = Subject::get_by_sql("SELECT * FROM " . T_SUBJECTS . " WHERE " . C_SUBJECT_CODE . "='" . $_POST['code'] . "' AND " . C_SUBJECT_COURSE_ID . "=" . $course_id);
if ($_POST['oper'] == 'add') {
    if (count($rows) > 0) {
        die("exists");
    }
    $subject = new Subject();
    $subject->code = $_POST['code'];
    $subject->description = $_POST['description'];
    $subject->units = $_POST['units'];
    $subject->prereq_subject_id = $prereq_subject_id;
    $subject->course_id = $course_id;
    $subject->year = $_POST['year'];
    $subject->semester = $_POST['semester'];
    $subject->curriculum_id = $_POST['curriculum_id'];
    $subject->create();
} else {
    if ($_POST['oper'] == 'edit') {
        $subject = Subject::get_by_id($_POST['id']);
        $subject->code = $_POST['code'];
        $subject->description = $_POST['description'];
        $subject->units = $_POST['units'];
        $subject->prereq_subject_id = $prereq_subject_id;
        $subject->course_id = $course_id;
        $subject->year = $_POST['year'];
        $subject->semester = $_POST['semester'];
        $subject->curriculum_id = $_POST['curriculum_id'];
        $subject->update();
    }
}
}
//$student_subjects = Grade::get_by_sql("SELECT * FROM " . T_STUDENT_GRADES . " WHERE ".C_GRADE_STUDENT_ID."=".$student->id);
$future_subjects = Subject::get_by_sql("SELECT * FROM " . T_SUBJECTS . " WHERE " . C_SUBJECT_COURSE_ID . "=" . $student->course_id . " AND " . C_SUBJECT_SEMESTER . " = " . $future_sem . " ORDER BY {$sidx} {$sord} LIMIT {$start} , {$limit}");
// $student_current_subjects = array();
// foreach($student_subjects as $student_subject)
// {
//     array_push($student_current_subjects, Subject::get_by_id($student_subject->subject_id));
// }
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
if (count($future_subjects) > 0) {
    foreach ($future_subjects as $final_subject) {
        $s .= "<row id='" . $final_subject->id . "'>";
        $s .= "<cell>" . $final_subject->id . "</cell>";
        $s .= "<cell>" . $final_subject->code . "</cell>";
        $s .= "<cell>" . $final_subject->description . "</cell>";
        $s .= "<cell>" . $final_subject->units . "</cell>";
        $subject_code = $final_subject->prereq_subject_id == 0 ? "NONE" : Subject::get_by_id($final_subject->prereq_subject_id)->code;
        $s .= "<cell>" . $subject_code . "</cell>";
        $s .= "<cell>" . Course::get_by_id($final_subject->course_id)->code . "</cell>";
        $s .= "<cell>" . $final_subject->semester . "</cell>";
        $s .= "<cell>" . $final_subject->year . "</cell>";
        $s .= "</row>";
    }
}
$s .= "</rows>";
echo $s;
require_once "../includes/initialize.php";
global $session;
if (!$session->is_logged_in()) {
    redirect_to("index.php");
}
$id = $_POST['id'];
$teacher_id = $_POST['teacher_id'];
$subject_id = $_POST['subject_id'];
$operator = $_POST['oper'];
if ($operator == 'add') {
    $object = new TeacherSubject();
    $object->teacher_id = $teacher_id;
    $object->subject_id = $subject_id;
    if (Subject::get_by_id($object->subject_id) != null && User::get_by_id($object->teacher_id) != null) {
        $object->create();
    }
} else {
    if ($operator == 'edit') {
        $object = TeacherSubject::get_by_id($id);
        $object->teacher_id = $teacher_id;
        $object->subject_id = $subject_id;
        if (Subject::get_by_id($object->subject_id) != null && User::get_by_id($object->teacher_id) != null) {
            $object->update();
        }
    } else {
        if ($operator == 'del') {
            TeacherSubject::get_by_id($id)->delete();
        }
    }
}
    $page = $total_pages;
}
$start = $limit * $page - $limit;
if ($start < 0) {
    $start = 0;
}
if (!$sidx) {
    $sidx = 1;
}
$TeacherSubjects = TeacherSubject::get_by_sql("SELECT * FROM " . T_TEACHER_SUBJECTS . " ORDER BY {$sidx} {$sord} LIMIT {$start} , {$limit}");
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
foreach ($TeacherSubjects as $TeacherSubject) {
    $subject = Subject::get_by_id($TeacherSubject->subject_id);
    $teacher = User::get_by_id($TeacherSubject->teacher_id);
    $s .= "<row id='" . $TeacherSubject->id . "'>";
    $s .= "<cell></cell>";
    $s .= "<cell>" . $TeacherSubject->id . "</cell>";
    $s .= "<cell>" . $teacher->id . "</cell>";
    $s .= "<cell>" . $teacher->name . "</cell>";
    $s .= "<cell>" . $subject->id . "</cell>";
    $s .= "<cell>" . $subject->code . "</cell>";
    $s .= "<cell>" . $subject->description . "</cell>";
    $s .= "</row>";
}
$s .= "</rows>";
echo $s;
</style>
<?php 
require_once "../../includes/initialize.php";
$student = Student::get_by_id($_GET['student_id']);
$grades = Grade::get_by_sql("SELECT * FROM " . T_STUDENT_GRADES . " WHERE " . C_GRADE_STUDENT_ID . " = " . $student->id);
$s = "<table>";
$s .= "<tr>";
$s .= "<td>SUBJECT</td>";
$s .= "<td>GRADE</td>";
$s .= "<td>REMARKS</td>";
$s .= "</tr>";
foreach ($grades as $grade) {
    $s .= "<tr>";
    if (Subject::get_by_id($grade->subject_id)->course_id != $student->course_id) {
        continue;
    }
    if (Subject::get_by_id($grade->subject_id)->semester != $student->semester) {
        continue;
    }
    $s .= "<td>" . Subject::get_by_id($grade->subject_id)->code . "</td>";
    $s .= "<td>" . $grade->grade . "</td>";
    if ($grade->grade >= 75) {
        $remarks = "PASSED";
    } else {
        $remarks = "FAILED";
    }
    $s .= "<td>" . $remarks . "</td>";
    $s .= "</tr>";
}
$s .= "</table>";
echo $s;
				<td>UNITS</td>
				<td>PREREQUISITE</td>
				<td>COURSE</td>
				<td>YEAR</td>
				<td>SEMESTER</td>
				<td>CURRICULUM</td>
			</tr>
		</thead>
		<?php 
$subjects = Subject::getByCurriculum($curriculumid);
if (count($subjects) > 0) {
    foreach ($subjects as $subject) {
        $course = Course::get_by_id($subject->course_id);
        $curriculum = Curriculum::get_by_id($subject->curriculum_id);
        if ($subject->prereq_subject_id != "") {
            $prerequisitesubject = Subject::get_by_id($subject->prereq_subject_id);
            if (!$prerequisitesubject) {
                $prerequisitesubject = new Subject();
                $prerequisitesubject->code = "NONE";
            }
        } else {
            $prerequisitesubject = new Subject();
            $prerequisitesubject->code = "NONE";
        }
        if ($subject->semester == 1) {
            $subject->semester = "First";
        } else {
            if ($subject->semester == 2) {
                $subject->semester = "Second";
            }
        }