{= # # # save_reports.cfv (Reports and Reports Menu) # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.update_reports_menu_labels"; include "templates.util.backup_util"; include "templates.config_pages.reports.save_reports_util"; include "templates.util.profiles.get_profile_data_util"; debug_message("#### save_reports.cfv"); # KHP-RC - currently we save all reports, regardless if it has been modified or not! # We have to change this, respectively we have to know which reports have been # modified so that we can clear the appropriate reports in sessions_cache.web_browser_sessions! string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_config_feature_permission(session_id, profile_name, "reports", "edit")) and get_is_valid_page_token(session_id, "reports", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); string client_profiles_list_checksum = v.fp.profiles_list_checksum; bool is_modified_reports_menu = v.fp.is_modified_reports_menu; node modified_reports_menu = "v.fp.reports_menu"; node new_or_modified_reports = "v.fp.reports"; node deleted_reports = "v.fp.deleted_reports"; string user_node_name = node_name(volatile.authenticated_user_node_path); # Get profiles checksum before the profile becomes saved! string profiles_list_checksum_before_profile_modification = get_profiles_list_checksum(session_id, is_root_admin, user_node_name); node profile = "profiles." . profile_name; # debug_message("\n" . node_as_string(modified_reports) . "\n"); # debug_message("#### number of modified_reports: " . num_subnodes(modified_reports) . "\n"); node existing_reports = profile . ".statistics.reports"; # Track reports which do not require a report link check # and report name changes to update report links. node up_to_date_reports = new_node(); node modified_report_names = new_node(); node item; string report_name_ori; string report_name; node report_elements; node report_element_item; string report_link; # # Handle deleted_reports # bool is_deleted_reports = num_subnodes(deleted_reports) > 0; if (is_deleted_reports) then ( node item; string report_name; foreach item deleted_reports ( report_name = node_name(item); if (existing_reports?{report_name}) then ( # Delete the report delete_node(existing_reports{report_name}); ); ); ); # # Handle new and modified reports # bool clear_reports_in_web_browser_sessions = false; if (num_subnodes(new_or_modified_reports) > 0) then ( foreach item new_or_modified_reports ( report_name_ori = @item{"report_name_ori"}; report_name = @item{"report_name"}; if (@item{"is_loaded"}) then ( handle_new_or_modified_report( existing_reports, item, report_name_ori, report_name ); # Track this report in up_to_date_reports. # This report will be excluded in any report link check # later because all report_links should be up to date. @up_to_date_reports{report_name} = true; ) else ( # Report only contains a subset of original data handle_minor_report_modifications( existing_reports, item, report_name_ori, report_name ); ); # Track report name change if this is not a new report # so that we can update report links. if (report_name_ori ne "" and (report_name_ori ne report_name)) then ( @modified_report_names{report_name_ori} = report_name; ); ); clear_reports_in_web_browser_sessions = true; ); # # Handle reports_menu (only if modified!) # if (is_modified_reports_menu) then ( node existing_reports_menu = profile . ".statistics.reports_menu"; # Delete existing menu items save_reports_remove_subnodes(existing_reports_menu); if (num_subnodes(modified_reports_menu) > 0) then ( handle_new_or_modified_report_menu(modified_reports_menu); clone_node(modified_reports_menu, profile . ".statistics.reports_menu"); # # Add labels to reports_menu (see templates.util.update_reports_menu_labels() for details) # update_reports_menu_labels(profile . ".statistics.reports_menu", profile . ".statistics.reports"); ); ); bool is_report_name_changes = num_subnodes(modified_report_names) > 0; # # Update report links of report elements which are not loaded # or not modified in client. # if (is_deleted_reports or is_report_name_changes) then ( foreach item existing_reports ( report_name = node_name(item); # Do not check report_link in modified reports if (!up_to_date_reports{report_name}) then ( report_elements = item{"report_elements"}; foreach report_element_item report_elements ( if (report_element_item?{"report_link"} and @report_element_item{"report_link"} ne "") then ( report_link = @report_element_item{"report_link"}; if (deleted_reports?{report_link}) then ( # Reset report_link @report_element_item{"report_link"} = ""; ) else if (modified_report_names?{report_link}) then ( # Set new report_name @report_element_item{"report_link"} = @modified_report_names{report_link}; ); ); ); ); ); ); # KHP 08/Aug/2013 - Changed save_node() to save_and_backup_profile() # save_node(profile); save_and_backup_profile(profile_name, profile); # Get profile_changes_dat, also in case of an error! string profile_changes_dat = get_profiles_list_data_after_profiles_changes( session_id, is_root_admin, user_node_name, client_profiles_list_checksum, profiles_list_checksum_before_profile_modification, profile_name, "save_profile"); # # Handle deleted_reports # # TODO, handle dependencies of deleted_reports # # # clear_reports_in_web_browser_sessions # # # KHP-RC, we should only clear modified reports and not all, see above KHP-RC info for details. # For the time being we clear all reports in web_browser_sessions string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; if (?(session_profile_path . ".web_browser_sessions")) then ( node web_browser_sessions = session_profile_path . ".web_browser_sessions"; node web_browser_session; foreach web_browser_session web_browser_sessions ( if (web_browser_session?{"reports"}) then ( delete_node(web_browser_session{"reports"}); save_node(web_browser_session); ); ); ); # # # Send response # string dat = "{"; dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat = close_json(dat); "reports.saveReportChangesResponse(" . dat . ")\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}