DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_LOGVIEW

Source


1 package body fnd_logview as
2 /* $Header: AFUTLPFB.pls 115.16 2002/02/08 21:49:36 nbhambha ship $ */
3 
4 
5 M_ROWS_PER_PAGE NUMBER := 1000;
6 
7 function convert_special_chars(inval in varchar2) return varchar2 is
8 begin
9  return(replace(
10              replace(
11              replace(
12              replace(inval, '&', '&'||'amp;' ),
13                             '"', '&'||'quot;'),
14                             '<', '&'||'lt;'  ),
15                             '>', '&'||'gt;'  ));
16 end;
17 
18 procedure preferences is
19 begin
20    preferences_sysadmin;
21 end;
22 
23 procedure preferences_user is
24 begin
25    preferences_generic('U');
26 end;
27 
28 procedure preferences_sysadmin is
29 begin
30    preferences_generic('S');
31 end;
32 
33 procedure preferences_sysadmin_debug is
34 begin
35    preferences_generic('SD');
36 end;
37 
38 /* Mode = 'U' for user mode, or 'S' for sysadmin */
39 procedure preferences_generic(user_mode in varchar2,
40                               user_id_x in number default NULL) is
41    AFLOG_ENABLED     BOOLEAN;
42    AFLOG_ENABLED_TXT VARCHAR2(30);
43    AFLOG_FILENAME    VARCHAR2(255);
44    AFLOG_LEVEL       NUMBER;
45    AFLOG_MODULE      VARCHAR2(2000);
46    RESULT            BOOLEAN;
47    SESSION_ID        NUMBER;
48    LEVEL_1           VARCHAR2(30);
49    LEVEL_2           VARCHAR2(30);
50    LEVEL_3           VARCHAR2(30);
51    LEVEL_4           VARCHAR2(30);
52    LEVEL_5           VARCHAR2(30);
53    LEVEL_6           VARCHAR2(30);
54 begin
55 
56 if icx_sec.validateSession
57 then
58  if(user_mode = 'SD') then
59    htp.p('<P><B>Note: you are running an unsupported screen.  This developer/troubleshooting screen is intended only as a last resort when regular screens are unreachable from the menu.  ');
60    htp.p('You may get "access denied" errors after you press buttons in this screen; ignore them and press the back arrow to get back.</B></P>');
61  end if;
62 
63   if(substr(user_mode,1,1) = 'S') then
64     /* Don't allow people who don't have sysadmin function */
65     /* to run sysadmin version of the page.  */
66     if((user_mode = 'S') and
67       (not fnd_function.test('FND_LOGPREFS'))) then
68        htp.p('Access denied; function FND_LOGPREFS required.');
69        return;
70     end if;
71 
72     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_ENABLED',
73                              user_id_z =>           -9999999,
74                              responsibility_id_z => -9999999,
75                              application_id_z =>    -9999999,
76                              val_z => aflog_enabled_txt,
77                              defined_z => result);
78     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_FILENAME',
79                              user_id_z =>           -9999999,
80                              responsibility_id_z => -9999999,
81                              application_id_z =>    -9999999,
82                              val_z => aflog_filename,
83                              defined_z => result);
84     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_LEVEL',
85                              user_id_z =>           -9999999,
86                              responsibility_id_z => -9999999,
87                              application_id_z =>    -9999999,
88                              val_z => aflog_level,
89                              defined_z => result);
90     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_MODULE',
91                              user_id_z =>           -9999999,
92                              responsibility_id_z => -9999999,
93                              application_id_z =>    -9999999,
94                              val_z => aflog_module,
95                              defined_z => result);
96     if (aflog_enabled_txt = 'Y') then
97        aflog_enabled := TRUE;
98      else
99        aflog_enabled := FALSE;
100     end if;
101   elsif(user_id_x is not null) then
102     /* Getting profile values for a particular user (not current user)*/
103     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_ENABLED',
104                              user_id_z => user_id_x,
105                              val_z => aflog_enabled_txt,
106                              defined_z => result);
107     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_FILENAME',
108                              user_id_z => user_id_x,
109                              val_z => aflog_filename,
110                              defined_z => result);
111     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_LEVEL',
112                              user_id_z => user_id_x,
113                              val_z => aflog_level,
114                              defined_z => result);
115     FND_PROFILE.GET_SPECIFIC(name_z => 'AFLOG_MODULE',
116                              user_id_z => user_id_x,
117                              val_z => aflog_module,
118                              defined_z => result);
119     if (aflog_enabled_txt = 'Y') then
120        aflog_enabled := TRUE;
121      else
122        aflog_enabled := FALSE;
123     end if;
124   else /* Getting profile values for the current user */
125     if (FND_PROFILE.VALUE('AFLOG_ENABLED') = 'Y') then
126        aflog_enabled_txt := 'Y';
127        aflog_enabled := TRUE;
128      else
129        aflog_enabled_txt := 'N';
130        aflog_enabled := FALSE;
131     end if;
132     aflog_filename := FND_PROFILE.VALUE('AFLOG_FILENAME');
133     aflog_level := to_number(FND_PROFILE.VALUE('AFLOG_LEVEL'));
134     aflog_module := FND_PROFILE.VALUE('AFLOG_MODULE');
135   end if;
136 
137   if(AFLOG_ENABLED) then
138      AFLOG_ENABLED_TXT := 'Checked';
139   else
140      AFLOG_ENABLED_TXT := '';
141   end if;
142 
143   LEVEL_1 := '';
144   LEVEL_2 := '';
145   LEVEL_3 := '';
146   LEVEL_4 := '';
147   LEVEL_5 := '';
148   LEVEL_6 := '';
149 
150   if(AFLOG_LEVEL = '1') then
151      LEVEL_1 := 'Checked';
152   elsif(AFLOG_LEVEL = '2') then
153      LEVEL_2 := 'Checked';
154   elsif(AFLOG_LEVEL = '3') then
155      LEVEL_3 := 'Checked';
156   elsif(AFLOG_LEVEL = '4') then
157      LEVEL_4 := 'Checked';
158   elsif(AFLOG_LEVEL = '5') then
159      LEVEL_5 := 'Checked';
160   elsif(AFLOG_LEVEL = '6') then
161      LEVEL_6 := 'Checked';
162   end if;
163 
164 
165  htp.p('<html>');
166  if (substr(user_mode,1,1) = 'S') then
167     htp.p('<title>'||'Site Logging Preferences'||'</title>');
168  else
169     htp.p('<title>'||'User Logging Preferences'||'</title>');
170  end if;
171 
172 
173  if (icx_sec.g_mode_code in ('115J', '115P', 'SLAVE')) then
174     htp.p('<body bgcolor= "#CCCCCC">');
175  else
176     htp.p('<body bgcolor="'||icx_plug_utilities.bgcolor||'">');
177  end if;
178 
179  htp.p('
180 
181 <FORM Method="post" Action="FND_LOGVIEW.UPDATE_PREFS">
182 
183 <TABLE>
184 <TR>
185 <TH></TH><TH ALIGN=LEFT>
186 ');
187  if (substr(user_mode,1,1) = 'S') then
188     htp.p('<H2>Site Logging Preferences</H2>');
189  else
190     if (user_id_x is not null) then
191        htp.p('<H2>User Logging Preferences</H2><P> preferences for Userid: '||
192        '<INPUT Type="text" size=20 maxlength=255 name="USER_ID" value="'||
193        to_char(user_id_x)||'"></P>');
194     else
195        htp.p('<H2>User Logging Preferences</H2>');
196     end if;
197  end if;
198 
199 htp.p('
200 </TH>
201 </TR>
202 <TR><TD ALIGN=RIGHT VALIGN=TOP>
203 Runtime Logging Enabled:
204 </TD><TD>
205 <INPUT Type="checkbox"  Name="ENABLED" '||aflog_enabled_txt||
206                       '>
207 
208 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
209 Logging level:
210 </TD><TD>
211 <INPUT Type="radio"  '||LEVEL_6||' Name="LEVEL" Value="6">Unexpected<BR>
212 <INPUT Type="radio"  '||LEVEL_5||' Name="LEVEL" Value="5">Error<BR>
213 <INPUT Type="radio"  '||LEVEL_4||' Name="LEVEL" Value="4">Exception<BR>
214 <INPUT Type="radio"  '||LEVEL_3||' Name="LEVEL" Value="3">Event<BR>
215 <INPUT Type="radio"  '||LEVEL_2||' Name="LEVEL" Value="2">Procedure<BR>
216 <INPUT Type="radio"  '||LEVEL_1||' Name="LEVEL" Value="1">Statement<BR>
217 
218 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
219 Filename:<BR>
220 (Normally left blank to log in database)
221 </TD><TD>
222 <INPUT Type="text" size=60 maxlength=255 name="FILENAME" value="'||
223     AFLOG_FILENAME||'">
224 
225 
226 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
227 Modules Enabled:
228 </TD><TD>
229 <TEXTAREA Type="text" maxlength=2000 rows=5 cols = 60 wrap=soft name="MODULE" >'||AFLOG_MODULE||'
230 </TEXTAREA>
231 
232 </TD>
233 ');
234 if(substr(user_mode,1,1) = 'S') then /* SYSADMIN MODE..... */
235 htp.p('
236 <TR><TD ALIGN=RIGHT VALIGN=TOP>
237 </TD><TD>
238 <INPUT Type=submit name=sysclearprefs
239       Value="Clear site preferences">
240 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
241 <!-- <INPUT Type=reset name=sysclear Value="Cancel">  -->
242 </TD><TD>
243 <INPUT Type=submit name=syssave Value="Save as site preferences">
244 <hr />
245 </TD></TR><TR><TD ALIGN=RIGHT VALIGN=TOP></TD><TD>
246 <TABLE border="1" ><TR><TD>
247 Session id to purge:
248 <INPUT Type="text" size=20 maxlength=255 name="SESSION_TO_PURGE" value="'||
249 to_char(icx_sec.getsessioncookie())||'">
250 </TD></TR><TR><TD><INPUT Type=submit name=sysclearsessionlog
251      Value="Purge log data for particular session"></TD></TR>
252 </TR></TABLE>
253 </TD></TR><TR><TD ALIGN=RIGHT VALIGN=TOP></TD><TD>
254 <TABLE border="1" ><TR><TD>
255 User name to purge:
256 <INPUT Type="text" size=20 maxlength=255 name="USER_TO_PURGE" value="'||
257 fnd_global.user_name()||'">
258 </TD></TR><TR><TD><INPUT Type=submit name=sysclearuserlog
259      Value="Purge log data for particular user"></TR>
260 </TD></TR></TABLE>
261 </TD></TR><TR><TD ALIGN=RIGHT VALIGN=TOP></TD><TD>
262 <TABLE border="1" ><TR><TD>
263 User name to set preferences for:
264 <INPUT Type="text" size=20 maxlength=255 name="USER_TO_SET" value="'||
265 fnd_global.user_name()||'">
266 </TD></TR><TR><TD><INPUT Type=submit name=syssetuserprefs
267      Value="Navigate to user log preferences screen"></TR>
268 </TD></TR></TABLE>
269 </TD></TR><TR><TD ALIGN=RIGHT VALIGN=TOP></TD><TD>
270 <INPUT Type=submit name=syspurgeallusers
271      Value="Purge log data for all sessions for all users"></TR>
272 </TD></TR>');
273 else /* USER MODE..... */
274 htp.p('
275 <TR><TD ALIGN=RIGHT VALIGN=TOP>
276 </TD><TD>
277 <INPUT Type=submit name=clearprefs
278       Value="Clear user preferences and use defaults">
279 
280 <TR><TD ALIGN=RIGHT VALIGN=TOP>
281 </TD><TD>
282 <INPUT Type=submit name=save Value="Save as user preferences">
283 <HR />
284 </TD></TR>
285 <TR><TD ALIGN=RIGHT VALIGN=TOP>
286 <!-- <INPUT Type=reset name=clear Value="Cancel">  -->
287 </TD><TD>
288 <INPUT Type=submit name=clearsessionlog
289      Value="Purge log data for this current user session">
290 
291 </TD></TR><TR><TD ALIGN=RIGHT VALIGN=TOP>
292 </TD><TD>
293 <INPUT Type=submit name=clearuserlog
294      Value="Purge log data for all sessions belonging to this user">
295 
296 </TD></TR>
297 ');
298 end if;
299 htp.p('
300 </TABLE>
301 </FORM>
302 ');
303 end if;  --icx_sec.validatesession
304 
305 exception
306     when others then
307         htp.p(SQLERRM);
308 end;
309 
310 /* Deprecated */
311 procedure find_display is
312 begin
313   find;
314 end;
315 
316 /* Deprecated */
317 procedure find is
318 begin
319   find_sysadmin;
320 end;
321 
322 procedure find_user is
323 begin
324   find_log('U');
325 end;
326 
327 procedure find_sysadmin is
328 begin
329   find_log('S');
330 end;
331 
332 procedure find_sysadmin_debug is
333 begin
334   find_log('SD');
335 end;
336 
337 /* Mode = 'U' for user mode, or 'S' for sysadmin */
338 procedure find_log(user_mode in varchar2) is
339 begin
340 if icx_sec.validateSession
341 then
342 
343  if(user_mode = 'SD') then
344    htp.p('<P><B>Note: you are running an unsupported screen.  This developer/troubleshooting screen is intended only as a last resort when the regular screens are unreachable from the menu. </B></P>');
345  end if;
346 
347  /* Don't allow people who don't have sysadmin function */
348  /* to run sysadmin version of the page.  */
349  if(user_mode = 'S') then
350     if(not fnd_function.test('FND_LOGFIND')) then
351        htp.p('Access denied; function FND_LOGFIND required.');
352        return;
353     end if;
354  end if;
355 
356 
357  htp.p('<html>');
358  htp.p('<title>'||'Find Log'||'</title>');
359 
360  if (icx_sec.g_mode_code in ('115J', '115P', 'SLAVE')) then
361     htp.p('<body bgcolor= "#CCCCCC">');
362  else
363     htp.p('<body bgcolor="'||icx_plug_utilities.bgcolor||'">');
364  end if;
365 
366  htp.p('
367 
368 <FORM Method="post" Action="FND_LOGVIEW.DISPLAY">
369 
370 <TABLE>
371 <TR>
372 <TH></TH><TH ALIGN=LEFT>
373 <H2>Find Log</H2>
374 </TH>
375 </TR>
376 <TR><TD ALIGN=RIGHT VALIGN=TOP>
377 Logging level:
378 </TD><TD>
379 <INPUT Type="radio" Name="LEVEL" Value="6">Unexpected<BR>
380 <INPUT Type="radio" Name="LEVEL" Value="5">Error<BR>
381 <INPUT Type="radio" Name="LEVEL" Value="4">Exception<BR>
382 <INPUT Type="radio" Name="LEVEL" Value="3">Event<BR>
383 <INPUT Type="radio" Name="LEVEL" Value="2">Procedure<BR>
384 <INPUT Type="radio" checked Name="LEVEL" Value="1">Statement<BR>
385 
386 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
387 Module to view:
388 </TD><TD>
389 <INPUT Type="text" size=60 maxlength=255 name="MODULE" >
390 
391 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
392 Start Date in format <BR>'||fnd_date.canonical_DT_mask||':
393 </TD><TD>
394 <INPUT Type="text" size=40 maxlength=200 name="START_DATE" >
395 
396 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
397 End Date in format <BR>'||fnd_date.canonical_DT_mask||':
398 </TD><TD>
399 <INPUT Type="text" size=40 maxlength=200 name="END_DATE">
400 
401 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
402 Only show log for current self service session:
403 </TD><TD>
404 <INPUT Type="checkbox"  Name="ONLY_SESSION" >
405 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
406 ');
407 
408 if(substr(user_mode,1,1) = 'S') then
409 htp.p('
410 Only show log for user
411 <INPUT Type="text" size=20 maxlength=80 name="USERNAME" value="'||
412     fnd_profile.value('USERNAME')||'">:
413 </TD><TD>
414 <INPUT Type="checkbox"  Name="ONLY_USER" checked >
415 
416 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
417 ');
418 end if;
419 htp.p('
420 Messages per result page:
421 </TD><TD>
422 <INPUT Type="text" size=10 maxlength=80 name="NUMROWS" value="'||
423     M_ROWS_PER_PAGE||'">
424 </TD><P></P><TR><TD ALIGN=RIGHT VALIGN=TOP>
425 ');
426 htp.p('
427 </TD><TD>
428 <INPUT Type=submit name=clearsessionlog
429      Value="Purge log data for this current user session">
430 
431 </TD><TR><TD ALIGN=RIGHT VALIGN=TOP>
432 </TD><TD>
433 <INPUT Type=submit name=clearuserlog
434      Value="Purge log data for all sessions belonging to this user">
435 
436 </TD><TR><TD ALIGN=RIGHT VALIGN=TOP>
437 <!-- <INPUT Type=reset name=clear Value="Cancel"> -->
438 </TD><TD>
439 ');
440 
441 if(substr(user_mode,1,1) = 'S') then
442 htp.p('
443 <INPUT Type=submit name=find_sysadmin Value="Find">
444 ');
445 else
446 htp.p('
447 <INPUT Type=submit name=find_user Value="Find">
448 ');
449 end if;
450 
451 htp.p('
452 
453 </TD></TABLE>
454 </FORM>
455 ');
456 end if;  --icx_sec.validatesession
457 
458 exception
459     when others then
460         htp.p(SQLERRM);
461 end;
462 
463 
464 procedure display( LEVEL     in VARCHAR2,
465                 MODULE       in VARCHAR2,
466                 START_DATE   in VARCHAR2,
467                 END_DATE     in VARCHAR2,
468                 ONLY_SESSION in VARCHAR2 default NULL,
469                 USERNAME     in VARCHAR2 default NULL,
470                 ONLY_USER    in VARCHAR2 default NULL,
471                 FIND_USER    in VARCHAR2 default NULL,
472                 FIND_SYSADMIN    in VARCHAR2 default NULL,
473                 CLEARSESSIONLOG  in VARCHAR2 default NULL,
474                 CLEARUSERLOG     in VARCHAR2 default NULL,
475                 STARTROW         in VARCHAR2 default NULL,
476                 NUMROWS          in VARCHAR2 default NULL)
477 is
478   f_level      number;
479   f_module     varchar2(2000);
480   f_start_date date;
481   f_end_date   date;
482   f_session_id number;
483   f_user_id    number;
484   f_startrow   number;
485   f_maxrow     number;
486   f_numrows    number;
487   f_buttonname   varchar2(255) := 'FIND_USER';
488   log_level_name varchar2(80);
489   timestamp_str  varchar2(80);
490   found_username varchar2(100) := NULL;
491   last_username  varchar2(100) := NULL;
492   last_userid    number;
493 
494   TYPE  DYNAMIC_CUR IS REF CURSOR;
495   row_set DYNAMIC_CUR;
496 
497   l_level      number;
498   l_module     varchar2(255);
499   l_msg_text   varchar2(4000);
500   l_timestamp  date;
501   l_session_id number;
502   l_user_id    number;
503   l_index      number;
504   l_dynamic_sql varchar(2000);
505 
506   b_level      boolean := FALSE;
507   b_module     boolean := FALSE;
508   b_dates      boolean := FALSE;
509   b_session_id boolean := FALSE;
510   b_user_id    boolean := FALSE;
511   b_previous_clause boolean := FALSE;
512 
513   nrows number;
514 begin
515 if icx_sec.validateSession
516 then
517  if (find_user is not null) then
518     f_buttonname := 'FIND_USER';
519     f_user_id := fnd_global.user_id;
520  elsif (find_sysadmin is not null) then
521     f_buttonname := 'FIND_SYSADMIN';
522     f_user_id := NULL;
523  elsif (clearsessionlog is not null) then /* if user pressed... */
524     nrows := FND_LOG_ADMIN.DELETE_BY_USER_SESSION(FND_GLOBAL.USER_ID,
525                                    icx_sec.getsessioncookie());
526     commit;
527     htp.p(
528        '<B>Cleared '|| nrows||
529        ' rows of log data for this session.  Use back arrow to get back.</B>');
530     return;
531  elsif (clearuserlog is not null) then /* if user pressed... */
532     nrows := FND_LOG_ADMIN.DELETE_BY_USER(FND_GLOBAL.USER_ID);
533     commit;
534     htp.p(
535       '<B>Cleared '|| nrows ||
536       ' rows of log data for this user.  Use back arrow to get back.</B>');
537     return;
538  else
539     htp.p('<B>Error- no buttonpress in fnd_logview.display.</B>');
540     return; /* Should never happen */
541  end if;
542 
543  if (startrow is NULL) then
544    f_startrow := 1;
545  else
546    f_startrow := to_number(startrow);
547  end if;
548 
549  if (numrows is NULL) then
550    f_numrows := M_ROWS_PER_PAGE;
551  else
552    f_numrows := to_number(numrows);
553  end if;
554 
555  f_maxrow := f_startrow + f_numrows;
556 
557 
558  f_level := level;
559  f_module := module;
560 
561  if(start_date is not null) then
562     f_start_date := fnd_date.canonical_to_date(start_date);
563  else
564     f_start_date := null;
565  end if;
566 
567  if(end_date is not null) then
568     f_end_date := fnd_date.canonical_to_date(end_date);
569  else
570     f_end_date := null;
571  end if;
572 
573  if(only_session is not null) then
574     f_session_id := icx_sec.getsessioncookie();
575  else
576     f_session_id := NULL;
577  end if;
578 
579  if(only_user is not null and username is not null) then
580     begin
581         select user_id into f_user_id from fnd_user
582         where user_name = upper(username);
583     exception
584         when no_data_found then
585            htp.p('Invalid username entered.  Finding data for current user.');
586         f_user_id := fnd_global.user_id;
587     end;
588  end if;
589 
590 
591  /* level 1 gets all levels, so we don't put level in the where clause */
592  /* in that case, to avoid confusing the db */
593  if ((f_level is not NULL) and (f_level > 1)) then
594    b_level := TRUE;
595  else
596    b_level := FALSE;
597  end if;
598 
599  if(f_module is not NULL)  then
600    b_module := TRUE;
601  else
602    b_module := FALSE;
603  end if;
604 
605  if ((f_start_date is not NULL) or (f_end_date is not NULL)) then
606    b_dates := TRUE;
607  else
608    b_dates := FALSE;
609  end if;
610 
611  if(f_session_id is not NULL)  then
612    b_session_id := TRUE;
613  else
614    b_session_id := FALSE;
615  end if;
616 
617  if(f_user_id is not NULL)  then
618    b_user_id := TRUE;
619  else
620    b_user_id := FALSE;
621  end if;
622 
623  l_dynamic_sql :=
624   'select MODULE||to_number(rownum), LOG_LEVEL, MESSAGE_TEXT, SESSION_ID, USER_ID, TIMESTAMP '||
625    'from fnd_log_messages '||
626   'where ';
627 
628  b_previous_clause := FALSE;
629 
630  if(b_level) then
631    if (b_previous_clause) then
632      l_dynamic_sql :=  l_dynamic_sql || 'AND ';
633    end if;
634    l_dynamic_sql := l_dynamic_sql || '(log_level >= :f_level) ';
635    b_previous_clause := TRUE;
636  end if;
637 
638  if(b_module) then
639    if (b_previous_clause) then
640      l_dynamic_sql :=  l_dynamic_sql || 'AND ';
641    end if;
642    l_dynamic_sql := l_dynamic_sql ||
643                    '(module like :f_module||''%'') ';
644    b_previous_clause := TRUE;
645  end if;
646 
647  if(b_dates) then
648    if (b_previous_clause) then
649      l_dynamic_sql :=  l_dynamic_sql || 'AND ';
650    end if;
651    l_dynamic_sql := l_dynamic_sql ||
652                 '((:f_start_date is NULL) or (timestamp >= :f_start_date)) '||
653             'AND ((:f_end_date is NULL)   or (timestamp <= :f_end_date)) ';
654    b_previous_clause := TRUE;
655  end if;
656 
657  if(b_session_id) then
658    if (b_previous_clause) then
659      l_dynamic_sql :=  l_dynamic_sql || 'AND ';
660    end if;
661    l_dynamic_sql := l_dynamic_sql ||
662                    '(session_id = :f_session_id) ';
663    b_previous_clause := TRUE;
664  end if;
665 
666  if(b_user_id) then
667    if (b_previous_clause) then
668      l_dynamic_sql :=  l_dynamic_sql || 'AND ';
669    end if;
670    l_dynamic_sql := l_dynamic_sql ||
671                    '(user_id = :f_user_id) ';
672    b_previous_clause := TRUE;
673  end if;
674 
675  /* if none of the arguments are passed, use a dummy where clause */
676  if ((not b_level) AND (not b_module) AND (not b_dates) AND
677      (not b_session_id) AND (not b_user_id) ) then
678    l_dynamic_sql := l_dynamic_sql || '(1=1) ';
679    b_previous_clause := TRUE;
680  end if;
681 
682  l_dynamic_sql := l_dynamic_sql ||
683                   ' AND (rownum <= :f_maxrow) '||
684                   'order by timestamp, log_sequence';
685 
686  /* We account for every possible combination of bind presence, */
687 /* and only bind in the ones that are actually present.  */
688 /* This allows the database to use the proper indexes for */
689 /* the binds that are present instead of just giving up */
690 /* and doing a full table scan.*/
691 
692 if (b_level) then
693   if (b_module) then
694     if (b_dates) then
695       if (b_session_id) then
696         if (b_user_id) then
697           OPEN row_set FOR l_dynamic_sql USING
698           f_level, f_module, f_start_date, f_start_date,
699           f_end_date, f_end_date, f_session_id, f_user_id,
700           f_maxrow;
701         else
702           OPEN row_set FOR l_dynamic_sql USING
703             f_level, f_module, f_start_date, f_start_date,
704             f_end_date, f_end_date, f_session_id, f_maxrow;
705         end if;
706       else
707         if (b_user_id) then
708           OPEN row_set FOR l_dynamic_sql USING
709             f_level, f_module, f_start_date, f_start_date,
710             f_end_date, f_end_date, f_user_id, f_maxrow;
711         else
712           OPEN row_set FOR l_dynamic_sql USING
713             f_level, f_module, f_start_date, f_start_date,
714             f_end_date, f_end_date, f_maxrow;
715         end if;
716       end if;
717     else
718       if (b_session_id) then
719         if (b_user_id) then
720           OPEN row_set FOR l_dynamic_sql USING
721             f_level, f_module, f_session_id, f_user_id, f_maxrow;
722         else
723           OPEN row_set FOR l_dynamic_sql USING
724             f_level, f_module, f_session_id, f_maxrow;
725         end if;
726       else
727         if (b_user_id) then
728           OPEN row_set FOR l_dynamic_sql USING
729             f_level, f_module, f_user_id, f_maxrow;
730         else
731           OPEN row_set FOR l_dynamic_sql USING
732             f_level, f_module, f_maxrow;
733         end if;
734       end if;
735     end if;
736   else
737     if (b_dates) then
738       if (b_session_id) then
739         if (b_user_id) then
740           OPEN row_set FOR l_dynamic_sql USING
741             f_level, f_start_date, f_start_date, f_end_date, f_end_date,
742             f_session_id, f_user_id, f_maxrow;
743         else
744           OPEN row_set FOR l_dynamic_sql USING
745             f_level, f_start_date, f_start_date, f_end_date, f_end_date,
746             f_session_id, f_maxrow;
747         end if;
748       else
749         if (b_user_id) then
750           OPEN row_set FOR l_dynamic_sql USING
751             f_level, f_start_date, f_start_date, f_end_date, f_end_date,
752             f_user_id, f_maxrow;
753         else
754           OPEN row_set FOR l_dynamic_sql USING
755             f_level, f_start_date, f_start_date, f_end_date, f_end_date,
756             f_maxrow;
757         end if;
758       end if;
759     else
760       if (b_session_id) then
761         if (b_user_id) then
762           OPEN row_set FOR l_dynamic_sql USING
763             f_level, f_session_id, f_user_id, f_maxrow;
764         else
765           OPEN row_set FOR l_dynamic_sql USING
766             f_level, f_session_id, f_maxrow;
767         end if;
768       else
769         if (b_user_id) then
770           OPEN row_set FOR l_dynamic_sql USING
771             f_level, f_user_id, f_maxrow;
772         else
773           OPEN row_set FOR l_dynamic_sql USING
774             f_level, f_maxrow;
775         end if;
776       end if;
777     end if;
778   end if;
779 else
780   if (b_module) then
781     if (b_dates) then
782       if (b_session_id) then
783         if (b_user_id) then
784           OPEN row_set FOR l_dynamic_sql USING
785             f_module, f_start_date, f_start_date, f_end_date, f_end_date,
786             f_session_id, f_user_id, f_maxrow;
787         else
788           OPEN row_set FOR l_dynamic_sql USING
789             f_module, f_start_date, f_start_date, f_end_date, f_end_date,
790             f_session_id, f_maxrow;
791         end if;
792       else
793         if (b_user_id) then
794           OPEN row_set FOR l_dynamic_sql USING
795             f_module, f_start_date, f_start_date, f_end_date, f_end_date,
796             f_user_id, f_maxrow;
797         else
798           OPEN row_set FOR l_dynamic_sql USING
799             f_module, f_start_date, f_start_date, f_end_date,
800             f_end_date, f_maxrow;
801         end if;
802       end if;
803     else
804       if (b_session_id) then
805         if (b_user_id) then
806           OPEN row_set FOR l_dynamic_sql USING
807             f_module, f_session_id, f_user_id, f_maxrow;
808         else
809           OPEN row_set FOR l_dynamic_sql USING
810             f_module, f_session_id, f_maxrow;
811         end if;
812       else
813         if (b_user_id) then
814           OPEN row_set FOR l_dynamic_sql USING
815             f_module, f_user_id, f_maxrow;
816         else
817           OPEN row_set FOR l_dynamic_sql USING
818             f_module, f_maxrow;
819         end if;
820       end if;
821     end if;
822   else
823     if (b_dates) then
824       if (b_session_id) then
825         if (b_user_id) then
826           OPEN row_set FOR l_dynamic_sql USING
827             f_start_date, f_start_date, f_end_date, f_end_date,
828             f_session_id, f_user_id, f_maxrow;
829         else
830           OPEN row_set FOR l_dynamic_sql USING
831             f_start_date, f_start_date, f_end_date, f_end_date,
832             f_session_id, f_maxrow;
833         end if;
834       else
835         if (b_user_id) then
836           OPEN row_set FOR l_dynamic_sql USING
837             f_start_date, f_start_date, f_end_date, f_end_date,
838             f_user_id, f_maxrow;
839         else
840           OPEN row_set FOR l_dynamic_sql USING
841             f_start_date, f_start_date, f_end_date, f_end_date,
842             f_maxrow;
843         end if;
844       end if;
845     else
846       if (b_session_id) then
847         if (b_user_id) then
848           OPEN row_set FOR l_dynamic_sql USING
849             f_session_id, f_user_id, f_maxrow;
850         else
851           OPEN row_set FOR l_dynamic_sql USING
852             f_session_id, f_maxrow;
853         end if;
854       else
855         if (b_user_id) then
856           OPEN row_set FOR l_dynamic_sql USING
857             f_user_id, f_maxrow;
858         else
859           OPEN row_set FOR l_dynamic_sql USING
860             f_maxrow;
861         end if;
862       end if;
863     end if;
864   end if;
865 end if;
866 
867  htp.p('<html>');
868  htp.p('<title>'||'Logged Messages'||'</title>');
869 
870  htp.p('
871 <H1>Logged Messages</H1>
872 
873 ');
874  htp.p('<B>Context</B>');
875  if(f_level = 1) then
876     htp.p('<BR>Level: Statement');
877   elsif(f_level = 2) then
878     htp.p('<BR>Level: Procedure');
879  elsif(f_level = 3) then
880     htp.p('<BR>Level: Event');
881  elsif(f_level = 4) then
882     htp.p('<BR>Level: Exception');
883  elsif(f_level = 5) then
884     htp.p('<BR>Level: Error');
885  elsif(f_level = 6) then
886     htp.p('<BR>Level: Unexpected');
887  end if;
888  htp.p('<BR>Module: '||nvl(f_module, '(None Specified)'));
889  htp.p('<BR>Start Date: '||nvl(fnd_date.date_to_canonical(f_start_date),
890                               '(None Specified)'));
891  htp.p('<BR>End Date: '||nvl(fnd_date.date_to_canonical(f_end_date),
892                               '(None Specified)'));
893  htp.p('<BR>Session ID: '||nvl(to_char(f_session_id), '(None Specified)'));
894  htp.p('<BR>User ID: '||nvl(to_char(f_user_id), '(None Specified)'));
895  htp.p('<BR><P></P>');
896 
897  htp.p('<TABLE border="1">');
898  htp.p('<TR>');
899  htp.p('<TH Align=Left>Time</TH>');
900  htp.p('<TH Align=Left>Session</TH>');
901  htp.p('<TH Align=Left>User</TH>');
902  htp.p('<TH Align=Left>Level</TH>');
903  htp.p('<TH Align=Left>Module</TH>');
904  htp.p('<TH Align=Left>Message Text</TH>');
905  htp.p('</TR>');
906 
907 
908  l_index := 0;
909  LOOP
910    FETCH row_set INTO l_module, l_level, l_msg_text,
911                      l_session_id, l_user_id, l_timestamp;
912    EXIT WHEN (l_index >= (f_maxrow-1));
913    EXIT WHEN row_set%NOTFOUND;
914    l_index:=l_index+1;
915    if (l_index >= f_startrow) then
916      /* This will need to be redone to use the lookups */
917      log_level_name := 'Unknown';
918      if(l_level = 1) then
919         log_level_name := 'Statement';
920      elsif(l_level = 2) then
921         log_level_name := 'Procedure';
922      elsif(l_level = 3) then
923         log_level_name := 'Event';
924      elsif(l_level = 4) then
925         log_level_name := 'Exception';
926      elsif(l_level = 5) then
927         log_level_name := 'Error';
928      elsif(l_level = 6) then
929         log_level_name := 'Unexpected';
930      end if;
931 
932      timestamp_str := fnd_date.date_to_canonical(l_timestamp);
933 
934      if(l_user_id is not null) then   /* Simple username cache for speed*/
935         if(l_user_id = last_userid) then
936            found_username := last_username;
937         else
938            begin
939              select user_name into found_username
940                from fnd_user
941               where user_id = l_user_id;
942            exception when no_data_found then
943              found_username := 'Invalid Userid: '||to_char(l_user_id);
944            end;
945            last_username := found_username;
946            last_userid   := l_user_id;
947         end if;
948      else
949         found_username := NULL;
950      end if;
951 
952      htp.p('<TR>');
953      htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
954                     convert_special_chars(timestamp_str)||'</TD>');
955      htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
956                     convert_special_chars(l_session_id)||'</TD>');
957      htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
958                     convert_special_chars(found_username)||'</TD>');
959      htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
960                     convert_special_chars(log_level_name)||'</TD>');
961      htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
962                     convert_special_chars(l_module)||'</TD>');
963      if ((not( instr(l_msg_text, fnd_global.local_chr(0)) = 0)) or
964            substr(l_msg_text,1,1) = '<') then /* If encoded message */
965         FND_MESSAGE.SET_ENCODED(l_msg_text);
966         htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
967                 convert_special_chars(FND_MESSAGE.GET)||'</TD>');
968      else
969         htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||
970                 convert_special_chars(l_msg_text)||'</TD>');
971      end if;
972      htp.p('</TR>');
973    end if; /* if (l_index >= f_startrow) */
974  END LOOP;
975  CLOSE row_set;
976  if (l_index > 0) then
977    htp.p('<P>Showing messages '||to_char(f_startrow)||
978           '..'||to_char(l_index));
979  end if;
980  if (l_index >= (f_maxrow-1)) then
981  /* If this row is further than what will fit on screen, render a */
982  /* button for the next screen of data */
983    f_startrow := f_startrow + f_numrows;
984    htp.p('
985 <FORM Method="post" Action="FND_LOGVIEW.DISPLAY">
986 <INPUT Type=submit name="'||f_buttonname||'"
987      Value="Next '||to_char(f_numrows)|| ' Messages">
988 <INPUT type="hidden" name="LEVEL" value="'||LEVEL||'" />
989 <INPUT type="hidden" name="MODULE" value="'||MODULE||'" />
990 <INPUT type="hidden" name="START_DATE" value="'||START_DATE||'" />
991 <INPUT type="hidden" name="END_DATE" value="'||END_DATE||'" />
992 <INPUT type="hidden" name="ONLY_SESSION" value="'||ONLY_SESSION||'" />
993 <INPUT type="hidden" name="USERNAME" value="'||USERNAME||'" />
994 <INPUT type="hidden" name="ONLY_USER" value="'||ONLY_USER||'" />
995 <INPUT type="hidden" name="STARTROW" value="'||to_char(f_startrow)||'" />
996 <INPUT type="hidden" name="NUMROWS" value="'||NUMROWS||'" />
997 <P>
998 ');
999  elsif (l_index = 0) then
1000    htp.p('<TR>');
1001    htp.p('<TD ALIGN=LEFT VALIGN=TOP>'||'No Log Messages returned.'||'</TD>');
1002    htp.p('</TR>');
1003  end if;
1004 htp.p('</TABLE>');
1005 
1006 end if;  --icx_sec.validatesession
1007 
1008 exception
1009     when others then
1010         htp.p(SQLERRM);
1011 end;
1012 
1013 
1014 procedure internal_check_results(result1 in boolean, result2 in boolean,
1015                                  result3 in boolean, result4 in boolean) is
1016 begin
1017       if(result1 = FALSE or
1018          result2 = FALSE or
1019          result3 = FALSE or
1020          result4 = FALSE  ) then
1021          htp.p(
1022           '<P></P>'||
1023           '<B><P>Error- could not save value(s) to the '||
1024           'profiles option(s): ');
1025           if(result1 = FALSE) then
1026              htp.p(' AFLOG_ENABLED');
1027           end if;
1028           if(result2 = FALSE) then
1029              htp.p(' AFLOG_FILENAME');
1030           end if;
1031           if(result3 = FALSE) then
1032              htp.p(' AFLOG_LEVEL');
1033           end if;
1034           if(result4 = FALSE) then
1035              htp.p(' AFLOG_MODULE');
1036           end if;
1037           htp.p(
1038           '.  Check to make sure that profile options are '||
1039           'in the fnd_profile_options table and if not, use the '||
1040           'aflogpro.ldt loader file to upload.</B></P>');
1041       end if;
1042 end;
1043 
1044 procedure Update_Prefs(
1045                 ENABLED     in VARCHAR2 default 'off',
1046                 FILENAME    in VARCHAR2,
1047                 LEVEL       in VARCHAR2 default NULL,
1048                 MODULE      in VARCHAR2,
1049                 SESSION_TO_PURGE   in VARCHAR2 default NULL,
1050                 USER_TO_PURGE      in VARCHAR2 default NULL,
1051                 USER_TO_SET        in VARCHAR2 default NULL,
1052                 SAVE               in VARCHAR2 default NULL,
1053                 clearprefs         in VARCHAR2 default NULL,
1054                 clearsessionlog    in VARCHAR2 default NULL,
1055                 clearuserlog       in VARCHAR2 default NULL,
1056                 clear              in VARCHAR2 default NULL,
1057                 sysclear           in VARCHAR2 default NULL,
1058                 syssave            in VARCHAR2 default NULL,
1059                 syspurgeallusers   in VARCHAR2 default NULL,
1060                 syssetuserprefs    in VARCHAR2 default NULL,
1061                 SYSCLEARPREFS      in VARCHAR2 default NULL,
1062                 SYSCLEARSESSIONLOG in VARCHAR2 default NULL,
1063                 SYSCLEARUSERLOG    in VARCHAR2 default NULL,
1064                 USER_ID            in VARCHAR2 default NULL) is
1065 
1066 c_error_message varchar2(2000);
1067 err_mesg varchar2(240);
1068 err_num number;
1069 made_changes boolean;
1070 result1 boolean;
1071 result2 boolean;
1072 result3 boolean;
1073 result4 boolean;
1074 purged       boolean;
1075 go_back_to_prefs boolean;
1076 user_id_x number;
1077 the_module varchar2(2000);
1078 the_filename varchar2(2000);
1079 nrows  number;
1080 
1081 begin
1082 if icx_sec.validateSession
1083 then
1084    made_changes     := TRUE;
1085    purged           := FALSE;
1086    go_back_to_prefs := TRUE;
1087 
1088    the_module := module;
1089    /* strip whitespace */
1090 
1091    /* Per bug 1687209, the following line was modified to use fnd_global.local_chr() instead of chr() */
1092    -- the_module := translate(the_module, chr(9)||chr(10)||chr(13), '   ');
1093    the_module := translate(the_module, fnd_global.local_chr(9)||fnd_global.local_chr(10)||fnd_global.local_chr(13), '   ');
1094    the_module := rtrim(ltrim(the_module));
1095 
1096    the_filename := filename;
1097    /* strip whitespace */
1098 
1099     /* Per bug 1687209, the following line was modified to use fnd_global.local_chr() instead of chr() */
1100    the_filename := translate(the_filename, fnd_global.local_chr(9)||fnd_global.local_chr(10)||fnd_global.local_chr(13), '   ');
1101    the_filename := rtrim(ltrim(the_filename));
1102 
1103    htp.p('<html>');
1104 
1105    if(syssave is not null) then /* If user pressed system save button */
1106       if(ENABLED = 'on') then
1107          result1 := FND_PROFILE.SAVE('AFLOG_ENABLED', 'Y', 'SITE');
1108       else
1109          result1 := FND_PROFILE.SAVE('AFLOG_ENABLED', 'N', 'SITE');
1110       end if;
1111       result2 := FND_PROFILE.SAVE('AFLOG_FILENAME', THE_FILENAME, 'SITE');
1112       result3 := FND_PROFILE.SAVE('AFLOG_LEVEL', LEVEL, 'SITE');
1113       result4 := FND_PROFILE.SAVE('AFLOG_MODULE', THE_MODULE, 'SITE');
1114       internal_check_results(result1, result2, result3, result4);
1115       commit;
1116       fnd_log_repository.init;
1117       htp.p('<B>Saved Site Level information.  </B>');
1118    elsif(save is not null) then /* If user pressed user save  */
1119       if(user_id is not NULL) then
1120          user_id_x := user_id;
1121       else
1122          user_id_x := FND_GLOBAL.USER_ID;
1123       end if;
1124       if(ENABLED = 'on') then
1125          result1 := FND_PROFILE.SAVE('AFLOG_ENABLED', 'Y', 'USER', user_id_x);
1126       else
1127          result1 := FND_PROFILE.SAVE('AFLOG_ENABLED', 'N', 'USER', user_id_x);
1128       end if;
1129       result2 := FND_PROFILE.SAVE('AFLOG_FILENAME', THE_FILENAME, 'USER',
1130                 user_id_x);
1131       result3 := FND_PROFILE.SAVE('AFLOG_LEVEL', LEVEL, 'USER', user_id_x);
1132       result4 := FND_PROFILE.SAVE('AFLOG_MODULE', THE_MODULE, 'USER',
1133                 user_id_x);
1134       internal_check_results(result1, result2, result3, result4);
1135       commit;
1136       fnd_log_repository.init;
1137       htp.p('<B>Saved User Level information.  </B>');
1138    elsif (sysclearprefs is not null) then /* If user pressed sysclearprefs*/
1139       result1 := FND_PROFILE.SAVE('AFLOG_ENABLED', '', 'SITE');
1140       result2 := FND_PROFILE.SAVE('AFLOG_FILENAME', '', 'SITE');
1141       result3 := FND_PROFILE.SAVE('AFLOG_LEVEL', '', 'SITE');
1142       result4 := FND_PROFILE.SAVE('AFLOG_MODULE', '', 'SITE');
1143       internal_check_results(result1, result2, result3, result4);
1144       commit;
1145       fnd_log_repository.init;
1146       htp.p('<B>Cleared site level information.</B>');
1147    elsif (clearprefs is not null) then /* If user pressed clearprefs */
1148       if(user_id is not NULL) then
1149          user_id_x := user_id;
1150       else
1151          user_id_x := FND_GLOBAL.USER_ID;
1152       end if;
1153       result1 := FND_PROFILE.SAVE('AFLOG_ENABLED',  '', 'USER', user_id_x);
1154       result2 := FND_PROFILE.SAVE('AFLOG_FILENAME', '', 'USER', user_id_x);
1155       result3 := FND_PROFILE.SAVE('AFLOG_LEVEL',    '', 'USER', user_id_x);
1156       result4 := FND_PROFILE.SAVE('AFLOG_MODULE',   '', 'USER', user_id_x);
1157       internal_check_results(result1, result2, result3, result4);
1158       commit;
1159       fnd_log_repository.init;
1160       htp.p('<B>Cleared user level information.</B>');
1161    elsif (sysclearsessionlog is not null) then /* if user pressed... */
1162       nrows := FND_LOG_ADMIN.DELETE_BY_SESSION(to_number(SESSION_TO_PURGE));
1163       commit;
1164       htp.p('<B>Purged '|| nrows ||' rows of log data for session '
1165            ||SESSION_TO_PURGE||'.</B>');
1166       purged := TRUE;
1167    elsif (clearsessionlog is not null) then /* if user pressed... */
1168       if(user_id is not NULL) then
1169          user_id_x := user_id;
1170       else
1171          user_id_x := FND_GLOBAL.USER_ID;
1172       end if;
1173       nrows := FND_LOG_ADMIN.DELETE_BY_USER_SESSION(user_id_x,
1174                                    icx_sec.getsessioncookie());
1175       commit;
1176       htp.p('<B>Purged '|| nrows || ' rows of log data for this session.</B>');
1177       purged := TRUE;
1178    elsif (sysclearuserlog is not null) then /* if user pressed... */
1179       user_id_x := NULL;
1180       begin
1181         select user_id into user_id_x from fnd_user
1182           where user_name = upper(USER_TO_PURGE);
1183       exception
1184         when no_data_found then
1185            htp.p('Invalid username entered.  Enter a valid username.');
1186            user_id_x := NULL;
1187       end;
1188       if(user_id_x is not NULL) then
1189          nrows := FND_LOG_ADMIN.DELETE_BY_USER(user_id_x);
1190          commit;
1191          htp.p('<B><P>Purged '|| nrows|| ' rows of log data for user '
1192                 ||USER_TO_PURGE||'.</P></B>');
1193          purged := TRUE;
1194       else
1195          made_changes := FALSE;
1196       end if;
1197    elsif (syspurgeallusers is not null) then /* if user pressed... */
1198       nrows := FND_LOG_ADMIN.DELETE_ALL;
1199       commit;
1200       htp.p('<B>Purged '|| nrows||
1201             ' rows of log data for all users, all sessions.</B>');
1202       purged := TRUE;
1203    elsif (syssetuserprefs is not null) then /* if user pressed... */
1204       user_id_x := NULL;
1205       begin
1206         select user_id into user_id_x from fnd_user
1207           where user_name = upper(USER_TO_SET);
1208       exception
1209         when no_data_found then
1210            htp.p('Invalid username entered.  Enter a valid username.');
1211            user_id_x := NULL;
1212       end;
1213       if(user_id_x is not NULL) then
1214          fnd_logview.preferences_generic('U', user_id_x);
1215          go_back_to_prefs := FALSE;
1216       end if;
1217       made_changes := FALSE;
1218    elsif (clearuserlog is not null) then /* if user pressed... */
1219       if(user_id is not NULL) then
1220          user_id_x := user_id;
1221       else
1222          user_id_x := FND_GLOBAL.USER_ID;
1223       end if;
1224       nrows := FND_LOG_ADMIN.DELETE_BY_USER(user_id_x);
1225       commit;
1226       purged := TRUE;
1227       htp.p('<B><P>Purged '|| nrows ||
1228             ' rows of log data for this user.</P></B>');
1229    else
1230       htp.p('<B><P>Internal Error- update_prefs call missing args.</P></B>');
1231       htp.p('<B><P>No data was changed.</P></B>');
1232    end if;
1233    if ((made_changes) and (not purged)) then
1234       htp.p('<P>This change will be in effect upon switching responsibility.</P>');
1235    end if;
1236 
1237    if((save is not NULL) or (clear is not NULL) or (clearprefs is not NULL) or
1238       (clearsessionlog is not NULL) or (clearuserlog is not NULL)) then
1239       if(user_id_x is not NULL) then
1240          if(user_id is NULL) then
1241            fnd_logview.preferences_generic('U');
1242          else
1243            fnd_logview.preferences_generic('U', user_id);
1244          end if;
1245          go_back_to_prefs := FALSE;
1246       end if;
1247    else
1248       if (go_back_to_prefs) then
1249          fnd_logview.preferences_sysadmin;
1250       end if;
1251    end if;
1252 
1253 end if;
1254 exception
1255     when others then
1256         err_num := SQLCODE;
1257         c_error_message := SQLERRM;
1258         select substr(c_error_message, 12, 512) into err_mesg from dual;
1259         icx_util.add_error(err_mesg);
1260         icx_admin_sig.error_screen(err_mesg);
1261 end;
1262 
1263 
1264 
1265 procedure test is
1266    AFLOG_ENABLED   BOOLEAN;
1267    AFLOG_FILENAME  VARCHAR2(255);
1268    AFLOG_LEVEL     NUMBER;
1269    AFLOG_MODULE    VARCHAR2(2000);
1270    SESSION_ID      NUMBER;
1271    USER_ID         NUMBER;
1272 begin
1273 
1274 if icx_sec.validateSession
1275 then
1276     htp.p('<html>');
1277 
1278   FND_LOGVIEW.Update_Prefs('on', null, 3,
1279     'FnD.sRc.FlEx.%, fnd.src.dict.afdict.afdget.start, fnd.src.flex.fdfv.fdfval.dff',
1280     null, null, null, 'Save', null, null, null, null, null, null,
1281             null, null, null, null, null, null);
1282 
1283   if (FND_PROFILE.VALUE('AFLOG_ENABLED') = 'Y') then
1284      aflog_enabled := TRUE;
1285   else
1286      aflog_enabled := FALSE;
1287   end if;
1288 
1289   aflog_filename := FND_PROFILE.VALUE('AFLOG_FILENAME');
1290   aflog_level := to_number(FND_PROFILE.VALUE('AFLOG_LEVEL'));
1291   aflog_module := FND_PROFILE.VALUE('AFLOG_MODULE');
1292   user_id := fnd_profile.value('USER_ID');
1293   session_id :=  icx_sec.getsessioncookie();
1294 
1295   htp.p('<BR> AFLOG_FILENAME='||AFLOG_FILENAME);
1296   htp.p('<BR> AFLOG_LEVEL='||TO_CHAR(AFLOG_LEVEL));
1297   htp.p('<BR> AFLOG_MODULE='||AFLOG_MODULE);
1298   htp.p('<BR> SESSION_ID='||SESSION_ID);
1299   htp.p('<BR> USER_ID='||USER_ID);
1300 
1301   htp.p('<title>'||'Logging system self-test results:'||'</title>');
1302 
1303   htp.p(' <B><P>Note: This test routine clears the log messages for the ');
1304   htp.p('  user and resets the user preferences, so be careful! </P></B>');
1305      if (icx_sec.g_mode_code in ('115J', '115P', 'SLAVE')) then
1306         htp.p('<body bgcolor= "#CCCCCC">');
1307     else
1308         htp.p('<body bgcolor="'||icx_plug_utilities.bgcolor||'">');
1309     end if;
1310 
1311  htp.p('
1312 <H1>Test logging system</H1>
1313 ');
1314 
1315 delete from FND_LOG_MESSAGES where user_id = USER_ID;
1316 commit;
1317 
1318   FND_LOG.STRING(3, 'fnd.src.dict.afdict.afdget.start', '1 (first)');
1319   FND_LOG.STRING(3, 'fnd.src.dict.afdict.afdget.start', '2 ');
1320   FND_LOG.STRING(3, 'fnd.src.flex.fdfvl.fdfval.kff.start', '3 ');
1321   FND_LOG.STRING(4, 'fnd.src.flex.fdfvl.fdfval.kff.start', '4 '||
1322   'Lots of text: (1200 characters or so) '||
1323   '123456789 123456789 123456789 123456789 123456789 -------- '||
1324   '123456789 123456789 123456789 123456789 123456789 -------- '||
1325   '123456789 123456789 123456789 123456789 123456789 -------- '||
1326   '123456789 123456789 123456789 123456789 123456789 -------- '||
1327   '123456789 123456789 123456789 123456789 123456789 -------- '||
1328   '123456789 123456789 123456789 123456789 123456789 -------- '||
1329   '123456789 123456789 123456789 123456789 123456789 -------- '||
1330   '123456789 123456789 123456789 123456789 123456789 -------- '||
1331   '123456789 123456789 123456789 123456789 123456789 -------- '||
1332   '123456789 123456789 123456789 123456789 123456789 -------- '||
1333   '123456789 123456789 123456789 123456789 123456789 -------- '||
1334   '123456789 123456789 123456789 123456789 123456789 -------- '||
1335   '123456789 123456789 123456789 123456789 123456789 -------- '||
1336   '123456789 123456789 123456789 123456789 123456789 -------- '||
1337   '123456789 123456789 123456789 123456789 123456789 -------- '||
1338   '123456789 123456789 123456789 123456789 123456789 -------- '||
1339   '123456789 123456789 123456789 123456789 123456789 -------- '||
1340   '123456789 123456789 123456789 123456789 123456789 -------- '||
1341   '123456789 123456789 123456789 123456789 123456789 -------- '||
1342   '123456789 123456789 123456789 123456789 123456789 -------- '||
1343   '123456789 123456789 123456789 123456789 123456789 -------- '
1344   );
1345   FND_LOG.STRING(5, 'fnd.src.dict.afdict.afdget.start', '5 (last)');
1346   FND_LOG.STRING(3, 'ThisWontLog', 'String that wont log');
1347   FND_LOG.STRING(1, 'fnd.src.dict.afdict.afdget.start', 'String that wont log 2');
1348 
1349   if FND_LOG.TEST(3, 'fnd.src.flex.fdfvl.fdfval.kff.start') then
1350      htp.p('correct- fnd.src.flex.fdfvl.fdfval.kff.start found<BR>');
1351   else
1352      htp.p('incorrect- fnd.src.flex.fdfvl.fdfval.kff.start not found<BR>');
1353   end if;
1354 
1355 
1356   if FND_LOG.TEST(3, 'fnd.src.something.blah.blah') then
1357      htp.p('incorrect- fnd.src.something.blah.blah found<BR>');
1358   else
1359      htp.p('correct- fnd.src.something.blah.blah not found<BR>');
1360   end if;
1361 
1362 
1363   if FND_LOG.TEST(2, 'fnd.src.flex.fdfvl.fdfval.kff.start') then
1364      htp.p('incorrect- fnd.src.flex.fdfvl.fdfval.kff.start found at level 2<BR>');
1365   else
1366      htp.p('correct- fnd.src.flex.fdfvl.fdfval.kff.start not found at level 2<BR>');
1367   end if;
1368 
1369 
1370   FND_LOGVIEW.Display(3, 'fnd.src.%',
1371            null, null, null, null, null, 'Find');
1372 
1373 end if;  --icx_sec.validatesession
1374 
1375 exception
1376     when others then
1377         htp.p(SQLERRM);
1378 end;
1379 
1380 end fnd_logview;