<?php
session_start();
include "../class/class.MySQL.php";
$db=new MySQL();
$action = $_REQUEST['action'];
$emp_id = $_REQUEST['emp_id'];
if($action == 'fill_qstns'){
	$data=array();
	$data['answer'] = $_POST['qns_answer_area'];
	$data['emp_id'] = $_POST['emp_id'];
	$data['question_id'] = $_POST['qst_id'];
	
	if(!empty($data['question_id'])){
		$count = count($data['question_id']);
		for($i=0;$i<$count;$i++){
			//echo "<br />Qst ID is : ".$data['question_id'][$i];
			//echo "<br />Ans is : ".$data['answer'][$i];	
			//echo "<br />Emp ID is : ".$emp_id;	
			//echo "<br />check:SELECT * FROM performance WHERE emp_id = '".$emp_id."' AND perform_qn_id = '".$data['question_id'][$i]."' ";
			$query1 = mysql_query("SELECT * FROM performance WHERE emp_id = '".$emp_id."' AND perform_qn_id = '".$data['question_id'][$i]."' ");
			$query1_num_rows = mysql_num_rows($query1);
			if($query1_num_rows > 0){
				$update_sql = "UPDATE performance SET answer = '".addslashes($data['answer'][$i])."',answered_modified_date='".date('Y-m-d')."' WHERE emp_id = '".$emp_id."' AND perform_qn_id = '".$data['question_id'][$i]."'";	
				$query1 = mysql_query($update_sql);	
			}else{
				if($data['answer'][$i])
				{
					$insert_sql = "INSERT INTO performance (perform_qn_id, emp_id, answer,answered_date) VALUES('".$data['question_id'][$i]."', '".$emp_id."', '".addslashes($data['answer'][$i])."','".date('Y-m-d')."' )";
					$query1 = mysql_query($insert_sql);	
				}
			}
		}
	}
	
	
}

?>