{= # # # export_from_gui_init.cfv # # This template is called when exporting a report element from the client GUI # # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.get_web_server_root_path"; debug_message("\n\n#### export_from_gui_init.cfv START \n"); string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); bool is_export_permission = is_root_admin or get_report_feature_permission(session_id, profile_name, "csv_export"); string page_token = v.sys.page_token; if (is_export_permission and get_is_valid_page_token(session_id, "statistics", page_token)) then ( debug_message("\n" . node_as_string("v.sys") . "\n"); string user_node_name = node_name(volatile.authenticated_user_node_path); debug_message("\n\n#### user_node_name:" . user_node_name . "\n"); string source_report_job_id = v.sys.report_job_id; string report_name = v.sys.report_name; string report_element_name = v.sys.report_element_name; int starting_row = v.sys.starting_row; int ending_row = v.sys.ending_row; bool export_active_aggregation_rows = v.sys.export_active_aggregation_rows; bool report_element_number = 0; bool export_average = false; bool export_min = false; bool export_max = false; bool export_total = false; string end_of_line = ""; # string csv_file = "c:\\__test_export_via_gui\\exported_data.csv"; # # # # # Clone the source report_job and update the clone with active export data (row numbers and aggregation) # # # # string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; node source_report_job = session_profile_path . ".report_jobs." . source_report_job_id; # # Get new report job id # string report_job_id = md5_digest("export" . source_report_job_id . now_us()); # # Save the new report job # string report_job_path = session_profile_path . ".report_jobs." . report_job_id; clone_node(source_report_job, report_job_path); save_node(report_job_path); node report_job = report_job_path; # # Update the report element in new report_job # node report_element = report_job . ".report_elements." . report_element_name; set_subnode_value(report_element, "starting_row", starting_row); set_subnode_value(report_element, "ending_row", ending_row); save_node(report_job); # # Check if we export any active aggregation row # if (export_active_aggregation_rows) then ( # KHP-RC, if Pivot Table consider also the active aggreagtion rows of the Pivot Table (overlay them) if (report_element?{"show_averages_row"}) then ( export_average = @report_element{"show_averages_row"}; ); if (report_element?{"show_min_row"}) then ( export_min = @report_element{"show_min_row"}; ); if (report_element?{"show_max_row"}) then ( export_max = @report_element{"show_max_row"}; ); if (report_element?{"show_totals_row"}) then ( export_total = @report_element{"show_totals_row"}; ); ); # # # # Get the cvs directory and cvs file # # # string web_server_root_path = get_web_server_root_path(); string export_path = "csv_export/" . user_node_name . "/" . profile_name . "/"; string file_name_prefix = if (report_name eq report_element_name) then (report_name) else (report_name . "_" . report_element_name); int count = 1; string file_name_number; bool is_unique_file_name = false; string file_name; string csv_file; while (!is_unique_file_name) ( if (count < 10) then ( file_name_number = "00" . count; ) else if (count < 100) then ( file_name_number = "0" . count; ) else ( file_name_number = count; ); file_name = file_name_prefix . "_" . file_name_number . ".csv"; if (!file_exists(web_server_root_path . export_path . file_name)) then ( is_unique_file_name = true; ); count++; ); string csv_file = web_server_root_path . export_path . file_name; debug_message("#### export_path: " . export_path . "\n"); debug_message("#### file_name: " . file_name . "\n"); # KHP 03/Sep/2009 - Note, we can't invoke filref() for the csv filename unless the file actually exists # in CGI mode if a temporary_directory_pathname and URL is defined because the C++ # attempts to copy this file to temporary_directory_pathname. # string csv_file_href_in_client_anchor = fileref(export_path . file_name); # KHP 03/Sep/2009 - Instead the csv_file_href_in_client_anchor we just send the required filref argument # and invoke fileref() when the exported file exists. string csv_fileref_argument = export_path . file_name; # # # # # Export the report element by starting a new process (we actually export via command_line!) # # # # # Note, we transfer the session_id to the separate process because the command line process itself issues # a none-GUI session_id! volatile.options.1 = "background"; volatile.options.2 = "-dp"; volatile.options.3 = "templates.statistics.export.export_from_gui"; volatile.options.4 = "-p"; volatile.options.5 = profile_name; volatile.options.6 = "-v"; volatile.options.7 = "e"; volatile.options.8 = "v.sys.report_job_id"; volatile.options.9 = report_job_id; volatile.options.10 = "v.sys.report_element_name"; volatile.options.11 = report_element_name; volatile.options.12 = "v.sys.export_average"; volatile.options.13 = export_average; volatile.options.14 = "v.sys.export_min"; volatile.options.15 = export_min; volatile.options.16 = "v.sys.export_max"; volatile.options.17 = export_max; volatile.options.18 = "v.sys.export_total"; volatile.options.19 = export_total; volatile.options.20 = "v.sys.csv_file"; volatile.options.21 = csv_file; volatile.options.22 = "volatile.session_id"; volatile.options.23 = session_id; volatile.options.24 = "v.sys.page_token"; volatile.options.25 = page_token; # debug_message("#### exec options: " . node_as_string('volatile.options') . "\n"); string pid = exec("", "volatile.options", false); # # # # Send response data # # # string dat = "{"; dat .= add_json("csvFile", csv_file, "string"); dat .= add_json("csvFilerefArgument", csv_fileref_argument, "string"); dat .= add_json("taskId", pid, "string"); dat = close_json(dat); "exportTable.startExportResponse(" . dat . ")\n"; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}