# ============================ # Subroutine report_zoom_setup # ============================ # Initiated from report.cfv include "templates.statistics.util.get_zoom_filter_expression"; include "templates.shared.util.clean_from_escape_values"; include "templates.shared.util.date_time.get_date_time_granularity"; include "templates.shared.util.date_time.get_month_as_number"; include "templates.shared.util.date_time.get_month_as_string"; include "templates.shared.util.date_time.get_number_of_days"; subroutine(report_zoom_setup( string profile_name, string report_name, bool zoom_is_active), ( # The report_name defines already the report on which the user zoomed; # though the report name may change if zoom_in_hierarchy_is_active is true bool new_zoom = false; bool zoom_in_hierarchy = false; bool sub_zoom_is_active = false; # new_zoom if (node_exists("volatile.sys.new_zoom")) then ( new_zoom = volatile.sys.new_zoom; ); # zoom_in_hierarchy if (node_exists("volatile.sys.zoom_in_hierarchy")) then ( zoom_in_hierarchy = volatile.sys.zoom_in_hierarchy; ); # sub_zoom_is_active if (node_exists("volatile.sys.sub_zoom_is_active")) then ( sub_zoom_is_active = volatile.sys.sub_zoom_is_active; ); if (zoom_is_active) then ( # Write any existing zoom values into the active_zoom_fields node node zoom_field; string zoom_fields_path = "volatile.sys.zoom_fields"; if (node_exists(zoom_fields_path)) then ( foreach zoom_field zoom_fields_path ( "internal.zoom.zoom_fields." . node_name(zoom_field) = node_value(zoom_field); ); ); # If new zoom then add the new values into the zoom_fields node, # existing hierarchical field values will be overwritten if (new_zoom) then ( string new_zoom_field = volatile.sys.new_zoom_field; string new_zoom_value = volatile.sys.new_zoom_value; # internal.zoom.zoom_field = new_zoom_field; # internal.zoom.zoom_value = new_zoom_value; "internal.zoom.zoom_fields." . new_zoom_field = new_zoom_value; if (sub_zoom_is_active) then ( string new_sub_zoom_field = volatile.sys.new_sub_zoom_field; string new_sub_zoom_value = volatile.sys.new_sub_zoom_value; "internal.zoom.zoom_fields." . new_sub_zoom_field = new_sub_zoom_value; ); # ----------------------------------------------------------- # if zoom_in_hierarchy verify if the zoomed item has subitems # ----------------------------------------------------------- # if no sub_items exist set the report_name to overview! # if no overview report exists then keep the current report! if (zoom_in_hierarchy and !sub_zoom_is_active) then ( bool zoom_value_has_subitems = db_item_has_subitems(new_zoom_field, new_zoom_value); debug_message("#### Zoom value has subitems: " . zoom_value_has_subitems . "\n"); if (!zoom_value_has_subitems) then ( report_name = "overview"; if (node_exists("internal.report.startup_report_name")) then ( report_name = internal.report.startup_report_name; ); ); ); ); # ------------------------------- # Check for date_time zoom values # ------------------------------- # If zoomed to date time keep track of it so that we can show the number_of_days # in the zoom section and modify number of days in the overview reports bool date_time_zoom_exists = false; string date_time_zoom_value; node zoom_field; foreach zoom_field "internal.zoom.zoom_fields" ( if (node_name(zoom_field) eq "date_time") then ( date_time_zoom_exists = true; date_time_zoom_value = node_value(zoom_field); last; ); ); if (date_time_zoom_exists) then ( date_time_zoom_value = clean_from_escape_values(date_time_zoom_value); string date_time_zoom_granularity = get_date_time_granularity(date_time_zoom_value); if (date_time_zoom_granularity eq "year" or date_time_zoom_granularity eq "month") then ( # get the number of days or number of months string calendar_path = "internal.date_time.query_result"; int the_year = substr(date_time_zoom_value, 7, 4); int number_of_days; if (date_time_zoom_granularity eq "year") then ( string start_date; string end_date; if (node_exists(calendar_path . "." . the_year - 1)) then ( start_date = "01/Jan/" . the_year . " __:__:__"; ) else ( string first_month_in_year = node_name(subnode_by_number(calendar_path . "." . the_year, 0)); string first_month_in_year_as_string = get_month_as_string(first_month_in_year); debug_message("\n\n\n\n@@@@ first_month_in_year: " . first_month_in_year . "\n"); debug_message("@@@@ first_month_in_year_as_string: " . first_month_in_year_as_string . "\n"); string days_path = calendar_path . "." . the_year . "." . first_month_in_year . ".days"; string first_day_in_month = node_name(subnode_by_number(days_path, 0)); if (length(first_day_in_month) == 1) then ( first_day_in_month = "0" . first_day_in_month; ); start_date = first_day_in_month . "/" . first_month_in_year_as_string . "/" . the_year . " __:__:__"; ); if (node_exists(calendar_path . "." . the_year + 1)) then ( end_date = "31/Dec/" . the_year . " __:__:__"; ) else ( int number_of_months = num_subnodes(calendar_path . "." . the_year); string last_month_in_year = node_name(subnode_by_number(calendar_path . "." . the_year, number_of_months - 1)); string last_month_in_year_as_string = get_month_as_string(last_month_in_year); string days_path = calendar_path . "." . the_year . "." . last_month_in_year . ".days"; int number_of_day_items = num_subnodes(days_path); string last_day_in_month = node_name(subnode_by_number(days_path, number_of_day_items - 1)); if (length(last_day_in_month) == 1) then ( last_day_in_month = "0" . last_day_in_month; ); end_date = last_day_in_month . "/" . last_month_in_year_as_string . "/" . the_year . " __:__:__"; ); debug_message("@@@@ start_date: " . start_date . "\n"); debug_message("@@@@ end_date: " . end_date . "\n"); number_of_days = get_number_of_days(start_date, end_date); ) else ( # this is a month string the_month_as_string = substr(date_time_zoom_value, 3, 3); int the_month = get_month_as_number(date_time_zoom_value); string calendar_month_path = calendar_path . "." . the_year . "." . the_month; int first_day_in_month; int last_day_in_month; # check if a month before and a month after the active month exists, # if so, then all days of the month will be used for number_of_days bool month_before_exists = false; bool month_after_exists = false; string active_year_month = the_year . "_" . the_month; string first_year_in_calendar = node_name(subnode_by_number(calendar_path, 0)); string first_month_in_calendar = node_name(subnode_by_number(calendar_path . "." . first_year_in_calendar, 0)); string first_year_month_in_calendar = first_year_in_calendar . "_" . first_month_in_calendar; int number_of_years = num_subnodes(calendar_path); string last_year_in_calendar = node_name(subnode_by_number(calendar_path, number_of_years - 1)); int number_of_months = num_subnodes(calendar_path . "." . last_year_in_calendar); string last_month_in_calendar = node_name(subnode_by_number(calendar_path . "." . last_year_in_calendar, number_of_months - 1)); string last_year_month_in_calendar = last_year_in_calendar . "_" . last_month_in_calendar; if (active_year_month ne first_year_month_in_calendar) then (month_before_exists = true;); if (active_year_month ne last_year_month_in_calendar) then (month_after_exists = true;); if (month_before_exists) then ( first_day_in_month = 1; ) else ( # get first day of month as in calendar first_day_in_month = node_name(subnode_by_number(calendar_month_path . ".days", 0)); ); if (month_after_exists) then ( # get all days of month last_day_in_month = (date_time_duration("__/" . the_month_as_string . "/" . the_year . " __:__:__")) / (24*60*60); ) else ( # get last day of month as in calendar int number_of_days_in_calendar = num_subnodes(calendar_month_path . ".days"); last_day_in_month = node_name(subnode_by_number(calendar_month_path . ".days", number_of_days_in_calendar - 1)); ); debug_message("\n\n\n\n\n@@@@ first_day_in_month: " . first_day_in_month . "\n"); debug_message("@@@@ last_day_in_month: " . last_day_in_month . "\n"); number_of_days = last_day_in_month - first_day_in_month + 1; ); internal.zoom.date_time_zoom_is_active = true; internal.zoom.date_time_zoom_granularity = date_time_zoom_granularity; internal.zoom.date_time_zoom_number_of_days = number_of_days; debug_message("@@@@ number_of_days: " . number_of_days . "\n"); ) else if (date_time_zoom_granularity eq "day") then ( internal.zoom.date_time_zoom_number_of_days = "1"; ) else ( # zoomed to hours, minutes or seconds internal.zoom.date_time_zoom_number_of_days = ""; ); ) else ( internal.zoom.date_time_zoom_is_active = false; internal.zoom.date_time_zoom_granularity = ""; internal.zoom.date_time_zoom_number_of_days = ""; ); # ----------------------- # build filter expression # ----------------------- string filter_expression = get_zoom_filter_expression(); debug_message("\n\n zoom filter_expression:\n" . replace_all(filter_expression, '$', '\\$') . "\n");#GMF # filter_expression = convert_salang_expression_to_cfg_string(filter_expression); # debug_message("\n\n zoom filter_expression after convert_salang_expression_to_cfg_string(:\n" . filter_expression . "\n"); internal.zoom.filter_expression = filter_expression; # ---------------------------- # set remaining internal nodes # ---------------------------- internal.zoom.zoom_is_active = true; internal.zoom.sub_zoom_is_active = false; ) else ( # -------------- # no zoom active # -------------- internal.zoom.zoom_is_active = false; internal.zoom.sub_zoom_is_active = false; internal.zoom.filter_expression = ""; internal.zoom.date_time_zoom_is_active = false; internal.zoom.date_time_zoom_granularity = ""; internal.zoom.date_time_zoom_number_of_days = ""; # delete any existing zoom fields if (node_exists("internal.zoom.zoom_fields")) then ( delete_node("internal.zoom.zoom_fields"); ); ); report_name; ));