<?php
//include "application/scripts/connect.php";
if(isset($_POST['student_session'])){
//echo "<script>alert('collected1!');</script>";		
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'];
	$term_started = $_POST['term_started'];
	$term_ended = $_POST['term_ended'];
	$next_begin = $_POST['next_begin'];
	$foot_note = $_POST['foot_note'];
	
	$sql = "UPDATE `exam_settings` SET
			`term_started` = '$term_started',
			`term_ended` = '$term_ended',
			`next_begin` = '$next_begin',
			`foot_note` = '$foot_note'
			WHERE `session` = '$student_session' AND `exam_id` = '$current_term';
	";
	
//echo $sql;
	
	if($query = mysqli_query($conn_db, $sql)){	

	echo "
	<script>
	alert('Term settings Updated!');
	
	all_term_started = document.getElementsByClassName('term_started');
	all_term_ended = document.getElementsByClassName('term_ended');
	all_next_begin = document.getElementsByClassName('next_begin');
	all_foot_note = document.getElementsByClassName('foot_note');
	
	for(var t = 0; t < all_term_started.length; t++){
		all_term_started[t].innerHTML = '$term_started';
		all_term_ended[t].innerHTML = '$term_ended';
		all_next_begin[t].innerHTML = '$next_begin';
		all_foot_note[t].innerHTML = '$foot_note';
	}
	
	/*
	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>";
	}
}




?>  