<?php 
session_start();
require '../dao/Assessment.php';
require '../dao/Global.php';
$success = "";
$msg = "";
$err = "";

if (isset($_POST['set_scores'])) {
	$student_id = $_POST['student_id'];
	$subject_id = $_POST['subject_id'];
	$class_id = $_POST['class_id'];
	$class_score = $_POST['class_score'];
	$class_score2 = (30/100)*$class_score;
	$exam_score = $_POST['exam_score'];
	$exam_score2 = (70/100)*$exam_score;
	$total_score = $exam_score2 + $class_score2;
	$staff_id = $_SESSION['staff_id'];
	//Globals
	$globals = $global->get_all_globals();
	$a_year_id = $globals[0]['a_year_id'];
	$semester_id = $globals[0]['semester_id'];
	$track_id = $globals[0]['track_id'];
	$date_created = date("Y-m-d");
	$data = array("student_id"=>$student_id,
				  "subject_id"=>$subject_id,
				  "class_id"=>$class_id,
				  "class_score"=>$class_score,
				  "exam_score"=>$exam_score,
				  "total_score"=>$total_score,
				  "staff_id"=>$staff_id,
				  "a_year_id"=>$a_year_id,
				  "semester_id"=>$semester_id,
				  "track_id"=>$track_id,
				  "date_created"=>$date_created
				);
	$isset = $assessment->if_isset($student_id,$class_id,$subject_id,$track_id,$semester_id,$a_year_id);
	if (!$isset) {
		$success = $assessment->assess($data);
	}else{
		$ass_id = $isset[0]['ass_id'];
		$success = $assessment->update($data,$ass_id);
	}
	
	if ($success) {
		echo 0;
	}else{
		echo 1;
	}
	


}

