{= # # # expand_session_paths.cfv # # # Called from client to dynamically expand a specific path # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.statistics.util.get_session_paths_query_id"; debug_message("\n\n\n#### expand_session_paths.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_access_reports = is_root_admin or get_access_reports_permission(session_id, profile_name); string page_token = v.fp.page_token; if (is_access_reports and get_is_valid_page_token(session_id, "statistics", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n\n"); string profiles_cache_path = "profiles_cache." . profile_name; # # Note, the short_report_element_id and the_path is re-send to the client as reference # string short_report_element_id = v.fp.short_report_element_id; string report_element_id = v.fp.report_element_id; string the_path = v.fp.the_path; # the path with underbars string the_path_node_name = replace_all(the_path, "_", ".next_pages."); node raw_report_element = "profiles_cache." . profile_name . ".raw_report_elements." . report_element_id; # KHP-RC --> GET maximum_text_length FROM CLIENT! # node text_sizes = raw_report_element . ".options.sizes.session_path"; # int maximum_text_length = @text_sizes{"maximum_text_length"}; int maximum_text_length = 200; # # # Set the filters # # if (@raw_report_element{"all_filters_expression"} ne "") then ( volatile.filters = @raw_report_element{"all_filters_expression"}; ) else ( volatile.filters = "nofilters"; ); # string all_filters_id = md5_digest(volatile.filters); # # # Get db info # # node db_info = get_database_info(profile_name, true); string database_last_modification_time = @db_info{"last_modification_time"}; # Clean up delete_node(db_info); # # # Query db # # delete_node("v.query_result"); v.query_result = ""; int expand_paths_greater_than = -1; string session_paths_query_id = get_session_paths_query_id( database_last_modification_time, # all_filters_id, report_element_id, expand_paths_greater_than, the_path ); # Check if the query exists in cache if (?(profiles_cache_path . ".queries." . session_paths_query_id)) then ( # debug_message("#### generated session_paths query: No, got it from cache \n\n"); clone_node(profiles_cache_path . ".queries." . session_paths_query_id, "v.query_result"); ) else ( delete_node("v.query_info"); v.query_info = ""; node query_info = "v.query_info"; @query_info{"report_element_type"} = "session_paths"; @query_info{"session_id_field"} = @raw_report_element{"session_id_field"}; @query_info{"session_page_field"} = @raw_report_element{"session_page_field"}; @query_info{"session_user_field"} = @raw_report_element{"session_user_field"}; @query_info{"session_sequence_number_field"} = @raw_report_element{"session_sequence_number_field"}; @query_info{"expand_paths_greater_than"} = expand_paths_greater_than; @query_info{"expanded_session_paths"} = ""; @query_info{"the_path"} = ""; node query_info_the_path = query_info{"the_path"}; # # Set query_info.the_path # if (!contains(the_path, "_")) then ( @query_info_the_path{the_path} = true; ) else ( delete_node("v.temp_split_result"); split(the_path, "_", "v.temp_split_result"); node split_item; string path_item_number; node path_item; foreach split_item "v.temp_split_result" ( # IMPORTANT # the_path may contain multiple path_item_number's (returns to same page), # i.e. the_path = "2_92_89_90_100_89_96". The duplicate "89" must also appear # in query_info.the_path twice, like this: # the_path = { # 2 = (bool) true # 92 = (bool) true # 89 = (bool) true # 90 = (bool) true # 100 = (bool) true # 89 = (bool) true # 96 = (bool) true # } # the_path # # Duplicate subnodes as above are legal and possible by using insert_node(), # as done below. Respectively, we use insert_node() to achieve this # behavior. path_item_number = @split_item; # debug_message("#### path_item_number: " . path_item_number . "\n"); path_item = new_node(); set_node_type(path_item, "bool"); @path_item = true; rename_node(path_item, path_item_number); insert_node(query_info_the_path, path_item, num_subnodes(query_info_the_path)); ); ); @query_info{"header"} = ""; debug_message("\n\n" . node_as_string("v.query_info") . "\n\n"); query_db_for_report(query_info, "v.query_result", "tbl"); # # # Save query to cache # # clone_node("v.query_result", profiles_cache_path . ".queries." . session_paths_query_id); save_node(profiles_cache_path . ".queries." . session_paths_query_id); ); debug_message("\n\n" . node_as_string("v.query_result") . "\n\n"); # debug_message("\n\n#### the_path_node_name: " . the_path_node_name . "\n\n"); # Note, as we specified the_path we get the deepest node as top level next_pages node in query result! # node the_path_item = "v.query_result.data.next_pages"; node next_pages = "v.query_result.data.next_pages"; # # # Handle row numbers # # int total_rows = num_subnodes(next_pages); int ending_row = 10; # the ending_row in display if (ending_row > total_rows) then ( ending_row = total_rows; ); # # # Add the path item to the raw report element # # node raw_path_item = raw_report_element . ".data.next_pages." . the_path_node_name; set_subnode_value(raw_path_item, "total_rows", total_rows); set_subnode_value(raw_path_item, "ending_row", ending_row); clone_node(next_pages, raw_path_item . ".next_pages"); save_node(raw_report_element); # # # Assemble javascript object # # int row_count = 1; node item; string path_id; string page_name; string events; string item_dat; string next_pages_dat = "["; foreach item next_pages ( path_id = node_name(item); page_name = @item{"page"}; events = format(@item{"events"}, "integer"); if (length(page_name) > maximum_text_length) then ( page_name = substr(page_name, 0, maximum_text_length) . "..."; ); item_dat = "{"; item_dat .= add_json("id", path_id, "string"); item_dat .= add_json("page", page_name, "string"); item_dat .= add_json("events", events, "string"); item_dat .= add_json("expanded", "false", "bool"); item_dat = close_json(item_dat) . ","; next_pages_dat .= item_dat; row_count++; if (row_count > ending_row) then ( last; ); ); next_pages_dat = replace_last(next_pages_dat, ",", "]"); # # # Send response # # string dat = "{"; dat .= add_json("sid", short_report_element_id, "string"); dat .= add_json("thePath", the_path, "string"); dat .= add_json("totalRows", total_rows, "int"); dat .= add_json("endingRow", ending_row, "int"); dat .= add_json("nextPages", next_pages_dat, "obj"); dat = close_json(dat); # debug_message("\n\n#### getSessionPathsItemsResponse dat:\n". dat . "\n\n"); "sessionPaths.expandSessionPathsResponse(" . dat . ")\n"; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}