begin
wwv_flow_imp_page.create_page(
 p_id=>10032
,p_name=>'Application Error Log'
,p_alias=>'APPLICATION-ERROR-LOG'
,p_page_mode=>'MODAL'
,p_step_title=>'Application Error Log'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200413860063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>This page provides an interactive report of all unexpected errors logged by this application.</p>',
'<p>Click on the column headings to sort and filter data, or click on the <strong>Actions</strong> button to customize column display and many additional advanced features. Click the <strong>Reset</strong> button to reset the interactive report back t'
||'o the default settings.</p>'))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187265664105063951)
,p_plug_name=>'Application Error Log'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select step_id,',
'       userid,',
'       time_stamp err_time,',
'       sqlerrm,',
'       sqlerrm_component_type,',
'       sqlerrm_component_name',
'  from apex_activity_log',
' where flow_id = :app_id',
'   and sqlerrm is not null'))
,p_plug_source_type=>'NATIVE_IR'
,p_prn_page_header=>'Application Error Log'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187266577185063952)
,p_name=>'Application Error Log'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'N'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187266577185063952
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187266691168063952)
,p_db_column_name=>'STEP_ID'
,p_display_order=>10
,p_column_identifier=>'A'
,p_column_label=>'Page'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187267073985063953)
,p_db_column_name=>'USERID'
,p_display_order=>20
,p_column_identifier=>'B'
,p_column_label=>'User'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187267404281063953)
,p_db_column_name=>'ERR_TIME'
,p_display_order=>30
,p_column_identifier=>'C'
,p_column_label=>'Occurrence'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_format_mask=>'since'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187267880756063954)
,p_db_column_name=>'SQLERRM'
,p_display_order=>40
,p_column_identifier=>'D'
,p_column_label=>'Error'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187268208323063954)
,p_db_column_name=>'SQLERRM_COMPONENT_TYPE'
,p_display_order=>50
,p_column_identifier=>'E'
,p_column_label=>'Context'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187268675275063955)
,p_db_column_name=>'SQLERRM_COMPONENT_NAME'
,p_display_order=>60
,p_column_identifier=>'F'
,p_column_label=>'Component Name'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187269335262063956)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31872694'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'STEP_ID:USERID:ERR_TIME:SQLERRM:SQLERRM_COMPONENT_TYPE:SQLERRM_COMPONENT_NAME:'
,p_sort_column_1=>'ERROR_TIME'
,p_sort_direction_1=>'DESC'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187270297389063957)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187265664105063951)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
end;
/
prompt --application/pages/page_10033
begin
wwv_flow_imp_page.create_page(
 p_id=>10033
,p_name=>'Page Performance'
,p_alias=>'PAGE-PERFORMANCE'
,p_page_mode=>'MODAL'
,p_step_title=>'Page Performance'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200413860063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>This page provides an interactive report of the page performance and popularity. The report is ordered by <strong>Weighted Performance</strong> which is calculated by multiplying the Median Elapsed time and number of Page Views.</p>',
'<p>Select the reporting timeframe (Default = 1 day) at the top of the page as necessary.<br>',
'Click on the column headings to sort and filter data, or click on the <strong>Actions</strong> button to customize column display and many additional advanced features. Click the <strong>Reset</strong> button to reset the interactive report back to t'
||'he default settings.</p>'))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187256095752063939)
,p_plug_name=>'Page Performance'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select step_id page,',
'    (   select page_name',
'        from apex_application_pages p',
'        where p.page_id = l.step_id',
'            and p.application_id = :app_id ) page_name,',
'    median(elap)                   median_elapsed,',
'    count(*) * median(elap)        weighted_performance,',
'    sum(decode(sqlerrm,null,0,1))  errors,',
'    count(distinct userid)         distinct_users,',
'    count(distinct session_id)     application_sessions,',
'    count(*)                       page_views,',
'    max(elap)                      max_elapsed,',
'    sum(nvl(num_rows,0))           total_rows,',
'    sum(decode(page_mode,''P'',1,0)) partial_page_views,',
'    sum(decode(page_mode,''D'',1,0)) full_page_views,',
'    min(elap)                      min_elapsed,',
'    avg(elap)                      avg_elapsed',
'from apex_activity_log l',
'where flow_id = :app_id',
'    and time_stamp >= sysdate - ( 1/24/60/60 * :P10033_TIMEFRAME )',
'    and userid is not null',
'group by step_id'))
,p_plug_source_type=>'NATIVE_IR'
,p_ajax_items_to_submit=>'P10033_TIMEFRAME'
,p_prn_page_header=>'Page Performance'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187256946346063940)
,p_name=>'Page Performance'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'N'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187256946346063940
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187257001459063940)
,p_db_column_name=>'PAGE'
,p_display_order=>15
,p_column_identifier=>'A'
,p_column_label=>'Page'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187257462875063941)
,p_db_column_name=>'PAGE_NAME'
,p_display_order=>25
,p_column_identifier=>'B'
,p_column_label=>'Page Name'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187257814004063941)
,p_db_column_name=>'MEDIAN_ELAPSED'
,p_display_order=>35
,p_column_identifier=>'C'
,p_column_label=>'Median Elapsed'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D9999'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187258202366063942)
,p_db_column_name=>'WEIGHTED_PERFORMANCE'
,p_display_order=>45
,p_column_identifier=>'D'
,p_column_label=>'Weighted Performance'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D99'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187258622286063943)
,p_db_column_name=>'ERRORS'
,p_display_order=>55
,p_column_identifier=>'E'
,p_column_label=>'Errors'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187259023463063943)
,p_db_column_name=>'DISTINCT_USERS'
,p_display_order=>65
,p_column_identifier=>'F'
,p_column_label=>'Distinct Users'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187259481194063944)
,p_db_column_name=>'APPLICATION_SESSIONS'
,p_display_order=>75
,p_column_identifier=>'G'
,p_column_label=>'Application Sessions'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187259834138063944)
,p_db_column_name=>'PAGE_VIEWS'
,p_display_order=>85
,p_column_identifier=>'H'
,p_column_label=>'Page Views'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187260200879063945)
,p_db_column_name=>'MAX_ELAPSED'
,p_display_order=>95
,p_column_identifier=>'I'
,p_column_label=>'Max Elapsed'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D9999'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187260684006063945)
,p_db_column_name=>'TOTAL_ROWS'
,p_display_order=>105
,p_column_identifier=>'J'
,p_column_label=>'Total Rows'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187261019369063946)
,p_db_column_name=>'PARTIAL_PAGE_VIEWS'
,p_display_order=>115
,p_column_identifier=>'K'
,p_column_label=>'Partial Page Views'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187261438481063946)
,p_db_column_name=>'FULL_PAGE_VIEWS'
,p_display_order=>125
,p_column_identifier=>'L'
,p_column_label=>'Full Page Views'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187261863085063947)
,p_db_column_name=>'MIN_ELAPSED'
,p_display_order=>135
,p_column_identifier=>'M'
,p_column_label=>'Min Elapsed'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D9999'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187262261045063947)
,p_db_column_name=>'AVG_ELAPSED'
,p_display_order=>145
,p_column_identifier=>'N'
,p_column_label=>'Avg Elapsed'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D9999'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187262910737063948)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31872630'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'PAGE:PAGE_NAME:MEDIAN_ELAPSED:WEIGHTED_PERFORMANCE:ERRORS:DISTINCT_USERS:APPLICATION_SESSIONS:PAGE_VIEWS'
,p_sort_column_1=>'WEIGHTED_PERFORMANCE'
,p_sort_direction_1=>'DESC'
,p_sort_column_2=>'PAGE_VIEWS'
,p_sort_direction_2=>'DESC'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187256154807063939)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#:t-ButtonRegion--slimPadding:t-ButtonRegion--noUI:t-Form--large'
,p_component_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_01'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187263859435063949)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187256095752063939)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187255991890063939)
,p_name=>'P10033_TIMEFRAME'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187256154807063939)
,p_prompt=>'Timeframe'
,p_source=>'900'
,p_source_type=>'STATIC'
,p_display_as=>'NATIVE_SELECT_LIST'
,p_named_lov=>'TIMEFRAME (4 WEEKS)'
,p_lov=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select disp,',
'       val as seconds',
'  from table( apex_util.get_timeframe_lov_data )',
' order by insert_order'))
,p_cHeight=>1
,p_field_template=>wwv_flow_imp.id(3187171421134063410)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'execute_validations', 'Y',
  'page_action_on_selection', 'NONE')).to_clob
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187256289598063939)
,p_name=>'Refresh Report'
,p_event_sequence=>10
,p_triggering_element_type=>'ITEM'
,p_triggering_element=>'P10033_TIMEFRAME'
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'change'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187265195653063951)
,p_event_id=>wwv_flow_imp.id(3187256289598063939)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_REFRESH'
,p_affected_elements_type=>'REGION'
,p_affected_region_id=>wwv_flow_imp.id(3187256095752063939)
,p_attribute_01=>'N'
);
end;
/
prompt --application/pages/page_10034
begin
wwv_flow_imp_page.create_page(
 p_id=>10034
,p_name=>'Page Views'
,p_alias=>'PAGE-VIEWS'
,p_page_mode=>'MODAL'
,p_step_title=>'Page Views'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200413860063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>This page provides an interactive report of the most recent page views.</p>',
'<p>Select the reporting timeframe (Default = 1 day) at the top of the page as necessary.<br>',
'Click on the column headings to sort and filter data, or click on the <strong>Actions</strong> button to customize column display and many additional advanced features. Click the <strong>Reset</strong> button to reset the interactive report back to t'
||'he default settings.</p>'))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187247450423063776)
,p_plug_name=>'Page Views'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select ',
'    step_id||''. ''||(select page_name',
'                    from apex_application_pages p',
'                    where p.page_id = l.step_id',
'                        and p.application_id = :APP_ID) page_name,',
'    userid_lc     user_id,',
'    time_stamp    timestamp,',
'    elap          elapsed,',
'    step_id       page,',
'    decode(page_mode,''P'',''Partial'',''D'',''Full'',page_mode) page_mode,',
'    component_name,',
'    num_rows,',
'    ir_search,',
'    sqlerrm  error',
'from apex_activity_log l',
'where flow_id = :app_id',
'    and time_stamp >= sysdate - ( 1/24/60/60 * :P10034_TIMEFRAME )',
'    and userid is not null',
'    and step_id is not null',
'order by time_stamp desc'))
,p_plug_source_type=>'NATIVE_IR'
,p_ajax_items_to_submit=>'P10034_TIMEFRAME'
,p_prn_page_header=>'Page Views'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187248347053063777)
,p_name=>'Page Views'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'N'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187248347053063777
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187249096313063929)
,p_db_column_name=>'PAGE_NAME'
,p_display_order=>10
,p_column_identifier=>'A'
,p_column_label=>'Page Name'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187249410048063930)
,p_db_column_name=>'USER_ID'
,p_display_order=>20
,p_column_identifier=>'B'
,p_column_label=>'User'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187249817993063930)
,p_db_column_name=>'TIMESTAMP'
,p_display_order=>30
,p_column_identifier=>'C'
,p_column_label=>'Timestamp'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_format_mask=>'since'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187250227765063931)
,p_db_column_name=>'ELAPSED'
,p_display_order=>40
,p_column_identifier=>'D'
,p_column_label=>'Elapsed'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990D0000'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187250693907063932)
,p_db_column_name=>'PAGE'
,p_display_order=>50
,p_column_identifier=>'E'
,p_column_label=>'Page'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187251039233063932)
,p_db_column_name=>'PAGE_MODE'
,p_display_order=>60
,p_column_identifier=>'F'
,p_column_label=>'Mode'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187251401540063933)
,p_db_column_name=>'COMPONENT_NAME'
,p_display_order=>70
,p_column_identifier=>'G'
,p_column_label=>'Component Name'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187251839088063934)
,p_db_column_name=>'NUM_ROWS'
,p_display_order=>80
,p_column_identifier=>'H'
,p_column_label=>'Num Rows'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187252265968063934)
,p_db_column_name=>'IR_SEARCH'
,p_display_order=>90
,p_column_identifier=>'I'
,p_column_label=>'IR Search'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_format_mask=>'999G999G999G999G999G990'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187252669809063935)
,p_db_column_name=>'ERROR'
,p_display_order=>100
,p_column_identifier=>'J'
,p_column_label=>'Error'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187253328649063936)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31872534'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'PAGE_NAME:USER_ID:TIMESTAMP:ELAPSED:PAGE_MODE'
,p_sort_column_1=>'TIMESTAMP'
,p_sort_direction_1=>'DESC'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187247566816063776)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#:t-ButtonRegion--slimPadding:t-ButtonRegion--noUI:t-Form--large'
,p_component_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_01'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187254251090063937)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187247450423063776)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187247382800063776)
,p_name=>'P10034_TIMEFRAME'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187247566816063776)
,p_prompt=>'Timeframe'
,p_source=>'900'
,p_source_type=>'STATIC'
,p_display_as=>'NATIVE_SELECT_LIST'
,p_named_lov=>'TIMEFRAME (4 WEEKS)'
,p_lov=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select disp,',
'       val as seconds',
'  from table( apex_util.get_timeframe_lov_data )',
' order by insert_order'))
,p_cHeight=>1
,p_field_template=>wwv_flow_imp.id(3187171421134063410)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'execute_validations', 'Y',
  'page_action_on_selection', 'NONE')).to_clob
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187247694750063776)
,p_name=>'Refresh Report'
,p_event_sequence=>10
,p_triggering_element_type=>'ITEM'
,p_triggering_element=>'P10034_TIMEFRAME'
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'change'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187255566075063939)
,p_event_id=>wwv_flow_imp.id(3187247694750063776)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_REFRESH'
,p_affected_elements_type=>'REGION'
,p_affected_region_id=>wwv_flow_imp.id(3187247450423063776)
,p_attribute_01=>'N'
);
end;
/
prompt --application/pages/page_10035
begin
wwv_flow_imp_page.create_page(
 p_id=>10035
,p_name=>'Automations Log'
,p_alias=>'AUTOMATIONS-LOG'
,p_page_mode=>'MODAL'
,p_step_title=>'Automations Log'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200413860063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>This page provides an interactive report of the automations log.</p>',
'<p>Review logged information about previous automation executions. The log contains start and end timestamps as well as details about processed rows (successful and with errors). Drill down into Messages to see individual messages for processed rows.'
||'</p>',
''))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187281658219063973)
,p_plug_name=>'Automations Log'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select l.id,',
'       l.start_timestamp,',
'       a.name automation_name,',
'       l.status,',
'       l.successful_row_count,',
'       l.error_row_count,',
'       (select count(1) from apex_automation_msg_log m where m.automation_log_id = l.id) msg_count,',
'       l.is_job,',
'       l.end_timestamp',
'  from apex_appl_automations a, apex_automation_log l',
' where a.automation_id = l.automation_id',
' and l.application_id = :APP_ID'))
,p_plug_source_type=>'NATIVE_IR'
,p_prn_page_header=>'Automations Log'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187282548069063974)
,p_name=>'Automations Log'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'N'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187282548069063974
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187282641397063974)
,p_db_column_name=>'ID'
,p_display_order=>10
,p_column_identifier=>'A'
,p_column_label=>'ID'
,p_column_type=>'NUMBER'
,p_display_text_as=>'HIDDEN_ESCAPE_SC'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187283033019063975)
,p_db_column_name=>'START_TIMESTAMP'
,p_display_order=>20
,p_column_identifier=>'B'
,p_column_label=>'Started'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187283445259063975)
,p_db_column_name=>'AUTOMATION_NAME'
,p_display_order=>30
,p_column_identifier=>'C'
,p_column_label=>'Automation'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187283887188063976)
,p_db_column_name=>'STATUS'
,p_display_order=>40
,p_column_identifier=>'D'
,p_column_label=>'Status'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187284272818063976)
,p_db_column_name=>'SUCCESSFUL_ROW_COUNT'
,p_display_order=>50
,p_column_identifier=>'E'
,p_column_label=>'Successful Rows'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187284692638063977)
,p_db_column_name=>'ERROR_ROW_COUNT'
,p_display_order=>60
,p_column_identifier=>'F'
,p_column_label=>'Error Rows'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187285068261063978)
,p_db_column_name=>'MSG_COUNT'
,p_display_order=>70
,p_column_identifier=>'G'
,p_column_label=>'Message'
,p_column_link=>'f?p=&APP_ID.:10036:&SESSION.:::RP,10036:P10036_LOG_ID:#ID#'
,p_column_linktext=>'#MSG_COUNT#'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187285447577063978)
,p_db_column_name=>'IS_JOB'
,p_display_order=>80
,p_column_identifier=>'H'
,p_column_label=>'Scheduled'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187285813254063979)
,p_db_column_name=>'END_TIMESTAMP'
,p_display_order=>90
,p_column_identifier=>'I'
,p_column_label=>'Ended'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187286903815063980)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31872870'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'START_TIMESTAMP:AUTOMATION_NAME:STATUS:SUCCESSFUL_ROW_COUNT:ERROR_ROW_COUNT:MSG_COUNT'
,p_sort_column_1=>'START_TIMESTAMP'
,p_sort_direction_1=>'DESC'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187287899835063981)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187281658219063973)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
end;
/
prompt --application/pages/page_10036
begin
wwv_flow_imp_page.create_page(
 p_id=>10036
,p_name=>'Log Messages'
,p_alias=>'LOG-MESSAGES'
,p_page_mode=>'MODAL'
,p_step_title=>'Log Messages'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200413860063428)
,p_dialog_chained=>'N'
,p_protection_level=>'C'
,p_page_component_map=>'03'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187288472700063981)
,p_plug_name=>'Automation Execution'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_report_region(
 p_id=>wwv_flow_imp.id(3187290809807063983)
,p_name=>'Messages'
,p_template=>wwv_flow_imp.id(3187097299988063379)
,p_display_sequence=>10
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_component_template_options=>'#DEFAULT#:t-Report--stretch:t-Report--altRowsDefault:t-Report--rowHighlight:t-Report--inline'
,p_source_type=>'NATIVE_SQL_REPORT'
,p_query_type=>'SQL'
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select message_timestamp,',
'       message,',
'       message_type,',
'       pk_value',
'  from apex_automation_msg_log',
' where automation_log_id = :P10036_LOG_ID'))
,p_ajax_enabled=>'Y'
,p_lazy_loading=>false
,p_query_row_template=>wwv_flow_imp.id(3187139143272063396)
,p_query_num_rows=>50
,p_query_options=>'DERIVED_REPORT_COLUMNS'
,p_query_no_data_found=>'no data found'
,p_query_num_rows_type=>'NEXT_PREVIOUS_LINKS'
,p_query_row_count_max=>50
,p_pagination_display_position=>'BOTTOM_RIGHT'
,p_prn_output=>'N'
,p_prn_format=>'PDF'
,p_sort_null=>'L'
,p_plug_query_strip_html=>'N'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187291278803063985)
,p_query_column_id=>1
,p_column_alias=>'MESSAGE_TIMESTAMP'
,p_column_display_sequence=>1
,p_column_heading=>'Timestamp'
,p_column_alignment=>'CENTER'
,p_default_sort_column_sequence=>1
,p_default_sort_dir=>'desc'
,p_disable_sort_column=>'N'
,p_include_in_export=>'Y'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187291638229063985)
,p_query_column_id=>2
,p_column_alias=>'MESSAGE'
,p_column_display_sequence=>2
,p_column_heading=>'Message'
,p_heading_alignment=>'LEFT'
,p_disable_sort_column=>'N'
,p_include_in_export=>'Y'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187292004423063986)
,p_query_column_id=>3
,p_column_alias=>'MESSAGE_TYPE'
,p_column_display_sequence=>3
,p_column_heading=>'Message Type'
,p_heading_alignment=>'LEFT'
,p_disable_sort_column=>'N'
,p_include_in_export=>'Y'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187292465529063986)
,p_query_column_id=>4
,p_column_alias=>'PK_VALUE'
,p_column_display_sequence=>4
,p_column_heading=>'Primary Key Value'
,p_heading_alignment=>'LEFT'
,p_disable_sort_column=>'N'
,p_include_in_export=>'Y'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187288828401063982)
,p_name=>'P10036_LOG_ID'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187288472700063981)
,p_use_cache_before_default=>'NO'
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187289259859063982)
,p_name=>'P10036_AUTOMATION_NAME'
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187288472700063981)
,p_prompt=>'Automation'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_begin_on_new_line=>'N'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187289631774063982)
,p_name=>'P10036_START_TIMESTAMP'
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187288472700063981)
,p_prompt=>'Started'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_begin_on_new_line=>'N'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187290083744063982)
,p_name=>'P10036_STATUS'
,p_item_sequence=>40
,p_item_plug_id=>wwv_flow_imp.id(3187288472700063981)
,p_prompt=>'Status'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_begin_on_new_line=>'N'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187290466089063983)
,p_process_sequence=>10
,p_process_point=>'BEFORE_HEADER'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Get Log Detail'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select automation_name,',
'       start_timestamp,',
'       status',
'  into :P10036_AUTOMATION_NAME,',
'       :P10036_START_TIMESTAMP,',
'       :P10036_STATUS',
'  from apex_automation_log',
' where id = :P10036_LOG_ID;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187290466089063983
);
end;
/
prompt --application/pages/page_10040
begin
wwv_flow_imp_page.create_page(
 p_id=>10040
,p_name=>'Configure Access Control'
,p_alias=>'CONFIGURE-ACCESS-CONTROL'
,p_page_mode=>'MODAL'
,p_step_title=>'Configure Access Control'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200316965063428)
,p_protection_level=>'U'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>Select the appropriate choice for any authenticated users.<br> ',
'Selecting <strong>No</strong> makes the application more secure as only specified users can access the application. ',
'However, if your application has a large user community then maintaining users may be onerous, and you may prefer to choose <strong>Yes</strong> and only enter application Administrators, and possibly Contributors.<br>',
'If you select <strong>Yes</strong> then you must also select how users not included in the users list are treated.</p>',
'<p>Select between requiring email addresses and any alphanumeric value for Usernames.<br>',
'Generally, you should set this setting to <strong>E-mail Address</strong> if your application uses (or will be configured to use) a centralized authentication scheme such as Oracle Access Manager, or SSO.</p>',
'<p><em><strong>Note:</strong> This application supports the following 3 access levels: Reader, Contributor, and Administrator.',
'<ul>',
'  <li><strong>Readers</strong> have read-only access to all information and can also view reports.</li>',
'  <li><strong>Contributors</strong> can create, edit and delete information and view reports.</li>',
'  <li><strong>Administrators</strong>, in addition to Contributors capability, can also perform configuration of the application by accessing the Administration section of the application.</li>',
'</ul>',
'</em></p>'))
,p_page_component_map=>'16'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187294680394063989)
,p_plug_name=>'Access Control Configuration'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187294728932063989)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187295995677063990)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187294728932063989)
,p_button_name=>'APPLY_CHANGES'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Apply Changes'
,p_button_position=>'CREATE'
,p_button_alignment=>'RIGHT'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187296274874063991)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187294728932063989)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_branch(
 p_id=>wwv_flow_imp.id(3187297645610063991)
,p_branch_name=>'Branch to Admin Page'
,p_branch_action=>'f?p=&APP_ID.:10000:&SESSION.::&DEBUG.:::&success_msg=#SUCCESS_MSG#'
,p_branch_point=>'AFTER_PROCESSING'
,p_branch_type=>'REDIRECT_URL'
,p_branch_sequence=>10
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187297965174063991)
,p_name=>'P10040_ALLOW_OTHER_USERS'
,p_is_required=>true
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187294680394063989)
,p_prompt=>'Any authenticated user may access this application'
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'if apex_app_setting.get_value( p_name => ''ACCESS_CONTROL_SCOPE'' ) = ''ACL_ONLY'' then',
'    return ''N'';',
'else',
'    return ''Y'';',
'end if;'))
,p_source_type=>'FUNCTION_BODY'
,p_source_language=>'PLSQL'
,p_display_as=>'NATIVE_YES_NO'
,p_cSize=>64
,p_cMaxlength=>4000
,p_cHeight=>4
,p_grid_label_column_span=>3
,p_field_template=>wwv_flow_imp.id(3187171421134063410)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_inline_help_text=>'Choose <strong>No</strong> if all users are defined in the access control list. Choose <strong>Yes</strong> if authenticated users not in the access control list may also use this application.'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'use_defaults', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187296370099063991)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187296274874063991)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187297064265063991)
,p_event_id=>wwv_flow_imp.id(3187296370099063991)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187298303354063992)
,p_process_sequence=>10
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Set Access Control'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'begin',
'    if :P10040_ALLOW_OTHER_USERS = ''Y'' then',
'        apex_app_setting.set_value (',
'            p_name  => ''ACCESS_CONTROL_SCOPE'',',
'            p_value => ''ALL_USERS'');',
'    else',
'        apex_app_setting.set_value (',
'            p_name  => ''ACCESS_CONTROL_SCOPE'',',
'            p_value => ''ACL_ONLY'');',
'    end if;',
'end;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_success_message=>'Access Control settings saved.'
,p_internal_uid=>3187298303354063992
);
end;
/
prompt --application/pages/page_10041
begin
wwv_flow_imp_page.create_page(
 p_id=>10041
,p_name=>'Manage User Access'
,p_alias=>'MANAGE-USER-ACCESS'
,p_page_mode=>'MODAL'
,p_step_title=>'Manage User Access'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200316965063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>This page shows a report of the application users and the access level granted.</p>',
'<p>Click on the column headings to sort and filter data, or click on the <strong>Actions</strong> button to customize column display and many additional advanced features.<br>',
'Click the <strong>Reset</strong> button to reset the interactive report back to the default settings.</p>',
'<p>Click the edit icon (yellow pencil) to edit the user details and access level, or to delete the user.</p>',
'<p>Click <strong>Add User</strong>, at the top of the report, to add a new user and their access level.</p>'))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187298761198063992)
,p_plug_name=>'Manage User Access'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select id,',
'   user_name_lc USERNAME,',
'   role_names ACCESS_ROLE',
'from APEX_APPL_ACL_USERS',
'where APPLICATION_ID = :APP_ID'))
,p_plug_source_type=>'NATIVE_IR'
,p_prn_page_header=>'Manage User Access'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187299870413063993)
,p_name=>'Manage User Access'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'C'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link=>'f?p=&APP_ID.:10042:&APP_SESSION.::::P10042_ID:#ID#'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187299870413063993
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187300387415064144)
,p_db_column_name=>'ID'
,p_display_order=>10
,p_column_identifier=>'A'
,p_column_label=>'ID'
,p_column_type=>'NUMBER'
,p_display_text_as=>'HIDDEN_ESCAPE_SC'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187300659532064145)
,p_db_column_name=>'USERNAME'
,p_display_order=>20
,p_column_identifier=>'B'
,p_column_label=>'Username'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187301021811064146)
,p_db_column_name=>'ACCESS_ROLE'
,p_display_order=>30
,p_column_identifier=>'C'
,p_column_label=>'Roles'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187301758820064146)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31873018'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'USERNAME:ACCESS_ROLE'
,p_sort_column_2=>'USERNAME'
,p_sort_direction_2=>'ASC'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187302610349064147)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187298761198063992)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft:t-Button--gapRight'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187303126877064147)
,p_button_sequence=>30
,p_button_plug_id=>wwv_flow_imp.id(3187298761198063992)
,p_button_name=>'ADD_MULTIPLE_USERS'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Add Multiple Users'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:10043:&SESSION.::&DEBUG.:10043::'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187303524522064148)
,p_button_sequence=>40
,p_button_plug_id=>wwv_flow_imp.id(3187298761198063992)
,p_button_name=>'ADD_USER'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Add User'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:10042:&SESSION.::&DEBUG.:10042'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187298851593063992)
,p_name=>'Refresh Report'
,p_event_sequence=>10
,p_triggering_element_type=>'REGION'
,p_triggering_region_id=>wwv_flow_imp.id(3187298761198063992)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'apexafterclosedialog'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187304111930064148)
,p_event_id=>wwv_flow_imp.id(3187298851593063992)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_REFRESH'
,p_affected_elements_type=>'REGION'
,p_affected_region_id=>wwv_flow_imp.id(3187298761198063992)
,p_attribute_01=>'N'
);
end;
/
prompt --application/pages/page_10042
begin
wwv_flow_imp_page.create_page(
 p_id=>10042
,p_name=>'Manage User Access'
,p_alias=>'USER_ACCESS'
,p_page_mode=>'MODAL'
,p_step_title=>'Manage User Access'
,p_first_item=>'AUTO_FIRST_ITEM'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200316965063428)
,p_dialog_chained=>'N'
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>Use this form to enter users, their email address and set their access level. ',
'The settings defined under <em>Configure Access Control</em> will determine whether the username must be their email address or can be any alphanumeric entry.</p>',
'<p>This application supports the following 3 access levels: Reader, Contributor, and Administrator.</p>',
'<ul>',
'  <li><strong>Readers</strong> have read-only access to all information and can also view reports.</li>',
'  <li><strong>Contributors</strong> can create, edit and delete information and view reports.</li>',
'  <li><strong>Administrators</strong>, in addition to Contributors capability, can also perform configuration of the application by accessing the Administration section of the application.</li>',
'</ul>',
'<p>When editing an existing user you can lock their account which will prevent them from accessing the application.</p>',
'<p><em><strong>Note:</strong>   If using Oracle Application Express accounts then users entered here must also be defined as end users by a Workspace Administrator, who can also set their password.</em></p>'))
,p_page_component_map=>'02'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187304662091064148)
,p_plug_name=>'Form on Manage User Access'
,p_region_template_options=>'#DEFAULT#:t-Form--stretchInputs'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_query_type=>'TABLE'
,p_query_table=>'APEX_APPL_ACL_USERS'
,p_include_rowid_column=>false
,p_is_editable=>true
,p_edit_operations=>'i:u:d'
,p_lost_update_check_type=>'VALUES'
,p_plug_source_type=>'NATIVE_FORM'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187304768994064148)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187307504825064150)
,p_button_sequence=>30
,p_button_plug_id=>wwv_flow_imp.id(3187304768994064148)
,p_button_name=>'SAVE'
,p_button_action=>'SUBMIT'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Apply Changes'
,p_button_position=>'NEXT'
,p_button_alignment=>'RIGHT'
,p_button_condition=>'P10042_ID'
,p_button_condition_type=>'ITEM_IS_NOT_NULL'
,p_database_action=>'UPDATE'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187307966592064151)
,p_button_sequence=>40
,p_button_plug_id=>wwv_flow_imp.id(3187304768994064148)
,p_button_name=>'CREATE'
,p_button_action=>'SUBMIT'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Add User'
,p_button_position=>'NEXT'
,p_button_alignment=>'RIGHT'
,p_button_condition=>'P10042_ID'
,p_button_condition_type=>'ITEM_IS_NULL'
,p_database_action=>'INSERT'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187305779699064149)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187304768994064148)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187307197909064150)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187304768994064148)
,p_button_name=>'DELETE'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#:t-Button--danger:t-Button--simple'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Delete'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
,p_confirm_message=>'&APP_TEXT$DELETE_MSG!RAW.'
,p_confirm_style=>'danger'
,p_button_condition=>'P10042_ID'
,p_button_condition_type=>'ITEM_IS_NOT_NULL'
,p_database_action=>'DELETE'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187308235650064151)
,p_name=>'P10042_ID'
,p_source_data_type=>'NUMBER'
,p_is_primary_key=>true
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_item_source_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_use_cache_before_default=>'NO'
,p_source=>'ID'
,p_source_type=>'REGION_SOURCE_COLUMN'
,p_display_as=>'NATIVE_HIDDEN'
,p_is_persistent=>'N'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187308669556064151)
,p_name=>'P10042_APPLICATION_ID'
,p_source_data_type=>'NUMBER'
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_item_source_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_use_cache_before_default=>'NO'
,p_item_default=>'&APP_ID.'
,p_source=>'APPLICATION_ID'
,p_source_type=>'REGION_SOURCE_COLUMN'
,p_display_as=>'NATIVE_HIDDEN'
,p_is_persistent=>'N'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187309087117064151)
,p_name=>'P10042_USER_NAME'
,p_source_data_type=>'VARCHAR2'
,p_is_required=>true
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_item_source_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_use_cache_before_default=>'NO'
,p_prompt=>'Username'
,p_source=>'USER_NAME'
,p_source_type=>'REGION_SOURCE_COLUMN'
,p_display_as=>'NATIVE_TEXT_FIELD'
,p_cSize=>60
,p_cMaxlength=>255
,p_read_only_when=>'P10042_ID'
,p_read_only_when_type=>'ITEM_IS_NOT_NULL'
,p_field_template=>wwv_flow_imp.id(3187172987677063411)
,p_is_persistent=>'N'
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'disabled', 'N',
  'send_on_page_submit', 'N',
  'submit_when_enter_pressed', 'N',
  'subtype', 'TEXT',
  'trim_spaces', 'BOTH')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187309427763064152)
,p_name=>'P10042_ROLE_IDS'
,p_source_data_type=>'VARCHAR2'
,p_is_required=>true
,p_item_sequence=>40
,p_item_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_item_source_plug_id=>wwv_flow_imp.id(3187304662091064148)
,p_use_cache_before_default=>'NO'
,p_prompt=>'Roles'
,p_source=>'ROLE_IDS'
,p_source_type=>'REGION_SOURCE_COLUMN'
,p_display_as=>'NATIVE_CHECKBOX'
,p_named_lov=>'ACCESS_ROLES'
,p_lov=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select role_name d, role_id r',
'from APEX_APPL_ACL_ROLES where application_id = :APP_ID ',
'order by 1'))
,p_field_template=>wwv_flow_imp.id(3187172987677063411)
,p_is_persistent=>'N'
,p_lov_display_extra=>'NO'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>When Access Control is enabled, Administrators have the ability to restrict access to certain application features for authenticated users. This application supports the following 3 roles: Reader, Contributor, and Administrator.<p>',
'<ul>',
'  <li><strong>Readers</strong> have read-only access to all information and can also view reports.</li>',
'  <li><strong>Contributors</strong> can create,edit and delete information and view reports.</li>',
'  <li><strong>Administrators</strong>,in addition to Contributors capability,can also perform configuration of the application.</li>',
'</ul>'))
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'number_of_columns', '1')).to_clob
,p_multi_value_type=>'SEPARATED'
,p_multi_value_separator=>':'
);
wwv_flow_imp_page.create_page_validation(
 p_id=>wwv_flow_imp.id(3187310714105064153)
,p_validation_name=>'Cannot remove yourself from administrator'
,p_validation_sequence=>10
,p_validation=>wwv_flow_string.join(wwv_flow_t_varchar2(
'if :P10042_USER_NAME = :APP_USER and',
'    apex_acl.is_role_removed_from_user (',
'        p_application_id => :APP_ID,',
'        p_user_name      => :APP_USER,',
'        p_role_static_id => ''ADMINISTRATOR'',',
'        p_role_ids       => apex_string.split_numbers(',
'                                p_str => case when :REQUEST = ''DELETE'' then',
'                                             null',
'                                         else',
'                                             :P10042_ROLE_IDS',
'                                         end,',
'                                p_sep => '':'') ) then',
'    return false;',
'else',
'    return true;',
'end if;'))
,p_validation2=>'PLSQL'
,p_validation_type=>'FUNC_BODY_RETURNING_BOOLEAN'
,p_error_message=>'You cannot remove administrator role from yourself.'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187305861189064149)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187305779699064149)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187306561346064150)
,p_event_id=>wwv_flow_imp.id(3187305861189064149)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187311092152064154)
,p_process_sequence=>10
,p_process_point=>'AFTER_HEADER'
,p_region_id=>wwv_flow_imp.id(3187304662091064148)
,p_process_type=>'NATIVE_FORM_INIT'
,p_process_name=>'Initialize form Manage User Access'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187311092152064154
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187311402511064154)
,p_process_sequence=>20
,p_process_point=>'AFTER_SUBMIT'
,p_region_id=>wwv_flow_imp.id(3187304662091064148)
,p_process_type=>'NATIVE_FORM_DML'
,p_process_name=>'Process form Manage User Access'
,p_attribute_01=>'REGION_SOURCE'
,p_attribute_05=>'Y'
,p_attribute_06=>'N'
,p_attribute_08=>'N'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187311402511064154
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187311883951064154)
,p_process_sequence=>40
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_CLOSE_WINDOW'
,p_process_name=>'Close Dialog'
,p_attribute_02=>'N'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187311883951064154
);
end;
/
prompt --application/pages/page_10043
begin
wwv_flow_imp_page.create_page(
 p_id=>10043
,p_name=>'Add Multiple Users - Step 1'
,p_alias=>'ADD-MULTIPLE-USERS-STEP-1'
,p_page_mode=>'MODAL'
,p_step_title=>'Add Multiple Users'
,p_first_item=>'AUTO_FIRST_ITEM'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200316965063428)
,p_dialog_chained=>'N'
,p_protection_level=>'C'
,p_deep_linking=>'N'
,p_page_component_map=>'16'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187312269144064154)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187312347290064154)
,p_plug_name=>'Wizard Container'
,p_region_template_options=>'#DEFAULT#:t-Form--stretchInputs'
,p_component_template_options=>'#DEFAULT#:t-WizardSteps--displayCurrentLabelOnly'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187312412299064154)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187312269144064154)
,p_button_name=>'NEXT'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#:t-Button--iconRight'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Next'
,p_button_position=>'NEXT'
,p_button_alignment=>'RIGHT'
,p_icon_css_classes=>'fa-chevron-right'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187314450231064156)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187312269144064154)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_branch(
 p_id=>wwv_flow_imp.id(3187315731682064156)
,p_branch_action=>'f?p=&APP_ID.:10044:&SESSION.::&DEBUG.:RP,10044::&success_msg=#SUCCESS_MSG#'
,p_branch_point=>'AFTER_PROCESSING'
,p_branch_type=>'REDIRECT_URL'
,p_branch_when_button_id=>wwv_flow_imp.id(3187312412299064154)
,p_branch_sequence=>10
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187316166028064157)
,p_name=>'P10043_ROLE'
,p_is_required=>true
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187312347290064154)
,p_prompt=>'Roles'
,p_display_as=>'NATIVE_CHECKBOX'
,p_named_lov=>'ACCESS_ROLES'
,p_lov=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select role_name d, role_id r',
'from APEX_APPL_ACL_ROLES where application_id = :APP_ID ',
'order by 1'))
,p_field_template=>wwv_flow_imp.id(3187172987677063411)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'number_of_columns', '3')).to_clob
,p_multi_value_type=>'SEPARATED'
,p_multi_value_separator=>':'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187316554623064157)
,p_name=>'P10043_PRELIM_USERS'
,p_is_required=>true
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187312347290064154)
,p_prompt=>'Usernames'
,p_placeholder=>'Enter usernames here'
,p_display_as=>'NATIVE_TEXTAREA'
,p_cSize=>80
,p_cMaxlength=>4000
,p_cHeight=>5
,p_field_template=>wwv_flow_imp.id(3187172987677063411)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_protection_level=>'I'
,p_inline_help_text=>'Enter usernames separated by commas, semicolons, or whitespace. Existing or duplicate usernames will automatically be ignored.'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'auto_height', 'N',
  'character_counter', 'N',
  'resizable', 'Y',
  'trim_spaces', 'BOTH')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187316956796064157)
,p_name=>'P10043_USERNAME_FORMAT'
,p_item_sequence=>40
,p_item_plug_id=>wwv_flow_imp.id(3187312347290064154)
,p_prompt=>'Username Format'
,p_display_as=>'NATIVE_CHECKBOX'
,p_named_lov=>'EMAIL_USERNAME_FORMAT'
,p_lov=>'.'||wwv_flow_imp.id(3187317082060064157)||'.'
,p_field_template=>wwv_flow_imp.id(3187172987677063411)
,p_item_template_options=>'#DEFAULT#'
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'number_of_columns', '1')).to_clob
,p_multi_value_type=>'SEPARATED'
,p_multi_value_separator=>':'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187314568738064156)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187314450231064156)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187315248132064156)
,p_event_id=>wwv_flow_imp.id(3187314568738064156)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187318000282064158)
,p_process_sequence=>10
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Create Collections'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'declare',
'    l_line      varchar2(32767);',
'    l_emails    apex_t_varchar2;',
'    l_username  varchar2(4000);',
'    l_at        number;',
'    l_dot       number;',
'    l_valid     boolean := true;',
'    l_domain    varchar2(4000);',
'begin',
'    -- create collections',
'    apex_collection.create_or_truncate_collection(''ACL_BULK_USER_INVALID'');',
'    apex_collection.create_or_truncate_collection(''ACL_BULK_USER_VALID'');',
'',
'    -- replace delimiting characters with commas',
'    l_line := :P10043_PRELIM_USERS;',
'    l_line := replace(l_line, chr(10), '' '');',
'    l_line := replace(l_line, chr(13), '' '');',
'    l_line := replace(l_line, chr(9),  '' '');',
'    l_line := replace(l_line, ''<'', '' '');',
'    l_line := replace(l_line, ''>'', '' '');',
'    l_line := replace(l_line, '';'', '' '');',
'    l_line := replace(l_line, '':'', '' '');',
'    l_line := replace(l_line, ''('', '' '');',
'    l_line := replace(l_line, '')'', '' '');',
'    l_line := replace(l_line, '' '', '','');',
'',
'    -- get one comma separated line of emails',
'    for j in 1 .. 1000 loop',
'        if instr(l_line, '',,'') > 0 then',
'            l_line := replace(l_line, '',,'', '','');',
'        else',
'            exit;',
'        end if;',
'    end loop;',
'',
'    -- get an array of emails',
'    l_emails := apex_string.split(l_line, '','');',
'',
'    -- add emails to a collection',
'    l_username := null;',
'    l_domain   := null;',
'    l_at       := 0;',
'    l_dot      := 0;',
'    for j in 1..l_emails.count loop',
'        l_valid    := true;',
'        l_username := upper(trim(l_emails(j)));',
'        l_username := trim(both ''.'' from l_username);',
'        l_username := replace(l_username, '' '', null);',
'        l_username := replace(l_username, chr(10), null);',
'        l_username := replace(l_username, chr(9), null);',
'        l_username := replace(l_username, chr(13), null);',
'        l_username := replace(l_username, chr(49824), null);',
'',
'        if l_username is not null then',
'            if nvl(:P10043_USERNAME_FORMAT,''x'') = ''EMAIL'' then',
'              -- Validate',
'              l_at     := instr(nvl(l_username, ''x''), ''@'');',
'              l_domain := substr(l_username, l_at+1);',
'              l_dot    := instr(l_domain, ''.'');',
'              if l_at < 2 then',
'                  -- invalid email',
'                  apex_collection.add_member(',
'                      p_collection_name => ''ACL_BULK_USER_INVALID'',',
'                      p_c001            => l_username,',
'                      p_c002            => apex_lang.message(''APEX.FEATURE.ACL.BULK_USER.MISSING_AT_SIGN''));',
'                  commit;',
'                  l_valid := false;',
'              end if;',
'',
'              if l_dot = 0 and l_valid then',
'                  apex_collection.add_member(',
'                      p_collection_name => ''ACL_BULK_USER_INVALID'',',
'                      p_c001            => l_username,',
'                      p_c002            => apex_lang.message(''APEX.FEATURE.ACL.BULK_USER.MISSING_DOT''));',
'                  commit;',
'                  l_valid := false;',
'              end if;',
'            end if;',
'',
'            if l_valid and length(l_username) > 255 then',
'                apex_collection.add_member(',
'                    p_collection_name => ''ACL_BULK_USER_INVALID'',',
'                    p_c001            => l_username,',
'                    p_c002            => apex_lang.message(''APEX.FEATURE.ACL.BULK_USER.USERNAME_TOO_LONG''));',
'                commit;',
'                l_valid := false;',
'            end if;',
'',
'            if l_valid then',
'                for c1 in (select user_name username',
'                             from APEX_APPL_ACL_USERS',
'                            where user_name = l_username and application_id = :APP_ID)',
'                loop',
'                    apex_collection.add_member(',
'                        p_collection_name => ''ACL_BULK_USER_INVALID'',',
'                        p_c001            => l_username,',
'                        p_c002            => apex_lang.message(''APEX.FEATURE.ACL.BULK_USER.ALREADY_IN_ACL''));',
'                    commit;',
'                    l_valid := false;',
'                    exit;',
'                end loop;',
'            end if;',
'',
'            if l_valid then',
'                for c1 in (select c001',
'                             from apex_collections',
'                            where collection_name = ''ACL_BULK_USER_VALID''',
'                              and c001            = l_username)',
'                loop',
'                    apex_collection.add_member(',
'                        p_collection_name => ''ACL_BULK_USER_INVALID'',',
'                        p_c001            => l_username,',
'                        p_c002            => apex_lang.message(''APEX.FEATURE.ACL.BULK_USER.DUPLICATE_USER''));',
'                        commit;',
'                    l_valid := false;',
'                    exit;',
'                end loop;',
'            end if;',
'',
'            if l_valid then',
'                apex_collection.add_member(',
'                    p_collection_name => ''ACL_BULK_USER_VALID'',',
'                    p_c001            => l_username,',
'                    p_c002            => null,',
'                    p_c003            => :P10043_ROLE);',
'                    commit;',
'            end if;',
'',
'        end if;',
'        l_username := null;',
'    end loop;',
'end;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187312412299064154)
,p_internal_uid=>3187318000282064158
);
end;
/
prompt --application/pages/page_10044
begin
wwv_flow_imp_page.create_page(
 p_id=>10044
,p_name=>'Add Multiple Users - Step 2'
,p_alias=>'ADD-MULTIPLE-USERS-STEP-2'
,p_page_mode=>'MODAL'
,p_step_title=>'Add Multiple Users'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_inline_css=>wwv_flow_string.join(wwv_flow_t_varchar2(
'.a-ListView-item .fa {',
'  color: var(--ut-component-text-muted-color);',
'}',
'',
'.a-ListView-item .u-success-text {',
'  color: var(--ut-palette-success) !important;',
'}'))
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200316965063428)
,p_protection_level=>'C'
,p_deep_linking=>'N'
,p_page_component_map=>'03'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187312537577064154)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187312666389064154)
,p_plug_name=>'Wizard Container'
,p_region_template_options=>'#DEFAULT#:t-Form--stretchInputs'
,p_component_template_options=>'#DEFAULT#:t-WizardSteps--displayCurrentLabelOnly'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>40
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_report_region(
 p_id=>wwv_flow_imp.id(3187312810057064154)
,p_name=>'Exceptions'
,p_parent_plug_id=>wwv_flow_imp.id(3187312666389064154)
,p_template=>wwv_flow_imp.id(3187065710399063367)
,p_display_sequence=>60
,p_region_template_options=>'#DEFAULT#:t-Region--noPadding:is-collapsed:t-Region--noUI:t-Region--scrollBody'
,p_component_template_options=>'t-Report--stretch:t-Report--staticRowColors:t-Report--rowHighlightOff'
,p_source_type=>'NATIVE_SQL_REPORT'
,p_query_type=>'SQL'
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select c001 username, c002 reason',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_INVALID''',
'order by 1'))
,p_display_when_condition=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select 1',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_INVALID'''))
,p_display_condition_type=>'EXISTS'
,p_ajax_enabled=>'Y'
,p_lazy_loading=>false
,p_query_row_template=>wwv_flow_imp.id(3187139143272063396)
,p_query_num_rows=>10000
,p_query_options=>'DERIVED_REPORT_COLUMNS'
,p_query_no_data_found=>'no data found'
,p_query_row_count_max=>500
,p_pagination_display_position=>'BOTTOM_RIGHT'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187319921339064160)
,p_query_column_id=>1
,p_column_alias=>'USERNAME'
,p_column_display_sequence=>1
,p_column_heading=>'Username'
,p_heading_alignment=>'LEFT'
);
wwv_flow_imp_page.create_report_columns(
 p_id=>wwv_flow_imp.id(3187320360027064161)
,p_query_column_id=>2
,p_column_alias=>'REASON'
,p_column_display_sequence=>2
,p_column_heading=>'Reason'
,p_heading_alignment=>'LEFT'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187312980557064154)
,p_plug_name=>'&P10044_VALID_COUNT. Users to Add'
,p_parent_plug_id=>wwv_flow_imp.id(3187312666389064154)
,p_region_template_options=>'#DEFAULT#'
,p_component_template_options=>'#DEFAULT#:t-Report--stretch:t-Report--staticRowColors:t-Report--rowHighlightOff'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>50
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select distinct c001 username',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID''',
'order by 1'))
,p_plug_source_type=>'NATIVE_JQM_LIST_VIEW'
,p_plug_query_num_rows=>10000
,p_plug_display_condition_type=>'EXISTS'
,p_plug_display_when_condition=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select 1',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'list_view_features', 'ADVANCED_FORMATTING',
  'text_formatting', '<span class="fa fa-check-circle u-success-text" aria-hidden="true"></span> <span style="line-height:36px;text-transform:lowercase;">&USERNAME!HTML.</span>')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187313045867064154)
,p_plug_name=>'Hidden Items'
,p_region_template_options=>'#DEFAULT#'
,p_component_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187323469122064317)
,p_plug_name=>'Valid Users Exist - Page Info'
,p_region_template_options=>'#DEFAULT#:margin-bottom-sm'
,p_component_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>20
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'sys.htp.prn(''<p>'');',
'sys.htp.prn(apex_lang.message (',
'                ''APEX.FEATURE.ACL.BULK_USER.CREATE_CONFIRM'',',
'                apex_escape.html(:P10044_VALID_COUNT),',
'                apex_escape.html(:P10044_ROLE)));',
'sys.htp.prn(''</p>'');'))
,p_plug_source_type=>'NATIVE_PLSQL'
,p_plug_query_num_rows=>15
,p_plug_display_condition_type=>'EXISTS'
,p_plug_display_when_condition=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select 1',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187324182629064318)
,p_plug_name=>'No Valid Users Exist - Page Info'
,p_region_template_options=>'#DEFAULT#:margin-bottom-sm'
,p_component_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>'<p>No valid new users found</p>'
,p_plug_query_num_rows=>15
,p_plug_display_condition_type=>'NOT_EXISTS'
,p_plug_display_when_condition=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select 1',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187313166320064154)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187312537577064154)
,p_button_name=>'SUBMIT'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Add Users'
,p_button_position=>'NEXT'
,p_button_alignment=>'RIGHT'
,p_button_condition=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select 1',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
,p_button_condition_type=>'EXISTS'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187324882664064319)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187312537577064154)
,p_button_name=>'PREVIOUS'
,p_button_action=>'REDIRECT_URL'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187173485940063411)
,p_button_image_alt=>'Previous'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'javascript:history.back();'
,p_icon_css_classes=>'fa-chevron-left'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187325260083064319)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187312537577064154)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'PREVIOUS'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187326590222064320)
,p_name=>'P10044_ROLE'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187313045867064154)
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select LISTAGG( role_name, '', '')',
'         WITHIN GROUP (ORDER BY role_name) role_name',
'from APEX_APPL_ACL_ROLES',
'where application_id = :APP_ID',
'and instr(:P10043_ROLE, role_id, 1) > 0'))
,p_source_type=>'QUERY'
,p_display_as=>'NATIVE_HIDDEN'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_protection_level=>'I'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187326964814064320)
,p_name=>'P10044_VALID_COUNT'
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187313045867064154)
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select count(*)',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
,p_source_type=>'QUERY'
,p_display_as=>'NATIVE_HIDDEN'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_protection_level=>'I'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187327324324064320)
,p_name=>'P10044_INVALID_COUNT'
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187313045867064154)
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select count(*)',
'  from apex_collections',
' where collection_name = ''ACL_BULK_USER_VALID'''))
,p_source_type=>'QUERY'
,p_display_as=>'NATIVE_HIDDEN'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_protection_level=>'I'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187325340155064319)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187325260083064319)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187326091257064319)
,p_event_id=>wwv_flow_imp.id(3187325340155064319)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187327754519064321)
,p_process_sequence=>10
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Add Users to Access Control List'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'declare',
'    l_user_role_ids apex_application_global.vc_arr2;',
'begin',
'    for c in (  select distinct c001 as username, c003 as user_roles',
'                from   apex_collections',
'                where  collection_name = ''ACL_BULK_USER_VALID'' )',
'    loop',
'         l_user_role_ids := apex_util.string_to_table(c.user_roles);',
'         for i in 1..l_user_role_ids.count loop',
'             apex_acl.add_user_role(p_application_id => :APP_ID, p_user_name => c.username, p_role_id => l_user_role_ids(i));',
'         end loop;',
'    end loop;',
'',
'    apex_collection.delete_collection(''ACL_BULK_USER_INVALID'');',
'    apex_collection.delete_collection(''ACL_BULK_USER_VALID'');',
'    :P10043_PRELIM_USERS := null;',
'end;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187313166320064154)
,p_process_success_message=>'User(s) added.'
,p_internal_uid=>3187327754519064321
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187328178317064321)
,p_process_sequence=>20
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_CLOSE_WINDOW'
,p_process_name=>'Close Dialog'
,p_attribute_02=>'N'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187328178317064321
);
end;
/
prompt --application/pages/page_10050
begin
wwv_flow_imp_page.create_page(
 p_id=>10050
,p_name=>'Feedback'
,p_alias=>'FEEDBACK'
,p_page_mode=>'MODAL'
,p_step_title=>'Feedback'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_inline_css=>wwv_flow_string.join(wwv_flow_t_varchar2(
'.feedback-positive, .feedback-negative, .feedback-neutral { padding: 8px; border-radius: 100%; background-color: white; margin: 4px; }',
'.feedback-positive { color: var(--ut-feedback-positive-text-color, var(--ut-palette-success)); }',
'.feedback-neutral { color: var(--ut-feedback-neutral-text-color, var(--ut-palette-warning)); }',
'.feedback-negative { color: var(--ut-feedback-negative-text-color, var(--ut-palette-danger)); }'))
,p_required_patch=>wwv_flow_imp.id(3187200520254063428)
,p_dialog_width=>'480'
,p_dialog_chained=>'N'
,p_protection_level=>'C'
,p_page_component_map=>'16'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187328511272064321)
,p_plug_name=>'Form on Feedback'
,p_region_template_options=>'#DEFAULT#:t-Form--stretchInputs'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187328676474064321)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187328791524064321)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187328676474064321)
,p_button_name=>'SUBMIT'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#:t-Button--gapLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Submit Feedback'
,p_button_position=>'CREATE'
,p_button_alignment=>'RIGHT'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187331723976064322)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187328676474064321)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'EDIT'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_branch(
 p_id=>wwv_flow_imp.id(3187337491655064326)
,p_branch_action=>'f?p=&APP_ID.:10051:&SESSION.::&DEBUG.:RP::'
,p_branch_point=>'AFTER_PROCESSING'
,p_branch_type=>'REDIRECT_URL'
,p_branch_sequence=>10
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187333036367064323)
,p_name=>'P10050_APPLICATION_ID'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187328511272064321)
,p_use_cache_before_default=>'NO'
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187333428097064323)
,p_name=>'P10050_PAGE_ID'
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187328511272064321)
,p_use_cache_before_default=>'NO'
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187333868722064324)
,p_name=>'P10050_USER_AGENT'
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187328511272064321)
,p_use_cache_before_default=>'NO'
,p_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select sys.owa_util.get_cgi_env(''user-agent'') x',
'from dual'))
,p_source_type=>'QUERY'
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187334288504064324)
,p_name=>'P10050_RATING'
,p_item_sequence=>35
,p_item_plug_id=>wwv_flow_imp.id(3187328511272064321)
,p_prompt=>'Experience'
,p_display_as=>'NATIVE_RADIOGROUP'
,p_named_lov=>'FEEDBACK_RATING'
,p_lov=>'.'||wwv_flow_imp.id(3187334390079064324)||'.'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_item_template_options=>'#DEFAULT#:t-Form-fieldContainer--radioButtonGroup'
,p_lov_display_extra=>'NO'
,p_escape_on_http_output=>'N'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'execute_validations', 'Y',
  'hide_radio_buttons', 'N',
  'number_of_columns', '3',
  'page_action_on_selection', 'NONE')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187336182236064325)
,p_name=>'P10050_FEEDBACK'
,p_item_sequence=>40
,p_item_plug_id=>wwv_flow_imp.id(3187328511272064321)
,p_prompt=>'Feedback'
,p_display_as=>'NATIVE_TEXTAREA'
,p_cSize=>64
,p_cMaxlength=>4000
,p_cHeight=>4
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'auto_height', 'N',
  'character_counter', 'N',
  'resizable', 'Y',
  'trim_spaces', 'BOTH')).to_clob
);
wwv_flow_imp_page.create_page_validation(
 p_id=>wwv_flow_imp.id(3187337002861064326)
,p_validation_name=>'At least One Feedback Required'
,p_validation_sequence=>10
,p_validation=>wwv_flow_string.join(wwv_flow_t_varchar2(
'if :P10050_FEEDBACK is null and :P10050_RATING is null then',
'    return false;',
'else',
'    return true;',
'end if;'))
,p_validation2=>'PLSQL'
,p_validation_type=>'FUNC_BODY_RETURNING_BOOLEAN'
,p_error_message=>'Please provide feedback or your experience.'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187331833539064322)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187331723976064322)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187332522824064323)
,p_event_id=>wwv_flow_imp.id(3187331833539064322)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187336654704064326)
,p_process_sequence=>10
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Submit Feedback'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'begin',
'apex_util.submit_feedback (',
'    p_comment              => :P10050_FEEDBACK,',
'    p_application_id       => :APP_ID,',
'    p_page_id              => :P10050_PAGE_ID,',
'    p_rating               => :P10050_RATING',
'',
'    );',
'end;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187328791524064321)
,p_process_success_message=>'Feedback Submitted'
,p_internal_uid=>3187336654704064326
);
end;
/
prompt --application/pages/page_10051
begin
wwv_flow_imp_page.create_page(
 p_id=>10051
,p_name=>'Feedback Submitted'
,p_alias=>'FEEDBACK-SUBMITTED'
,p_page_mode=>'MODAL'
,p_step_title=>'Feedback Submitted'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_required_patch=>wwv_flow_imp.id(3187200520254063428)
,p_protection_level=>'C'
,p_page_component_map=>'11'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187329112294064321)
,p_plug_name=>'Feedback Submitted'
,p_icon_css_classes=>'fa-check-circle'
,p_region_template_options=>'#DEFAULT#:t-Alert--wizard:t-Alert--customIcons:t-Alert--success'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187041800015063357)
,p_plug_display_sequence=>10
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187329045897064321)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187329112294064321)
,p_button_name=>'CLOSE'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Close'
,p_button_position=>'EDIT'
,p_button_alignment=>'RIGHT'
,p_button_css_classes=>'w40p'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187329241046064321)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187329045897064321)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187339081264064327)
,p_event_id=>wwv_flow_imp.id(3187329241046064321)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
end;
/
prompt --application/pages/page_10053
begin
wwv_flow_imp_page.create_page(
 p_id=>10053
,p_name=>'Manage Feedback'
,p_alias=>'MANAGE-FEEDBACK'
,p_page_mode=>'MODAL'
,p_step_title=>'Manage Feedback'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_inline_css=>wwv_flow_string.join(wwv_flow_t_varchar2(
'/* Color feedback rating icons */',
'.feedback-positive { color: var(--ut-feedback-positive-text-color, var(--ut-palette-success)); }',
'.feedback-neutral { color: var(--ut-feedback-neutral-text-color, var(--ut-palette-warning)); }',
'.feedback-negative { color: var(--ut-feedback-negative-text-color, var(--ut-palette-danger)); }'))
,p_page_template_options=>'#DEFAULT#:ui-dialog--stretch:t-Dialog--noPadding'
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200520254063428)
,p_protection_level=>'C'
,p_help_text=>wwv_flow_string.join(wwv_flow_t_varchar2(
'<p>Feedback can be entered by end users from any normal page within the application.</p>',
'<p>This report shows the feedback entered, any response enter by administrators, and the status of the feedback.</p>',
'<p>Click the edit icon (yellow pencil) to enter a response or update the feedback status.</p>',
'<p><em><strong>Note:</strong> If feedback recipients have been defined then feedback submissions will also be emailed to the email addresses in the feedback recipients list.</em></p>'))
,p_page_component_map=>'18'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187330498244064321)
,p_plug_name=>'Manage Feedback'
,p_region_template_options=>'#DEFAULT#:t-IRR-region--noBorders'
,p_plug_template=>wwv_flow_imp.id(3187097299988063379)
,p_plug_display_sequence=>10
,p_query_type=>'SQL'
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'select feedback_id id,',
'    page_id||''. ''||page_name page_name,',
'    created_on created,',
'    lower(created_by) created_by,',
'    feedback,',
'    feedback_rating rating,',
'    case feedback_rating',
'      when 1 then ''fa-frown-o feedback-negative'' ',
'      when 2 then ''fa-emoji-neutral feedback-neutral''  ',
'      when 3 then ''fa-smile-o feedback-positive''',
'    end rating_icon,',
'    feedback_status status,',
'    public_response response,',
'    http_user_agent user_agent,',
'    updated_on updated,',
'    lower(updated_by) updated_by,',
'    page_id',
'',
'',
'',
'',
'from apex_team_feedback f',
'where application_id = :APP_ID'))
,p_plug_source_type=>'NATIVE_IR'
,p_prn_page_header=>'Manage Feedback'
);
wwv_flow_imp_page.create_worksheet(
 p_id=>wwv_flow_imp.id(3187350289364064335)
,p_name=>'Manage Feedback'
,p_max_row_count=>'1000000'
,p_max_row_count_message=>'The maximum row count for this report is #MAX_ROW_COUNT# rows.  Please apply a filter to reduce the number of records in your query.'
,p_no_data_found_message=>'No data found.'
,p_pagination_type=>'ROWS_X_TO_Y'
,p_pagination_display_pos=>'BOTTOM_RIGHT'
,p_report_list_mode=>'TABS'
,p_lazy_loading=>false
,p_show_detail_link=>'C'
,p_download_formats=>'CSV:HTML:XLSX:PDF'
,p_enable_mail_download=>'Y'
,p_detail_link=>'f?p=&APP_ID.:10054:&APP_SESSION.::::P10054_ID:#ID#'
,p_detail_link_text=>'<span aria-label="Edit"><span class="fa fa-edit" aria-hidden="true" title="Edit"></span></span>'
,p_owner=>'OGOBRECHT'
,p_internal_uid=>3187350289364064335
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187350306262064335)
,p_db_column_name=>'ID'
,p_display_order=>1
,p_column_identifier=>'A'
,p_column_label=>'ID'
,p_column_type=>'NUMBER'
,p_display_text_as=>'HIDDEN_ESCAPE_SC'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187350783258064336)
,p_db_column_name=>'PAGE_NAME'
,p_display_order=>11
,p_column_identifier=>'B'
,p_column_label=>'Page'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187351125415064336)
,p_db_column_name=>'CREATED'
,p_display_order=>21
,p_column_identifier=>'C'
,p_column_label=>'Filed'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_format_mask=>'since'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187351574755064337)
,p_db_column_name=>'CREATED_BY'
,p_display_order=>31
,p_column_identifier=>'D'
,p_column_label=>'Filed By'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187351942907064337)
,p_db_column_name=>'FEEDBACK'
,p_display_order=>41
,p_column_identifier=>'E'
,p_column_label=>'Feedback'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187352383681064338)
,p_db_column_name=>'RATING'
,p_display_order=>51
,p_column_identifier=>'F'
,p_column_label=>'Rating'
,p_column_html_expression=>'<span class="fa #RATING_ICON#" aria-hidden="true" title="#RATING#"></span>'
,p_column_type=>'STRING'
,p_display_text_as=>'LOV_ESCAPE_SC'
,p_column_alignment=>'CENTER'
,p_tz_dependent=>'N'
,p_rpt_named_lov=>wwv_flow_imp.id(3187334390079064324)
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187352767625064338)
,p_db_column_name=>'RATING_ICON'
,p_display_order=>55
,p_column_identifier=>'G'
,p_column_label=>'RATING ICON'
,p_column_type=>'STRING'
,p_display_text_as=>'HIDDEN_ESCAPE_SC'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187353127019064339)
,p_db_column_name=>'STATUS'
,p_display_order=>61
,p_column_identifier=>'H'
,p_column_label=>'Status'
,p_column_type=>'NUMBER'
,p_display_text_as=>'LOV_ESCAPE_SC'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_rpt_named_lov=>wwv_flow_imp.id(3187344748395064331)
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187353535678064339)
,p_db_column_name=>'RESPONSE'
,p_display_order=>71
,p_column_identifier=>'I'
,p_column_label=>'Response'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187353938718064340)
,p_db_column_name=>'USER_AGENT'
,p_display_order=>81
,p_column_identifier=>'J'
,p_column_label=>'User Agent'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187354342948064340)
,p_db_column_name=>'UPDATED'
,p_display_order=>91
,p_column_identifier=>'K'
,p_column_label=>'Updated'
,p_column_type=>'DATE'
,p_heading_alignment=>'LEFT'
,p_format_mask=>'since'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187354750007064341)
,p_db_column_name=>'UPDATED_BY'
,p_display_order=>101
,p_column_identifier=>'L'
,p_column_label=>'Updated By'
,p_column_type=>'STRING'
,p_heading_alignment=>'LEFT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_column(
 p_id=>wwv_flow_imp.id(3187355156160064341)
,p_db_column_name=>'PAGE_ID'
,p_display_order=>111
,p_column_identifier=>'M'
,p_column_label=>'Page'
,p_column_type=>'NUMBER'
,p_heading_alignment=>'RIGHT'
,p_column_alignment=>'RIGHT'
,p_tz_dependent=>'N'
,p_use_as_row_header=>'N'
);
wwv_flow_imp_page.create_worksheet_rpt(
 p_id=>wwv_flow_imp.id(3187355979335064342)
,p_application_user=>'APXWS_DEFAULT'
,p_report_seq=>10
,p_report_alias=>'31873560'
,p_status=>'PUBLIC'
,p_is_default=>'Y'
,p_report_columns=>'PAGE_NAME:CREATED:CREATED_BY:FEEDBACK:RATING:STATUS:RESPONSE:UPDATED:UPDATED_BY'
,p_sort_column_1=>'UPDATED'
,p_sort_direction_1=>'DESC'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187356820517064343)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187330498244064321)
,p_button_name=>'RESET_REPORT'
,p_button_action=>'REDIRECT_PAGE'
,p_button_template_options=>'t-Button--iconLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174230973063412)
,p_button_image_alt=>'Reset'
,p_button_position=>'RIGHT_OF_IR_SEARCH_BAR'
,p_button_alignment=>'RIGHT'
,p_button_redirect_url=>'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::&DEBUG.:&APP_PAGE_ID.,RR::'
,p_icon_css_classes=>'fa-undo-alt'
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187330359955064321)
,p_name=>'Refresh Report'
,p_event_sequence=>10
,p_triggering_element_type=>'REGION'
,p_triggering_region_id=>wwv_flow_imp.id(3187330498244064321)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'apexafterclosedialog'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187358132282064345)
,p_event_id=>wwv_flow_imp.id(3187330359955064321)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_REFRESH'
,p_affected_elements_type=>'REGION'
,p_affected_region_id=>wwv_flow_imp.id(3187330498244064321)
,p_attribute_01=>'N'
);
end;
/
prompt --application/pages/page_10054
begin
wwv_flow_imp_page.create_page(
 p_id=>10054
,p_name=>'Feedback'
,p_alias=>'FEEDBACK1'
,p_page_mode=>'MODAL'
,p_step_title=>'Feedback'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_inline_css=>wwv_flow_string.join(wwv_flow_t_varchar2(
'/* Color feedback rating icons */',
'.feedback-positive { color: var(--ut-feedback-positive-text-color, var(--ut-palette-success)); }',
'.feedback-neutral { color: var(--ut-feedback-neutral-text-color, var(--ut-palette-warning)); }',
'.feedback-negative { color: var(--ut-feedback-negative-text-color, var(--ut-palette-danger)); }'))
,p_required_role=>wwv_flow_imp.id(3187203052990063429)
,p_required_patch=>wwv_flow_imp.id(3187200520254063428)
,p_dialog_chained=>'N'
,p_protection_level=>'C'
,p_page_component_map=>'16'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187329727918064321)
,p_plug_name=>'Form Items Region'
,p_region_template_options=>'#DEFAULT#:t-Form--stretchInputs'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187329807934064321)
,p_plug_name=>'Buttons'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187049829875063360)
,p_plug_display_sequence=>10
,p_plug_display_point=>'REGION_POSITION_03'
,p_plug_query_num_rows=>15
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'expand_shortcuts', 'N',
  'output_as', 'HTML',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187329922060064321)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187329807934064321)
,p_button_name=>'SAVE'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#:t-Button--gapLeft'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_is_hot=>'Y'
,p_button_image_alt=>'Apply Changes'
,p_button_position=>'CREATE'
,p_button_alignment=>'RIGHT'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187340632702064329)
,p_button_sequence=>10
,p_button_plug_id=>wwv_flow_imp.id(3187329807934064321)
,p_button_name=>'CANCEL'
,p_button_action=>'DEFINED_BY_DA'
,p_button_template_options=>'#DEFAULT#'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Cancel'
,p_button_position=>'EDIT'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
);
wwv_flow_imp_page.create_page_button(
 p_id=>wwv_flow_imp.id(3187330182112064321)
,p_button_sequence=>20
,p_button_plug_id=>wwv_flow_imp.id(3187329807934064321)
,p_button_name=>'DELETE'
,p_button_action=>'SUBMIT'
,p_button_template_options=>'#DEFAULT#:t-Button--danger:t-Button--simple'
,p_button_template_id=>wwv_flow_imp.id(3187174154034063412)
,p_button_image_alt=>'Delete'
,p_button_position=>'EDIT'
,p_button_alignment=>'RIGHT'
,p_button_execute_validations=>'N'
,p_confirm_message=>'&APP_TEXT$DELETE_MSG!RAW.'
,p_confirm_style=>'danger'
,p_button_condition=>'P10054_ID'
,p_button_condition_type=>'ITEM_IS_NOT_NULL'
,p_database_action=>'DELETE'
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187342242089064329)
,p_name=>'P10054_ID'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187342624030064330)
,p_name=>'P10054_PAGE_ID'
,p_item_sequence=>20
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Page'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187343030788064330)
,p_name=>'P10054_FILED'
,p_item_sequence=>30
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Filed'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_begin_on_new_line=>'N'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187343408820064330)
,p_name=>'P10054_RATING_ICON'
,p_item_sequence=>40
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Rating'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_begin_on_new_line=>'N'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_escape_on_http_output=>'N'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'HTML_UNSAFE',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187343899537064331)
,p_name=>'P10054_FEEDBACK'
,p_item_sequence=>50
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Feedback'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187344287295064331)
,p_name=>'P10054_RESPONSE'
,p_item_sequence=>60
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Response'
,p_display_as=>'NATIVE_TEXTAREA'
,p_cSize=>64
,p_cMaxlength=>4000
,p_cHeight=>4
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'auto_height', 'N',
  'character_counter', 'N',
  'resizable', 'Y',
  'trim_spaces', 'BOTH')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187344686706064331)
,p_name=>'P10054_FEEDBACK_STATUS'
,p_item_sequence=>70
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'Status'
,p_display_as=>'NATIVE_SELECT_LIST'
,p_named_lov=>'FEEDBACK_STATUS'
,p_lov=>'.'||wwv_flow_imp.id(3187344748395064331)||'.'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'execute_validations', 'Y',
  'page_action_on_selection', 'NONE')).to_clob
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187346998022064333)
,p_name=>'P10054_USER_AGENT'
,p_item_sequence=>100
,p_item_plug_id=>wwv_flow_imp.id(3187329727918064321)
,p_prompt=>'User Agent'
,p_display_as=>'NATIVE_DISPLAY_ONLY'
,p_field_template=>wwv_flow_imp.id(3187171670589063410)
,p_lov_display_extra=>'NO'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'based_on', 'VALUE',
  'format', 'PLAIN',
  'send_on_page_submit', 'Y',
  'show_line_breaks', 'Y')).to_clob
);
wwv_flow_imp_page.create_page_da_event(
 p_id=>wwv_flow_imp.id(3187340794880064329)
,p_name=>'Cancel Dialog'
,p_event_sequence=>10
,p_triggering_element_type=>'BUTTON'
,p_triggering_button_id=>wwv_flow_imp.id(3187340632702064329)
,p_bind_type=>'bind'
,p_execution_type=>'IMMEDIATE'
,p_bind_event_type=>'click'
);
wwv_flow_imp_page.create_page_da_action(
 p_id=>wwv_flow_imp.id(3187341452023064329)
,p_event_id=>wwv_flow_imp.id(3187340794880064329)
,p_event_result=>'TRUE'
,p_action_sequence=>10
,p_execute_on_page_init=>'N'
,p_action=>'NATIVE_DIALOG_CANCEL'
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187347411975064333)
,p_process_sequence=>10
,p_process_point=>'AFTER_HEADER'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Load Data'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'for l_feedback in (',
'   select page_id,',
'          page_name,',
'          case feedback_rating',
'                when 1 then ''<span class="fa fa-frown-o feedback-negative" aria-hidden="true" title="Negative"></span>'' ',
'                when 2 then ''<span class="fa fa-emoji-neutral feedback-neutral" aria-hidden="true" title="Neutral"></span>''  ',
'                when 3 then ''<span class="fa fa-smile-o feedback-positive" aria-hidden="true" title="Positive"></span>'' ',
'                end rating_icon,',
'          lower(created_by) || '' - '' || apex_util.get_since(created_on) filed,',
'          feedback,',
'          public_response,',
'          feedback_status,',
'          http_user_agent',
'     from apex_team_feedback',
'    where feedback_id = :P10054_ID )',
'loop',
'   :P10054_PAGE_ID         := l_feedback.page_id||''. ''||l_feedback.page_name;',
'   :P10054_FILED           := l_feedback.filed;',
'   :P10054_RATING_ICON     := l_feedback.rating_icon;',
'   :P10054_FEEDBACK        := l_feedback.feedback;',
'   :P10054_RESPONSE        := l_feedback.public_response;',
'   :P10054_FEEDBACK_STATUS := l_feedback.feedback_status;',
'   :P10054_USER_AGENT      := l_feedback.http_user_agent;',
'end loop;'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187347411975064333
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187347836941064333)
,p_process_sequence=>10
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Reply to Feedback'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'apex_util.reply_to_feedback (',
'    p_feedback_id     => :P10054_ID,',
'    p_status          => :P10054_FEEDBACK_STATUS,',
'    p_public_response => :P10054_RESPONSE );'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187329922060064321)
,p_process_success_message=>'Action Processed.'
,p_internal_uid=>3187347836941064333
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187348262644064334)
,p_process_sequence=>20
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_PLSQL'
,p_process_name=>'Delete Feedback'
,p_process_sql_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'apex_util.delete_feedback (',
'    p_feedback_id => :P10054_ID );'))
,p_process_clob_language=>'PLSQL'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187330182112064321)
,p_process_success_message=>'Feedback Deleted'
,p_internal_uid=>3187348262644064334
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187348679690064334)
,p_process_sequence=>40
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_SESSION_STATE'
,p_process_name=>'Clear Page(s) Cache'
,p_attribute_01=>'CLEAR_CACHE_CURRENT_PAGE'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_process_when_button_id=>wwv_flow_imp.id(3187330182112064321)
,p_internal_uid=>3187348679690064334
);
wwv_flow_imp_page.create_page_process(
 p_id=>wwv_flow_imp.id(3187349081155064334)
,p_process_sequence=>50
,p_process_point=>'AFTER_SUBMIT'
,p_process_type=>'NATIVE_CLOSE_WINDOW'
,p_process_name=>'Close Dialog'
,p_attribute_02=>'N'
,p_error_display_location=>'INLINE_IN_NOTIFICATION'
,p_internal_uid=>3187349081155064334
);
end;
/
prompt --application/pages/page_10060
begin
wwv_flow_imp_page.create_page(
 p_id=>10060
,p_name=>'About'
,p_alias=>'HELP'
,p_page_mode=>'MODAL'
,p_step_title=>'About This Application'
,p_warn_on_unsaved_changes=>'N'
,p_first_item=>'AUTO_FIRST_ITEM'
,p_autocomplete_on_off=>'OFF'
,p_group_id=>wwv_flow_imp.id(3187204642715063431)
,p_page_template_options=>'#DEFAULT#'
,p_required_patch=>wwv_flow_imp.id(3187201089189063428)
,p_page_is_public_y_n=>'Y'
,p_protection_level=>'C'
,p_help_text=>'All application help text can be accessed from this page. The links in the "Documentation" region give a much more in-depth explanation of the application''s features and functionality.'
,p_page_component_map=>'10'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187359082159064345)
,p_plug_name=>'About This App'
,p_region_template_options=>'#DEFAULT#:t-Region--noPadding:t-Region--hideHeader:t-Region--noBorder:t-Region--scrollBody'
,p_plug_template=>wwv_flow_imp.id(3187101599337063381)
,p_plug_display_sequence=>20
,p_location=>null
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'htp.p(apex_markdown.to_html(''',
'',
'Hi,',
'',
'I am Ottmar Gobrecht and this is my Oracle APEX playground.',
'',
'I use this app to showcase my open source code and to test ideas.',
'',
'You can download this app as it currently is. Have a look in the top right ',
'navigation menu under the question mark entry. When I working on it, some things',
'can be broken some times...',
'',
'Happy APEXing :-)',
'',
'Ottmar',
'',
'''));'))
,p_plug_source_type=>'NATIVE_PLSQL'
);
end;
/
prompt --application/pages/page_10061
begin
wwv_flow_imp_page.create_page(
 p_id=>10061
,p_name=>'Help'
,p_alias=>'PAGE_HELP'
,p_page_mode=>'MODAL'
,p_step_title=>'Help'
,p_warn_on_unsaved_changes=>'N'
,p_autocomplete_on_off=>'OFF'
,p_page_template_options=>'#DEFAULT#'
,p_required_patch=>wwv_flow_imp.id(3187201089189063428)
,p_dialog_chained=>'N'
,p_page_is_public_y_n=>'Y'
,p_protection_level=>'C'
,p_page_component_map=>'10'
);
wwv_flow_imp_page.create_page_plug(
 p_id=>wwv_flow_imp.id(3187359799747064346)
,p_plug_name=>'Search Dialog'
,p_region_template_options=>'#DEFAULT#'
,p_escape_on_http_output=>'Y'
,p_plug_template=>wwv_flow_imp.id(3187047050139063359)
,p_plug_display_sequence=>10
,p_plug_source=>wwv_flow_string.join(wwv_flow_t_varchar2(
'for c1 in ',
'(',
'    select page_title, help_text ',
'      from apex_application_pages',
'     where page_id = :P10061_PAGE_ID ',
'       and application_id = :APP_ID',
')',
'loop',
'    if c1.help_text is null then',
'        sys.htp.p(''No help is available for this page.'');',
'    else',
'        if substr(c1.help_text, 1, 3) != ''<p>'' then',
'            sys.htp.p(''<p>'');',
'        end if;',
'',
'        sys.htp.p(apex_application.do_substitutions(c1.help_text));',
'',
'        if substr(trim(c1.help_text), -4) != ''</p>'' then',
'            sys.htp.p(''</p>'');',
'        end if;',
'    end if;',
'end loop;'))
,p_plug_source_type=>'NATIVE_PLSQL'
,p_plug_query_num_rows=>15
);
wwv_flow_imp_page.create_page_item(
 p_id=>wwv_flow_imp.id(3187360155325064346)
,p_name=>'P10061_PAGE_ID'
,p_item_sequence=>10
,p_item_plug_id=>wwv_flow_imp.id(3187359799747064346)
,p_display_as=>'NATIVE_HIDDEN'
,p_lov_display_extra=>'NO'
,p_protection_level=>'S'
,p_attributes=>wwv_flow_t_plugin_attributes(wwv_flow_t_varchar2(
  'value_protected', 'Y')).to_clob
);
end;
/
prompt --application/deployment/definition
begin
wwv_flow_imp_shared.create_install(
 p_id=>wwv_flow_imp.id(3198790027011248064)
,p_deinstall_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'-- Plug-in Gantt Objects',
'begin',
'   for i in (',
'      select ''drop table ''',
'             || table_name',
'             || '' cascade constraints purge'' as ddl',
'        from user_tables',
'       where table_name in (',
'                ''PLUGIN_GANTT_DEMO_HOLIDAYS'',',
'                ''PLUGIN_GANTT_DEMO_LINKS'',',
'                ''PLUGIN_GANTT_DEMO_TASKS''',
'             )',
'   )',
'   loop',
'      execute immediate i.ddl;',
'   end loop;',
'end;',
'/',
'',
'begin',
'   for i in (',
'      select ''drop sequence '' || sequence_name as ddl',
'        from user_sequences',
'       where sequence_name in (',
'                ''PLUGIN_GANTT_DEMO_LINKS_SEQ'',',
'                ''PLUGIN_GANTT_DEMO_TASKS_SEQ''',
'             )',
'   )',
'   loop',
'      execute immediate i.ddl;',
'   end loop;',
'end;',
'/',
''))
,p_required_free_kb=>100
,p_required_sys_privs=>'CREATE MATERIALIZED VIEW:CREATE PROCEDURE:CREATE SEQUENCE:CREATE TABLE:CREATE TRIGGER:CREATE VIEW'
);
end;
/
prompt --application/deployment/install/install_console_1_0_1
begin
wwv_flow_imp_shared.create_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_install_id=>wwv_flow_imp.id(3198790027011248064)
,p_name=>'Console 1.0.1'
,p_sequence=>10
,p_script_type=>'INSTALL'
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'--DO NOT CHANGE THIS FILE - IT IS GENERATED WITH THE BUILD SCRIPT sources/build.js',
'set define on',
'set serveroutput on',
'set verify off',
'set feedback off',
'set linesize 240',
'set trimout on',
'set trimspool on',
'whenever sqlerror exit sql.sqlcode rollback',
'',
'prompt ORACLE INSTRUMENTATION CONSOLE: CREATE DATABASE OBJECTS',
'prompt - Project page https://github.com/ogobrecht/console',
'-- select * from all_plsql_object_settings where name = ''CONSOLE'';',
'',
'prompt - Set compiler flags',
'declare',
'  v_apex_installed     varchar2(5) := ''FALSE''; -- Do not change (is set dynamically).',
'  v_utils_public       varchar2(5) := ''FALSE''; -- Make utilities public available (for testing or other usages).',
'  v_native_compilation boolean     := false;   -- Set this to true on your own risk (in the Oracle cloud you will get likely an "insufficient privileges" error)',
'  v_count pls_integer;',
'begin',
'',
'  execute immediate ''alter session set plsql_warnings = ''''enable:all,disable:5004,disable:6005,disable:6006,disable:6009,disable:6010,disable:6027'''''';',
'  execute immediate ''alter session set plscope_settings = ''''identifiers:all'''''';',
'  execute immediate ''alter session set plsql_optimize_level = 3'';',
'',
'  if v_native_compilation then',
'    execute immediate ''alter session set plsql_code_type=''''native'''''';',
'  end if;',
'',
'  select count(*) into v_count from all_objects where object_type = ''SYNONYM'' and object_name = ''APEX_EXPORT'';',
'  v_apex_installed := case when v_count = 0 then ''FALSE'' else ''TRUE'' end;',
'',
'  execute immediate ''alter session set plsql_ccflags = ''''''',
'    || ''APEX_INSTALLED:'' || v_apex_installed || '',''',
'    || ''UTILS_PUBLIC:''   || v_utils_public   || '''''''';',
'',
'end;',
'/',
'',
'declare',
'  v_count pls_integer;',
'begin',
'  select count(*) into v_count from user_tables where table_name = ''CONSOLE_CONF'';',
'  if v_count = 0 then',
'    dbms_output.put_line(''- Table CONSOLE_CONF not found, run creation command'');',
'    execute immediate q''{',
'      create table console_conf (',
'        conf_id           varchar2 (   4 byte)  not null  ,',
'        conf_sysdate      date                  not null  ,',
'        conf_user         varchar2 (  64 byte)            ,',
'        level_id          number   (   1,0)     not null  ,',
'        level_name        varchar2 (  10 byte)  not null  ,',
'        check_interval    number   (   2,0)     not null  ,',
'        enable_ascii_art  varchar2 (   5 byte)  not null  ,',
'        client_prefs      varchar2 (4000 byte)            ,',
'        --',
'        constraint  console_conf_pk   primary key ( conf_id )                                                                          ,',
'        constraint  console_conf_ck1  check ( conf_id = ''CONF'' )                                                                       ,',
'        constraint  console_conf_ck2  check ( level_id in (1, 2, 3, 4, 5) )                                                            ,',
'        constraint  console_conf_ck3  check ( level_name = decode(level_id, 1,''error'', 2,''warning'', 3,''info'', 4,''debug'', 5,''trace'') )  ,',
'        constraint  console_conf_ck4  check ( check_interval between 10 and 60 )                                                       ,',
'        constraint  console_conf_ck5  check ( enable_ascii_art in (''true'',''false'') )',
'      )',
'    }'';',
'  else',
'    dbms_output.put_line(''- Table CONSOLE_CONF found, no action required'');',
'  end if;',
'',
'end;',
'/',
'',
'comment on table  console_conf                  is ''Holds the console configuration in a single record.'';',
'comment on column console_conf.conf_id          is ''The primary key - is secured by a check constraint which allows only one record in the table.'';',
'comment on column console_conf.conf_user        is ''The user who configured the console the last time.'';',
'comment on column console_conf.conf_sysdate     is ''The date when console was configured the last time.'';',
'comment on column console_conf.level_id         is ''The defined log level ID.'';',
'comment on column console_conf.level_name       is ''The defined log level name (only for informational purposes).'';',
'comment on column console_conf.check_interval   is ''The number of seconds a session looks for a changed configuration.'';',
'comment on column console_conf.enable_ascii_art is ''Currently used to have more fun with the APEX error handling messages. But who knows...'';',
'comment on column console_conf.client_prefs     is ''Client preferences in CSV format. We save it in this way to have always only one row of configuration data which we read with the result cache.'';',
'',
'',
'',
'',
'',
'declare',
'  v_count pls_integer;',
'  --',
'  procedure create_index (',
'    p_type        varchar2,',
'    p_column_list varchar2,',
'    p_postfix     varchar2)',
'  is',
'  begin',
'    with t as (',
'      select listagg(column_name, '', '') within group(order by column_position) as index_column_list',
'        from user_ind_columns',
'      where table_name = ''CONSOLE_LOGS''',
'      group by index_name',
'    )',
'    select count(*)',
'      into v_count',
'      from t',
'    where index_column_list = p_column_list;',
'    if v_count = 0 then',
'      dbms_output.put_line(''- Index for CONSOLE_LOGS column list '' || p_column_list || '' not found, run creation command'');',
'      execute immediate ''create '' || p_type || '' index CONSOLE_LOGS_'' || p_postfix || '' on CONSOLE_LOGS ('' || p_column_list || '')'';',
'    else',
'      dbms_output.put_line(''- Index for CONSOLE_LOGS column list '' || p_column_list || '' found, no action required'');',
'    end if;',
'  end;',
'  --',
'begin',
'',
'  --create table',
'  select count(*) into v_count from user_tables where table_name = ''CONSOLE_LOGS'';',
'  if v_count = 0 then',
'    dbms_output.put_line(''- Table CONSOLE_LOGS not found, run creation command'');',
'    execute immediate q''{',
'      create table console_logs (',
'        log_id             number   (   *,0)               generated by default  on null   as identity (cache 1000),',
'        log_time           timestamp with local time zone                        not null  ,',
'        level_id           number   (   1,0)                                     not null  ,',
'        level_name         varchar2 (  10 byte)                                  not null  ,',
'        permanent          varchar2 (   1 byte)                                  not null  ,',
'        scope              varchar2 ( 256 byte)                                            ,',
'        message            clob                                                            ,',
'        error_code         number   (  10,0)                                               ,',
'        call_stack         varchar2 (4000 byte)                                            ,',
'        session_user       varchar2 (  32 byte)                                            ,',
'        module             varchar2 (  48 byte)                                            ,',
'        action             varchar2 (  32 byte)                                            ,',
'        client_info        varchar2 (  64 byte)                                            ,',
'        client_identifier  varchar2 (  64 byte)                                            ,',
'        ip_address         varchar2 (  48 byte)                                            ,',
'        host               varchar2 (  64 byte)                                            ,',
'        os_user            varchar2 (  64 byte)                                            ,',
'        os_user_agent      varchar2 ( 200 byte)                                            ,',
'        --',
'        constraint  console_logs_pk  primary key (log_id)                                  ,',
'        constraint  console_logs_ck  check       (permanent in (''Y'',''N''))',
'      )',
'    }'';',
'  else',
'    dbms_output.put_line(''- Table CONSOLE_LOGS found, no action required'');',
'  end if;',
'',
'  create_index (null, ''LOG_TIME, LEVEL_ID'', ''IX'');',
'',
'end;',
'/',
'',
'comment on table  console_logs                   is ''Table for log entries of the package CONSOLE. Column names are mostly driven by the attribute names of SYS_CONTEXT(''''USERENV'''') and DBMS_SESSION for easier mapping and clearer context.'';',
'comment on column console_logs.log_id            is ''Primary key based on a sequence.'';',
'comment on column console_logs.log_time          is ''Log systimestamp.'';',
'comment on column console_logs.level_id          is ''Level ID. Can be 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace).'';',
'comment on column console_logs.level_name        is ''Level name - for informational purposes only. Indexed columns are only LOG_TIME, LEVEL_ID. If you need more indexes please help yourself.'';',
'comment on column console_logs.permanent         is ''If ''''Y'''' the log entry will not be deleted when calling CONSOLE.PURGE or CONSOLE.PURGE_ALL.'';',
'comment on column console_logs.scope             is ''The current unit/module in which the log was generated (OWNER.PACKAGE.MODULE.SUBMODULE, line number). Couls also be an external scope provided by the user.'';',
'comment on column console_logs.message           is ''The log message itself.'';',
'comment on column console_logs.error_code        is ''The error code. Is normally the SQLCODE, but could also be a user error code when log entry was coming from an external process (user interface, ETL preprocessing, whatever...)'';',
'comment on column console_logs.call_stack        is ''The call_stack and in case of an error also the error stack and error backtrace. Could also be an external call stack provided by the user.'';',
'comment on column console_logs.session_user      is ''The name of the session user (the user who logged on). This may change during the duration of a database session as Real Application Security sessions are attached or detached. For enterprise users'
||', returns the schema. For other users, returns the database user name. If a Real Application Security session is currently attached to the database session, returns user XS$NULL.'';',
'comment on column console_logs.module            is ''The application name (module). Can be set by an application using the DBMS_APPLICATION_INFO package or OCI.'';',
'comment on column console_logs.action            is ''The action/position in the module. Can be set through the DBMS_APPLICATION_INFO package or OCI.'';',
'comment on column console_logs.client_info       is ''The client information. Can be set by an application using the DBMS_APPLICATION_INFO package or OCI.'';',
'comment on column console_logs.client_identifier is ''The client identifier. Can be set by an application using the DBMS_SESSION.SET_IDENTIFIER procedure, the OCI attribute OCI_ATTR_CLIENT_IDENTIFIER, or Oracle Dynamic Monitoring Service (DMS). This a'
||'ttribute is used by various database components to identify lightweight application users who authenticate as the same database user.'';',
'comment on column console_logs.ip_address        is ''IP address of the machine from which the client is connected. If the client and server are on the same machine and the connection uses IPv6 addressing, then it is set to ::1.'';',
'comment on column console_logs.host              is ''Name of the host machine from which the client is connected.'';',
'comment on column console_logs.os_user           is ''Operating system user name of the client process that initiated the database session.'';',
'comment on column console_logs.os_user_agent     is ''Operating system user agent (for example web browser engine). This information will only be available, if actively provided to one of the console log methods. For APEX we have a plug-in to log clie'
||'nt side JavaScript errors, which provides here the user agent of the browser.'';',
'',
'',
'',
'',
'prompt - Package CONSOLE (spec)',
'create or replace package console authid definer is',
'',
'c_name    constant varchar2 ( 30 byte ) := ''Oracle Instrumentation Console''       ;',
'c_version constant varchar2 ( 10 byte ) := ''1.0.1''                                ;',
'c_url     constant varchar2 ( 36 byte ) := ''https://github.com/ogobrecht/console'' ;',
'c_license constant varchar2 (  3 byte ) := ''MIT''                                  ;',
'c_author  constant varchar2 ( 15 byte ) := ''Ottmar Gobrecht''                      ;',
'',
'',
'/**',
'',
'Oracle Instrumentation Console',
'==============================',
'',
'An instrumentation tool for Oracle developers. Save to install on production and',
'mostly API compatible with the [JavaScript',
'console](https://developers.google.com/web/tools/chrome-devtools/console/api).',
'',
'For more infos have a look at the [project page on',
'GitHub](https://github.com/ogobrecht/console).',
'',
'**/',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC SIMPLE TYPES',
'--------------------------------------------------------------------------------',
'',
'subtype t_int  is pls_integer;',
'subtype t_1b   is varchar2 (    1 byte);',
'subtype t_2b   is varchar2 (    2 byte);',
'subtype t_4b   is varchar2 (    4 byte);',
'subtype t_8b   is varchar2 (    8 byte);',
'subtype t_16b  is varchar2 (   16 byte);',
'subtype t_32b  is varchar2 (   32 byte);',
'subtype t_64b  is varchar2 (   64 byte);',
'subtype t_128b is varchar2 (  128 byte);',
'subtype t_256b is varchar2 (  256 byte);',
'subtype t_512b is varchar2 (  512 byte);',
'subtype t_1kb  is varchar2 ( 1024 byte);',
'subtype t_2kb  is varchar2 ( 2048 byte);',
'subtype t_4kb  is varchar2 ( 4096 byte);',
'subtype t_8kb  is varchar2 ( 8192 byte);',
'subtype t_16kb is varchar2 (16384 byte);',
'subtype t_32kb is varchar2 (32767 byte);',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC COMPLEX TYPES',
'--------------------------------------------------------------------------------',
'',
'type t_client_prefs_row is record(',
'  client_identifier t_64b   ,',
'  check_interval    integer ,',
'  exit_sysdate      date    ,',
'  level_id          integer ,',
'  level_name        t_16b   ,',
'  call_stack        t_8b    ,',
'  user_env          t_8b    ,',
'  apex_env          t_8b    ,',
'  cgi_env           t_8b    ,',
'  console_env       t_8b    );',
'type t_attribute_value_row is record(',
'  attribute t_128b ,',
'  value     t_4kb  );',
'type t_client_prefs_tab      is table of t_client_prefs_row;',
'type t_client_prefs_tab_i    is table of t_client_prefs_row index by pls_integer;',
'type t_attribute_value_tab   is table of t_attribute_value_row;',
'type t_attribute_value_tab_i is table of t_attribute_value_row index by pls_integer;',
'type t_vc2_tab               is table of t_32kb;',
'type t_vc2_tab_i             is table of t_32kb index by pls_integer;',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC CONSTANTS',
'--------------------------------------------------------------------------------',
'',
'c_level_error            constant t_int   :=      1 ;',
'c_level_warning          constant t_int   :=      2 ;',
'c_level_info             constant t_int   :=      3 ;',
'c_level_debug            constant t_int   :=      4 ;',
'c_level_trace            constant t_int   :=      5 ;',
'c_check_interval_min     constant t_int   :=      3 ; -- seconds',
'c_check_interval_default constant t_int   :=     10 ; -- seconds',
'c_check_interval_max     constant t_int   :=     60 ; -- seconds',
'c_duration_min           constant t_int   :=      1 ; -- minutes',
'c_duration_default       constant t_int   :=     60 ; -- minutes',
'c_duration_max           constant t_int   :=   1440 ; -- minutes (1 day)',
'c_enable_ascii_art       constant boolean :=   true ;',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC CONSOLE METHODS',
'--------------------------------------------------------------------------------',
'',
'function my_client_identifier return varchar2;',
'/**',
'',
'Returns the current session identifier of the own session. This information is cached in a',
'package variable and determined on package initialization.',
'',
'```sql',
'select console.my_client_identifier from dual;',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function my_log_level return integer;',
'/**',
'',
'Returns the current log level of the own session. This information is cached in a',
'package variable for performance reasons and re-evaluated every 10 seconds.',
'',
'```sql',
'select console.my_log_level from dual;',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure error_save_stack;',
'/**',
'',
'Saves the error stack, so that you are able to handle the error on the most',
'outer point in your code without loosing detail information of the original',
'error nested deeper in your code.',
'',
'With this method we try to prevent log spoiling  - if you use it right you can',
'have ONE log entry for your errors with the saved details where the error',
'occured.',
'',
'EXAMPLE',
'',
'```sql',
'set define off',
'set feedback off',
'set serveroutput on',
'set linesize 120',
'set pagesize 40',
'column call_stack heading "Call Stack" format a120',
'whenever sqlerror exit sql.sqlcode rollback',
'',
'prompt TEST ERROR_SAVE_STACK',
'',
'prompt - compile package spec',
'create or replace package some_api is',
'  procedure do_stuff;',
'end;',
'{{/}}',
'',
'prompt - compile package body',
'create or replace package body some_api is',
'------------------------------------------------------------------------------',
'    procedure do_stuff is',
'    --------------------------------------',
'        procedure sub1 is',
'        --------------------------------------',
'            procedure sub2 is',
'            --------------------------------------',
'                procedure sub3 is',
'                begin',
'                  console.assert(1 = 2, ''Demo'');',
'                exception --sub3',
'                  when others then',
'                    console.error_save_stack;',
'                    raise;',
'                end;',
'            --------------------------------------',
'            begin',
'              sub3;',
'            exception --sub2',
'              when others then',
'                console.error_save_stack;',
'                raise;',
'            end;',
'        --------------------------------------',
'        begin',
'          sub2;',
'        exception --sub1',
'          when others then',
'            console.error_save_stack;',
'            raise no_data_found;',
'        end;',
'    --------------------------------------',
'    begin',
'      sub1;',
'    exception --do_stuff',
'      when others then',
'        console.error;',
'        raise;',
'    end;',
'------------------------------------------------------------------------------',
'end;',
'{{/}}',
'',
'prompt - call the package',
'begin',
'  some_api.do_stuff;',
'exception',
'  when others then',
'    null; --> I know, I know, never do that without a final raise...',
'          --> But we want only test our logging without killing the script run...',
'end;',
'{{/}}',
'',
'prompt - FINISHED, selecting now the call stack from the last log entry...',
'',
'select call_stack from console_logs order by log_id desc fetch first row only;',
'```',
'',
'EXAMPLE OUTPUT',
'',
'```bash',
'TEST ERROR_SAVE_STACK',
'- compile package spec',
'- compile package body',
'- call the package',
'- FINISHED, selecting now the call stack from the last log entry...',
'',
'Call Stack',
'------------------------------------------------------------------------------------------------------------------------',
'{{#}}### Saved Error Stack',
'',
'- PLAYGROUND.SOME_API.DO_STUFF.SUB1.SUB2.SUB3, line 14 (line 11, ORA-20777 Assertion failed: Demo)',
'- PLAYGROUND.SOME_API.DO_STUFF.SUB1.SUB2, line 22 (line 19)',
'- PLAYGROUND.SOME_API.DO_STUFF.SUB1, line 30 (line 27)',
'- PLAYGROUND.SOME_API.DO_STUFF, line 38 (line 35, ORA-01403 no data found)',
'',
'{{#}}### Call Stack',
'',
'- PLAYGROUND.SOME_API.DO_STUFF, line 38',
'- __anonymous_block, line 2',
'',
'{{#}}### Error Stack',
'',
'- ORA-01403 no data found',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 31',
'- ORA-20777 Assertion failed: Test assertion with line break.',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 23',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 15',
'- ORA-06512 at "PLAYGROUND.CONSOLE", line 750',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 11',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 19',
'- ORA-06512 at "PLAYGROUND.SOME_API", line 27',
'',
'{{#}}### Error Backtrace',
'',
'- PLAYGROUND.SOME_API, line 31',
'- PLAYGROUND.SOME_API, line 23',
'- PLAYGROUND.SOME_API, line 15',
'- PLAYGROUND.CONSOLE, line 750',
'- PLAYGROUND.SOME_API, line 11',
'- PLAYGROUND.SOME_API, line 19',
'- PLAYGROUND.SOME_API, line 27',
'- PLAYGROUND.SOME_API, line 35',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure error (',
'  p_message         in clob     default null  , -- The log message itself',
'  p_permanent       in boolean  default false , -- Should the log entry be permanent (not deleted by purge methods)',
'  p_call_stack      in boolean  default true  , -- Include call stack',
'  p_apex_env        in boolean  default false , -- Include APEX environment',
'  p_cgi_env         in boolean  default false , -- Include CGI environment',
'  p_console_env     in boolean  default false , -- Include Console environment',
'  p_user_env        in boolean  default false , -- Include user environment',
'  p_user_agent      in varchar2 default null  , -- User agent of browser or other client technology',
'  p_user_scope      in varchar2 default null  , -- Override PL/SQL scope',
'  p_user_error_code in integer  default null  , -- Override PL/SQL error code',
'  p_user_call_stack in varchar2 default null    -- Override PL/SQL call stack',
');',
'/**',
'',
'Log a message with the level 1 (error).',
'',
'**/',
'',
'function error (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 1 (error). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure warn (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  );',
'/**',
'',
'Log a message with the level 2 (warning).',
'',
'**/',
'',
'function warn (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 2 (warning). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure info (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  );',
'/**',
'',
'Log a message with the level 3 (info).',
'',
'**/',
'',
'function info (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 3 (info). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure log (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  );',
'/**',
'',
'Log a message with the level 3 (info).',
'',
'**/',
'',
'function log (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 3 (info). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure debug (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  );',
'/**',
'',
'Log a message with the level 4 (debug).',
'',
'**/',
'',
'function debug (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 4 (debug). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure trace (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default true  ,',
'  p_cgi_env         in boolean  default true  ,',
'  p_console_env     in boolean  default true  ,',
'  p_user_env        in boolean  default true  ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  );',
'/**',
'',
'Log a message with the level 5 (trace).',
'',
'**/',
'',
'function trace (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default true  ,',
'  p_cgi_env         in boolean  default true  ,',
'  p_console_env     in boolean  default true  ,',
'  p_user_env        in boolean  default true  ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'/**',
'',
'Log a message with the level 5 (trace). Returns the log ID.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count ( p_label in varchar2 default null );',
'/**',
'',
'Creates a new counter with a value of one or adds one to an existing counter.',
'',
'Does not depend on a log level, can be used anywhere to count things.',
'',
'EXAMPLE',
'',
'```sql',
'declare',
'  v_counter varchar2(30) := ''Processing xyz'';',
'begin',
'  for i in 1 .. 10 loop',
'    console.count(v_counter);',
'  end loop;',
'  console.count_current(v_counter); -- without optional message',
'',
'  for i in 1 .. 100 loop',
'    console.count(v_counter);',
'  end loop;',
'  console.count_current(v_counter, ''end of step two'');',
'',
'  for i in 1 .. 1000 loop',
'    console.count(v_counter);',
'  end loop;',
'  console.count_end(v_counter, ''end of step three'');',
'end;',
'{{/}}',
'```',
'',
'This will produce the following log messages in the table CONSOLE_LOGS when your',
'current log level is 3 (info) or higher:',
'',
'- Processing xyz: 10',
'- Processing xyz: 110 - end of step two',
'- Processing xyz: 1110 - end of step three',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_reset ( p_label in varchar2 default null );',
'/**',
'',
'Reset an existin'))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'g counter or create a new one.',
'',
'Does not depend on a log level, can be used anywhere to count things.',
'',
'Also see procedure `count` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_current (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null );',
'/**',
'',
'Log the current value of a counter, if the sessions log level is greater or',
'equal 3 (info).',
'',
'Also see procedure `count` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_end (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null );',
'/**',
'',
'Log the current value of a counter, if the sessions log level is greater or',
'equal 3 (info). Delete the counter.',
'',
'Also see procedure `count` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function count_current (',
'  p_label   in varchar2 default null )',
'return t_int;',
'/**',
'',
'Returns the current counter value or null, if the given label does not exist.',
'',
'Does not depend on a log level, can be used anywhere to count things.',
'',
'Also see procedure `count` above. The following example does not use the',
'optional label, therefore the implicit label used in the background will be',
'`default`. As we get only the value back from the funtion and we need only one',
'counter at the same time this is ok for us here and it keeps the code simple.',
'',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'',
'begin',
'  console.print(''Counting nonsense...'');',
'  for i in 1 .. 1000 loop',
'    if mod(i, 3) = 0 then',
'      console.count;',
'    end if;',
'  end loop;',
'  console.printf(''Current value: %s'', console.count_current );',
'',
'  console.count_reset;',
'  for i in 1 .. 10 loop',
'    console.count;',
'  end loop;',
'  console.printf(''Final value: %s'', console.count_end );',
'end;',
'',
'{{/}}',
'```',
'',
'This will print something like the following to the server output:',
'',
'```',
'Counting nonsense...',
'Current value: 333',
'Final value: 10',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function count_end (',
'  p_label   in varchar2 default null )',
'return t_int;',
'/**',
'',
'Returns the current counter value or null, if the given label does not exist.',
'Deletes the counter.',
'',
'Does not depend on a log level, can be used anywhere to count things.',
'',
'Also see function `count_current` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time ( p_label in varchar2 default null );',
'/**',
'',
'Create and a new timer. If the timer is already existing it will start again',
'with the current local timestamp.',
'',
'Does not depend on a log level, can be used anywhere to measure runtime.',
'',
'EXAMPLE',
'',
'```sql',
'declare',
'  v_timer varchar2(30) := ''Processing xyz'';',
'begin',
'',
'  --basic usage',
'  console.time;',
'  sys.dbms_session.sleep(0.1);',
'  console.time_end; -- without optional label and message',
'',
'  console.time(v_timer);',
'',
'  sys.dbms_session.sleep(0.1);',
'  console.time_current(v_timer); -- without optional message',
'',
'  sys.dbms_session.sleep(0.1);',
'  console.time_current(v_timer, ''end of step two'');',
'',
'  sys.dbms_session.sleep(0.1);',
'  console.time_end(v_timer, ''end of step three'');',
'',
'end;',
'{{/}}',
'```',
'',
'This will produce the following log messages in the table CONSOLE_LOGS when your',
'current log level is 3 (info) or higher:',
'',
'- default: 00:00:00.102508',
'- Processing xyz: 00:00:00.108048',
'- Processing xyz: 00:00:00.212045 - end of step two',
'- Processing xyz: 00:00:00.316084 - end of step three',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_reset ( p_label in varchar2 default null );',
'/**',
'',
'Reset an existing timer or create a new one.',
'',
'Does not depend on a log level, can be used anywhere to measure runtime.',
'',
'Also see procedure `time` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_current (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null );',
'/**',
'',
'Log the elapsed time, if the sessions log level is greater or equal 3 (info).',
'',
'Can be called multiple times - use `console.time_end` to log the elapsed time',
'and delete the timer.',
'',
'Also see procedure `time` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_end (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null );',
'/**',
'',
'Log the elapsed time and delete the timer, if the sessions log level is greater',
'or equal 3 (info).',
'',
'Also see procedure `time` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function time_current ( p_label in varchar2 default null ) return varchar2;',
'/**',
'',
'Returns the elapsed time as varchar in the format 00:00:00.000000 or null, if',
'the given label does not exist.',
'',
'Does not depend on a log level, can be used anywhere to measure runtime.',
'',
'Can be called multiple times - use `console.time_end` to return the elapsed time',
'and delete the timer.',
'',
'Also see procedure `time` above. The following example does not use the optional',
'label, therefore the implicit label used in the background will be `default`. As',
'we get only the runtime back from the funtion in the format 00:00:00.000000 and',
'we need only one timer at the same time this is ok for us here and it keeps the',
'code simple.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'',
'begin',
'  console.time;',
'',
'  console.print(''Processing step one...'');',
'  sys.dbms_session.sleep(0.1);',
'  console.printf(''Elapsed time: %s'', console.time_current);',
'',
'  console.print(''Processing step two...'');',
'  sys.dbms_session.sleep(0.1);',
'  console.printf(''Elapsed time: %s'', console.time_current);',
'',
'  console.print(''Processing step three...'');',
'  sys.dbms_session.sleep(0.1);',
'  console.printf(''Elapsed time: %s'', console.time_end);',
'end;',
'{{/}}',
'```',
'',
'This will result in something like the following output:',
'',
'```',
'Processing step one...',
'Elapsed time: 00:00:00.105398',
'Processing step two...',
'Elapsed time: 00:00:00.209267',
'Processing step three...',
'Elapsed time: 00:00:00.313301',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function time_end ( p_label in varchar2 default null ) return varchar2;',
'/**',
'',
'Returns the elapsed time as varchar in the format 00:00:00.000000 or null, if',
'the given label does not exist. Deletes the timer.',
'',
'Does not depend on a log level, can be used anywhere to measure runtime.',
'',
'Also see function `time_current` above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure table# (',
'  p_data_cursor       in sys_refcursor         ,',
'  p_comment           in varchar2 default null ,',
'  p_include_row_num   in boolean  default true ,',
'  p_max_rows          in integer  default 100  ,',
'  p_max_column_length in integer  default 1000 );',
'/**',
'',
'Logs a cursor as a HTML table with the level 3 (info).',
'',
'Using a cursor for the table method is very flexible, but opening a cursor can',
'produce unnecessary work for your system when you are not in the log level info.',
'Therefore please check your current log level before you open the cursor.',
'',
'EXAMPLE',
'',
'```sql',
'declare',
'  v_dataset sys_refcursor;',
'begin',
'  -- Your business logic here...',
'',
'  -- Debug code',
'  if console.level_is_info then',
'    open v_dataset for',
'      select table_name,',
'             tablespace_name,',
'             logging,',
'             num_rows,',
'             last_analyzed,',
'             partitioned,',
'             has_identity',
'        from user_tables;',
'    console.table#(v_dataset);',
'  end if;',
'',
'  -- Your business logic here...',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure assert (',
'  p_expression in boolean,',
'  p_message    in varchar2',
');',
'/**',
'',
'If the given expression evaluates to false, an error is raised with the given',
'message.',
'',
'EXAMPLE',
'',
'```sql',
'declare',
'  x number := 5;',
'  y number := 3;',
'begin',
'  console.assert(',
'    x < y,',
'    ''x should be less then y (x='' || to_char(x) || '', y='' || to_char(y) || '')''',
'  );',
'exception',
'  when others then',
'    console.error;',
'    raise;',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure assertf (',
'  p_expression in boolean               ,',
'  p_message    in varchar2              ,',
'  p0           in varchar2 default null ,',
'  p1           in varchar2 default null ,',
'  p2           in varchar2 default null ,',
'  p3           in varchar2 default null ,',
'  p4           in varchar2 default null ,',
'  p5           in varchar2 default null ,',
'  p6           in varchar2 default null ,',
'  p7           in varchar2 default null ,',
'  p8           in varchar2 default null ,',
'  p9           in varchar2 default null',
');',
'/**',
'',
'If the given expression evaluates to false, an error is raised with the given',
'formatted message.',
'',
'EXAMPLE',
'',
'```sql',
'declare',
'  x number := 5;',
'  y number := 3;',
'begin',
'  console.assertf(',
'    x < y,',
'    ''x should be less then y (x=%s, y=%s)'',',
'    to_char(x),',
'    to_char(y)',
'  );',
'exception',
'  when others then',
'    console.error;',
'    raise;',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param ( p_name in varchar2, p_value in varchar2                       );',
'/**',
'',
'Add a parameter to the package internal parameter collection which will be',
'included in the next log call (error, warn, info, log, debug or trace)',
'',
'The procedure is overloaded to support different parameter types.',
'',
'VARCHAR and CLOB parameters are shortened to 2000 characters and additionally',
'escaped for Markdown table columns (replacing all line endings with whitespace',
'and the pipe character with `&#124;`). If you need your full parameter text then',
'please use the `p_message` CLOB parameter in the log methods error, warn, info,',
'log, debug and trace to do your own parameter handling.',
'',
'```sql',
'procedure add_param ( p_name in varchar2, p_value in varchar2                       );',
'procedure add_param ( p_name in varchar2, p_value in number                         );',
'procedure add_param ( p_name in varchar2, p_value in date                           );',
'procedure add_param ( p_name in varchar2, p_value in timestamp                      );',
'procedure add_param ( p_name in varchar2, p_value in timestamp with time zone       );',
'procedure add_param ( p_name in varchar2, p_value in timestamp with local time zone );',
'procedure add_param ( p_name in varchar2, p_value in interval year to month         );',
'procedure add_param ( p_name in varchar2, p_value in interval day to second         );',
'procedure add_param ( p_name in varchar2, p_value in boolean                        );',
'procedure add_param ( p_name in varchar2, p_value in clob                           );',
'procedure add_param ( p_name in varchar2, p_value in xmltype                        );',
'```',
'',
'EXAMPLE',
'',
'```sql',
'--create demo procedure',
'create or replace procedure demo_proc (',
'  p_01 varchar2                       ,',
'  p_02 number                         ,',
'  p_03 date                           ,',
'  p_04 timestamp                      ,',
'  p_05 timestamp with time zone       ,',
'  p_06 timestamp with local time zone ,',
'  p_07 interval year to month         ,',
'  p_08 interval day to second         ,',
'  p_09 boolean                        ,',
'  p_10 clob                           ,',
'  p_11 xmltype                        )',
'is',
'begin',
'  raise_application_error(-20999, ''Test Error.'');',
'exception',
'  when others then',
'    console.add_param(''p_01'', p_01);',
'    console.add_param(''p_02'', p_02);',
'    console.add_param(''p_03'', p_03);',
'    console.add_param(''p_04'', p_04);',
'    console.add_param(''p_05'', p_05);',
'    console.add_param(''p_06'', p_06);',
'    console.add_param(''p_07'', p_07);',
'    console.add_param(''p_08'', p_08);',
'    console.add_param(''p_09'', p_09);',
'    console.add_param(''p_10'', p_10);',
'    console.add_param(''p_11'', p_11);',
'    console.error(''Ooops, something went wrong'');',
'    raise;',
'end demo_proc;',
'{{/}}',
'',
'--run demo procedure',
'begin',
'  demo_proc (',
'    p_01 => ''test vc2''                             ,',
'    p_02 => 1.23                                   ,',
'    p_03 => sysdate                                ,',
'    p_04 => systimestamp                           ,',
'    p_05 => systimestamp                           ,',
'    p_06 => localtimestamp                         ,',
'    p_07 => interval ''4-2'' year to month           ,',
'    p_08 => interval ''7 6:12:42.123'' day to second ,',
'    p_09 => true                                   ,',
'    p_10 => to_clob(''test clob'')                   ,',
'    p_11 => xmltype(''<test_xml/>'')                 );',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'procedure add_param ( p_name in varchar2, p_value in number                         );',
'procedure add_param ( p_name in varchar2, p_value in date                           );',
'procedure add_param ( p_name in varchar2, p_value in timestamp                      );',
'procedure add_param ( p_name in varchar2, p_value in timestamp with time zone       );',
'procedure add_param ( p_name in varchar2, p_value in timestamp with local time zone );',
'procedure add_param ( p_name in varchar2, p_value in interval year to month         );',
'procedure add_param ( p_name in varchar2, p_value in interval day to second         );',
'procedure add_param ( p_name in varchar2, p_value in boolean                        );',
'procedure add_param ( p_name in varchar2, p_value in clob                           );',
'procedure add_param ( p_name in varchar2, p_value in xmltype                        );',
'',
'--------------------------------------------------------------------------------',
'',
'function format (',
'  p_message in varchar2              ,',
'  p0        in varchar2 default null ,',
'  p1        in varchar2 default null ,',
'  p2        in varchar2 default null ,',
'  p3        in varchar2 default null ,',
'  p4        in varchar2 default null ,',
'  p5        in varchar2 default null ,',
'  p6        in varchar2 default null ,',
'  p7        in varchar2 default null ,',
'  p8        in varchar2 default null ,',
'  p9        in varchar2 default null )',
'return varchar2;',
'/**',
'',
'Formats a message with the following rules:',
'',
'1. Replace all occurrences of `%0` .. `%9` by id with the corresponding',
'   parameters `p0` .. `p9`',
'2. Replace `%n` with new lines (line feed character)',
'3. Replace all occurrences of `%s` in positional order with the corresponding',
'   parameters using sys.utl_lms.format_message - also see the [Oracle',
'   docs](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/UTL_LMS.html#GUID-88FFBFB6-FCA4-4951-884B-B0275BD5DF44).',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure action ( p_action in varchar2 );',
'/**',
'',
'An alias for dbms_application_info.set_action.',
'',
'Use the given action to set the session action attribute (in memory operation,',
'does not log anything). This attribute is then visible in the system session',
'views, the user environment and will be logged within all console logging',
'methods.',
'',
'When you set the action attribute with `console.action` you should also reset it',
'when you have finished your work to prevent wrong info in the system and your',
'logging for subsequent method calls.',
'',
'EXAMPLE',
'',
'```sql',
'begin',
'  console.action(''My process/task'');',
'  -- do your stuff here...',
'  console.action(null);',
'exception',
'  when others then',
'    console.error(''something went wrong'');',
'    console.action(null);',
'    raise;',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure module (',
'  p_module in varchar2,',
'  p_action in varchar2 default null',
');',
'/**',
'',
'An alias for dbms_application_info.set_module.',
'',
'Use the given module and action to set the session module and action attributes',
'(in memory operation, does not log anything). These attributes are then visible',
'in the system session views, the user environment and will be logged within all',
'console logging methods.',
'',
'Please note that your app framework may set the module and you should consider',
'to only set the action attribute with the `action` (see below).',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function level_error     return integer; /** Returns the number code for the level 1 error.     **/',
'function level_warning   return integer; /** Returns the number code for the level 2 warning.   **/',
'function level_info      return integer; /** Returns the number code for the level 3 info.      **/',
'function level_debug     return integer; /** Returns the number code for the level 4 debug.     **/',
'function level_trace     return integer; /** Returns the number code for the level 5 trace.     **/',
'',
'function level_is_warning return boolean; /** Returns true when the level is greater than or equal warning, otherwise false. **/',
'function level_is_info    return boolean; /** Returns true when the level is greater than or equal info, otherwise false.    **/',
'function level_is_debug   return boolean; /** Returns true when the level is greater than or equal debug, otherwise false.   **/',
'function level_is_trace   return boolean; /** Returns true when the level is greater than or equal trace, otherwise false.   **/',
'',
'function level_is_warning_yn return varchar2; /** Returns ''Y'' when the level is greater than or equal warning, otherwise ''N''. **/',
'function level_is_info_yn    return varchar2; /** Returns ''Y'' when the level is greater than or equal info, otherwise ''N''.    **/',
'function level_is_debug_yn   return varchar2; /** Returns ''Y'' when the level is greater than or equal debug, otherwise ''N''.   **/',
'function level_is_trace_yn   return varchar2; /** Returns ''Y'' when the level is greater than or equal trace, otherwise ''N''.   **/',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC HELPER METHODS',
'--------------------------------------------------------------------------------',
'',
'$if $$apex_installed $then',
'',
'function apex_error_handling ( p_error in apex_error.t_error )',
'return apex_error.t_error_result;',
'/**',
'',
'You can register this example APEX error handler function to log APEX internal',
'errors.',
'',
'To do so go into the Application Builder into your app > Edit Application',
'Properties > Error Handling > Error Handling Function. You can then provide here',
'`console.apex_error_handling`.',
'',
'For more info see the [official',
'docs](https://docs.oracle.com/en/database/oracle/application-express/20.2/aeapi/Example-of-an-Error-Handling-Function.html#GUID-2CD75881-1A59-4787-B04B-9AAEC14E1A82).',
'',
'The implementation code (see package body) is taken from the docs and aligned',
'for CONSOLE as a starting point. If this does not fit your needs then simply',
'reimplement an own function and use that instead.',
'',
'**/',
'',
'function apex_plugin_render (',
'  p_dynamic_action in apex_plugin.t_dynamic_action ,',
'  p_plugin         in apex_plugin.t_plugin         )',
'return apex_plugin.t_dynamic_action_render_result;',
'/**',
'',
'Used for the APEX plugin to capture frontend JavaScript errors.',
'',
'If you plan to use the plugin make sure you have either console installed in',
'your APEX parsing schema or a synonym named `console` for it as this function is',
'referenced in the plug-in as a callback to `console.apex_plugin_render`.',
'',
'**/',
'function apex_plugin_ajax (',
'  p_dynamic_action in apex_plugin.t_dynamic_action ,',
'  p_plugin         in apex_plugin.t_plugin         )',
'return apex_plugin.t_dynamic_action_ajax_result;',
'/**',
'',
'Used for the APEX plugin to capture frontend JavaScript errors.',
'',
'If you plan to use the plugin make sure you have either console installed in',
'your APEX parsing schema or a synonym named `console` for it as this function is',
'referenced in the plug-in as a callback to `console.apex_plugin_ajax`.',
'',
'**/',
'',
'$end',
'',
'--------------------------------------------------------------------------------',
'',
'procedure conf (',
'  p_level            in integer default null , -- Level 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace).',
'  p_check_interval   in integer default null , -- The number of seconds a session looks for a changed configuration. Allowed values: 1 to 60 seconds.',
'  p_enable_ascii_art in boolean default null   -- Currently used to have more fun with the APEX error handling messages. But who knows...',
');',
'/**',
'',
'Set the global console configuration.',
'',
'DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR',
'MANAGING GLOBAL PREFERENCES.',
'',
'EXAMPLE',
'',
'```sql',
'--set all sessions to level warning',
'exec console.conf(p_level => 2);',
'--or',
'exec console.conf(p_level => console.c_level_warning);',
'',
'--set multiple options at once',
'begin',
'  console.conf(',
'    p_level             => console.c_level_info,',
'    p_check_interval    => 10',
'  );',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure init (',
'  p_client_identifier in varchar2                                  , -- The client identifier provided by the application or console itself.',
'  p_level             in integer  default c_level_info             , -- Level 2 (warning), 3 (info), 4 (debug) or 5 (trace).',
'  p_duration          in integer  default c_duration_default       , -- The number of minutes the session should be in client preferences mode. Allowed values: 1 to 1440 minutes (24 hours).',
'  p_check_interval    in integer  default c_check_interval_default , -- The number of seconds a session looks for a changed configuration. Allowed values: 1 to 60 seconds.',
'  p_call_stack        in boolean  default false                    , -- Should the call stack be included.',
'  p_user_env          in boolean  default false                    , -- Should the user environment be included.',
'  p_apex_env          in boolean  default false                    , -- Should the APEX environment be included.',
'  p_cgi_env           in boolean  default false                    , -- Should the CGI environment be included.',
'  p_console_env       in boolean  default false                      -- Should the console environment be included.',
');',
'/**',
'',
'Init/set the preferences for a specific session/client_identifier and duration.',
'',
'To avoid spoiling the context with very long input the parameter',
'p_client_identifier is truncated after 64 characters before using it.',
'',
'For easier usage there is an overloaded procedure available which uses always',
'your own session/client_identifier.',
'',
'DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR',
'MANAGING CLIENT PREFERENCES.',
'',
'EXAMPLES',
'',
'```sql',
'-- Dive into your own session with the default log level of 3 (info) and the',
'-- default duration of 60 (minutes).',
'exec console.init;',
'',
'-- With level 4 (debug) for the next 15 minutes.',
'exec console.init(4, 15);',
'',
'-- Using a constant for the level',
'exec console.init(console.c_level_debug, 90);',
'',
'-- Debug an APEX session...',
'exec console.init(''OGOBRECHT:8805903776765'', 4, 90);',
'',
'-- ...with named parameters',
'begin',
'  console.init(',
'    p_client_identifier => ''OGOBRECHT:8805903776765'',',
'    p_level             => console.c_level_debug,',
'    p_duration          => 15',
'  );',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'procedure init (',
'  p_level          in integer default c_level_info             , -- Level 2 (warning), 3 (info), 4 (debug) or 5 (trace).',
'  p_duration       in integer default c_duration_default       , -- The number of minutes the session should be in client preferences mode. Allowed values: 1 to 1440 minutes (24 hours).',
'  p_check_interval in integer default c_check_interval_default , -- The number of seconds a session in logging mode looks for a changed configuration. Allowed values: 1 to 60 seconds.',
'  p_call_stack     in boolean default false                    , -- Should the call stack be included.',
'  p_user_env       in boolean default false                    , -- Should the user environment be included.',
'  p_apex_env       in boolean default false                    , -- Should the APEX environment be included.',
'  p_cgi_env        in boolean default false                    , -- Should the CGI environment be included.',
'  p_console_env    in boolean default false                      -- Should the console environment be included.',
');',
'/**',
'',
'An overloaded procedure for easier initialization of the own',
'session/client_identifier in an development IDE.',
'',
'**/',
'',
'procedure exit (',
'  p_client_identifier in varchar2 default my_client_identifier -- The client identifier provided by the application or console itself.',
');',
'/**',
'',
'Exit/unset the preferences for a specific session/client_identifier.',
'',
'If you exit/unset your own client preferencs then this has an immediate effect',
'as we can unset the preferences in our package state. If you exit another',
'session/client_identifier then it can take some seconds until the other',
'session/client_identifier is reloading the configuration from the context (if',
'available) or the client_prefs table. The default check interval for a changed',
'configuration is ten seconds.',
'',
'Exit/unset the preferences means also the cached log entries will be flushed to',
'the logging table CONSOLE_LOGS. If you do not need the cached entries you can',
'delete them in advance by calling the `clear` procedure.',
'',
'DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR',
'MANAGING CLIENT PREFERENCES.',
'',
'**/',
'',
'procedure exit_all;',
'/**',
'',
'Exit/unset all client preferences in one go.',
'',
'EXAMPLE',
'',
'```sql',
'exec console.exit_all;',
'```',
'',
'**/',
'',
'',
'--------------------------------------------------------------------------------',
'',
'function version return varchar2;',
'/**',
'',
'Returns the version information from the console package.',
'',
'',
'```sql',
'select console.version from dual;',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function split_to_table (',
'  p_string in varchar2             , -- The string to split into a table.',
'  p_sep    in varchar2 default '',''   -- The separator.',
') return t_vc2_tab pipelined;',
'/**',
'',
'Splits a string into a (pipelined) SQL table of varchar2.',
'',
'If the separator is null the string will be splitted into its characters.',
'',
'EXAMPLE',
'',
'```sql',
'select * from console.split_to_table(''1,2,3'');',
'```',
'',
'| COLUMN_VALUE |',
'|--------------|',
'| 1            |',
'| 2            |',
'| 3            |',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function split (',
'  p_string in varchar2             , -- The string to split into an array.',
'  p_sep    in varchar2 default '',''   -- The separator.',
') return t_vc2_tab_i;',
'/**',
'',
'Splits a string into a PL/SQL associative array.',
'',
'If the separator is null the string will be splitted into its characters.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'declare',
'  v_array console.t_vc2_tab_i;',
'begin',
'  v_array := console.split(''A,B,C'');',
'  for i in 1 .. v_array.count loop',
'    console.print(i||'': ''||v_array(i));',
'  end loop;',
'end;',
'{{/}}',
'',
'1: A',
'2: B',
'3: C',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function join (',
'  p_table in t_vc2_tab_i          , -- The PL/SQL array to join into a string.',
'  p_sep   in varchar2 default '',''   -- The separator.',
') return varchar2;',
'/**',
'',
'Joins a PL/SQL associative array into a string.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_yn ( p_bool in boolean ) return varchar2;',
'/**',
'',
'Converts a boolean value to a string.',
'',
'Returns `Y` when the input is true, `N` when the input is false and null when',
'the input is null.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_string ( p_bool in boolean ) return varchar2;',
'/**',
'',
'Converts a boolean value to a string.',
'',
'Returns `true` when the input is true, `false` when the input is false and null',
'when the input is null.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_bool ( p_string in varchar2 ) return boolean;',
'/**',
'',
'Converts a string to a boolean value.',
'',
'Returns true when the uppercased, trimmed input is `TRUE`, `Y`, `YES` or `1`.',
'When the input is `FALSE`, `N`, `NO` or `0` false is returned. In all other',
'cases null is returned.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_html_table (',
'  p_data_cursor       in sys_refcursor         ,',
'  p_comment           in varchar2 default null ,',
'  p_include_row_num   in boolean  default true ,',
'  p_max_rows          in integer  default 100  ,',
'  p_max_column_length in integer  default 1000 )',
'return clob;',
'/**',
'',
'Helper to convert a cursor to a HTML table.',
'',
'Note: As this helper is designed to work always it does not check your log',
'level. And if it would check, it would not help for the opening of the cursor,',
'which is done before. To save work for your database in cases you are not in',
'logging mode you should check the log level before open the cursor. Please see the',
'examples below.',
'',
'EXAMPLES 1 - Open cursor in advance',
'',
'```sql',
'declare',
'  v_dataset sys_refcursor;',
'begin',
'  -- Your business logic here.',
'',
'  -- Debug code',
'  if console.level_is_info then',
'    open v_dataset for select * from user_tables;',
'    console.info(console.to_html_table(v_dataset));',
'  end if;',
'end;',
'{{/}}',
'```',
'',
'EXAMPLES 2 - Open cursor in for loop',
'',
'```sql',
'begin',
'  -- Your business logic here.',
'',
'  -- Debug code',
'  if console.my_log_level >= console.c_level_info then',
'    for i in (',
'      select console.to_html_table(cursor(select * from user_tables)) as html',
'        from dual )',
'    loop',
'      console.info(i.html);',
'    e'))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'nd loop;',
'  end if;',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_md_code_block (',
'  p_text in varchar2 )',
'return varchar2;',
'/**',
'',
'Converts the given text to a Markdown code block by indent each line with four',
'spaces.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function to_md_tab_header (',
'  p_key   in varchar2 default ''Attribute'' ,',
'  p_value in varchar2 default ''Value''     )',
'return varchar2;',
'/**',
'',
'Converts the given key and value strings to a Markdown table header.',
'',
'`to_md_tab_header` will return the following Markdown table header:',
'',
'```md',
'| Attribute                      | Value                                       |',
'| ------------------------------ | ------------------------------------------- |',
'```',
'',
'**/',
'',
'function to_md_tab_data (',
'  p_key              in varchar2               ,',
'  p_value            in varchar2               ,',
'  p_value_max_length in integer  default 1000  ,',
'  p_show_null_values in boolean  default false )',
'return varchar2;',
'/**',
'',
'Converts the given key and value strings to a Markdown table data row.',
'',
'EXAMPLE',
'',
'`to_md_tab_header(''CLIENT_IDENTIFIER'', ''{o,o} 4C8E71DF0001'')` will return the',
'following Markdown table row:',
'',
'```md',
'| CLIENT_IDENTIFIER              | {o,o} 4C8E71DF0001                          |',
'',
'```',
'',
'**/',
'',
'function to_unibar (',
'  p_value                   in number            ,',
'  p_scale                   in number default 1  ,',
'  p_width_block_characters  in number default 25 ,',
'  p_fill_scale              in number default 0',
') return varchar2 deterministic;',
'/**',
'',
'Returns a text bar consisting of unicode block characters.',
'',
'You can build simple text based bar charts with it. Not all fonts implement',
'clean block characters, so the result depends a little bit on the font. The',
'unicode block characters can have eight different widths from 1/8 up to 8/8 -',
'together with the default width of a bar chart of 25 characters you can show bar',
'charts with a precision of 0.5 percent - that is not bad for a text based bar',
'chart...',
'',
'EXAMPLE',
'',
'```sql',
'column textbar format a30',
'',
'select ''Some text''       as description, 0.84 as value, console.to_unibar(0.84) as textbar from dual union all',
'select ''Some other text'' as description, 0.75 as value, console.to_unibar(0.75) as textbar from dual union all',
'select ''Bla bla bla''     as description, 0.54 as value, console.to_unibar(0.54) as textbar from dual;',
'```',
'',
'RESULT',
'',
'```',
'DESCRIPTION          VALUE TEXTBAR',
'--------------- ---------- ------------------------------',
unistr('Some text              .84 \2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588'),
unistr('Some other text        .75 \2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\258A'),
unistr('Bla bla bla            .54 \2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\2588\258C'),
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure print ( p_message in varchar2 );',
'/**',
'',
'An alias for dbms_output.put_line.',
'',
'Writing dbms_output.put_line is very annoying for me...',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure printf (',
'  p_message in varchar2              ,',
'  p0        in varchar2 default null ,',
'  p1        in varchar2 default null ,',
'  p2        in varchar2 default null ,',
'  p3        in varchar2 default null ,',
'  p4        in varchar2 default null ,',
'  p5        in varchar2 default null ,',
'  p6        in varchar2 default null ,',
'  p7        in varchar2 default null ,',
'  p8        in varchar2 default null ,',
'  p9        in varchar2 default null );',
'/**',
'',
'A shorthand for',
'',
'```',
'begin',
'  console.print(console.format(''A string with %s %s.'', ''dynamic'', ''content''));',
'  --is equivalent to',
'  console.printf(''A string with %s %s.'', ''dynamic'', ''content'');',
'end;',
'{{/}}',
'```',
'',
'Also see [console.format](#function-format)',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function  runtime ( p_start in timestamp ) return varchar2;',
'/**',
'',
'Returns a string in the format hh24:mi:ss.ff6 (for example 00:00:01.123456).',
'',
'Is internally used by the `time_end` method and uses `localtimestamp` to compare',
'with `p_start`.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'declare',
'  v_start timestamp := localtimestamp;',
'begin',
'',
'  --do your stuff here',
'',
'  dbms_output.put_line(''Runtime: '' || console.runtime(v_start));',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime_seconds ( p_start in timestamp ) return number;',
'/**',
'',
'Subtracts the start `localtimestamp` from the current `localtimestamp` and',
'returns the exracted seconds.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'declare',
'  v_start timestamp := localtimestamp;',
'begin',
'',
'  --do your stuff here',
'',
'  dbms_output.put_line (',
'    ''Runtime (seconds): '' || to_char(console.runtime_seconds(v_start)) );',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime_milliseconds ( p_start in timestamp ) return number;',
'/**',
'',
'Subtracts the start `localtimestamp` from the current `localtimestamp` and',
'returns the exracted milliseconds.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on',
'declare',
'  v_start timestamp := localtimestamp;',
'begin',
'',
'  --do your stuff here',
'',
'  dbms_output.put_line (',
'    ''Runtime (milliseconds): '' || to_char(console.runtime_milliseconds(v_start)) );',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function level_name (p_level in integer) return varchar2 deterministic;',
'/**',
'',
'Returns the level name for a given level id and null, if the level is not',
'between 0 and 4.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function scope return varchar2;',
'/**',
'',
'Get the current scope (method, line number) from the call stack.',
'',
'Is used internally by console to automatically provide the scope attribute for a',
'log entry.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function call_stack return varchar2;',
'/**',
'',
'Get the current call stack (and error stack/backtrace, if available).',
'',
'Is used internally by console to provide the call stack for a log entry when',
'requested by one of the logging methods (which is the default for error and',
'trace).',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function apex_env return clob;',
'/**',
'',
'Get the current APEX environment.',
'',
'Is used internally by console to provide the APEX environment for a log entry',
'when requested by one of the logging methods.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function cgi_env return varchar2;',
'/**',
'',
'Get the current CGI environment.',
'',
'Is used internally by console to provide the CGI environment for a log entry',
'when requested by one of the logging methods.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function user_env return varchar2;',
'/**',
'',
'Get the current user environment.',
'',
'Is used internally by console to provide the user environment for a log entry',
'when requested by one of the logging methods.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function console_env return varchar2;',
'/**',
'',
'Get the current console environment.',
'',
'Is used internally by console to provide the console environment for a log entry',
'when requested by one of the logging methods.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'procedure clob_append (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 ,',
'  p_text  in            varchar2 );',
'/**',
'',
'High performance clob concatenation. Also see clob_flush_cache below.',
'',
'Is used internally by console for the table method (and other things). Do not',
'forget a final flush cache call when you use it in your own code.',
'',
'EXAMPLE',
'',
'```sql',
'set serveroutput on feedback off',
'declare',
'  v_start  timestamp := localtimestamp;',
'  v_clob   clob;',
'  v_cache  varchar2(32767 char);',
'begin',
'  for i in 1..100000 loop',
'    console.clob_append(v_clob, v_cache, ''a'');',
'  end loop;',
'  console.clob_flush_cache(v_clob, v_cache);',
'  dbms_output.put_line(''Runtime (seconds): '' || to_char(console.runtime_seconds(v_start)));',
'  dbms_output.put_line(''Lenght CLOB      : '' || length(v_clob));',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'procedure clob_append (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 ,',
'  p_text  in            clob     );',
'/**',
'',
'High performance clob concatenation.',
'',
'Overloaded method for appending a clob. Also see clob_append above with p_text',
'beeing a varchar2 parameter and clob_flush_cache below.',
'',
'**/',
'',
'procedure clob_flush_cache (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 );',
'/**',
'',
'Flushes finally the cache in a high performance clob concatenation.',
'',
'Also see clob_append above.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function status return t_attribute_value_tab pipelined;',
'/**',
'',
'View the current package status (config, number entries cache/timer/counter,',
'version etc.).',
'',
'EXAMPLE',
'',
'```sql',
'select * from console.status();',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function conf return t_attribute_value_tab pipelined;',
'/**',
'',
'View the global console configuration.',
'',
'EXAMPLE',
'',
'```sql',
'select * from console.conf();',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function client_prefs return t_client_prefs_tab pipelined;',
'/**',
'',
'View the client preferences.',
'',
'EXAMPLE',
'',
'```sql',
'select * from console.client_prefs();',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'procedure purge (',
'  p_min_level in integer default c_level_info, -- Delete log entries greater or equal the given level.',
'  p_min_days  in number  default 30 );         -- Delete log entries older than the given minimum days.',
'/**',
'',
'Deletes log entries for the given condition.',
'',
'Deletion is only allowed for the owner of the package console.',
'',
'EXAMPLES',
'',
'```sql',
'--> default: all level info, debug and trace older than 30 days',
'exec console.purge;',
'',
'--> all three examples are equivalent',
'exec console.purge(3, 0.25);',
'exec console.purge(console.c_level_info, 0.25);',
'exec console.purge(p_min_level => console.c_level_info, p_min_days => 0.25);',
'```',
'',
'**/',
'',
'procedure purge_all;',
'/**',
'',
'Deletes all log entries except level permanent.',
'',
'Deletion is only allowed for the owner of the package console.',
'',
'EXAMPLE',
'',
'```sql',
'exec console.purge_all;',
'```',
'',
'**/',
'',
'procedure purge_job_create (',
'  p_repeat_interval in varchar2 default ''FREQ=DAILY;BYHOUR=1;'' , -- See the Oracle docs: https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/scheduling-jobs-with-oracle-scheduler.html#GUID-10B1E444-8330-4EC9-85F8-9428D749F7D5',
'  p_min_level       in integer  default c_level_info           , -- Delete log entries greater or equal the given level.',
'  p_min_days        in number   default 30                       -- Delete log entries older than the given minimum days.',
');',
'/**',
'Creates a cleanup job which deletes old log entries from console_logs and stale',
'debug sessions from console_client_prefs.',
'**/',
'procedure purge_job_drop;    /** Drops the cleanup job (if it exists).    **/',
'procedure purge_job_enable;  /** Enables the cleanup job (if it exists).  **/',
'procedure purge_job_disable; /** Disables the cleanup job (if it exists). **/',
'procedure purge_job_run;     /** Runs the cleanup job (if it exists).     **/',
'',
'--------------------------------------------------------------------------------',
'-- PRIVATE HELPER METHODS (only visible when ccflag `utils_public` is set to true)',
'--------------------------------------------------------------------------------',
'',
'$if $$utils_public $then',
'',
'procedure utl_set_client_identifier;',
'',
'procedure utl_set_session_conf;',
'',
'procedure utl_set_conf (',
'  p_conf console_conf%rowtype );',
'',
'procedure utl_set_client_prefs (',
'  p_prefs varchar2 );',
'',
'function utl_get_conf return console_conf%rowtype result_cache;',
'',
'function utl_get_client_prefs (',
'  p_all_prefs_csv varchar2     ,',
'  p_client_identifier varchar2 )',
'return t_client_prefs_row;',
'',
'function utl_get_client_prefs_tab return t_client_prefs_tab_i;',
'',
'function utl_escape_md_tab_text (',
'  p_text varchar2 )',
'return varchar2;',
'',
'function utl_last_error return varchar2;',
'',
'function utl_logging_is_enabled (',
'  p_level integer )',
'return boolean;',
'',
'function utl_normalize_label (',
'  p_label varchar2 )',
'return varchar2;',
'',
'function utl_replace_linebreaks (',
'  p_text varchar2                     ,',
'  p_replace_with varchar2 default '' '' )',
'return varchar2;',
'',
'function utl_get_clean_client_prefs_csv (',
'  p_client_identifier_to_remove in varchar2           default null ,',
'  p_client_prefs_to_append      in t_client_prefs_row default null )',
'return varchar2;',
'',
'function utl_client_prefs_to_csv (',
'  p_client_prefs t_client_prefs_row )',
'return varchar2;',
'',
'function utl_csv_to_client_prefs (',
'  p_csv varchar2 ) return t_client_prefs_row;',
'',
'function utl_csv_get_client_identifier (',
'  p_csv varchar2 )',
'return varchar2;',
'',
'function utl_csv_get_exit_sysdate (',
'  p_csv varchar2 )',
'return date;',
'',
'function utl_csv_get_check_interval (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_csv_get_level (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_csv_get_boolean_options (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_create_log_entry (',
'  p_level           in integer                ,',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'',
'$end',
'',
'end console;',
'/',
'',
'prompt - Package CONSOLE (body)',
'create or replace package body console is',
'',
'--------------------------------------------------------------------------------',
'-- PRIVATE CONSTANTS, TYPES, GLOBALS',
'--------------------------------------------------------------------------------',
'',
'c_crlf                   constant t_2b  := chr(13) || chr(10);',
'c_cr                     constant t_1b  := chr(13);',
'c_lf                     constant t_1b  := chr(10);',
'c_lflf                   constant t_2b  := chr(10) || chr(10);',
'c_ampersand              constant t_1b  := chr(38);',
'c_html_ampersand         constant t_8b  := chr(38) || ''amp;'';',
'c_html_less_then         constant t_4b  := chr(38) || ''lt;'';',
'c_html_greater_then      constant t_4b  := chr(38) || ''gt;'';',
'c_timestamp_format       constant t_32b := ''yyyy-mm-dd hh24:mi:ss.ff6'';',
'c_date_format            constant t_32b := ''yyyy-mm-dd hh24:mi:ss'';',
'c_date_format_short      constant t_16b := ''yymmddhh24miss'';',
'c_default_label          constant t_8b  := ''default'';',
'c_conf_id                constant t_4b  := ''CONF'';',
'c_client_id_prefix       constant t_8b  := ''{o,o} '';',
'c_console_owner          constant t_32b := $$plsql_unit_owner;',
'c_console_job_name       constant t_16b := ''CONSOLE_PURGE'';',
'c_param_value_max_length constant t_int :=  2000;',
'c_assert_error_code      constant t_int := -20777 ;',
'c_assert_error_message   constant t_32b := ''Assertion failed: '';',
'',
'-- CONSTANTS FOR BITAND OPERATIONS',
'c_call_stack             constant t_int := 16;',
'c_user_env               constant t_int :=  8;',
'c_apex_env               constant t_int :=  4;',
'c_cgi_env                constant t_int :=  2;',
'c_console_env            constant t_int :=  1;',
'',
'-- NUMERIC TYPE IDENTFIERS',
'-- c_number                 constant t_int :=   2; -- float',
'-- c_binary_float           constant t_int := 100;',
'-- c_binary_double          constant t_int := 101;',
'-- STRING TYPE IDENTFIERS',
'-- c_char                   constant t_int :=  96; -- nchar',
'-- c_varchar2               constant t_int :=   1; -- nvarchar2',
'   c_long                   constant t_int :=   8;',
'   c_clob                   constant t_int := 112; -- nclob',
'   c_xmltype                constant t_int := 109; -- anydata, anydataset, anytype, object type, varray, nested table',
'-- c_rowid                  constant t_int :=  69;',
'-- c_urowid                 constant t_int := 208;',
'-- BINARY TYPE IDENTFIERS',
'   c_raw                    constant t_int :=  23;',
'   c_long_raw               constant t_int :=  24;',
'   c_blob                   constant t_int := 113;',
'   c_bfile                  constant t_int := 114;',
'-- DATE TYPE IDENTFIERS',
'-- c_date                   constant t_int :=  12;',
'-- c_timestamp              constant t_int := 180;',
'-- c_timestamp_tz           constant t_int := 181;',
'-- c_timestamp_ltz          constant t_int := 231;',
'-- INTERVAL TYPE IDENTFIERS',
'-- c_interval_year_to_month constant t_int := 182;',
'-- c_interval_day_to_second constant t_int := 183;',
'-- CURSOR TYPE IDENTFIERS',
'-- c_ref                    constant t_int := 111;',
'-- c_ref_cursor             constant t_int := 102; -- same identfiers for strong and weak ref cursor',
'',
'type t_timers_tab      is table of timestamp index by t_128b;',
'type t_counters_tab    is table of t_int     index by t_128b;',
'type t_saved_stack_tab is table of t_1kb     index by binary_integer;',
'',
'g_params         t_attribute_value_tab_i;',
'g_timers         t_timers_tab;',
'g_counters       t_counters_tab;',
'g_saved_stack    t_saved_stack_tab;',
'g_prev_error_msg t_1kb;',
'',
'g_conf_client_identifier t_64b;',
'g_conf_exit_sysdate      date;',
'g_conf_check_interval    integer;',
'g_conf_check_sysdate     date;',
'g_conf_level             t_int;',
'g_conf_call_stack        boolean;',
'g_conf_user_env          boolean;',
'g_conf_apex_env          boolean;',
'g_conf_cgi_env           boolean;',
'g_conf_console_env       boolean;',
'g_conf_enable_ascii_art  boolean;',
'',
'-------------------------------------------------------------------------------',
'-- PRIVATE HELPER METHODS (forward declarations)',
'--------------------------------------------------------------------------------',
'',
'$if not $$utils_public $then',
'',
'procedure utl_set_client_identifier;',
'',
'procedure utl_set_session_conf;',
'',
'procedure utl_set_conf (',
'  p_conf console_conf%rowtype );',
'',
'procedure utl_set_client_prefs (',
'  p_prefs varchar2 );',
'',
'function utl_get_conf return console_conf%rowtype result_cache;',
'',
'function utl_get_client_prefs (',
'  p_all_prefs_csv varchar2     ,',
'  p_client_identifier varchar2 )',
'return t_client_prefs_row;',
'',
'function utl_get_client_prefs_tab return t_client_prefs_tab_i;',
'',
'function utl_escape_md_tab_text (',
'  p_text varchar2 )',
'return varchar2;',
'',
'function utl_last_error return varchar2;',
'',
'function utl_logging_is_enabled (',
'  p_level integer )',
'return boolean;',
'',
'function utl_normalize_label (',
'  p_label varchar2 )',
'return varchar2;',
'',
'function utl_replace_linebreaks (',
'  p_text varchar2                     ,',
'  p_replace_with varchar2 default '' '' )',
'return varchar2;',
'',
'function utl_get_clean_client_prefs_csv (',
'  p_client_identifier_to_remove in varchar2           default null ,',
'  p_client_prefs_to_append      in t_client_prefs_row default null )',
'return varchar2;',
'',
'function utl_client_prefs_to_csv (',
'  p_client_prefs t_client_prefs_row )',
'return varchar2;',
'',
'function utl_csv_to_client_prefs (',
'  p_csv varchar2 ) return t_client_prefs_row;',
'',
'function utl_csv_get_client_identifier (',
'  p_csv varchar2 )',
'return varchar2;',
'',
'function utl_csv_get_exit_sysdate (',
'  p_csv varchar2 )',
'return date;',
'',
'function utl_csv_get_check_interval (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_csv_get_level (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_csv_get_boolean_options (',
'  p_csv varchar2 )',
'return integer;',
'',
'function utl_create_log_entry (',
'  p_level           in integer                ,',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type;',
'',
'$end',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC CONSOLE METHODS',
'--------------------------------------------------------------------------------',
'',
'function my_client_identifier return varchar2 is',
'begin',
'  return g_conf_client_identifier;',
'end my_client_identifier;',
'',
'--------------------------------------------------------------------------------',
'',
'function my_log_level return integer is',
'begin',
'  return g_conf_level;',
'end my_log_level;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure error_save_stack is',
'begin',
'  g_saved_stack(g_saved_stack.count + 1) := substr(scope || utl_last_error, 1, 1024);',
'end error_save_stack;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure error (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_log_id := utl_create_log_entry (',
'    p_level           => c_level_error     ,',
'    p_message         => p_message         ,',
'    p_permanent       => p_permanent       ,',
'    p_call_stack      => p_call_stack      ,',
'    p_apex_env        => p_apex_env        ,',
'    p_cgi_env         => p_cgi_env         ,',
'    p_console_env     => p_console_env     ,',
'    p_user_env        => p_user_env        ,',
'    p_user_agent      => p_user_agent      ,',
'    p_user_scope      => p_user_scope      ,',
'    p_user_error_code => p_user_error_code ,',
'    p_user_call_stack => p_user_call_stack );',
'end error;',
'',
'function error (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_log_id := utl_create_log_entry (',
'    p_level           => c_level_error     ,',
'    p_message         => p_message         ,',
'    p_permanent       => p_permanent       ,',
'    p_call_stack      => p_call_stack      ,',
'    p_apex_env        => p_apex_env        ,',
'    p_cgi_env         => p_cgi_env         ,',
'    p_console_env     => p_console_env     ,',
'    p_user_env        => p_user_env        ,',
'    p_user_agent      => p_user_agent      ,',
'    p_user_scope      => p_user_scope      ,',
'    p_user_error_code => p_user_error_code ,',
'    p_user_call_stack => p_user_call_stack );',
'  return v_log_id;',
'end error;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure warn (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_warning) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_warning   ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'end warn;',
'',
'function warn (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_warning) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_warning   ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'  return v_log_id;',
'end warn;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure info (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_info) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_info      ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'end info;',
'',
'function info (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_info) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_info      ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'  return v_log_id;',
'end info;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure log (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env       '))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
' in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_info) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_info      ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'end log;',
'',
'function log (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_info) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_info    ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'  return v_log_id;',
'end log;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure debug (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_debug) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_debug     ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'end debug;',
'',
'function debug (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_debug) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_debug     ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'  return v_log_id;',
'end debug;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure trace (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default true  ,',
'  p_cgi_env         in boolean  default true  ,',
'  p_console_env     in boolean  default true  ,',
'  p_user_env        in boolean  default true  ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_trace) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_trace     ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'end trace;',
'',
'function trace (',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default true  ,',
'  p_apex_env        in boolean  default true  ,',
'  p_cgi_env         in boolean  default true  ,',
'  p_console_env     in boolean  default true  ,',
'  p_user_env        in boolean  default true  ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_trace) then',
'    v_log_id := utl_create_log_entry (',
'      p_level           => c_level_trace     ,',
'      p_message         => p_message         ,',
'      p_permanent       => p_permanent       ,',
'      p_call_stack      => p_call_stack      ,',
'      p_apex_env        => p_apex_env        ,',
'      p_cgi_env         => p_cgi_env         ,',
'      p_console_env     => p_console_env     ,',
'      p_user_env        => p_user_env        ,',
'      p_user_agent      => p_user_agent      ,',
'      p_user_scope      => p_user_scope      ,',
'      p_user_error_code => p_user_error_code ,',
'      p_user_call_stack => p_user_call_stack );',
'  else',
'    g_params.delete;',
'  end if;',
'  return v_log_id;',
'end trace;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count (',
'  p_label in varchar2 default null )',
'is',
'  v_label t_128b;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    g_counters(v_label) := g_counters(v_label) + 1;',
'  else',
'    g_counters(v_label) := 1;',
'  end if;',
'end count;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_reset (',
'  p_label in varchar2 default null )',
'is',
'  v_label t_128b;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    g_counters(v_label) := 0;',
'  else',
'    g_counters(v_label) := 0;',
'  end if;',
'end count_reset;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_current (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null )',
'is',
'  v_label  t_128b;',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    if utl_logging_is_enabled (c_level_info) then',
'      v_log_id := utl_create_log_entry (',
'        p_level   => c_level_info,',
'        p_message => v_label || '': '' || to_char(g_counters(v_label)) ||',
'                     case when p_message is not null then '' - '' || p_message end',
'      );',
'    end if;',
'  else',
'    warn(''Counter `'' || v_label || ''` does not exist.'');',
'  end if;',
'end count_current;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure count_end (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null )',
'is',
'  v_label  t_128b;',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    if utl_logging_is_enabled (c_level_info) then',
'      v_log_id := utl_create_log_entry (',
'        p_level   => c_level_info,',
'        p_message => v_label || '': '' || to_char(g_counters(v_label)) ||',
'                     case when p_message is not null then '' - '' || p_message end',
'    );',
'    end if;',
'    g_counters.delete(v_label);',
'  else',
'    warn(''Counter `'' || v_label || ''` does not exist.'');',
'  end if;',
'end count_end;',
'',
'--------------------------------------------------------------------------------',
'',
'function count_current (',
'  p_label in varchar2 default null )',
'return t_int',
'is',
'  v_label  t_128b;',
'  v_return t_int;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    v_return := g_counters(v_label);',
'  end if;',
'  return v_return;',
'end count_current;',
'',
'--------------------------------------------------------------------------------',
'',
'function count_end (',
'  p_label in varchar2 default null )',
'return t_int',
'is',
'  v_label  t_128b;',
'  v_return t_int;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_counters.exists(v_label) then',
'    v_return := g_counters(v_label);',
'    g_counters.delete(v_label);',
'  end if;',
'  return v_return;',
'end count_end;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time (',
'  p_label in varchar2 default null )',
'is',
'begin',
'  g_timers(utl_normalize_label(p_label)) := localtimestamp;',
'end time;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_reset (',
'  p_label in varchar2 default null )',
'is',
'begin',
'  time(p_label);',
'end time_reset;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_current (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null )',
'is',
'  v_label  t_128b;',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_timers.exists(v_label) then',
'    if utl_logging_is_enabled (c_level_info) then',
'      v_log_id := utl_create_log_entry (',
'        p_level   => c_level_info,',
'        p_message => v_label || '': '' || runtime (g_timers(v_label)) ||',
'                     case when p_message is not null then '' - '' || p_message end',
'      );',
'    end if;',
'  else',
'    warn(''Timer `'' || v_label || ''` does not exist.'');',
'  end if;',
'end time_current;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure time_end (',
'  p_label   in varchar2 default null ,',
'  p_message in varchar2 default null )',
'is',
'  v_label  t_128b;',
'  v_log_id console_logs.log_id%type;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_timers.exists(v_label) then',
'    if utl_logging_is_enabled (c_level_info) then',
'      v_log_id := utl_create_log_entry (',
'        p_level   => c_level_info,',
'        p_message => v_label || '': '' || runtime (g_timers(v_label)) ||',
'                     case when p_message is not null then '' - '' || p_message end',
'      );',
'    end if;',
'    g_timers.delete(v_label);',
'  else',
'    warn(''Timer `'' || v_label || ''` does not exist.'');',
'  end if;',
'end time_end;',
'',
'--------------------------------------------------------------------------------',
'',
'function time_current (',
'  p_label in varchar2 default null )',
'return varchar2',
'is',
'  v_label  t_128b;',
'  v_return t_64b;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_timers.exists(v_label) then',
'    v_return :=  runtime(g_timers(v_label));',
'  end if;',
'  return v_return;',
'end time_current;',
'',
'--------------------------------------------------------------------------------',
'',
'function time_end (',
'  p_label in varchar2 default null )',
'return varchar2',
'is',
'  v_label  t_128b;',
'  v_return t_64b;',
'begin',
'  v_label := utl_normalize_label(p_label);',
'  if g_timers.exists(v_label) then',
'    v_return :=  runtime(g_timers(v_label));',
'    g_timers.delete(v_label);',
'  end if;',
'  return v_return;',
'end time_end;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure table# (',
'  p_data_cursor       in sys_refcursor         ,',
'  p_comment           in varchar2 default null ,',
'  p_include_row_num   in boolean  default true ,',
'  p_max_rows          in integer  default 100  ,',
'  p_max_column_length in integer  default 1000 )',
'is',
'  v_log_id console_logs.log_id%type;',
'begin',
'  if utl_logging_is_enabled (c_level_info) then',
'    v_log_id := utl_create_log_entry (',
'      p_level   => c_level_info,',
'      p_message => to_html_table (',
'        p_data_cursor       => p_data_cursor       ,',
'        p_comment           => p_comment           ,',
'        p_include_row_num   => p_include_row_num   ,',
'        p_max_rows          => p_max_rows          ,',
'        p_max_column_length => p_max_column_length ) );',
'  end if;',
'end table#;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure assert (',
'  p_expression in boolean  ,',
'  p_message    in varchar2 )',
'is',
'begin',
'  if not p_expression then',
'    raise_application_error(',
'      c_assert_error_code,',
'      c_assert_error_message || p_message,',
'      true);',
'  end if;',
'end assert;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure assertf (',
'  p_expression in boolean               ,',
'  p_message    in varchar2              ,',
'  p0           in varchar2 default null ,',
'  p1           in varchar2 default null ,',
'  p2           in varchar2 default null ,',
'  p3           in varchar2 default null ,',
'  p4           in varchar2 default null ,',
'  p5           in varchar2 default null ,',
'  p6           in varchar2 default null ,',
'  p7           in varchar2 default null ,',
'  p8           in varchar2 default null ,',
'  p9           in varchar2 default null )',
'is',
'begin',
'  if not p_expression then',
'    raise_application_error(',
'      c_assert_error_code,',
'      format(',
'        c_assert_error_message || p_message,',
'        p0 => p0,',
'        p1 => p1,',
'        p2 => p2,',
'        p3 => p3,',
'        p4 => p4,',
'        p5 => p5,',
'        p6 => p6,',
'        p7 => p7,',
'        p8 => p8,',
'        p9 => p9),',
'      true);',
'  end if;',
'end assertf;',
'',
'--------------------------------------------------------------------------------',
'',
'function format (',
'  p_message in varchar2              ,',
'  p0        in varchar2 default null ,',
'  p1        in varchar2 default null ,',
'  p2        in varchar2 default null ,',
'  p3        in varchar2 default null ,',
'  p4        in varchar2 default null ,',
'  p5        in varchar2 default null ,',
'  p6        in varchar2 default null ,',
'  p7        in varchar2 default null ,',
'  p8        in varchar2 default null ,',
'  p9        in varchar2 default null )',
'return varchar2 is',
'  v_message t_32kb := p_message;',
'begin',
'  -- id replacements',
'  v_message := replace(v_message, ''%0'', p0);',
'  v_message := replace(v_message, ''%1'', p1);',
'  v_message := replace(v_message, ''%2'', p2);',
'  v_message := replace(v_message, ''%3'', p3);',
'  v_message := replace(v_message, ''%4'', p4);',
'  v_message := replace(v_message, ''%5'', p5);',
'  v_message := replace(v_message, ''%6'', p6);',
'  v_message := replace(v_message, ''%7'', p7);',
'  v_message := replace(v_message, ''%8'', p8);',
'  v_message := replace(v_message, ''%9'', p9);',
'',
'  -- new line',
'  v_message := replace(v_message, ''%n'', c_lf);',
'',
'  -- positional replacements',
'  return sys.utl_lms.format_message(v_message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);',
'end format;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in varchar2 )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := substr(p_value, 1, c_param_value_max_length);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in number   )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_char(p_value);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in date     )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_char(p_value, ''yyyy-mm-dd hh24:mi:ss'');',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2  ,',
'  p_value in timestamp )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_char(p_value, ''yyyy-mm-dd hh24:mi:ssxff'');',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2                 ,',
'  p_value in timestamp with time zone )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_char(p_value, ''yyyy-mm-dd hh24:mi:ssxff tzr'');',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2                       ,',
'  p_value in timestamp with local time zone )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_char(p_value, ''yyyy-mm-dd hh24:mi:ssxff tzr'');',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2               ,',
'  p_value in interval year to month )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := substr(to_char(p_value), 1, c_param_value_max_length);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2               ,',
'  p_value in interval day to second )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := substr(to_char(p_value), 1, c_param_value_max_length);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in boolean  )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := to_string(p_value);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in clob     )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := substr(p_value, 1, c_param_value_max_length);',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure add_param (',
'  p_name  in varchar2 ,',
'  p_value in xmltype  )',
'is',
'  v_param t_attribute_value_row;',
'begin',
'  v_param.attribute := substr(p_name, 1, 128);',
'  v_param.value     := case when p_value is not null then substr(p_value.getclobval(), 1, c_param_value_max_length) else null end;',
'  g_params(g_params.count + 1) := v_param;',
'end add_param;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure action (',
'  p_action in varchar2 )',
'is',
'begin',
'  sys.dbms_application_info.set_action (',
'    p_action );',
'end action;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure module (',
'  p_module in varchar2,',
'  p_action in varchar2 default null',
')',
'is',
'begin',
'  sys.dbms_application_info.set_module(',
'    p_module ,',
'    p_action );',
'end module;',
'',
'--------------------------------------------------------------------------------',
'',
'function level_error   return integer is begin return c_level_error  ; end;',
'function level_warning return integer is begin return c_level_warning; end;',
'function level_info    return integer is begin return c_level_info   ; end;',
'function level_debug   return integer is begin return c_level_debug  ; end;',
'function level_trace   return integer is begin return c_level_trace  ; end;',
'',
'function level_is_warning return boolean is begin return utl_logging_is_enabled(c_level_warning); end;',
'function level_is_info    return boolean is begin return utl_logging_is_enabled(c_level_info   ); end;',
'function level_is_debug   return boolean is begin return utl_logging_is_enabled(c_level_debug  ); end;',
'function level_is_trace   return boolean is begin return utl_logging_is_enabled(c_level_trace  ); end;',
'',
'function level_is_warning_yn return varchar2 is begin return to_yn(utl_logging_is_enabled(c_level_warning)); end;',
'function level_is_info_yn    return varchar2 is begin return to_yn(utl_logging_is_enabled(c_level_info   )); end;',
'function level_is_debug_yn   return varchar2 is begin return to_yn(utl_logging_is_enabled(c_level_debug  )); end;',
'function level_is_trace_yn   return varchar2 is begin return to_yn(utl_logging_is_enabled(c_level_trace  )); end;',
'',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC HELPER METHODS',
'--------------------------------------------------------------------------------',
'',
'$if $$apex_installed $then',
'',
'function apex_error_handling (',
'  p_error in apex_error.t_error )',
'return apex_error.t_error_result',
'is',
'  v_result          apex_error.t_error_result;',
'  v_log_id          number;',
'  v_constraint_name t_256b;',
'  v_app_id          t_int := v(''APP_ID'');',
'  v_app_page_id     t_int := v(''APP_PAGE_ID'');',
'  --',
'  function extract_constraint_name(',
'    p_sqlerrm in varchar2)',
'  return varchar2 is',
'  begin',
'    return regexp_substr(p_sqlerrm, ''\(\S+?\.(\S+?)\)'', 1, 1, ''i'', 1);',
'  end;',
'  --',
'  function ascii_art (',
'    p_type in varchar2 ) -- html, md',
'  return varchar2 is',
'    v_return t_1kb;',
'    v_troll  t_1kb := q''[',
'                \|||/',
'                (o o)',
'    ,-------ooO--(_)------------.',
'    | Ooops, there was an ERROR |',
'    | Application ID: #APP_ID## |',
'    | Log ID: #LOG_ID########## |',
'    ''----------------Ooo--------''',
'               |__|__|',
'                || ||',
'               ooO Ooo   ]'' || c_lf;',
'  begin',
'    if g_conf_enable_ascii_art then',
'      v_return :=',
'        case p_type when ''html'' then ''<pre>'' when ''md'' then c_lflf||''```'' end             ||',
'        replace(replace(v_troll,',
'          ''#APP_ID##''        , rpad( v_app_id                             ,  9, '' '') ),',
'          ''#LOG_ID##########'', rpad( nvl(to_char(v_log_id), ''this.log_id''), 17, '' '') )  ||',
'        case p_type when ''html'' then ''</pre>'' when ''md'' then ''```'' end          ;',
'    end if;',
'    return v_return;',
'  end ascii_art;',
'  --',
'  function create_apex_lang_message (',
'    p_constraint_name in varchar2',
'  ) return varchar2',
'  is',
'    pragma autonomous_transaction;',
'    v_message_text t_1kb :=',
'      ''DEVELOPER TODO: Change the message in APEX > Application Builder > Shared Components > Text Messages for constraint '' ||',
'      p_constraint_name || ''.'';',
'  begin',
'    apex_lang.create_message(',
'      p_application_id => v_app_id,',
'      p_name           => p_constraint_name,',
'      p_language       => nvl(apex_util.get_preference(''FSP_LANGUAGE_PREFERENCE''), ''en''),',
'      p_message_text   => v_message_text);',
'    commit;',
'    return v_message_text;',
'  end create_apex_lang_message;',
'  --',
'  function to_md_li_pre (',
'    p_text in varchar2)',
'  return varchar2 is',
'    v_fences t_32b := ''    ```'';',
'  begin',
'    return',
'      case when p_text is null',
'        then null',
'        else c_lf || v_fences || c_lf || to_md_code_block(p_text) || c_lf || v_fences',
'      end;',
'  end to_md_li_pre;',
'  --',
'  function log_message (',
'    p_text in varchar2 )',
'  return clob is',
'    v_clob  clob;',
'    v_cache t_32kb;',
'  begin',
'    clob_append ( v_clob, v_cache, p_text                   || c_lflf                                              );',
'    clob_append ( v_clob, v_cache, ''## Technical Info''      || c_lflf                                              );',
'    clob_append ( v_clob, v_cache, ''1. is_internal_error: '' || to_string(p_error.is_internal_error)        || c_lf );',
'    clob_append ( v_clob, v_cache, ''2. apex_error_code: ''   || p_error.apex_error_code                     || c_lf );',
'    clob_append ( v_clob, v_cache, ''3. original message: ''  || p_error.message                             || c_lf );',
'    clob_append ( v_clob, v_cache, ''4. ora_sqlcode: ''       || p_error.ora_sqlcode                         || c_lf );',
'    clob_append ( v_clob, v_cache, ''5. ora_sqlerrm: ''       || utl_replace_linebreaks(p_error.ora_sqlerrm) || c_lf );',
'    clob_append ( v_clob, v_cache, ''6. component.type: ''    || p_error.component.type                      || c_lf );',
'    clob_append ( v_clob, v_cache, ''7. component.id: ''      || p_error.component.id                        || c_lf );',
'    clob_append ( v_clob, v_cache, ''8. component.name: ''    || p_error.component.name                      || c_lf );',
'    clob_append ( v_clob, v_cache, ''9. error_backtrace: ''   || to_md_li_pre(p_error.error_backtrace)       || c_lf );',
'    clob_append ( v_clob, v_cache, ''10. error_statement: ''  || to_md_li_pre(p_error.error_statement)       || c_lf );',
'    clob_flush_cache ( v_clob, v_cache );',
'    return v_clob;',
'  end log_message;',
'  --',
'begin',
'  v_result := apex_error.init_error_result (p_error => p_error);',
'',
'  -- If it''s an internal error raised by APEX, like an invalid statement or code',
'  -- which can''t be executed, the error text might contain security sensitive',
'  -- information. To avoid this security problem we can rewrite the error to a',
'  -- generic error message and log the original error message for further',
'  -- investigation by the help desk.',
'  if p_error.is_internal_error then',
'',
'    -- Mask all errors that are not common runtime errors (Access Denied errors',
'    -- raised by application / page authorization and all errors regarding',
'    -- session and session state).',
'    if not p_error.is_common_runtime_error then',
'',
'      -- Log error and return log ID as reference.',
'      v_log_id := error (',
'        p_message         => log_message(''Unexpected internal application error.'') ,',
'        p_call_stack      => false                                                                            ,',
'        p_apex_env        => true                                                                             ,',
'        p_user_scope      => ''APEX BACKEND ERROR HANDLER: App '' || v_app_id || '', page '' || v_app_page_id     ,',
'        p_user_error_code => p_error.ora_sqlcode                                                              ,',
'        p_user_call_stack => ''#### Error Backtrace'' || c_lflf || p_error.error_backtrace                        );',
'',
'      -- Change the message to the generic error message which doesn''t expose',
'      -- any sensitive information.',
'      v_result.message :=',
'        case when v_result.display_location = apex_error.c_on_error_page then ascii_art(''html'') end ||',
'        ''An unexpected internal application error has occurred. '' ||',
'        ''Please get in contact with your Oracle APEX support team and provide '' ||',
'        ''"App ID '' || to_char(v_app_id) || '', Log ID '' || to_char(v_log_id) ||',
'        ''" for further investigation.'';',
'      v_result.additional_info := null;',
'',
'    end if;',
'',
'  else',
'',
'    -- Always show the error as inline error.',
'    --',
'    -- NOTE: If you have created manual tabular '))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'forms (using the package',
'    --       apex_item/htmldb_item in the SQL statement) you should still use',
'    --       "On error page" on that pages to avoid loosing entered data.',
'    v_result.display_location :=',
'      case when v_result.display_location = apex_error.c_on_error_page',
'        then apex_error.c_inline_in_notification',
'        else v_result.display_location',
'      end;',
'',
'    -- NOTE: If you want to have friendlier ORA error messages, you can also',
'    --       define a text message with the name pattern APEX.ERROR.ORA-number',
'    --       There is no need to implement custom code for that.',
'    --',
'    -- If it''s a constraint violation like',
'    --',
'    -- * ORA-00001: unique constraint violated',
'    -- * ORA-02091: transaction rolled back (-> can hide a deferred constraint)',
'    -- * ORA-02290: check constraint violated',
'    -- * ORA-02291: integrity constraint violated - parent key not found',
'    -- * ORA-02292: integrity constraint violated - child record found',
'    --',
'    -- We try to get a friendly error message from APEX text messages. If we',
'    -- don''t find the constraint name there we create a new text message, that',
'    -- has to be changed by the developers.',
'    if p_error.ora_sqlcode in (-1, -2091, -2290, -2291, -2292) then',
'      v_constraint_name := extract_constraint_name(p_error.ora_sqlerrm);',
'      v_result.message := apex_lang.message( v_constraint_name );',
'',
'      if v_result.message = v_constraint_name then',
'',
'        -- * Idea by Roel Hartman:',
'        --   https://roelhartman.blogspot.com/2021/02/stop-using-validations-for-checking.html',
'        -- * Also see this video by Anton and Neelesh:',
'        --   https://www.insum.ca/episode-22-error-handling/',
'        v_result.message := create_apex_lang_message (v_constraint_name);',
'',
'        -- Log a permanent error, so developers get information that they need',
'        -- to change the text message.',
'        error (',
'          p_message         => log_message (v_result.message)                                               ,',
'          p_permanent       => true                                                                         ,',
'          p_call_stack      => false                                                                        ,',
'          p_apex_env        => true                                                                         ,',
'          p_user_scope      => ''APEX BACKEND ERROR HANDLER: App '' || v_app_id || '', page '' || v_app_page_id ,',
'          p_user_error_code => p_error.ora_sqlcode                                                          ,',
'          p_user_call_stack => ''#### Error Backtrace'' || c_lflf || p_error.error_backtrace                    );',
'',
'      end if;',
'',
'    end if;',
'',
'    -- If an ORA error has been raised, for example a',
'    -- raise_application_error(-20xxx, ''...'') in a table trigger or in a PL/SQL',
'    -- package called by a process and we haven''t found the error in our lookup',
'    -- table, then we just want to see the actual error text and not the full',
'    -- error stack with all the ORA error numbers.',
'    if p_error.ora_sqlcode is not null and v_result.message = p_error.message then',
'      v_result.message := apex_error.get_first_ora_error_text (p_error => p_error);',
'    end if;',
'',
'    -- If no associated page item/tabular form column has been set, we can use',
'    -- apex_error.auto_set_associated_item to automatically guess the affected',
'    -- error field by examine the ORA error for constraint names or column',
'    -- names.',
'    if v_result.page_item_name is null and v_result.column_alias is null then',
'      apex_error.auto_set_associated_item (',
'        p_error        => p_error,',
'        p_error_result => v_result );',
'    end if;',
'',
'  end if;',
'',
'  return v_result;',
'end apex_error_handling;',
'',
'--------------------------------------------------------------------------------',
'',
'function apex_plugin_render (',
'  p_dynamic_action  in  apex_plugin.t_dynamic_action ,',
'  p_plugin          in  apex_plugin.t_plugin         )',
'return apex_plugin.t_dynamic_action_render_result is',
'  v_result apex_plugin.t_dynamic_action_render_result;',
'begin',
'  v_result.ajax_identifier := apex_plugin.get_ajax_identifier;',
'',
'  if apex_application.g_debug then',
'    apex_plugin_util.debug_dynamic_action(',
'      p_plugin          => p_plugin         ,',
'      p_dynamic_action  => p_dynamic_action );',
'  end if;',
'',
'  apex_javascript.add_library(',
'    p_name                   => ''console''            ,',
'    p_directory              => p_plugin.file_prefix ,',
'    p_check_to_add_minified  => true                 );',
'',
'  apex_javascript.add_onload_code(',
'    ''oic.pluginId         = ''  || apex_javascript.add_value(apex_plugin.get_ajax_identifier, false) ||  '';'' ||',
'    ''oic.version          = "'' || console.version                                                   || ''";'' ||',
'    ''oic.clientIdentifier = "'' || console.my_client_identifier                                      || ''";'' ||',
'    ''oic.level            = ''  || console.my_log_level                                              ||  '';'' ||',
'    ''oic.init();''    ,',
'    ''COM.OGOBRECHT.CONSOLE'' );',
'',
'  v_result.javascript_function := ''function(){ null; }'';',
'',
'  return v_result;',
'end apex_plugin_render;',
'',
'--------------------------------------------------------------------------------',
'',
'function apex_plugin_ajax (',
'  p_dynamic_action  in  apex_plugin.t_dynamic_action ,',
'  p_plugin          in  apex_plugin.t_plugin         )',
'return apex_plugin.t_dynamic_action_ajax_result is',
'  v_result          apex_plugin.t_dynamic_action_ajax_result;',
'  v_level           t_int;',
'  v_message         t_32kb;',
'  v_user_scope      t_32kb;',
'  v_user_call_stack t_32kb;',
'  v_user_agent      t_32kb;',
'begin',
'  -- If we do not provide a value for p_user_scope and p_user_call_stack, then',
'  -- our console package provides per default the values from the PL/SQL',
'  -- environment. But this is useless for frontend messages from JavaScript.',
'  -- Therefore we set any null value for these two parmaters to a point.',
'  v_level           := to_number(apex_application.g_x01) ;',
'  v_message         := apex_application.g_x02            ;',
'  v_user_scope      := nvl(apex_application.g_x03, ''.'')  ;',
'  v_user_call_stack := nvl(apex_application.g_x04, ''.'')  ;',
'  v_user_agent      := apex_application.g_x05            ;',
'  case v_level',
'    when c_level_error then',
'      console.error(',
'        p_message         => v_message         ,',
'        p_user_scope      => v_user_scope      ,',
'        p_user_call_stack => v_user_call_stack ,',
'        p_user_agent      => v_user_agent      );',
'    when c_level_warning then',
'      console.warn (',
'        p_message         => v_message         ,',
'        p_user_scope      => v_user_scope      ,',
'        p_user_call_stack => v_user_call_stack ,',
'        p_user_agent      => v_user_agent      );',
'    when c_level_info then',
'      console.info (',
'        p_message         => v_message         ,',
'        p_user_scope      => v_user_scope      ,',
'        p_user_call_stack => v_user_call_stack ,',
'        p_user_agent      => v_user_agent      );',
'    when c_level_debug then',
'      console.debug(',
'        p_message         => v_message         ,',
'        p_user_scope      => v_user_scope      ,',
'        p_user_call_stack => v_user_call_stack ,',
'        p_user_agent      => v_user_agent      );',
'    when c_level_trace then',
'      console.trace(',
'        p_message         => v_message         ,',
'        p_user_scope      => v_user_scope      ,',
'        p_user_call_stack => v_user_call_stack ,',
'        p_user_agent      => v_user_agent      );',
'  else',
'    null;',
'  end case;',
'',
'  htp.prn(''SUCCESS'');',
'  return v_result;',
'exception when others then',
'  htp.prn(sqlerrm);',
'  return v_result;',
'end apex_plugin_ajax;',
'',
'$end',
'',
'--------------------------------------------------------------------------------',
'',
'procedure conf (',
'  p_level            in integer default null ,',
'  p_check_interval   in integer default null ,',
'  p_enable_ascii_art in boolean default null )',
'is',
'  v_conf console_conf%rowtype;',
'begin',
'  assert (',
'    c_console_owner = sys_context(''USERENV'',''SESSION_USER''),',
'    ''Only the owner of the package console is allowed to change the configuration.'');',
'  v_conf := utl_get_conf; -- this will handle the defaults if we don''t have configured console yet.',
'  v_conf.conf_sysdate     := sysdate;',
'  v_conf.conf_user        := substrb(coalesce(sys_context(''USERENV'',''OS_USER''), sys_context(''USERENV'',''SESSION_USER'')), 1, 64);',
'  v_conf.level_id         := coalesce(p_level, v_conf.level_id);',
'  v_conf.level_name       := level_name(v_conf.level_id);',
'  v_conf.check_interval   := coalesce(p_check_interval, v_conf.check_interval);',
'  v_conf.enable_ascii_art := to_string(coalesce(p_enable_ascii_art, to_bool(v_conf.enable_ascii_art)));',
'  assert (',
'    v_conf.level_id between c_level_error and c_level_trace,',
'    ''Level needs to be 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace).'');',
'  assertf (',
'    v_conf.check_interval between c_check_interval_default and c_check_interval_max,',
'    ''Check interval needs to be between %s and %s (seconds). '' ||',
'    ''Values between %s and %s seconds can only be set per session with the procedure init.'',',
'    c_check_interval_default,',
'    c_check_interval_max,',
'    c_check_interval_min,',
'    c_check_interval_default);',
'  utl_set_conf(v_conf);',
'  utl_set_session_conf;',
'end conf;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure init (',
'  p_client_identifier in varchar2                                  ,',
'  p_level             in integer  default c_level_info             ,',
'  p_duration          in integer  default c_duration_default       ,',
'  p_check_interval    in integer  default c_check_interval_default ,',
'  p_call_stack        in boolean  default false                    ,',
'  p_user_env          in boolean  default false                    ,',
'  p_apex_env          in boolean  default false                    ,',
'  p_cgi_env           in boolean  default false                    ,',
'  p_console_env       in boolean  default false                    )',
'is',
'  v_prefs t_client_prefs_row;',
'  v_conf  console_conf%rowtype;',
'begin',
'  assert (',
'    p_level between c_level_error and c_level_trace,',
'    ''Level needs to be 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace). '' ||',
'    ''NOTE: Level 1 (error) will be always logged and needs no explicit call to the init method.'' );',
'  assert (',
'    p_client_identifier is not null,',
'    ''Client identifier must not be null.'');',
'  assertf (',
'    p_duration between c_duration_min and c_duration_max,',
'    ''Duration needs to be between %s and %s (minutes).'',',
'    c_duration_min,',
'    c_duration_max);',
'  assertf (',
'    p_check_interval between c_check_interval_min and c_check_interval_max,',
'    ''Check interval needs to be between %s and %s (seconds).'',',
'    c_check_interval_min,',
'    c_check_interval_max);',
'  assert ( p_call_stack  is not null, ''Call stack needs to be true or false (not null).''  );',
'  assert ( p_user_env    is not null, ''User env needs to be true or false (not null).''    );',
'  assert ( p_apex_env    is not null, ''APEX env needs to be true or false (not null).''    );',
'  assert ( p_cgi_env     is not null, ''CGI env needs to be true or false (not null).''     );',
'  assert ( p_console_env is not null, ''Console env needs to be true or false (not null).'' );',
'  --',
'  v_prefs.client_identifier := p_client_identifier;',
'  v_prefs.level_id          := p_level;',
'  v_prefs.level_name        := level_name(p_level);',
'  v_prefs.call_stack        := to_string(p_call_stack);',
'  v_prefs.user_env          := to_string(p_user_env);',
'  v_prefs.apex_env          := to_string(p_apex_env);',
'  v_prefs.cgi_env           := to_string(p_cgi_env);',
'  v_prefs.console_env       := to_string(p_console_env);',
'  v_prefs.check_interval    := p_check_interval;',
'  v_prefs.exit_sysdate      := sysdate + 1/24/60 * p_duration;',
'  utl_set_client_prefs(',
'    utl_get_clean_client_prefs_csv(',
'      p_client_identifier_to_remove => v_prefs.client_identifier,',
'      p_client_prefs_to_append      => v_prefs',
'    )',
'  );',
'  -- If we want to monitor our own session, wee need to load the configuration',
'  -- data from the context or table into the cache (package variables).',
'  -- Otherwise we need to wait until the cache duration is over (which defaults',
'  -- to 10 seconds) and the package reloads the configuration from the context',
'  -- or table on next call of a public logging method.',
'  if p_client_identifier = g_conf_client_identifier then',
'    utl_set_session_conf;',
'  end if;',
'end init;',
'',
'procedure init (',
'  p_level          in integer default c_level_info             ,',
'  p_duration       in integer default c_duration_default       ,',
'  p_check_interval in integer default c_check_interval_default ,',
'  p_call_stack     in boolean default false                    ,',
'  p_user_env       in boolean default false                    ,',
'  p_apex_env       in boolean default false                    ,',
'  p_cgi_env        in boolean default false                    ,',
'  p_console_env    in boolean default false                    )',
'is',
'begin',
'  init (',
'    p_client_identifier => g_conf_client_identifier ,',
'    p_level             => p_level                  ,',
'    p_duration          => p_duration               ,',
'    p_check_interval    => p_check_interval         ,',
'    p_call_stack        => p_call_stack             ,',
'    p_user_env          => p_user_env               ,',
'    p_apex_env          => p_apex_env               ,',
'    p_cgi_env           => p_cgi_env                ,',
'    p_console_env       => p_console_env            );',
'end init;',
'',
'--------------------------------------------------------------------------------',
'',
'-- We need this procedure to be able to use the identifier "exit". An internal',
'-- call to "exit" would not compile, to "exit_" it is ok. Also see calls to',
'-- "exit_" in the next two procedures.',
'procedure exit_ (',
'  p_client_identifier in varchar2 )',
'is',
'  v_conf console_conf%rowtype;',
'begin',
'  assert(p_client_identifier is not null, ''Client identifier must not be null.'');',
'  utl_set_client_prefs(',
'    utl_get_clean_client_prefs_csv(',
'      p_client_identifier_to_remove => p_client_identifier',
'    )',
'  );',
'  -- If we monitor our own session, wee need to load the configuration',
'  -- data from the context or table into the cache (package variables).',
'  -- Otherwise we need to wait until the cache duration is over (which defaults',
'  -- to 10 seconds) and the package reloads the configuration from the context',
'  -- or table on next call of a public logging method.',
'  if p_client_identifier = g_conf_client_identifier then',
'    utl_set_session_conf;',
'  end if;',
'end exit_;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure exit (',
'  p_client_identifier in varchar2 default my_client_identifier )',
'is',
'begin',
'  exit_(p_client_identifier);',
'end exit;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure exit_all is',
'begin',
'  utl_set_client_prefs(null);',
'  utl_set_session_conf;',
'end exit_all;',
'',
'--------------------------------------------------------------------------------',
'',
'function version return varchar2 is',
'begin',
'  return c_version;',
'end version;',
'',
'--------------------------------------------------------------------------------',
'',
'function split_to_table (',
'  p_string in varchar2,',
'  p_sep    in varchar2 default '',''',
') return t_vc2_tab pipelined is',
'  v_array t_vc2_tab_i;',
'begin',
'  if p_string is not null then',
'    v_array := split(p_string, p_sep);',
'    for i in 1 .. v_array.count loop',
'        pipe row ( v_array(i) );',
'    end loop;',
'  end if;',
'end split_to_table;',
'',
'--------------------------------------------------------------------------------',
'',
'function split (',
'  p_string in varchar2,',
'  p_sep    in varchar2 default '',''',
') return t_vc2_tab_i is',
'  v_str        t_32kb;',
'  v_idx        t_int;',
'  v_sep_length t_int;',
'  v_return     t_vc2_tab_i;',
'begin',
'  if p_string is not null then',
'    if p_sep is null then',
'      for i in 1 .. length(p_string) loop',
'        v_return(v_return.count + 1) := substr(p_string, i, 1);',
'      end loop;',
'    else',
'      v_str := p_string;',
'      v_sep_length := length(p_sep);',
'      loop',
'        v_idx := instr(v_str, p_sep);',
'        if v_idx > 0 then',
'          v_return(v_return.count + 1) := substr(v_str, 1, v_idx - 1);',
'          v_str := substr(v_str, v_idx + v_sep_length);',
'        else',
'          v_return(v_return.count + 1) := v_str;',
'          exit;',
'        end if;',
'      end loop;',
'    end if;',
'  end if;',
'  return v_return;',
'end split;',
'',
'--------------------------------------------------------------------------------',
'',
'function join (',
'  p_table in t_vc2_tab_i,',
'  p_sep   in varchar2 default '',''',
') return varchar2 is',
'  v_return t_32kb;',
'begin',
'  for i in 1 .. p_table.count loop',
'    v_return := v_return || p_sep || p_table(i);',
'  end loop;',
'  return v_return;',
'end join;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_yn (',
'  p_bool in boolean )',
'return varchar2 is',
'begin',
'  return case when p_bool then ''Y'' else ''N'' end;',
'end to_yn;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_string (',
'  p_bool in boolean )',
'return varchar2 is',
'begin',
'  return case when p_bool then ''true'' else ''false'' end;',
'end to_string;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_bool (',
'  p_string in varchar2 )',
'return boolean is',
'begin',
'  return',
'    case',
'      when upper(trim(p_string)) in (''TRUE'', ''Y'', ''YES'', ''1'')',
'        then true',
'      when upper(trim(p_string)) in (''FALSE'', ''N'', ''NO'', ''0'')',
'        then false',
'      else null',
'    end;',
'end to_bool;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_html_table (',
'  p_data_cursor       in sys_refcursor         ,',
'  p_comment           in varchar2 default null ,',
'  p_include_row_num   in boolean  default true ,',
'  p_max_rows          in integer  default 100  ,',
'  p_max_column_length in integer  default 1000 )',
'return clob is',
'  v_data_cursor        sys_refcursor := p_data_cursor;',
'  v_cursor_id          integer;',
'  v_clob               clob;',
'  v_cache              t_32kb;',
'  v_data_count         t_int := 0;',
'  v_col_count          t_int;',
'  v_desc_tab           sys.dbms_sql.desc_tab3;',
'  v_buffer_varchar2    t_32kb;',
'  v_buffer_clob        clob;',
'  v_buffer_xmltype     xmltype;',
'  v_buffer_long_length t_int;',
'  --',
'  procedure close_cursor ( p_cursor_id in out integer ) is',
'  begin',
'    if sys.dbms_sql.is_open(p_cursor_id) then',
'      sys.dbms_sql.close_cursor(p_cursor_id);',
'    end if;',
'  exception',
'    when invalid_cursor then null;',
'  end close_cursor;',
'  --',
'  function escape ( p_text in varchar2 ) return varchar2 is',
'  begin',
'    return replace(replace(replace(p_text,',
'      c_ampersand, c_html_ampersand    ),',
'      ''<''        , c_html_less_then    ),',
'      ''>''        , c_html_greater_then );',
'  end;',
'  --',
'  procedure describe_columns is',
'  begin',
'    sys.dbms_sql.describe_columns3(v_cursor_id, v_col_count, v_desc_tab);',
'    for i in 1..v_col_count loop',
'      if v_desc_tab(i).col_type = c_clob then',
'        sys.dbms_sql.define_column(v_cursor_id, i, v_buffer_clob);',
'      elsif v_desc_tab(i).col_type = c_xmltype then',
'        sys.dbms_sql.define_column(v_cursor_id, i, v_buffer_xmltype);',
'      elsif v_desc_tab(i).col_type = c_long then',
'        sys.dbms_sql.define_column_long(v_cursor_id, i);',
'      elsif v_desc_tab(i).col_type in (c_raw, c_long_raw, c_blob, c_bfile) then',
'        null; --> we ignore binary data types',
'      else',
'        sys.dbms_sql.define_column(v_cursor_id, i, v_buffer_varchar2, p_max_column_length);',
'      end if;',
'    end loop;',
'  end describe_columns;',
'  --',
'  procedure create_header is',
'  begin',
'    clob_append(v_clob, v_cache, c_lf || ''<tr><!--- header -->'' || c_lf);',
'    if p_include_row_num then',
'      clob_append(v_clob, v_cache, ''<th id="row_num">Row#</th>'' || c_lf);',
'    end if;',
'    for i in 1..v_col_count loop',
'      clob_append(v_clob, v_cache, ''<th id="'' || lower(v_desc_tab(i).col_name) || ''">''',
'      || initcap(replace(v_desc_tab(i).col_name, ''_'', '' '')) || ''</th>'' || c_lf);',
'    end loop;',
'    clob_append(v_clob, v_cache, ''</tr><!-- header -->'' || c_lf);',
'  end create_header;',
'  --',
'  procedure create_data is',
'  begin',
'    loop',
'      exit when sys.dbms_sql.fetch_rows(v_cursor_id) = 0 or v_data_count = p_max_rows;',
'      v_data_count := v_data_count + 1;',
'      clob_append(v_clob, v_cache, c_lf || ''<tr><!--- row '' || to_char(v_data_count) || '' -->'' || c_lf);',
'      if p_include_row_num then',
'        clob_append(v_clob, v_cache, ''<td headers="row_num">'' || to_char(v_data_count) || ''</td>'' || c_lf);',
'      end if;',
'      for i in 1..v_col_count loop',
'        clob_append(v_clob, v_cache, ''<td headers="'' || lower(v_desc_tab(i).col_name) || ''">'');',
'        --',
'        if v_desc_tab(i).col_type = c_clob then',
'          sys.dbms_sql.column_value(v_cursor_id, i, v_buffer_clob);',
'          clob_append(',
'            v_clob,',
'            v_cache,',
'            escape(substr(v_buffer_clob, 1, p_max_column_length))',
'            || case when length(v_buffer_clob) > p_max_column_length then ''...'' end',
'          );',
'        --',
'        elsif v_desc_tab(i).col_type = c_xmltype then',
'          sys.dbms_sql.column_value(v_cursor_id, i, v_buffer_xmltype);',
'          if v_buffer_xmltype is not null then',
'            v_buffer_clob := v_buffer_xmltype.getclobval();',
'            clob_append(',
'              v_clob,',
'              v_cache,',
'              escape(substr(v_buffer_clob, 1, p_max_column_length))',
'              || case when length(v_buffer_clob) > p_max_column_length then ''...'' end',
'            );',
'          end if;',
'        --',
'        elsif v_desc_tab(i).col_type = c_long then',
'          sys.dbms_sql.column_value_long(v_cursor_id, i, p_max_column_length, 0, v_buffer_varchar2, v_buffer_long_length);',
'            clob_append(',
'              v_clob,',
'              v_cache,',
'              escape(v_buffer_varchar2)',
'              || case when v_buffer_long_length > p_max_column_length then ''...'' end',
'            );',
'        --',
'        elsif v_desc_tab(i).col_type in (c_raw, c_long_raw, c_blob, c_bfile) then',
'          clob_append(v_clob, v_cache, ''Binary data type skipped - not supported for HTML'');',
'        --',
'        else',
'          sys.dbms_sql.column_value(v_cursor_id, i, v_buffer_varchar2);',
'          clob_append(v_clob, v_cache, escape(v_buffer_varchar2));',
'        end if;',
'        --',
'        clob_append(v_clob, v_cache, ''</td>'' || c_lf);',
'      end loop;',
'      clob_append(v_clob, v_cache, ''</tr><!-- row '' || to_char(v_data_count) || '' -->'' || c_lf);',
'    end loop;',
'  end create_data;',
'  --',
'begin',
'  v_cursor_id := sys.dbms_sql.to_cursor_number(v_data_cursor);',
'  describe_columns;',
'  if p_comment is not null then',
'    clob_append(v_clob, v_cache, escape(p_comment) || c_lflf);',
'  end if;',
'  clob_append(v_clob, v_cache, ''<table>'' || c_lf);',
'  create_header;',
'  create_data;',
'  clob_append(v_clob, v_cache, c_lf || ''</table>'' || c_lf);',
'  clob_flush_cache(v_clob, v_cache);',
'  close_cursor(v_cursor_id);',
'  return v_clob;',
'end to_html_table;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_md_code_block (',
'  p_text in varchar2 )',
'return varchar2 is',
'begin',
'  return',
'    ''    '' ||',
'    rtrim(',
'      trim( replace(replace(p_text, c_crlf, c_lf), c_lf, c_lf||''    '') ),',
'      c_lf',
'    );',
'end to_md_code_block;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_md_tab_header (',
'  p_key   in varchar2 default ''Attribute'' ,',
'  p_value in varchar2 default ''Value''     )',
'return varchar2 is',
'  v_key   t_32kb;',
'  v_value t_32kb;',
'begin',
'  v_key   := utl_escape_md_tab_text(p_key);',
'  v_value := utl_escape_md_tab_text(p_value);',
'  return ''| '' ||',
'    case when nvl(length(v_key),   0) < 30 then rpad(nvl(v_key  ,'' ''), 30, '' '') else v_key   end || '' | '' ||',
'    case when nvl(length(v_value), 0) < 43 then rpad(nvl(v_value,'' ''), 43, '' '') else v_value end || '' |''  || c_lf ||',
'    ''| ------------------------------ | ------------------------------------------- |'' || c_lf;',
'end to_md_tab_header;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_md_tab_data (',
'  p_key              in varchar2               ,',
'  p_value            in varchar2               ,',
'  p_value_max_length in integer  default 1000  ,',
'  p_show_null_values in boolean  default false )',
'return varchar2 is',
'  v_key   t_32kb;',
'  v_value t_32kb;',
'begin',
'  if p_value is null and not p_show_null_values then',
'    return null;',
'  else',
'    v_key   := utl_escape_md_tab_text(p_key);',
'    v_value := utl_escape_md_tab_text(substr(p_value, 1, p_value_max_length));',
'    return ''| '' ||',
'      case when nvl(length(v_key),   0) < 30 then rpad(nvl(v_key  ,'' ''), 30, '' '') else v_key   end || '' | '' ||',
'      case when nvl(length(v_value), 0) < 43 then rpad(nvl(v_value,'' ''), 43, '' '') else v_value end || '' |''  || c_lf;',
'  end if;',
'end to_md_tab_data;',
'',
'--------------------------------------------------------------------------------',
'',
'function to_unibar (',
'  p_value                  in number            ,',
'  p_scale                  in number default 1  ,',
'  p_width_block_characters in number default 25 ,',
'  p_fill_scale             in number default 0  )',
'return varchar2 deterministic is',
'  v_return              t_1kb;',
'  v_value_one_character number;',
'begin',
'  if p_value is not null then',
'  -- calculate the value of one character',
'    v_value_one_character := p_scale / p_width_block_characters;',
'',
'  -- create textbar: full block characters',
'    for i in 1..floor(p_value / v_value_one_character) loop',
'      v_return := v_return || unistr(''\2588'');',
'    end loop;',
'',
'  -- create textbar: last character - can be between 0 and 8(rounded), because there',
'  -- are block character available in unicode for 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8 and 1;',
'    case round((p_value / v_value_one_character - floor(p_value / v_value_one_character)) / 0.125)',
'      when 1 then -- 1/8 = char U+258F',
'        v_return := v_return || unistr(''\258F'');',
'      when 2 then -- 2/8 = char U+258E',
'        v_return := v_return || unistr(''\258E'');',
'      when 3 then -- 3/8 = char U+258D',
'        v_return := v_return || unistr(''\258D'');',
'      when 4 then -- 4/8 = char U+258C',
'        v_return := v_return || unistr(''\258C'');',
'      when 5 then -- 5/8 = char U+258B',
'        v_return := v_return || unistr(''\258B'');',
'      when 6 then -- 6/8 = char U+258A',
'        v_return := v_return || unistr(''\258A'');',
'      when 7 then -- 7/8 = char U+2589',
'        v_return := v_return || unistr(''\2589'');',
'      when 8 then -- 8/8 = char U+2588',
'        v_return := v_return || unistr(''\2588'');',
'      else',
'        null;',
'    end case;',
'',
'  -- fill up scale with shade',
'    if p_fill_scale = 1 then',
'      for i in 1..( p_width_block_characters - nvl(length(v_return), 0) ) loop',
'        v_return := v_return || unistr(''\2591'');',
'      end loop;',
'    end if;',
'  end if;',
'',
'  return v_return;',
'exception',
'  when value_error then',
'    return unistr(''\221E'');',
'end to_unibar;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure print ( p_message in varchar2 ) is',
'begin',
'  sys.dbms_output.put_line(p_message);',
'end print;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure printf (',
'  p_message in varchar2              ,',
'  p0        in varchar2 default null ,',
'  p1        in varchar2 default null ,',
'  p2        in varchar2 default null ,',
'  p3        in varchar2 default null ,',
'  p4        in varchar2 default null ,',
'  p5        in varchar2 default null ,',
'  p6        in varchar2 default null ,',
'  p7        in varchar2 default null ,',
'  p8        in varchar2 default null ,',
'  p9        in varchar2 default null )',
'is',
'begin',
'  sys.dbms_output.put_line(',
'    console.format(',
'      p_message => p_message ,',
'      p0        => p0        ,',
'      p1        => p1        ,',
'      p2        => p2        ,',
'      p3        => p3        ,',
'      p4        => p4        ,',
'      p5        => p5        ,',
'      p6        => p6        ,',
'      p7        => p7        ,',
'      p8        => p8        ,',
'      p9        => p9        ));',
'end printf;',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime ( p_start in timestamp ) return varchar2 is',
'  v_runtime t_32b;',
'begin',
'  v_runtime := to_char(localtimestamp - p_start);',
'  return substr(v_runtime, instr(v_runtime,'':'')-2, 15);',
'end runtime;',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime_seconds ( p_start in timestamp ) return number is',
'  v_runtime interval day to second;',
'begin',
'  v_runtime := localtimestamp - p_start;',
'  return',
'    extract(hour   from v_runtime) * 3600 +',
'    extract(minute from v_runtime) *   60 +',
'    extract(second from v_runtime)        ;',
'end runtime_seconds;',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime_milliseconds ( p_start in timestamp ) return number is',
'begin',
'  return runtime_seconds(p_start) * 1000;',
'end runtime_milliseconds;',
'',
'--------------------------------------------------------------------------------',
'',
'function level_name (p_level in integer) return varchar2 deterministic is',
'begin',
'  return case p_level',
'    when 1 then ''error''',
'    when 2 then ''warning''',
'    when 3 then ''info''',
'    when 4 then ''debug''',
'    when 5 then ''trace''',
'    else null',
'  end;',
'end level_name;',
'',
'---------------------------------------------------------------------'))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'-----------',
'',
'function scope return varchar2 is',
'  v_return     t_32kb;',
'  v_subprogram t_32kb;',
'begin',
'  if sys.utl_call_stack.dynamic_depth > 0 then',
'    --ignore 1, is always this function (scope) itself',
'    for i in 2 .. sys.utl_call_stack.dynamic_depth',
'    loop',
'      v_subprogram := sys.utl_call_stack.concatenate_subprogram( sys.utl_call_stack.subprogram(i) );',
'      --exclude console package from the scope',
'      if instr ( upper(v_subprogram), ''CONSOLE.'' ) = 0 then',
'        v_return := v_return',
'          || case when sys.utl_call_stack.owner(i) is not null then sys.utl_call_stack.owner(i) || ''.'' end',
'          || v_subprogram',
'          || case when sys.utl_call_stack.unit_line(i) is not null then '', line '' || sys.utl_call_stack.unit_line(i) end;',
'      end if;',
'      exit when v_return is not null;',
'    end loop;',
'  end if;',
'  return v_return;',
'end scope;',
'',
'--------------------------------------------------------------------------------',
'',
'function call_stack return varchar2',
'is',
'  v_return     t_32kb;',
'  v_subprogram t_32kb;',
'begin',
'',
'  if g_saved_stack.count > 0 then',
'    v_return := v_return || ''#### Saved Error Stack'' || c_lflf;',
'    for i in 1 .. g_saved_stack.count',
'    loop',
'      v_return := v_return || ''- '' || g_saved_stack (i) || c_lf;',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  if sys.utl_call_stack.dynamic_depth > 0 then',
'    v_return := v_return || ''#### Call Stack'' || c_lflf;',
'    --ignore 1, is always this function (call_stack) itself',
'    for i in 2 .. sys.utl_call_stack.dynamic_depth',
'    loop',
'      v_subprogram := sys.utl_call_stack.concatenate_subprogram ( sys.utl_call_stack.subprogram(i) );',
'      --exclude console package from the call stack',
'      if instr( upper(v_subprogram), ''CONSOLE.'' ) = 0 then',
'        v_return := v_return',
'          || ''- ''',
'          || case when sys.utl_call_stack.owner(i) is not null then sys.utl_call_stack.owner(i) || ''.'' end',
'          || v_subprogram',
'          || case when sys.utl_call_stack.unit_line(i) is not null then '', line '' || sys.utl_call_stack.unit_line(i) end',
'          || c_lf;',
'      end if;',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  if sys.utl_call_stack.error_depth > 0 then',
'    v_return := v_return || ''#### Error Stack'' || c_lflf;',
'    for i in 1 .. sys.utl_call_stack.error_depth',
'    loop',
'      v_return := v_return',
'        || ''- ORA-''',
'        || trim(to_char(sys.utl_call_stack.error_number(i), ''00009'')) || '' ''',
'        || utl_replace_linebreaks(sys.utl_call_stack.error_msg(i)) || c_lf;',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  if sys.utl_call_stack.backtrace_depth > 0 then',
'    v_return := v_return || ''#### Error Backtrace'' || c_lflf;',
'    for i in 1 .. sys.utl_call_stack.backtrace_depth',
'    loop',
'      v_return := v_return',
'        || ''- ''',
'        || coalesce( sys.utl_call_stack.backtrace_unit(i), ''__anonymous_block'' )',
'        || '', line '' || sys.utl_call_stack.backtrace_line(i) || c_lf;',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  return v_return || chr(10);',
'end call_stack;',
'',
'--------------------------------------------------------------------------------',
'',
'function apex_env return clob',
'is',
'  v_clob        clob;',
'  v_cache       t_32kb;',
'  v_value       t_32kb;',
'  v_app_id      t_int;',
'  v_app_page_id t_int;',
'  v_app_session t_int;',
'  --',
'begin',
'  $if not $$apex_installed $then',
'  null;',
'  $else',
'',
'  --https://jeffkemponoracle.com/2015/11/apex-5-application-context/',
'  --https://joelkallman.blogspot.com/2016/09/correlating-apex-sessions-to-database.html',
'  --sys_context(''APEX$SESSION'',''APP_USER'')',
'  --sys_context(''APEX$SESSION'',''WORKSPACE_ID'')',
'  v_app_id      :=           v(                 ''APP_ID''      );',
'  v_app_page_id :=           v(                 ''APP_PAGE_ID'' );',
'  v_app_session := sys_context( ''APEX$SESSION'', ''APP_SESSION'' );',
'',
'  clob_append(v_clob, v_cache, ''#### APEX Environment'' || c_lflf);',
'',
'  clob_append(v_clob, v_cache,',
'    ''##### Application Items'' ||',
'    case when v_app_id is not null then '' - APP_ID '' || v_app_id end ||',
'    c_lflf || to_md_tab_header(''Item Name''));',
'  for i in (',
'    select item_name',
'      from apex_application_items',
'    where application_id = v_app_id )',
'  loop',
'    v_value := v(i.item_name);',
'    clob_append(v_clob, v_cache, to_md_tab_data(i.item_name, v_value));',
'  end loop;',
'  clob_append(v_clob, v_cache, c_lf);',
'',
'  --Only page items from current page when level < debug, otherwise all page items.',
'  clob_append(v_clob, v_cache,',
'    ''##### Page Items'' ||',
'    case when g_conf_level < c_level_debug and v_app_page_id is not null then '' - APP_PAGE_ID '' || v_app_page_id end ||',
'    c_lflf || to_md_tab_header(''Item Name''));',
'  for i in (',
'    select item_name',
'      from apex_application_page_items',
'    where application_id = v_app_id',
'      and page_id        = case when (select console.my_log_level from dual) >= (select console.level_debug from dual)',
'                              then page_id',
'                              else v_app_page_id',
'                            end )',
'  loop',
'    v_value := v(i.item_name);',
'    clob_append(v_clob, v_cache, to_md_tab_data(i.item_name, v_value));',
'  end loop;',
'  clob_append(v_clob, v_cache, c_lf);',
'',
'  clob_flush_cache(v_clob, v_cache);',
'',
'  $end',
'  return v_clob;',
'end apex_env;',
'',
'--------------------------------------------------------------------------------',
'',
'function cgi_env return varchar2',
'is',
'  v_return t_32kb;',
'begin',
'  v_return := ''#### CGI Environment'' || c_lflf || to_md_tab_header;',
'  for i in 1 .. nvl(sys.owa.num_cgi_vars, 0) loop',
'    v_return := v_return ||',
'      to_md_tab_data(',
'        p_key   => sys.owa.cgi_var_name(i) ,',
'        p_value => sys.owa.cgi_var_val (i) );',
'  end loop;',
'  v_return := v_return || c_lf;',
'  return v_return;',
'exception',
'  when value_error then',
'    --> we simply return here what we already have and forget about the rest...',
'    return v_return;',
'end cgi_env;',
'',
'--------------------------------------------------------------------------------',
'',
'function console_env return varchar2',
'is',
'  v_return t_32kb;',
'  v_index  t_128b;',
'  --',
'  procedure append_row (p_key in varchar2, p_value in varchar2) is',
'  begin',
'    v_return := v_return || to_md_tab_data(p_key, p_value, p_show_null_values => true);',
'  end append_row;',
'  --',
'begin',
'  v_return := ''#### Console Environment'' || c_lflf || to_md_tab_header;',
'  append_row(''c_version'',                       to_char( c_version                              ));',
'  append_row(''localtimestamp'',                  to_char( localtimestamp,          c_date_format ));',
'  append_row(''sysdate'',                         to_char( sysdate,                 c_date_format ));',
'  append_row(''g_conf_check_sysdate'',            to_char( g_conf_check_sysdate,    c_date_format ));',
'  append_row(''g_conf_exit_sysdate'',             to_char( g_conf_exit_sysdate,     c_date_format ));',
'  append_row(''g_conf_client_identifier'',                 g_conf_client_identifier                );',
'  append_row(''g_conf_level'',                    to_char( g_conf_level                           ));',
'  append_row(''level_name(g_conf_level)'',     level_name( g_conf_level                           ));',
'  append_row(''g_conf_check_interval'',           to_char( g_conf_check_interval                  ));',
'  append_row(''g_conf_enable_ascii_art'',       to_string( g_conf_enable_ascii_art                ));',
'  append_row(''g_conf_call_stack'',             to_string( g_conf_call_stack                      ));',
'  append_row(''g_conf_user_env'',               to_string( g_conf_user_env                        ));',
'  append_row(''g_conf_apex_env'',               to_string( g_conf_apex_env                        ));',
'  append_row(''g_conf_cgi_env'',                to_string( g_conf_cgi_env                         ));',
'  append_row(''g_conf_console_env'',            to_string( g_conf_console_env                     ));',
'  append_row(''g_counters.count'',                to_char( g_counters.count                       ));',
'  append_row(''g_timers.count'',                  to_char( g_timers.count                         ));',
'  append_row(''g_saved_stack.count'',             to_char( g_saved_stack.count                    ));',
'  append_row(''g_prev_error_msg'', utl_replace_linebreaks( g_prev_error_msg                       ));',
'',
'  v_return := v_return || c_lf;',
'',
'  if g_timers.count > 0 then',
'    v_return := v_return || ''##### Running Timers'' || c_lflf || to_md_tab_header(''Label'', ''Start Time (localtimestamp)'');',
'    v_index := g_timers.first;',
'    loop',
'      exit when v_index is null;',
'      append_row(v_index, to_char(g_timers(v_index), c_timestamp_format));',
'      v_index := g_timers.next(v_index);',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  if g_counters.count > 0 then',
'    v_return := v_return || ''##### Running Counters'' || c_lflf || to_md_tab_header(''Label'', ''Current Count'');',
'    v_index := g_counters.first;',
'    loop',
'      exit when v_index is null;',
'      append_row(v_index, to_char(g_counters(v_index)));',
'      v_index := g_counters.next(v_index);',
'    end loop;',
'    v_return := v_return || c_lf;',
'  end if;',
'',
'  return v_return;',
'exception',
'  when value_error then',
'    --> we simply return here what we already have and forget about the rest...',
'    return v_return;',
'end console_env;',
'',
'--------------------------------------------------------------------------------',
'',
'function user_env return varchar2',
'is',
'  v_return t_32kb;',
'  invalid_user_env_key exception;',
'  pragma exception_init(invalid_user_env_key, -2003);',
'  --',
'  procedure append_row (p_key in varchar2) is',
'  begin',
'    v_return := v_return || to_md_tab_data(',
'      p_key              => p_key                         ,',
'      p_value            => sys_context(''USERENV'', p_key) ,',
'      p_value_max_length => 4000); --> we do this for the CURRENT_SQL attribute, which can have up to 4000 bytes',
'  exception',
'    when invalid_user_env_key then',
'      null;',
'  end append_row;',
'  --',
'begin',
'  v_return := ''#### User Environment'' || c_lflf || to_md_tab_header;',
'  --',
'  append_row(''ACTION'');',
'  append_row(''AUDITED_CURSORID'');',
'  append_row(''AUTHENTICATED_IDENTITY'');',
'  append_row(''AUTHENTICATION_DATA'');',
'  append_row(''AUTHENTICATION_METHOD'');',
'  append_row(''BG_JOB_ID'');',
'  append_row(''CDB_DOMAIN'');',
'  append_row(''CDB_NAME'');',
'  append_row(''CLIENT_IDENTIFIER'');',
'  append_row(''CLIENT_INFO'');',
'  append_row(''CLIENT_PROGRAM_NAME'');',
'  append_row(''CON_ID'');',
'  append_row(''CON_NAME'');',
'  append_row(''CURRENT_BIND'');',
'  append_row(''CURRENT_EDITION_ID'');',
'  append_row(''CURRENT_EDITION_NAME'');',
'  append_row(''CURRENT_SCHEMA'');',
'  append_row(''CURRENT_SCHEMAID'');',
'  append_row(''CURRENT_SQL_LENGTH'');',
'  append_row(''CURRENT_SQL'');',
'  append_row(''CURRENT_USER'');',
'  append_row(''CURRENT_USERID'');',
'  append_row(''DATABASE_ROLE'');',
'  append_row(''DB_DOMAIN'');',
'  append_row(''DB_NAME'');',
'  append_row(''DB_SUPPLEMENTAL_LOG_LEVEL'');',
'  append_row(''DB_UNIQUE_NAME'');',
'  append_row(''DBLINK_INFO'');',
'  append_row(''ENTERPRISE_IDENTITY'');',
'  append_row(''ENTRYID'');',
'  append_row(''FG_JOB_ID'');',
'  append_row(''GLOBAL_CONTEXT_MEMORY'');',
'  append_row(''GLOBAL_UID'');',
'  append_row(''HOST'');',
'  append_row(''IDENTIFICATION_TYPE'');',
'  append_row(''INSTANCE_NAME'');',
'  append_row(''INSTANCE'');',
'  append_row(''IP_ADDRESS'');',
'  append_row(''IS_APPLICATION_PDB'');',
'  append_row(''IS_APPLICATION_ROOT'');',
'  append_row(''IS_APPLY_SERVER'');',
'  append_row(''IS_DG_ROLLING_UPGRADE'');',
'  append_row(''ISDBA'');',
'  append_row(''LANG'');',
'  append_row(''LANGUAGE'');',
'  append_row(''LDAP_SERVER_TYPE'');',
'  append_row(''MODULE'');',
'  append_row(''NETWORK_PROTOCOL'');',
'  append_row(''NLS_CALENDAR'');',
'  append_row(''NLS_CURRENCY'');',
'  append_row(''NLS_DATE_FORMAT'');',
'  append_row(''NLS_DATE_LANGUAGE'');',
'  append_row(''NLS_SORT'');',
'  append_row(''NLS_TERRITORY'');',
'  append_row(''ORACLE_HOME'');',
'  append_row(''OS_USER'');',
'  append_row(''PLATFORM_SLASH'');',
'  append_row(''POLICY_INVOKER'');',
'  append_row(''PROXY_ENTERPRISE_IDENTITY'');',
'  append_row(''PROXY_USER'');',
'  append_row(''PROXY_USERID'');',
'  append_row(''SCHEDULER_JOB'');',
'  append_row(''SERVER_HOST'');',
'  append_row(''SERVICE_NAME'');',
'  append_row(''SESSION_DEFAULT_COLLATION'');',
'  append_row(''SESSION_EDITION_ID'');',
'  append_row(''SESSION_EDITION_NAME'');',
'  append_row(''SESSION_USER'');',
'  append_row(''SESSION_USERID'');',
'  append_row(''SESSIONID'');',
'  append_row(''SID'');',
'  append_row(''STATEMENTID'');',
'  append_row(''TERMINAL'');',
'  append_row(''UNIFIED_AUDIT_SESSIONID'');',
'  --',
'  v_return := v_return || c_lf ||',
'    ''We tried to show [documented attributes from Oracle 19c](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SYS_CONTEXT.html#GUID-B9934A5D-D97B-4E51-B01B-80C76A5BD086).'' || c_lf ||',
'    ''On older databases not existing attributes or values which are null are simply omitted.'' || c_lflf;',
'  return v_return;',
'exception',
'  when value_error then',
'    --> we simply return here what we already have and forget about the rest...',
'    return v_return;',
'end user_env;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure clob_append (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 ,',
'  p_text  in            varchar2 )',
'is',
'begin',
'  p_cache := p_cache || p_text;',
'exception',
'  when value_error then',
'    if p_clob is null then',
'      p_clob := p_cache;',
'    else',
'      sys.dbms_lob.writeappend(p_clob, length(p_cache), p_cache);',
'    end if;',
'    p_cache := p_text;',
'end clob_append;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure clob_append (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 ,',
'  p_text  in            clob     )',
'is',
'begin',
'  if p_text is not null then',
'    clob_flush_cache(p_clob, p_cache);',
'    if p_clob is null then',
'      p_clob := p_text;',
'    else',
'      sys.dbms_lob.writeappend(p_clob, length(p_text), p_text);',
'    end if;',
'  end if;',
'end clob_append;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure clob_flush_cache (',
'  p_clob  in out nocopy clob     ,',
'  p_cache in out nocopy varchar2 )',
'is',
'begin',
'  if p_cache is not null then',
'    if p_clob is null then',
'      p_clob := p_cache;',
'    else',
'      sys.dbms_lob.writeappend(p_clob, length(p_cache), p_cache);',
'    end if;',
'    p_cache := null;',
'  end if;',
'end clob_flush_cache;',
'',
'--------------------------------------------------------------------------------',
'',
'function status return t_attribute_value_tab pipelined is',
'  v_row t_attribute_value_row;',
'begin',
'  if g_conf_check_sysdate < sysdate then',
'    utl_set_session_conf;',
'  end if;',
'',
'  v_row.attribute := ''c_version''               ; v_row.value :=                to_char( c_version                              ); pipe row(v_row);',
'  v_row.attribute := ''localtimestamp''          ; v_row.value :=                to_char( localtimestamp,          c_date_format ); pipe row(v_row);',
'  v_row.attribute := ''sysdate''                 ; v_row.value :=                to_char( sysdate,                 c_date_format ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_check_sysdate''    ; v_row.value :=                to_char( g_conf_check_sysdate,    c_date_format ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_exit_sysdate''     ; v_row.value :=                to_char( g_conf_exit_sysdate,     c_date_format ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_client_identifier''; v_row.value :=                         g_conf_client_identifier                ; pipe row(v_row);',
'  v_row.attribute := ''g_conf_level''            ; v_row.value :=                to_char( g_conf_level                           ); pipe row(v_row);',
'  v_row.attribute := ''level_name(g_conf_level)''; v_row.value :=             level_name( g_conf_level                           ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_check_interval''   ; v_row.value :=                to_char( g_conf_check_interval                  ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_enable_ascii_art'' ; v_row.value :=              to_string( g_conf_enable_ascii_art                ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_call_stack''       ; v_row.value :=              to_string( g_conf_call_stack                      ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_user_env''         ; v_row.value :=              to_string( g_conf_user_env                        ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_apex_env''         ; v_row.value :=              to_string( g_conf_apex_env                        ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_cgi_env''          ; v_row.value :=              to_string( g_conf_cgi_env                         ); pipe row(v_row);',
'  v_row.attribute := ''g_conf_console_env''      ; v_row.value :=              to_string( g_conf_console_env                     ); pipe row(v_row);',
'  v_row.attribute := ''g_counters.count''        ; v_row.value :=                to_char( g_counters.count                       ); pipe row(v_row);',
'  v_row.attribute := ''g_timers.count''          ; v_row.value :=                to_char( g_timers.count                         ); pipe row(v_row);',
'  v_row.attribute := ''g_saved_stack.count''     ; v_row.value :=                to_char( g_saved_stack.count                    ); pipe row(v_row);',
'  v_row.attribute := ''g_prev_error_msg''        ; v_row.value := utl_replace_linebreaks( g_prev_error_msg                       ); pipe row(v_row);',
'end status;',
'',
'--------------------------------------------------------------------------------',
'',
'function conf',
'return t_attribute_value_tab pipelined is',
'  v_row  t_attribute_value_row;',
'  v_conf console_conf%rowtype;',
'begin',
'  v_conf := utl_get_conf;',
'  v_row.attribute := ''conf_sysdate''    ; v_row.value := to_char( v_conf.conf_sysdate, c_date_format ); pipe row(v_row);',
'  v_row.attribute := ''conf_user''       ; v_row.value :=          v_conf.conf_user                    ; pipe row(v_row);',
'  v_row.attribute := ''level_id''        ; v_row.value := to_char( v_conf.level_id                    ); pipe row(v_row);',
'  v_row.attribute := ''level_name''      ; v_row.value :=          v_conf.level_name                   ; pipe row(v_row);',
'  v_row.attribute := ''check_interval''  ; v_row.value := to_char( v_conf.check_interval              ); pipe row(v_row);',
'  v_row.attribute := ''enable_ascii_art''; v_row.value :=          v_conf.enable_ascii_art             ; pipe row(v_row);',
'  v_row.attribute := ''client_prefs''    ; v_row.value :=          v_conf.client_prefs                 ; pipe row(v_row);',
'end conf;',
'',
'--------------------------------------------------------------------------------',
'',
'function client_prefs',
'return t_client_prefs_tab pipelined is',
'  v_list  t_client_prefs_tab_i;',
'begin',
'  v_list := utl_get_client_prefs_tab;',
'  for i in 1 .. v_list.count loop',
'    pipe row(v_list(i));',
'  end loop;',
'end client_prefs;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge (',
'  p_min_level in integer default c_level_info,',
'  p_min_days  in number  default 30 )',
'is',
'  pragma autonomous_transaction;',
'begin',
'  assert (',
'    p_min_level in (1,2,3,4,5),',
'    ''Minimum level must be 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace).'');',
'  assert (',
'    c_console_owner = sys_context(''USERENV'',''SESSION_USER''),',
'    ''Only the owner of the package console is allowed to purge log entries.'');',
'  delete from console_logs',
'    where level_id >= p_min_level',
'      and permanent = ''N''',
'      and log_time <= localtimestamp - p_min_days;',
'  commit;',
'end purge;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_all is',
'begin',
'  purge(',
'    p_min_level => 1,',
'    p_min_days  => -1 -- to be sure we delete everything (localtimestamp - -1 is the same time tomorrow)',
'  );',
'end purge_all;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_job_create (',
'  p_repeat_interval in varchar2 default ''FREQ=DAILY;BYHOUR=1;'' ,',
'  p_min_level       in integer  default c_level_info           ,',
'  p_min_days        in number   default 30                     )',
'is',
'begin',
'  execute immediate replace(replace(replace(replace(q''[',
'    begin',
'      for i in (',
'        select ''#CONSOLE_JOB_NAME#'' as job_name from dual',
'        minus',
'        select job_name from user_scheduler_jobs )',
'      loop',
'        sys.dbms_scheduler.create_job(',
'          job_name        => i.job_name                                                                   ,',
'          job_type        => ''PLSQL_BLOCK''                                                                ,',
'          job_action      => ''begin console.purge(p_min_level=>#MIN_LEVEL#,p_min_days=>#MIN_DAYS#); end;'' ,',
'          start_date      => sysdate                                                                      ,',
'          repeat_interval => ''#REPEAT_INTERVAL#''                                                          ,',
'          enabled         => true                                                                         ,',
'          auto_drop       => false                                                                        ,',
'          comments        => ''Purge CONSOLE log entries.''                                                 );',
'      end loop;',
'    end;',
'  ]'',',
'  ''#CONSOLE_JOB_NAME#'', c_console_job_name ),',
'  ''#REPEAT_INTERVAL#'' , p_repeat_interval  ),',
'  ''#MIN_LEVEL#''       , p_min_level        ),',
'  ''#MIN_DAYS#''        , p_min_days         );',
'end purge_job_create;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_job_drop is',
'begin',
'  execute immediate replace(q''[',
'    begin',
'      for i in (',
'        select job_name',
'          from user_scheduler_jobs',
'         where job_name = ''#CONSOLE_JOB_NAME#'' )',
'      loop',
'        sys.dbms_scheduler.drop_job(',
'          job_name => i.job_name ,',
'          force    => true       );',
'      end loop;',
'    end;',
'  ]'',',
'  ''#CONSOLE_JOB_NAME#'', c_console_job_name );',
'end purge_job_drop;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_job_enable is',
'begin',
'  execute immediate replace(q''[',
'    begin',
'      for i in (',
'        select job_name',
'          from user_scheduler_jobs',
'         where job_name = ''#CONSOLE_JOB_NAME#'' )',
'      loop',
'        sys.dbms_scheduler.enable(name => i.job_name);',
'      end loop;',
'    end;',
'  ]'',',
'  ''#CONSOLE_JOB_NAME#'', c_console_job_name );',
'end purge_job_enable;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_job_disable is',
'begin',
'  execute immediate replace(q''[',
'    begin',
'      for i in (',
'        select job_name',
'          from user_scheduler_jobs',
'         where job_name = ''#CONSOLE_JOB_NAME#'' )',
'      loop',
'        sys.dbms_scheduler.disable(',
'          name  => i.job_name ,',
'          force => true       );',
'      end loop;',
'    end;',
'  ]'',',
'  ''#CONSOLE_JOB_NAME#'', c_console_job_name );',
'end purge_job_disable;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure purge_job_run is',
'begin',
'  execute immediate replace(q''[',
'    begin',
'      for i in (',
'        select job_name',
'          from user_scheduler_jobs',
'         where job_name = ''#CONSOLE_JOB_NAME#'' )',
'      loop',
'        sys.dbms_scheduler.run_job(job_name => i.job_name);',
'      end loop;',
'    end;',
'  ]'',',
'  ''#CONSOLE_JOB_NAME#'', c_console_job_name );',
'end purge_job_run;',
'',
'',
'--------------------------------------------------------------------------------',
'-- PRIVATE HELPER METHODS',
'--------------------------------------------------------------------------------',
'',
'function utl_escape_md_tab_text (p_text in varchar2) return varchar2 is',
'begin',
'  return replace(replace(replace(replace(p_text,',
'    c_crlf,   '' ''),',
'    c_lf,     '' ''),',
'    c_cr,     '' ''),',
'    ''|'', ''&#124;'');',
'end utl_escape_md_tab_text;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_last_error return varchar2 is',
'  v_return t_32kb;',
'begin',
'  if sys.utl_call_stack.error_depth > 0 and sys.utl_call_stack.backtrace_depth > 0 then',
'    if sys.utl_call_stack.error_number(1) != 6512 and sys.utl_call_stack.error_msg(1) != coalesce(g_prev_error_msg, ''null'') then',
'      --Get the last backtrace line number and also the error message',
'      v_return := '' (line '' || to_char(sys.utl_call_stack.backtrace_line(sys.utl_call_stack.backtrace_depth)) ||',
'        '', ORA-'' || trim(to_char(sys.utl_call_stack.error_number(1), ''00009'')) || '' '' ||',
'        utl_replace_linebreaks(sys.utl_call_stack.error_msg(1)) || '')'';',
'      --Set the new error message as the last error message.',
'      g_prev_error_msg := sys.utl_call_stack.error_msg(1);',
'    else',
'      --Get only the last backtrace line number',
'      v_return := '' (line '' || to_char(sys.utl_call_stack.backtrace_line(sys.utl_call_stack.backtrace_depth)) || '')'';',
'    end if;',
'  end if;',
'',
'  return v_return;',
'end utl_last_error;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_logging_is_enabled (',
'  p_level in integer )',
'return boolean is',
'begin',
'  if g_conf_check_sysdate < sysdate then',
'    utl_set_session_conf;',
'  end if;',
'  return g_conf_level >= p_level or sqlcode != 0;',
'end utl_logging_is_enabled;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_normalize_label (p_label in varchar2) return varchar2 is',
'begin',
'  return coalesce(substr(p_label, 1, 128), c_default_label);',
'end utl_normalize_label;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_replace_linebreaks (',
'  p_text         in varchar2             ,',
'  p_replace_with in varchar2 default '' '' )',
'return varchar2 is',
'begin',
'  return replace(replace(replace(p_text,',
'    c_crlf, p_replace_with),',
'    c_lf,   p_replace_with),',
'    c_cr,   p_replace_with);',
'end utl_replace_linebreaks;',
'',
'--------------------------------------------------------------------------------',
'',
'/* HOW TO CHECK THE RESULT CACHE',
'select id, name, cache_id, type, status, invalidations, scan_count',
'  from v$result_cache_objects',
' where name like ''%CONSOLE%''',
'   and status != ''Invalid'';',
'*/',
'function utl_get_conf',
'return console_conf%rowtype result_cache is',
'  v_row console_conf%rowtype;',
'begin',
'  select *',
'    into v_row',
'    from console_conf',
'   where conf_id = c_conf_id;',
'  return v_row;',
'exception',
'  when no_data_found then',
'    -- set defaults',
'    v_row.conf_id          := c_conf_id;',
'    v_row.conf_sysdate     := sysdate;',
'    v_row.conf_user        := ''autodefault'';',
'    v_row.level_id         := c_level_error;',
'    v_row.level_name       := level_name(c_level_error);',
'    v_row.check_interval   := c_check_interval_default;',
'    v_row.enable_ascii_art := to_string(c_enable_ascii_art);',
'    return v_row;',
'end utl_get_conf;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure utl_set_conf (',
'  p_conf in console_conf%rowtype )',
'is',
'  pragma autonomous_transaction;',
'begin',
'  update console_conf set row = p_conf where conf_id = c_conf_id;',
'  if sql%rowcount = 0 then',
'    insert into console_conf values p_conf;',
'  end if;',
'  commit;',
'end utl_set_conf;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure utl_set_client_prefs (',
'  p_prefs in varchar2 )',
'is',
'  pragma autonomous_transaction;',
'  procedure update_client_prefs is',
'  begin',
'    update console_conf set client_prefs = p_prefs where conf_id = c_conf_id;',
'  end;',
'begin',
'  assert(lengthb(p_prefs) <= 4000, ''Sorry, we cannot save your client preferencs - seems you have too many session in debug mode.'');',
'  update_client_prefs;',
'  if sql%rowcount = 0 then',
'    utl_set_conf(utl_get_conf); -- utl_get_conf handles not existing conf with default values',
'    update_client_prefs;',
'  end if;',
'  commit;',
'end utl_set_client_prefs;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_get_client_prefs (',
'  p_all_prefs_csv     in varchar2 ,',
'  p_client_identifier in varchar2 )',
'return t_client_prefs_row is',
'  v_all_prefs_csv   t_32kb := p_all_prefs_csv;',
'  v_csv             t_32kb;',
'  v_prefs           t_client_prefs_row;',
'  v_boolean_options t_int;',
'  v_start           t_int;',
'  v_stop            t_int;',
'begin',
'  if v_all_prefs_csv is not null then',
'    v_all_prefs_csv := replace(v_all_prefs_csv, c_cr, c_lf);',
'    v_start := instr(v_all_prefs_csv, p_client_identifier||'','');',
'    v_stop  := instr(v_all_prefs_csv, c_lf, v_start);',
'    v_csv   := substr(v_all_prefs_csv, v_start, v_stop - v_start);',
'    --too slow: also see tests/performance.sql',
'    --v_csv   := regexp_substr(p_all_prefs_csv, ''^''||p_client_identifier||'',.*$'', 1, 1, ''im'');',
'    if v_csv is not null then',
'      v_prefs.exit_sysdate := utl_csv_get_exit_sysdate(v_csv);',
'      -- For performance reasons we will proceed the other columns only, if needed.',
'      -- This function is called every time a session is initializing the package console.',
'      if v_prefs.exit_sysdate >= sysdate then',
'        --v_prefs.client_identifier := utl_csv_get_client_identifier ( v_csv );',
'        v_boolean_options         := utl_csv_get_boolean_options   ( v_csv );',
'        v_prefs.level_id          := utl_csv_get_level             ( v_csv );',
'        v_prefs.check_interval    := utl_csv_get_check_interval    ( v_csv );',
'        v_prefs.call_stack        := to_string ( bitand ( v_boolean_options, c_call_stack  ) = c_call_stack  );',
'        v_prefs.user_env          := to_string ( bitand ( v_boolean_options, c_user_env    ) = c_user_env    );',
'        v_prefs.apex_env          := to_string ( bitand ( v_boolean_options, c_apex_env    ) = c_apex_env    );',
'        v_prefs.cgi_env           := to_string ( bitand ( v_boolean_options, c_cgi_env    '))
);
wwv_flow_imp_shared.append_to_install_script(
 p_id=>wwv_flow_imp.id(6090467230035747463)
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
' ) = c_cgi_env     );',
'        v_prefs.console_env       := to_string ( bitand ( v_boolean_options, c_console_env ) = c_console_env );',
'        v_prefs.level_name        := level_name ( v_prefs.level_id );',
'      end if;',
'    end if;',
'  end if;',
'  return v_prefs;',
'end utl_get_client_prefs;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_get_client_prefs_tab return t_client_prefs_tab_i is',
'  v_tab   t_client_prefs_tab_i;',
'  v_conf  console_conf%rowtype;',
'  v_prefs t_32kb;',
'  v_pos   t_int := 1;',
'  v_len   t_int;',
'  v_lf    t_int;',
'begin',
'  v_conf := utl_get_conf;',
'  v_prefs := replace(replace(replace(replace(v_conf.client_prefs,',
'    c_crlf, c_lf),',
'    c_cr  , c_lf),',
'    c_lflf, c_lf),',
'    c_lflf, c_lf);',
'  v_len := length(v_prefs);',
'  loop',
'    v_lf := nvl(instr(v_prefs, c_lf, v_pos), 0);',
'    exit when v_lf = 0;',
'    if v_lf > v_pos then',
'      v_tab(v_tab.count + 1) := utl_csv_to_client_prefs(substr(v_prefs, v_pos, v_lf - v_pos));',
'    end if;',
'    v_pos := v_lf + 1;',
'  end loop;',
'  return v_tab;',
'end utl_get_client_prefs_tab;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_get_clean_client_prefs_csv (',
'  p_client_identifier_to_remove in varchar2           default null ,',
'  p_client_prefs_to_append      in t_client_prefs_row default null )',
'return varchar2 is',
'  v_prefs t_32kb;',
'  v_tab   t_client_prefs_tab_i;',
'begin',
'  v_tab := utl_get_client_prefs_tab;',
'  for i in 1 .. v_tab.count loop',
'    --filter out invalid client pefs',
'    if  v_tab(i).client_identifier is not null',
'    and v_tab(i).level_id is not null',
'    and v_tab(i).call_stack is not null',
'    and v_tab(i).user_env is not null',
'    and v_tab(i).cgi_env is not null',
'    and v_tab(i).user_env is not null',
'    and v_tab(i).console_env is not null',
'    and v_tab(i).check_interval is not null',
'    and v_tab(i).exit_sysdate is not null',
'    and v_tab(i).exit_sysdate      >= sysdate',
'    and v_tab(i).client_identifier != nvl(p_client_identifier_to_remove, ''NULL_VALUE_DETECTED'')',
'    then',
'      v_prefs := v_prefs || utl_client_prefs_to_csv(v_tab(i));',
'    end if;',
'  end loop;',
'  if p_client_prefs_to_append.client_identifier is not null then',
'    v_prefs := v_prefs || utl_client_prefs_to_csv(p_client_prefs_to_append);',
'  end if;',
'  return v_prefs;',
'end utl_get_clean_client_prefs_csv;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_remove_stale_client_prefs (',
'  p_all_prefs_csv     in varchar2 ,',
'  p_client_identifier in varchar2 )',
'return varchar2 is',
'  v_return t_32kb := p_all_prefs_csv;',
'begin',
'  return v_return;',
'end utl_remove_stale_client_prefs;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_get_client_identifier (',
'  p_csv in varchar2 )',
'return varchar2 is',
'  v_stop t_int;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_stop := instr(p_csv, '','', -1, 4) - 1;',
'  return substrb(substr(p_csv, 1, v_stop), 1, 64);',
'end;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_get_exit_sysdate (',
'  p_csv in varchar2 )',
'return date is',
'  v_return date;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_return := nvl(to_date(',
'    substr(',
'      p_csv,',
'      instr(p_csv, '','', -1, 1) + 1 -- first comma from the end + 1',
'    ) default null on conversion error,',
'    c_date_format_short',
'  ), sysdate - 1);',
'  return v_return;',
'end utl_csv_get_exit_sysdate;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_get_check_interval (',
'  p_csv in varchar2 )',
'return integer is',
'  v_return t_int;',
'  v_start  t_int;',
'  v_stop   t_int;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_start := instr(p_csv, '','', -1, 2) + 1;',
'  v_stop  := instr(p_csv, '','', -1, 1);',
'  v_return := to_number(',
'    substr(',
'      p_csv,',
'      v_start,',
'      v_stop - v_start',
'    ) default c_check_interval_default on conversion error',
'  );',
'  return case when v_return not between c_check_interval_min and c_check_interval_max then c_check_interval_default else v_return end;',
'end utl_csv_get_check_interval;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_get_boolean_options (',
'  p_csv in varchar2 )',
'return integer is',
'  v_start t_int;',
'  v_stop  t_int;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_start := instr(p_csv, '','', -1, 3) + 1;',
'  v_stop  := instr(p_csv, '','', -1, 2);',
'  return to_number (',
'    substr(',
'      p_csv,',
'      v_start,',
'      v_stop - v_start',
'    ) default 0 on conversion error',
'  );',
'end utl_csv_get_boolean_options;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_get_level (',
'  p_csv in varchar2 )',
'return integer is',
'  v_return t_int;',
'  v_start  t_int;',
'  v_stop   t_int;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_start := instr(p_csv, '','', -1, 4) + 1;',
'  v_stop  := instr(p_csv, '','', -1, 3);',
'  v_return := to_number(',
'    substr(',
'      p_csv,',
'      v_start,',
'      v_stop - v_start',
'    ) default c_level_error on conversion error',
'  );',
'  return case when v_return not between c_level_error and c_level_trace then c_level_error else v_return end;',
'end utl_csv_get_level;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_csv_to_client_prefs (',
'  p_csv in varchar2)',
'return t_client_prefs_row is',
'  v_return          t_client_prefs_row;',
'  v_boolean_options t_int;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  v_boolean_options          := utl_csv_get_boolean_options   ( p_csv );',
'  v_return.exit_sysdate      := utl_csv_get_exit_sysdate      ( p_csv );',
'  v_return.client_identifier := utl_csv_get_client_identifier ( p_csv );',
'  v_return.level_id          := utl_csv_get_level             ( p_csv );',
'  v_return.check_interval    := utl_csv_get_check_interval    ( p_csv );',
'  v_return.call_stack        := to_string ( bitand ( v_boolean_options, c_call_stack  ) = c_call_stack  );',
'  v_return.user_env          := to_string ( bitand ( v_boolean_options, c_user_env    ) = c_user_env    );',
'  v_return.apex_env          := to_string ( bitand ( v_boolean_options, c_apex_env    ) = c_apex_env    );',
'  v_return.cgi_env           := to_string ( bitand ( v_boolean_options, c_cgi_env     ) = c_cgi_env     );',
'  v_return.console_env       := to_string ( bitand ( v_boolean_options, c_console_env ) = c_console_env );',
'  v_return.level_name        := level_name ( v_return.level_id );',
'  return v_return;',
'end utl_csv_to_client_prefs;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_client_prefs_to_csv (',
'  p_client_prefs in t_client_prefs_row )',
'return varchar2 is',
'  v_return t_32kb;',
'begin',
'  --csv format: client_identifier,level,boolean_options,check_interval,exit_sysdate',
'  return',
'    p_client_prefs.client_identifier                                             || '','' ||',
'    to_char(p_client_prefs.level_id)                                             || '','' ||',
'    to_char(',
'      case when p_client_prefs.call_stack  = ''true'' then c_call_stack  else 0 end +',
'      case when p_client_prefs.user_env    = ''true'' then c_user_env    else 0 end +',
'      case when p_client_prefs.apex_env    = ''true'' then c_apex_env    else 0 end +',
'      case when p_client_prefs.cgi_env     = ''true'' then c_cgi_env     else 0 end +',
'      case when p_client_prefs.console_env = ''true'' then c_console_env else 0 end ) || '','' ||',
'    to_char(p_client_prefs.check_interval)                                       || '','' ||',
'    to_char(p_client_prefs.exit_sysdate, c_date_format_short)                    || c_lf;',
'end utl_client_prefs_to_csv;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure utl_set_client_identifier is',
'begin',
'  g_conf_client_identifier := sys_context(''USERENV'', ''CLIENT_IDENTIFIER'');',
'  if g_conf_client_identifier is null or g_conf_client_identifier = '':'' then',
'    g_conf_client_identifier := c_client_id_prefix || sys.dbms_session.unique_session_id;',
'    sys.dbms_session.set_identifier(g_conf_client_identifier);',
'  end if;',
'end utl_set_client_identifier;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure utl_set_session_conf is',
'  v_conf  console_conf%rowtype;',
'  v_prefs t_client_prefs_row;',
'begin',
'  v_conf  := utl_get_conf;',
'  v_prefs := utl_get_client_prefs(v_conf.client_prefs, g_conf_client_identifier);',
'',
'  --If we have no real exit sysdate, we set it to 24 hours.',
'  --Session conf will be re-evaluated at least every 10 seconds.',
'  g_conf_exit_sysdate     := coalesce ( v_prefs.exit_sysdate         , sysdate + 1           );',
'  g_conf_check_interval   := coalesce ( v_prefs.check_interval       , v_conf.check_interval );',
'  g_conf_level            := coalesce ( v_prefs.level_id             , v_conf.level_id       );',
'  --',
'  g_conf_call_stack       := coalesce ( to_bool(v_prefs.call_stack)  , false                 );',
'  g_conf_user_env         := coalesce ( to_bool(v_prefs.user_env)    , false                 );',
'  g_conf_apex_env         := coalesce ( to_bool(v_prefs.apex_env)    , false                 );',
'  g_conf_cgi_env          := coalesce ( to_bool(v_prefs.cgi_env)     , false                 );',
'  g_conf_console_env      := coalesce ( to_bool(v_prefs.console_env) , false                 );',
'  --',
'  g_conf_enable_ascii_art := to_bool(v_conf.enable_ascii_art);',
'  --',
'  g_conf_check_sysdate    := least(g_conf_exit_sysdate, sysdate + 1/24/60/60 * g_conf_check_interval);',
'',
'end utl_set_session_conf;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_create_log_entry (',
'  p_level           in integer                ,',
'  p_message         in clob     default null  ,',
'  p_permanent       in boolean  default false ,',
'  p_call_stack      in boolean  default false ,',
'  p_apex_env        in boolean  default false ,',
'  p_cgi_env         in boolean  default false ,',
'  p_console_env     in boolean  default false ,',
'  p_user_env        in boolean  default false ,',
'  p_user_agent      in varchar2 default null  ,',
'  p_user_scope      in varchar2 default null  ,',
'  p_user_error_code in integer  default null  ,',
'  p_user_call_stack in varchar2 default null  )',
'return console_logs.log_id%type',
'is',
'  pragma autonomous_transaction;',
'  v_row   console_logs%rowtype;',
'  v_cache t_32kb;',
'begin',
'  v_row.scope :=',
'    case',
'      when p_user_scope is not null then substrb(p_user_scope, 1, 256)',
'      else substrb(scope, 1, 256)',
'    end;',
'',
'  -- This is the very first (possible) assignment to the row.message variable,',
'  -- so we can do it without our clob_append method.',
'  v_row.message :=',
'    case',
'      when p_message is not null then p_message || c_lflf',
'      when sqlcode != 0 then sqlerrm || c_lflf',
'      else null',
'    end;',
'',
'  -- Add params, if any',
'  if g_params.count > 0 then',
'    clob_append(v_row.message, v_cache, ''#### Parameters'' || c_lflf || to_md_tab_header(''Parameter Name''));',
'    for i in 1 .. g_params.count loop',
'      clob_append(v_row.message, v_cache, to_md_tab_data(g_params(i).attribute, g_params(i).value, c_param_value_max_length));',
'    end loop;',
'    clob_append(v_row.message, v_cache, c_lf);',
'    g_params.delete;',
'',
'  end if;',
'',
'  v_row.error_code :=',
'    case',
'      when p_user_error_code is not null then p_user_error_code',
'      when sqlcode != 0 then sqlcode',
'      else null',
'    end;',
'',
'  if p_user_call_stack is not null then',
'    v_row.call_stack := substrb(p_user_call_stack, 1, 4000);',
'  elsif p_call_stack then',
'    --Save the last occured error (if any and if we called before',
'    --error_save_stack) before we going to log the callstack.',
'    if sqlcode != 0 and g_saved_stack.count > 0 then',
'      error_save_stack;',
'    end if;',
'    v_row.call_stack := substrb(call_stack, 1, 4000);',
'    if p_level = 1 then',
'      --We finally logged the saved stack, so we need to reset it.',
'      g_saved_stack.delete;',
'      g_prev_error_msg := null;',
'    end if;',
'  end if;',
'',
'  if p_apex_env or g_conf_apex_env then',
'    clob_append(v_row.message, v_cache, apex_env);',
'  end if;',
'',
'  if p_cgi_env or g_conf_cgi_env then',
'    clob_append(v_row.message, v_cache, cgi_env);',
'  end if;',
'',
'  if p_console_env or g_conf_console_env then',
'    clob_append(v_row.message, v_cache, console_env);',
'  end if;',
'',
'  if p_user_env or g_conf_user_env then',
'    clob_append(v_row.message, v_cache, user_env);',
'  end if;',
'',
'  clob_flush_cache(v_row.message, v_cache);',
'',
'  v_row.log_time          := localtimestamp;',
'  v_row.level_id          := p_level;',
'  v_row.level_name        := level_name(p_level);',
'  v_row.permanent         := to_yn(p_permanent);',
'  v_row.session_user      := substrb ( sys_context ( ''USERENV'', ''SESSION_USER''      ), 1, 32 );',
'  v_row.module            := substrb ( sys_context ( ''USERENV'', ''MODULE''            ), 1, 48 );',
'  v_row.action            := substrb ( sys_context ( ''USERENV'', ''ACTION''            ), 1, 32 );',
'  v_row.client_info       := substrb ( sys_context ( ''USERENV'', ''CLIENT_INFO''       ), 1, 64 );',
'  v_row.client_identifier := substrb ( sys_context ( ''USERENV'', ''CLIENT_IDENTIFIER'' ), 1, 64 );',
'  v_row.ip_address        := substrb ( sys_context ( ''USERENV'', ''IP_ADDRESS''        ), 1, 48 );',
'  v_row.host              := substrb ( sys_context ( ''USERENV'', ''HOST''              ), 1, 64 );',
'  v_row.os_user           := substrb ( sys_context ( ''USERENV'', ''OS_USER''           ), 1, 64 );',
'  v_row.os_user_agent     := substrb ( p_user_agent, 1, 200 );',
'',
'  insert into console_logs values v_row returning log_id into v_row.log_id;',
'  commit;',
'',
'  return v_row.log_id;',
'end utl_create_log_entry;',
'',
'--------------------------------------------------------------------------------',
'',
'--package inizialization',
'begin',
'  utl_set_client_identifier;',
'  utl_set_session_conf;',
'end console;',
'/',
'',
'declare',
'  v_count pls_integer;',
'begin',
'  select count(*)',
'    into v_count',
'    from user_errors',
'   where name = ''CONSOLE'';',
'  if v_count = 0 then',
'    begin',
'      -- without execute immediate this script will raise an error when the package console is not valid',
'      select count(*) into v_count from user_scheduler_jobs where job_name = ''CONSOLE_PURGE'';',
'      if v_count = 0 then',
'        dbms_output.put_line(''- Job CONSOLE_PURGE not found, run creation command with the defaults (purge entries of level info after 30 days)'');',
'        execute immediate ''begin console.purge_job_create; end;'';',
'      else',
'        dbms_output.put_line(''- Job CONSOLE_PURGE found, no action required'');',
'      end if;',
'    exception',
'      when others then',
'        dbms_output.put_line(''A T T E N T I O N  -  A N  E R R O R  O C C U R E D'');',
'        dbms_output.put_line(''- Unable to check/create the purge job. You can purge old log entries with the procedures console.purge and purge_all by yourself.'');',
'        dbms_output.put_line(''- You can also try to create the purge job by youself with this code: begin console.purge_job_create; end;'');',
'        dbms_output.put_line(''- The oracle error on check/create the purge job was: '' || sqlerrm);',
'    end;',
'  end if;',
'end;',
'/',
'',
'',
'-- check for errors in package console',
'declare',
'  v_count                   pls_integer;',
'begin',
'  select count(*)',
'    into v_count',
'    from user_errors',
'   where name = ''CONSOLE'';',
'  if v_count > 0 then',
'    dbms_output.put_line(''- Package CONSOLE has errors :-('');',
'  end if;',
'end;',
'/',
'',
'column "Name"      format a15',
'column "Line,Col"  format a10',
'column "Type"      format a10',
'column "Message"   format a80',
'',
'select name || case when type like ''%BODY'' then '' body'' end as "Name",',
'       line || '','' || position as "Line,Col",',
'       attribute               as "Type",',
'       text                    as "Message"',
'  from user_errors',
' where name = ''CONSOLE''',
' order by name, line, position;',
'',
'prompt',
'declare',
'  v_count           pls_integer;',
'  v_console_version varchar2(10 byte);',
'begin',
'  select count(*)',
'    into v_count',
'    from user_errors',
'   where name = ''CONSOLE'';',
'  if v_count = 0 then',
'    -- without execute immediate this script will raise an error when the package console is not valid',
'    execute immediate ''select console.version from dual'' into v_console_version;',
'    execute immediate replace( q''[',
'      -- We are doing a direct insert to create a log entry independent of the current log level.',
'      declare',
'        v_row console_logs%rowtype;',
'      begin',
'        v_row.log_time    := localtimestamp;',
'        v_row.level_id    := 3;',
'        v_row.level_name  := console.level_name(3);',
'        v_row.permanent   := ''Y'';',
'        v_row.scope       := ''Library Installation'';',
'        v_row.message     := ''{o,o} CONSOLE v#CONSOLE_VERSION# installed'';',
'        insert into console_logs values v_row;',
'        commit;',
'      end;]'', ''#CONSOLE_VERSION#'', v_console_version);',
'    dbms_output.put_line(''>           '');',
'    dbms_output.put_line(''>   .___.   '');',
'    dbms_output.put_line(''>   {o,o}   '');',
'    dbms_output.put_line(''>   /)__)   Hopefully you have now sharper debugging eyes with'');',
'    dbms_output.put_line(''>   -"-"-   CONSOLE v'' || v_console_version);',
'    dbms_output.put_line(''>           '');',
'  end if;',
'end;',
'/',
'prompt',
'',
'',
'',
'',
''))
);
end;
/
prompt --application/deployment/install/install_model_0_3_0
begin
wwv_flow_imp_shared.create_install_script(
 p_id=>wwv_flow_imp.id(6107146805866004775)
,p_install_id=>wwv_flow_imp.id(3198790027011248064)
,p_name=>'Model 0.3.0 '
,p_sequence=>20
,p_script_type=>'INSTALL'
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'--DO NOT CHANGE THIS FILE - IT IS GENERATED WITH THE BUILD SCRIPT build.js',
'set define on',
'set serveroutput on',
'set verify off',
'set feedback off',
'set linesize 240',
'set trimout on',
'set trimspool on',
'whenever sqlerror exit sql.sqlcode rollback',
'',
'prompt ORACLE DATA MODEL UTILITIES: CREATE DATABASE OBJECTS',
'prompt - Project page https://github.com/ogobrecht/model',
'prompt - Package MODEL (spec)',
'create or replace package model authid current_user is',
'',
'c_name    constant varchar2 ( 30 byte ) := ''Oracle Data Model Utilities''        ;',
'c_version constant varchar2 ( 10 byte ) := ''0.3.0''                              ;',
'c_url     constant varchar2 ( 34 byte ) := ''https://github.com/ogobrecht/model'' ;',
'c_license constant varchar2 (  3 byte ) := ''MIT''                                ;',
'c_author  constant varchar2 ( 15 byte ) := ''Ottmar Gobrecht''                    ;',
'',
'c_dict_tabs_list constant varchar2 (200 byte) := ''',
'  user_tables         ,',
'  user_tab_columns    ,',
'  user_constraints    ,',
'  user_cons_columns   ,',
'  user_tab_comments   ,',
'  user_mview_comments ,',
'  user_col_comments   ,',
''';',
'',
'/**',
'',
'Oracle Data Model Utilities',
'===========================',
'',
'PL/SQL utilities to support data model activities like reporting, visualizations...',
'',
'This project is in an early stage - use it at your own risk...',
'',
'CHANGELOG',
'',
'- 0.3.0 (2021-10-28): New helper methods get_data_default_vc, get_search_condition_vc',
'- 0.2.1 (2021-10-24): Fix error on unknown tables, add elapsed time to output, reformat code',
'- 0.2.0 (2021-10-23): Add a param for custom tab lists, improved docs',
'- 0.1.0 (2021-10-22): Initial minimal version',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC SIMPLE TYPES',
'--------------------------------------------------------------------------------',
'',
'subtype t_int  is pls_integer;',
'subtype t_1b   is varchar2 (    1 byte);',
'subtype t_2b   is varchar2 (    2 byte);',
'subtype t_4b   is varchar2 (    4 byte);',
'subtype t_8b   is varchar2 (    8 byte);',
'subtype t_16b  is varchar2 (   16 byte);',
'subtype t_32b  is varchar2 (   32 byte);',
'subtype t_64b  is varchar2 (   64 byte);',
'subtype t_128b is varchar2 (  128 byte);',
'subtype t_256b is varchar2 (  256 byte);',
'subtype t_512b is varchar2 (  512 byte);',
'subtype t_1kb  is varchar2 ( 1024 byte);',
'subtype t_2kb  is varchar2 ( 2048 byte);',
'subtype t_4kb  is varchar2 ( 4096 byte);',
'subtype t_8kb  is varchar2 ( 8192 byte);',
'subtype t_16kb is varchar2 (16384 byte);',
'subtype t_32kb is varchar2 (32767 byte);',
'',
'--------------------------------------------------------------------------------',
'-- PUBLIC MODEL METHODS',
'--------------------------------------------------------------------------------',
'',
'procedure create_dict_mviews (',
'  p_dict_tabs_list varchar2 default c_dict_tabs_list',
');',
'/**',
'',
'Create materialized views for data dictionary tables.',
'',
'The mviews are named like `table_name` + `_mv`.',
'',
'Per default only mviews for some user_xxx tables are created - also see',
'`c_dict_tabs_list` in package signature above.',
'',
'You can overwrite the default by provide your own data dictionary table list:',
'',
'EXAMPLES',
'',
'```sql',
'-- log is written to serveroutput, so we enable it here',
'set serveroutput on',
'',
'-- with default data dictionary table list',
'exec model.create_dict_mviews;',
'',
'-- with custom data dictionary table list',
'exec model.create_dict_mviews(''all_tables, all_tab_columns'');',
'',
'-- works also when you provide the resulting mviev names instead',
'-- of the table names or when you have line breaks in your list',
'begin',
'  model.create_dict_mviews(''',
'    all_tables_mv       ,',
'    all_tab_columns_mv  ,',
'    all_constraints_mv  ,',
'    all_cons_columns_mv ,',
'  '');',
'end;',
'{{/}}',
'```',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure refresh_dict_mviews (',
'  p_dict_tabs_list varchar2 default c_dict_tabs_list',
');',
'/**',
'',
'Refresh the materialized views.',
'',
'Same rules and defaults as for the `create_dict_mviews` method (see above).',
'',
'If you created a custum set of mviews you should provide the same parameter',
'value here for the refresh.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'procedure drop_dict_mviews (',
'  p_dict_tabs_list varchar2 default c_dict_tabs_list',
');',
'/**',
'',
'Drop the materialized views.',
'',
'Same rules and defaults as for the `create_dict_mviews` method (see above).',
'',
'If you created a custum set of mviews you should provide the same parameter',
'value here for the drop.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function get_data_default_vc (',
'  p_dict_tab_name varchar2,',
'  p_table_name    varchar2,',
'  p_column_name   varchar2,',
'  p_owner         varchar2 default user)',
'  return varchar2;',
'/**',
'',
'Convert the LONG column DATA_DEFAULT to varchar2(4000).',
'',
'Is used in `create_dict_mviews`. Works only for the dictionary tables',
'USER_TAB_COLUMNS, USER_TAB_COLS, ALL_TAB_COLUMNS, ALL_TAB_COLS,',
'USER_NESTED_TABLE_COLS, ALL_NESTED_TABLE_COLS.',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'function get_search_condition_vc (',
'  p_dict_tab_name   varchar2,',
'  p_constraint_name varchar2,',
'  p_owner           varchar2 default user)',
'  return varchar2;',
'/**',
'',
'Convert the LONG column SEARCH_CONDITION to varchar2(4000).',
'',
'Is used in `create_dict_mviews`. Works only for the dictionary_tables',
'USER_CONSTRAINTS, ALL_CONSTRAINTS',
'',
'**/',
'',
'--------------------------------------------------------------------------------',
'',
'end model;',
'/',
'',
'prompt - Package MODEL (body)',
'create or replace package body model is',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_cleanup_tabs_list(p_tabs_list varchar2) return varchar2 is',
'begin',
'  return trim(both '','' from regexp_replace(regexp_replace(p_tabs_list, ''\s+''), '',{2,}'', '',''));',
'end;',
'',
'--------------------------------------------------------------------------------',
'',
'function runtime ( p_start in timestamp ) return varchar2 is',
'  v_runtime t_32b;',
'begin',
'  v_runtime := to_char(localtimestamp - p_start);',
'  return substr(v_runtime, instr(v_runtime,'':'')-2, 15);',
'end runtime;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_runtime_seconds ( p_start in timestamp ) return number is',
'  v_runtime interval day to second;',
'begin',
'  v_runtime := localtimestamp - p_start;',
'  return',
'    extract(hour   from v_runtime) * 3600 +',
'    extract(minute from v_runtime) *   60 +',
'    extract(second from v_runtime)        ;',
'end utl_runtime_seconds;',
'',
'--------------------------------------------------------------------------------',
'',
'function utl_create_dict_mview ( p_table_name varchar2 ) return integer is',
'  v_table_name t_1kb;',
'  v_mview_name t_1kb;',
'  v_sql        t_32kb;',
'  v_return     t_int := 0;',
'begin',
'  v_table_name := lower(trim(substr(p_table_name, 1, 1000)));',
'  v_mview_name := v_table_name || ''_mv'';',
'  for i in (',
'    with base as (',
'      select table_name, column_name, data_type, data_length',
'        from all_tab_cols',
'       where owner = ''SYS''',
'         and table_name = upper(v_table_name)',
'       order by column_id',
'    )',
'    select table_name,',
'           column_name,',
'           data_type,',
'           data_length,',
'           case when data_type = ''LONG'' then (',
'             select count(*) ',
'               from base ',
'              where column_name = t.column_name || ''_VC'') ',
'           end as vc_column_exists',
'      from base t  ',
'  )',
'  loop',
'    v_sql := v_sql || ''  '' ||',
'      case when i.data_type != ''LONG'' then ',
'        lower(i.column_name) || '','' || chr(10)',
'        else ',
'          ''to_lob('' || lower(i.column_name) || '') as '' || lower(i.column_name) || '','' || chr(10) ||',
'          case when i.vc_column_exists = 0 then ',
'            case i.column_name',
'              when ''DATA_DEFAULT'' then ',
'                ''  case when data_default is not null then model.get_data_default_vc(p_dict_tab_name=>'''''' || v_table_name || ',
'                  '''''',p_table_name=>table_name,p_column_name=>column_name'' || ',
'                  case when v_table_name like ''all%'' then '',p_owner=>owner'' end || ',
'                  '') end as '' || lower(i.column_name) || ''_vc,'' || chr(10)',
'              when ''SEARCH_CONDITION'' then ',
'                ''  case when search_condition is not null then model.get_search_conditions_vc(p_dict_tab_name=>'''''' || v_table_name || ',
'                  '''''',p_table_name=>table_name,p_constraint_name=>constraint_name,p_owner=>owner'' ||',
'                  '') end as '' || lower(i.column_name) || ''_vc,'' || chr(10)',
'            end',
'          end',
'      end;',
'  end loop;',
'  if v_sql is not null then',
'    v_return := 1;',
'    v_sql    := ''create materialized view '' || v_mview_name || '' as '' || chr(10) ||',
'                    ''select''                                          || chr(10) ||',
'                    rtrim(v_sql, '','' || chr(10))                      || chr(10) ||',
'                    ''from''                                            || chr(10) ||',
'                    ''  '' || v_table_name;',
'    dbms_output.put_line(v_sql);',
'    dbms_output.put_line(''- '' || v_mview_name);',
'    execute immediate(v_sql);',
'  end if;',
'  return v_return;',
'end utl_create_dict_mview;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure create_dict_mviews ( p_dict_tabs_list varchar2 default c_dict_tabs_list ) is',
'  v_start          timestamp := localtimestamp;',
'  v_dict_tabs_list t_32kb    := utl_cleanup_tabs_list(p_dict_tabs_list);',
'  v_count          t_int     := 0;',
'begin',
'  dbms_output.put_line(''MODEL - CREATE DICT MVIEWS'');',
'  for i in (',
'    -- https://blogs.oracle.com/sql/post/split-comma-separated-values-into-rows-in-oracle-database',
'    with',
'    base as ( select v_dict_tabs_list as str from dual ),',
'    tabs as (',
'       select regexp_replace(upper(trim(regexp_substr(str, ''[^,]+'', 1, level))), ''_MV$'') as table_name',
'         from base',
'      connect by level <= length(str) - length(replace(str, '','')) + 1',
'    )',
'    select table_name from tabs',
'    minus',
'    select regexp_replace(mview_name, ''_MV$'') from user_mviews where regexp_like (mview_name, ''_MV$'')',
'  )',
'  loop',
'    v_count := v_count + utl_create_dict_mview(i.table_name);',
'  end loop;',
'  dbms_output.put_line(''- '' || v_count || '' mview'' || case when v_count != 1 then ''s'' end || '' created in '' || runtime(v_start));',
'',
'end create_dict_mviews;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure refresh_dict_mviews ( p_dict_tabs_list varchar2 default c_dict_tabs_list ) is',
'  v_start          timestamp := localtimestamp;',
'  v_dict_tabs_list t_32kb    := utl_cleanup_tabs_list(p_dict_tabs_list);',
'  v_count          t_int     := 0;',
'begin',
'  dbms_output.put_line(''MODEL - REFRESH DICT MVIEWS'');',
'  for i in (',
'    with',
'    base as ( select v_dict_tabs_list as str from dual ),',
'    tabs as (',
'       select regexp_replace(upper(trim(regexp_substr(str, ''[^,]+'', 1, level))), ''_MV$'') as table_name',
'         from base',
'      connect by level <= length(str) - length(replace(str, '','')) + 1',
'    ),',
'    expected_mviews as ( select table_name || ''_MV'' as mview_name from tabs )',
'    select mview_name from expected_mviews natural join user_mviews',
'  )',
'  loop',
'    dbms_output.put_line(''- '' || lower(i.mview_name));',
'    dbms_mview.refresh(list => i.mview_name, method => ''c'');',
'    v_count := v_count + 1;',
'  end loop;',
'  dbms_output.put_line(''- '' || v_count || '' mview'' || case when v_count != 1 then ''s'' end || '' refreshed in '' || runtime(v_start));',
'end refresh_dict_mviews;',
'',
'--------------------------------------------------------------------------------',
'',
'procedure drop_dict_mviews ( p_dict_tabs_list varchar2 default c_dict_tabs_list ) is',
'  v_start          timestamp := localtimestamp;',
'  v_dict_tabs_list t_32kb    := utl_cleanup_tabs_list(p_dict_tabs_list);',
'  v_count          t_int     := 0;',
'begin',
'  dbms_output.put_line(''MODEL - DROP DICT MVIEWS'');',
'  for i in(',
'    with',
'    base as ( select v_dict_tabs_list as str from dual ),',
'    tabs as (',
'       select regexp_replace(upper(trim(regexp_substr(str, ''[^,]+'', 1, level))), ''_MV$'') as table_name',
'         from base',
'      connect by level <= length(str) - length(replace(str, '','')) + 1',
'    ),',
'    expected_mviews as ( select table_name || ''_MV'' as table_name from tabs )',
'    select mview_name from expected_mviews join user_mviews on table_name = mview_name )',
'  loop',
'    dbms_output.put_line(''- '' || lower(i.mview_name));',
'    execute immediate ''drop materialized view '' || i.mview_name;',
'    v_count := v_count + 1;',
'  end loop;',
'  dbms_output.put_line(''- '' || v_count || '' mview'' || case when v_count != 1 then ''s'' end || '' dropped in '' || runtime(v_start));',
'end drop_dict_mviews;',
'',
'--------------------------------------------------------------------------------',
'',
'function get_data_default_vc (',
'  p_dict_tab_name varchar2,',
'  p_table_name    varchar2,',
'  p_column_name   varchar2,',
'  p_owner         varchar2 default user)',
'  return varchar2',
'as',
'  v_long long;',
'begin',
'  case',
'    when upper(p_dict_tab_name) in (''USER_TAB_COLUMNS'', ''USER_TAB_COLS'') then',
'      select data_default into v_long',
'        from user_tab_columns',
'       where table_name = upper(p_table_name)',
'         and column_name = upper(p_column_name);',
'    when upper(p_dict_tab_name) in (''ALL_TAB_COLUMNS'', ''ALL_TAB_COLS'') then',
'      select data_default into v_long',
'        from all_tab_columns',
'       where owner = p_owner',
'         and table_name = upper(p_table_name)',
'         and column_name = upper(p_column_name);',
'    when upper(p_dict_tab_name) = ''USER_NESTED_TABLE_COLS'' then',
'      select data_default into v_long',
'        from user_nested_table_cols',
'       where table_name = upper(p_table_name)',
'         and column_name = upper(p_column_name);',
'    when upper(p_dict_tab_name) = ''ALL_NESTED_TABLE_COLS'' then',
'      select data_default into v_long',
'        from all_nested_table_cols',
'       where owner = p_owner',
'         and table_name = upper(p_table_name)',
'         and column_name = upper(p_column_name);',
'    else',
'      raise_application_error(-20999, ''Unsupported dictionary table '' || p_dict_tab_name);',
'  end case;',
'  return substr(v_long, 1, 4000);',
'end get_data_default_vc;',
'',
'--------------------------------------------------------------------------------',
'',
'function get_search_condition_vc (',
'  p_dict_tab_name   varchar2,',
'  p_constraint_name varchar2,',
'  p_owner           varchar2 default user)',
'  return varchar2',
'as',
'  v_long long;',
'begin',
'  case upper(p_dict_tab_name)',
'    when ''USER_CONSTRAINTS'' then',
'      select search_condition into v_long',
'        from user_constraints',
'       where owner = p_owner',
'         and constraint_name = upper(p_constraint_name);',
'    when ''ALL_CONSTRAINTS'' then',
'      select search_condition into v_long',
'        from all_constraints',
'       where owner = p_owner',
'         and constraint_name = upper(p_constraint_name);',
'    else',
'      raise_application_error(-20999, ''Unsupported dictionary table '' || p_dict_tab_name);',
'  end case;',
'  return substr(v_long, 1, 4000);',
'end get_search_condition_vc;',
'',
'--------------------------------------------------------------------------------',
'',
'end model;',
'/',
'prompt - FINISHED',
'',
''))
);
end;
/
prompt --application/deployment/install/install_materialized_views_for_dictionary_tables
begin
wwv_flow_imp_shared.create_install_script(
 p_id=>wwv_flow_imp.id(6109648274643017322)
,p_install_id=>wwv_flow_imp.id(3198790027011248064)
,p_name=>'Materialized views for dictionary tables'
,p_sequence=>30
,p_script_type=>'INSTALL'
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'begin',
'  model.create_dict_mviews(''',
'    user_tables_mv       ,',
'    user_tab_columns_mv  ,',
'    user_constraints_mv  ,',
'    user_cons_columns_mv ,',
'  '');',
'end;',
'/'))
);
end;
/
prompt --application/deployment/install/install_plug_in_gantt_demo_tables
begin
wwv_flow_imp_shared.create_install_script(
 p_id=>wwv_flow_imp.id(14738455477611820746)
,p_install_id=>wwv_flow_imp.id(3198790027011248064)
,p_name=>'Plug-in Gantt Demo Tables'
,p_sequence=>40
,p_script_type=>'INSTALL'
,p_script_clob=>wwv_flow_string.join(wwv_flow_t_varchar2(
'declare',
'   v_count pls_integer;',
'begin',
'',
'   select count(*) into v_count from user_tables where table_name = ''PLUGIN_GANTT_DEMO_TASKS'';',
'   if v_count = 0 then',
'      execute immediate q''{',
'         create table plugin_gantt_demo_tasks (',
'             t_id           number              generated by default on null as identity (start with 7),',
'             t_parent_t_id  number              ,',
'             t_title        varchar2(80 char)   not null,',
'             t_description  varchar2(400 char)  ,',
'             t_start_date   date not null       ,',
'             t_duration     number              default 0 not null,',
'             t_progress     number(4, 3)        default 0 not null,',
'             t_sort_order   number              default 0 not null,',
'             --',
'             constraint  plugin_gantt_demo_tasks_pk  primary key (t_id),',
'             constraint  plugin_gantt_demo_tasks_fk  foreign key (t_parent_t_id) references plugin_gantt_demo_tasks (t_id),',
'             constraint  plugin_gantt_demo_tasks_ck  check (t_progress between 0 and 1)',
'         )',
'    }'';',
'   end if;',
'',
'   select count(*) into v_count from user_tables where table_name = ''PLUGIN_GANTT_DEMO_LINKS'';',
'   if v_count = 0 then',
'      execute immediate q''{',
'         create table plugin_gantt_demo_links (',
'             l_id      number     generated by default on null as identity (start with 6),',
'             l_source  number     not null,',
'             l_target  number     not null,',
'             l_type    number(1)  not null,',
'             --',
'             constraint  plugin_gantt_demo_links_pk    primary key (l_id),',
'             constraint  plugin_gantt_demo_links_fk_1  foreign key (l_source) references plugin_gantt_demo_tasks (t_id),',
'             constraint  plugin_gantt_demo_links_fk_2  foreign key (l_target) references plugin_gantt_demo_tasks (t_id),',
'             constraint  plugin_gantt_demo_links_ck    check (l_type in (0, 1, 2, 3))',
'         )',
'    }'';',
'   end if;',
'',
'   select count(*) into v_count from user_tables where table_name = ''PLUGIN_GANTT_DEMO_HOLIDAYS'';',
'   if v_count = 0 then',
'      execute immediate q''{',
'         create table plugin_gantt_demo_holidays (',
'             h_date     date          not null,',
'             h_comment  varchar2(30)  ,',
'             --',
'             constraint  plugin_gantt_demo_holidays_pk  primary key (h_date),',
'             constraint  plugin_gantt_demo_holidays_ck  check (h_date = trunc(h_date))',
'         )',
'    }'';',
'   end if;',
'',
'end;',
'/',
'',
'declare',
'   v_count pls_integer;',
'begin',
'',
'   select count(*) into v_count from plugin_gantt_demo_tasks;',
'   if v_count = 0 then',
'      insert into plugin_gantt_demo_tasks',
'      values (1,',
'         null,',
'         ''Project #1'',',
'         null,',
'         date ''2017-04-01'',',
'         11,',
'         0.6,',
'         1',
'      );',
'      insert into plugin_gantt_demo_tasks',
'      values (',
'         2,',
'         1,',
'         ''Task #1'',',
'         null,',
'         date ''2017-04-03'',',
'         5,',
'         1,',
'         2',
'      );',
'      insert into plugin_gantt_demo_tasks',
'      values (',
'         3,',
'         1,',
'         ''Task #2'',',
'         null,',
'         date ''2017-04-02'',',
'         7,',
'         0.5,',
'         3',
'      );',
'      insert into plugin_gantt_demo_tasks',
'      values (',
'         4,',
'         3,',
'         ''Task #2.1'',',
'         null,',
'         date ''2017-04-03'',',
'         2,',
'         1,',
'         4',
'      );',
'      insert into plugin_gantt_demo_tasks',
'      values (',
'         5,',
'         3,',
'         ''Task #2.2'',',
'         null,',
'         date ''2017-04-04'',',
'         3,',
'         0.8,',
'         5',
'      );',
'      insert into plugin_gantt_demo_tasks',
'      values (',
'         6,',
'         3,',
'         ''Task #2.3'',',
'         null,',
'         date ''2017-04-05'',',
'         4,',
'         0.2,',
'         6',
'      );',
'   end if;',
'',
'   select count(*) into v_count from plugin_gantt_demo_links;',
'   if v_count = 0 then',
'      insert into plugin_gantt_demo_links',
'      values (',
'         1,',
'         1,',
'         2,',
'         1',
'      );',
'      insert into plugin_gantt_demo_links',
'      values (',
'         2,',
'         1,',
'         3,',
'         1',
'      );',
'      insert into plugin_gantt_demo_links',
'      values (',
'         3,',
'         3,',
'         4,',
'         1',
'      );',
'      insert into plugin_gantt_demo_links',
'      values (',
'         4,',
'         4,',
'         5,',
'         0',
'      );',
'      insert into plugin_gantt_demo_links',
'      values (',
'         5,',
'         5,',
'         6,',
'         0',
'      );',
'   end if;',
'',
'   select count(*) into v_count from plugin_gantt_demo_holidays;',
'   if v_count = 0 then',
'      insert into plugin_gantt_demo_holidays',
'      values (',
'         date ''2017-04-04'',',
'         ''Dummy holiday''',
'      );',
'   end if;',
'',
'end;',
'/',
'',
'commit;'))
);
end;
/
prompt --application/deployment/checks
begin
null;
end;
/
prompt --application/deployment/buildoptions
begin
null;
end;
/
prompt --application/end_environment
begin
wwv_flow_imp.import_end(p_auto_install_sup_obj => nvl(wwv_flow_application_install.get_auto_install_sup_obj, false)
);
commit;
end;
/
set verify on feedback on define on
prompt  ...done
