<?php
//include "application/scripts/connect.php";
if(isset($_POST['student_session'])){
define('BASEPATH', "/smartsms/");
define('ENVIRONMENT', "production");
include "../config/database.php";

$hostname = $db['default']['hostname'];
$username = $db['default']['username'];
$password = $db['default']['password'];
$database = $db['default']['database'];
$dbdriver = $db['default']['dbdriver'];


// Create connection
$conn_db = mysqli_connect($hostname, $username, $password, $database);
// Check connection
if (!$conn_db) {
    die("Connection failed: " . mysqli_connect_error());
}
	//student_session,current_term,this_student_id,type,this_comment
	$student_session = $_POST['student_session'];
	$current_term = $_POST['current_term'];
	$this_student_id = $_POST['this_student_id'];
	$type = $_POST['type'];
	$this_comment = $_POST['this_comment'];
	
	$sql = "UPDATE `exam_results_comment` SET
			`$type"."_comment` = '$this_comment'
			WHERE `session` = '$student_session' AND `exam_id` = '$current_term' AND `student_id` = '$this_student_id';
	";
	
//echo $sql;
	
	if($query = mysqli_query($conn_db, $sql)){	
	$div_id = "term_$type". "_$this_student_id";
	if($current_term == 'ANNUAL'){
	$div_id = "aterm_$type". "_$this_student_id";	
	}
	echo "
	<script>
	alert('Comment Updated $current_term');
	document.getElementById('$div_id').setAttribute('value', '$this_comment');
	document.getElementsByClassName('$div_id')[0].setAttribute('value', '$this_comment');
	document.getElementsByClassName('$div_id')[1].setAttribute('value', '$this_comment');

	</script>";
	}
	else{
		echo "<script>alert('failed');</script>";
	}
}




?>  