DBA Data[Home] [Help]

PACKAGE BODY: APPS.WF_INITIATE

Source


1 package body WF_INITIATE as
2 /* $Header: wfinitb.pls 120.3 2005/10/04 05:16:53 rtodi ship $ */
3 
4 ---
5 procedure Print_Error
6 is
7   error_name	varchar2(30);
8   error_message	varchar2(2000);
9   error_stack	varchar2(32000);
10 begin
11   htp.htmlOpen;
12   htp.headOpen;
13   htp.title(wf_core.translate('ERROR'));
14   htp.headClose;
15   wfa_sec.header(background_only=>TRUE);
16 
17   htp.header(1, wf_core.translate('ERROR'));
18   htp.br;
19   --
20   wf_core.get_error(error_name, error_message, error_stack);
21   if (error_name is not null) then
22 	htp.p(error_message);
23   elsif (sqlcode <> 0) then
24 	htp.p(sqlerrm);
25   end if;
26 
27   htp.br;
28   if (error_stack is not null) then
29 	htp.p(wf_core.translate('WFMON_ERROR_STACK'));
30 	htp.p(replace(error_stack,wf_core.newline,'<br>') || '<br>');
31   end if;
32   --
33   htp.bodyClose;
34   htp.htmlClose;
35   --
36 end Print_Error;
37 
38 --
39 -- GetLookup (PRIVATE)
40 --   Produce a lookup response field
41 -- IN
42 --   name - field name
43 --   value - default value (lookup code)
44 --   format - lookup type
45 --
46 procedure GetLookup(
47   name in varchar2,
48   value in varchar2,
49   format in varchar2,
50   seq    in varchar2)
51 as
52   cursor lookup_codes(p_lookup_type varchar2) is
53     select MEANING, LOOKUP_CODE
54     from   WF_LOOKUPS
55     where  LOOKUP_TYPE = p_lookup_type
56     order by MEANING;
57 
58   template varchar2(4000);
59 
60 begin
61   -- always print the display field as null
62   htp.formHidden('h_fdocnames', '');
63 
64   -- Create hidden field and select list
65   template := htf.formHidden('h_fnames', name||'#LOOKUP#'||format)||
66               wf_core.newline||
67               htf.formSelectOpen('h_fvalues',
68                                   cattributes=>'id="i_attr'||seq||'"');
69 
70   -- Add all lookups to select list
71   for i in lookup_codes(format) loop
72     if (i.lookup_code = value) then
73       template := template||wf_core.newline||
74                   htf.formSelectOption(cvalue=>i.meaning,
75                                        cattributes=>'value='||i.lookup_code,
76 			               cselected=>'SELECTED');
77     else
78       template := template||wf_core.newline||
79                   htf.formSelectOption(cvalue=>i.meaning,
80                                        cattributes=>'value='||i.lookup_code);
81     end if;
82   end loop;
83   template := template||wf_core.newline||htf.formSelectClose;
84   htp.tableData(template, 'left',cattributes=>'id=""');
85 exception
86   when others then
87     wf_core.context('Wf_initiate', 'GetLookup', name, value, format);
88     raise;
89 end GetLookup;
90 
91 -- GetDocument (PRIVATE)
92 -- Prints the document text field with the DM lov button.
93 Procedure GetDocument (name      in varchar2,
94              format    in varchar2,
95              dvalue    in varchar2,
96              index_num in varchar2) is
97 
98    l_username      varchar2(320);   -- Username to query
99    l_callback_URL  varchar2(4000);
100    l_attach_URL    varchar2(4000);
101 begin
102 
103   htp.formHidden('h_fnames', name||'#DOCUMENT#'||format);
104   htp.formHidden('h_fvalues', null);
105 
106   -- Set the destination field name for the document id
107   fnd_document_management.set_document_id_html (
108         null,
109         'WF_INITIATE',
110         'h_fvalues['||index_num||']',
111         'h_fdocnames['||index_num||']',
112         l_callback_url);
113 
114   -- Check session and current user
115   wfa_sec.GetSession(l_username);
116   l_username := upper(l_username);
117 
118   fnd_document_management.get_launch_attach_url (
119         l_username,
120         l_callback_url,
121         TRUE,
122         l_attach_url);
123 
124   -- document field
125   htp.tableData(cvalue=>htf.formText(cname=>'h_fdocnames', csize=>32,
126                                      cmaxlength=>60,
127                                      cvalue=>dvalue,
128                 cattributes=>'id="i_attr'||index_num||'"')
129                 ||'   '||l_attach_URL,
130                 calign=>'Left',
131                 cattributes=>'id=""');
132 
133 exception
134   when others then
135     wf_core.context('Wf_Initiate', 'GetDocument', name, format, dvalue);
136     raise;
137 end GetDocument;
138 
139 --
140 -- GetField (PRIVATE)
141 -- Produce a text response field
142 procedure GetField(
143   name         in varchar2,
144   type         in varchar2,
145   format       in varchar2,
146   dvalue       in varchar2,
147   index_num    in varchar2)
148 is
149   len      pls_integer;
150 begin
151   -- Figure field len
152   if (type = 'VARCHAR2') then
153     len := nvl(to_number(format), 4000);
154   elsif (type = 'DATE') then
155     len := nvl(to_number(length(format)),40);
156   else
157     len := 40;
158   end if;
159 
160   -- Draw field
161   htp.formHidden('h_fnames', name||'#'||type||'#'||format);
162   -- always print the display field as null
163   htp.formHidden('h_fdocnames', '');
164 --
165 -- commented out multi-line field for text
166 --
167 --  if (len <= 80) then
168     -- single line field
169     htp.tableData(
170         cvalue=>htf.formText(cname=>'h_fvalues', csize=>40,
171                              cmaxlength=>len,
172                     cvalue=>replace(dvalue,'&','&'),
173           cattributes=>'id="i_attr'||index_num||'"'),
174         calign=>'Left',
175         cattributes=>'id=""');
176 --  else
177        -- multi line field
178 --        htp.tableData(
179 --         	    cvalue=>htf.formTextareaOpen2(
180 --                            cname=>'h_fvalues',
181 --                            nrows=>2,
182 --                            ncolumns=>40,
183 --                            cwrap=>'SOFT',
184 --                            cattributes=>'maxlength='||to_char(len))||
185 --                            dvalue||
186 --                            htf.formTextareaClose,
187 --                   calign=>'Left',
188 --                   cattributes=>'id=""');
189 --     end if;
190 exception
191   when others then
192     wf_core.context('Wf_Initiate', 'GetField', name, type, format, dvalue,
193       index_num);
194     raise;
195 end GetField;
196 --
197 --
198 -- GetRole (PRIVATE)
199 -- Produce a Role response field
200 procedure GetRole(
201   name         in varchar2,
202   dvalue       in varchar2,
203   seq          in varchar2 )
204 is
205   len       pls_integer;
206 
207 -- variable for LOV
208   l_url    varchar2(1000);
209   l_media  varchar2(240) := wfa_html.image_loc;
210   l_icon   varchar2(30)  := 'FNDILOV.gif';
211   l_text   varchar2(30) := '';
212   l_message varchar2(240) := null;
213 
214 --
215 begin
216   -- Draw field
217   htp.formHidden('h_fnames', name||'#ROLE#');
218   -- always print the display field as null
219   htp.formHidden('h_fvalues', null);
220 
221   -- add LOV here: Note:bottom is name of frame.
222   -- Note: The REPLACE function replaces all the space characters with
223   -- the proper escape sequence.
224   l_url := 'javascript:fnd_open_dm_display_window('||''''||
225             REPLACE('wf_lov.display_lov?p_lov_name='||'owner'||
226             '&p_display_name='||'WFA_FIND_USER'||
227             '&p_validation_callback=wfa_html.wf_user_val'||
228             '&p_dest_hidden_field=top.opener.parent.document.WF_INITIATE.h_fvalues['||seq||'].value'||
229             '&p_current_value=top.opener.parent.document.WF_INITIATE.h_fdocnames['||seq||'].value'||
230             '&p_display_key='||'Y'||
231             '&p_dest_display_field=top.opener.parent.document.WF_INITIATE.h_fdocnames['||seq||'].value',
232              ' ', '%20')||''''||',500,500)';
233 
234   l_message := wf_core.translate ('WFPREF_LOV');
235 
236   -- print everything together so ther is no gap.
237   htp.tabledata(htf.formText(cname=>'h_fdocnames',
238                 csize=>30,
239                 cmaxlength=>240,
240                 cvalue=>dvalue,
241                 cattributes=>'id="i_attr'||seq||'"')||
242                '<A href='||l_url||'>'||
243                '<IMG src="'||l_media||l_icon||'" border=0 alt="'||
244                     l_message||'" onmouseover="window.status='||''''||
245                     l_message||''''||';return true"></A>',
246                   cattributes=>'id=""');
247 
248 exception
249   when others then
250     wf_core.context('Wf_initiate', 'GetRole', name, seq);
251     raise;
252 end GetRole;
253 
254 
255 --
256 -- GetLookupMeaning (PRIVATE)
257 --   Retrieve displayed value of lookup
258 -- IN
259 --   ltype - lookup type
260 --   lcode - lookup code
261 -- RETURNS
262 --   Displayed meaning of lookup code
263 --
264 function GetLookupMeaning(
265   ltype in varchar2,
266   lcode in varchar2)
267 return varchar2
268 is
269   meaning varchar2(80);
270   cursor lov_lookup is
271   select WL.MEANING
272   from WF_LOOKUPS WL
273   where WL.LOOKUP_TYPE = GetLookupMeaning.ltype
274   and WL.LOOKUP_CODE = GetLookupMeaning.lcode;
275 
276 begin
277   open lov_lookup;
278   fetch lov_lookup into meaning;
279   close lov_lookup;
280 
281   if meaning is null then
282      meaning :=lcode;
283   end if;
284 
285   return(meaning);
286 exception
287   when others then
288     wf_core.context('Wf_initiate', 'GetLookupMeaning', ltype, lcode);
289     raise;
290 end GetLookupMeaning;
291 
292 
293 --
294 -- GetDisplayValue (PRIVATE)
295 --   Get displayed value of a response field
296 -- IN
297 --   type - field type (VARCHAR2, NUMBER, DATE, LOOKUP, URL)
298 --   format - field format (depends on type)
299 --   tvalue - text value
300 --   nvalue - number value
301 --   dvalue - date value
302 -- RETURNS
303 --   Displayed value
304 --
305 function GetDisplayValue(
306   type in varchar2,
307   format in varchar2,
308   tvalue in varchar2,
309   nvalue in number,
310   dvalue in date)
311 return varchar2
312 is
313   value varchar2(4000);
314 begin
315   if (type = 'VARCHAR2') then
316     value := tvalue;
317   elsif (type = 'NUMBER') then
318     if (format is null) then
319       value := to_char(nvalue);
320     else
321       value := to_char(nvalue, format);
322     end if;
323   elsif (type = 'DATE') then
324     if (format is null) then
325       value := to_char(dvalue);
326     else
327       value := to_char(dvalue, format);
328     end if;
329   elsif (type = 'LOOKUP') then
330     value := GetLookupMeaning(format, tvalue);
331   elsif (type = 'URL') then
332     value := tvalue;
333   else
334     -- Default to return text value unchanged
335     value := tvalue;
336   end if;
337 
338   return(value);
339 
340 exception
341   when others then
342     wf_core.context('Wf_initiate', 'GetDisplayValue', type, format,
343                     tvalue, to_char(nvalue), to_char(dvalue));
344     raise;
345 end GetDisplayValue;
346 
347 
348 
349 --
350 -- ItemType
351 --
352 -- MODIFICATION LOG:
353 -- 06-JUN-2001 JWSMITH BUG 1819232 -Added summary attr for table tag for ADA
354 --
355 procedure ItemType as
356 
357   username	varchar2(320);
358   admin_role    varchar2(320);  -- Role for admin mode
359   admin_mode    varchar2(1);    -- Does user have admin privledges
360   l_error_msg varchar2(2000) := null;
361 
362   cursor itemtypes is
363   select name, display_name, nvl(description,' ') description
364   from   wf_item_types_vl
365   where  name not in ('WFSTD','WFERROR','WFMAIL')
366   order by name;
367 begin
368   --
369   -- Authenticate user
370   wfa_sec.GetSession(username);
371   username := upper(username);
372   admin_role := wf_core.translate('WF_ADMIN_ROLE');
373   if (admin_role = '*' or
374          Wf_Directory.IsPerformer(username, admin_role)) then
375          admin_mode := 'Y';
376   else
377      l_error_msg := wf_core.translate('WFINIT_INVALID_ADMIN');
378   end if;
379   --
380   -- Header and Page Title
381   --
382   htp.htmlOpen;
383   htp.headOpen;
384   htp.title(wf_core.translate('WFINIT_ITEM_TYPE_TITLE'));
385   wfa_html.create_help_function('wf/links/tes.htm?TESTING');
386   htp.headClose;
387   wfa_sec.header(page_title=>wf_core.translate('WFINIT_ITEM_TYPE_TITLE'));
388   --
389   if (l_error_msg IS NOT NULL) THEN
390      htp.center(htf.bold(l_error_msg));
391      return;
392   end if;
393   --
394   htp.tableOpen(cattributes=>'border=1 cellpadding=1 cellspacing=3 bgcolor=white align=center summary= "' || wf_core.translate('WFINIT_ITEM_TYPE_TITLE') || '"');
395   htp.tableRowOpen(cattributes=>'bgcolor=#006699');
396   htp.tableHeader(cvalue=>'<font color=#FFFFFF>'||
397                          wf_core.translate('ITEMTYPE')||'</font>',
398                 calign=>'center',
399                 cattributes=>'id="' || wf_core.translate('ITEMTYPE') || '"');
400   htp.tableHeader(cvalue=>'<font color=#FFFFFF>'||
401                          wf_core.translate('WFITD_INTERNAL_NAME')||'</font>',
402                 calign=>'center',
403                 cattributes=>'id="' || wf_core.translate('WFITD_INTERNAL_NAME') || '"');
404   htp.tableHeader(cvalue=>'<font color=#FFFFFF>'||
405                          wf_core.translate('DESCRIPTION')||'</font>',
406                 calign=>'center',
407                 cattributes=>'id="' || wf_core.translate('DESCRIPTION') || '"');
408   htp.tableRowClose;
409   --
410   --
411 
412   for typerec in itemtypes loop
413  	htp.tableRowOpen('bgcolor=#ffffcc');
414 
415 	htp.tableData(cvalue=>htf.anchor(wfa_html.base_url
416                               ||'/wf_initiate.Process?ItemType='||wfa_html.conv_special_url_chars(typerec.name),
417 			      ctext=>typerec.display_name),
418                        cattributes=>'headers="' || wf_core.translate('ITEMTYPE') || '"');
419 
420 	htp.tableData(cvalue=>typerec.name,  calign=>'left',
421             cattributes=>'headers="' || wf_core.translate('WFITD_INTERNAL_NAME') || '"');
422 	htp.tableData(cvalue=>typerec.description, calign=>'left',
423            cattributes=>'headers="' || wf_core.translate('DESCRIPTION') || '"');
424 	htp.tableRowClose;
425   end loop;
426   --
427   --
428   htp.tableClose;
429   wfa_sec.Footer;
430   htp.htmlClose;
431 exception
432   when others then
433     if (ItemTypes%isopen) then
434       close ItemTypes;  -- Close cursor just in case
435     end if;
436     rollback;
437     wf_core.context('Wf_Initiate', 'ItemType');
438     print_error;
439 end ItemType;
440 
441 
442 --
443 -- Process
444 --   generate response frame contents
445 --   to gather all required input to launch the workflow
446 -- IN
447 --
448 -- MODIFICATION LOG:
449 -- 06-JUN-2001 JWSMITH BUG 1819232 -Added ID attr for TD tag for ADA
450 --             - Added summary attr for table tag for ADA
451 --
452 procedure Process(ItemType in varchar2 )
453 as
454   --
455   -- Item Attributes Cursor
456   --
457   cursor ItemAttrs is
458   select name, display_name, type, subtype, format,
459          text_default, number_default, date_default
460   from   wf_item_attributes_vl
461   where  item_type = Process.itemtype
465   --
462   order by sequence;
463   --
464   -- Runnable Process cursor
466   cursor RunnableProcesses is
467   select wfrp.process_name, wfrp.display_name
468   from   wf_runnable_processes_v wfrp
469   where  wfrp.item_type =  Process.itemtype
470   order  by wfrp.display_name;
471   --
472   --
473   --
474   admin_mode 		varchar2(1);
475   admin_role		varchar2(320);
476   l_error_msg		varchar2(240);
477   username 	 	varchar2(320);
478   dvalue 		varchar2(2000);
479   respcnt 		pls_integer :=0;
480   l_itemTypeDisp 	varchar2(80);
481 
482   l_media       	varchar2(240):= wfa_html.image_loc;
483   l_icon        	varchar2(30) := 'FNDILOV.gif';
484   l_url         	varchar2(1000);
485   l_onmouseover         varchar2(240);
486   l_message             varchar2(240)   := wf_core.translate ('WFPREF_LOV');
487   l_text        	varchar2(30) := '';
488 --
489 --
490 --
491 begin
492 
493   -- Authenticate user
494   wfa_sec.GetSession(username);
495   username := upper(username);
496   admin_role := wf_core.translate('WF_ADMIN_ROLE');
497   if (admin_role = '*' or
498          Wf_Directory.IsPerformer(username, admin_role)) then
499          admin_mode := 'Y';
500   else
501      l_error_msg := wf_core.translate('WFINIT_INVALID_ADMIN');
502   end if;
503   --
504   -- Header and Page Title
505   --
506   htp.htmlOpen;
507   htp.headOpen;
508   htp.title(wf_core.translate('WFINIT_PROCESS_TITLE'));
509   wfa_html.create_help_function('wf/links/ini.htm?INIT_WF');
510 
511   -- Add the java script to the header to open the dm window for
512   -- any DM function that and any standard LOV
513   fnd_document_management.get_open_dm_attach_window;
514   fnd_document_management.get_open_dm_display_window;
515 
516   htp.headClose;
517 
518   wfa_sec.Header(FALSE, '', wf_core.translate('WFINIT_PROCESS_TITLE')||' - '||Process.ItemType);
519   htp.br;
520 
521   --
522   if (l_error_msg IS NOT NULL) THEN
523      htp.center(htf.bold(l_error_msg));
524      return;
525   end if;
526   --
527   --
528   -- Response body content
529   --
530   --
531   --
532   select display_name
533   into   l_ItemTypeDisp
534   from   wf_item_types_vl
535   where  name = Process.ItemType;
536 
537   --
538   -- wf_initiate.SubmitWorkflow is the url(procedure) to which the contents
539   -- of this form is sent
540   htp.formOpen(curl=>wfa_html.base_url||'/Wf_Initiate.SubmitWorkflow',
541                cmethod=>'Post', cattributes=>'NAME="WF_INITIATE"');
542 
543   --
544   -- Add dummy fields to start both array-type input fields.
545   -- These dummy values are needed so that the array parameters to
546   -- the submit procedure will not be null even if there are no real
547   -- response fields.  This would cause a pl/sql error, because array
548   -- parameters can't be defaulted.
549   --
550   htp.formHidden('h_fnames', 'Dummy_Name');
551   htp.formHidden('h_fvalues', 'Dummy_Value');
552   htp.formHidden('h_fdocnames', 'Dummy_Display_Name');
553   --
554   htp.formHidden('itemtype',Process.ItemType);
555   --
556   --
557   -- Item Key
558   --
559   htp.tableOpen(cattributes=>'border=0 cellpadding=2 cellspacing=0 ALIGN=CENTER summary="' || wf_core.translate('WFINIT_PROCESS_TITLE') || '"');
560   htp.tableRowOpen;
561   htp.tableData(cvalue=>'<LABEL FOR="i_itemkey">' ||
562                 wf_core.translate('ITEMKEY') || '</LABEL>',  calign=>'right',
563        cattributes=>'id=""');
564   htp.tableData(cvalue=>htf.formText(cname=>'itemkey',csize=>40,
565 			cmaxlength=>240,
566                         cattributes=>'id="i_itemkey"'),
567         		calign=>'Left',
568                         cattributes=>'id=""');
569   htp.tableRowClose;
570   --
571   -- User Key
572   --
573   htp.tableRowOpen;
574   htp.tableData(cvalue=>'<LABEL FOR="i_user_itemkey">' ||
575                         wf_core.translate('USER_ITEMKEY') || '</LABEL>',
576                         calign=>'right',
577                         cattributes=>'id=""');
578   htp.tableData(cvalue=>htf.formText(cname=>'userkey', csize=>40,
579 			cmaxlength=>240,
580                         cattributes=>'id="i_user_itemkey"'),
581         		calign=>'Left',
582                         cattributes=>'id=""');
583   htp.tableRowClose;
584   --
585   -- Process name
586   --
587   htp.tableRowOpen('bgcolor=#ffffcc');
588   htp.tableData(cvalue=>'<LABEL FOR="i_process_name">' ||
589            wf_core.translate('PROCESS_NAME') || '</LABEL>',  calign=>'right',
590            cattributes=>'id=""');
591   htp.p('<TD ID="">');
592   htp.formSelectOpen(cname=>'Process',cattributes=>'id="i_process_name"');
593 
594   -- add a null process which will invoke the selector function
595   htp.formSelectOption(cvalue=>wf_core.translate('WFA_NULL_PROCESS')
596 			,cattributes=>'value='||'""');
597   for wfp in RunnableProcesses loop
598 	htp.formSelectOption(cvalue=>wfp.display_name
599 			,cattributes=>'value='||'"'||wfp.process_name||'"');
600   end loop;
601 
602   htp.formSelectClose;
603   htp.p('</TD>');
604   htp.tableRowClose;
605   htp.formHidden('owner', null);
609   --
606 
607   --
608   -- Process Owner
610   -- add LOV here: Note:bottom is name of frame.
611   -- Note: The REPLACE function replaces all the space characters with
612   -- the proper escape sequence.
613   l_url := 'javascript:fnd_open_dm_display_window('||''''||
614             REPLACE('wf_lov.display_lov?p_lov_name='||'owner'||
615             '&p_display_name='||'WFA_FIND_USER'||
616             '&p_validation_callback=wfa_html.wf_user_val'||
617             '&p_dest_hidden_field=top.opener.parent.document.WF_INITIATE.owner.value'||
618             '&p_current_value=top.opener.parent.document.WF_INITIATE.display_owner.value'||
619             '&p_display_key='||'Y'||
620             '&p_dest_display_field=top.opener.parent.document.WF_INITIATE.display_owner.value',
621              ' ', '%20')||''''||',500,500)';
622 
623   htp.tableRowOpen;
624   htp.tableData(cvalue=>'<LABEL FOR="i_process_owner">' ||
625                 wf_core.translate('PROCESS_OWNER') ||
626                 '</LABEL>',  calign=>'right',
627                 cattributes=>'id=""');
628 
629   -- print everything together so ther is no gap.
630   htp.tabledata(htf.formText(cname=>'display_owner', csize=>30,
631                  cmaxlength=>240,
632                  cvalue=>username,
633                  cattributes=>'id="i_process_owner"')||
634         '<A href='||l_url||'>'||
635         '<IMG src="'||l_media||l_icon||'" border=0 alt="'||
636          l_message||'" onmouseover="window.status='||''''||
637          l_message||''''||';return true"></A>',
638          cattributes=>'id=""');
639 
640   htp.tableRowClose;
641 
642   for rec in itemattrs loop
643     respcnt := respcnt + 1;
644     htp.tableRowOpen('bgcolor=#ffffcc');
645     htp.tableData(cvalue=>'<LABEL FOR="i_attr'|| respcnt ||'">' ||
646                   rec.display_name || '</LABEL>',
647                   calign=>'right',
648                   cattributes=>'id=""');
649 
650     dvalue := GetDisplayValue(rec.type, rec.format, rec.text_default,
651 	     rec.number_default, rec.date_default);
652 
653     if (rec.type = 'LOOKUP') then
654        GetLookup(rec.name, rec.text_default, rec.format, to_char(respcnt));
655     elsif (rec.type = 'ROLE') then
656        wf_initiate.GetRole(rec.name, rec.text_default,
657 			to_char(respcnt) );
658     elsif (rec.type = 'DOCUMENT') then
659        GetDocument(rec.name, rec.format, dvalue, to_char(respcnt) );
660     else
661        GetField(rec.name, rec.type, rec.format, dvalue, to_char(respcnt) );
662     end if;
663     htp.tableRowClose;
664   end loop;
665 
666   htp.tableClose;
667 
668   htp.formHidden('h_counter', to_char(respcnt+1));
669 
670   htp.br;
671 
672 
673   --Submit Button
674 
675   htp.tableopen(calign=>'CENTER', cattributes=>'summary=""');
676   htp.tableRowOpen;
677 
678   l_url         := 'javascript:document.WF_INITIATE.submit()';
679   l_icon        := 'FNDJLFOK.gif';
680   l_text        := wf_core.translate ('WFMON_OK');
681   l_onmouseover := wf_core.translate ('WFMON_OK');
682 
683   htp.p('<TD ID="">');
684 
685   wf_pref.create_reg_button (l_url, l_onmouseover, l_media, l_icon, l_text);
686 
687   htp.p('</TD>');
688 
689   l_url         := wfa_html.base_url||'/wf_initiate.itemType';
690   l_icon        := 'FNDJLFCN.gif';
691   l_text        := wf_core.translate ('CANCEL');
692   l_onmouseover := wf_core.translate ('CANCEL');
693 
694   htp.p('<TD ID="">');
695 
696   wf_pref.create_reg_button (l_url, l_onmouseover, l_media, l_icon, l_text);
697 
698   htp.p('</TD>');
699 
700   htp.tableRowClose;
701 
702   htp.tableclose;
703 
704 
705   htp.formClose;
706   --
707   -- NOTE: Do NOT create any more fields for h_names or h_values here.  The
708   -- submit buttons created above must be the last values for these fields
709   -- to work around an MSIE bug that always sends the submit button last.
710   -- Page footer
711   --
712   Wfa_Sec.Footer;
713   htp.htmlClose;
714 exception
715   when others then
716     if (itemattrs%isopen) then
717       close itemattrs;  -- Close cursor just in case
718     end if;
719     rollback;
720     wf_core.context('Wf_Initiate', 'Process');
721     print_error;
722 end Process;
723 
724 
725 --
726 -- SetAttribute (PRIVATE)
727 --   Set response attributes when processing a response.
728 -- IN
729 --   ItemType		- Item Type
730 --   ItemKey		- Item Key
731 --   Attr_Name_Type 	- attribute name#type#format
732 --   Attr_Value 	- attribute value
733 --   Attr_Doc_Name 	- attribute display value - usually discarded
734 --
735 procedure SetAttribute(
736   itemtype       in varchar2,
737   itemkey        in varchar2,
738   attr_name_type in varchar2,
739   attr_value     in varchar2,
740   attr_doc_name  in varchar2)
741 as
742   first     pls_integer;
743   second    pls_integer;
744   attr_type varchar2(8);
745   attr_name varchar2(30);
746   attr_fmt  varchar2(240);
747   --
748   badfmt boolean:=FALSE;
749   input_too_long boolean:=FALSE;
750   l_attr_value varchar2(320);
751 
752 begin
756   -- for now is to look for attr name starting from 2nd character.
753   -- Parse out name#type#format
754   -- It is ok to have # in attribute name as the leading character
755   -- It is also possible to have # in format, so the best thing we can do
757   -- Attr name cannot be null.
758   first  := instr(attr_name_type, '#', 2);
759   second := instr(attr_name_type, '#', 2, 2);
760   attr_name := substr(attr_name_type, 1, first-1);
761   attr_type := substr(attr_name_type, first+1, second-first-1);
762   attr_fmt  := substr(attr_name_type, second+1,
763                       length(attr_name_type)-second);
764   --
765   begin
766   if (attr_type = 'DATE') then
767     if (attr_fmt is not null) then
768       wf_engine.SetItemAttrDate(SetAttribute.itemType,SetAttribute.itemkey,
769 					attr_name,to_date(attr_value,attr_fmt));
770     else
771        wf_engine.SetItemAttrDate (SetAttribute.itemType,SetAttribute.itemkey ,
772 					attr_name,to_date(attr_value,SYS_CONTEXT('USERENV','NLS_DATE_FORMAT')));
773     end if;
774   elsif (attr_type = 'NUMBER') then
775     if (attr_fmt is not null) then
776        wf_engine.SetItemAttrNumber(SetAttribute.itemType,SetAttribute.itemkey,  attr_name,
777                                     to_number(attr_value, attr_fmt));
778     else
779      wf_engine.SetItemAttrNumber (SetAttribute.itemType,SetAttribute.itemkey,  attr_name,
780                                     to_number(attr_value));
781     end if;
782   elsif (attr_type = 'VARCHAR2' )
783      and (length(attr_value) > nvl(to_number(attr_fmt),length(attr_value))) then
784       input_too_long:=true;
785   elsif (attr_type = 'ROLE' ) then
786 
787       /*
788       ** If this is a role then try to get the unique role name for the
789       ** user that was selected.  Since this could be a display name
790       ** or an internal name, make sure to get the unique internal name
791       */
792       l_attr_value := attr_value;
793 
794       wfa_html.validate_display_name (attr_doc_name, l_attr_value);
795 
796       wf_engine.setitemattrtext( SetAttribute.itemType,SetAttribute.itemkey,
797 					 attr_name, l_attr_value);
798   elsif (attr_type = 'DOCUMENT' ) then
799      -- if PLSQL then use the display value into which the user typed
800      if upper(substr(attr_doc_name,1, 5)) = 'PLSQL' then
801 
802       wf_engine.setitemattrtext( SetAttribute.itemType,SetAttribute.itemkey,
803 					 attr_name, attr_doc_name);
804      -- use the hidden field populated by doc lov
805      else
806 
807       wf_engine.setitemattrtext( SetAttribute.itemType,SetAttribute.itemkey,
808 					 attr_name, attr_value);
809      end if;
810 
811   else
812     -- Lookup, VARCHAR2 or misc value
813       wf_engine.setitemattrtext( SetAttribute.itemType,SetAttribute.itemkey,
814 					 attr_name, attr_value);
815   end if;
816   exception
817   when others then
818     if (wf_core.error_name is null) and (attr_fmt is not null) then
819       badfmt := true;
820     else
821       raise;
822     end if;
823   end;
824   if (badfmt) then
825     Wf_Core.Token('FORMAT', attr_fmt);
826     Wf_core.Token('VALUE',attr_value);
827     Wf_Core.Raise('WFINIT_INVALID_FMT');
828   end if;
829   if input_too_long then
830     Wf_Core.Token('FORMAT', attr_fmt);
831     Wf_core.Token('INPUT',substr(attr_value,1,10));
832     Wf_core.Token('TRUNC',substr(attr_value,to_number(attr_fmt)+1));
833     wf_core.raise('WFINIT_INPUT_TOOLONG');
834   end if;
835 
836 exception
837   when others then
838         wf_core.context('Wf_initiate', 'SetAttribute',
839                         SetAttribute.itemType,SetAttribute.itemkey,
840 			attr_name_type, attr_value, attr_doc_name);
841     raise;
842 end SetAttribute;
843 
844 
845 --
846 -- SubmitWorkflow
847 --   Submit the workflow
848 -- IN
849 procedure SubmitWorkflow(
850   itemtype      in varchar2 ,
851   itemkey       in varchar2 ,
852   userkey       in varchar2 ,
853   process       in varchar2 ,
854   Owner  	in varchar2 ,
855   display_Owner in varchar2 ,
856   h_fnames      in Name_Array,
857   h_fvalues     in Value_Array,
858   h_fdocnames   in Value_Array, -- the display field
859   h_counter     in varchar2)
860 as
861   username   varchar2(320);
862   t_owner    varchar2(320);
863   admin_role varchar2(320);
864   admin_mode varchar2(10);
865   counter    pls_integer;
866   access_key varchar2(2000);
867   l_error_msg   VARCHAR2(2000);
868 begin
869 
870   -- Authenticate user
871   wfa_sec.GetSession(username);
872   username := upper(username);
873   admin_role := wf_core.translate('WF_ADMIN_ROLE');
874   if (admin_role = '*' or
875          Wf_Directory.IsPerformer(username, admin_role)) then
876          admin_mode := 'Y';
877   else
878      l_error_msg := wf_core.translate('WFINIT_INVALID_ADMIN');
879   end if;
880 
881   -- Convert the display name of the owner to a username if necessary
882   t_owner := owner;
883   wfa_html.validate_display_name (display_owner, t_owner);
884 
885   --
886   if (l_error_msg IS NOT NULL) THEN
887      htp.center(htf.bold(l_error_msg));
888      return;
889   end if;
890 
891   wf_engine.createprocess(itemtype => SubmitWorkflow.itemtype,
892 			  itemkey  => SubmitWorkflow.itemkey,
893 			  process  => SubmitWorkflow.process );
894 
895   if SubmitWorkflow.UserKey is not null then
896     wf_engine.SetItemUserKey(ItemType=> SubmitWorkflow.ItemType,
897 	  		     ItemKey => SubmitWorkflow.ItemKey,
898 			     UserKey => SubmitWorkflow.UserKey);
899   end if;
900 
901   if SubmitWorkflow.t_Owner is not null then
902      wf_engine.SetItemOwner (itemtype=>SubmitWorkflow.itemtype,
903 			     itemkey =>SubmitWorkflow.itemkey,
904 			     owner   =>upper(SubmitWorkflow.t_Owner) );
905   end if;
906 
907   --
908   -- Set attributes in the reponse array.
909   -- Start at 2 to step over the Dummy_Name/Dummy_Value pair added at
910   -- the start of the array.
911   --
912   for counter in 2 .. to_number(h_counter) loop
913     SetAttribute(SubmitWorkflow.itemtype, SubmitWorkflow.itemkey,
914                  h_fnames(counter), h_fvalues(counter), h_fdocnames(counter));
915   end loop;
916 
917   -- Submit workflow
918   wf_engine.startprocess(SubmitWorkflow.itemtype, SubmitWorkflow.itemkey);
919 
920 
921   -- go to the advanced envelope to display all the results.
922   -- call it with all options so it displays every activity response.
923   owa_util.redirect_url(curl=>wf_monitor.GetAdvancedEnvelopeUrl(
924 				x_agent      => wfa_html.base_url,
925 				x_item_type  => SubmitWorkflow.itemtype,
926 				x_item_key   => SubmitWorkflow.itemkey,
927 				x_admin_mode => 'YES',
928                                 x_options    => 'YES'),
929         bclose_header=>TRUE);
930 
931   --
932 exception
933   when others then
934     rollback;
935     wf_core.context('Wf_Initiate','SubmitWorkflow',
936                     itemtype, itemkey);
937     print_error;
938 
939 end SubmitWorkflow;
940 --
941 --
942 end WF_INITIATE;