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

include_once($path_to_root . "/includes/ui/items_cart.inc");
include($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
include_once($path_to_root . "/inventory/includes/item_validation.inc");
include_once($path_to_root . "/admin/includes/import_stock_balances.inc");
//include_once($path_to_root . "/includes/project_cost_functions.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/assets/includes/ui/import_assets_ui.inc");
include_once($path_to_root . "/assets/includes/ui/import_asset_details_ui.inc");      
include_once($path_to_root . "/assets/includes/db/import_assets_db.inc");
include_once($path_to_root . "/assets/includes/import_assets.inc");
include_once($path_to_root . "/assets/includes/db/assets_db.inc");

        
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 Assets"), false, false, "", $js);

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


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


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_assets_import_file($Mode, $_POST['import_function']);
}


if(isset($_POST['Refresh_File_Data'])){
    
    delete_existing_assets();
     
    read_assets_import_file(null, $_POST['import_function']);
}

if(isset($_POST['Validate_File_Data'])){

    save_import_assets(false);
}

if(isset($_POST['Import_File_Data'])){

    save_import_assets(true);
}
        
//----------------------------------------------------------------------------------------

global $Ajax;

start_form(true);

br(2);

start_table(TABLESTYLE2);

$values_array['IMPORT_ASSETS'] = 'Import Assets';

custom_values_list_row("Import Values :", 'import_function', $values_array, null, false, true);
file_row(_("Attached File") . ":", 'filename', 'filename');


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

br();
br();

display_heading2("File Contents");



div_start('AssetImportFileDataTable');

    display_assets_file_data();
    
div_end();

$Ajax->activate('AssetImportFileDataTable');  
//    display_assets_import_file_data(null, $_POST['import_function'], isset($_POST['Import_File_Data']));
  
  br(2);
    
    submit_center_first('Import_File_Data', _("Import"), '', 'default');
    submit('Validate_File_Data', 'Validate', true, '', 'default'); 
    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();



?>
