DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_WEBATTCH

Source


1 package body FND_WEBATTCH as
2 /* $Header: AFATCHMB.pls 120.3 2006/05/26 15:47:24 blash ship $ */
3 
4 
5 -- Package Variables which stores the seed data for attachments.
6 g_function_name	varchar2(30) := null;
7 g_entity_name	varchar2(40) := null;
8 g_pk1_value	varchar2(100) := null;
9 g_pk2_value	varchar2(100) := null;
10 g_pk3_value	varchar2(100) := null;
11 g_pk4_value	varchar2(150) := null;
12 g_pk5_value	varchar2(150) := null;
13 g_chr_newline	varchar2(1) :='
14 '; -- NewLine Character
15 
16 
17 -- GetSummaryStatus
18 -- IN
19 --	function_name	--Function name of the form
20 --	entity_name	- Entity name for which attachment is made.
21 --	pk1_value	- First Primary Key value of the entity.
22 --	  to
23 --	pk5_value	- Fifth Primary key value of the entity.
24 -- OUT
25 -- 	attchmt_status	- Indicates Attachment Status -
26 --				 'EMPTY','FULL','DISABLED'.
27 --
28 procedure GetSummaryStatus (
29 	x_function_name		in varchar2,
30 	x_entity_name		in varchar2,
31 	x_pk1_value		in varchar2,
32 	x_pk2_value		in varchar2	default NULL,
33 	x_pk3_value		in varchar2	default NULL,
34 	x_pk4_value		in varchar2	default NULL,
35 	x_pk5_value		in varchar2	default NULL,
36 	attchmt_status		out NOCOPY varchar2
37 )
38 as
39   attchmt_exists	varchar2(1);
40   attachment_defined_flag	boolean;
41   l_function_type 	varchar2(1) := 'F';
42 begin
43 
44 
45   -- Validate the session
46   /*if NOT (icx_sec.ValidateSession(null)) then
47      return;
48   end if; */
49 
50   -- Set the parameters to package global
51   g_function_name := x_function_name;
52   g_entity_name	:= x_entity_name;
53   g_pk1_value	:= x_pk1_value;
54   g_pk2_value	:= x_pk2_value;
55   g_pk3_value	:= x_pk3_value;
56   g_pk4_value	:= x_pk4_value;
57   g_pk5_value	:= x_pk5_value;
58 
59   -- Find out if attachment is enabled in this function.
60   fnd_attachment_util_pkg.init_atchmt (
61 			g_function_name,
62 			attachment_defined_flag,
63 			l_function_type);
64 
65   -- If the attachment is enabled then enable the link.
66   if ( attachment_defined_flag = TRUE ) then
67 
68       -- Set the link to 'FULL' or 'EMPTY'.
69       attchmt_exists:=fnd_attachment_util_pkg.get_atchmt_exists (
70 			g_entity_name,
71 			g_pk1_value,
72 			g_pk2_value,
73 			g_pk3_value,
74 			g_pk4_value,
75 			g_pk5_value,
76 			g_function_name,
77 			l_function_type);
78      if (attchmt_exists = 'Y') then
79 	attchmt_status := 'FULL';
80      elsif (attchmt_exists = 'N') then
81         attchmt_status := 'EMPTY';
82      end if;
83   else
84 	attchmt_status := 'DISABLED';
85   end if;
86 exception
87   when others then
88     attchmt_status := 'DISABLED';
89 end GetSummaryStatus;
90 
91 -- GetSummaryList
92 --  IN
93 -- 	attchmt_status	- Indicates Attachment Status -
94 --				 EMPTY, FULL, DISABLED.
95 --	from_url	- URL from which the attachments is invoked from.
96 --			  This is required to set the back link.
97 --	query_only	- Query flag is set 'Y' when called in query only
98 --			  mode.
99 -- OUT
100 --	URL		- URL string to linked to the attachment button.
101 --
102 
103 procedure GetSummaryList (
104 	attchmt_status	in varchar2	default 'DISABLED',
105 	from_url	in varchar2,
106 	query_only	in varchar2	default 'N',
107 	package_name	in varchar2	default 'FND_WEBATTCH',
108 	URL		out NOCOPY varchar2
109 )
110 as
111 begin
112 
113   -- Check if the attachment status.
114   if    (attchmt_status <>  'DISABLED') then
115      URL := fnd_web_config.plsql_agent || package_name
116 	||'.Summary?function_name=' || icx_call.encrypt2(g_function_name)
117 	||'&'||'entity_name='|| icx_call.encrypt2(g_entity_name)
118 	||'&'||'pk1_value='|| icx_call.encrypt2(g_pk1_value)
119 	||'&'||'pk2_value='|| icx_call.encrypt2(g_pk2_value)
120 	||'&'||'pk3_value='|| icx_call.encrypt2(g_pk3_value)
121 	||'&'||'pk4_value='|| icx_call.encrypt2(g_pk4_value)
122 	||'&'||'pk5_value='|| icx_call.encrypt2(g_pk5_value)
123 	||'&'||'from_url=' || icx_call.encrypt2(from_url)
124 	||'&'||'query_only='|| icx_call.encrypt2(query_only);
125   end if;
126 
127 end GetSummaryList;
128 
129 --
130 -- Summary
131 --	Construct the list of attachments for an entity.
132 --
133 procedure Summary (
134 	function_name		in varchar2,
135 	entity_name		in varchar2,
136 	pk1_value		in varchar2,
137 	pk2_value		in varchar2	default NULL,
138 	pk3_value		in varchar2	default NULL,
139 	pk4_value		in varchar2	default NULL,
140 	pk5_value		in varchar2	default NULL,
141 	from_url		in varchar2,
142 	query_only		in varchar2	default 'N'
143 ) as
144 
145   l_function_name     varchar2(30) := icx_call.decrypt2(summary.function_name);
146   l_entity_name	varchar2(40)  := icx_call.decrypt2(summary.entity_name);
147   l_pk1_value	varchar2(100) := icx_call.decrypt2(summary.pk1_value);
148   l_pk2_value	varchar2(100) := icx_call.decrypt2(summary.pk2_value);
149   l_pk3_value	varchar2(100) := icx_call.decrypt2(summary.pk3_value);
150   l_pk4_value	varchar2(150) := icx_call.decrypt2(summary.pk4_value);
151   l_pk5_value	varchar2(150) := icx_call.decrypt2(summary.pk5_value);
152   l_from_url	varchar2(2000) := icx_call.decrypt2(summary.from_url);
153   l_query_only	varchar2(100) := icx_call.decrypt2(summary.query_only);
154   l_lang	varchar2(24);
155   l_dcdname	varchar2(80):= owa_util.get_cgi_env('SCRIPT_NAME');
156   l_packagename	varchar2(80) := 'FND_WEBATTCH';
157 begin
158 
159   -- Validate the session
160   if NOT (icx_sec.ValidateSession(null)) then
161      return;
162   end if;
163 
164   -- Set the language
165   l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
166 
167 
168   -- Show attachment summary and document info in frames.
169   htp.htmlOpen;
170   htp.headOpen;
171 
172   htp.framesetopen(crows=>'60, *, *', cattributes =>'frameborder=no border=0');
173 
174   -- Call the procedure that prints header
175   htp.frame (csrc => l_dcdname || '/fnd_webattch.Header?Lang='||l_lang,
176 		cname => 'header_frame', cmarginheight=>'0',
177 		cmarginwidth=> '0', cscrolling => 'NO',
178 		cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
179 
180   -- Print The Body of the Summary page.
181   htp.frame (csrc => l_dcdname ||'/'||
182 		'fnd_webattch.PrintSummary?package_name='|| l_packagename ||
183 		'&'||'function_name='||l_function_name ||
184 		'&'||'entity_name='||l_entity_name ||
185 		'&'||'pk1_value='||l_pk1_value ||
186 		'&'||'pk2_value='||l_pk2_value ||
187 		'&'||'pk3_value='||l_pk3_value ||
188 		'&'||'pk4_value='||l_pk4_value ||
189 		'&'||'pk5_value='||l_pk5_value||
190 		'&'||'from_url='||l_from_url ||
191 		'&'||'query_only='||l_query_only,
192 		cname => 'list_frame',
193 	     cmarginheight=>'0', cmarginwidth=> '10', cscrolling => 'AUTO',
194 	     cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
195 
196   -- Make an empty frame for document data.
197   htp.frame (csrc => l_dcdname || '/'||'fnd_webattch.PrintBlankPage',
198 		cname => 'document_frame', cmarginheight=>'0',
199 		cmarginwidth=> '10', cscrolling => 'AUTO',
200 		cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
201 
202   -- Close the frameset.
203   htp.framesetclose;
204 
205 end Summary;
206 
207 -- procedure DocumentInformation (Private Procedure)
208 -- IN
209 --	x_datatype_id	- 0 if all the document info.type are blank.
210 --	x_short_text	- Short text document Info.
211 --	x_long_text	- Long text document Info.
212 --	x_file_name	- File / URL info. : File Name when datatype_id is 6
213 --					     URL when datatype_id is 5
214 --
215 procedure DocumentInformation (
216 	x_datatype_id	in number				,
217 	x_short_text	in varchar2		default NULL	,
218 	x_long_text	in long			default NULL	,
219 	x_file_name	in varchar2		default NULL
220 ) as
221 
222    l_callback_url       varchar2(4000);
223    l_search_document_url       varchar2(4000);
224    l_username                  varchar2(80);
225 
226 begin
227 
228   -- Construct the text document Information.
229   if (x_datatype_id = 1 ) then
230 
231      --htp.tableOpen( cattributes => ' border=0 cellpadding=2 cellspacing=0');
232      --htp.tableRowOpen( cvalign => 'TOP' );
233      htp.tableRowOpen;
234      htp.p('<TD align=right valign=top height=5 width=35%>');
235      htp.p('</TD>');
236      htp.p('<TD align=left>');
237      htp.p('<FONT class=datablack><TEXTAREA NAME ="text"  ROWS=4 + COLS=38>'||
238            x_short_text || '</TEXTAREA></FONT>');
239      /*htp.tableData( htf.formTextareaOpen2( cname => 'text', nrows => '8',
240                     ncolumns => '60', cwrap => 'virtual') ||
241                     x_short_text ||
242                     htf.formTextareaClose);*/
243      htp.tableRowClose;
244      htp.tableClose;
245      htp.formHidden ( cname =>'file_name', cvalue=>'');
246      htp.formHidden ( cname =>'url', cvalue=>'');
247   elsif(x_datatype_id = 2) then
248 
249      --htp.tableOpen( cattributes => ' border=0 cellpadding=2 cellspacing=0');
250      --htp.tableRowOpen( cvalign => 'TOP' );
251      htp.tableRowOpen;
252      htp.p('<TD align=right valign=top height=5 width=35%>');
253      htp.p('</TD>');
254      htp.p('<TD align=left>');
255      htp.p('<FONT class=datablack><TEXTAREA NAME ="text"  ROWS=4 + COLS=38>'||
256 	   x_long_text || '</TEXTAREA></FONT>');
257      /*htp.tableData( htf.formTextareaOpen2( cname => 'text', nrows => '8',
258                     ncolumns => '60', cwrap => 'virtual') ||
259                     x_long_text ||
260                     htf.formTextareaClose);*/
261      htp.tableRowClose;
262      htp.tableClose;
263      htp.formHidden ( cname =>'file_name', cvalue=>'');
264      htp.formHidden ( cname =>'url', cvalue=>'');
265 
266   -- Construct file type document information
267   elsif (x_datatype_id = 6 ) then
268 
269      htp.formHidden ( cname =>'text', cvalue=>'');
270      --htp.tableOpen(  cattributes => ' border=0 cellpadding=2 cellspacing=0' );
271      --htp.tableRowOpen( cvalign => 'TOP' );
272      htp.tableRowOpen;
273      htp.p('<TD align=right valign=top height=5 width=35%>');
274      htp.p('</TD>');
275      htp.p('<TD align=left>');
276      htp.p('<FONT class=datablack><INPUT TYPE="File" NAME="file_name"'||
277            'VALUE="'||x_file_name||'" SIZE="32"></FONT>');
278 
279      /*htp.tableData( '<INPUT TYPE="File" NAME="file_name" VALUE="Upload File" SIZE="60">', calign => 'left');*/
280      htp.tableRowClose;
281      htp.tableClose;
282      htp.formHidden ( cname =>'url', cvalue=>'');
283 
284   -- Construct the URL document information
285   elsif (x_datatype_id = 5 ) then
286      htp.formHidden ( cname =>'text', cvalue=>'');
287      htp.formHidden ( cname =>'file_name', cvalue=>'');
288 
289      --htp.tableOpen(  cattributes => ' border=0 cellpadding=2 cellspacing=0' );
290      --htp.tableRowOpen( cvalign => 'TOP' );
291      htp.tableRowOpen;
292      htp.p('<TD align=right valign=top height=5 width=35%>');
293      htp.p('</TD>');
294      htp.p('<TD align=left>');
295      htp.p('<FONT class=datablack><INPUT TYPE="Text" NAME="url" '||
296 	   'VALUE="'|| x_file_name ||'" SIZE="40"></FONT>');
297      /*htp.tableData( htf.formText( cname => 'url', csize => '70',
298                     cmaxlength => '100', cvalue =>x_file_name ),
299          calign => 'left');*/
300      htp.tableRowClose;
301      htp.tableClose;
302   elsif (x_datatype_id = 7 ) then
303      /*
304      ** Create the callback syntax to update the local fields
305      */
306      fnd_document_management.set_document_id_html (
307         null,
308         'FNDATTACH',
309         'dmid',
310         'dmname',
311         l_callback_url);
312 
313      -- Get the url syntax for performing a search
314      fnd_document_management.get_launch_attach_url (
315         l_username,
316         l_callback_url,
317         TRUE,
318         l_search_document_URL);
319 
320      -- DM Datatype
321      --htp.tableOpen(  cattributes => ' border=0 cellpadding=2 cellspacing=0' );
322      --htp.tableRowOpen( cvalign => 'TOP' );
323      htp.tableRowOpen;
324      htp.p('<TD align=right valign=top height=5 width=35%>');
325      htp.p('</TD>');
326      htp.p('<TD align=left>');
327      htp.p('<FONT class=datablack><INPUT TYPE="Text" NAME="dmid" '||
328 	   'VALUE="'||x_file_name|| '" SIZE="40"></FONT>'||
329 	   l_search_document_URL);
330      /*htp.tableData( htf.formText( cname => 'dmid', csize => '70',
331 		cvalue=>x_file_name)|| l_search_document_URL,
332 		calign => 'left');*/
333      htp.tableRowClose;
334      htp.tableClose;
335 
336      htp.formHidden ( cname =>'text', cvalue=>'');
337      htp.formHidden ( cname =>'url', cvalue=>'');
338   end if;
339 
340 end DocumentInformation;
341 
342 --
343 -- UpdateAttachment
344 --	Displays the attachment information for update.
345 -- IN
346 --	attached_document_id
347 --	function_name	--Function name of the form
348 --	entity_name	- Entity name for which attachment is made.
349 --	pk1_value	- First Primary Key value of the entity.
350 --	  to
351 --	pk5_value	- Fifth Primary key value of the entity.
352 --	from_url	- URL from which the attachments is invoked from.
353 --			  This is required to set the back link.
354 --	query_only	- Query flag is set 'Y' when called in query only
355 --			  mode.
356 --
357 
358 procedure UpdateAttachment(
359 	attached_document_id		in varchar2,
360 	function_name			in varchar2,
361 	entity_name			in varchar2,
362 	pk1_value			in varchar2,
363 	pk2_value			in varchar2	default NULL,
364 	pk3_value			in varchar2	default NULL,
368 	query_only			in varchar2	default 'N'
365 	pk4_value			in varchar2	default NULL,
366 	pk5_value			in varchar2	default NULL,
367 	from_url			in varchar2,
369 )
370 as
371 l_attached_document_id	varchar2(16);
372 l_function_name	varchar2(30);
373 l_entity_name	varchar2(40);
374 l_pk1_value	varchar2(100);
375 l_pk2_value	varchar2(100);
376 l_pk3_value	varchar2(150);
377 l_pk4_value	varchar2(150);
378 l_pk5_value	varchar2(150);
379 l_from_url	varchar2(2000);
380 l_query_only	varchar2(1);
381 l_lang		varchar2(24);
382 l_dcdname	varchar2(80):= owa_util.get_cgi_env('SCRIPT_NAME');
383 l_packagename	varchar2(80) := 'FND_WEBATTCH';
384 
385 begin
386 
387   -- Validate the session
388   if NOT (icx_sec.ValidateSession(null)) then
389      return;
390   end if;
391 
392   -- Set the language
393   l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
394 
395   -- Decrypt all parameters.
396   l_attached_document_id :=
397 		icx_call.decrypt2(UpdateAttachment.attached_document_id);
398   l_function_name := icx_call.decrypt2(UpdateAttachment.function_name);
399   l_entity_name	:= icx_call.decrypt2(UpdateAttachment.entity_name);
400   l_pk1_value := icx_call.decrypt2(UpdateAttachment.pk1_value);
401   l_pk2_value := icx_call.decrypt2(UpdateAttachment.pk2_value);
402   l_pk3_value := icx_call.decrypt2(UpdateAttachment.pk3_value);
403   l_pk4_value := icx_call.decrypt2(UpdateAttachment.pk4_value);
404   l_pk5_value := icx_call.decrypt2(UpdateAttachment.pk5_value);
405   l_from_url := icx_call.decrypt2(UpdateAttachment.from_url);
406   l_query_only := icx_call.decrypt2(UpdateAttachment.query_only);
407 
408   -- Call the procedure that prints header
409   htp.htmlOpen;
410   htp.headOpen;
411 
412   htp.framesetopen(crows=>'60, *', cattributes =>'frameborder=no border=0');
413 
414   -- Call the procedure that prints header
415   htp.frame (csrc => l_dcdname || '/fnd_webattch.Header?Lang='||l_lang,
416 		cname => 'top_frame', cmarginheight=>'0',
417 		cmarginwidth=> '0', cscrolling => 'NO',
418 		cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
419 
420   -- Print The Body of the Add Attachment page.
421   htp.frame (csrc => l_dcdname ||
422 		'/fnd_webattch.PrintUpdateAttachment?attached_document_id='||
423 						l_attached_document_id ||
424 		'&'||'package_name='|| l_packagename ||
425 		'&'||'function_name='||l_function_name ||
426 		'&'||'entity_name='||l_entity_name ||
427 		'&'||'pk1_value='||l_pk1_value ||
428 		'&'||'pk2_value='||l_pk2_value ||
429 		'&'||'pk3_value='||l_pk3_value ||
430 		'&'||'pk4_value='||l_pk4_value ||
431 		'&'||'pk5_value='||l_pk5_value||
432 		'&'||'from_url='||l_from_url ||
433 		'&'||'query_only='||l_query_only,
434 		cname => 'main_frame',
435 	     cmarginheight=>'0', cmarginwidth=> '10', cscrolling => 'AUTO',
436 	     cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
437 
438   -- Close the frameset.
439   htp.framesetclose;
440 
441 end UpdateAttachment;
442 
443 
444 -- DeleteAttachment
445 --	Deletes the attachment and document.
446 -- IN
447 --	attached_document_id
448 --
449 
450 procedure DeleteAttachment(
451 	attached_document_id	in varchar2,
452 	function_name		in varchar2,
453 	entity_name		in varchar2,
454 	pk1_value		in varchar2,
455 	pk2_value		in varchar2	default NULL,
456 	pk3_value		in varchar2	default NULL,
457 	pk4_value		in varchar2	default NULL,
458 	pk5_value		in varchar2	default NULL,
459 	from_url		in varchar2,
460 	query_only		in varchar2	default 'N'
461 )
462 as
463    cursor delatt_cursor (x_attached_document_id varchar2) is
464 	select datatype_id,file_name,media_id
465 	  from fnd_attached_docs_form_vl
466 	 where attached_document_id =  to_number(x_attached_document_id);
467 
468  deldatarec	delatt_cursor%ROWTYPE;
469 
470  l_datatype_id 		number;
471  l_media_id 		number;
472  l_file_name 		varchar2(255);
473  l_attached_document_id	varchar2(16) :=
474 		icx_call.decrypt2(deleteattachment.attached_document_id);
475 begin
476 
477   -- Validate the session
478   if NOT (icx_sec.ValidateSession(null)) then
479      return;
480   end if;
481 
482   -- Get the datatype_id for the attachment.
483   open delatt_cursor (l_attached_document_id);
484   fetch delatt_cursor into deldatarec;
485   if delatt_cursor%NOTFOUND then
486      return;
487   end if;
488 
489   l_datatype_id := deldatarec.datatype_id ;
490   l_file_name := deldatarec.file_name;
491   l_media_id := deldatarec.media_id;
492 
493   -- Call the procedure to delete the attachment and document.
494   fnd_attached_documents3_pkg.delete_row ( l_attached_document_id,
495 					   l_datatype_id, 'Y' );
496 
497   -- Delete the file from fnd_lobs.
498   if (l_datatype_id = 6 ) then
499       DELETE FROM fnd_lobs WHERE file_id = l_media_id;
500   end if;
501 
502   -- Redirect the URL to the file location
503   owa_util.redirect_url (curl => owa_util.get_owa_service_path||
504       'fnd_webattch.Summary?function_name=' || function_name
505         ||'&'||'entity_name='||entity_name
506         ||'&'||'pk1_value='||pk1_value
507         ||'&'||'pk2_value='||pk2_value
508         ||'&'||'pk3_value='||pk3_value
509         ||'&'||'pk4_value='||pk4_value
513 
510         ||'&'||'pk5_value='||pk5_value
511         ||'&'||'from_url='||from_url
512         ||'&'||'query_only='||query_only);
514 end DeleteAttachment;
515 
516 --
517 -- AddAttachment
518 --	Creates an attachment and document.
519 -- IN
520 --	function_name	- Function name of the web function
521 --	entity_name	- Entity name to which the attachment is made.
522 --	pk1_value	- First primary key of the entity.
523 --	 through
524 --	pk5_value	- Fifth primary key value of the entity.
525 --	from_url	- URL from which the attachments is invoked from.
526 --			  This is required to set the back link.
527 --	query_only	- Query flag is set 'Y' when called in query only
528 --			  mode.
529 --
530 
531 procedure AddAttachment(
532 	function_name		in varchar2,
533 	entity_name		in varchar2,
534 	pk1_value		in varchar2,
535 	pk2_value		in varchar2	default NULL,
536 	pk3_value		in varchar2	default NULL,
537 	pk4_value		in varchar2	default NULL,
538 	pk5_value		in varchar2	default NULL,
539 	from_url		in varchar2,
540 	query_only		in varchar2	default 'N'
541 ) as
542 
543   l_function_name varchar2(30);
544   l_entity_name	varchar2(40) ;
545   l_pk1_value	varchar2(100);
546   l_pk2_value	varchar2(100);
547   l_pk3_value	varchar2(150);
548   l_pk4_value	varchar2(150);
549   l_pk5_value	varchar2(150);
550   l_from_url	varchar2(2000);
551   l_query_only	varchar2(1);
552   l_lang	varchar2(24);
553   l_dcdname	varchar2(80):= owa_util.get_cgi_env('SCRIPT_NAME');
554   l_packagename	varchar2(80) := 'FND_WEBATTCH';
555 
556   begin
557 
558   -- Validate the session
559   if NOT (icx_sec.ValidateSession(null)) then
560      return;
561   end if;
562 
563   -- Set the language
564   l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
565 
566   -- Decrypt all the parameters.
567   l_function_name :=icx_call.decrypt2(AddAttachment.function_name);
568   l_entity_name	:= icx_call.decrypt2(AddAttachment.entity_name);
569   l_pk1_value	:= icx_call.decrypt2(AddAttachment.pk1_value);
570   l_pk2_value	:= icx_call.decrypt2(AddAttachment.pk2_value);
571   l_pk3_value	:= icx_call.decrypt2(AddAttachment.pk3_value);
572   l_pk4_value	:= icx_call.decrypt2(AddAttachment.pk4_value);
573   l_pk5_value	:= icx_call.decrypt2(AddAttachment.pk5_value);
574   l_from_url	:= icx_call.decrypt2(AddAttachment.from_url);
575   l_query_only	:= icx_call.decrypt2(AddAttachment.query_only);
576 
577   -- Call the procedure that prints header
578   htp.htmlOpen;
579   htp.headOpen;
580 
581   htp.framesetopen(crows=>'60, *', cattributes =>'frameborder=no border=0');
582 
583   -- Call the procedure that prints header
584   htp.frame (csrc => l_dcdname || '/fnd_webattch.Header?Lang='||l_lang,
585 		cname => 'tooolbar_frame', cmarginheight=>'0',
586 		cmarginwidth=> '0', cscrolling => 'NO',
587 		cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
588 
589   -- Print The Body of the Add Attachment page.
590   htp.frame (csrc => l_dcdname ||
591 		'/fnd_webattch.PrintAddAttachment?package_name='||
592 						l_packagename ||
593 		'&'||'function_name='||l_function_name ||
594 		'&'||'entity_name='||l_entity_name ||
595 		'&'||'pk1_value='||l_pk1_value ||
596 		'&'||'pk2_value='||l_pk2_value ||
597 		'&'||'pk3_value='||l_pk3_value ||
598 		'&'||'pk4_value='||l_pk4_value ||
599 		'&'||'pk5_value='||l_pk5_value||
600 		'&'||'from_url='||l_from_url ||
601 		'&'||'query_only='||l_query_only,
602 		cname => 'form_frame',
603 	     cmarginheight=>'0', cmarginwidth=> '10', cscrolling => 'AUTO',
604 	     cnoresize => 'NORESIZE', cattributes => 'FRAMEBORDER=NO');
605 
606   -- Close the frameset.
607   htp.framesetclose;
608 
609 end AddAttachment;
610 
611 -- ViewTextDocument
612 -- IN
613 --	media_id	- Key to retrive the document info.
614 --	datatype_id	- 1 if it is 'Short Text'
615 --			  2 if it is 'Long Text'.
616 --	function_name	- Function name of the form
617 --	entity_name	- Entity name for which attachment is made.
618 --	pk1_value	- First Primary Key value of the entity.
619 --	  to
620 --	pk5_value	- Fifth Primary key value of the entity.
621 --	from_url	- URL from which the attachments is invoked from.
622 --			  This is required to set the back link.
623 --	query_only	- Query flag is set 'Y' when called in query only
624 --			  mode.
625 
626 procedure ViewTextDocument (
627 	attached_document_id	in varchar2		,
628 	function_name		in varchar2		,
629 	entity_name		in varchar2		,
630 	pk1_value		in varchar2		,
631 	pk2_value		in varchar2		,
632 	pk3_value		in varchar2		,
633 	pk4_value		in varchar2		,
634 	pk5_value		in varchar2		,
635 	from_url		in varchar2		,
636 	query_only		in varchar2	default 'N'
637 )as
638 
639   l_lang		varchar2(24);
640 
641 begin
642 
643   -- Validate the session
644   if NOT (icx_sec.ValidateSession(null)) then
645      return;
646   end if;
647 
648   -- Set the language
649   l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
650 
651   -- Call the procedure that prints header
652   --Header(fnd_message.get_string('FND', 'FND-WEBATCH-VIEWTEXT-TITLE'),l_lang);
653 
654   -- Call PrintTextDocument with the packagename
655   PrintTextDocument (
659         	entity_name		=> entity_name	,
656 		package_name		=> 'FND_WEBATTCH'	,
657 		attached_document_id 	=> attached_document_id	,
658 		function_name		=> function_name	,
660         	pk1_value		=> pk1_value		,
661         	pk2_value		=> pk2_value		,
662         	pk3_value		=> pk3_value		,
663         	pk4_value		=> pk4_value		,
664         	pk5_value		=> pk5_value		,
665         	from_url		=> from_url		,
666         	query_only		=> query_only	);
667 
668 end ViewTextDocument;
669 
670 -- ViewFileDocument
671 --	Displays the file document.
672 -- IN
673 --	attached_document_id - Unique id for an attachment.
674 --	function_name	- Function name of the form
675 --	entity_name	- Entity name for which attachment is made.
676 --	pk1_value	- First Primary Key value of the entity.
677 --	  to
678 --	pk5_value	- Fifth Primary key value of the entity.
679 --	from_url	- URL from which the attachments is invoked from.
680 --			  This is required to set the back link.
681 --	query_only	- Query flag is set 'Y' when called in query only
682 --			  mode.
683 --
684 
685 procedure ViewFileDocument (
686 	attached_document_id	in varchar2
687 ) as
688 
689    cursor filename_cursor (l_attached_document_id varchar2) is
690      select dt.file_name, dt.media_id
691      from fnd_attached_documents ad, fnd_documents_tl dt
692      where  ad.document_id = dt.document_id
693      and  ad.attached_document_id = to_number(l_attached_document_id);
694 
695  l_url			varchar2(255);
696  l_file_name		varchar2(255);
697  l_attached_document_id	varchar2(16) := icx_call.decrypt2
698 				(viewfiledocument.attached_document_id);
699  gfm_agent      varchar2(255);
700  l_script_name          varchar2(255);
701  l_media_id             number;
702 
703 begin
704 
705   -- Validate the session
706   if NOT (icx_sec.ValidateSession(null)) then
707      return;
708   end if;
709 
710   -- Get the file_name which also has the file_content_type.
711   open filename_cursor (l_attached_document_id);
712   fetch filename_cursor into l_file_name, l_media_id;
713   if filename_cursor%NOTFOUND then
714 	owa_util.status_line(404, 'File Not Found', TRUE);
715 	RETURN;
716   end if;
717 
718   l_script_name := owa_util.get_cgi_env('SCRIPT_NAME');
719   /*web_plsql_agent := SUBSTR(l_script_name, 2,
720 			 INSTR(l_script_name, '/', 2) - 1);
721   web_server_prefix := 'http://' || owa_util.get_cgi_env('SERVER_NAME') ||
722         ':' || owa_util.get_cgi_env('SERVER_PORT'); */
723   gfm_agent := fnd_web_config.gfm_agent;
724 
725   l_url := fnd_gfm.construct_download_URL( gfm_agent, l_media_id, FALSE);
726 
727   -- Redirect the URL to display the file
728   owa_util.redirect_url( l_url );
729 
730 end ViewFileDocument;
731 
732 PROCEDURE add_attachment_gfm_wrapper(
733 	access_id NUMBER,
734         seq_num VARCHAR2 ,
735         category_id VARCHAR2,
736         document_description VARCHAR2,
737         datatype_id VARCHAR2,
738         text VARCHAR2 DEFAULT NULL,
739         file_name VARCHAR2 DEFAULT NULL,
740         url VARCHAR2 DEFAULT NULL,
741         function_name VARCHAR2 DEFAULT NULL,
742         entity_name VARCHAR2 DEFAULT NULL,
743         pk1_value VARCHAR2 DEFAULT NULL,
744         pk2_value VARCHAR2 DEFAULT NULL,
745         pk3_value VARCHAR2 DEFAULT NULL,
746         pk4_value VARCHAR2 DEFAULT NULL,
747         pk5_value VARCHAR2 DEFAULT NULL,
748         from_url VARCHAR2 DEFAULT NULL,
749         query_only VARCHAR2 DEFAULT NULL,
750         user_id    VARCHAR2 DEFAULT NULL,
751         dmid       VARCHAR2 DEFAULT NULL,
752         dmname     VARCHAR2 DEFAULT NULL,
753         package_name VARCHAR2
754         ) AS
755   l_media_id NUMBER;
756   l_file_name VARCHAR2(255);
757 BEGIN
758 
759   IF TO_NUMBER(datatype_id) = 6  THEN
760     l_media_id := fnd_gfm.confirm_upload(access_id    => access_id,
761                                       	file_name    => file_name,
762                                       	program_name => 'ADD_ATTACHMENT');
763     l_file_name := 'INTERNAL';
764   ELSIF TO_NUMBER(datatype_id) = 7 THEN
765     l_file_name := dmid;
766   END IF;
767 
768   Add_Attachment(seq_num, category_id, document_description, datatype_id,
769         text, l_file_name, url, function_name, entity_name, pk1_value,
770         pk2_value, pk3_value, pk4_value, pk5_value, l_media_id, user_id);
771 
772   -- This htp call is required for webDB implementation.
773   htp.p('');
774 
775 END;
776 
777 -- Add_Attachment
778 -- IN
779 --	seq_num		- Attachment Seq Number.
780 --	category_description
781 --	document_description
782 --	datatype_name	- Datatype identifier
783 --	document_text	- Document Text Input.
784 --	file_name	- File name
785 --	URL		- URL
786 --	function_name	- Function name of the form
787 --	entity_name	- Entity name for which attachment is made.
788 --	pk1_value	- First Primary Key value of the entity.
789 --	  to
790 --	pk5_value	- Fifth Primary key value of the entity.
791 --	from_url	- URL from which the attachments is invoked from.
792 --			  This is required to set the back link.
793 --	query_only	- Query flag is set 'Y' when called in query only
794 --			  mode.
798 --
795 --	media_id	- Document Content reference.
796 --	user_id		- Login id of the user
797 --      usage_type      - one-time or standard or template.
799 
800 procedure Add_Attachment (
801 	seq_num			in varchar2			,
802 	category_id		in varchar2			,
803 	document_description	in varchar2			,
804 	datatype_id		in varchar2			,
805 	text			in long				,
806 	file_name		in varchar2			,
807 	url			in varchar2			,
808 	function_name		in varchar2			,
809 	entity_name		in varchar2			,
810 	pk1_value		in varchar2			,
811 	pk2_value		in varchar2			,
812 	pk3_value		in varchar2			,
813 	pk4_value		in varchar2			,
814 	pk5_value		in varchar2			,
815 	media_id		in number			,
816 	user_id			in varchar2			,
817         usage_type              in varchar2 DEFAULT 'O'		,
818 	title			in varchar2 DEFAULT NULL
819 ) as
820 
821  l_rowid 		varchar2(30);
822  l_attached_document_id	number;
823  l_media_id		number:= add_attachment.media_id;
824  l_document_id		number;
825 
826  l_file_name		varchar2(255);
827  l_creation_date	date := SYSDATE;
828  l_created_by		number;
829  l_last_update_date	date := SYSDATE;
830  l_last_updated_by	number;
831  l_lang			varchar2(40);
832 
833 begin
834 
835   -- Set file name
836   if (to_number(datatype_id) = 5 ) then
837 	l_file_name := url;
838   elsif (to_number(datatype_id) in (6,7) ) then
839 	l_file_name := add_attachment.file_name;
840   end if;
841 
842   -- Set the WHO Columns.
843   l_created_by := to_number(user_id);
844   l_last_updated_by := l_created_by;
845 
846   -- Attached Document Id has to be populated from the sequence.
847   select fnd_attached_documents_s.nextval
848   into l_attached_document_id
849   from sys.dual;
850 
851   -- Set the language parameter
852   select userenv ('LANG')
853   into l_lang
854   from dual;
855 
856   -- Call the server side package for adding the attachment and documents.
857   fnd_attached_documents_pkg.insert_row (
858 	x_rowid			=> l_rowid			,
859 	x_attached_document_id	=> l_attached_document_id	,
860 	x_document_id		=> l_document_id		,
861 	x_creation_date		=> l_creation_date		,
862 	x_created_by		=> l_created_by			,
863 	x_last_update_date	=> l_last_update_date		,
864 	x_last_updated_by	=> l_last_updated_by		,
865 	x_last_update_login	=> NULL				,
866 	x_seq_num		=> to_number(seq_num)		,
867 	x_entity_name		=> entity_name			,
868 	x_column1		=> NULL				,
869 	x_pk1_value		=> pk1_value			,
870 	x_pk2_value		=> pk2_value			,
871 	x_pk3_value		=> pk3_value			,
872 	x_pk4_value		=> pk4_value			,
873 	x_pk5_value		=> pk5_value			,
874 	x_automatically_added_flag	=> 'N'			,
875 	x_request_id		=> NULL				,
876 	x_program_application_id	=>NULL			,
877 	x_program_id		=> NULL				,
878 	x_program_update_date	=> NULL				,
879 	x_attribute_category	=> NULL				,
880 	x_attribute1		=> NULL				,
881 	x_attribute2		=> NULL				,
882 	x_attribute3		=> NULL				,
883 	x_attribute4		=> NULL				,
884 	x_attribute5		=> NULL				,
885 	x_attribute6		=> NULL				,
886 	x_attribute7		=> NULL				,
887 	x_attribute8		=> NULL				,
888 	x_attribute9		=> NULL				,
889 	x_attribute10		=> NULL				,
890 	x_attribute11		=> NULL				,
891 	x_attribute12		=> NULL				,
892 	x_attribute13		=> NULL				,
893 	x_attribute14		=> NULL				,
894 	x_attribute15		=> NULL				,
895 	x_datatype_id		=> to_number(datatype_id)	,
896 	x_category_id		=> to_number(category_id)	,
897 	x_security_type		=> 4				,
898 	x_security_id		=> NULL				,
899 	x_publish_flag		=> 'Y'				,
900 	x_image_type		=> NULL				,
901 	x_storage_type		=> NULL				,
902 	x_usage_type		=> usage_type			,
903 	x_language		=> l_lang			,
904 	x_description		=> document_description		,
905 	x_file_name		=> l_file_name			,
906 	x_media_id		=> l_media_id			,
907 	x_doc_attribute_category	=> NULL			,
908 	x_doc_attribute1	=> NULL				,
909 	x_doc_attribute2	=> NULL				,
910 	x_doc_attribute3	=> NULL				,
911 	x_doc_attribute4	=> NULL				,
912 	x_doc_attribute5	=> NULL				,
913 	x_doc_attribute6	=> NULL				,
914 	x_doc_attribute7	=> NULL				,
915 	x_doc_attribute8	=> NULL				,
916 	x_doc_attribute9	=> NULL				,
917 	x_doc_attribute10	=> NULL				,
918 	x_doc_attribute11	=> NULL				,
919 	x_doc_attribute12	=> NULL				,
920 	x_doc_attribute13	=> NULL				,
921 	x_doc_attribute14	=> NULL				,
922 	x_doc_attribute15	=> NULL				,
923 	x_create_doc		=> 'N'				,
924 	x_url			=> url				,
925 	x_title			=> title
926   );
927 
928   -- Commit the transaction
929   commit;
930 
931   -- After the data is inserted into fnd_attached_documents, fnd_documents and
932   -- fnd_documents_tl table using the above procedure we get the media_id
933   -- which will be used to insert the text into fnd_document_short_text table.
934   if (to_number(datatype_id) = 2 ) then -- Text Datatype
935   	INSERT INTO fnd_documents_long_text(
936        		media_id,
937        		long_text) VALUES (
938        		l_media_id,
939        		text);
940 
941         -- Commit the transaction
942         commit;
943   elsif (to_number(datatype_id) = 1 ) then -- Short text Type Documents.
944   	INSERT INTO fnd_documents_short_text(
945        		media_id,
949 
946        		short_text) VALUES (
947        		l_media_id,
948        		text);
950         -- Commit the transaction
951         commit;
952   end if;
953 
954 exception
955   when others then
956   rollback;
957 
958 end Add_Attachment;
959 
960 PROCEDURE update_attachment_gfm_wrapper(
961         seq_num varchar2,
962         category_id varchar2,
963         document_description varchar2 DEFAULT NULL,
964         text varchar2 DEFAULT NULL,
965         file_name varchar2 DEFAULT NULL,
966         url varchar2 DEFAULT NULL,
967         attached_document_id varchar2 DEFAULT NULL,
968         datatype_id varchar2,
969         function_name varchar2 DEFAULT NULL,
970         entity_name varchar2 DEFAULT NULL,
971         pk1_value varchar2 DEFAULT NULL,
972         pk2_value varchar2 DEFAULT NULL,
973         pk3_value varchar2 DEFAULT NULL,
974         pk4_value varchar2 DEFAULT NULL,
975         pk5_value varchar2 DEFAULT NULL,
976         from_url varchar2 DEFAULT NULL,
977         query_only varchar2 DEFAULT NULL,
978         dmid       VARCHAR2 DEFAULT NULL,
979         dmname     VARCHAR2 DEFAULT NULL,
980         package_name varchar2
981   ) AS
982   l_media_id NUMBER;
983   l_file_name VARCHAR2(255);
984   l_user_id	VARCHAR2(24);
985   l_package_name	VARCHAR2(64);
986   l_access_id NUMBER;
987   l_start_pos NUMBER :=1;
988   l_length NUMBER := 0 ;
989 BEGIN
990 
991   -- Parse the packagename into package name, access_id and user_id.
992   l_length := instr(package_name,';',l_start_pos) - l_start_pos;
993   l_user_id := substr(package_name,l_start_pos,l_length);
994 
995   l_start_pos := l_start_pos + l_length + 1 ;
996   l_length := instr(package_name,';',l_start_pos) - l_start_pos;
997   l_package_name := substr(package_name,l_start_pos,l_length);
998 
999 
1000   l_start_pos := l_start_pos + l_length + 1 ;
1001   l_length := instr(package_name,';',l_start_pos) - l_start_pos;
1002   l_access_id := to_number(substr(package_name,l_start_pos,l_length));
1003 
1004   IF TO_NUMBER(datatype_id) = 6 THEN
1005     l_media_id := fnd_gfm.confirm_upload(access_id    => l_access_id,
1006                                         file_name    => file_name,
1007                                         program_name => 'UPDATE_ATTACHMENT');
1008     l_file_name := 'INTERNAL';
1009   ELSIF TO_NUMBER(datatype_id) = 7 THEN
1010     l_file_name := dmid;
1011   END IF;
1012 
1013   Update_Attachment(seq_num, category_id, document_description, text,
1014         l_file_name, url, attached_document_id, datatype_id, function_name,
1015         entity_name, pk1_value, pk2_value, pk3_value, pk4_value, pk5_value,
1016         l_media_id, l_user_id);
1017 
1018   -- This htp call is required for webDB implementation.
1019   htp.p('');
1020 
1021 END;
1022 
1023 -- Update_Attachment
1024 -- IN
1025 --	seq_num		- Attachment Seq Number.
1026 --	category_description
1027 --	document_description
1028 --	datatype_name	- Datatype identifier
1029 --	document_text	- Document Text Input.
1030 --	file_name	- File name
1031 --	URL		- URL
1032 --	function_name	--Function name of the form
1033 --	entity_name	- Entity name for which attachment is made.
1034 --	pk1_value	- First Primary Key value of the entity.
1035 --	  to
1036 --	pk5_value	- Fifth Primary key value of the entity.
1037 --      user_id         - Login id of the user
1038 --	media_id	- Document Content reference.
1039 --
1040 
1041 procedure Update_Attachment (
1042 	seq_num			in varchar2			,
1043 	category_id		in varchar2			,
1044 	document_description	in varchar2			,
1045 	text			in long				,
1046 	file_name		in varchar2			,
1047 	url			in varchar2			,
1048 	attached_document_id	in varchar2			,
1049 	datatype_id		in varchar2			,
1050 	function_name		in varchar2			,
1051 	entity_name		in varchar2			,
1052 	pk1_value		in varchar2			,
1053 	pk2_value		in varchar2			,
1054 	pk3_value		in varchar2			,
1055 	pk4_value		in varchar2			,
1056 	pk5_value		in varchar2			,
1057 	media_id		in number			,
1058         user_id                 in varchar2
1059 ) as
1060    cursor update_att_cursor (x_attached_document_id varchar2,
1061 			     x_function_name varchar2) is
1062 	select	row_id, document_id, media_id, start_date_active,
1063 		end_date_active, datatype_id
1064 	from 	fnd_attached_docs_form_vl
1065 	where attached_document_id = to_number(x_attached_document_id)
1066 	and   function_name= x_function_name
1067 	and   function_type = 'F';
1068 
1069   upddatarec	update_att_cursor%ROWTYPE;
1070 
1071  l_datatype_id	number;
1072  l_file_name	varchar2(255);
1073  l_last_update_date	date := SYSDATE;
1074  l_last_updated_by	number;
1075 
1076  l_document_id	number;
1077  l_media_id	number;
1078  l_attached_document_id	varchar2(16):= update_attachment.attached_document_id;
1079  l_function_name	varchar2(32):= update_attachment.function_name;
1080  l_lang		varchar2(40);
1081 
1082 begin
1083 
1084   -- Reterive the data for the attachment.
1085   open update_att_cursor (l_attached_document_id,l_function_name);
1086   fetch update_att_cursor into upddatarec;
1087   if update_att_cursor%NOTFOUND then
1088      close update_att_cursor;
1089      return;
1090   end if;
1091 
1092   -- Set file name and media id depending on datatype id.
1096   elsif (to_number(datatype_id) = 6) then
1093   if (to_number(datatype_id) = 5 ) then
1094 	l_file_name := url;
1095 	l_media_id  := null;
1097 	l_media_id := update_attachment.media_id;
1098 	l_file_name := update_attachment.file_name;
1099   elsif (to_number(datatype_id) = 7 ) then
1100 	l_file_name := update_attachment.file_name;
1101 	l_media_id  := null;
1102   else
1103 	l_file_name := update_attachment.file_name;
1104   	l_media_id := upddatarec.media_id;
1105   end if;
1106 
1107   -- Set the WHO Columns.
1108   l_last_updated_by := to_number(Update_Attachment.user_id);
1109 
1110   -- Set the language
1111   select USERENV('LANG')
1112   into l_lang
1113   from dual;
1114 
1115   -- Call the server side package for adding the attachment and documents.
1116   fnd_attached_documents_pkg.update_row (
1117 	x_rowid	=> upddatarec.row_id				,
1118 	x_attached_document_id	=> attached_document_id	,
1119 	x_document_id	=> upddatarec.document_id		,
1120 	x_last_update_date	=> l_last_update_date	,
1121 	x_last_updated_by	=> l_last_updated_by	,
1122 	x_last_update_login	=> NULL			,
1123 	x_seq_num	=> to_number(seq_num)		,
1124 	x_entity_name	=> entity_name			,
1125 	x_column1	=> NULL				,
1126 	x_pk1_value	=> pk1_value			,
1127 	x_pk2_value	=> pk2_value			,
1128 	x_pk3_value	=> pk3_value			,
1129 	x_pk4_value	=> pk4_value			,
1130 	x_pk5_value	=> pk5_value			,
1131 	x_automatically_added_flag	=> 'N'		,
1132 	x_request_id	=> NULL				,
1133 	x_program_application_id	=>NULL		,
1134 	x_program_id	=> NULL				,
1135 	x_program_update_date	=> NULL			,
1136 	x_attribute_category	=> NULL			,
1137 	x_attribute1	=> NULL				,
1138 	x_attribute2	=> NULL				,
1139 	x_attribute3	=> NULL				,
1140 	x_attribute4	=> NULL				,
1141 	x_attribute5	=> NULL				,
1142 	x_attribute6	=> NULL				,
1143 	x_attribute7	=> NULL				,
1144 	x_attribute8	=> NULL				,
1145 	x_attribute9	=> NULL				,
1146 	x_attribute10	=> NULL				,
1147 	x_attribute11	=> NULL				,
1148 	x_attribute12	=> NULL				,
1149 	x_attribute13	=> NULL				,
1150 	x_attribute14	=> NULL				,
1151 	x_attribute15	=> NULL				,
1152 	x_datatype_id	=> datatype_id			,
1153 	x_category_id	=> to_number(category_id)	,
1154 	x_security_type	=> 4				,
1155 	x_security_id	=> NULL				,
1156 	x_publish_flag	=> 'Y'				,
1157 	x_image_type	=> NULL				,
1158 	x_storage_type	=> NULL				,
1159 	x_usage_type	=> 'O'				,
1160 	x_start_date_active => upddatarec.start_date_active	,
1161 	x_end_date_active => upddatarec.end_date_active	,
1162 	x_language	=> l_lang		,
1163 	x_description	=> document_description		,
1164 	x_file_name	=> l_file_name			,
1165 	x_media_id	=> l_media_id			,
1166 	x_doc_attribute_category	=> NULL		,
1167 	x_doc_attribute1	=> NULL			,
1168 	x_doc_attribute2	=> NULL			,
1169 	x_doc_attribute3	=> NULL			,
1170 	x_doc_attribute4	=> NULL			,
1171 	x_doc_attribute5	=> NULL			,
1172 	x_doc_attribute6	=> NULL			,
1173 	x_doc_attribute7	=> NULL			,
1174 	x_doc_attribute8	=> NULL			,
1175 	x_doc_attribute9	=> NULL			,
1176 	x_doc_attribute10	=> NULL			,
1177 	x_doc_attribute11	=> NULL			,
1178 	x_doc_attribute12	=> NULL			,
1179 	x_doc_attribute13	=> NULL			,
1180 	x_doc_attribute14	=> NULL			,
1181 	x_doc_attribute15	=> NULL
1182   );
1183 
1184   -- Commit the transaction.
1185   commit;
1186 
1187   -- When the text is altered the the fnd_documents_short_text
1188   -- needs to be updated.  When the file type is altered we have to
1189   -- upload the file.
1190   if (datatype_id = 1 )  then -- Short Text Datatype
1191      UPDATE fnd_documents_short_text
1192      set short_text = text
1193      where media_id = l_media_id;
1194 
1195      -- Commit the transaction.
1196      commit;
1197 
1198   elsif (datatype_id = 2 ) then -- Long Text Document
1199      UPDATE fnd_documents_long_text
1200      set long_text = text
1201      where media_id = l_media_id;
1202 
1203      -- Commit the transaction.
1204      commit;
1205   end if;
1206 
1207 exception
1208   when others then
1209     rollback;
1210     if (update_att_cursor%ISOPEN) then
1211 	close update_att_cursor;
1212     end if;
1213 end Update_Attachment;
1214 
1215 -- ReloadSummary
1216 -- IN
1217 --      package_name    - Calling package name.
1218 --      function_name   - Function name of the form
1219 --      entity_name     - Entity name for which attachment is made.
1220 --      pk1_value       - First Primary Key value of the entity.
1221 --        to
1222 --      pk5_value       - Fifth Primary key value of the entity.
1223 --      from_url        - URL from which the attachments is invoked from.
1224 --                        This is required to set the back link.
1225 --      query_only      - Query flag is set 'Y' when called in query only
1226 --                        mode.
1227 --
1228 
1229 procedure ReloadSummary(
1230         package_name            in varchar2     default 'FND_WEBATTCH',
1231         function_name           in varchar2,
1232         entity_name             in varchar2,
1233         pk1_value               in varchar2,
1234         pk2_value               in varchar2     default NULL,
1235         pk3_value               in varchar2     default NULL,
1236         pk4_value               in varchar2     default NULL,
1237         pk5_value               in varchar2     default NULL,
1238         from_url                in varchar2                 ,
1242 begin
1239         query_only              in varchar2     default 'N'
1240 ) as
1241 
1243 
1244   -- Redirect the URL to the file location
1245   owa_util.redirect_url (curl => owa_util.get_owa_service_path|| package_name||
1246       '.Summary?function_name='|| icx_call.encrypt2(function_name)
1247         ||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1248         ||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1249         ||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1250         ||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
1251         ||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1252         ||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1253         ||'&'||'from_url=' ||icx_call.encrypt2(from_url)
1254         ||'&'||'query_only='||icx_call.encrypt2(query_only));
1255 
1256 end ReloadSummary;
1257 
1258 -- Header
1259 --      Creates Header for Attachment pages.
1260 -- IN
1261 --      Title   - Title of the page.
1262 --	Lang	- Language of the Title.
1263 --
1264 procedure Header( Lang	in varchar2
1265 ) as
1266 begin
1267 
1268   -- Validate the session
1269   if NOT (icx_sec.ValidateSession(null)) then
1270 	return;
1271   end if;
1272 
1273   htp.htmlOpen;
1274   htp.bodyOpen;
1275   -- Body background color.
1276   htp.p('<BODY bgcolor="#cccccc">');
1277 
1278   icx_admin_sig.toolbar(language_code => Header.Lang);
1279 
1280   -- Style sheet declaration.
1281   htp.p('<LINK REL=STYLESHEET HREF="/OA_HTML/US/osswa.css" TYPE="text/css">');
1282 
1283   htp.bodyClose;
1284   htp.htmlClose;
1285 
1286 end Header;
1287 
1288 -- PrintSummary
1289 --      Prints the attachment summary page body (No Titles and Links).
1290 -- IN
1291 --	package_name	- Calling package name.
1292 --      function_name   - Function name of the web function
1293 --      entity_name     - Entity name to which the attachment is made.
1294 --      pk1_value       - First primary key of the entity.
1295 --       through
1296 --      pk5_value       - Fifth primary key value of the entity.
1297 --      from_url        - URL from which the attachments is invoked from.
1298 --                        This is required to set the back link.
1299 --      query_only      - Query flag is set 'Y' when called in query only
1300 --                        mode.
1301 --
1302 
1303 procedure PrintSummary(
1304 	package_name            in varchar2     default 'FND_WEBATTCH',
1305         function_name           in varchar2,
1306         entity_name             in varchar2,
1307         pk1_value               in varchar2,
1308         pk2_value               in varchar2     default NULL,
1309         pk3_value               in varchar2     default NULL,
1310         pk4_value               in varchar2     default NULL,
1311         pk5_value               in varchar2     default NULL,
1312         from_url                in varchar2,
1313         query_only              in varchar2     default 'N'
1314 ) as
1315   cursor al_cursor is
1316     select SEQ_NUM ,
1317            CATEGORY_DESCRIPTION,
1318            DOCUMENT_DESCRIPTION,
1319            DATATYPE_NAME,
1320            DATATYPE_ID,
1321            FILE_NAME,
1322            USAGE_TYPE,
1323            USER_ENTITY_NAME,
1324            MEDIA_ID,
1325            ATTACHED_DOCUMENT_ID
1326     from   FND_ATTACHED_DOCS_FORM_VL
1327     where  FUNCTION_NAME =printsummary.function_name
1328     and    FUNCTION_TYPE ='F'
1329     and   (SECURITY_TYPE = 4 OR PUBLISH_FLAG = 'Y')
1330     and   (ENTITY_NAME= printsummary.entity_name and
1331 	  	PK1_VALUE=printsummary.pk1_value and
1332             decode(printsummary.pk2_value,null,'*',PK2_VALUE)=
1333   	    decode(printsummary.pk2_value,null,'*',printsummary.pk2_value) and
1334             decode(printsummary.pk3_value,null,'*',PK3_VALUE)=
1335 	    decode(printsummary.pk3_value,null,'*',printsummary.pk3_value) and
1336             decode(printsummary.pk4_value,null,'*',PK4_VALUE)=
1337 	    decode(printsummary.pk4_value,null,'*',printsummary.pk4_value) and
1338             decode(printsummary.pk5_value,null,'*',PK5_VALUE)=
1339 	    decode(printsummary.pk5_value,null,'*',printsummary.pk5_value))
1340     order by USER_ENTITY_NAME,SEQ_NUM;
1341 
1342   atlstrec 		al_cursor%ROWTYPE;
1343   link_string		varchar2(2000);
1344   l_del_msg	varchar2(255);
1345   l_title	varchar2(164);
1346   l_lang	varchar2(24);
1347   l_username	varchar2(80);
1348   j		number := 1.0;
1349 
1350 begin
1351 
1352   -- Validate the session
1353   if NOT (icx_sec.ValidateSession(null)) then
1354 	return;
1355   end if;
1356 
1357   -- Set the language
1358   l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
1359   l_username := UPPER(ICX_SEC.GetID(99));
1360 
1361   -- Retrive the delete message from the message dictionary
1362   l_del_msg := fnd_message.get_string('FND','ATCHMT-DELETE-ATCHMT');
1363 
1364   -- Set the title
1365   l_title := fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-TITLE');
1366 
1367   htp.htmlOpen;
1368   htp.headOpen;
1369   htp.p( '<SCRIPT LANGUAGE="JavaScript">');
1370   htp.p( ' function delete_attachment (del_url) {
1371       if (confirm('||'"'||l_del_msg||'"'||'))
1372       {
1373        	  parent.location=del_url
1374       }
1375     }');
1376   htp.print('function help_window(){
1377       help_win = window.open('||
1378 	fnd_help.get_url('ICX','@T_ATTACH')||
1382 	fnd_help.get_url('ICX','@T_ATTACH')||
1379 	', "help_win","resizable=yes,scrollbars=yes,toolbar=yes,width=450,'||
1380 	'height=250");
1381       help_win = window.open('||
1383 	', "help_win","resizable=yes,scrollbars=yes,toolbar=yes,width=450,'||
1384 	'height=250")}');
1385   htp.print(  '</SCRIPT>' );
1386   htp.title(l_title);
1387 
1388   -- Add the java script to the header to open the dm window for
1389   -- any DM function that is executed.
1390   fnd_document_management.get_open_dm_attach_window;
1391 
1392   -- Add java script to the header to open display window
1393   fnd_document_management.get_open_dm_display_window;
1394 
1395   -- Style sheet declaration.
1396   htp.p('<LINK REL=STYLESHEET HREF="/OA_HTML/US/osswa.css" TYPE="text/css">');
1397 
1398   htp.headClose;
1399   htp.bodyOpen;
1400 
1401   -- Body background color.
1402   htp.p('<BODY bgcolor="#cccccc">');
1403   htp.br;
1404 
1405 
1406   -- Process the cursor
1407   open al_cursor;
1408   fetch al_cursor into atlstrec;
1409   if al_cursor%NOTFOUND then
1410      close al_cursor;
1411      htp.bold(fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-NOATCHMTS'));
1412      htp.br;
1413      htp.print( '</LEFT>' );
1414      htp.br;
1415      htp.br;
1416      --htp.tableOpen( cattributes => ' border=1 cellpadding=3 bgcolor=white' );
1417      -- Branch to the bottom header
1418      GOTO bottom_header;
1419   end if;
1420 
1421   -- Create a header.
1422   htp.p('<table width=98% cellpadding=0 cellspacing=0 border=0>');
1423   htp.p('<tr bgcolor=#336699>');
1424   htp.p('<td><font color=#336699>.</font></td>');
1425   htp.p('<TD width=100% nowrap><FONT CLASS=containertitle>'||
1426 		fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-HEADING')
1427 		||' : '||atlstrec.user_entity_name||'</FONT></TD>');
1428   htp.tableRowClose;
1429   htp.tableClose;
1430   htp.br;
1431 
1432   -- There are some attachments for the entity. Construct the page.
1433   htp.p('<table width=98% bgcolor=#999999 cellpadding=2 '||
1434 						'cellspacing=0 border=0>');
1435   htp.p('<tr><td>');
1436 
1437   htp.p('<table width=100% cellpadding=2 cellspacing=1 border=0>');
1438   htp.p('<TR BGColor="336699">');
1439 
1440   --Top Column Headings
1441   htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1442                 '<FONT class=promptwhite>'||
1443                 fnd_message.get_string('FND','FND-WEBATCH-DOCUMENT-DETAILS')||
1444                                '</TD>');
1445   htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1446                 '<FONT class=promptwhite>'||
1447                 fnd_message.get_string('FND','FND-WEBATCH-DOCUMENT-SEQUENCE')||
1448                                '</TD>');
1449   htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1450                 '<FONT class=promptwhite>'||
1451                 fnd_message.get_string('FND','FND-WEBATCH-DOCUMENT-DESCRIPTI')||
1452                                '</TD>');
1453   htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1454                 '<FONT class=promptwhite>'||
1455                 fnd_message.get_string('FND','FND-WEBATCH-DOCUMENT-CATEGORY')||
1456                                '</TD>');
1457   htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1458                 '<FONT class=promptwhite>'||
1459                 fnd_message.get_string('FND','FND-WEBATCH-DOCUMENT-DATATYPE')||
1460                                '</TD>');
1461   if (query_only <> 'Y') then
1462      htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1463                 '<FONT class=promptwhite>'||
1464                 fnd_message.get_string('FND','FND-WEBATCH-EDIT-ATCHMT')||
1465                                '</TD>');
1466      htp.p('<TD align=center valign=bottom bgcolor="336699"> '||
1467                 '<FONT class=promptwhite>'||
1468                 fnd_message.get_string('FND','FND-WEBATCH-REMOVE-ATCHMT')||
1469                                '</TD>');
1470   end if;
1471 
1472   -- Create Attachment List to displayed.
1473   loop
1474 
1475     -- Make altenate rows with different background.
1476     if (round(j/2) = j/2) then
1477         htp.p('<TR BGColor="ffffff">');
1478     else
1479         htp.p('<TR BGColor="99ccff">');
1480     end if;
1481 
1482     --Construct the one html line per row fetched.
1483     if (atlstrec.datatype_id = 6) then
1484       htp.p('<TD ><FONT class=tabledata>'||
1485 		htf.anchor2(owa_util.get_owa_service_path
1486 		||'fnd_webattch.ViewFileDocument?attached_document_id='
1487                 ||icx_call.encrypt2(to_char(atlstrec.attached_document_id)),
1488          	htf.img2( '/OA_MEDIA/FNDIITMD.gif',
1489 			calt => fnd_message.get_string('FND','HE_VIEW')
1490 			||' '||atlstrec.datatype_name,
1491 			cattributes => 'border=no'),
1492 		ctarget=>'document_frame') ||'</TD>');
1493     elsif(atlstrec.datatype_id = 5) then
1494       htp.p('<TD ><FONT class=tabledata>'||
1495 	    htf.anchor2(atlstrec.file_name,
1496          	htf.img2( '/OA_MEDIA/FNDIITMD.gif',
1497 			calt => fnd_message.get_string('FND','HE_VIEW')
1498 			||' '||atlstrec.datatype_name,
1499 			cattributes => 'border=no'),
1500 		ctarget=>'document_frame')
1501 	  ||'</TD>');
1502     elsif(atlstrec.datatype_id = 7) then
1503           -- Get the HTML text for displaying the document
1504        fnd_document_management.get_launch_document_url (
1505 	      l_username,
1509       htp.p('<TD ><FONT class=tabledata>'||
1506               atlstrec.file_name,
1507               FALSE,
1508               link_string);
1510 		htf.anchor2(link_string, htf.img2( '/OA_MEDIA/FNDIITMD.gif',
1511 			calt => fnd_message.get_string('FND','HE_VIEW')
1512 			||' '||atlstrec.datatype_name,
1513 			cattributes => 'border=no'),
1514 		ctarget=>'document_frame')
1515 	  ||'</TD>');
1516     elsif(atlstrec.datatype_id = 1) OR
1517 	 (atlstrec.datatype_id = 2) then
1518 	htp.p('<TD ><FONT class=tabledata>'||
1519 		htf.anchor2(owa_util.get_owa_service_path|| package_name
1520 		||'.ViewTextDocument?attached_document_id='||
1521                 icx_call.encrypt2(to_char(atlstrec.attached_document_id))
1522 		||'&'||'function_name='||icx_call.encrypt2(function_name)
1523             	||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1524             	||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1525             	||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1526             	||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
1527             	||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1528             	||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1529             	||'&'||'from_url='||icx_call.encrypt2(from_url)
1530             	||'&'||'query_only='||icx_call.encrypt2(query_only),
1531          	htf.img2( '/OA_MEDIA/FNDIITMD.gif',
1532 			calt => fnd_message.get_string('FND','HE_VIEW')
1533 			||' '||atlstrec.datatype_name,
1534 			cattributes => 'border=no'),
1535 		ctarget=>'document_frame')
1536 	  ||'</TD>');
1537     end if;
1538     htp.p('<TD ><FONT class=tabledata>'|| atlstrec.seq_num|| '</TD>');
1539     htp.p('<TD ><FONT class=tabledata>'|| atlstrec.document_description||
1540 	  '</TD>');
1541     htp.p('<TD ><FONT class=tabledata>'|| atlstrec.category_description ||
1542 	  '</TD>');
1543     htp.p('<TD ><FONT class=tabledata>'|| atlstrec.datatype_name|| '</TD>');
1544 
1545     if  (atlstrec.usage_type <> 'S') and
1546         (query_only <> 'Y') then
1547 	htp.p('<TD ><FONT class=tabledata>'||
1548 		htf.anchor2(owa_util.get_owa_service_path|| package_name
1549 		||'.UpdateAttachment?attached_document_id='||
1550            	icx_call.encrypt2(to_char(atlstrec.attached_document_id))
1551            	||'&'||'function_name='||icx_call.encrypt2(function_name)
1552            	||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1553            	||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1554            	||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1555            	||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
1556            	||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1557            	||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1558            	||'&'||'from_url='|| icx_call.encrypt2
1559 					(replace(from_url,'&','%26'))
1560            	||'&'||'query_only='||icx_call.encrypt2(query_only),
1561          	htf.img2( '/OA_MEDIA/FNDIEDIT.gif', calign => 'CENTER',
1562             	calt => '''Edit Attachment''',
1563             	cattributes => 'border=yes width=17 height=16'),
1564             	cattributes=>'target="_top"')
1565 	  ||'</TD>');
1566     end if;
1567 
1568     if (query_only <> 'Y' ) then
1569 	htp.p('<TD ><FONT class=tabledata>'||
1570 		htf.anchor2('javascript:delete_attachment('''
1571 		|| owa_util.get_owa_service_path
1572 		||'fnd_webattch.DeleteAttachment?attached_document_id='
1573 		||icx_call.encrypt2(to_char(atlstrec.attached_document_id))
1574            	||'&'||'function_name='||icx_call.encrypt2(function_name)
1575            	||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1576            	||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1577            	||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1578            	||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1579            	||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1580            	||'&'||'from_url='||
1581                	 icx_call.encrypt2(replace(from_url,'&','%26'))
1582            	||'&'||'query_only='||icx_call.encrypt2(query_only)||''')',
1583                 htf.img2( '/OA_MEDIA/FNDIDELR.gif',
1584                    calign => 'CENTER', calt => '''Delete Attachment''',
1585                    cattributes => 'border=yes width=17 height=16'))
1586 	  ||'</TD>');
1587     end if;
1588     htp.tableRowClose;
1589 
1590     j := j + 1 ;
1591 
1592     fetch al_cursor into atlstrec;
1593     exit when al_cursor%NOTFOUND;
1594   end loop;
1595   close al_cursor;
1596 
1597   htp.tableClose;
1598   htp.p('</TD>');
1599   htp.p('</TR>');
1600   htp.p('</TABLE>');
1601 
1602   <<bottom_header>>
1603   htp.br;
1604   htp.p ('<LEFT>');
1605   if (query_only <> 'Y' ) then
1606      -- Create buttons for adding and back links.
1607      htp.p('<!-- This is a button table containing 2 buttons. The first'||
1608 		' row defines the edges and tops-->');
1609      htp.p('<TD ALIGN="LEFT" WIDTH="100%">');
1610      htp.p('<table cellpadding=0 cellspacing=0 border=0>');
1611      htp.p('<tr>');
1612      htp.p('<!-- left hand button, round left side and square right side-->');
1613      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDL.gif></td>');
1614      htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
1615      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRR.gif></td>');
1616      htp.p('<!-- standard spacer between square button images-->        ');
1617      htp.p('<td width=2 rowspan=5></td>');
1618 
1619      htp.p('<!-- right hand button, square left side and round right side-->');
1623      htp.p('</tr>');
1620      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRL.gif></td>');
1621      htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
1622      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDR.gif></td>');
1624      htp.p('<tr>');
1625      htp.p('<!-- one cell of this type required for every button -->');
1626      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1627      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1628      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1629      htp.p('</tr>');
1630      htp.p('<tr>');
1631      htp.p('<!-- Text and links for each button are listed here-->');
1632      htp.p('<td bgcolor=#cccccc height=20 nowrap><a href="'
1633 	||owa_util.get_owa_service_path ||package_name
1634 	||'.AddAttachment?function_name='||icx_call.encrypt2(function_name)
1635         ||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1636         ||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1637         ||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1638         ||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
1639         ||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1640         ||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1641         ||'&'||'from_url='||icx_call.encrypt2(replace(from_url,'&','%26'))
1642         ||'&'||'query_only='||icx_call.encrypt2(query_only)
1643 	||'"target="_parent"><font class=button>'
1644 	||fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-ADD'));
1645      htp.p('</FONT></TD>');
1646      htp.p('<TD bgcolor=#cccccc height=20 nowrap><A href="'
1647 	|| from_url|| '" target="_parent" ><FONT class=button>'
1648 	|| fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-EXIT'));
1649      htp.p('</FONT></TD>');
1650      htp.p('</FONT></A></TD>');
1651      htp.p('</TR>');
1652 
1653      htp.p('<TR>');
1654      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1655      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1656      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1657      htp.p('</TR>');
1658      htp.p('<TR>');
1659      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1660      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1661      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1662      htp.p('</TR>');
1663      htp.p('</TABLE>');
1664   else
1665      htp.p('<!-- This is a button table containing 1 buttons. The first'||
1666 				' row defines the edges and tops-->');
1667      htp.p('<TD ALIGN="LEFT" WIDTH="100%">');
1668      htp.p('<table cellpadding=0 cellspacing=0 border=0>');
1669      htp.p('<tr>');
1670      htp.p('<!-- button, round left side and right side-->');
1671      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDL.gif></td>');
1672      htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
1673      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDR.gif></td>');
1674 
1675      htp.p('<tr>');
1676      htp.p('<!-- one cell of this type required for every button -->');
1677      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1678      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1679      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
1680      htp.p('</tr>');
1681      htp.p('<tr>');
1682      htp.p('<!-- Text and links for each button are listed here-->');
1683      htp.p('<TD bgcolor=#cccccc height=20 nowrap><A href="'
1684 	|| from_url|| '"><FONT class=button>'
1685 	|| fnd_message.get_string('FND','FND-WEBATCH-SUMMARY-EXIT'));
1686      htp.p('</FONT></TD>');
1687      htp.p('</FONT></A></TD>');
1688      htp.p('</TR>');
1689 
1690      htp.p('<TR>');
1691      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1692      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1693      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
1694      htp.p('</TR>');
1695      htp.p('</TABLE>');
1696   end if;
1697 
1698   htp.bodyClose;
1699   htp.htmlClose;
1700 
1701   exception
1702     when others then
1703     rollback;
1704     if (al_cursor%isopen) then
1705        close al_cursor;
1706     end if;
1707 end PrintSummary;
1708 
1709 -- PrintTextDocument
1710 --      Print the web page that displays text document information.
1711 -- IN
1712 --      package_name    - Calling package name.
1713 --      attached_document_id - Reference to the attached document
1714 --      function_name   - Function name of the web function
1715 --      entity_name     - Entity name to which the attachment is made.
1716 --      pk1_value       - First primary key of the entity.
1717 --       through
1718 --      pk5_value       - Fifth primary key value of the entity.
1719 --      from_url        - URL from which the attachments is invoked from.
1723 --
1720 --                        This is required to set the back link.
1721 --      query_only      - Query flag is set 'Y' when called in query only
1722 --                        mode.
1724 
1725 procedure PrintTextDocument(
1726         package_name            in varchar2     default 'FND_WEBATTCH',
1727         attached_document_id    in varchar2,
1728         function_name           in varchar2     ,
1729         entity_name             in varchar2     ,
1730         pk1_value               in varchar2     ,
1731         pk2_value               in varchar2     default NULL,
1732         pk3_value               in varchar2     default NULL,
1733         pk4_value               in varchar2     default NULL,
1734         pk5_value               in varchar2     default NULL,
1735         from_url                in varchar2,
1736         query_only              in varchar2     default 'N'
1737  ) as
1738 
1739 
1740   l_seq_num			number;
1741   l_datatype_id			number;
1742   l_text			long;
1743   l_category_description	varchar2(255);
1744   l_document_description	varchar2(255);
1745   l_html_text			varchar2(32000);
1746   l_function_name     varchar2(30) :=
1747 			icx_call.decrypt2(PrintTextDocument.function_name);
1748   l_attached_document_id	varchar2(16):=
1749                 icx_call.decrypt2(PrintTextDocument.attached_document_id);
1750 
1751 begin
1752 
1753   -- Find out the datatype of text being displayed.
1754   select fd.datatype_id
1755   into l_datatype_id
1756   from fnd_documents fd, fnd_attached_documents fad
1757   where fd.document_id = fad.document_id
1758    and  fad.attached_document_id = to_number(l_attached_document_id);
1759 
1760   -- Get the document text for the attachment.
1761   if (l_datatype_id = 2) then
1762      select  fdfv.seq_num, fdfv.category_description,
1763              fdfv.document_description, fdlt.long_text
1764      into  l_seq_num,l_category_description,l_document_description,l_text
1765      from  fnd_attached_docs_form_vl fdfv, fnd_documents_long_text fdlt
1766      where fdfv.media_id = fdlt.media_id
1767       and  fdfv.attached_document_id = to_number(l_attached_document_id)
1768       and  fdfv.function_name = l_function_name
1769       and  fdfv.function_type = 'F';
1770   else
1771      select  fdfv.seq_num, fdfv.category_description,
1772              fdfv.document_description, fdst.short_text
1773      into  l_seq_num,l_category_description,l_document_description,l_text
1774      from  fnd_attached_docs_form_vl fdfv, fnd_documents_short_text fdst
1775      where fdfv.media_id = fdst.media_id
1776       and  fdfv.attached_document_id = to_number(l_attached_document_id)
1777       and  fdfv.function_name = l_function_name
1778       and  fdfv.function_type = 'F';
1779   end if;
1780 
1781   -- Replace all newline character with <BR> and newline character.
1782   l_html_text := substrb(replace(l_text, fnd_webattch.g_chr_newline,
1783                                  '<BR>'||fnd_webattch.g_chr_newline),
1784                           	 1, 32000);
1785 
1786   htp.bodyClose;
1787   htp.htmlClose;
1788   htp.p('<BODY bgcolor="#cccccc">');
1789 
1790   -- Display the text
1791   htp.formOpen('','','','','NAME="displaytext"');
1792   htp.tableOpen(  cattributes => ' border=0 cellpadding=2 cellspacing=0' );
1793   htp.tableRowOpen;
1794   htp.p('<TD>');
1795   htp.p('</TD>');
1796   htp.tableRowClose;
1797   htp.tableRowOpen;
1798   htp.tableData( l_html_text);
1799   htp.tableRowClose;
1800   htp.tableClose;
1801 
1802   htp.formClose;
1803   htp.bodyClose;
1804   htp.htmlClose;
1805 
1806 exception
1807 
1808   when NO_DATA_FOUND then
1809     htp.p(fnd_message.get_string('FND','FND-WEBATCH-ERROR-RETRIEVING'));
1810     htp.bodyClose;
1811     htp.htmlClose;
1812 
1813 end PrintTextDocument;
1814 
1815 -- PrintUpdateAttachment
1816 --      Prints the HTML form to update attachment and document information.
1817 -- IN
1818 --      package_name    - Calling package name.
1819 --      seq_num         - Attachment Seq Number.
1820 --      attached_document_id
1821 --      function_name   - Function name of the web function
1822 --      entity_name     - Entity name to which the attachment is made.
1826 --      from_url        - URL from which the attachments is invoked from.
1823 --      pk1_value       - First primary key of the entity.
1824 --       through
1825 --      pk5_value       - Fifth primary key value of the entity.
1827 --                        This is required to set the back link.
1828 --      query_only      - Query flag is set 'Y' when called in query only
1829 --                        mode.
1830 --
1831 
1832 procedure PrintUpdateAttachment (
1833         package_name            in varchar2     default 'FND_WEBATTCH',
1834         attached_document_id    in varchar2,
1835         function_name           in varchar2,
1836         entity_name             in varchar2,
1837         pk1_value               in varchar2,
1838         pk2_value               in varchar2     default NULL,
1839         pk3_value               in varchar2     default NULL,
1840         pk4_value               in varchar2     default NULL,
1841         pk5_value               in varchar2     default NULL,
1842         from_url                in varchar2,
1843         query_only      	in varchar2     default 'N'
1844 ) as
1845   cursor att_doc_cursor is
1846     select	seq_num,
1847    		category_description,
1848    		document_description,
1849    		datatype_id,
1850    		media_id,
1851    		file_name
1852     from fnd_attached_docs_form_vl
1853     where attached_document_id = PrintUpdateAttachment.attached_document_id;
1854 
1855   cursor doc_cat_cursor is
1856     select user_name,category_id,default_datatype_name,default_datatype_id
1857     from fnd_doc_categories_active_vl
1858     where category_id in
1859        (select fdcu.category_id
1860         from fnd_doc_category_usages fdcu, fnd_attachment_functions af
1861    	where af.attachment_function_id = fdcu.attachment_function_id
1862    	 and  af.function_name = PrintUpdateAttachment.function_name
1863          and  af.function_type = 'F'
1864    	 and  fdcu.enabled_flag = 'Y')
1865 	order by user_name;
1866 
1867   attdocrec	att_doc_cursor%ROWTYPE;
1868 
1869   document_short_text		varchar2(2000);
1870   document_long_text		long;
1871   x_seq_num			number;
1872   x_category_description	varchar2(255);
1873   x_document_description	varchar2(255);
1874   x_datatype_id			number;
1875   x_media_id			number;
1876   x_file_name			varchar2(255);
1877   l_lang			varchar2(24);
1878   access_id                  	number;
1879   upload_action			varchar2(2000);
1880   l_username			varchar2(80);
1881   l_reload_url			varchar2(2000);
1882 
1883   begin
1884 
1885    -- Validate the session
1886    if NOT (icx_sec.ValidateSession(null)) then
1887 	return;
1888    end if;
1889 
1890    -- Set the language
1891    l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
1892    l_username := UPPER(ICX_SEC.GetID(99));
1893 
1894    -- Construct reload URL.
1895    l_reload_url := owa_util.get_owa_service_path|| package_name||
1896         '.Summary?function_name='|| icx_call.encrypt2(function_name)
1897         ||'&'||'entity_name='||icx_call.encrypt2(entity_name)
1898         ||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
1899         ||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
1900         ||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
1901         ||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
1902         ||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
1903         ||'&'||'from_url=' ||icx_call.encrypt2(from_url)
1904         ||'&'||'query_only='||icx_call.encrypt2(query_only);
1905 
1906    htp.htmlOpen;
1907    htp.headOpen;
1908 
1909    -- Add the java script to the header to open the dm window for
1910    -- any DM function that is executed.
1911    fnd_document_management.get_open_dm_attach_window;
1912 
1913    -- Add java script to the header to open display window
1914    fnd_document_management.get_open_dm_display_window;
1915 
1916    -- Add java script to open the summary window.
1917    htp.p( '<SCRIPT LANGUAGE="JavaScript">');
1918    htp.p( ' function applySubmit(url) {
1919        document.UPDATE_ATCHMT.submit();
1920        top.location.href = url;
1921    }');
1922    htp.print(  '</SCRIPT>' );
1923 
1924    -- Style sheet declaration.
1925    htp.p('<LINK REL=STYLESHEET HREF="/OA_HTML/US/osswa.css" '||
1926                                                     'TYPE="text/css">');
1927 
1928    htp.headClose;
1929    htp.bodyOpen;
1930 
1931    -- Body background color.
1932    htp.p('<BODY bgcolor="#cccccc">');
1933    htp.br;
1934 
1935    -- Print the Page Header.
1936    htp.p('<table width=98% cellpadding=0 cellspacing=0 border=0>');
1937    htp.p('<tr bgcolor=#336699>');
1938    htp.p('<td><font color=#336699>.</font></td>');
1939    htp.p('<TD width=100% nowrap><FONT CLASS=containertitle>'||
1940          fnd_message.get_string('FND','FND-WEBATCH-EDIT-ATCHMT-HEADIN')
1941          ||'</FONT></TD>');
1942    htp.tableRowClose;
1943    htp.tableClose;
1944    htp.br;
1945 
1946    -- Select the updatable information.
1947    open att_doc_cursor;
1948    fetch att_doc_cursor into attdocrec;
1949    if att_doc_cursor%NOTFOUND then
1950      close att_doc_cursor;
1951      htp.p(fnd_message.get_string('FND','FND-WEBATCH-ERROR-RETRIEVING')
1952 								||'for update');
1953      htp.print( '</LEFT>' );
1954      htp.bodyClose;
1955      htp.htmlclose;
1956      return;
1957    end if;
1961       x_datatype_id:= attdocrec.datatype_id;
1958 
1959    loop
1960       x_seq_num 	:= attdocrec.seq_num;
1962       x_media_id 	:= attdocrec.media_id;
1963       x_file_name 	:= attdocrec.file_name;
1964       x_category_description := attdocrec.category_description;
1965       x_document_description := attdocrec.document_description;
1966 
1967       fetch att_doc_cursor into attdocrec;
1968       exit when att_doc_cursor%NOTFOUND;
1969    end loop;
1970    close att_doc_cursor;
1971 
1972    -- GFM Preparation
1973    access_id := fnd_gfm.authorize(NULL);
1974    upload_action := 'fnd_webattch.update_attachment_gfm_wrapper';
1975 
1976    htp.formOpen( curl => upload_action, cattributes=>'NAME="UPDATE_ATCHMT"',
1977                 cmethod => 'POST',cenctype=> 'multipart/form-data');
1978 
1979    -- Set the Attachment Information.
1980    htp.p('<table width=97% cellpadding=0 cellspacing=0 border=0>');
1981    htp.p('<!-- This row contains the help text -->');
1982    htp.p('<tr bgcolor=#cccccc>');
1983 
1984    htp.p('<td valign=top>');
1985    htp.p('<FONT CLASS=helptext>'||'&'||'nbsp;  '||
1986          '<IMG src=/OA_MEDIA/FNDIREQD.gif align=top>'||
1987          fnd_message.get_string('FND', 'FND-WEBATCH-REQ-FIELDS')||
1988          '</FONT>');
1989    htp.p('</TD>');
1990    htp.p('</TR>');
1991    htp.p('</TABLE>');
1992    htp.br;
1993 
1994    --Set the Attachment Information.
1995    htp.tableOpen(  cattributes => ' border=0 cellpadding=0 '||
1996                                   'width=97% cellspacing=0' );
1997    htp.tableRowOpen;
1998    htp.p('<TD align=right valign=top height=5 width=15%>'||
1999          '<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2000 	 '<FONT class=promptblack>'||
2001          fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-SEQUENCE')
2002          || ' </FONT></TD>');
2003 
2004    htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>'||
2005          '<FONT class=datablack><INPUT NAME='||'"seq_num"'||
2006          ' TYPE='||'"text"'||'  VALUE='|| to_char(x_seq_num)||
2007 	 ' SIZE=4 MAXLENGTH=20></FONT></TD>');
2008    htp.tableRowClose;
2009 
2010    --Process the category poplist.
2011    htp.tableRowOpen;
2012    htp.p('<TD align=right valign=top>'||
2013          '<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2014          '<FONT class=promptblack>'||
2015          fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-CATEGORY')
2016          || ' </FONT></TD>');
2017    htp.p('<TD><font class=datablack>');
2018    htp.formSelectOpen( cname => 'category_id' );
2019    FOR dc in doc_cat_cursor LOOP
2020      if (dc.user_name <> ' ' ) then
2021         if (dc.user_name <> x_category_description ) then
2022            htp.p('<OPTION value='||to_char(dc.category_id)||'>'||dc.user_name);
2023         else
2024 	   htp.p('<OPTION SELECTED value='||to_char(dc.category_id)||
2025                  '>'||dc.user_name);
2026         end if;
2027      else
2028         htp.p('<OPTION value>'||x_category_description);
2029      end if;
2030    END LOOP;
2031    htp.formSelectClose;
2032    htp.p('</FONT></TD>');
2033    htp.tableRowClose;
2034 
2035    -- Display Document Description.
2036    htp.tableRowOpen;
2037    htp.p('<TD align=right valign=top>'||
2038                 '<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2039                 '<FONT class=promptblack>'||
2040                 fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-DESCRIPTI')
2041                 || ' </FONT></TD>');
2042      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>'||
2043            '<FONT class=datablack><INPUT NAME='||'"document_description"'||
2044            ' TYPE='||'"text"'|| '  VALUE="'|| x_document_description ||
2045 	   '" SIZE=25 MAXLENGTH=80></FONT></TD>');
2046    htp.tableRowClose;
2047    htp.tableRowOpen;
2048 
2049    htp.p('<td colspan=5 valign=bottom height=30 VALIGN=CENTER ALIGN=LEFT>');
2050    htp.p('<FONT CLASS=datablack>'||
2051          fnd_message.get_string('FND', 'FND-WEBATCH-DOC-INFO-HEADING')||
2052          '</FONT></TD></TR>');
2053    htp.p('<TR><TD colspan=5 height=1 bgcolor=black>'||
2054          '<IMG src=/OA_MEDIA/FNDPX1.gif></TD></TR>');
2055    htp.p('<TR><TD height=10></TD></TR>');
2056    --htp.tableClose;
2057 
2058    -- Query the text from the database.
2059    if (x_datatype_id = 1 ) then
2060       select short_text
2061         into document_short_text
2062       from fnd_documents_short_text
2063       where media_id = x_media_id;
2064 
2065       -- Display the blank text information for Update.
2066       DocumentInformation (x_datatype_id => x_datatype_id,
2067 			  x_short_text => document_short_text);
2068 
2069    elsif (x_datatype_id = 2) then
2070       select long_text
2071         into document_long_text
2072       from fnd_documents_long_text
2073       where media_id = x_media_id;
2074 
2075       -- Display the blank text information for Update.
2076       DocumentInformation (x_datatype_id => x_datatype_id,
2077                           x_long_text => document_long_text);
2078 
2079    elsif (x_datatype_id = 6) then
2080 
2081       -- Display the File Information for update.
2082       DocumentInformation (x_datatype_id => x_datatype_id,
2083 			  x_file_name => x_file_name);
2084 
2085    elsif (x_datatype_id = 5) then
2086 
2087       -- Display blank URL document Information for Update
2091 
2088       DocumentInformation (x_datatype_id => x_datatype_id,
2089 			  x_file_name => x_file_name);
2090    elsif (x_datatype_id = 7) then
2092       -- Display blank URL document Information for Update
2093       DocumentInformation (x_datatype_id => x_datatype_id,
2094 			  x_file_name => x_file_name);
2095    else
2096       htp.formHidden ( cname =>'text', cvalue=>'');
2097       htp.formHidden ( cname =>'file_name', cvalue=>'');
2098       htp.formHidden ( cname =>'url', cvalue=>'');
2099    end if;
2100 
2101    -- Set the data needed for displaying summary as hidden field.
2102    htp.formHidden ( cname =>'attached_document_id',
2103 					cvalue=> attached_document_id );
2104    htp.formHidden ( cname =>'datatype_id', cvalue=> to_char(x_datatype_id));
2105    htp.formHidden ( cname =>'function_name', cvalue=> function_name );
2106 
2107    htp.formHidden ( cname =>'entity_name', cvalue=> entity_name);
2108    htp.formHidden ( cname =>'pk1_value', cvalue=> pk1_value);
2109    htp.formHidden ( cname =>'pk2_value', cvalue=> pk2_value);
2110    htp.formHidden ( cname =>'pk3_value', cvalue=> pk3_value);
2111    htp.formHidden ( cname =>'pk4_value', cvalue=> pk4_value);
2112    htp.formHidden ( cname =>'pk5_value', cvalue=> pk5_value);
2113    htp.formHidden ( cname =>'from_url',  cvalue=> from_url);
2114    htp.formHidden ( cname =>'query_only', cvalue=> query_only);
2115    htp.formHidden ( cname =>'package_name', cvalue=>
2116 	icx_sec.getID(icx_sec.PV_WEB_USER_ID)||';'
2117 	|| PrintUpdateAttachment.package_name ||';'||to_char(access_id)||';');
2118    htp.br;
2119 
2120    -- Create buttons for adding and back links.
2121    htp.p('<!-- This is a button table containing 2 buttons. The first'||
2122          ' row defines the edges and tops-->');
2123    htp.p('<TD ALIGN="LEFT" WIDTH="100%">');
2124    htp.p('<table cellpadding=0 cellspacing=0 border=0>');
2125    htp.p('<tr>');
2126    htp.p('<!-- left hand button, round left side and square right side-->');
2127    htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDL.gif></td>');
2128    htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
2129    htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRR.gif></td>');
2130    htp.p('<!-- standard spacer between square button images-->        ');
2131    htp.p('<td width=2 rowspan=5></td>');
2132 
2133    htp.p('<!-- right hand button, square left side and round right side-->');
2134    htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRL.gif></td>');
2135    htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
2136    htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDR.gif></td>');
2137    htp.p('</tr>');
2138    htp.p('<tr>');
2139    htp.p('<!-- one cell of this type required for every button -->');
2140    htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2141    htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2142    htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2143    htp.p('</tr>');
2144    htp.p('<tr>');
2145    htp.p('<!-- Text and links for each button are listed here-->');
2146    htp.p('<td bgcolor=#cccccc height=20 nowrap>'||
2147          '<A href="javascript:applySubmit('''||l_reload_url||''')"'||
2148          '  OnMouseOver="window.status='''||'OK'||''';return true">'||
2149          '<font class=button>'||
2150          fnd_message.get_string('FND','FND-WEBATCH-UPDATE-ATTACHMENT'));
2151    htp.p('</FONT></TD>');
2152    htp.p('<td bgcolor=#cccccc height=20 nowrap>'||
2153          '<A href="javascript:document.UPDATE_ATCHMT.reset()"'||
2154          '  OnMouseOver="window.status='''||'Reset'||''';return true">'||
2155          '<font class=button>'||
2156          fnd_message.get_string('FND','FND-WEBATCH-FORM-RESET'));
2157    htp.p('</FONT></TD>');
2158    htp.p('</FONT></A></TD>');
2159    htp.p('</TR>');
2160 
2161    htp.p('<TR>');
2162    htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2163    htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2164    htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2165    htp.p('</TR>');
2166    htp.p('<TR>');
2167    htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2168    htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2169    htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2170    htp.p('</TR>');
2171    htp.p('</TABLE>');
2172 
2173    htp.formClose;
2174    htp.bodyClose;
2175    htp.htmlClose;
2176 
2177    exception
2178    when others then
2179      rollback;
2180      if (doc_cat_cursor%isopen) then
2181        close doc_cat_cursor;
2182      end if;
2183      if (att_doc_cursor%isopen) then
2184        close att_doc_cursor;
2185      end if;
2186 end PrintUpdateAttachment;
2187 
2188 -- PrintAddAttachment
2189 --      Prints the HTML form to add attachment and document information.
2190 -- IN
2191 --      package_name    - Calling package name.
2192 --      function_name   - Function name of the web function
2193 --      entity_name     - Entity name to which the attachment is made.
2194 --      pk1_value       - First primary key of the entity.
2195 --       through
2196 --      pk5_value       - Fifth primary key value of the entity.
2197 --      from_url        - URL from which the attachments is invoked from.
2198 --                        This is required to set the back link.
2199 --      query_only      - Query flag is set 'Y' when called in query only
2200 --                        mode.
2204         package_name    in varchar2     default 'FND_WEBATTCH',
2201 --
2202 
2203 Procedure PrintAddAttachment(
2205         function_name   in varchar2,
2206         entity_name     in varchar2,
2207         pk1_value       in varchar2,
2208         pk2_value       in varchar2     default NULL,
2209         pk3_value       in varchar2     default NULL,
2210         pk4_value       in varchar2     default NULL,
2211         pk5_value       in varchar2     default NULL,
2212         from_url        in varchar2,
2213         query_only      in varchar2     default 'N'
2214  ) as
2215    cursor dc_cursor is
2216 	select user_name,category_id,default_datatype_name,default_datatype_id
2217 	from fnd_doc_categories_active_vl
2218 	where category_id in
2219 	 (select fdcu.category_id
2220 	  from fnd_doc_category_usages fdcu, fnd_attachment_functions af
2221 	  where af.attachment_function_id = fdcu.attachment_function_id
2222 	   and     af.function_name = PrintAddAttachment.function_name
2223            and     af.function_type = 'F'
2224 	   and     fdcu.enabled_flag = 'Y')
2225 	order by user_name;
2226 
2227    cursor sm_cursor is
2228     select NVL(max(seq_num),0) + 10
2229       from fnd_attached_documents
2230      where entity_name = PrintAddAttachment.entity_name
2231      and   pk1_value   = PrintAddAttachment.pk1_value
2232      and decode(PrintAddAttachment.pk2_value,null,'*',PK2_VALUE) =
2233     decode(PrintAddAttachment.pk2_value,null,'*',PrintAddAttachment.pk2_value)
2234      and decode(PrintAddAttachment.pk3_value,null,'*',PK3_VALUE)=
2235     decode(PrintAddAttachment.pk3_value,null,'*',PrintAddAttachment.pk3_value)
2236      and decode(PrintAddAttachment.pk4_value,null,'*',PK4_VALUE)=
2237     decode(PrintAddAttachment.pk4_value,null,'*', PrintAddAttachment.pk4_value)
2238      and decode(PrintAddAttachment.pk5_value,null,'*',PK5_VALUE)=
2239     decode(PrintAddAttachment.pk5_value,null,'*',PrintAddAttachment.pk5_value);
2240 
2241    seq_num	 	number := 10;
2242    l_lang		varchar2(24);
2243    access_id     	number;
2244    upload_action	varchar2(2000);
2245    l_callback_url       varchar2(4000);
2246    l_search_document_url       varchar2(4000);
2247    l_username                  varchar2(80);
2248    l_reload_url       varchar2(2000);
2249 
2250    begin
2251 
2252      -- Validate the session
2253      if NOT (icx_sec.ValidateSession(null)) then
2254 	return;
2255      end if;
2256 
2257      -- Set the language
2258      l_lang :=  icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
2259      l_username := UPPER(ICX_SEC.GetID(99));
2260 
2261      l_reload_url := owa_util.get_owa_service_path|| package_name||
2262         '.Summary?function_name='|| icx_call.encrypt2(function_name)
2263 	||'&'||'entity_name='||icx_call.encrypt2(entity_name)
2264 	||'&'||'pk1_value='||icx_call.encrypt2(pk1_value)
2265 	||'&'||'pk2_value='||icx_call.encrypt2(pk2_value)
2266 	||'&'||'pk3_value='||icx_call.encrypt2(pk3_value)
2267 	||'&'||'pk4_value='||icx_call.encrypt2(pk4_value)
2268 	||'&'||'pk5_value='||icx_call.encrypt2(pk5_value)
2269 	||'&'||'from_url=' ||icx_call.encrypt2(from_url)
2270 	||'&'||'query_only='||icx_call.encrypt2(query_only);
2271 
2272      htp.htmlOpen;
2273      htp.headOpen;
2274 
2275      -- Add the java script to the header to open the dm window for
2276      -- any DM function that is executed.
2277      fnd_document_management.get_open_dm_attach_window;
2278 
2279      -- Add java script to the header to open display window
2280      fnd_document_management.get_open_dm_display_window;
2281 
2282      htp.p( '<SCRIPT LANGUAGE="JavaScript">');
2283      htp.p( ' function applySubmit(url) {
2284          document.ADD_ATCHMT.submit();
2285 	 top.location.href = url;
2286      }');
2287      htp.print(  '</SCRIPT>' );
2288 
2289      -- Style sheet declaration.
2290      htp.p('<LINK REL=STYLESHEET HREF="/OA_HTML/US/osswa.css" '||
2291 							'TYPE="text/css">');
2292 
2293      htp.headClose;
2294      htp.bodyOpen;
2295 
2296      -- Body background color.
2297      htp.p('<BODY bgcolor="#cccccc">');
2298      htp.br;
2299 
2300      -- Print the Page Header.
2301      htp.p('<table width=98% cellpadding=0 cellspacing=0 border=0>');
2302      htp.p('<tr bgcolor=#336699>');
2303      htp.p('<td><font color=#336699>.</font></td>');
2304      htp.p('<TD width=100% nowrap><FONT CLASS=containertitle>'||
2305             fnd_message.get_string('FND','FND-WEBATCH-ADDATCHMT-HEADING')
2306             ||'</FONT></TD>');
2307      htp.tableRowClose;
2308      htp.tableClose;
2309      htp.br;
2310 
2311      -- GFM Preparation
2312      access_id := fnd_gfm.authorize(NULL);
2313      upload_action := 'fnd_webattch.add_attachment_gfm_wrapper';
2314 
2315      htp.formOpen( curl => upload_action , cattributes=>'NAME="ADD_ATCHMT"',
2316                 cmethod => 'POST',cenctype=> 'multipart/form-data');
2317 
2318      htp.p('<table width=97% cellpadding=0 cellspacing=0 border=0>');
2319      htp.p('<!-- This row contains the help text -->');
2320      htp.p('<tr bgcolor=#cccccc>');
2321 
2322      htp.p('<td valign=top>');
2323      htp.p('<FONT CLASS=helptext>'||'&'||'nbsp;  '||
2324            fnd_message.get_string('FND', 'FND-WEBATCH-ATCHMT-INFO-HEADIN')||'  '
2325 	   ||'<IMG src=/OA_MEDIA/FNDIREQD.gif align=top>'||
2326      	   fnd_message.get_string('FND', 'FND-WEBATCH-REQ-FIELDS')||'  '||
2327 	   '</FONT>');
2328      htp.p('</TD>');
2332 
2329      htp.p('</TR>');
2330      htp.p('</TABLE>');
2331      htp.br;
2333      --Set the Attachment Information.
2334      htp.tableOpen(  cattributes => ' border=0 cellpadding=0 '||
2335 					'width=97% cellspacing=0' );
2336 
2337      -- Get the max Sequence Number and set it seq_num.
2338      open sm_cursor;
2339      fetch sm_cursor into seq_num;
2340      close sm_cursor;
2341 
2342      htp.tableRowOpen;
2343      htp.p('<TD align=right valign=top height=5 width=35%>'||
2344 		'<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2345 		'<FONT class=promptblack>'||
2346 		fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-SEQUENCE')
2347 		|| ' </FONT></TD>');
2348 
2349      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>'||
2350 	   '<FONT class=datablack><INPUT NAME='||'"seq_num"'||
2351 	   ' TYPE='||'"text"'||'  VALUE='||
2352 	   to_char(seq_num)||' SIZE=4 MAXLENGTH=20></FONT></TD>');
2353      htp.tableRowClose;
2354 
2355      --Process the category poplist.
2356      htp.tableRowOpen;
2357      htp.p('<TD align=right valign=top>'||
2358 		'<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2359 		'<FONT class=promptblack>'||
2360 		fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-CATEGORY')
2361 		|| ' </FONT></TD>');
2362      htp.p('<TD><FONT class=datablack>');
2363      htp.formSelectOpen( cname => 'category_id' );
2364      FOR dc in dc_cursor LOOP
2365          if (dc.user_name <> ' ' ) then
2366            htp.p('<OPTION value='||to_char(dc.category_id)||'>'|| dc.user_name);
2367          else
2368            htp.p('<OPTION value>'||dc.user_name);
2369          end if;
2370      END LOOP;
2371      htp.formSelectClose;
2372      htp.p('</FONT></TD>');
2373      htp.tableRowClose;
2374 
2375      -- Display Document Description.
2376      htp.tableRowOpen;
2377      htp.p('<TD align=right valign=top>'||
2378 		'<IMG src=/OA_MEDIA/FNDIREQD.gif border=no>'||
2379 		'<FONT class=promptblack>'||
2380 		fnd_message.get_string('FND', 'FND-WEBATCH-DOCUMENT-DESCRIPTI')
2381 		|| ' </FONT></TD>');
2382      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>'||
2383 	   '<FONT class=datablack><INPUT NAME='||'"document_description"'||
2384 	   ' TYPE='||'"text"'|| ' SIZE=25 MAXLENGTH=80></FONT></TD>');
2385      htp.tableRowClose;
2386 
2387      -- Construct the Document Information area.
2388      -- Text datatype
2389      htp.tableRowOpen;
2390 
2391      htp.p('<td colspan=5 valign=bottom height=30 VALIGN=CENTER ALIGN=LEFT>');
2392      htp.p('<FONT CLASS=datablack>'||
2393      	   fnd_message.get_string('FND', 'FND-WEBATCH-DOC-INFO-HEADING')||
2394 	   '</FONT></TD></TR>');
2395      htp.p('<TR><TD colspan=5 height=1 bgcolor=black>'||
2396 	   '<IMG src=/OA_MEDIA/FNDPX1.gif></TD></TR>');
2397      htp.p('<TR><TD height=10></TD></TR>');
2398 
2399      htp.tableRowOpen;
2400      htp.p('<TD align=left valign=top>');
2401      htp.p('<FONT class=promptblack><INPUT name="datatype_id"'||
2402 	   'type=radio checked value="2">'||
2403 	   fnd_message.get_string('FND','FND-WEBATCH-TEXT-DATATYPE')||'</TD>');
2404      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>');
2405      htp.p('<FONT class=datablack><TEXTAREA NAME ="text"  ROWS=4 + COLS=38>'||
2406 							'</TEXTAREA></FONT>');
2407      htp.tableRowClose;
2408 
2409      -- File Datatype
2410      htp.tableRowOpen;
2411      htp.p('<TD align=left>');
2412      htp.p('<FONT class=promptblack><INPUT name="datatype_id"'||
2413 	   'type=radio value="6">'||
2414 	   fnd_message.get_string('FND','FND-WEBATCH-FILE-DATATYPE')||'</TD>');
2415      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>');
2416      htp.p('<FONT class=datablack><INPUT TYPE="File" NAME="file_name"'||
2417 					' SIZE="32"></FONT>');
2418      htp.tableRowClose;
2419 
2420      -- URL Datatype
2421      htp.tableRowOpen;
2422      htp.p('<TD align=left>');
2423      htp.p('<FONT class=promptblack><INPUT name="datatype_id"'||
2424 	 'type=radio value="5">'||
2425 	 fnd_message.get_string('FND','FND-WEBATCH-WEBPAGE-DATATYPE')||'</TD>');
2426      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>');
2427      htp.p('<FONT class=datablack><INPUT TYPE="Text" NAME="url"'||
2428 					' SIZE="40"></FONT>');
2429      htp.tableRowClose;
2430 
2431      /*
2432      ** Create the callback syntax to update the local fields
2433      */
2434      fnd_document_management.set_document_id_html (
2435         null,
2436         'FNDATTACH',
2437         'dmid',
2438         'dmname',
2439         l_callback_url);
2440 
2441      -- Get the url syntax for performing a search
2442      fnd_document_management.get_launch_attach_url (
2443         l_username,
2444         l_callback_url,
2445         TRUE,
2446         l_search_document_URL);
2447 
2448      -- DM Datatype
2449      htp.tableRowOpen;
2450      htp.p('<TD align=left width=35% NOWRAP>');
2451      htp.p('<FONT class=promptblack><INPUT name="datatype_id"'||
2452 	   'type=radio value="5">'||
2453 	   fnd_message.get_string('FND','FND-WEBATCH-DM-DATATYPE')||'</TD>');
2454      htp.p('<TD  VALIGN=CENTER ALIGN=LEFT>');
2455      htp.p('<FONT class=datablack><INPUT TYPE="Text" NAME="dmid"'||
2456 	   ' SIZE="40"></FONT>'||l_search_document_URL);
2457      htp.tableRowClose;
2458      htp.tableClose;
2459 
2460      -- Set the data needed for add attachment as hidden field.
2461      htp.formHidden (cname =>'access_id', cvalue=> to_char(access_id));
2465      htp.formHidden (cname =>'pk2_value', cvalue=> pk2_value);
2462      htp.formHidden (cname =>'function_name', cvalue=> function_name);
2463      htp.formHidden (cname =>'entity_name', cvalue=> entity_name);
2464      htp.formHidden (cname =>'pk1_value', cvalue=> pk1_value);
2466      htp.formHidden (cname =>'pk3_value', cvalue=> pk3_value);
2467      htp.formHidden (cname =>'pk4_value', cvalue=> pk4_value);
2468      htp.formHidden (cname =>'pk5_value', cvalue=> pk5_value);
2469      htp.formHidden (cname =>'from_url',  cvalue=> from_url);
2470      htp.formHidden (cname =>'query_only',cvalue=> query_only);
2471      htp.formHidden (cname =>'user_id',
2472                         cvalue=> icx_sec.getID(icx_sec.PV_WEB_USER_ID));
2473      htp.formHidden (cname =>'package_name',cvalue=>
2474 				PrintAddAttachment.package_name );
2475 
2476      -- Submit and Reset Buttons.
2477      -- Create buttons for adding and back links.
2478      htp.br;
2479      htp.p('<!-- This is a button table containing 2 buttons. The first'||
2480                 ' row defines the edges and tops-->');
2481      htp.p('<TD ALIGN="LEFT" WIDTH="100%">');
2482      htp.p('<table cellpadding=0 cellspacing=0 border=0>');
2483      htp.p('<tr>');
2484      htp.p('<!-- left hand button, round left side and square right side-->');
2485      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDL.gif></td>');
2486      htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
2487      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRR.gif></td>');
2488      htp.p('<!-- standard spacer between square button images-->        ');
2489      htp.p('<td width=2 rowspan=5></td>');
2490 
2491      htp.p('<!-- right hand button, square left side and round right side-->');
2492      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBSQRL.gif></td>');
2493      htp.p('<td bgcolor=#333333><img src=/OA_MEDIA/FNDPX3.gif></td>');
2494      htp.p('<td rowspan=5><img src=/OA_MEDIA/FNDBRNDR.gif></td>');
2495      htp.p('</tr>');
2496      htp.p('<tr>');
2497      htp.p('<!-- one cell of this type required for every button -->');
2498      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2499      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2500      htp.p('<td bgcolor=#ffffff><img src=/OA_MEDIA/FNDPX6.gif></td>');
2501      htp.p('</tr>');
2502      htp.p('<tr>');
2503      htp.p('<!-- Text and links for each button are listed here-->');
2504      htp.p('<td bgcolor=#cccccc height=20 nowrap>'||
2505 	   '<A href="javascript:applySubmit('''||l_reload_url||''')"'||
2506 	   '  OnMouseOver="window.status='''||'OK'||''';return true">'||
2507            '<font class=button>'||
2508            fnd_message.get_string('FND','FND-WEBATCH-ADD-ATTACHMENT'));
2509      htp.p('</FONT></TD>');
2510      htp.p('<td bgcolor=#cccccc height=20 nowrap>'||
2511 	   '<A href="javascript:document.ADD_ATCHMT.reset()"'||
2512 	   '  OnMouseOver="window.status='''||'Reset'||''';return true">'||
2513            '<font class=button>'||
2514            fnd_message.get_string('FND','FND-WEBATCH-FORM-RESET'));
2515      htp.p('</FONT></TD>');
2516      htp.p('</FONT></A></TD>');
2517      htp.p('</TR>');
2518 
2519      htp.p('<TR>');
2520      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2521      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2522      htp.p('<TD bgcolor=#666666><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2523      htp.p('</TR>');
2524      htp.p('<TR>');
2525      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2526      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2527      htp.p('<TD bgcolor=#333333><IMG src=/OA_MEDIA/FNDPX3.gif></TD>');
2528      htp.p('</TR>');
2529      htp.p('</TABLE>');
2530      htp.formClose;
2531      htp.bodyClose;
2532      htp.htmlClose;
2533 
2534    exception
2535      when others then
2536        htp.print('Error occured and control in exception');
2537        rollback;
2538        if (dc_cursor%isopen) then
2539          close dc_cursor;
2540        end if;
2541 end PrintAddAttachment;
2542 
2543 PROCEDURE PrintBlankPage
2544 IS
2545 BEGIN
2546   htp.htmlOpen;
2547   htp.bodyOpen;
2548 
2549   -- Body background color.
2550   htp.p('<BODY bgcolor="#cccccc">');
2551 
2552   htp.bodyClose;
2553   htp.htmlClose;
2554 END PrintBlankPage;
2555 
2556 /*===========================================================================
2557 
2558 Function        set_document_identifier
2559 
2560 Purpose         This is call back implemented to pass the document reference
2561                 identifier to the attachments.
2562 
2563 
2564 file_id - A unique access key for document reference attributes
2565                         being attached to a application entity.
2566 
2567 document_identifier - full concatenated document attribute strings.
2568         nodeid:libraryid:documentid:version:document_name
2569 
2570 ============================================================================*/
2571 PROCEDURE set_document_identifier (
2572 p_file_id         IN  VARCHAR2,
2573 p_document_id     IN  VARCHAR2)
2574 
2575 IS
2576 
2577 BEGIN
2578   /*
2579   ** Update FND_TEMP_FILE_PARAMETERS
2580   */
2581   IF (p_file_id IS NOT NULL) THEN
2582         UPDATE  fnd_temp_file_parameters
2583         SET     FILE_PARAMETERS = p_document_id
2584         WHERE   FILE_ID = p_file_id;
2585 
2586         if (SQL%NOTFOUND) then
2587           RAISE NO_DATA_FOUND;
2588         end if;
2589   END IF;
2590 
2591 
2592    htp.headOpen;
2593    htp.title(wf_core.translate('WFDM_TRANSPORT_WINDOW'));
2594    htp.headClose;
2595 
2596    htp.htmlopen;
2597 
2598    htp.p('<body bgcolor="#CCCCCC" onLoad="javascript:top.window.close();'||
2599          'return true;">');
2600 
2601    htp.htmlclose;
2602 
2603 
2604 END set_document_identifier;
2605 
2606 /*===========================================================================
2607 
2608 Function        authorizeDMTransaction
2609 
2610 Purpose         This will provide a secure key for DM transaction from forms.
2611 
2612 
2613 file_id -       A unique access key for document reference attributes
2614                 being attached to a application entity.
2615 
2616 ============================================================================*/
2617 procedure authorizeDMTransaction(
2618 		file_id OUT NOCOPY VARCHAR2)
2619 IS
2620   pragma AUTONOMOUS_TRANSACTION;
2621   l_file_id	varchar2(32);
2622 BEGIN
2623   -- Generate Random Number for secured access key
2624   fnd_random_pkg.init(7);
2625   fnd_random_pkg.seed(to_number(to_char(sysdate, 'JSSSSS')), 10, false);
2626   l_file_id := fnd_random_pkg.get_next;
2627 
2628   -- Store the file attributes for secured access and commit the
2629   -- transaction.
2630   insert into fnd_temp_file_parameters (file_id, file_parameters)
2631   values (l_file_id, null);
2632 
2633   -- Commit the transaction
2634   COMMIT;
2635 
2636   -- Set the file id to the ouput parameter
2637   file_id := l_file_id;
2638 
2639 END;
2640 
2641 end FND_WEBATTCH;