<?php
//include "application/scripts/connect.php";

function get_comment($session,$exam_id,$student_id){
define('BASEPATH', "/smartsms/");
define('ENVIRONMENT', "production");
include "application/config/database.php";

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

$database2 = 27686;

// Create connection
$conn_db = mysqli_connect($hostname, $username, $password, $database);
// Check connection
if (!$conn_db) {
    die("Connection failed: " . mysqli_connect_error());
}

	$sql2 = "SELECT * from `exam_results_comment` WHERE session='$session' AND exam_id='$exam_id' AND student_id='$student_id' ORDER BY `id` DESC LIMIT 1;";
	$query2 = mysqli_query($conn_db, $sql2);
		if(mysqli_num_rows($query2) == 0){
		$sql3 = "INSERT INTO `exam_results_comment` (`session`, `exam_id`, `student_id`) VALUES ('$session', '$exam_id', '$student_id');";
		$query3 = mysqli_query($conn_db, $sql3);
		return "";
		}
		else {
			$row = mysqli_fetch_assoc($query2);
			$comment = array();
			$comment['teacher_comment'] = $row['teacher_comment'];
			$comment['head_comment'] = $row['head_comment'];
			return $comment;
		}

}


if(isset($_POST['student_session'])){
	//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'];
	
	$div_id = "term_$type". "_$this_student_id";
	echo "
	<script>
	alert('update alert $this_student_id $this_comment');
	alert('$div_id');
	//$('#$div_id').val('$this_comment');
	//document.body.innerHTML = 'akdhal';
	if(document.getElementById('$div_id').setAttribute('value', '$this_comment')){
		alert('comment successful!');
	}
	</script>";
}




?>  