<?php
/**********************************************************************
***********************************************************************/
$path_to_root="../..";
$page_security = 'SA_IMPORT_BOQ_ITEMS';

include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");


include_once($path_to_root . "/projects/includes/ui/import_project_boq_items_ui.inc");
//include_once($path_to_root . "/projects/includes/db/import_project_boq_items_main_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_groups_db.inc");

include_once($path_to_root . "/projects/includes/db/project_boq_item_detail_edit_db.inc");

include_once($path_to_root . "/projects/includes/ui/import_project_boq_item_details_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_items_db.inc");

include_once($path_to_root . "/projects/includes/ui/import_project_boq_item_materials_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_material_db.inc");

include_once($path_to_root . "/projects/includes/ui/import_project_boq_item_costs_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_costs_db.inc");

$processed_values;
$previous_time_entry;
$data;
$day_start_time = "";
$day_end_time = "";
$closed;
$a;
$previous_employee_code;
$k;


if (isset($_GET['vw']))
	$view_id = $_GET['vw'];
else
	$view_id = find_submit('view');

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "Import BOQ Item Data"), false, false, "", $js);

simple_page_mode(true);
//----------------------------------------------------------------------------------------


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


function viewing_controls()
{
	global $selected_id;
	
    start_table(TABLESTYLE_NOBORDER);

	start_row();
	systypes_list_cells(_("Type:"), 'filterType', null, true);
	if (list_updated('filterType'))
		$selected_id = -1;;

	end_row();
    end_table(1);

}

function edit_link($row)
{
  	return button('Edit'.$row["id"], _("Edit"), _("Edit"), ICON_VIEW);
}


function delete_link($row)
{
  	return button('Delete'.$row["id"], _("Delete"), _("Delete"), ICON_DELETE);
}



if(isset($_POST['Refresh_File_Data'])){
    clear_session_variable('import_project_boq_items');
}


if ($Mode == 'Delete')
{
	$row = get_attendance_file($selected_id);
	$dir =  company_path()."/attendance_files";
	if (file_exists($dir."/".$row['unique_name'])){
		unlink($dir."/".$row['unique_name']);
    }
    delete_saved_records($selected_id);
	delete_attendance_file($selected_id);	
    $selected_id =-1;
    $Mode = 'RESET';
    
	display_notification(_("Attendance file has been deleted.")); 
	
}

if ($Mode == 'RESET')
{
	unset($_POST['trans_no']);
	unset($_POST['description']);
	$selected_id = -1;
}


if(isset($_POST['Upload_File']))
{
    upload_project_boq_item_import_file($Mode, $_POST['import_values']);
}
//----------------------------------------------------------------------------------------

start_form(true);


br(2);

start_table(TABLESTYLE2);

$values_array['BOQ_ITEM_DETAILS'] = "BOQ Item Details";
$values_array['BOQ_ITEM_MATERIALS'] = "BOQ Item Materials";
$values_array['BOQ_ITEM_COSTS'] = "BOQ Item Costs";


custom_values_list_row("Import Values :", 'import_values', $values_array, null, false, true);
file_row(_("Attached File") . ":", 'filename', 'filename');
//project_list_row("Project :", 'project_id', null, 'Select a project', true);

end_table(1);
hidden('selected_id', $selected_id);
submit_center_first("Upload_File", "Upload");

br(2);



start_table(TABLESTYLE2);

project_list_row("Project :", 'project_id', null, 'Select a project', true);

end_table();

if(list_updated('project_id')){
    clear_session_variable('import_project_boq_items');
}


br();

    br();
    display_heading2("File Contents");
    br();
    display_project_boq_item_import_file_data($_POST['project_id'], $_POST['import_values'], isset($_POST['Validate_File_Data']), isset($_POST['Import_File_Data']));
    br(2);
    
    submit_center_first("Validate_File_Data", "Validate");
    submit("Import_File_Data", "Import");
    submit_center_last("Refresh_File_Data", "Refresh");

    br(2);

if(isset($_SESSION['attendance_file_result'])){
    display_result($_SESSION['attendance_file_result']);
    unset($_SESSION['attendance_file_result']);
}

end_form();

end_page();

?>
