DBA Data[Home] [Help]

PACKAGE BODY: APPS.WF_PREF

Source


1 package body WF_PREF as
2 /* $Header: wfprfb.pls 120.3 2006/10/04 09:42:18 hgandiko ship $ */
3 
4 
5 --
6 -- Package Globals
7 --
8 
9 --
10 -- Error (PRIVATE)
11 --   Print a page with an error message.
12 --   Errors are retrieved from these sources in order:
13 --     1. wf_core errors
14 --     2. Oracle errors
15 --     3. Unspecified INTERNAL error
16 --
17 procedure Error
18 as
19 begin
20     null;
21 end Error;
22 
23 /*===========================================================================
24 
25 Function        get_open_lov_window_html
26 
27 Purpose         Get the javascript function to open a lov window based on
28                 a url and a window size.
29 
30 ============================================================================*/
31 PROCEDURE get_open_lov_window_html IS
32 
33 BEGIN
34 
35    htp.p('<SCRIPT LANGUAGE="JavaScript"> <!-- hide the script''s contents from feeble browsers');
36 
37    htp.p(
38       'function fnd_open_dm_window(x,y)
39        {
40           window.focus();
41           document.WF_PREF.p_dm_home.value = x + '':''+ y;
42        }'
43    );
44 
45    htp.p('<!-- done hiding from old browsers --> </SCRIPT>');
46 
47    htp.p('<NOSCRIPT>' || WF_CORE.Translate('WFA_NOSCRIPT') || '</NOSCRIPT>');
48 
49    EXCEPTION
50    WHEN OTHERS THEN
51       Wf_Core.Context('wf_pref',
52                       'get_open_lov_window_html');
53       RAISE;
54 
55 END get_open_lov_window_html;
56 
57 -- Javascript function to validate new passwords
58 -- Bug# 2127392
59 
60 PROCEDURE validate_password IS
61 
62 BEGIN
63 
64    htp.p('<SCRIPT LANGUAGE="JavaScript"> <!-- hide the script''s contents from feeble browsers');
65 
66    htp.p(
67       'function form_submit()
68        {
69           var l_submit = true;
70           if ( document.WF_PREF.p_ldap_npwd.value.length > 0 || document.WF_PREF.p_ldap_rpwd.value.length > 0 )
71           {
72              if ( document.WF_PREF.p_ldap_npwd.value.length < 5 )
73              {
74                  l_submit = false;
75                  window.alert("' || wf_core.translate('WFPREF_LDAP_PASSWORD_LEN') ||'");
76                  document.WF_PREF.p_ldap_npwd.focus();
77              }
78              else if( document.WF_PREF.p_ldap_npwd.value != document.WF_PREF.p_ldap_rpwd.value )
79              {
80                  l_submit = false;
81                  window.alert("' || wf_core.translate('WFPREF_LDAP_PASSWORD_MISMATCH') || '");
82                  document.WF_PREF.p_ldap_rpwd.focus();
83              }
84            }
85            if ( l_submit == true)
86               document.WF_PREF.submit();
87        }'
88    );
89 
90    htp.p('<!-- done hiding from old browsers --> </SCRIPT>');
91 
92    htp.p('<NOSCRIPT>' || WF_CORE.Translate('WFA_NOSCRIPT') || '</NOSCRIPT>');
93 
94    EXCEPTION
95    WHEN OTHERS THEN
96       Wf_Core.Context('wf_pref',
97                       'validate_password');
98       RAISE;
99 
100 END validate_password;
101 
102 
103 procedure create_reg_button (
104 when_pressed_url  IN VARCHAR2,
105 onmouseover       IN VARCHAR2,
106 icon_top          IN VARCHAR2,
107 icon_name         IN VARCHAR2,
108 show_text         IN VARCHAR2)
109 IS
110 
111 onmouseover_text varchar2(240) := null;
112 
113 BEGIN
114 
115     wfa_html.create_reg_button (when_pressed_url, onmouseover, icon_top, icon_name, show_text);
116 
117 exception
118   when others then
119     rollback;
120     wf_core.context('Wf_Pref', 'create_reg_button',when_pressed_url,onmouseover,
121                     icon_top,icon_name,show_text);
122     wf_pref.Error;
123 
124 end create_reg_button;
125 
126 --
127 -- Edit
128 --   Edit user preferences
129 --
130 procedure edit (edit_defaults in varchar2)
131 is
132 begin
133   null;
134 exception
135   when others then
136     rollback;
137     wf_core.context('Wf_Pref', 'Edit', edit_defaults);
138     wf_pref.Error;
139 end edit;
140 
141 --
142 -- Edit
143 --   Edit user preferences
144 --
145 procedure edit_form (edit_defaults in varchar2)
146 is
147 begin
148   null;
149 exception
150   when others then
151     rollback;
152     wf_core.context('Wf_Pref', 'Edit_Form', edit_defaults);
153     wf_pref.Error;
154 end edit_form;
155 
156 --
157 -- Lang_LOV
158 --   Create the data for the Language List of Values
159 --
160 procedure Lang_LOV (p_titles_only   IN VARCHAR2,
161                     p_find_criteria IN VARCHAR2)
162 
163 IS
164 
165 l_username VARCHAR2(320);
166 l_code      VARCHAR2(4);
167 l_language  VARCHAR2(30);
168 l_territory VARCHAR2(30);
169 l_row_count NUMBER := 0;
170 
171 CURSOR c_lang_lov (c_find_criteria IN VARCHAR2) IS
172 SELECT nls_language, nls_territory, code
173 FROM   wf_languages
174 WHERE  nls_language like c_find_criteria
175 AND    installed_flag = 'Y'
176 ORDER  BY nls_language;
177 
178 BEGIN
179    -- Authenticate user
180    wfa_sec.GetSession(l_username);
181 
182    IF (p_titles_only = 'N') THEN
183 
184       SELECT COUNT(*)
185       INTO   l_row_count
186       FROM   wf_languages
187       WHERE  nls_language like p_find_criteria||'%'
188       AND    installed_flag = 'Y';
189 
190    END IF;
191 
192    htp.p(wf_core.translate('WFPREF_LANGUAGE_PROMPT'));
193    htp.p('3');
194    htp.p(TO_CHAR(l_row_count));
195    htp.p(wf_core.translate('WFPREF_LANGUAGE_PROMPT'));
196    htp.p('50');
197    htp.p(wf_core.translate('WFPREF_TERRITORY_PROMPT'));
198    htp.p('50');
199    htp.p('CODE');
200    htp.p('0');
201 
202    IF (p_titles_only = 'N') THEN
203 
204       OPEN c_lang_lov (p_find_criteria||'%');
205 
206       /*
207       ** Loop through all the language rows for the given find_criteria
208       ** and write them out to the web page
209       */
210       LOOP
211 
212          FETCH c_lang_lov INTO
213              l_language, l_territory, l_code;
214 
215          EXIT WHEN c_lang_lov%NOTFOUND;
216 
217          htp.p (l_language);
218          htp.p (l_territory);
219          htp.p (l_code);
220 
221       END LOOP;
222 
223    END IF;
224 
225 exception
226   when others then
227     rollback;
228     wf_core.context('Wf_Pref', 'lang_lov',p_titles_only, p_find_criteria);
229     wf_pref.Error;
230 END lang_lov;
231 
232 --
233 -- Terr_LOV
234 --   Create the data for the Territories List of Values
235 --
236 procedure Terr_LOV (p_titles_only   IN VARCHAR2,
237                     p_find_criteria IN VARCHAR2)
238 
239 IS
240 
241 l_code      VARCHAR2(4);
242 l_territory VARCHAR2(30);
243 l_language  VARCHAR2(30);
244 l_row_count NUMBER := 0;
245 l_username  VARCHAR2(320);
246 
247 CURSOR c_Terr_lov (c_find_criteria IN VARCHAR2) IS
248 SELECT
249  nls_territory,
250  nls_language,
251  code
252 FROM   wf_languages
253 WHERE  nls_territory like c_find_criteria
254 AND    installed_flag = 'Y'
255 ORDER  BY nls_language;
256 
257 BEGIN
258 
259    -- Authenticate user
260    wfa_sec.GetSession(l_username);
261 
262    IF (p_titles_only = 'N') THEN
263 
264       SELECT COUNT(*)
265       INTO   l_row_count
266       FROM   wf_languages
267       WHERE  nls_territory like p_find_criteria||'%'
268       AND    installed_flag = 'Y';
269 
270    END IF;
271 
272    htp.p(wf_core.translate('WFPREF_TERRITORY_PROMPT'));
273    htp.p('3');
274    htp.p(TO_CHAR(l_row_count));
275    htp.p(wf_core.translate('WFPREF_TERRITORY_PROMPT'));
276    htp.p('50');
277    htp.p(wf_core.translate('WFPREF_LANGUAGE_PROMPT'));
278    htp.p('50');
279    htp.p('Code');
280    htp.p('0');
281 
282    IF (p_titles_only = 'N') THEN
283 
284       OPEN c_Terr_lov (p_find_criteria||'%');
285 
286       /*
287       ** Loop through all the language rows for the given find_criteria
288       ** and write them out to the web page
289       */
290       LOOP
291 
292          FETCH c_Terr_lov INTO
293              l_territory, l_language, l_code;
294 
295          EXIT WHEN c_Terr_lov%NOTFOUND;
296 
297          htp.p (l_territory);
298          htp.p (l_language);
299          htp.p (l_code);
300 
301       END LOOP;
302 
303    END IF;
304 
305 exception
306   when others then
307     rollback;
308     wf_core.context('Wf_Pref', 'Terr_lov',p_titles_only, p_find_criteria);
309     wf_pref.Error;
310 END terr_lov;
311 
312 --
313 -- DM_LOV
314 --   Create the data for the Territories List of Values
315 --
316 procedure DM_LOV (p_titles_only   IN VARCHAR2,
317                   p_find_criteria IN VARCHAR2)
318 
319 IS
320 
321 l_username  VARCHAR2(320);
322 l_node_id   NUMBER;
323 l_node_name VARCHAR2(80);
324 l_node_desc VARCHAR2(240);
325 l_row_count NUMBER := 0;
326 
327 CURSOR c_dm_lov (c_find_criteria IN VARCHAR2) IS
328 SELECT
329 node_id,
330 node_name,
331 node_description
332 FROM   fnd_dm_nodes
333 WHERE  node_name like p_find_criteria||'%'
334 ORDER  BY node_name;
335 
336 BEGIN
337 
338    -- Authenticate user
339    wfa_sec.GetSession(l_username);
340 
341    IF (p_titles_only = 'N') THEN
342 
343       SELECT COUNT(*)
344       INTO   l_row_count
345       FROM   fnd_dm_nodes
346       WHERE  node_name like p_find_criteria||'%';
347 
348    END IF;
349 
350    htp.p(wf_core.translate('WFPREF_DMHOME_PROMPT'));
351    htp.p('3');
352    htp.p(TO_CHAR(l_row_count));
353    htp.p(wf_core.translate('WFPREF_DMHOME_PROMPT'));
354    htp.p('40');
355    htp.p(wf_core.translate('DESCRIPTION'));
356    htp.p('60');
357    htp.p('NODE_ID');
358    htp.p('0');
359 
360    IF (p_titles_only = 'N') THEN
361 
362       OPEN c_dm_lov (p_find_criteria||'%');
363 
364       /*
365       ** Loop through all the language rows for the given find_criteria
366       ** and write them out to the web page
367       */
368       LOOP
369 
370          FETCH c_dm_lov INTO
371              l_node_id, l_node_name,l_node_desc;
372 
373          EXIT WHEN c_dm_lov%NOTFOUND;
374 
375          htp.p (l_node_name);
376          htp.p (l_node_desc);
377          htp.p (TO_CHAR(l_node_id));
378 
379       END LOOP;
380 
381    END IF;
382 
383 exception
384   when others then
385     rollback;
386     wf_core.context('Wf_Pref', 'DM_lov',p_titles_only, p_find_criteria);
387     wf_pref.Error;
388 END DM_LOV;
389 
390 
391 PROCEDURE update_pref (
392 p_admin_role            IN VARCHAR2,
393 p_display_admin_role    IN VARCHAR2,
394 p_web_agent             IN VARCHAR2,
395 p_edit_defaults         IN VARCHAR2,
396 p_language              IN VARCHAR2,
397 p_territory             IN VARCHAR2,
398 p_date_format           IN VARCHAR2,
399 p_dm_node_id            IN VARCHAR2,
400 p_dm_home               IN VARCHAR2,
401 p_mailtype              IN VARCHAR2,
402 p_classid               IN VARCHAR2,
403 p_plugin_loc            IN VARCHAR2,
404 p_plugin_ver            IN VARCHAR2,
405 p_system_guid           IN VARCHAR2,
406 p_system_name           IN VARCHAR2,
407 p_system_status         IN VARCHAR2,
408 p_ldap_host             IN VARCHAR2,
409 p_ldap_port             IN VARCHAR2,
410 p_ldap_user             IN VARCHAR2,
411 p_ldap_opwd             IN VARCHAR2,
412 p_ldap_npwd             IN VARCHAR2,
413 p_ldap_rpwd             IN VARCHAR2,
414 p_ldap_log_base         IN VARCHAR2,
415 p_ldap_user_base        IN VARCHAR2,
416 p_text_signon           IN VARCHAR2
417 ) IS
418 
419 BEGIN
420   null;
421 END update_pref;
422 
423 --update_pref for OA FWK UI. This is Framework specific API that gives
424 --validation errors using out parameter p_err_msg. Exceptions are
425 --wrapped in OAF.
426 
427 PROCEDURE update_pref_fwk (
428 p_admin_role            IN VARCHAR2,
429 p_display_admin_role    IN VARCHAR2,
430 p_web_agent             IN VARCHAR2,
431 p_edit_defaults         IN VARCHAR2,
432 p_language              IN VARCHAR2,
433 p_territory             IN VARCHAR2,
434 p_date_format           IN VARCHAR2,
435 p_dm_node_id            IN VARCHAR2,
436 p_dm_home               IN VARCHAR2,
437 p_mailtype              IN VARCHAR2,
438 p_classid               IN VARCHAR2,
439 p_plugin_loc            IN VARCHAR2,
440 p_plugin_ver            IN VARCHAR2,
441 p_system_guid           IN VARCHAR2,
442 p_system_name           IN VARCHAR2,
443 p_system_status         IN VARCHAR2,
444 p_ldap_host             IN VARCHAR2,
445 p_ldap_port             IN VARCHAR2,
446 p_ldap_user             IN VARCHAR2,
447 p_ldap_opwd             IN VARCHAR2,
448 p_ldap_npwd             IN VARCHAR2,
449 p_ldap_rpwd             IN VARCHAR2,
450 p_ldap_log_base         IN VARCHAR2,
451 p_ldap_user_base        IN VARCHAR2,
452 p_text_signon           IN VARCHAR2,
453 p_num_format            IN VARCHAR2,
454 p_browser_dll_loc       IN VARCHAR2,
455 p_err_msg               OUT NOCOPY VARCHAR2
456 ) IS
457 
458   l_row_count   number := 0;
459   l_combo_count number := 0;
460   l_dm_node_id  number;
461   l_name        varchar2(320);   -- Username to query
462   username      varchar2(320);   -- Username to query
463   realname      varchar2(360);  -- Display name of username
464   admin_role    varchar2(320);   -- Role for admin mode
465   admin_mode    varchar2(1);    -- Does user have admin privledges
466   s0            varchar2(2000);
467   l_url         varchar2(240);
468   l_test_date   varchar2(40);
469   l_media       varchar2(240) := wfa_html.image_loc;
470   l_icon        varchar2(30) := 'FNDILOV.gif';
471   l_text        varchar2(30) := '';
472   l_onmouseover varchar2(240)  := wf_core.translate ('WFPREF_LOV');
473   l_error_msg   varchar2(2000) := NULL;
474   l_sguid       raw(16);
475   rowid         varchar2(30);
476 
477   /* Bug 2127392 */
478   l_ldap_error  varchar2(2000) := NULL;
479   l_ldap_pwd    varchar2(30);
480   l_ldap_opwd   varchar2(30);
481 BEGIN
482   l_ldap_opwd := p_ldap_opwd;
483 
484   -- wfa_sec.GetSession(username) cannot be used from Framework, Use GetFWKUserName instead
485   username := wfa_sec.GetFWKUserName;
486   username := upper(username);
487   wf_directory.GetRoleInfo(username, realname, s0, s0, s0, s0);
488   IF (p_edit_defaults = 'Y') THEN
489      admin_mode := 'N';
490      admin_role := wf_core.translate('WF_ADMIN_ROLE');
491      if (admin_role = '*' or
492          Wf_Directory.IsPerformer(username, admin_role)) then
493          admin_mode := 'Y';
494          username := '-WF_DEFAULT-';
495      else
496          -- cannot edit defaults unless you're the administrator
497          l_error_msg := wf_core.translate('WFPREF_INVALID_ADMIN');
498 
502 
499      end if;
500 
501   END IF;
503   -- Validate the language preference
504   IF (p_language IS NOT NULL) THEN
505 
506      SELECT count(*)
507      INTO   l_row_count
508      FROM   wf_languages
509      WHERE  nls_language = p_language
510      AND    installed_flag = 'Y';
511 
512   ELSE
513 
514     -- If there is no value then set it to null
515     l_row_count := 1;
516 
517   END IF;
518 
519   -- Validate the combination of language/territory preferences are valid
520   IF (p_language IS NOT NULL AND l_row_count <> 0
521        AND p_territory IS NOT NULL) THEN
522 
523      SELECT count(*)
524      INTO   l_combo_count
525      FROM   wf_languages
526      WHERE  nls_language = p_language
527      AND    nls_territory = p_territory
528      AND    installed_flag = 'Y';
529 
530      IF (l_combo_count = 0) THEN
531 
532          l_error_msg := wf_core.translate ('WFPREF_INVALID_COMBO');
533 
534      END IF;
535 
536 
537   END IF;
538 
539   IF (l_row_count > 0) THEN
540 
541      IF (l_combo_count > 0) THEN
542 
543        -- put the language preference
544        fnd_preference.put (username, 'WF', 'LANGUAGE', p_language);
545 
546      END IF;
547 
548   ELSE
549 
550      l_error_msg := wf_core.translate ('WFPREF_INVALID_LANGUAGE');
551 
552   END IF;
553 
554   -- Validate the territory preference
555   IF (p_territory IS NOT NULL) THEN
556 
557      SELECT count(*)
558      INTO   l_row_count
559      FROM   wf_languages
560      WHERE  nls_territory = p_territory
561      AND    installed_flag = 'Y';
562 
563   ELSE
564 
565     -- If there is no value then set it to null
566     l_row_count := 1;
567 
568   END IF;
569 
570   IF (l_row_count > 0) THEN
571 
572      IF (l_combo_count > 0) THEN
573 
574         -- put the territory preference
575         fnd_preference.put (username, 'WF', 'TERRITORY', p_territory);
576 
577      END IF;
578 
579   ELSE
580 
581      l_error_msg := wf_core.translate ('WFPREF_INVALID_TERRITORY');
582 
583   END IF;
584 
585   -- Validate the date format
586   BEGIN
587 
588      SELECT TO_CHAR(sysdate, RTRIM(p_date_format))
589      INTO   l_test_date
590      FROM   dual;
591 
592      EXCEPTION
593      WHEN OTHERS THEN
594           l_error_msg :=  wf_core.translate ('WFPREF_INVALID_DATE_FORMAT') ||
595                 ': ' || p_date_format;
596 
597   END;
598 
599   IF (l_error_msg IS NULL) THEN
600 
601      -- put the date format preference
602      -- The rtrim is required if the user adds a blank space at the end
603      -- of the format and we concatenate on a time format with a space then
604      -- the double space will cause an ora-1830 errror.
605      fnd_preference.put (username, 'WF', 'DATEFORMAT', RTRIM(p_date_format));
606 
607   END IF;
608 
609   -- put the number format preference  - Added new parameter for Global preference OAF page
610 
611   IF(p_num_format IS NOT NULL) THEN
612        fnd_preference.put (username, 'WF', 'NUMBERFORMAT', p_num_format);
613   END IF;
614 
615   -- Bug 2589782 Update LDAP info only if Global preference values are
616   -- updated by an Admin
617 
618   IF (p_edit_defaults = 'Y' AND admin_mode = 'Y') THEN
619      -- put the LDAP preferences
620      fnd_preference.put('#INTERNAL', 'LDAP_SYNCH', 'HOST',     p_ldap_host);
621      fnd_preference.put('#INTERNAL', 'LDAP_SYNCH', 'PORT',     p_ldap_port);
622      fnd_preference.put('#INTERNAL', 'LDAP_SYNCH', 'USERNAME', p_ldap_user);
623 
624      -- Bug 2127392 Validating LDAP password
625 
626      l_ldap_pwd  := fnd_preference.eget('#INTERNAL','LDAP_SYNCH', 'EPWD', 'LDAP_PWD');
627 
628      IF (l_ldap_opwd is NULL) THEN
629         l_ldap_opwd := 'x';
630      END IF;
631      IF (l_ldap_pwd is NULL) THEN
632         l_ldap_pwd := 'x';
633      END IF;
634 
635      IF (l_ldap_opwd <> 'x' OR length(p_ldap_rpwd) > 0) THEN
636         IF (l_ldap_pwd <> l_ldap_opwd) THEN
637            l_ldap_error := wf_core.translate ('WFPREF_INVALID_LDAP_PASSWORD');
638         END IF;
639 
640         -- New password updated only if the Old password is valid
641         IF (l_ldap_error IS NULL) THEN
642             fnd_preference.eput('#INTERNAL','LDAP_SYNCH', 'EPWD', p_ldap_rpwd,
643                                 'LDAP_PWD');
644         ELSE
645             l_error_msg := l_ldap_error;
646         END IF;
647      END IF;
648 
649      fnd_preference.put('#INTERNAL', 'LDAP_SYNCH', 'CHANGELOG_DIR', p_ldap_log_base);
650      fnd_preference.put('#INTERNAL', 'LDAP_SYNCH', 'USER_DIR', p_ldap_user_base);
651 
652   END IF;
653 
654   -- put the mail preference
655   fnd_preference.put (username, 'WF', 'MAILTYPE', p_mailtype);
656 
657   -- put the text only mail preference
661   --IF (p_browser_dll_loc IS NOT NULL) THEN // not required
658   fnd_preference.put (username, 'WF', 'WF_SIG_TEXT_ONLY', p_text_signon);
659 
660   -- put the browser signing DLL location preference  - Added new parameter for Global preference OAF page
662    fnd_preference.put (username, 'WF', 'WF_SIG_IE_DLL', p_browser_dll_loc);
663   --END IF;
664 
665   -- put the dm home node preference
666   fnd_document_management.set_dm_home (username, l_dm_node_id);
667 
668 
669    IF (admin_mode = 'Y') THEN
670 
671       -- Check the admin role
672       IF (p_display_admin_role <> '*') THEN
673 
674          admin_role := p_admin_role;
675          -- Get all the username find criteria resolved
676          -- rajaagra march-3-2004 bug 4185567
677          -- wfa_html.validate_display_name (p_display_admin_role, admin_role);
678 
679          BEGIN
680 
681             wf_directory.GetRoleInfo(UPPER(admin_role), realname, s0, s0, s0, s0);
682             if (realname IS NULL) then
683 
684                l_name := NULL;
685 
686             else
687 
688                l_name := UPPER(admin_role);
689 
690             end if;
691 
692          END;
693 
694       ELSE
695 
696          l_name := '*';
697 
698       END IF;
699 
700       IF (l_name IS NOT NULL) THEN
701 
702          -- Update the admin role
703          UPDATE wf_resources
704          SET    text = UPPER(l_name)
705          WHERE  type = 'WFTKN'
706          AND    name = 'WF_ADMIN_ROLE';
707 
708       ELSE
709         l_error_msg := wf_core.translate ('WFPREF_INVALID_ROLE_NAME')||
710                  ': ' || UPPER(p_display_admin_role);
711 
712       END IF;
713 
714       -- Update the web agent
715       UPDATE wf_resources
716       SET    text = p_web_agent
717       WHERE  type = 'WFTKN'
718       AND    name = 'WF_WEB_AGENT';
719 
720       /*
721        ** Bug 2307342
722        ** It is no longer possible to update jinitiator info
723        ** from the Global Preferences page
724 
725       -- Update the jinitiator info
726       UPDATE wf_resources
727       SET    text = p_classid
728       WHERE  type = 'WFTKN'
729       AND    name = 'WF_CLASSID';
730 
731       UPDATE wf_resources
732       SET    text = p_plugin_loc
733       WHERE  type = 'WFTKN'
734       AND    name = 'WF_PLUGIN_DOWNLOAD';
735 
736       UPDATE wf_resources
737       SET    text = p_plugin_ver
738       WHERE  type = 'WFTKN'
739       AND    name = 'WF_PLUGIN_VERSION';
740 
741       */
742 
743       -- Update/Insert the Local System Info
744       -- validate the system name
745       if p_system_guid is not null then
746         l_sguid := hextoraw(p_system_guid);
747         Wf_Event_Html.Validate_System_Name(p_system_name, l_sguid);
748 
749         -- update the local system guid
750         begin
751           Wf_Resources_Pkg.Update_Row(
752           x_type=>'WFTKN',
753           x_name=>'WF_SYSTEM_GUID',
754           x_protect_level=>0,
755           x_custom_level=>0,
756           x_id=>0,
757           x_text=>rawtohex(l_sguid)
758           );
759         exception
760           when NO_DATA_FOUND then
761             Wf_Resources_Pkg.Insert_Row(
762             x_rowid=>rowid,
763             x_type=>'WFTKN',
764             x_name=>'WF_SYSTEM_GUID',
765             x_protect_level=>0,
766             x_custom_level=>0,
767             x_id=>0,
768             x_text=>rawtohex(l_sguid)
769             );
770         end;
771       end if;
772 
773       -- update the local system status
774       begin
775           Wf_Resources_Pkg.Update_Row(
776           x_type=>'WFTKN',
777           x_name=>'WF_SYSTEM_STATUS',
778           x_protect_level=>0,
779           x_custom_level=>0,
780           x_id=>0,
781           x_text=>p_system_status
782         );
783       exception
784         when NO_DATA_FOUND then
785           Wf_Resources_Pkg.Insert_Row(
786             x_rowid=>rowid,
787             x_type=>'WFTKN',
788             x_name=>'WF_SYSTEM_STATUS',
789             x_protect_level=>0,
790             x_custom_level=>0,
791             x_id=>0,
792             x_text=>p_system_status
793           );
794       end;
795 
796    END IF;
797 
798    IF (l_error_msg IS NULL) THEN
799 
800       p_err_msg := NULL;
801 
802    ELSE
803       -- to be returned back to OAF page
804       p_err_msg := l_error_msg;
805 
806    END IF;
807 exception
808   when others then
809     rollback;
810     wf_core.context('Wf_Pref', 'update_pref',
811                     p_language ,
812                     p_territory   ,
813                     p_admin_role,
814                     p_display_admin_role   );
815    --Since Error procedure cannot be called here, raise the exception so that it can be wrapped in Framework
816    raise;
817 END update_pref_fwk;
818 
819 FUNCTION get_pref
820 (
821 p_user_name        IN  VARCHAR2,
822 p_preference_name  IN  VARCHAR2
823 )  RETURN VARCHAR2 IS
824 
825 l_preference_value    VARCHAR2(240) := NULL;
826 
827 BEGIN
828 
829    -- Check if there is a preference for this user
830    SELECT MAX(PREFERENCE_VALUE)
831    INTO   l_preference_value
832    FROM   FND_USER_PREFERENCES
833    WHERE  USER_NAME = p_user_name
834    AND    PREFERENCE_NAME = p_preference_name
835    AND    MODULE_NAME = 'WF';
836 
837    -- If there is no preference for this user then try to
838    -- get the default
839    IF (l_preference_value IS NULL) THEN
840 
841       SELECT MAX(PREFERENCE_VALUE)
842       INTO   l_preference_value
843       FROM   FND_USER_PREFERENCES
844       WHERE  USER_NAME = '-WF_DEFAULT-'
845       AND    PREFERENCE_NAME = p_preference_name
846       AND    MODULE_NAME = 'WF';
847 
848    END IF;
849 
850    /*
851    ** The following hard code is for the mailer.  The wf_roles view
852    ** defaults the language to the session value if it doesn't find a
853    ** preference.  If the global is not set and one user is set and another
854    ** one isn't then it could cause the next user to receive a message in
855    ** a random laguage.  At least if it's in american we can detect the bug
856    ** and set it to 32.  Yes it's a narrow case but it may prevent a bug
857    */
858 
859    if (l_preference_value IS NULL AND p_preference_name = 'LANGUAGE') THEN
860 
861       l_preference_value := 'AMERICAN';
862 
863    elsif (l_preference_value IS NULL AND p_preference_name = 'TERRITORY') THEN
864 
865       l_preference_value := 'AMERICA';
866 
867    end if;
868 
869    return l_preference_value;
870 
871 END get_pref;
872 
873 end WF_PREF;