<?php
/****************************************
/*  Author 	: Kvvaradha
/*  Module 	: Enhanced HRM
/*  E-mail 	: admin@kvcodes.com
/*  Version : 1.0
/*  Http 	: www.kvcodes.com
*****************************************/
$page_security = 'SA_OPEN';
$path_to_root="../../..";
include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include($path_to_root . "/modules/ExtendedHRM/includes/Payroll.inc" );
page(_("Indemnity Settings"));

CheckEmptyResult('kv_empl_allowances', sprintf(_("There is no allowances in this system. Kindly Open '%s' to update it"), "<a href='".$path_to_root."/modules/ExtendedHRM/manage/allowances.php'>"._("Allowance")."</a>"));

if (isset($_POST['addupdate'])) {		
		$allowances = kv_get_allowances('Earnings');
		$all_arr = [];
		foreach($allowances as $single){
			if(isset($_POST[$single['id']]) && $_POST[$single['id']] == 1)
				$all_arr[] = $single['id'];
		}
		if(!empty($all_arr)){
			$_POST['allowances'] = base64_encode(serialize($all_arr));
		}else 
			$_POST['allowances'] = '';
    	
    	Update('kv_empl_option', array('option_name' => 'indemnity'), array('option_value' =>  $_POST['allowances']));   
		display_notification(_("Selected Indemnity Settings has been updated"));  	
} 
//-------------------------------------------------------------------------------------------------
start_form();
start_table(TABLESTYLE2);
table_section_title(_("Allowances"));
$myrow = get_hrm_option('indemnity');

$allowances = kv_get_allowances('Earnings');
foreach($allowances as $single){
	if( !empty($myrow) && in_array($single['id'], $myrow))
		$_POST[$single['id']] = 1;
	kv_check_row(_($single['description']), $single['id'], null);
}
end_table(1);
submit_center('addupdate', _("Submit"), true, '', 'default');
end_form();
end_page();
?>
<style>
	/*table { width: auto; }*/
</style>