<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_SALESPRICE';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/payroll/includes/payroll_db.inc");

if (!@$_GET['popup'])
	page(_($help_context = "Employment History"));

//---------------------------------------------------------------------------------------------------

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------
$input_error = 0;

if (isset($_GET['employee_code']))
{
	$_POST['employee_code'] = $_GET['employee_code'];
}

//---------------------------------------------------------------------------------------------------
if (!@$_GET['popup'])
	start_form();

if (!isset($_POST['employee_code']))
	//$_POST['employee_code'] = get_global_employee_code();

if (!@$_GET['popup'])
{
	/*echo "<center>" . _("Item:"). "&nbsp;";
	echo sales_items_list('employee_code', $_POST['employee_code'], false, true, '', array('editable' => false));
	echo "<hr></center>";
         * 
         */
}
else
	br(2);
//set_global_employee_code($_POST['employee_code']);

//----------------------------------------------------------------------------------------------------

if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
{

	$input_error = 0;
        /*if ($_POST['employee_code'] == $_POST['family_member_no'])
        {
            $input_error = 1;
            $msg = _("Family member has to be a different member.");
        }
         * 
         */

	if ($input_error != 1)
	{

                if ($selected_id != -1) 
		{
			//editing an existing price
			update_qualification($selected_id, $_POST['qualification'],
                                $_POST['comment'], date2sql($_POST['obtained_date']));

			$msg = _("Employee qualification has been updated.");
		}
		else
		{
                        add_qualification($_POST['employee_code'], $_POST['qualification'],
                                $_POST['comment'], date2sql($_POST['obtained_date']));

                        $msg = _("Employee qualification has been added.");
		}
		display_notification($msg);
		$Mode = 'RESET';
	}

}

//------------------------------------------------------------------------------------------------------

if ($Mode == 'Delete')
{
	//the link to delete a selected record was clicked
	//delete_promotion_benefit_item($selected_id);
	display_notification(_("The selected family member has been deleted."));
	$Mode = 'RESET';
}

if ($Mode == 'RESET')
{
	$selected_id = -1;
}

if (list_updated('stock_id')) {
	$Ajax->activate('price_table');
	$Ajax->activate('price_details');
}
if (list_updated('stock_id') || isset($_POST['_curr_abrev_update']) || isset($_POST['_sales_type_id_update'])) {
	// after change of stock, currency or salestype selector
	// display default calculated price for new settings. 
	// If we have this price already in db it is overwritten later.
	unset($_POST['price']);
	$Ajax->activate('price_details');
}

//---------------------------------------------------------------------------------------------------

$qualifications_list = get_qualifications($_POST['employee_code']);

div_start('price_table');
start_table(TABLESTYLE, "width=60%");

$th = array(
    _("Qualification"), _("Obtained_date"), _("Comment"), "", "");
table_header($th);
$k = 0; //row colour counter
$calculated = false;


while ($myrow = db_fetch($qualifications_list))
{

	alt_table_row_color($k);

    	label_cell($myrow["qualification"],"align=center");
        label_cell(sql2date($myrow["obtained_date"]),"align=center");
        label_cell($myrow["comment"],"align=center");
 	edit_button_cell("Edit".$myrow['id'], _("Edit"));
 	delete_button_cell("Delete".$myrow['id'], _("Delete"));
        
        end_row();

}

end_table();

/*if (db_num_rows($prices_list) == 0)
{
	if (get_company_pref('add_pct') != -1)
		$calculated = true;
	display_note(_("There are no prices set up for this part."), 1);
}
 * 
 */
div_end();
//------------------------------------------------------------------------------------------------

echo "<br>";

if ($Mode == 'Edit')
{

        $qualification_record = get_qualification($selected_id);
        $qualification_detail_row  = db_fetch($qualification_record);
//        var_dump($promotion_benefit_item_row);
//        echo $selected_id;
	$_POST['qualification'] = $qualification_detail_row["qualification"];
        $_POST['comment'] = $qualification_detail_row["comment"];
        $_POST['obtained_date'] = sql2date($qualification_detail_row["obtained_date"]);

}

hidden('selected_id', $selected_id);
if (@$_GET['popup'])
{
	hidden('_tabs_sel', get_post('_tabs_sel'));
	hidden('popup', @$_GET['popup']);
}
div_start('price_details');
start_table(TABLESTYLE2);

//value_list_row(_("Relationship:"), 'family_member_relationship_id', 'F_MEMBERS');

text_row(_("Qualification:"), 'qualification', null, 50, 50);

date_row(_('Obtained_date:'), 'obtained_date');

textarea_row(_('Comment:'), 'comment', null, 25, 3);

end_table(1);

submit_add_or_update_center($selected_id == -1, '', 'both');
div_end();

if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}	
?>
