{= # # # save_xrefs_data.cvf # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.rebuild_db_advice.hide_rebuild_db_advice_msg"; include "templates.util.backup_util"; include "templates.util.profiles.get_profile_data_util"; debug_message("#### save_xrefs_data.cvf 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, "xrefs", "edit")) and get_is_valid_page_token(session_id, "xrefs", page_token)) then ( debug_message("\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 new_xrefs = "v.fp.xrefs"; bool set_hide_rebuild_db_advice_message = v.fp.set_hide_rebuild_db_advice_message; node item; # # # # Delete any existing xrefs # # # if (?(profile . ".database.cross_reference_groups")) then ( node existsing_xrefs = profile . ".database.cross_reference_groups"; foreach item existsing_xrefs ( delete_node(item); ); ); # # # # Handle new_xrefs # # # if (num_subnodes(new_xrefs) > 0) then ( # # Sort new_xrefs to maintain position # sort(new_xrefs, "field:position,integer,ascending"); node fields; node field_item; foreach item new_xrefs ( # Remove the position node delete_node(item{"position"}); # Handle fields node fields = item{"fields"}; # Sort fields node (each field name contains a temp integer value by which we sort) sort(fields, "field:value,integer,ascending"); # Remove position values in fields foreach field_item fields ( set_node_value(field_item, ""); ); ); # Clone modified data to the profiles cross_reference_groups clone_node(new_xrefs, profile . ".database.cross_reference_groups"); ); # debug_message("\n#### new_xrefs after sorting: " . node_as_string(new_xrefs) . "\n"); # # # # 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"); # # # Handle set_hide_rebuild_db_advice_message # # hide_rebuild_db_advice_msg("xrefs", set_hide_rebuild_db_advice_message); # # Response # string dat = "{"; dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat = close_json(dat); "processSaveXrefsResponse(" . dat . ")\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}