<?php
/****************************************
/*  Author 	: Kvvaradha
/*  Module 	: Extended HRM
/*  E-mail 	: admin@kvcodes.com
/*  Version : 1.0
/*  Http 	: www.kvcodes.com
*****************************************/

$page_security = 'HR_EMPL_INFO';
$path_to_root="../../..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
add_access_extensions();

simple_page_mode(true);


if (isset($_GET['empl_id']))
	$_POST['empl_id'] = $_GET['empl_id'];

$empl_id = get_post('empl_id');

if (list_updated('empl_id')) {	
	$Ajax->activate('approsisal');	
}

if ($Mode == 'ADD_ITEM' && can_process()) {
		
	Insert('kv_empl_appraisal', array('user_id' => $_POST['user_id'],'empl_id'=>$_POST['empl_id'], 'description' => $_POST['description'], 'date' => array($_POST['date'], 'date'), 'status' => $_POST['status']));
		display_notification(_("A new Comment Added Successfully"));
		$Mode = 'RESET';
	}

if ($Mode=='UPDATE_ITEM'){
	Update('kv_empl_appraisal', array( 'id' => $_POST['selected_id']), array('user_id' => $_POST['user_id'], 'description' => $_POST['description'],  'date' => array($_POST['date'], 'date'), 'status' => $_POST['status']) );
		display_notification(_("The Selected Comment Updated Successfully"));
		$Mode = 'RESET';
	}
if ($Mode == 'Delete'){
		if (Delete('kv_empl_appraisal', array('id' => $selected_id))) {	
			display_notification(_("The Selected Comment Deleted Successfully"));
		}
		$Mode = 'RESET';
	}
function can_process(){
		/*if (strlen($_POST['user_id']) == 0) {
			display_error(_("The comment Person name cannot be empty."));
			set_focus('user_id');
			return false;
		}*/
		if (strlen($_POST['description']) == 0) {
			display_error(_("Description cannot be empty."));
			set_focus('description');
			return false;
		}
		if (!is_date(@$_POST['date'])) {
			display_error(_("Invalid Date."));
			set_focus('grade');
			return false;
		}
		return true; 
	}

	// function db_read() {
	// 	return GetRow('kv_empl_appraisal', array('type_id' => $this->entity));
	// }
	
	function delete_check() {
		return true;
	}

	//	Delete all degree for degree in current class/entity


if ($Mode == 'RESET'){	
	unset($_POST['description']);
	$selected_id = -1;
	$Ajax->activate('Comment_Details');
}

$degree = GetDataJoin('kv_empl_appraisal AS sal', array( 
	0 => array('join' => 'LEFT', 'table_name' => 'users AS user', 'conditions' => 'user.id= sal.user_id')),
	array('user.real_name, sal.description, sal.date, sal.id, sal.status'),['empl_id' => $empl_id]);		
div_start('appraisal');
		start_form();
		start_table(TABLESTYLE, "width=70%");

		$th = array( _("Name"), _("Comment"), _("Rating"), _("Date"),  "", "");	
		table_header($th);	
		if(!empty($degree))	
			foreach($degree as $de) {				
				//label_cell($de['id']);					
				label_cell($de['real_name']);
				label_cell(nl2br($de['description']));
				label_cell($de['status']);
				label_cell(sql2date($de['date']));		
					
				edit_button_cell("Edit".$de['id'], _("Edit"));
	 			delete_button_cell("Delete".$de['id'], _("Delete"));
				end_row();	
			}
		end_table(1);

		div_start('Comment_Details');	
		start_outer_table(TABLESTYLE);
	
		table_section(1);
		table_section_title(_("Comment Detail"));

		if($selected_id != -1) {
			if($Mode == 'Edit')	{
			$de = GetRow('kv_empl_appraisal', array( 'id' => $selected_id));	
			$_POST['date'] = sql2date($de['date']);
			
			$_POST['description'] = $de['description'];
			$_POST['status'] = $de['status'];
			$_POST['user_id'] = $de['user_id'];		
			hidden('user_id', $_POST['user_id']);
			hidden('selected_id',$selected_id);
			label_row(_("Name")." :", GetSingleValue('users', 'real_name', array('id' => get_post('user_id'))));
		}
		}else{
			hidden('user_id', $_SESSION['wa_current_user']->user);
			label_row(_("Name")." :", $_SESSION['wa_current_user']->name);
		}		
		
		textarea_row(_("Comment")." :", 'description', null, 45, 8);			
		number_list_row(_("Rating"), 'status', null, 1, 10);
		hidden('date', Today());				
		//hidden('status', 0);
		
		end_outer_table(1);	
		submit_add_or_update_center($selected_id == -1, '', 'both');
		
		div_end();
end_form();
end_page();

?>