{= # # # # save_report_fields.cfv # # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.config_pages.report_fields.save_report_fields_util"; include "templates.util.backup_util"; include "templates.util.profiles.get_profile_data_util"; # Following nodes/properties are send from the client and must # be deleted prior saving the report fields: # - ori_node_name # - is_new # - position (defines node order) # The form processing report fields node contains a ori_node_name subnode # which is used to check if a node name changed. In case of a # node name change we have to update any dependend report_field in reports. # After this check the we need to delete the subnodes ori_node_name, etc. debug_message("\n\n#### save_report_fields.cfv START \n"); 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, "report_fields", "edit")) and get_is_valid_page_token(session_id, "report_fields", page_token)) then ( debug_message("\n\n" . node_as_string("v.fp") . "\n"); string user_node_name = node_name(volatile.authenticated_user_node_path); string client_profiles_list_checksum = v.fp.profiles_list_checksum; # 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; node report_fields = profile . ".statistics.report_fields"; node new_report_fields = "v.fp.report_fields"; bool is_new_report_fields = (num_subnodes(new_report_fields) > 0); debug_message("#### is_new_report_fields: " . is_new_report_fields . "\n"); if (is_new_report_fields) then ( # # # Sort report fields # # sort(new_report_fields, "field:position,integer,ascending"); # # # Handle node names, resolve labels and clean up from helper nodes # The following subroutine returns ori_node_names_with_new_node_names. If this node # contains any subnodes then we must update existing report field names in reports. # # node ori_node_names_with_new_node_names = process_new_report_fields(new_report_fields); debug_message("#### new_report_fields after cleanup:\n" . node_as_string(new_report_fields) . "\n"); debug_message("#### ori_node_names_with_new_node_names:\n" . node_as_string(ori_node_names_with_new_node_names) . "\n"); # # # Update any report_field node name changes in reports # # update_report_fields_in_reports(profile, ori_node_names_with_new_node_names); ); # # # Delete existing report fields # # node item; foreach item report_fields ( delete_node(item); ); # # # Clone new report fields # # if (is_new_report_fields) then ( clone_node(new_report_fields, report_fields); ); # # # Save the profile # # # 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"); # # # Response # # string dat = "{"; dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat = close_json(dat); "reportFields.saveReportFieldsResponse(" . dat . ")\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}