DBA Data[Home] [Help]

PACKAGE BODY: APPS.IBE_DSP_HIERARCHY_SETUP_PVT

Source


1 PACKAGE BODY IBE_DSP_HIERARCHY_SETUP_PVT AS
2 /* $Header: IBEVCHSB.pls 120.3 2005/12/28 13:21:13 savarghe ship $ */
3 
4   --
5   --
6   -- Start of Comments
7   --
8   -- NAME
9   --   IBE_DSP_HIERARCHY_SETUP_PVT
10   --
11   -- PURPOSE
12   --   Private API for saving, retrieving and updating sections.
13   --
14   -- NOTES
15   --   This is a pulicly accessible pacakge.  It should be used by all
16   --   sources for saving, retrieving and updating personalized queries
17   -- within the personalization framework.
18   --
19 
20   -- HISTORY
21   --   11/28/99           VPALAIYA         Created
22   --   12/12/02           SCHAK         Modified for NOCOPY (Bug # 2691704) and Debug (Bug # 2691710) Changes.
23   --   12/19/02           SCHAK         Modified for reverting Debug (IBEUtil) Changes.
24   --   12/21/02           SCHAK         Modified for NOCOPY (Bug # 2691704)) Changes and adding exceptions.
25   --   07/21/04           SVIJAYKR      Modified for performance bug (Bug # 3765932) - removed literals from cursor query
26 
27   -- **********************************************************************************************************
28 
29 G_PKG_NAME  CONSTANT VARCHAR2(30):='IBE_DSP_HIERAHCY_SETUP_PVT';
30 G_FILE_NAME CONSTANT VARCHAR2(12):='IBEVCHSB.pls';
31 G_ENABLE_TRACE VARCHAR2(1) := 'N';
32 
33 TYPE section_map_rec IS RECORD
34   (
35     from_section_id   NUMBER,
36     to_section_id     NUMBER
37   );
38 
39 TYPE section_map_list IS TABLE OF section_map_rec;
40 
41 --
42 -- get master mini site id for the store
43 --
44 PROCEDURE Get_Master_Mini_Site_Id
45   (
46    x_mini_site_id    OUT NOCOPY NUMBER,
47    x_root_section_id OUT NOCOPY NUMBER
48   )
49 IS
50   l_api_name                     CONSTANT VARCHAR2(30) :=
51     'Get_Master_Mini_Site_Id';
52   l_api_version                  CONSTANT NUMBER       := 1.0;
53 
54   CURSOR c1 IS
55     SELECT msite_id, msite_root_section_id FROM ibe_msites_b
56       WHERE UPPER(master_msite_flag) = 'Y';
57 BEGIN
58 
59   OPEN c1;
60   FETCH c1 INTO x_mini_site_id, x_root_section_id;
61   IF (c1%NOTFOUND) THEN
62     CLOSE c1;
63     RAISE FND_API.G_EXC_ERROR;
64   END IF;
65   CLOSE c1;
66 
67 END Get_Master_Mini_Site_Id;
68 
69 --
70 -- get concatenation of all section ids starting with the p_section_id
71 --
72 PROCEDURE Get_Concat_Ids
73   (
74    p_section_id          IN  NUMBER,
75    p_master_mini_site_id IN  NUMBER,
76    x_concat_ids          OUT NOCOPY VARCHAR2,
77    x_level_number        OUT NOCOPY NUMBER
78   )
79 IS
80   l_api_name                     CONSTANT VARCHAR2(30) := 'Get_Concat_Ids';
81   l_api_version                  CONSTANT NUMBER       := 1.0;
82 
83   l_delimiter                    CONSTANT VARCHAR2(1)  := '.';
84 
85   --
86   -- Get the list of ancestors for l_c_section_id upto the root section
87   --
88   CURSOR c1(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER) IS
89     SELECT parent_section_id FROM ibe_dsp_msite_sct_sects
90       WHERE parent_section_id IS NOT NULL
91       AND mini_site_id = l_c_master_mini_site_id
92       START WITH child_section_id = l_c_section_id
93       CONNECT BY PRIOR parent_section_id = child_section_id
94       AND PRIOR mini_site_id = l_c_master_mini_site_id
95       AND mini_site_id = l_c_master_mini_site_id;
96 BEGIN
97 
98   x_concat_ids := p_section_id;
99   x_level_number := 1;
100   FOR r1 IN c1(p_section_id, p_master_mini_site_id) LOOP
101     x_concat_ids := r1.parent_section_id || l_delimiter || x_concat_ids;
102     x_level_number := x_level_number + 1;
103   END LOOP;
104 
105 EXCEPTION
106 
107    WHEN OTHERS THEN
108      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
109      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
110      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
111      FND_MESSAGE.Set_Token('REASON', SQLERRM);
112      FND_MSG_PUB.Add;
113      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
114 
115 END Get_Concat_Ids;
116 
117 PROCEDURE Delete_Recursive_Sections
118   (
119    p_api_version                    IN NUMBER,
120    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
121    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
122    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
123    p_master_mini_site_id            IN NUMBER,
124    p_section_id                     IN NUMBER,
125    x_return_status                  OUT NOCOPY VARCHAR2,
126    x_msg_count                      OUT NOCOPY NUMBER,
127    x_msg_data                       OUT NOCOPY VARCHAR2
128   )
129 IS
130   l_api_name                     CONSTANT VARCHAR2(30) :=
131     'Delete_Recursive_Sections';
132   l_api_version                  CONSTANT NUMBER       := 1.0;
133   l_msg_count                    NUMBER;
134   l_msg_data                     VARCHAR2(2000);
135 
136   l_section_id                   NUMBER;
137   l_child_section_id             NUMBER;
138   l_mini_site_id                 NUMBER;
139   l_count                        NUMBER := -1;
140 
141   CURSOR c1(l_c_section_id IN NUMBER) IS
142     SELECT child_section_id FROM ibe_dsp_msite_sct_sects
143       WHERE parent_section_id = l_c_section_id AND
144       mini_site_id = p_master_mini_site_id;
145 
146 BEGIN
147 
148   -- cannot have savepoints within a recursively called function
149 
150   -- Initialize API return status to success
151   x_return_status := FND_API.G_RET_STS_SUCCESS;
152 
153   -- check if p_section_id has any children, if yes, then delete recursively
154   -- else delete the current section and return
155 
156   OPEN c1(p_section_id);
157   FETCH c1 INTO l_child_section_id;
158   IF (c1%NOTFOUND) THEN
159     -- p_section_id is a leaf section, delete it
160     CLOSE c1;
161 
162     IBE_DSP_SECTION_GRP.Delete_Section
163       (
164       p_api_version         => p_api_version,
165       p_init_msg_list       => FND_API.G_FALSE,
166       p_commit              => FND_API.G_FALSE,
167       p_validation_level    => p_validation_level,
168       p_section_id          => p_section_id,
169       p_access_name         => FND_API.G_MISS_CHAR,
170       x_return_status       => x_return_status,
171       x_msg_count           => x_msg_count,
172       x_msg_data            => x_msg_data
173       );
174 
175     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
176       RAISE FND_API.G_EXC_ERROR;
177     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
178       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
179     END IF;
180 
181   ELSE
182 
183     -- p_section_id is not a leaf section, so delete its children
184 
185     LOOP -- first time loop already has a valid l_child_section_id
186 
187       Delete_Recursive_Sections
188         (
189         p_api_version                    => p_api_version,
190         p_init_msg_list                  => FND_API.G_FALSE,
191         p_commit                         => FND_API.G_FALSE,
192         p_validation_level               => p_validation_level,
193         p_master_mini_site_id            => p_master_mini_site_id,
194         p_section_id                     => l_child_section_id,
195         x_return_status                  => x_return_status,
196         x_msg_count                      => x_msg_count,
197         x_msg_data                       => x_msg_data
198         );
199 
200       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
201         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RECUR_SCT_DEL_FAIL');
202         FND_MESSAGE.Set_Token('SECTION_ID', l_child_section_id);
203         FND_MSG_PUB.Add;
204         RAISE FND_API.G_EXC_ERROR;
205       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
206         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RECUR_SCT_DEL_FAIL');
207         FND_MESSAGE.Set_Token('SECTION_ID', l_child_section_id);
208         FND_MSG_PUB.Add;
209         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
210       END IF;
211 
212       FETCH c1 INTO l_child_section_id;
213       EXIT WHEN c1%NOTFOUND;
214 
215     END LOOP;
216 
217     CLOSE c1;
218 
219     -- after deleting the child of p_section_id, delete itself
220     IBE_DSP_SECTION_GRP.Delete_Section
221       (
222       p_api_version         => p_api_version,
223       p_init_msg_list       => FND_API.G_FALSE,
224       p_commit              => FND_API.G_FALSE,
225       p_validation_level    => p_validation_level,
226       p_section_id          => p_section_id,
227       p_access_name         => FND_API.G_MISS_CHAR,
228       x_return_status       => x_return_status,
229       x_msg_count           => x_msg_count,
230       x_msg_data            => x_msg_data
231       );
232 
233     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
234       RAISE FND_API.G_EXC_ERROR;
235     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
236       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
237     END IF;
238 
239   END IF;
240 
241 EXCEPTION
242 
243    WHEN FND_API.G_EXC_ERROR THEN
244      x_return_status := FND_API.G_RET_STS_ERROR;
245      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
246                                p_data       =>      x_msg_data,
247                                p_encoded    =>      'F');
248 
249    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
250      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
251      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
252                                p_data       =>      x_msg_data,
253                                p_encoded    =>      'F');
254 
255    WHEN OTHERS THEN
256      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
257      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
258      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
259      FND_MESSAGE.Set_Token('REASON', SQLERRM);
260      FND_MSG_PUB.Add;
261 
262      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
263 
264      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
265      THEN
266        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
267      END IF;
268 
269      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
270                                p_data       =>      x_msg_data,
271                                p_encoded    =>      'F');
272 
273 END Delete_Recursive_Sections;
274 
275 --
276 -- Associate the section (p_section_id) and all its valid descendants
277 -- (i.e. with available_for_all_sites_flag = 'Y') to mini-site p_mini_site_id
278 -- This procedure also makes the association for the p_mini_site_id with the
279 -- descendants section items.
280 -- Assumption: p_section_id will be associated with p_mini_site_id irrespective
281 -- of its available_for_all_sites_flag
282 --
283 PROCEDURE Associate_Recursive_MSite_Sct
284   (
285    p_api_version                    IN NUMBER,
286    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
287    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
288    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
289    p_section_id                     IN NUMBER,
290    p_mini_site_id                   IN NUMBER,
291    p_master_mini_site_id            IN NUMBER,
292    x_return_status                  OUT NOCOPY VARCHAR2,
293    x_msg_count                      OUT NOCOPY NUMBER,
294    x_msg_data                       OUT NOCOPY VARCHAR2
295   )
296 IS
297   l_api_name                     CONSTANT VARCHAR2(30) :=
298     'Associate_Recursive_MSite_Sct';
299   l_api_version                  CONSTANT NUMBER       := 1.0;
300   l_msg_count                    NUMBER;
301   l_msg_data                     VARCHAR2(2000);
302 
303   l_are_subsections_present      BOOLEAN;
304   l_section_id                   NUMBER;
305   l_child_section_id             NUMBER;
306   l_mini_site_id                 NUMBER;
307   l_mini_site_section_section_id NUMBER;
308   l_mini_site_section_item_id    NUMBER;
309   l_count                        NUMBER := -1;
310 
311   --
312   -- Get the detail info for MSS association for l_c_section_id from the
313   -- master mini-site's entry
314   --
315   CURSOR c1(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
316   IS SELECT parent_section_id, child_section_id, start_date_active,
317     end_date_active, sort_order
318     FROM ibe_dsp_msite_sct_sects
319     WHERE child_section_id = l_c_section_id
320     AND mini_site_id = l_c_master_mini_site_id;
321 
322   --
323   -- Get all the children sections for l_c_section_id which have
324   -- available_in_all_sites_flag set to 'Y' (for master mini-site)
325   --
326   CURSOR c2(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
327   IS SELECT S.section_id AS s_section_id
328     FROM ibe_dsp_msite_sct_sects MSS, ibe_dsp_sections_b S
329     WHERE MSS.child_section_id = S.section_id
330     AND MSS.parent_section_id = l_c_section_id
331     AND MSS.mini_site_id = l_c_master_mini_site_id
332     AND S.available_in_all_sites_flag = 'Y';
333 
334   --
335   -- Get all the children items for the section l_c_section_id
336   --
337   CURSOR c3(l_c_section_id IN NUMBER)
338   IS SELECT section_item_id
339     FROM ibe_dsp_section_items
340     WHERE section_id = l_c_section_id;
341 
342 BEGIN
343 
344   -- cannot have savepoints within a recursively called function
345 
346   -- Initialize API return status to success
347   x_return_status := FND_API.G_RET_STS_SUCCESS;
348 
349   --
350   -- Associate the section p_section_id to mini-site p_mini_site_id
351   --
352   -- todo change logic here to have open, fetch, close instead, and test
353   --
354   FOR r1 IN c1(p_section_id, p_master_mini_site_id) LOOP
355 
356     IBE_DSP_MSITE_SCT_SECT_PVT.Create_MSite_Section_Section
357       (
358       p_api_version                    => p_api_version,
359       p_init_msg_list                  => FND_API.G_FALSE,
360       p_commit                         => FND_API.G_FALSE,
361       p_validation_level               => p_validation_level,
362       p_mini_site_id                   => p_mini_site_id,
363       p_parent_section_id              => r1.parent_section_id,
364       p_child_section_id               => r1.child_section_id,
365       p_start_date_active              => r1.start_date_active,
366       p_end_date_active                => r1.end_date_active,
367       p_level_number                   => FND_API.G_MISS_NUM,
368       p_sort_order                     => r1.sort_order,
369       p_concat_ids                     => FND_API.G_MISS_CHAR,
370       x_mini_site_section_section_id   => l_mini_site_section_section_id,
371       x_return_status                  => x_return_status,
372       x_msg_count                      => x_msg_count,
373       x_msg_data                       => x_msg_data
374       );
375 
376     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
377       RAISE FND_API.G_EXC_ERROR;
378     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
379       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
380     END IF;
381 
382     -- as there should be only one entry returned from c1
383     EXIT;
384 
385   END LOOP; -- end loop r1
386 
387   --
388   -- Associate the child sections of p_section_id with p_mini_site_id
389   -- which will be done in calling this same procedure recursively
390   --
391 
392   -- Flag which will used to determine if p_section_id has sub-sections or
393   -- not. If it does not, then it is possible that it has items as children
394   l_are_subsections_present := FALSE;
395   FOR r2 IN c2(p_section_id, p_master_mini_site_id) LOOP
396 
397     l_are_subsections_present := TRUE;
398 
399     Associate_Recursive_MSite_Sct
400       (
401       p_api_version                    => p_api_version,
405       p_section_id                     => r2.s_section_id,
402       p_init_msg_list                  => FND_API.G_FALSE,
403       p_commit                         => FND_API.G_FALSE,
404       p_validation_level               => p_validation_level,
406       p_mini_site_id                   => p_mini_site_id,
407       p_master_mini_site_id            => p_master_mini_site_id,
408       x_return_status                  => x_return_status,
409       x_msg_count                      => x_msg_count,
410       x_msg_data                       => x_msg_data
411       );
412 
413     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
414       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
415       FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
416       FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_id);
417       FND_MSG_PUB.Add;
418       RAISE FND_API.G_EXC_ERROR;
419     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
420       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
421       FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
422       FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_id);
423       FND_MSG_PUB.Add;
424       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
425     END IF;
426 
427   END LOOP;
428 
429   --
430   -- p_section_id doesn't have children sections, its possible that it may
431   -- have children items. For those items, create an entry in MSI table
432   --
433   IF (NOT l_are_subsections_present) THEN
434 
435     FOR r3 IN c3(p_section_id) LOOP
436 
437       -- Notes: start_date_active is not used in MSI, therefore adding
438       -- beginning of time value
439       IBE_DSP_MSITE_SCT_ITEM_PVT.Create_MSite_Section_Item
440         (
441         p_api_version                    => p_api_version,
442         p_init_msg_list                  => FND_API.G_FALSE,
443         p_commit                         => FND_API.G_FALSE,
444         p_validation_level               => p_validation_level,
445         p_mini_site_id                   => p_mini_site_id,
446         p_section_item_id                => r3.section_item_id,
447         p_start_date_active              => sysdate,
448         p_end_date_active                => FND_API.G_MISS_DATE,
449         x_mini_site_section_item_id      => l_mini_site_section_item_id,
450         x_return_status                  => x_return_status,
451         x_msg_count                      => x_msg_count,
452         x_msg_data                       => x_msg_data
453         );
454 
455       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
456         RAISE FND_API.G_EXC_ERROR;
457       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
458         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
459       END IF;
460 
461     END LOOP; -- end loop r3
462 
463   END IF;
464 
465   --
466   -- End of main API body.
467 
468   -- Standard check of p_commit.
469   IF (FND_API.To_Boolean(p_commit)) THEN
470     COMMIT WORK;
471   END IF;
472 
473   -- Standard call to get message count and if count is 1, get message info.
474   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
475                             p_data    =>      x_msg_data,
476                             p_encoded =>      'F');
477 
478 EXCEPTION
479 
480    WHEN FND_API.G_EXC_ERROR THEN
481      x_return_status := FND_API.G_RET_STS_ERROR;
482      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
483                                p_data       =>      x_msg_data,
484                                p_encoded    =>      'F');
485 
486    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
487      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
488      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
489                                p_data       =>      x_msg_data,
490                                p_encoded    =>      'F');
491 
492    WHEN OTHERS THEN
493      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
494      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
495      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
496      FND_MESSAGE.Set_Token('REASON', SQLERRM);
497      FND_MSG_PUB.Add;
498 
499      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
500 
501      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
502      THEN
503        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
504      END IF;
505 
506      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
507                                p_data       =>      x_msg_data,
508                                p_encoded    =>      'F');
509 
510 END Associate_Recursive_MSite_Sct;
511 
512 FUNCTION Get_Layout_Type(p_deliverable_id IN NUMBER) RETURN VARCHAR2
513 IS
514   CURSOR c_get_layout_type_csr(c_item_id NUMBER) IS
515     SELECT access_name, applicable_to_code
516       FROM jtf_amv_items_b
517      WHERE item_id = c_item_id
518 	  AND deliverable_type_code = 'TEMPLATE';
519 
520   l_access_name VARCHAR2(40);
521   l_applicable_to_code VARCHAR2(40);
522 BEGIN
523   IF ((p_deliverable_id IS NULL) OR (p_deliverable_id = -1)) THEN
524     RETURN 'F';
525   ELSE
526     OPEN c_get_layout_type_csr(p_deliverable_id);
527     FETCH c_get_layout_type_csr INTO l_access_name, l_applicable_to_code;
528     IF (c_get_layout_type_csr%NOTFOUND) THEN
532     CLOSE c_get_layout_type_csr;
529       CLOSE c_get_layout_type_csr;
530       RETURN 'F';
531     END IF;
533     IF (l_applicable_to_code = 'SECTION_LAYOUT') THEN
534       IF (l_access_name = 'STORE_CTLG_SCT_COMMON') THEN
535 	   RETURN 'F';
536 	 ELSE
537         RETURN 'C';
538       END IF;
539     ELSE
540       RETURN 'F';
541     END IF;
542   END IF;
543 END Get_Layout_Type;
544 
545 -- This procedure will check the layout type of a section.
546 -- layout type has following two choices:
547 -- 1) F - section is using fixed layout
548 -- 2) C - section is using configurable layout
549 --
550 PROCEDURE Get_Sect_Layout_Type(p_section_id IN NUMBER,
551                           x_deliverable_id OUT NOCOPY NUMBER,
552 					 x_layout_type OUT NOCOPY VARCHAR2)
553 IS
554   CURSOR c_get_deliverable_id_csr(c_section_id NUMBER) IS
555     SELECT deliverable_id
556       FROM ibe_dsp_sections_b
557      WHERE section_id = c_section_id;
558 
559   l_deliverable_id NUMBER;
560 BEGIN
561   OPEN c_get_deliverable_id_csr(p_section_id);
562   FETCH c_get_deliverable_id_csr INTO l_deliverable_id;
563   IF (c_get_deliverable_id_csr%NOTFOUND) THEN
564     CLOSE c_get_deliverable_id_csr;
565     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
566   END IF;
567   CLOSE c_get_deliverable_id_csr;
568   x_layout_type := Get_Layout_Type(l_deliverable_id);
569   x_deliverable_id := l_deliverable_id;
570 END Get_Sect_Layout_Type;
571 
572 -- This procedure will copy the layout component mapping from
573 -- parent section to the child section when the section is using
574 -- new configurable layout.
575 -- If the section is not using any layout (blank in deliverable_id)
576 -- or using old standard layout, then no layout component mapping
577 -- will be copied over.
578 PROCEDURE Copy_Layout_Comp_Mapping
579 (p_api_version       IN NUMBER,
580  p_init_msg_list     IN VARCHAR2 := FND_API.G_FALSE,
581  p_commit            IN VARCHAR2 := FND_API.G_FALSE,
582  p_source_section_id IN NUMBER,
583  p_target_section_id  IN NUMBER,
584  p_include_all       IN VARCHAR2 := FND_API.G_FALSE,
585  x_return_status     OUT NOCOPY VARCHAR2,
586  x_msg_count         OUT NOCOPY NUMBER,
587  x_msg_data          OUT NOCOPY VARCHAR2)
588 IS
589  l_api_name    CONSTANT VARCHAR2(30) := 'copy_layout_comp_mapping';
590  l_api_version CONSTANT NUMBER := 1.0;
591  l_full_name   CONSTANT VARCHAR2(60) := g_pkg_name ||'.'|| l_api_name;
592  l_return_status     VARCHAR2(1);
593 
594  l_msg_count NUMBER;
595  l_msg_data VARCHAR2(4000);
596 
597  -- Call save_logical_content to save the layout component
598  -- mapping inherit from the parent
599  l_lgl_ctnt_rec IBE_LogicalContent_GRP.OBJ_LGL_CTNT_REC_TYPE;
600  l_lgl_ctnt_tbl IBE_LogicalContent_GRP.OBJ_LGL_CTNT_TBL_TYPE;
601 
602  l_source_deliverable_id NUMBER;
603  l_source_layout_type VARCHAR2(1);
604 
605  CURSOR c_get_component_mapping_all(c_section_id NUMBER) IS
606    SELECT obj.item_id, obj.context_id, obj.object_type
607      FROM ibe_dsp_obj_lgl_ctnt obj,  ibe_dsp_context_b context
608     WHERE obj.object_id = c_section_id
609       AND obj.object_type = 'S'
610 	 AND obj.context_id = context.context_id
611 	 AND context.context_type_code = 'LAYOUT_COMPONENT';
612 	--  AND context.component_type_code <> 'OLD_PROCESS';
613 
614   -- Specific layout component templates are excluded
615   -- for example, subsection, featured section, product section
616   -- old process template
617   CURSOR c_get_component_mapping(c_section_id NUMBER) IS
618     SELECT obj.item_id, obj.context_id, obj.object_type
619       FROM ibe_dsp_obj_lgl_ctnt obj,  ibe_dsp_context_b context
620      WHERE obj.object_id = c_section_id
621 	  AND obj.object_type = 'S'
622 	  AND obj.context_id = context.context_id
623 	  AND context.context_type_code = 'LAYOUT_COMPONENT'
624 	  AND context.access_name <> 'CENTER';
625 	 -- AND context.component_type_code <> 'OLD_PROCESS'
626 
627 BEGIN
628   SAVEPOINT copy_layout_comp_mapping;
629   IF NOT FND_API.compatible_api_call(l_api_version,
630        p_api_version, l_api_name, g_pkg_name ) THEN
631     RAISE FND_API.g_exc_unexpected_error;
632   END IF;
633   IF FND_API.to_boolean(p_init_msg_list) THEN
634     FND_MSG_PUB.initialize;
635   END IF;
636   -- Initialize API return status to success
637   x_return_status := FND_API.g_ret_sts_success;
638 
639   Get_Sect_Layout_Type(p_section_id => p_source_section_id,
640     x_deliverable_id => l_source_deliverable_id,
641     x_layout_type => l_source_layout_type);
642 
643   IF (l_source_layout_type = 'C') THEN
644     -- Bulk collection will be used for inserting the data into mapping table
645     IF (p_include_all = FND_API.G_FALSE) THEN
646       DELETE FROM ibe_dsp_obj_lgl_ctnt obj
647 	   WHERE obj.object_id = p_target_section_id
648 	     AND obj.object_type = 'S'
649 		AND EXISTS (
650 		  SELECT 1
651 		    FROM ibe_dsp_context_b context
652              WHERE obj.context_id = context.context_id
653 		     AND context.context_type_code = 'LAYOUT_COMPONENT')
654 		AND NOT EXISTS(
655               SELECT 1
656                 FROM ibe_dsp_context_b context, ibe_dsp_obj_lgl_ctnt obj1
657                WHERE obj1.context_id = obj.context_id
658 			  AND obj1.context_id = context.context_id
662 			  AND context.component_type_code <> 'CENTER');
659 			  AND obj1.object_id = p_source_section_id
660 			  AND obj1.object_type = 'S'
661 			  AND context.context_type_code = 'LAYOUT_COMPONENT'
663 		--  AND context.component_type_code <> 'OLD_PROCESS'
664       -- Component mapping except old processing and center display template
665       FOR mapping IN c_get_component_mapping(p_source_section_id) LOOP
666 	   UPDATE ibe_dsp_obj_lgl_ctnt
667            SET OBJECT_VERSION_NUMBER = OBJECT_VERSION_NUMBER + 1,
668                ITEM_ID = mapping.item_id,
669                CREATED_BY = FND_GLOBAL.user_id,
670 	          CREATION_DATE = SYSDATE,
671                LAST_UPDATED_BY = FND_GLOBAL.user_id,
672 		     LAST_UPDATE_DATE = SYSDATE,
673 			LAST_UPDATE_LOGIN = FND_GLOBAL.login_id
674 	   WHERE object_id = p_target_section_id
675 	     AND object_type = 'S'
676 	     AND context_id = mapping.context_id;
677         IF sql%NOTFOUND THEN
678           INSERT INTO ibe_dsp_obj_lgl_ctnt(OBJ_LGL_CTNT_ID,
679             OBJECT_VERSION_NUMBER, CREATED_BY, CREATION_DATE,
680             LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN,
681             SECURITY_GROUP_ID, CONTEXT_ID, OBJECT_TYPE, OBJECT_ID,
682             ITEM_ID)
683           VALUES(ibe_dsp_obj_lgl_ctnt_s1.NEXTVAL,1,FND_GLOBAL.user_id,SYSDATE,
684             FND_GLOBAL.user_id, SYSDATE, FND_GLOBAL.login_id, NULL,
685             mapping.context_id, 'S', p_target_section_id, mapping.item_id);
686 	   END IF;
687 	 END LOOP;
688     ELSE
689       -- Component exclude old processing
690       DELETE FROM ibe_dsp_obj_lgl_ctnt obj
691 	   WHERE obj.object_id = p_target_section_id
692 	     AND obj.object_type = 'S'
693 		AND EXISTS (
694 		  SELECT 1
695 		    FROM ibe_dsp_context_b context
696              WHERE obj.context_id = context.context_id
697 		     AND context.context_type_code = 'LAYOUT_COMPONENT')
698 		AND NOT EXISTS(
699               SELECT 1
700                 FROM ibe_dsp_context_b context, ibe_dsp_obj_lgl_ctnt obj1
701                WHERE obj1.context_id = obj.context_id
702 			  AND obj1.context_id = context.context_id
703 			  AND obj1.object_id = p_source_section_id
704 			  AND obj1.object_type = 'S'
705 			  AND context.context_type_code = 'LAYOUT_COMPONENT');
706 			--  AND context.component_type_code <> 'OLD_PROCESS');
707       FOR mapping IN c_get_component_mapping_all(p_source_section_id) LOOP
708 	   UPDATE ibe_dsp_obj_lgl_ctnt
709           SET OBJECT_VERSION_NUMBER = OBJECT_VERSION_NUMBER + 1,
710               ITEM_ID = mapping.item_id,
711               CREATED_BY = FND_GLOBAL.user_id,
712 		    CREATION_DATE = SYSDATE,
713               LAST_UPDATED_BY = FND_GLOBAL.user_id,
714 		    LAST_UPDATE_DATE = SYSDATE,
715 		    LAST_UPDATE_LOGIN = FND_GLOBAL.login_id
716 	     WHERE object_id = p_target_section_id
717 		  AND object_type = 'S'
718 		  AND context_id = mapping.context_id;
719         IF sql%NOTFOUND THEN
720           INSERT INTO ibe_dsp_obj_lgl_ctnt(OBJ_LGL_CTNT_ID,
721             OBJECT_VERSION_NUMBER, CREATED_BY, CREATION_DATE,
722             LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN,
723             SECURITY_GROUP_ID, CONTEXT_ID, OBJECT_TYPE, OBJECT_ID,
724             ITEM_ID)
725           VALUES(ibe_dsp_obj_lgl_ctnt_s1.NEXTVAL,1,FND_GLOBAL.user_id,SYSDATE,
726               FND_GLOBAL.user_id, SYSDATE, FND_GLOBAL.login_id, NULL,
727               mapping.context_id, 'S', p_target_section_id, mapping.item_id);
728 	   END IF;
729 	 END LOOP;
730     END IF;
731   END IF;
732   --
733   -- End of main API body.
734   -- Standard check of p_commit.
735   IF (FND_API.To_Boolean(p_commit)) THEN
736     COMMIT;
737   END IF;
738   -- Standard call to get message count and if count is 1, get message info.
739   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
740                             p_data    =>      x_msg_data,
741 					   p_encoded =>      'F');
742 EXCEPTION
743   WHEN FND_API.G_EXC_ERROR THEN
744     ROLLBACK TO copy_layout_comp_mapping;
745     x_return_status := FND_API.G_RET_STS_ERROR;
746     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
747       p_data  => x_msg_data,
748 	 p_encoded => 'F');
749   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
750     ROLLBACK TO copy_layout_comp_mapping;
751     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
752     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
753       p_data  => x_msg_data,
754 	 p_encoded => 'F');
755   WHEN OTHERS THEN
756     ROLLBACK TO copy_layout_comp_mapping;
757     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
758     IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
759       FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
760     END IF;
761     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
762       p_data  => x_msg_data,
763 	 p_encoded => 'F');
764 END Copy_Layout_Comp_Mapping;
765 
766 PROCEDURE Create_Hierarchy_Section
767   (
768    p_api_version                    IN NUMBER,
769    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
770    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
771    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
772    p_parent_section_id              IN NUMBER   := FND_API.G_MISS_NUM,
773    p_parent_section_access_name     IN VARCHAR2 := FND_API.G_MISS_CHAR,
774    p_access_name                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
778    p_status_code                    IN VARCHAR2,
775    p_start_date_active              IN DATE,
776    p_end_date_active                IN DATE     := FND_API.G_MISS_DATE,
777    p_section_type_code              IN VARCHAR2,
779    p_display_context_id             IN NUMBER   := FND_API.G_MISS_NUM,
780    p_deliverable_id                 IN NUMBER   := FND_API.G_MISS_NUM,
781    p_available_in_all_sites_flag    IN VARCHAR2 := FND_API.G_MISS_CHAR,
782    p_auto_placement_rule            IN VARCHAR2 := FND_API.G_MISS_CHAR,
783    p_order_by_clause                IN VARCHAR2 := FND_API.G_MISS_CHAR,
784    p_sort_order                     IN NUMBER   := FND_API.G_MISS_NUM,
785    p_display_name                   IN VARCHAR2,
786    p_description                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
787    p_long_description               IN VARCHAR2 := FND_API.G_MISS_CHAR,
788    p_keywords                       IN VARCHAR2 := FND_API.G_MISS_CHAR,
789    p_attribute_category             IN VARCHAR2 := FND_API.G_MISS_CHAR,
790    p_attribute1                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
791    p_attribute2                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
792    p_attribute3                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
793    p_attribute4                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
794    p_attribute5                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
795    p_attribute6                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
796    p_attribute7                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
797    p_attribute8                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
798    p_attribute9                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
799    p_attribute10                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
800    p_attribute11                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
801    p_attribute12                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
802    p_attribute13                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
803    p_attribute14                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
804    p_attribute15                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
805    p_inherit_layout                 IN VARCHAR2,
806    x_section_id                     OUT NOCOPY NUMBER,
807    x_return_status                  OUT NOCOPY VARCHAR2,
808    x_msg_count                      OUT NOCOPY NUMBER,
809    x_msg_data                       OUT NOCOPY VARCHAR2
810   )
811 IS
812   l_api_name                     CONSTANT VARCHAR2(30) :=
813     'Create_Hierarchy_Section';
814   l_api_version                  CONSTANT NUMBER       := 1.0;
815   l_msg_count                    NUMBER;
816   l_msg_data                     VARCHAR2(2000);
817 
818   l_section_item_id              NUMBER;
819   l_parent_section_id            NUMBER;
820   l_parent_section_type_code     VARCHAR2(30);
821   l_master_mini_site_id          NUMBER;
822   l_master_root_section_id       NUMBER;
823   l_mini_site_section_section_id NUMBER;
824   l_concat_ids                   VARCHAR2(2000);
825   l_level_number                 NUMBER;
826   l_tmp_id                       NUMBER;
827 
828   -- assuming non-root section is to be created, unless otherwise found
829   l_is_root_section              BOOLEAN := FALSE;
830 
831   -- For 11.5.10
832   -- This flag will be checked to see if use configurable layout
833   -- or standard layout (old). By default, configurable layout will
834   -- be used
835   l_use_configurable_layout BOOLEAN := TRUE;
836   l_deliverable_id NUMBER;
837   l_parent_deli_id NUMBER := NULL;
838   l_parent_layout_type VARCHAR2(1) := NULL;
839   -- Need to access name to the new seed configurable layout template
840   -- access name
841   -- Make the cursor query use bind variables
842 
843   l_access_name                  VARCHAR2(50);
844   l_deliverable_type_code        VARCHAR2(50);
845   l_applicable_to_code           VARCHAR2(50);
846   l_application_id               NUMBER;
847 
848   CURSOR c_get_configurable_csr(l_c_access_name IN VARCHAR2,
849                                 l_c_deliverable_type_code IN VARCHAR2,
850                                 l_c_applicable_to_code IN VARCHAR2,
851                                 l_c_application_id IN NUMBER ) IS
852     SELECT item_id
853       FROM jtf_amv_items_b
854      WHERE access_name = l_c_access_name
855       AND deliverable_type_code = l_c_deliverable_type_code
856       AND applicable_to_code = l_c_applicable_to_code
857       AND application_id = l_c_application_id;
858 
859   CURSOR c1(l_c_section_id IN NUMBER)
860   IS SELECT section_type_code
861     FROM ibe_dsp_sections_b
862     WHERE section_id = l_c_section_id;
863 
864   CURSOR c2(l_c_access_name IN VARCHAR2)
865   IS SELECT section_id, section_type_code
866     FROM ibe_dsp_sections_b
867     WHERE access_name = l_c_access_name;
868 
869   CURSOR c3(l_c_section_id IN NUMBER)
870   IS SELECT section_item_id
871     FROM ibe_dsp_section_items
872     WHERE section_id = l_c_section_id;
873 
874   CURSOR c4 IS SELECT msite_root_section_id
875     FROM ibe_msites_b
876     WHERE master_msite_flag = 'Y';
877 
878   CURSOR c5(l_c_master_mini_site_id IN NUMBER)
879   IS SELECT msite_id
880     FROM ibe_msites_vl
881     WHERE msite_id <> l_c_master_mini_site_id;
882 
883   CURSOR c6(l_c_master_mini_site_id IN NUMBER,
884     l_c_section_id IN NUMBER,
885     l_c_parent_section_id IN NUMBER)
886   IS SELECT msite_id
887     FROM ibe_msites_vl
888     WHERE msite_id <> l_c_master_mini_site_id AND
892     AND mini_site_id <> l_c_master_mini_site_id
889     (msite_root_section_id = l_c_section_id OR
890     EXISTS (SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
891     WHERE mini_site_id = msite_id
893     AND child_section_id = l_c_parent_section_id));
894 
895 BEGIN
896 
897   -- Standard Start of API savepoint
898   SAVEPOINT  CREATE_HIERARCHY_SECTION_PVT;
899 
900   -- Standard call to check for call compatibility.
901   IF NOT FND_API.Compatible_API_Call(l_api_version,
902                                      p_api_version,
903                                      l_api_name,
904                                      G_PKG_NAME)
905   THEN
906     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
907   END IF;
908 
909   -- Give values to cursor variables for c_get_configurable_crsr
910   l_access_name           := 'STORE_SCT_CONFIGURABLE_LAYOUT';
911   l_deliverable_type_code := 'TEMPLATE';
912   l_applicable_to_code    := 'SECTION_LAYOUT';
913   l_application_id        := 671;
914 
915 
916 
917   -- Initialize message list if p_init_msg_list is set to TRUE.
918   IF FND_API.to_Boolean(p_init_msg_list) THEN
919     FND_MSG_PUB.initialize;
920   END IF;
921 
922   -- Initialize API return status to success
923   x_return_status := FND_API.G_RET_STS_SUCCESS;
924 
925   --
926   -- Get parent section id
927   -- Check if either p_parent_section_id or p_parent_section_access_name
928   -- is defined
929   --
930   IF ((p_parent_section_id IS NOT NULL) AND
931       (p_parent_section_id <> FND_API.G_MISS_NUM))
932   THEN
933 
934     l_parent_section_id := p_parent_section_id; -- parent_section_id specified
935 
936     OPEN c1(l_parent_section_id);
937     FETCH c1 INTO l_parent_section_type_code;
938     IF c1%NOTFOUND THEN
939       CLOSE c1;
940       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_SCT_ID');
941       FND_MESSAGE.Set_Token('SECTION_ID', l_parent_section_id);
942       FND_MSG_PUB.Add;
943       RAISE FND_API.G_EXC_ERROR;
944     END IF;
945     CLOSE c1;
946 
947   ELSIF ((p_parent_section_access_name IS NOT NULL) AND
948          (p_parent_section_access_name <> FND_API.G_MISS_CHAR))
949   THEN
950     --    query for parent section id
951     OPEN c2(p_parent_section_access_name);
952     FETCH c2 INTO l_parent_section_id, l_parent_section_type_code;
953     IF (c2%NOTFOUND) THEN
954       CLOSE c2;
955       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_GET_SCT_ACSS_NAME');
956       FND_MESSAGE.Set_Token('ACCESS_NAME', p_parent_section_access_name);
957       FND_MSG_PUB.Add;
958       RAISE FND_API.G_EXC_ERROR;
959     END IF;
960     CLOSE c2;
961 
962   ELSE
963     -- neither parent section id nor access name is specified
964     -- This means the section to be added is a root section, i.e., with no
965     -- parent
966     l_is_root_section := TRUE;
967     l_parent_section_id := NULL;
968   END IF;
969 
970   IF (l_is_root_section) THEN
971     -- Make sure that there is no other root section id
972     OPEN c4;
973     FETCH c4 INTO l_tmp_id;
974     IF (c4%NOTFOUND) THEN
975       CLOSE c4;
976       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_MASTER_MSITE_NOT_FOUND');
977       FND_MSG_PUB.Add;
978       RAISE FND_API.G_EXC_ERROR;
979     ELSE
980       CLOSE c4;
981       IF (l_tmp_id IS NOT NULL) THEN
982       -- already a root section defined
983       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_ROOT_SCT_ALREADY_DEF');
984       FND_MESSAGE.Set_Token('SECTION_ID', l_tmp_id);
985       FND_MSG_PUB.Add;
986       RAISE FND_API.G_EXC_ERROR;
987       END IF;
988     END IF;
989 
990   ELSE
991     -- check if the parent section is a navigational type section
992     -- if not, throw error
993     IF (l_parent_section_type_code <> 'N') THEN
994       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_PRNT_SCT_NOT_NAV');
995       FND_MESSAGE.Set_Token('SECTION_ID', l_parent_section_id);
996       FND_MSG_PUB.Add;
997       RAISE FND_API.G_EXC_ERROR;
998     END IF;
999 
1000     -- check if the parent section (which is navigational) doesn't have
1001     -- children as items. If there are child items for a section, then cannot
1002     -- add child section to it
1003     OPEN c3(l_parent_section_id);
1004     FETCH c3 INTO l_section_item_id;
1005     IF (c3%FOUND) THEN
1006       CLOSE c3;
1007       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_PRNT_SCT_HAS_CHILD_ITM');
1008       FND_MESSAGE.Set_Token('SECTION_ID', l_parent_section_id);
1009       FND_MSG_PUB.Add;
1010       RAISE FND_API.G_EXC_ERROR;
1011     END IF;
1012     CLOSE c3;
1013 
1014   END IF; -- end l_is_root_section
1015 
1016   --
1017   -- 11.5.10 deliverable id setting for configurable layout
1018   -- The child section will inherit the parent section's layout
1019   --  if the parent section is using configurable layout
1020   -- otherwise, the seed configurable layout will be used.
1021   --
1022   -- Make the cursor query use bind variables instead of hard coding the values
1023 
1024   l_deliverable_id := p_deliverable_id;
1025   IF (p_inherit_layout = FND_API.G_TRUE) THEN
1026     IF (l_use_configurable_layout) THEN
1027       IF (p_parent_section_id IS NULL) THEN
1028         OPEN c_get_configurable_csr(l_access_name,l_deliverable_type_code,
1029                                     l_applicable_to_code,l_application_id);
1033         END IF;
1030         FETCH c_get_configurable_csr INTO l_deliverable_id;
1031         IF (c_get_configurable_csr%NOTFOUND) THEN
1032           l_deliverable_id := p_deliverable_id;
1034         CLOSE c_get_configurable_csr;
1035       ELSE
1036         Get_Sect_Layout_Type(p_section_id => p_parent_section_id,
1037           x_deliverable_id => l_parent_deli_id,
1038 	     x_layout_type => l_parent_layout_type);
1039         IF l_parent_layout_type = 'C' THEN
1040           l_deliverable_id := l_parent_deli_id;
1041         ELSE
1042         OPEN c_get_configurable_csr(l_access_name,l_deliverable_type_code,
1043                                     l_applicable_to_code,l_application_id);
1044           FETCH c_get_configurable_csr INTO l_deliverable_id;
1045           IF (c_get_configurable_csr%NOTFOUND) THEN
1046             l_deliverable_id := p_deliverable_id;
1047           END IF;
1048           CLOSE c_get_configurable_csr;
1049         END IF;
1050       END IF;
1051     END IF;
1052   END IF;
1053   -- create section entry
1054   IBE_DSP_SECTION_GRP.Create_Section
1055   (
1056    p_api_version                  => p_api_version,
1057    p_init_msg_list                => FND_API.G_FALSE,
1058    p_commit                       => FND_API.G_FALSE,
1059    p_validation_level             => p_validation_level,
1060    p_access_name                  => p_access_name,
1061    p_start_date_active            => p_start_date_active,
1062    p_end_date_active              => p_end_date_active,
1063    p_section_type_code            => p_section_type_code,
1064    p_status_code                  => p_status_code,
1065    p_display_context_id           => p_display_context_id,
1066    p_deliverable_id               => l_deliverable_id,
1067    p_available_in_all_sites_flag  => p_available_in_all_sites_flag,
1068    p_auto_placement_rule          => p_auto_placement_rule,
1069    p_order_by_clause              => p_order_by_clause,
1070    p_display_name                 => p_display_name,
1071    p_description                  => p_description,
1072    p_long_description             => p_long_description,
1073    p_keywords                     => p_keywords,
1074    p_attribute_category           => p_attribute_category,
1075    p_attribute1                   => p_attribute1,
1076    p_attribute2                   => p_attribute2,
1077    p_attribute3                   => p_attribute3,
1078    p_attribute4                   => p_attribute4,
1079    p_attribute5                   => p_attribute5,
1080    p_attribute6                   => p_attribute6,
1081    p_attribute7                   => p_attribute7,
1082    p_attribute8                   => p_attribute8,
1083    p_attribute9                   => p_attribute9,
1084    p_attribute10                  => p_attribute10,
1085    p_attribute11                  => p_attribute11,
1086    p_attribute12                  => p_attribute12,
1087    p_attribute13                  => p_attribute13,
1088    p_attribute14                  => p_attribute14,
1089    p_attribute15                  => p_attribute15,
1090    x_section_id                   => x_section_id,
1091    x_return_status                => x_return_status,
1092    x_msg_count                    => x_msg_count,
1093    x_msg_data                     => x_msg_data
1094   );
1095 
1096   IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1097     RAISE FND_API.G_EXC_ERROR;
1098   ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1099     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1100   END IF;
1101 
1102   --
1103   -- get master mini site id for the store
1104   --
1105   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
1106                           x_root_section_id => l_master_root_section_id);
1107 
1108   --
1109   -- Get the concat_ids and level number
1110   --
1111   IF (l_is_root_section) THEN
1112     l_concat_ids := NULL;
1113     l_level_number := 1;
1114   ELSE
1115     Get_Concat_Ids(l_parent_section_id, l_master_mini_site_id,
1116                    l_concat_ids, l_level_number);
1117     l_level_number := l_level_number + 1;
1118   END IF;
1119 
1120   --
1121   -- Create mini site section section entry for root mini site
1122   --
1123   IBE_DSP_MSITE_SCT_SECT_PVT.Create_MSite_Section_Section
1124   (
1125    p_api_version                    => p_api_version,
1126    p_init_msg_list                  => FND_API.G_FALSE,
1127    p_commit                         => FND_API.G_FALSE,
1128    p_validation_level               => p_validation_level,
1129    p_mini_site_id                   => l_master_mini_site_id,
1130    p_parent_section_id              => l_parent_section_id,
1131    p_child_section_id               => x_section_id,
1132    p_start_date_active              => p_start_date_active,
1133    p_end_date_active                => p_end_date_active,
1134    p_level_number                   => l_level_number,
1135    p_sort_order                     => p_sort_order,
1136    p_concat_ids                     => l_concat_ids,
1137    x_mini_site_section_section_id   => l_mini_site_section_section_id,
1138    x_return_status                  => x_return_status,
1139    x_msg_count                      => x_msg_count,
1140    x_msg_data                       => x_msg_data
1141   );
1142 
1143       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1144       RAISE FND_API.G_EXC_ERROR;
1145     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1146       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1147     END IF;
1148 
1149   -- todo fm
1150 
1154   --
1151   --
1152   -- If root section is being inserted, make sure that ibe_msites_b is
1153   -- updated to have msite_root_section_id as x_section_id
1155   IF (l_is_root_section) THEN
1156 
1157     UPDATE ibe_msites_b
1158       SET msite_root_section_id = x_section_id,
1159       object_version_number = object_version_number + 1
1160       WHERE master_msite_flag = 'Y';
1161 
1162     IF (sql%NOTFOUND) THEN
1163       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_MASTER_MSITE_RT_SCT_F');
1164       FND_MESSAGE.Set_Token('SECTION_ID', x_section_id);
1165       FND_MSG_PUB.Add;
1166       RAISE FND_API.G_EXC_ERROR;
1167     END IF;
1168 
1169   END IF;
1170 
1171   --
1172   -- Add all the candidate sites to the section. Add them only if the
1173   -- available in all sites flag is either missing or set to 'Y'. For iStore
1174   -- it should be always true (based on the UI)
1175   --
1176   IF (p_available_in_all_sites_flag = 'Y' OR
1177       p_available_in_all_sites_flag = FND_API.G_MISS_CHAR)
1178   THEN
1179     IF (l_is_root_section) THEN
1180 
1181       FOR r5 IN  c5(l_master_mini_site_id) LOOP
1182         --
1183         -- Create mini site section section entry for candidate mini sites
1184         --
1185         IBE_DSP_MSITE_SCT_SECT_PVT.Create_MSite_Section_Section
1186           (
1187           p_api_version                    => p_api_version,
1188           p_init_msg_list                  => FND_API.G_FALSE,
1189           p_commit                         => FND_API.G_FALSE,
1190           p_validation_level               => p_validation_level,
1191           p_mini_site_id                   => r5.msite_id,
1192           p_parent_section_id              => l_parent_section_id,
1193           p_child_section_id               => x_section_id,
1194           p_start_date_active              => p_start_date_active,
1195           p_end_date_active                => p_end_date_active,
1196           p_level_number                   => FND_API.G_MISS_NUM,
1197           p_sort_order                     => p_sort_order,
1198           p_concat_ids                     => FND_API.G_MISS_CHAR,
1199           x_mini_site_section_section_id   => l_mini_site_section_section_id,
1200           x_return_status                  => x_return_status,
1201           x_msg_count                      => x_msg_count,
1202           x_msg_data                       => x_msg_data
1203           );
1204 
1205     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1206       RAISE FND_API.G_EXC_ERROR;
1207     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1208       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1209     END IF;
1210 
1211         -- todo fm
1212 
1213       END LOOP;
1214 
1215     ELSE
1216 
1217       FOR r6 IN  c6(l_master_mini_site_id, x_section_id, l_parent_section_id)
1218       LOOP
1219         --
1220         -- Create mini site section section entry for candidate mini sites
1221         --
1222         IBE_DSP_MSITE_SCT_SECT_PVT.Create_MSite_Section_Section
1223           (
1224           p_api_version                    => p_api_version,
1225           p_init_msg_list                  => FND_API.G_FALSE,
1226           p_commit                         => FND_API.G_FALSE,
1227           p_validation_level               => p_validation_level,
1228           p_mini_site_id                   => r6.msite_id,
1229           p_parent_section_id              => l_parent_section_id,
1230           p_child_section_id               => x_section_id,
1231           p_start_date_active              => p_start_date_active,
1232           p_end_date_active                => p_end_date_active,
1233           p_level_number                   => FND_API.G_MISS_NUM,
1234           p_sort_order                     => p_sort_order,
1235           p_concat_ids                     => FND_API.G_MISS_CHAR,
1236           x_mini_site_section_section_id   => l_mini_site_section_section_id,
1237           x_return_status                  => x_return_status,
1238           x_msg_count                      => x_msg_count,
1239           x_msg_data                       => x_msg_data
1240           );
1241 
1242     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1243       RAISE FND_API.G_EXC_ERROR;
1244     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1245       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1246     END IF;
1247 
1248         -- todo fm
1249 
1250       END LOOP;
1251 
1252     END IF;
1253 
1254   END IF;
1255 
1256   -- 11.5.10 Save the layout component mapping
1257   -- from the parent section
1258   IF ((p_inherit_layout = FND_API.G_TRUE)
1259     AND (l_parent_section_id IS NOT NULL)) THEN
1260     IF (l_parent_layout_type = 'C') THEN
1261       Copy_Layout_Comp_Mapping(
1262         p_api_version => 1.0,
1263 	   p_init_msg_list => FND_API.G_FALSE,
1264 	   p_commit => FND_API.G_FALSE,
1265 	   p_source_section_id => l_parent_section_id,
1266 	   p_target_section_id => x_section_id,
1267 	   p_include_all => FND_API.G_FALSE,
1268 	   x_return_status => x_return_status,
1269 	   x_msg_count => l_msg_count,
1270 	   x_msg_data => l_msg_data);
1271        IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1272 	    RAISE FND_API.G_EXC_ERROR;
1273        ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1274 	    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1275 	  END IF;
1276      END IF;
1277   END IF;
1278   -- Standard check of p_commit.
1279   IF (FND_API.To_Boolean(p_commit)) THEN
1283   -- Standard call to get message count and if count is 1, get message info.
1280     COMMIT WORK;
1281   END IF;
1282 
1284   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
1285                             p_data    =>      x_msg_data,
1286                             p_encoded =>      'F');
1287 
1288 EXCEPTION
1289 
1290    WHEN FND_API.G_EXC_ERROR THEN
1291      ROLLBACK TO CREATE_HIERARCHY_SECTION_PVT;
1292      x_return_status := FND_API.G_RET_STS_ERROR;
1293      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1294                                p_data       =>      x_msg_data,
1295                                p_encoded    =>      'F');
1296 
1297    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1298      ROLLBACK TO CREATE_HIERARCHY_SECTION_PVT;
1299      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1300      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1301                                p_data       =>      x_msg_data,
1302                                p_encoded    =>      'F');
1303 
1304    WHEN OTHERS THEN
1305      ROLLBACK TO CREATE_HIERARCHY_SECTION_PVT;
1306      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
1307      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
1308      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
1309      FND_MESSAGE.Set_Token('REASON', SQLERRM);
1310      FND_MSG_PUB.Add;
1311 
1312      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1313 
1314      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1315      THEN
1316        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1317      END IF;
1318 
1319      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1320                                p_data       =>      x_msg_data,
1321                                p_encoded    =>      'F');
1322 
1323 END Create_Hierarchy_Section;
1324 
1325 PROCEDURE Create_Hierarchy_Section
1326   (
1327    p_api_version                    IN NUMBER,
1328    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
1329    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
1330    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
1331    p_parent_section_id              IN NUMBER   := FND_API.G_MISS_NUM,
1332    p_parent_section_access_name     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1333    p_access_name                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1334    p_start_date_active              IN DATE,
1335    p_end_date_active                IN DATE     := FND_API.G_MISS_DATE,
1336    p_section_type_code              IN VARCHAR2,
1337    p_status_code                    IN VARCHAR2,
1338    p_display_context_id             IN NUMBER   := FND_API.G_MISS_NUM,
1339    p_deliverable_id                 IN NUMBER   := FND_API.G_MISS_NUM,
1340    p_available_in_all_sites_flag    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1341    p_auto_placement_rule            IN VARCHAR2 := FND_API.G_MISS_CHAR,
1342    p_order_by_clause                IN VARCHAR2 := FND_API.G_MISS_CHAR,
1343    p_sort_order                     IN NUMBER   := FND_API.G_MISS_NUM,
1344    p_display_name                   IN VARCHAR2,
1345    p_description                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1346    p_long_description               IN VARCHAR2 := FND_API.G_MISS_CHAR,
1347    p_keywords                       IN VARCHAR2 := FND_API.G_MISS_CHAR,
1348    p_attribute_category             IN VARCHAR2 := FND_API.G_MISS_CHAR,
1349    p_attribute1                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1350    p_attribute2                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1351    p_attribute3                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1352    p_attribute4                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1353    p_attribute5                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1354    p_attribute6                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1355    p_attribute7                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1356    p_attribute8                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1357    p_attribute9                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1358    p_attribute10                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1359    p_attribute11                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1360    p_attribute12                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1361    p_attribute13                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1362    p_attribute14                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1363    p_attribute15                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1364    x_section_id                     OUT NOCOPY NUMBER,
1365    x_return_status                  OUT NOCOPY VARCHAR2,
1366    x_msg_count                      OUT NOCOPY NUMBER,
1367    x_msg_data                       OUT NOCOPY VARCHAR2
1368   )
1369 IS
1370 BEGIN
1371  Create_Hierarchy_Section
1372   (
1373    p_api_version              => p_api_version,
1374    p_init_msg_list            => p_init_msg_list,
1375    p_commit                   => p_commit,
1376    p_validation_level         => p_validation_level,
1377    p_parent_section_id        => p_parent_section_id,
1378    p_parent_section_access_name=>p_parent_section_access_name,
1379    p_access_name              => p_access_name,
1380    p_start_date_active        => p_start_date_active,
1381    p_end_date_active          => p_end_date_active,
1382    p_section_type_code        => p_section_type_code,
1383    p_status_code              => p_status_code,
1384    p_display_context_id       => p_display_context_id,
1388    p_order_by_clause          => p_order_by_clause,
1385    p_deliverable_id           => p_deliverable_id,
1386    p_available_in_all_sites_flag=> p_available_in_all_sites_flag,
1387    p_auto_placement_rule      => p_auto_placement_rule,
1389    p_sort_order               => p_sort_order,
1390    p_display_name             => p_display_name,
1391    p_description              => p_description,
1392    p_long_description         => p_long_description,
1393    p_keywords                 => p_keywords,
1394    p_attribute_category       => p_attribute_category,
1395    p_attribute1               => p_attribute1,
1396    p_attribute2               => p_attribute2,
1397    p_attribute3               => p_attribute3,
1398    p_attribute4               => p_attribute4,
1399    p_attribute5               => p_attribute5,
1400    p_attribute6               => p_attribute6,
1401    p_attribute7               => p_attribute7,
1402    p_attribute8               => p_attribute8,
1403    p_attribute9               => p_attribute9,
1404    p_attribute10              => p_attribute10,
1405    p_attribute11              => p_attribute11,
1406    p_attribute12              => p_attribute12,
1407    p_attribute13              => p_attribute13,
1408    p_attribute14              => p_attribute14,
1409    p_attribute15              => p_attribute15,
1410    p_inherit_layout           => FND_API.G_TRUE,
1411    x_section_id               => x_section_id,
1412    x_return_status            => x_return_status,
1413    x_msg_count                => x_msg_count,
1414    x_msg_data                 => x_msg_data
1415   );
1416 END Create_Hierarchy_Section;
1417 
1418 --
1419 -- if sort_number specified, then update ibe_dsp_msite_sct_sects table too
1420 -- p_mss_object_version_number will be used only then, and also it should be
1421 -- specified if sort_number is specified
1422 -- p_upd_dsc_scts_status (value 'Y' or 'N') will be used to update all the
1423 -- descendant section's (of p_section_id) status to p_status_code. If Y, then
1424 -- update all descendants (including p_section_id), else update only
1425 -- p_section_id's status.
1426 --
1427 PROCEDURE Update_Hierarchy_Section
1428   (
1429    p_api_version                    IN NUMBER,
1430    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
1431    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
1432    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
1433    p_section_id                     IN NUMBER   := FND_API.G_MISS_NUM,
1434    p_object_version_number          IN NUMBER,
1435    p_mss_object_version_number      IN NUMBER   := FND_API.G_MISS_NUM,
1436    p_access_name                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1437    p_start_date_active              IN DATE     := FND_API.G_MISS_DATE,
1438    p_end_date_active                IN DATE     := FND_API.G_MISS_DATE,
1439    p_section_type_code              IN VARCHAR2 := FND_API.G_MISS_CHAR,
1440    p_status_code                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1441    p_display_context_id             IN NUMBER   := FND_API.G_MISS_NUM,
1442    p_deliverable_id                 IN NUMBER   := FND_API.G_MISS_NUM,
1443    p_available_in_all_sites_flag    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1444    p_auto_placement_rule            IN VARCHAR2 := FND_API.G_MISS_CHAR,
1445    p_order_by_clause                IN VARCHAR2 := FND_API.G_MISS_CHAR,
1446    p_sort_order                     IN NUMBER   := FND_API.G_MISS_NUM,
1447    p_display_name                   IN VARCHAR2 := FND_API.G_MISS_CHAR,
1448    p_description                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1449    p_long_description               IN VARCHAR2 := FND_API.G_MISS_CHAR,
1450    p_keywords                       IN VARCHAR2 := FND_API.G_MISS_CHAR,
1451    p_attribute_category             IN VARCHAR2 := FND_API.G_MISS_CHAR,
1452    p_attribute1                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1453    p_attribute2                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1454    p_attribute3                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1455    p_attribute4                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1456    p_attribute5                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1457    p_attribute6                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1458    p_attribute7                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1459    p_attribute8                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1460    p_attribute9                     IN VARCHAR2 := FND_API.G_MISS_CHAR,
1461    p_attribute10                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1462    p_attribute11                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1463    p_attribute12                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1464    p_attribute13                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1465    p_attribute14                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1466    p_attribute15                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1467    p_upd_dsc_scts_status            IN VARCHAR2 := FND_API.G_MISS_CHAR,
1468    x_return_status                  OUT NOCOPY VARCHAR2,
1469    x_msg_count                      OUT NOCOPY NUMBER,
1470    x_msg_data                       OUT NOCOPY VARCHAR2
1471   )
1472 IS
1473   l_api_name                     CONSTANT VARCHAR2(30) :=
1474     'Update_Hierarchy_Section';
1475   l_api_version                  CONSTANT NUMBER       := 1.0;
1476   l_msg_count                    NUMBER;
1477   l_msg_data                     VARCHAR2(2000);
1478 
1479   l_section_id                   NUMBER;
1480   l_section_section_id           NUMBER;
1481   l_parent_section_id            NUMBER;
1482   l_master_mini_site_id          NUMBER;
1483   l_master_root_section_id       NUMBER;
1487     FROM ibe_dsp_msite_sct_sects
1484 
1485   CURSOR c1(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
1486   IS SELECT parent_section_id
1488     WHERE child_section_id = l_c_section_id
1489     AND mini_site_id = l_c_master_mini_site_id;
1490 
1491   CURSOR c2(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
1492   IS SELECT mini_site_section_section_id
1493     FROM ibe_dsp_msite_sct_sects
1494     WHERE mini_site_id = l_c_master_mini_site_id
1495     AND parent_section_id = l_c_section_id;
1496 
1497   --
1498   -- Get the descendant sections of l_c_section_id (not including
1499   -- l_c_section_id)
1500   --
1501   CURSOR c3(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
1502   IS SELECT section_id, object_version_number FROM ibe_dsp_sections_b
1503     WHERE section_id IN
1504     (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
1505     WHERE mini_site_id = l_c_master_mini_site_id
1506     START WITH parent_section_id = l_c_section_id
1507     AND mini_site_id = l_c_master_mini_site_id
1508     CONNECT BY PRIOR child_section_id = parent_section_id
1509     AND PRIOR mini_site_id = l_c_master_mini_site_id
1510     AND mini_site_id = l_c_master_mini_site_id);
1511 
1512 BEGIN
1513 
1514   -- Standard Start of API savepoint
1515   SAVEPOINT  UPDATE_HIERARCHY_SECTION_PVT;
1516 
1517   -- Standard call to check for call compatibility.
1518   IF NOT FND_API.Compatible_API_Call(l_api_version,
1519                                      p_api_version,
1520                                      l_api_name,
1521                                      G_PKG_NAME)
1522   THEN
1523     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1524   END IF;
1525 
1526   -- Initialize message list if p_init_msg_list is set to TRUE.
1527   IF FND_API.to_Boolean(p_init_msg_list) THEN
1528     FND_MSG_PUB.initialize;
1529   END IF;
1530 
1531   -- Initialize API return status to success
1532   x_return_status := FND_API.G_RET_STS_SUCCESS;
1533 
1534   --
1535   -- Get section id
1536   --
1537   IF ((p_section_id IS NOT NULL) AND
1538       (p_section_id <> FND_API.G_MISS_NUM))
1539   THEN
1540 
1541     l_section_id := p_section_id; -- section_id specified
1542 
1543   ELSE
1544     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_ID_NULL_OR_NOTSPEC');
1545     FND_MSG_PUB.Add;
1546     RAISE FND_API.G_EXC_ERROR;
1547   END IF;
1548 
1549   --
1550   -- Check (and validate) if p_sort_order is specified
1551   --
1552   IF (p_sort_order <> FND_API.G_MISS_NUM) THEN
1553 
1554     IF ((p_mss_object_version_number = FND_API.G_MISS_NUM) OR
1555         (p_mss_object_version_number IS NULL))
1556     THEN
1557       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_NO_MSS_OVN');
1558       FND_MSG_PUB.Add;
1559       RAISE FND_API.G_EXC_ERROR;
1560     END IF;
1561 
1562   END IF;
1563 
1564   --
1565   -- get master mini site id for the store
1566   --
1567   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
1568                           x_root_section_id => l_master_root_section_id);
1569 
1570   -- Check if the section which have children as sections is being updated to
1571   -- non-navigational section type.
1572   OPEN c2(l_section_id, l_master_mini_site_id);
1573   FETCH c2 INTO l_section_section_id;
1574   IF (c2%FOUND) THEN
1575     -- section has children sections
1576     CLOSE c2;
1577     IF((p_section_type_code <> FND_API.G_MISS_CHAR) AND
1578        (p_section_type_code <> 'N'))
1579     THEN
1580       -- non-navigations section with children sections is being changed to
1581       -- type other than 'N' (navigational)
1582       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_NAV_SCT_TYPE_CHNG_FAIL');
1583       FND_MSG_PUB.Add;
1584       RAISE FND_API.G_EXC_ERROR;
1585     END IF;
1586   ELSE
1587     CLOSE c2;
1588   END IF;
1589 
1590   IBE_DSP_SECTION_GRP.Update_Section
1591     (
1592     p_api_version                    => p_api_version,
1593     p_init_msg_list                  => FND_API.G_FALSE,
1594     p_commit                         => FND_API.G_FALSE,
1595     p_validation_level               => p_validation_level,
1596     p_section_id                     => p_section_id,
1597     p_object_version_number          => p_object_version_number,
1598     p_access_name                    => p_access_name,
1599     p_start_date_active              => p_start_date_active,
1600     p_end_date_active                => p_end_date_active,
1601     p_section_type_code              => p_section_type_code,
1602     p_status_code                    => p_status_code,
1603     p_display_context_id             => p_display_context_id,
1604     p_deliverable_id                 => p_deliverable_id,
1605     p_available_in_all_sites_flag    => p_available_in_all_sites_flag,
1606     p_auto_placement_rule            => p_auto_placement_rule,
1607     p_order_by_clause                => p_order_by_clause,
1608     p_display_name                   => p_display_name,
1609     p_description                    => p_description,
1610     p_long_description               => p_long_description,
1611     p_keywords                       => p_keywords,
1612     p_attribute_category             => p_attribute_category,
1613     p_attribute1                     => p_attribute1,
1614     p_attribute2                     => p_attribute2,
1615     p_attribute3                     => p_attribute3,
1619     p_attribute7                     => p_attribute7,
1616     p_attribute4                     => p_attribute4,
1617     p_attribute5                     => p_attribute5,
1618     p_attribute6                     => p_attribute6,
1620     p_attribute8                     => p_attribute8,
1621     p_attribute9                     => p_attribute9,
1622     p_attribute10                    => p_attribute10,
1623     p_attribute11                    => p_attribute11,
1624     p_attribute12                    => p_attribute12,
1625     p_attribute13                    => p_attribute13,
1626     p_attribute14                    => p_attribute14,
1627     p_attribute15                    => p_attribute15,
1628     x_return_status                  => x_return_status,
1629     x_msg_count                      => x_msg_count,
1630     x_msg_data                       => x_msg_data
1631     );
1632 
1633     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1634       RAISE FND_API.G_EXC_ERROR;
1635     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1636       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1637     END IF;
1638 
1639     --
1640     -- Update ibe_dsp_msite_sct_sects only if the sort order is present
1641     --
1642     IF (p_sort_order <> FND_API.G_MISS_NUM) THEN
1643       --
1644       -- get parent section id of the section to be updated
1645       --
1646       OPEN c1(p_section_id, l_master_mini_site_id);
1647       FETCH c1 INTO l_parent_section_id;
1648       IF (c1%NOTFOUND) THEN
1649         CLOSE c1;
1650         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_GET_PRNT_SCT_FAIL');
1651         FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
1652         FND_MSG_PUB.Add;
1653         RAISE FND_API.G_EXC_ERROR;
1654       END IF;
1655       CLOSE c1;
1656 
1657       --
1658       -- update ibe_dsp_msite_sct_sects
1659       --
1660       IBE_DSP_MSITE_SCT_SECT_PVT.Update_MSite_Section_Section
1661         (
1662         p_api_version                    => p_api_version,
1663         p_init_msg_list                  => FND_API.G_FALSE,
1664         p_commit                         => FND_API.G_FALSE,
1665         p_validation_level               => p_validation_level,
1666         p_mini_site_section_section_id   => FND_API.G_MISS_NUM,
1667         p_object_version_number          => p_mss_object_version_number,
1668         p_mini_site_id                   => l_master_mini_site_id,
1669         p_parent_section_id              => l_parent_section_id,
1670         p_child_section_id               => p_section_id,
1671         p_start_date_active              => FND_API.G_MISS_DATE,
1672         p_end_date_active                => FND_API.G_MISS_DATE,
1673         p_level_number                   => FND_API.G_MISS_NUM,
1674         p_sort_order                     => p_sort_order,
1675         p_concat_ids                     => FND_API.G_MISS_CHAR,
1676         x_return_status                  => x_return_status,
1677         x_msg_count                      => x_msg_count,
1678         x_msg_data                       => x_msg_data
1679         );
1680 
1681       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1682         RAISE FND_API.G_EXC_ERROR;
1683       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1684         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1685       END IF;
1686 
1687     END IF; -- p_sort_order <> FND_API.G_MISS_NUM OR ...
1688 
1689     --
1690     -- Update status of descendant sections of p_section_id
1691     --
1692     IF (p_upd_dsc_scts_status = 'Y') THEN
1693 
1694       FOR r3 in c3(p_section_id, l_master_mini_site_id) LOOP
1695 
1696         IBE_DSP_SECTION_GRP.Update_Section
1697           (
1698           p_api_version                    => p_api_version,
1699           p_init_msg_list                  => FND_API.G_FALSE,
1700           p_commit                         => FND_API.G_FALSE,
1701           p_validation_level               => p_validation_level,
1702           p_section_id                     => r3.section_id,
1703           p_object_version_number          => r3.object_version_number,
1704           p_access_name                    => FND_API.G_MISS_CHAR,
1705           p_start_date_active              => FND_API.G_MISS_DATE,
1706           p_end_date_active                => FND_API.G_MISS_DATE,
1707           p_section_type_code              => FND_API.G_MISS_CHAR,
1708           p_status_code                    => p_status_code,
1709           p_display_context_id             => FND_API.G_MISS_NUM,
1710           p_deliverable_id                 => FND_API.G_MISS_NUM,
1711           p_available_in_all_sites_flag    => FND_API.G_MISS_CHAR,
1712           p_auto_placement_rule            => FND_API.G_MISS_CHAR,
1713           p_order_by_clause                => FND_API.G_MISS_CHAR,
1714           p_display_name                   => FND_API.G_MISS_CHAR,
1715           p_description                    => FND_API.G_MISS_CHAR,
1716           p_long_description               => FND_API.G_MISS_CHAR,
1717           p_keywords                       => FND_API.G_MISS_CHAR,
1718           p_attribute_category             => FND_API.G_MISS_CHAR,
1719           p_attribute1                     => FND_API.G_MISS_CHAR,
1720           p_attribute2                     => FND_API.G_MISS_CHAR,
1721           p_attribute3                     => FND_API.G_MISS_CHAR,
1722           p_attribute4                     => FND_API.G_MISS_CHAR,
1723           p_attribute5                     => FND_API.G_MISS_CHAR,
1727           p_attribute9                     => FND_API.G_MISS_CHAR,
1724           p_attribute6                     => FND_API.G_MISS_CHAR,
1725           p_attribute7                     => FND_API.G_MISS_CHAR,
1726           p_attribute8                     => FND_API.G_MISS_CHAR,
1728           p_attribute10                    => FND_API.G_MISS_CHAR,
1729           p_attribute11                    => FND_API.G_MISS_CHAR,
1730           p_attribute12                    => FND_API.G_MISS_CHAR,
1731           p_attribute13                    => FND_API.G_MISS_CHAR,
1732           p_attribute14                    => FND_API.G_MISS_CHAR,
1733           p_attribute15                    => FND_API.G_MISS_CHAR,
1734           x_return_status                  => x_return_status,
1735           x_msg_count                      => x_msg_count,
1736           x_msg_data                       => x_msg_data
1737           );
1738 
1739         IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1740           FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_UPD_DSC_SCT_STATUS_FL');
1741           FND_MESSAGE.Set_Token('SECTION_ID', r3.section_id);
1742           FND_MESSAGE.Set_Token('OVN', r3.object_version_number);
1743           FND_MSG_PUB.Add;
1744           RAISE FND_API.G_EXC_ERROR;
1745         ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1746           FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_UPD_DSC_SCT_STATUS_FL');
1747           FND_MESSAGE.Set_Token('SECTION_ID', r3.section_id);
1748           FND_MESSAGE.Set_Token('OVN', r3.object_version_number);
1749           FND_MSG_PUB.Add;
1750           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1751         END IF;
1752 
1753       END LOOP; -- end for r3
1754 
1755     END IF; -- end if (p_upd_dsc_scts_status)
1756 
1757     --
1758     -- End of main API body.
1759 
1760     -- Standard check of p_commit.
1761     IF (FND_API.To_Boolean(p_commit)) THEN
1762       COMMIT WORK;
1763     END IF;
1764 
1765     -- Standard call to get message count and if count is 1, get message info.
1766     FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
1767                               p_data    =>      x_msg_data,
1768                               p_encoded =>      'F');
1769 
1770 EXCEPTION
1771 
1772    WHEN FND_API.G_EXC_ERROR THEN
1773      ROLLBACK TO UPDATE_HIERARCHY_SECTION_PVT;
1774      x_return_status := FND_API.G_RET_STS_ERROR;
1775      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1776                                p_data       =>      x_msg_data,
1777                                p_encoded    =>      'F');
1778 
1779    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1780      ROLLBACK TO UPDATE_HIERARCHY_SECTION_PVT;
1781      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1782      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1783                                p_data       =>      x_msg_data,
1784                                p_encoded    =>      'F');
1785 
1786    WHEN OTHERS THEN
1787      ROLLBACK TO UPDATE_HIERARCHY_SECTION_PVT;
1788      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
1789      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
1790      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
1791      FND_MESSAGE.Set_Token('REASON', SQLERRM);
1792      FND_MSG_PUB.Add;
1793 
1794      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1795 
1796      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1797      THEN
1798        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1799      END IF;
1800 
1801      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1802                                p_data       =>      x_msg_data,
1803                                p_encoded    =>      'F');
1804 
1805 END Update_Hierarchy_Section;
1806 
1807 
1808 --- modified for better performance 11/20/03 ab
1809 
1810 PROCEDURE Delete_Hierarchy_Section
1811   (
1812    p_api_version                    IN NUMBER,
1813    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
1814    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
1815    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
1816    p_section_id                     IN NUMBER   := FND_API.G_MISS_NUM,
1817    p_access_name                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
1818    x_return_status                  OUT NOCOPY VARCHAR2,
1819    x_msg_count                      OUT NOCOPY NUMBER,
1820    x_msg_data                       OUT NOCOPY VARCHAR2
1821   )
1822 IS
1823   l_api_name                     CONSTANT VARCHAR2(30) :=
1824     'Delete_Hierarchy_Section';
1825   l_api_version                  CONSTANT NUMBER       := 1.0;
1826   l_msg_count                    NUMBER;
1827   l_msg_data                     VARCHAR2(2000);
1828 
1829   l_section_id                   NUMBER;
1830   l_master_mini_site_id          NUMBER;
1831   l_master_root_section_id       NUMBER;
1832 
1833   CURSOR c1(l_c_access_name IN VARCHAR2)
1834   IS SELECT section_id FROM ibe_dsp_sections_b
1835     WHERE access_name = l_c_access_name;
1836 
1837   CURSOR c_get_child_sections( l_section_id in NUMBER ,l_master_mini_site_id in NUMBER) IS
1838     SELECT S.section_id
1839     FROM ibe_dsp_sections_vl S, ibe_dsp_msite_sct_sects MSS
1840     WHERE S.section_id = MSS.child_section_id
1841     AND MSS.mini_site_id = l_master_mini_site_id
1842     AND S.section_id IN
1843     (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
1847     CONNECT BY PRIOR child_section_id = parent_section_id
1844     WHERE mini_site_id = l_master_mini_site_id
1845     START WITH parent_section_id = l_section_id
1846     AND mini_site_id = l_master_mini_site_id
1848     AND mini_site_id = l_master_mini_site_id)
1849     ORDER BY MSS.level_number desc;
1850 
1851 BEGIN
1852 
1853   -- Standard Start of API savepoint
1854   SAVEPOINT  DELETE_HIERARCHY_SECTION_PVT;
1855 
1856   -- Standard call to check for call compatibility.
1857   IF NOT FND_API.Compatible_API_Call(l_api_version,
1858                                      p_api_version,
1859                                      l_api_name,
1860                                      G_PKG_NAME)
1861   THEN
1862     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1863   END IF;
1864 
1865   -- Initialize message list if p_init_msg_list is set to TRUE.
1866   IF FND_API.to_Boolean(p_init_msg_list) THEN
1867     FND_MSG_PUB.initialize;
1868   END IF;
1869 
1870   -- Initialize API return status to success
1871   x_return_status := FND_API.G_RET_STS_SUCCESS;
1872   --
1873   -- Validate input data
1874   --
1875   IF ((p_section_id IS NOT NULL) AND
1876       (p_section_id <> FND_API.G_MISS_NUM))
1877   THEN
1878     -- p_section_id specified, continue
1879     l_section_id := p_section_id;
1880   ELSIF ((p_access_name IS NOT NULL) AND
1881          (p_access_name <> FND_API.G_MISS_CHAR))
1882   THEN
1883     -- find out the section_id from the access_name
1884     OPEN c1(p_access_name);
1885     FETCH c1 INTO l_section_id;
1886     IF (c1%NOTFOUND) THEN
1887       CLOSE c1;
1888       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_SCT_ACSS_NAME');
1889       FND_MESSAGE.Set_Token('ACCESS_NAME', p_access_name);
1890       FND_MSG_PUB.Add;
1891       RAISE FND_API.G_EXC_ERROR;
1892     END IF;
1893     CLOSE c1;
1894   ELSE
1895     -- neither access_name nor section_id is specified
1896     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_ID_OR_ACSS');
1897     FND_MSG_PUB.Add;
1898     RAISE FND_API.G_EXC_ERROR;
1899   END IF;
1900 
1901   --
1902   -- get master mini site id for the store
1903   --
1904   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
1905                           x_root_section_id => l_master_root_section_id);
1906 
1907   --
1908   -- Delete all the descendents of the section
1909   FOR r1 in c_get_child_sections(p_section_id,l_master_mini_site_id) loop
1910      IBE_DSP_SECTION_GRP.Delete_Section
1911       (
1912       p_api_version         => p_api_version,
1913       p_init_msg_list       => FND_API.G_FALSE,
1914       p_commit              => FND_API.G_FALSE,
1915       p_validation_level    => p_validation_level,
1916       p_section_id          => r1.section_id,
1917       p_access_name         => FND_API.G_MISS_CHAR,
1918       x_return_status       => x_return_status,
1919       x_msg_count           => x_msg_count,
1920       x_msg_data            => x_msg_data
1921       );
1922 
1923     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
1924       RAISE FND_API.G_EXC_ERROR;
1925     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
1926       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1927     END IF;
1928   END LOOP;
1929   -- after deleting the children of p_section_id, delete itself
1930     IBE_DSP_SECTION_GRP.Delete_Section
1931       (
1932       p_api_version         => p_api_version,
1933       p_init_msg_list       => FND_API.G_FALSE,
1934       p_commit              => FND_API.G_FALSE,
1935       p_validation_level    => p_validation_level,
1936       p_section_id          => p_section_id,
1937       p_access_name         => FND_API.G_MISS_CHAR,
1938       x_return_status       => x_return_status,
1939       x_msg_count           => x_msg_count,
1940       x_msg_data            => x_msg_data
1941       );
1942 
1943   --
1944   -- End of main API body.
1945 
1946   -- Standard check of p_commit.
1947   IF (FND_API.To_Boolean(p_commit)) THEN
1948     COMMIT WORK;
1949   END IF;
1950 
1951   -- Standard call to get message count and if count is 1, get message info.
1952   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
1953                             p_data    =>      x_msg_data,
1954                             p_encoded =>      'F');
1955 
1956 EXCEPTION
1957 
1958    WHEN FND_API.G_EXC_ERROR THEN
1959      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
1960      x_return_status := FND_API.G_RET_STS_ERROR;
1961      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1962                                p_data       =>      x_msg_data,
1963                                p_encoded    =>      'F');
1964 
1965    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1966      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
1967      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1968      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1969                                p_data       =>      x_msg_data,
1970                                p_encoded    =>      'F');
1971 
1972    WHEN OTHERS THEN
1973      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
1974      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
1975      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
1976      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
1977      FND_MESSAGE.Set_Token('REASON', SQLERRM);
1978      FND_MSG_PUB.Add;
1979 
1983      THEN
1980      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1981 
1982      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1984        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1985      END IF;
1986 
1987      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
1988                                p_data       =>      x_msg_data,
1989                                p_encoded    =>      'F');
1990 
1991 END Delete_Hierarchy_Section;
1992 
1993 
1994 /*PROCEDURE Delete_Hierarchy_Section
1995   (
1996    p_api_version                    IN NUMBER,
1997    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
1998    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
1999    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2000    p_section_id                     IN NUMBER   := FND_API.G_MISS_NUM,
2001    p_access_name                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
2002    x_return_status                  OUT NOCOPY VARCHAR2,
2003    x_msg_count                      OUT NOCOPY NUMBER,
2004    x_msg_data                       OUT NOCOPY VARCHAR2
2005   )
2006 IS
2007   l_api_name                     CONSTANT VARCHAR2(30) :=
2008     'Delete_Hierarchy_Section';
2009   l_api_version                  CONSTANT NUMBER       := 1.0;
2010   l_msg_count                    NUMBER;
2011   l_msg_data                     VARCHAR2(2000);
2012 
2013   l_section_id                   NUMBER;
2014   l_master_mini_site_id          NUMBER;
2015   l_master_root_section_id       NUMBER;
2016 
2017   CURSOR c1(l_c_access_name IN VARCHAR2)
2018   IS SELECT section_id FROM ibe_dsp_sections_b
2019     WHERE access_name = l_c_access_name;
2020 
2021 BEGIN
2022 
2023   -- Standard Start of API savepoint
2024   SAVEPOINT  DELETE_HIERARCHY_SECTION_PVT;
2025 
2026   -- Standard call to check for call compatibility.
2027   IF NOT FND_API.Compatible_API_Call(l_api_version,
2028                                      p_api_version,
2029                                      l_api_name,
2030                                      G_PKG_NAME)
2031   THEN
2032     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2033   END IF;
2034 
2035   -- Initialize message list if p_init_msg_list is set to TRUE.
2036   IF FND_API.to_Boolean(p_init_msg_list) THEN
2037     FND_MSG_PUB.initialize;
2038   END IF;
2039 
2040   -- Initialize API return status to success
2041   x_return_status := FND_API.G_RET_STS_SUCCESS;
2042 
2043   --
2044   -- Validate input data
2045   --
2046   IF ((p_section_id IS NOT NULL) AND
2047       (p_section_id <> FND_API.G_MISS_NUM))
2048   THEN
2049     -- p_section_id specified, continue
2050     l_section_id := p_section_id;
2051   ELSIF ((p_access_name IS NOT NULL) AND
2052          (p_access_name <> FND_API.G_MISS_CHAR))
2053   THEN
2054     -- find out the section_id from the access_name
2055     OPEN c1(p_access_name);
2056     FETCH c1 INTO l_section_id;
2057     IF (c1%NOTFOUND) THEN
2058       CLOSE c1;
2059       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_SCT_ACSS_NAME');
2060       FND_MESSAGE.Set_Token('ACCESS_NAME', p_access_name);
2061       FND_MSG_PUB.Add;
2062       RAISE FND_API.G_EXC_ERROR;
2063     END IF;
2064     CLOSE c1;
2065   ELSE
2066     -- neither access_name nor section_id is specified
2067     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_ID_OR_ACSS');
2068     FND_MSG_PUB.Add;
2069     RAISE FND_API.G_EXC_ERROR;
2070   END IF;
2071 
2072   --
2073   -- get master mini site id for the store
2074   --
2075   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
2076                           x_root_section_id => l_master_root_section_id);
2077 
2078   --
2079   -- Delete the current section and all its descendants
2080   --
2081   Delete_Recursive_Sections
2082     (
2083     p_api_version                    => p_api_version,
2084     p_init_msg_list                  => FND_API.G_FALSE,
2085     p_commit                         => FND_API.G_FALSE,
2086     p_validation_level               => p_validation_level,
2087     p_master_mini_site_id            => l_master_mini_site_id,
2088     p_section_id                     => l_section_id,
2089     x_return_status                  => x_return_status,
2090     x_msg_count                      => x_msg_count,
2091     x_msg_data                       => x_msg_data
2092     );
2093 
2094   IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2095     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RECUR_SCT_DEL_FAIL');
2096     FND_MESSAGE.Set_Token('SECTION_ID', l_section_id);
2097     FND_MSG_PUB.Add;
2098     RAISE FND_API.G_EXC_ERROR;
2099   ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2100     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RECUR_SCT_DEL_FAIL');
2101     FND_MESSAGE.Set_Token('SECTION_ID', l_section_id);
2102     FND_MSG_PUB.Add;
2103     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2104   END IF;
2105 
2106   --
2107   -- End of main API body.
2108 
2109   -- Standard check of p_commit.
2110   IF (FND_API.To_Boolean(p_commit)) THEN
2111     COMMIT WORK;
2112   END IF;
2113 
2114   -- Standard call to get message count and if count is 1, get message info.
2115   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
2116                             p_data    =>      x_msg_data,
2120 
2117                             p_encoded =>      'F');
2118 
2119 EXCEPTION
2121    WHEN FND_API.G_EXC_ERROR THEN
2122      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
2123      x_return_status := FND_API.G_RET_STS_ERROR;
2124      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2125                                p_data       =>      x_msg_data,
2126                                p_encoded    =>      'F');
2127 
2128    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2129      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
2130      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2131      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2132                                p_data       =>      x_msg_data,
2133                                p_encoded    =>      'F');
2134 
2135    WHEN OTHERS THEN
2136      ROLLBACK TO DELETE_HIERARCHY_SECTION_PVT;
2137      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
2138      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
2139      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
2140      FND_MESSAGE.Set_Token('REASON', SQLERRM);
2141      FND_MSG_PUB.Add;
2142 
2143      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2144 
2145      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2146      THEN
2147        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2148      END IF;
2149 
2150      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2151                                p_data       =>      x_msg_data,
2152                                p_encoded    =>      'F');
2153 
2154 END Delete_Hierarchy_Section;
2155 */
2156 
2157 --bug 2699547, code for PROCEDURE Get_Hierarchy_Sections removed
2158 
2159 --
2160 -- for each item in p_inventory_item_ids, associate the item to p_section_id
2161 --
2162 PROCEDURE Associate_Items_To_Section
2163   (
2164    p_api_version                    IN NUMBER,
2165    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
2166    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
2167    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2168    p_section_id                     IN NUMBER,
2169    p_inventory_item_ids             IN JTF_NUMBER_TABLE,
2170    p_organization_ids               IN JTF_NUMBER_TABLE,
2171    p_start_date_actives             IN JTF_DATE_TABLE,
2172    p_end_date_actives               IN JTF_DATE_TABLE,
2173    p_sort_orders                    IN JTF_NUMBER_TABLE,
2174    p_association_reason_codes       IN JTF_VARCHAR2_TABLE_300,
2175    x_section_item_ids               OUT NOCOPY JTF_NUMBER_TABLE,
2176    x_duplicate_association_status   OUT NOCOPY VARCHAR2,
2177    x_return_status                  OUT NOCOPY VARCHAR2,
2178    x_msg_count                      OUT NOCOPY NUMBER,
2179    x_msg_data                       OUT NOCOPY VARCHAR2
2180   )
2181 IS
2182   l_api_name                     CONSTANT VARCHAR2(30) :=
2183     'Associate_Items_To_Section';
2184   l_api_version                  CONSTANT NUMBER       := 1.0;
2185   l_msg_count                    NUMBER;
2186   l_msg_data                     VARCHAR2(2000);
2187 
2188   l_section_id                   NUMBER;
2189   l_mini_site_id                 NUMBER;
2190   l_mini_site_section_item_id    NUMBER;
2191   l_tmp_section_item_id          NUMBER;
2192   l_duplicate_flags              JTF_VARCHAR2_TABLE_300;
2193 
2194   -- get all the mini-sites to which the section belongs to except the
2195   -- master mini-site(s)
2196   CURSOR c1(l_c_section_id IN NUMBER)
2197   IS SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
2198     WHERE child_section_id = l_c_section_id
2199     AND mini_site_id NOT IN
2200     (SELECT msite_id FROM ibe_msites_b
2201     WHERE UPPER(master_msite_flag) = 'Y');
2202 
2203   CURSOR c2(l_c_section_id IN NUMBER,
2204     l_c_inventory_item_id IN NUMBER,
2205     l_c_organization_id IN NUMBER)
2206   IS SELECT section_item_id FROM ibe_dsp_section_items
2207     WHERE section_id = l_c_section_id
2208     AND inventory_item_id = l_c_inventory_item_id
2209     AND organization_id = l_c_organization_id;
2210 
2211 BEGIN
2212 
2213   -- Standard Start of API savepoint
2214   SAVEPOINT  ASSOCIATE_ITEMS_TO_SECTION_PVT;
2215 
2216   -- Standard call to check for call compatibility.
2217   IF NOT FND_API.Compatible_API_Call(l_api_version,
2218                                      p_api_version,
2219                                      l_api_name,
2220                                      G_PKG_NAME)
2221   THEN
2222     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2223   END IF;
2224 
2225   -- Initialize message list if p_init_msg_list is set to TRUE.
2226   IF FND_API.to_Boolean(p_init_msg_list) THEN
2227     FND_MSG_PUB.initialize;
2228   END IF;
2229 
2230   -- Initialize API return status to success
2231   x_return_status := FND_API.G_RET_STS_SUCCESS;
2232   x_duplicate_association_status := FND_API.G_RET_STS_SUCCESS;
2233 
2234   -- todo optimize using FORALL and BIND COLLECT
2235   x_section_item_ids := JTF_NUMBER_TABLE();
2236   l_duplicate_flags := JTF_VARCHAR2_TABLE_300();
2237   FOR i IN 1..p_inventory_item_ids.COUNT LOOP
2238 
2239     x_section_item_ids.EXTEND();
2240     l_duplicate_flags.EXTEND();
2241 
2242     OPEN c2(p_section_id, p_inventory_item_ids(i), p_organization_ids(i));
2243     FETCH c2 INTO l_tmp_section_item_id;
2244     IF (c2%FOUND) THEN
2245 
2246       CLOSE c2;
2250 
2247       x_duplicate_association_status := FND_API.G_RET_STS_ERROR;
2248       x_section_item_ids(i) := l_tmp_section_item_id;
2249       l_duplicate_flags(i) := FND_API.G_RET_STS_ERROR;
2251       -- add a message if the association already exists. Don't raise error.
2252       -- This message will be used to display as a warning in the UI
2253       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_ITM_ALREADY_ASSOC');
2254       FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
2255       FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_inventory_item_ids(i));
2256       FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_organization_ids(i));
2257       FND_MSG_PUB.Add;
2258 
2259     ELSE
2260 
2261       CLOSE c2;
2262       l_duplicate_flags(i) := FND_API.G_RET_STS_SUCCESS;
2263 
2264       -- insert an entry in ibe_dsp_section_items table
2265       IBE_DSP_SECTION_ITEM_PVT.Create_Section_Item
2266         (
2267         p_api_version                    => p_api_version,
2268         p_init_msg_list                  => FND_API.G_FALSE,
2269         p_commit                         => FND_API.G_FALSE,
2270         p_validation_level               => p_validation_level,
2271         p_section_id                     => p_section_id,
2272         p_inventory_item_id              => p_inventory_item_ids(i),
2273         p_organization_id                => p_organization_ids(i),
2274         p_start_date_active              => p_start_date_actives(i),
2275         p_end_date_active                => p_end_date_actives(i),
2276         p_sort_order                     => p_sort_orders(i),
2277         p_association_reason_code        => p_association_reason_codes(i),
2278         x_section_item_id                => x_section_item_ids(i),
2279         x_return_status                  => x_return_status,
2280         x_msg_count                      => x_msg_count,
2281         x_msg_data                       => x_msg_data
2282         );
2283 
2284       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2285         RAISE FND_API.G_EXC_ERROR;
2286       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2287         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2288       END IF;
2289 
2290     END IF;
2291 
2292   END LOOP;
2293 
2294   -- add entries into ibe_dsp_msite_sct_items for each mini-site (except
2295   -- master mini-sites)
2296   FOR r1 IN c1(p_section_id) LOOP -- for each mini-site
2297 
2298     FOR i IN 1..x_section_item_ids.COUNT LOOP
2299 
2300       IF (l_duplicate_flags(i) = FND_API.G_RET_STS_SUCCESS) THEN
2301 
2302         IBE_DSP_MSITE_SCT_ITEM_PVT.Create_MSite_Section_Item
2303           (
2304           p_api_version                    => p_api_version,
2305           p_init_msg_list                  => FND_API.G_FALSE,
2306           p_commit                         => FND_API.G_FALSE,
2307           p_validation_level               => p_validation_level,
2308           p_mini_site_id                   => r1.mini_site_id,
2309           p_section_item_id                => x_section_item_ids(i),
2310           p_start_date_active              => p_start_date_actives(i),
2311           p_end_date_active                => p_end_date_actives(i),
2312           x_mini_site_section_item_id      => l_mini_site_section_item_id,
2313           x_return_status                  => x_return_status,
2314           x_msg_count                      => x_msg_count,
2315           x_msg_data                       => x_msg_data
2316           );
2317 
2318         IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2319           RAISE FND_API.G_EXC_ERROR;
2320         ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2321           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2322         END IF;
2323 
2324       END IF; -- end (l_duplicate_flags(i) = FND_API.G_RET_STS_SUCCESS)
2325 
2326     END LOOP; -- end for i
2327 
2328   END LOOP; -- end for r1
2329 
2330   --
2331   -- End of main API body.
2332 
2333   -- Standard check of p_commit.
2334   IF (FND_API.To_Boolean(p_commit)) THEN
2335     COMMIT WORK;
2336   END IF;
2337 
2338   -- Standard call to get message count and if count is 1, get message info.
2339   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
2340                             p_data    =>      x_msg_data,
2341                             p_encoded =>      'F');
2342 
2343 EXCEPTION
2344 
2345    WHEN FND_API.G_EXC_ERROR THEN
2346      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
2347      x_return_status := FND_API.G_RET_STS_ERROR;
2348      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2349                                p_data       =>      x_msg_data,
2350                                p_encoded    =>      'F');
2351 
2352    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2353      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
2354      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2355      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2356                                p_data       =>      x_msg_data,
2357                                p_encoded    =>      'F');
2358 
2359    WHEN OTHERS THEN
2360      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
2361      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
2362      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
2363      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
2364      FND_MESSAGE.Set_Token('REASON', SQLERRM);
2365      FND_MSG_PUB.Add;
2366 
2367      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2368 
2372      END IF;
2369      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2370      THEN
2371        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2373 
2374      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2375                                p_data       =>      x_msg_data,
2376                                p_encoded    =>      'F');
2377 
2378 END Associate_Items_To_Section;
2379 
2380 --
2381 -- for each section in p_section_ids, associate the item inventory_item_id
2382 -- to it
2383 PROCEDURE Associate_Sections_To_Item
2384   (
2385    p_api_version                    IN NUMBER,
2386    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
2387    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
2388    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2389    p_inventory_item_id              IN NUMBER,
2390    p_organization_id                IN NUMBER,
2391    p_section_ids                    IN JTF_NUMBER_TABLE,
2392    p_start_date_actives             IN JTF_DATE_TABLE,
2393    p_end_date_actives               IN JTF_DATE_TABLE,
2394    p_sort_orders                    IN JTF_NUMBER_TABLE,
2395    p_association_reason_codes       IN JTF_VARCHAR2_TABLE_300,
2396    x_section_item_ids               OUT NOCOPY JTF_NUMBER_TABLE,
2397    x_duplicate_association_status   OUT NOCOPY VARCHAR2,
2398    x_return_status                  OUT NOCOPY VARCHAR2,
2399    x_msg_count                      OUT NOCOPY NUMBER,
2400    x_msg_data                       OUT NOCOPY VARCHAR2
2401   )
2402 IS
2403   l_api_name                     CONSTANT VARCHAR2(30) :=
2404     'Associate_Sections_To_Item';
2405   l_api_version                  CONSTANT NUMBER       := 1.0;
2406   l_msg_count                    NUMBER;
2407   l_msg_data                     VARCHAR2(2000);
2408 
2409   l_section_id                   NUMBER;
2410   l_mini_site_id                 NUMBER;
2411   l_mini_site_section_item_id    NUMBER;
2412   l_tmp_section_item_id          NUMBER;
2413 
2414   -- get all the mini-sites to which the section belongs to except the
2415   -- master mini-site(s)
2416   CURSOR c1(l_c_section_id IN NUMBER)
2417   IS SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
2418     WHERE child_section_id = l_c_section_id
2419     AND mini_site_id NOT IN
2420     (SELECT msite_id FROM ibe_msites_b
2421     WHERE UPPER(master_msite_flag) = 'Y');
2422 
2423   CURSOR c2(l_c_section_id IN NUMBER,
2424     l_c_inventory_item_id IN NUMBER,
2425     l_c_organization_id IN NUMBER)
2426   IS SELECT section_item_id FROM ibe_dsp_section_items
2427     WHERE section_id = l_c_section_id
2428     AND inventory_item_id = l_c_inventory_item_id
2429     AND organization_id = l_c_organization_id;
2430 
2431 BEGIN
2432 
2433   -- Standard Start of API savepoint
2434   SAVEPOINT  ASSOCIATE_SECTIONS_TO_ITEM_PVT;
2435 
2436   -- Standard call to check for call compatibility.
2437   IF NOT FND_API.Compatible_API_Call(l_api_version,
2438                                       p_api_version,
2439                                       l_api_name,
2440                                       G_PKG_NAME)
2441   THEN
2442     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2443   END IF;
2444 
2445   -- Initialize message list if p_init_msg_list is set to TRUE.
2446   IF FND_API.to_Boolean(p_init_msg_list) THEN
2447     FND_MSG_PUB.initialize;
2448   END IF;
2449 
2450   -- Initialize API return status to success
2451   x_return_status := FND_API.G_RET_STS_SUCCESS;
2452   x_duplicate_association_status := FND_API.G_RET_STS_SUCCESS;
2453 
2454   -- todo optimize using FORALL and BIND COLLECT
2455   x_section_item_ids := JTF_NUMBER_TABLE();
2456   FOR i IN 1..p_section_ids.COUNT LOOP
2457 
2458     x_section_item_ids.EXTEND();
2459 
2460     OPEN c2(p_section_ids(i), p_inventory_item_id, p_organization_id);
2461     FETCH c2 INTO l_tmp_section_item_id;
2462     IF (c2%FOUND) THEN
2463       CLOSE c2;
2464 
2465       x_duplicate_association_status := FND_API.G_RET_STS_ERROR;
2466       x_section_item_ids(i) := l_tmp_section_item_id;
2467 
2468       -- add a message if the association already exists. Don't raise error.
2469       -- This message will be used to display as a warning in the UI
2470       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_ITM_ALREADY_ASSOC');
2471       FND_MESSAGE.Set_Token('SECTION_ID', p_section_ids(i));
2472       FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_inventory_item_id);
2473       FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_organization_id);
2474       FND_MSG_PUB.Add;
2475 
2476     ELSE
2477 
2478       CLOSE c2;
2479 
2480       --
2481       -- insert an entry in ibe_dsp_section_items table
2482       --
2483       IBE_DSP_SECTION_ITEM_PVT.Create_Section_Item
2484         (
2485         p_api_version                    => p_api_version,
2486         p_init_msg_list                  => FND_API.G_FALSE,
2487         p_commit                         => FND_API.G_FALSE,
2488         p_validation_level               => p_validation_level,
2489         p_section_id                     => p_section_ids(i),
2490         p_inventory_item_id              => p_inventory_item_id,
2491         p_organization_id                => p_organization_id,
2492         p_start_date_active              => p_start_date_actives(i),
2493         p_end_date_active                => p_end_date_actives(i),
2494         p_sort_order                     => p_sort_orders(i),
2498         x_msg_count                      => x_msg_count,
2495         p_association_reason_code        => p_association_reason_codes(i),
2496         x_section_item_id                => x_section_item_ids(i),
2497         x_return_status                  => x_return_status,
2499         x_msg_data                       => x_msg_data
2500         );
2501 
2502       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2503         RAISE FND_API.G_EXC_ERROR;
2504       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2505         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2506       END IF;
2507 
2508       -- add entries into ibe_dsp_msite_sct_items for each mini-site (except
2509       -- master mini-sites)
2510       FOR r1 IN c1(p_section_ids(i)) LOOP -- for each mini-site
2511 
2512         IBE_DSP_MSITE_SCT_ITEM_PVT.Create_MSite_Section_Item
2513           (
2514           p_api_version                    => p_api_version,
2515           p_init_msg_list                  => FND_API.G_FALSE,
2516           p_commit                         => FND_API.G_FALSE,
2517           p_validation_level               => p_validation_level,
2518           p_mini_site_id                   => r1.mini_site_id,
2519           p_section_item_id                => x_section_item_ids(i),
2520           p_start_date_active              => p_start_date_actives(i),
2521           p_end_date_active                => p_end_date_actives(i),
2522           x_mini_site_section_item_id      => l_mini_site_section_item_id,
2523           x_return_status                  => x_return_status,
2524           x_msg_count                      => x_msg_count,
2525           x_msg_data                       => x_msg_data
2526           );
2527 
2528         IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2529           RAISE FND_API.G_EXC_ERROR;
2530         ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2531           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2532         END IF;
2533 
2534       END LOOP; -- end r1
2535 
2536     END IF;
2537 
2538   END LOOP; -- end i
2539 
2540   --
2541   -- End of main API body.
2542 
2543   -- Standard check of p_commit.
2544   IF (FND_API.To_Boolean(p_commit)) THEN
2545     COMMIT WORK;
2546   END IF;
2547 
2548   -- Standard call to get message count and if count is 1, get message info.
2549   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
2550                             p_data    =>      x_msg_data,
2551                             p_encoded =>      'F');
2552 
2553 EXCEPTION
2554 
2555    WHEN FND_API.G_EXC_ERROR THEN
2556      ROLLBACK TO ASSOCIATE_SECTIONS_TO_ITEM_PVT;
2557      x_return_status := FND_API.G_RET_STS_ERROR;
2558      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2559                                p_data       =>      x_msg_data,
2560                                p_encoded    =>      'F');
2561 
2562    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2563      ROLLBACK TO ASSOCIATE_SECTIONS_TO_ITEM_PVT;
2564      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2565      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2566                                p_data       =>      x_msg_data,
2567                                p_encoded    =>      'F');
2568 
2569    WHEN OTHERS THEN
2570      ROLLBACK TO ASSOCIATE_SECTIONS_TO_ITEM_PVT;
2571      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
2572      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
2573      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
2574      FND_MESSAGE.Set_Token('REASON', SQLERRM);
2575      FND_MSG_PUB.Add;
2576 
2577      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2578 
2579      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2580      THEN
2581        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2582      END IF;
2583 
2584      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2585                                p_data       =>      x_msg_data,
2586                                p_encoded    =>      'F');
2587 
2588 END Associate_Sections_To_Item;
2589 
2590 --
2591 -- for each section in p_section_ids, delete each of the inventory_item_ids
2592 -- Entries in p_sections_ids and p_inventory_item_ids are assumed to be unique
2593 --
2594 PROCEDURE Disassociate_Scts_To_Itms
2595   (
2596    p_api_version                    IN NUMBER,
2597    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
2598    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
2599    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2600    p_section_ids                    IN JTF_NUMBER_TABLE,
2601    p_inventory_item_ids             IN JTF_NUMBER_TABLE,
2602    p_organization_ids               IN JTF_NUMBER_TABLE,
2603    x_return_status                  OUT NOCOPY VARCHAR2,
2604    x_msg_count                      OUT NOCOPY NUMBER,
2605    x_msg_data                       OUT NOCOPY VARCHAR2
2606   )
2607 IS
2608   l_api_name                     CONSTANT VARCHAR2(30) :=
2609     'Disassociate_Scts_To_Itms';
2610   l_api_version                  CONSTANT NUMBER       := 1.0;
2611   l_msg_count                    NUMBER;
2612   l_msg_data                     VARCHAR2(2000);
2613 
2614   l_section_id                   NUMBER;
2615 
2616 BEGIN
2617 
2618   -- Standard Start of API savepoint
2619   SAVEPOINT  DISASSOCIATE_SCTS_TO_ITMS_PVT;
2620 
2624                                      l_api_name,
2621   -- Standard call to check for call compatibility.
2622   IF NOT FND_API.Compatible_API_Call(l_api_version,
2623                                      p_api_version,
2625                                      G_PKG_NAME)
2626   THEN
2627     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2628   END IF;
2629 
2630   -- Initialize message list if p_init_msg_list is set to TRUE.
2631   IF FND_API.to_Boolean(p_init_msg_list) THEN
2632     FND_MSG_PUB.initialize;
2633   END IF;
2634 
2635   -- Initialize API return status to success
2636   x_return_status := FND_API.G_RET_STS_SUCCESS;
2637 
2638   -- todo optimize using FORALL and BIND COLLECT
2639   FOR i IN 1..p_section_ids.COUNT LOOP
2640 
2641     FOR j IN 1..p_inventory_item_ids.COUNT LOOP
2642       -- delete entry in ibe_dsp_section_items table
2643       IBE_DSP_SECTION_ITEM_PVT.Delete_Section_Item
2644         (
2645         p_api_version                    => p_api_version,
2646         p_init_msg_list                  => FND_API.G_FALSE,
2647         p_commit                         => FND_API.G_FALSE,
2648         p_validation_level               => p_validation_level,
2649         p_call_from_trigger              => FALSE,
2650         p_section_item_id                => FND_API.G_MISS_NUM,
2651         p_section_id                     => p_section_ids(i),
2652         p_inventory_item_id              => p_inventory_item_ids(j),
2653         p_organization_id                => p_organization_ids(j),
2654         x_return_status                  => x_return_status,
2655         x_msg_count                      => x_msg_count,
2656         x_msg_data                       => x_msg_data
2657         );
2658 
2659       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2660         RAISE FND_API.G_EXC_ERROR;
2661       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2662         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2663       END IF;
2664 
2665     END LOOP; -- j loop
2666 
2667   END LOOP; -- i loop
2668 
2669   --
2670   -- End of main API body.
2671 
2672   -- Standard check of p_commit.
2673   IF (FND_API.To_Boolean(p_commit)) THEN
2674     COMMIT WORK;
2675   END IF;
2676 
2677   -- Standard call to get message count and if count is 1, get message info.
2678   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
2679                             p_data    =>      x_msg_data,
2680                             p_encoded =>      'F');
2681 
2682 EXCEPTION
2683 
2684    WHEN FND_API.G_EXC_ERROR THEN
2685      ROLLBACK TO DISASSOCIATE_SCTS_TO_ITMS_PVT;
2686      x_return_status := FND_API.G_RET_STS_ERROR;
2687      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2688                                p_data       =>      x_msg_data,
2689                                p_encoded    =>      'F');
2690 
2691    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2692      ROLLBACK TO DISASSOCIATE_SCTS_TO_ITMS_PVT;
2693      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2694      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2695                                p_data       =>      x_msg_data,
2696                                p_encoded    =>      'F');
2697 
2698    WHEN OTHERS THEN
2699      ROLLBACK TO DISASSOCIATE_SCTS_TO_ITMS_PVT;
2700      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
2701      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
2702      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
2703      FND_MESSAGE.Set_Token('REASON', SQLERRM);
2704      FND_MSG_PUB.Add;
2705 
2706      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2707 
2708      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2709      THEN
2710        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2711      END IF;
2712 
2713      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2714                                p_data       =>      x_msg_data,
2715                                p_encoded    =>      'F');
2716 
2717 END Disassociate_Scts_To_Itms;
2718 
2719 --
2720 -- for each section in p_section_ids, delete each of the inventory_item_ids
2721 -- Entries in p_sections_ids and p_inventory_item_ids are assumed to be unique
2722 --
2723 PROCEDURE Disassociate_Scts_Itms
2724   (
2725    p_api_version                    IN NUMBER,
2726    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
2727    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
2728    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2729    p_section_item_ids               IN JTF_NUMBER_TABLE,
2730    x_return_status                  OUT NOCOPY VARCHAR2,
2731    x_msg_count                      OUT NOCOPY NUMBER,
2732    x_msg_data                       OUT NOCOPY VARCHAR2
2733   )
2734 IS
2735   l_api_name                     CONSTANT VARCHAR2(30) :=
2736     'Disassociate_Scts_Itms';
2737   l_api_version                  CONSTANT NUMBER       := 1.0;
2738   l_msg_count                    NUMBER;
2739   l_msg_data                     VARCHAR2(2000);
2740 
2741   l_section_id                   NUMBER;
2742 
2743 BEGIN
2744 
2745   -- Standard Start of API savepoint
2746   SAVEPOINT  DISASSOCIATE_SCTS_ITMS_PVT;
2747 
2748   -- Standard call to check for call compatibility.
2749   IF NOT FND_API.Compatible_API_Call(l_api_version,
2750                                      p_api_version,
2754     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2751                                      l_api_name,
2752                                      G_PKG_NAME)
2753   THEN
2755   END IF;
2756 
2757   -- Initialize message list if p_init_msg_list is set to TRUE.
2758   IF FND_API.to_Boolean(p_init_msg_list) THEN
2759     FND_MSG_PUB.initialize;
2760   END IF;
2761 
2762   -- Initialize API return status to success
2763   x_return_status := FND_API.G_RET_STS_SUCCESS;
2764 
2765   -- todo optimize using FORALL and BIND COLLECT
2766   FOR i IN 1..p_section_item_ids.COUNT LOOP
2767 
2768     -- delete entry in ibe_dsp_section_items table
2769     IBE_DSP_SECTION_ITEM_PVT.Delete_Section_Item
2770       (
2771       p_api_version                    => p_api_version,
2772       p_init_msg_list                  => FND_API.G_FALSE,
2773       p_commit                         => FND_API.G_FALSE,
2774       p_validation_level               => p_validation_level,
2775       p_call_from_trigger              => FALSE,
2776       p_section_item_id                => p_section_item_ids(i),
2777       p_section_id                     => FND_API.G_MISS_NUM,
2778       p_inventory_item_id              => FND_API.G_MISS_NUM,
2779       p_organization_id                => FND_API.G_MISS_NUM,
2780       x_return_status                  => x_return_status,
2781       x_msg_count                      => x_msg_count,
2782         x_msg_data                       => x_msg_data
2783       );
2784 
2785       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
2786         RAISE FND_API.G_EXC_ERROR;
2787       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
2788         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2789       END IF;
2790 
2791   END LOOP; -- i loop
2792 
2793   --
2794   -- End of main API body.
2795 
2796   -- Standard check of p_commit.
2797   IF (FND_API.To_Boolean(p_commit)) THEN
2798     COMMIT WORK;
2799   END IF;
2800 
2801   -- Standard call to get message count and if count is 1, get message info.
2802   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
2803                             p_data    =>      x_msg_data,
2804                             p_encoded =>      'F');
2805 
2806 EXCEPTION
2807 
2808    WHEN FND_API.G_EXC_ERROR THEN
2809      ROLLBACK TO DISASSOCIATE_SCTS_ITMS_PVT;
2810      x_return_status := FND_API.G_RET_STS_ERROR;
2811      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2812                                p_data       =>      x_msg_data,
2813                                p_encoded    =>      'F');
2814 
2815    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2816      ROLLBACK TO DISASSOCIATE_SCTS_ITMS_PVT;
2817      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2818      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2819                                p_data       =>      x_msg_data,
2820                                p_encoded    =>      'F');
2821 
2822    WHEN OTHERS THEN
2823      ROLLBACK TO DISASSOCIATE_SCTS_ITMS_PVT;
2824      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
2825      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
2826      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
2827      FND_MESSAGE.Set_Token('REASON', SQLERRM);
2828      FND_MSG_PUB.Add;
2829 
2830      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2831 
2832      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2833      THEN
2834        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2835      END IF;
2836 
2837      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
2838                                p_data       =>      x_msg_data,
2839                                p_encoded    =>      'F');
2840 
2841 END Disassociate_Scts_Itms;
2842 
2843 --
2844 -- Associate p_mini_site_ids with p_section_id. If there are any other
2845 -- mini-sites associated with p_section_id, they will be removed. At the
2846 -- end of this procedure, p_section_id will be associated with only mini-sites
2847 -- specified in p_mini_site_ids. Also all the descendants of p_section_id
2848 -- will have an association with each of the p_mini_site_ids, if
2849 -- available_in_all_sites_flag is 'Y'
2850 --
2851 PROCEDURE Associate_MSites_To_Section
2852   (
2853    p_api_version                    IN NUMBER,
2854    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
2855    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
2856    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2857    p_section_id                     IN NUMBER,
2858    p_mini_site_ids                  IN JTF_NUMBER_TABLE,
2859    x_return_status                  OUT NOCOPY VARCHAR2,
2860    x_msg_count                      OUT NOCOPY NUMBER,
2861    x_msg_data                       OUT NOCOPY VARCHAR2
2862   )
2863 IS
2864   l_api_name                     CONSTANT VARCHAR2(30) :=
2865     'Associate_MSites_To_Section';
2866   l_api_version                  CONSTANT NUMBER       := 1.0;
2867   l_msg_count                    NUMBER;
2868   l_msg_data                     VARCHAR2(2000);
2869 
2870   l_found_flag                   BOOLEAN;
2871   l_counter                      NUMBER;
2872   l_row_id                       VARCHAR2(30);
2873   l_master_mini_site_id          NUMBER;
2874   l_master_root_section_id       NUMBER;
2875   l_mini_site_section_section_id NUMBER;
2876   l_mini_site_section_item_id    NUMBER;
2880 
2877   l_parent_mini_site_ids         JTF_NUMBER_TABLE;
2878   l_root_mini_site_ids           JTF_NUMBER_TABLE;
2879   l_old_mini_site_ids            JTF_NUMBER_TABLE;
2881   --
2882   -- Get the mini-sites to which the parent of l_c_child_section_id belongs to
2883   -- and which does not include master mini-site id
2884   --
2885   CURSOR c1(l_c_child_section_id IN NUMBER,
2886     l_c_master_mini_site_id IN NUMBER)
2887   IS SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
2888     WHERE child_section_id =
2889     (SELECT parent_section_id FROM ibe_dsp_msite_sct_sects
2890     WHERE child_section_id = l_c_child_section_id
2891     AND mini_site_id = l_c_master_mini_site_id)
2892     AND mini_site_id <> l_c_master_mini_site_id;
2893 
2894   --
2895   -- Get the mini-sites to which l_c_section_id belongs to and which does
2896   -- not include master mini-site id
2897   --
2898   CURSOR c2(l_c_section_id IN NUMBER,
2899     l_c_master_mini_site_id IN NUMBER)
2900   IS SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
2901     WHERE child_section_id = l_c_section_id
2902     AND   mini_site_id <> l_c_master_mini_site_id;
2903 
2904   --
2905   -- Get the row in ibe_dsp_msite_sct_items which belongs to mini-site
2906   -- l_c_mini_site_id, and the section item id is one of the descendants
2907   -- of the section l_c_section_id
2908   --
2909   -- Bug 2684417 (use UNION instead of OR clause)
2910   CURSOR c3(l_c_section_id IN NUMBER,
2911     l_c_mini_site_id IN NUMBER,
2912     l_c_master_mini_site_id IN NUMBER)
2913   IS SELECT MSI.mini_site_section_item_id
2914      FROM   ibe_dsp_msite_sct_items MSI,
2915             ibe_dsp_section_items SI,
2916             ibe_dsp_msite_sct_sects MSS
2917      WHERE  MSI.mini_site_id = l_c_mini_site_id
2918      AND    MSI.section_item_id = SI.section_item_id
2919      AND    SI.section_id = MSS.child_section_id
2920      AND    MSS.mini_site_id = l_c_master_mini_site_id
2921      AND    MSS.child_section_id = l_c_section_id
2922 
2923    UNION
2924 
2925      SELECT MSI.mini_site_section_item_id
2926      FROM   ibe_dsp_msite_sct_items MSI,
2927             ibe_dsp_section_items SI,
2928             ibe_dsp_msite_sct_sects MSS
2929      WHERE  MSI.mini_site_id = l_c_mini_site_id
2930      AND    MSI.section_item_id = SI.section_item_id
2931      AND    SI.section_id = MSS.child_section_id
2932      AND    MSS.mini_site_id = l_c_master_mini_site_id
2933 	AND    MSS.child_section_id IN
2934               (SELECT child_section_id
2935 			FROM ibe_dsp_msite_sct_sects
2936                START WITH parent_section_id = l_c_section_id
2937 			AND mini_site_id = l_master_mini_site_id
2938                CONNECT BY PRIOR child_section_id = parent_section_id
2939                AND mini_site_id = l_master_mini_site_id);
2940 
2941   --
2942   -- Get the (master) info for the section l_c_section_id and all its
2943   -- descendants
2944   --
2945 --  CURSOR c4(l_c_section_id IN NUMBER,
2946 --     l_c_master_mini_site_id IN NUMBER)
2947 --   IS SELECT parent_section_id, child_section_id, start_date_active,
2948 --     end_date_active, sort_order
2949 --     FROM ibe_dsp_msite_sct_sects
2950 --     WHERE mini_site_id = l_c_master_mini_site_id
2951 --     START WITH child_section_id = l_c_section_id
2952 --     CONNECT BY PRIOR child_section_id = parent_section_id
2953 --     AND PRIOR mini_site_id = l_c_master_mini_site_id
2954 --     AND mini_site_id = l_c_master_mini_site_id;
2955 --
2956 --   CURSOR c5(l_c_section_id IN NUMBER,
2957 --     l_c_master_mini_site_id IN NUMBER)
2958 --   IS SELECT SI.section_item_id
2959 --     FROM ibe_dsp_msite_sct_sects MSS, ibe_dsp_section_items SI
2960 --     WHERE SI.section_id = MSS.child_section_id
2961 --     AND   MSS.mini_site_id = l_c_master_mini_site_id
2962 --     AND   (MSS.child_section_id = l_c_section_id OR
2963 --     MSS.child_section_id IN
2964 --     (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
2965 --     START WITH child_section_id = l_c_section_id
2966 --     CONNECT BY PRIOR child_section_id = parent_section_id
2967 --     AND PRIOR mini_site_id = l_c_master_mini_site_id));
2968 
2969   --
2970   -- Get the list of mini-sites for which l_c_section_id is the
2971   -- root section id
2972   --
2973   CURSOR c6(l_c_section_id IN NUMBER) IS SELECT msite_id
2974     FROM ibe_msites_b
2975     WHERE msite_root_section_id = l_c_section_id
2976     AND master_msite_flag <> 'Y';
2977 
2978   --
2979   -- Get the detail info for MSS association for l_c_section_id from the
2980   -- master mini-site's entry
2981   --
2982   CURSOR c_get_section_hierary_info(l_c_section_id IN NUMBER,
2983 	l_c_master_mini_site_id IN NUMBER)
2984   IS SELECT parent_section_id, start_date_active, end_date_active, sort_order
2985     FROM ibe_dsp_msite_sct_sects
2986     WHERE child_section_id = l_c_section_id
2987     AND mini_site_id = l_c_master_mini_site_id;
2988 
2989   l_parent_section_id NUMBER;
2990   l_start_date_active DATE;
2991   l_end_date_active DATE;
2992   l_sort_order NUMBER;
2993 BEGIN
2994 
2995   -- Standard Start of API savepoint
2996   SAVEPOINT  ASSOCIATE_MSITES_TO_SECTION;
2997 
2998   -- Standard call to check for call compatibility.
2999   IF NOT FND_API.Compatible_API_Call(l_api_version,
3000                                      p_api_version,
3001                                      l_api_name,
3002                                      G_PKG_NAME)
3003   THEN
3004     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3008   IF FND_API.to_Boolean(p_init_msg_list) THEN
3005   END IF;
3006 
3007   -- Initialize message list if p_init_msg_list is set to TRUE.
3009     FND_MSG_PUB.initialize;
3010   END IF;
3011 
3012   -- Initialize API return status to success
3013   x_return_status := FND_API.G_RET_STS_SUCCESS;
3014 
3015   --
3016   -- Get master mini site id for the store
3017   --
3018   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
3019                           x_root_section_id => l_master_root_section_id);
3020 
3021   --
3022   -- Check if the parent section of p_section_id belongs to all the mini-sites
3023   -- specified in p_mini_site_ids. If not, then that mini-site should be
3024   -- have root section id as p_section_id.
3025   -- Also lock the rows (todo) for the parent section, so that they don't get
3026   -- changed while the child section and its descendants are assigned with
3027   -- mini-sites
3028   --
3029 
3030   --
3031   -- Get the list of mini-sites to which the parent section (of p_section_id)
3032   -- belongs to
3033   --
3034   l_counter := 1;
3035   l_parent_mini_site_ids := JTF_NUMBER_TABLE();
3036   FOR r1 IN c1(p_section_id, l_master_mini_site_id) LOOP
3037     l_parent_mini_site_ids.EXTEND();
3038     l_parent_mini_site_ids(l_counter) := r1.mini_site_id;
3039     l_counter := l_counter + 1;
3040   END LOOP;
3041 
3042   --
3043   -- Get the list of mini-sites (l_root_mini_site_ids) for which the section
3044   -- (p_section_id) is the root section. This will be used later in processing
3045   -- logic
3046   --
3047   l_counter := 1;
3048   l_root_mini_site_ids := JTF_NUMBER_TABLE();
3049   FOR r6 IN c6(p_section_id) LOOP
3050     l_root_mini_site_ids.EXTEND();
3051     l_root_mini_site_ids(l_counter) := r6.msite_id;
3052     l_counter := l_counter + 1;
3053   END LOOP;
3054 
3055   -- Check if p_mini_site_ids is a subset of l_parent_mini_site_ids
3056   -- Check this only if the section is not the master root section
3057   -- If an entry in p_mini_site_ids does not exist in l_parent_mini_site_ids,
3058   -- then it could be possible that that p_mini_site_ids' entry has the
3059   -- root section id as p_section_id. In this case, don't raise an error.
3060   -- If not, then raise an error
3061   IF (p_section_id <> l_master_root_section_id) THEN
3062     FOR i IN 1..p_mini_site_ids.COUNT LOOP
3063 
3064       l_found_flag := FALSE;
3065       FOR j IN 1..l_parent_mini_site_ids.COUNT LOOP
3066         IF (p_mini_site_ids(i) = l_parent_mini_site_ids(j)) THEN
3067           l_found_flag := TRUE;
3068           EXIT;
3069         END IF;
3070       END LOOP; -- loop j
3071 
3072       -- if not found in the list of parent mini-site ids, check if this
3073       -- section (p_section_id) is root section for p_mini_site_ids(i). If yes,
3074       -- then don't raise error. Otherwise do.
3075       IF (NOT l_found_flag) THEN
3076 
3077         FOR k IN 1..l_root_mini_site_ids.COUNT LOOP
3078           IF(p_mini_site_ids(i) = l_root_mini_site_ids(k)) THEN
3079             l_found_flag := TRUE;
3080             EXIT;
3081           END IF;
3082 
3083         END LOOP; -- loop k
3084 
3085       END IF;
3086 
3087       IF (NOT l_found_flag) THEN
3088         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVALID_MSITE_SCT_ASSC');
3089         FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_ids(i));
3090         FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
3091         FND_MSG_PUB.Add;
3092         RAISE FND_API.G_EXC_ERROR;
3093       END IF;
3094 
3095     END LOOP; -- loop i
3096   END IF;
3097 
3098   --
3099   -- Find the old mini-sites to which the p_section_id belongs
3100   --
3101   l_counter := 1;
3102   l_old_mini_site_ids := JTF_NUMBER_TABLE();
3103   FOR r2 IN c2(p_section_id, l_master_mini_site_id) LOOP
3104     l_old_mini_site_ids.EXTEND();
3105     l_old_mini_site_ids(l_counter) := r2.mini_site_id;
3106     l_counter := l_counter + 1;
3107   END LOOP;
3108 
3109   --
3110   -- Find out the mini-sites for which the association should be removed for
3111   -- p_section_id and its descendants
3112   --
3113   FOR i IN 1..l_old_mini_site_ids.COUNT LOOP
3114     l_found_flag := FALSE;
3115     FOR j IN 1..p_mini_site_ids.COUNT LOOP
3116       IF (l_old_mini_site_ids(i) = p_mini_site_ids(j)) THEN
3117         l_found_flag := TRUE;
3118         EXIT;
3119       END IF;
3120     END LOOP; -- j loop
3121 
3122     IF (NOT l_found_flag) THEN
3123       -- l_old_mini_site_ids(i)'s association to be removed from
3124       -- ibe_dsp_msite_sct_sects and ibe_dsp_msite_sct_items
3125 
3126       -- remove from ibe_dsp_msite_sct_items
3127       FOR r3 IN c3(p_section_id, l_old_mini_site_ids(i), l_master_mini_site_id) LOOP
3128         DELETE FROM ibe_dsp_msite_sct_items
3129           WHERE mini_site_section_item_id = r3.mini_site_section_item_id;
3130       END LOOP;
3131 
3132     -- remove from ibe_dsp_msite_sct_sects
3133     --Bug 2684417 (break up into 2 deletes)
3134     DELETE FROM  ibe_dsp_msite_sct_sects
3135            WHERE mini_site_id = l_old_mini_site_ids(i)
3136            AND   child_section_id = p_section_id;
3137 
3138     DELETE FROM  ibe_dsp_msite_sct_sects
3139            WHERE mini_site_id = l_old_mini_site_ids(i)
3140            AND   child_section_id IN
3141                    (SELECT child_section_id
3145                     CONNECT BY prior child_section_id = parent_section_id
3142 			     FROM ibe_dsp_msite_sct_sects
3143                     START WITH parent_section_id = p_section_id
3144 				AND mini_site_id = l_master_mini_site_id
3146                     AND mini_site_id = l_master_mini_site_id);
3147 
3148     END IF;
3149   END LOOP; -- i loop
3150 
3151 
3152   --
3153   -- Add the new entries for the new mini-site ids
3154   --
3155   OPEN c_get_section_hierary_info(p_section_id, l_master_mini_site_id);
3156   FETCH c_get_section_hierary_info INTO l_parent_section_id,
3157     l_start_date_active, l_end_date_active, l_sort_order;
3158   IF c_get_section_hierary_info%NOTFOUND THEN
3159     l_parent_section_id := -1;
3160   END IF;
3161   CLOSE c_get_section_hierary_info;
3162 
3163   FOR i IN 1..p_mini_site_ids.COUNT LOOP
3164 
3165     l_found_flag := FALSE;
3166     FOR j IN 1..l_old_mini_site_ids.COUNT LOOP
3167       IF (p_mini_site_ids(i) = l_old_mini_site_ids(j)) THEN
3168         l_found_flag := TRUE;
3169 	   -- minisite id is linked to the section already
3170 	   -- If so, update the section-msite record if the parent section
3171 	   -- is not set correctly.
3172 	   IF (l_parent_section_id <> -1) AND (l_parent_section_id IS NOT NULL) THEN
3173 	     UPDATE IBE_DSP_MSITE_SCT_SECTS
3174 		   SET parent_section_id = l_parent_section_id,
3175                  start_date_active = l_start_date_active,
3176                  end_date_active = l_end_date_active,
3177 			  sort_order = l_sort_order,
3178 			  last_update_date = SYSDATE,
3179 			  last_updated_by = FND_GLOBAL.user_id
3180 	      WHERE mini_site_id = l_old_mini_site_ids(j)
3181 		   AND child_section_id = p_section_id
3182 		   AND parent_section_id <> l_parent_section_id;
3183 	   END IF;
3184         EXIT;
3185       END IF;
3186     END LOOP; -- loop j
3187 
3188     IF (NOT l_found_flag) THEN
3189       -- new entry found, should add entry for p_section_id and for all
3190       -- its descendants in ibe_dsp_msite_sct_sects and
3191       -- ibe_dsp_msite_sct_items table
3192 
3193       -- add entries in ibe_dsp_msite_sct_sects and ibe_dsp_msite_sct_items
3194       -- table
3195       Associate_Recursive_MSite_Sct
3196         (
3197         p_api_version                    => p_api_version,
3198         p_init_msg_list                  => FND_API.G_FALSE,
3199         p_commit                         => FND_API.G_FALSE,
3200         p_validation_level               => p_validation_level,
3201         p_section_id                     => p_section_id,
3202         p_mini_site_id                   => p_mini_site_ids(i),
3203         p_master_mini_site_id            => l_master_mini_site_id,
3204         x_return_status                  => x_return_status,
3205         x_msg_count                      => x_msg_count,
3206         x_msg_data                       => x_msg_data
3207         );
3208 
3209       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3210         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
3211         FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
3212         FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_ids(i));
3213         FND_MSG_PUB.Add;
3214         RAISE FND_API.G_EXC_ERROR;
3215       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3216         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
3217         FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
3218         FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_ids(i));
3219         FND_MSG_PUB.Add;
3220         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3221       END IF;
3222 
3223     END IF; -- if NOT l_found_flag
3224 
3225   END LOOP; -- loop i
3226 
3227   --
3228   -- End of main API body.
3229 
3230   -- Standard check of p_commit.
3231   IF (FND_API.To_Boolean(p_commit)) THEN
3232     COMMIT WORK;
3233   END IF;
3234 
3235   -- Standard call to get message count and if count is 1, get message info.
3236   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
3237                             p_data    =>      x_msg_data,
3238                             p_encoded =>      'F');
3239 
3240 EXCEPTION
3241 
3242     WHEN FND_API.G_EXC_ERROR THEN
3243       ROLLBACK TO ASSOCIATE_MSITES_TO_SECTION;
3244       x_return_status := FND_API.G_RET_STS_ERROR;
3245       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3246                                 p_data       =>      x_msg_data,
3247                                 p_encoded    =>      'F');
3248 
3249     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3250       ROLLBACK TO ASSOCIATE_MSITES_TO_SECTION;
3251       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3252       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3253                                 p_data       =>      x_msg_data,
3254                                 p_encoded    =>      'F');
3255 
3256     WHEN OTHERS THEN
3257       ROLLBACK TO ASSOCIATE_MSITES_TO_SECTION;
3258       FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
3259       FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
3260       FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
3261       FND_MESSAGE.Set_Token('REASON', SQLERRM);
3262       FND_MSG_PUB.Add;
3263 
3264       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3265 
3266       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3267       THEN
3268         FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3272                                 p_data       =>      x_msg_data,
3269       END IF;
3270 
3271       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3273                                 p_encoded    =>      'F');
3274 
3275 END Associate_MSites_To_Section;
3276 
3277 --
3278 -- Associate p_mini_site_ids with root section p_section_id.
3279 -- Previously associated sections and items for this mini-site will be removed
3280 -- Also all the descendants of p_section_id will have an association with
3281 -- p_mini_site_id (for seciton, if available_in_all_sites_flag is 'Y')
3282 -- This procedure doesn't check if p_section_id is root section id for
3283 -- p_mini_site_id in ibe_msites_b table
3284 --
3285 PROCEDURE Associate_Root_Sct_To_MSite
3286   (
3287    p_api_version                    IN NUMBER,
3288    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
3289    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
3290    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
3291    p_section_id                     IN NUMBER,
3292    p_mini_site_id                   IN NUMBER,
3293    x_return_status                  OUT NOCOPY VARCHAR2,
3294    x_msg_count                      OUT NOCOPY NUMBER,
3295    x_msg_data                       OUT NOCOPY VARCHAR2
3296   )
3297 IS
3298   l_api_name                     CONSTANT VARCHAR2(30) :=
3299     'Associate_Root_Sct_To_MSite';
3300   l_api_version                  CONSTANT NUMBER       := 1.0;
3301   l_msg_count                    NUMBER;
3302   l_msg_data                     VARCHAR2(2000);
3303 
3304   l_master_mini_site_id          NUMBER;
3305   l_master_root_section_id       NUMBER;
3306 
3307 BEGIN
3308 
3309   -- Standard Start of API savepoint
3310   SAVEPOINT  ASSOCIATE_ROOT_SCT_TO_MSITE;
3311 
3312   -- Standard call to check for call compatibility.
3313   IF NOT FND_API.Compatible_API_Call(l_api_version,
3314                                      p_api_version,
3315                                      l_api_name,
3316                                      G_PKG_NAME)
3317   THEN
3318     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3319   END IF;
3320 
3321   -- Initialize message list if p_init_msg_list is set to TRUE.
3322   IF FND_API.to_Boolean(p_init_msg_list) THEN
3323     FND_MSG_PUB.initialize;
3324   END IF;
3325 
3326   -- Initialize API return status to success
3327   x_return_status := FND_API.G_RET_STS_SUCCESS;
3328 
3329   --
3330   -- Get master mini site id for the store
3331   --
3332   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
3333                           x_root_section_id => l_master_root_section_id);
3334 
3335   --
3336   -- Check if the p_mini_site_id is not master mini-site id
3337   --
3338   IF (p_mini_site_id = l_master_mini_site_id) THEN
3339     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVALID_ROOT_SCT_MSITE');
3340     FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_id);
3341     FND_MSG_PUB.Add;
3342     RAISE FND_API.G_EXC_ERROR;
3343   END IF;
3344 
3345   --
3346   -- Remove all the occurrences of p_mini_site_id from ibe_dsp_msite_sct_sects
3347   -- and ibe_dsp_msite_sct_items table
3348   --
3349   DELETE FROM ibe_dsp_msite_sct_sects
3350     WHERE mini_site_id = p_mini_site_id;
3351   IF (sql%NOTFOUND) THEN
3352     -- ok, as there could be no data in ibe_dsp_msite_sct_sects
3353     NULL;
3354   END IF;
3355 
3356   DELETE FROM ibe_dsp_msite_sct_items
3357     WHERE mini_site_id = p_mini_site_id;
3358   IF (sql%NOTFOUND) THEN
3359     -- ok, as there could be no data in ibe_dsp_msite_sct_items
3360     NULL;
3361   END IF;
3362 
3363   -- Associate p_mini_site_id with p_section_id and all its descendants
3364   -- (sections and items). For section, the available_in_all_sites_flag
3365   -- should be 'Y'
3366   Associate_Recursive_MSite_Sct
3367     (
3368     p_api_version                    => p_api_version,
3369     p_init_msg_list                  => FND_API.G_FALSE,
3370     p_commit                         => FND_API.G_FALSE,
3371     p_validation_level               => p_validation_level,
3372     p_section_id                     => p_section_id,
3373     p_mini_site_id                   => p_mini_site_id,
3374     p_master_mini_site_id            => l_master_mini_site_id,
3375     x_return_status                  => x_return_status,
3376     x_msg_count                      => x_msg_count,
3377     x_msg_data                       => x_msg_data
3378     );
3379 
3380   IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3381     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
3382     FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
3383     FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_id);
3384     FND_MSG_PUB.Add;
3385     RAISE FND_API.G_EXC_ERROR;
3386   ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3387     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_RCR_MSITE_SCT_ASC_FAIL');
3388     FND_MESSAGE.Set_Token('SECTION_ID', p_section_id);
3389     FND_MESSAGE.Set_Token('MINI_SITE_ID', p_mini_site_id);
3390     FND_MSG_PUB.Add;
3391     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3392   END IF;
3393 
3394   --
3395   -- End of main API body.
3396 
3397   -- Standard check of p_commit.
3398   IF (FND_API.To_Boolean(p_commit)) THEN
3399     COMMIT WORK;
3400   END IF;
3401 
3402   -- Standard call to get message count and if count is 1, get message info.
3406 
3403   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
3404                             p_data    =>      x_msg_data,
3405                             p_encoded =>      'F');
3407 EXCEPTION
3408 
3409     WHEN FND_API.G_EXC_ERROR THEN
3410       ROLLBACK TO ASSOCIATE_ROOT_SCT_TO_MSITE;
3411       x_return_status := FND_API.G_RET_STS_ERROR;
3412       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3413                                 p_data       =>      x_msg_data,
3414                                 p_encoded    =>      'F');
3415 
3416     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3417       ROLLBACK TO ASSOCIATE_ROOT_SCT_TO_MSITE;
3418       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3419       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3420                                 p_data       =>      x_msg_data,
3421                                 p_encoded    =>      'F');
3422 
3423     WHEN OTHERS THEN
3424       ROLLBACK TO ASSOCIATE_ROOT_SCT_TO_MSITE;
3425       FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
3426       FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
3427       FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
3428       FND_MESSAGE.Set_Token('REASON', SQLERRM);
3429       FND_MSG_PUB.Add;
3430 
3431       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3432 
3433       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3434       THEN
3435         FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3436       END IF;
3437 
3438       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3439                                 p_data       =>      x_msg_data,
3440                                 p_encoded    =>      'F');
3441 
3442 END Associate_Root_Sct_To_MSite;
3443 
3444 PROCEDURE Update_Hierarchy_Item
3445   (
3446    p_api_version                    IN NUMBER,
3447    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
3448    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
3449    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
3450    p_inventory_item_id              IN NUMBER,
3451    p_organization_id                IN NUMBER,
3452    p_last_updated_by                IN NUMBER,
3453    p_last_update_login              IN NUMBER,
3454    p_last_update_date               IN DATE,
3455    p_web_status_type                IN VARCHAR2 := FND_API.G_MISS_CHAR,
3456    p_description                    IN VARCHAR2 := FND_API.G_MISS_CHAR,
3457    p_long_description               IN VARCHAR2 := FND_API.G_MISS_CHAR,
3458    x_return_status                  OUT NOCOPY VARCHAR2,
3459    x_msg_count                      OUT NOCOPY NUMBER,
3460    x_msg_data                       OUT NOCOPY VARCHAR2
3461   )
3462 IS
3463   l_api_name                     CONSTANT VARCHAR2(30) := 'Update_Hierarchy_Item';
3464   l_api_version                  CONSTANT NUMBER       := 1.0;
3465   l_msg_count                    NUMBER;
3466   l_msg_data                     VARCHAR2(2000);
3467 
3468   l_section_id                   NUMBER;
3469   l_parent_section_id            NUMBER;
3470   l_master_mini_site_id          NUMBER;
3471   l_master_root_section_id       NUMBER;
3472   l_in_item_rec                  INV_ITEM_GRP.ITEM_REC_TYPE;
3473   l_out_item_rec                 INV_ITEM_GRP.ITEM_REC_TYPE;
3474   l_out_error_tbl                INV_ITEM_GRP.ERROR_TBL_TYPE;
3475 
3476 BEGIN
3477 
3478   -- Standard Start of API savepoint
3479   SAVEPOINT  UPDATE_HIERARCHY_ITEM_PVT;
3480 
3481   -- Standard call to check for call compatibility.
3482   IF NOT FND_API.Compatible_API_Call(l_api_version,
3483                                      p_api_version,
3484                                      l_api_name,
3485                                      G_PKG_NAME)
3486   THEN
3487     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3488   END IF;
3489 
3490   -- Initialize message list if p_init_msg_list is set to TRUE.
3491   IF FND_API.to_Boolean(p_init_msg_list) THEN
3492     FND_MSG_PUB.initialize;
3493   END IF;
3494 
3495   -- Initialize API return status to success
3496   x_return_status := FND_API.G_RET_STS_SUCCESS;
3497 
3498   --
3499   -- Get inventory item id
3500   --
3501   IF ((p_inventory_item_id IS NULL) OR
3502       (p_inventory_item_id = FND_API.G_MISS_NUM))
3503   THEN
3504     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVALID_INV_ITEM_ID');
3505     FND_MSG_PUB.Add;
3506     RAISE FND_API.G_EXC_ERROR;
3507   END IF;
3508 
3509   --
3510   -- Get organization id
3511   --
3512   IF ((p_organization_id IS NULL) OR
3513       (p_organization_id = FND_API.G_MISS_NUM))
3514   THEN
3515     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVALID_INV_ORG_ID');
3516     FND_MSG_PUB.Add;
3517     RAISE FND_API.G_EXC_ERROR;
3518   END IF;
3519 
3520   --
3521   -- Set the values for inventory to be updated
3522   --
3523   l_in_item_rec.INVENTORY_ITEM_ID := p_inventory_item_id;
3524   l_in_item_rec.ORGANIZATION_ID   := p_organization_id;
3525   l_in_item_rec.LAST_UPDATED_BY   := p_last_updated_by;
3526   l_in_item_rec.LAST_UPDATE_DATE  := p_last_update_date;
3527   l_in_item_rec.LAST_UPDATE_LOGIN := p_last_update_login;
3528   l_in_item_rec.WEB_STATUS        := p_web_status_type;
3529   l_in_item_rec.DESCRIPTION       := p_description;
3530   l_in_item_rec.LONG_DESCRIPTION  := p_long_description;
3531 
3532 
3533   INV_ITEM_GRP.Update_Item
3534     (
3538     p_Item_rec            => l_in_item_rec,
3535     p_commit              => FND_API.G_FALSE,
3536     p_lock_rows           => FND_API.G_TRUE,
3537     p_validation_level    => p_validation_level,
3539     x_Item_rec            => l_out_item_rec,
3540     x_return_status       => x_return_status,
3541     x_Error_tbl           => l_out_error_tbl
3542     );
3543 
3544     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3545 
3546       FOR i IN 1..l_out_error_tbl.count LOOP
3547         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INV_API_ERROR');
3548         FND_MESSAGE.Set_Token('MESSAGE_NAME', l_out_error_tbl(i).MESSAGE_NAME);
3549         FND_MESSAGE.Set_Token('MESSAGE_TEXT', l_out_error_tbl(i).MESSAGE_TEXT);
3550         FND_MESSAGE.Set_Token('TRANSACTION_ID',
3551           l_out_error_tbl(i).TRANSACTION_ID);
3552         FND_MESSAGE.Set_Token('UNIQUE_ID', l_out_error_tbl(i).UNIQUE_ID);
3553         FND_MESSAGE.Set_Token('TABLE_NAME', l_out_error_tbl(i).TABLE_NAME);
3554         FND_MESSAGE.Set_Token('COLUMN_NAME', l_out_error_tbl(i).COLUMN_NAME);
3555         FND_MESSAGE.Set_Token('ORGANIZATION_ID',
3556           l_out_error_tbl(i).ORGANIZATION_ID);
3557         FND_MSG_PUB.Add;
3558       END LOOP;
3559 
3560       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_UPDATE_INV_ITEM_FAIL');
3561       FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_inventory_item_id);
3562       FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_organization_id);
3563       FND_MSG_PUB.Add;
3564       RAISE FND_API.G_EXC_ERROR;
3565     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3566 
3567       FOR i IN 1..l_out_error_tbl.count LOOP
3568         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INV_API_ERROR');
3569         FND_MESSAGE.Set_Token('MESSAGE_NAME', l_out_error_tbl(i).MESSAGE_NAME);
3570         FND_MESSAGE.Set_Token('MESSAGE_TEXT', l_out_error_tbl(i).MESSAGE_TEXT);
3571         FND_MESSAGE.Set_Token('TRANSACTION_ID',
3572           l_out_error_tbl(i).TRANSACTION_ID);
3573         FND_MESSAGE.Set_Token('UNIQUE_ID', l_out_error_tbl(i).UNIQUE_ID);
3574         FND_MESSAGE.Set_Token('TABLE_NAME', l_out_error_tbl(i).TABLE_NAME);
3575         FND_MESSAGE.Set_Token('COLUMN_NAME', l_out_error_tbl(i).COLUMN_NAME);
3576         FND_MESSAGE.Set_Token('ORGANIZATION_ID',
3577           l_out_error_tbl(i).ORGANIZATION_ID);
3578         FND_MSG_PUB.Add;
3579       END LOOP;
3580 
3581       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_UPDATE_INV_ITEM_FAIL');
3582       FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_inventory_item_id);
3583       FND_MESSAGE.Set_Token('ORGANIZATION_ID', p_organization_id);
3584       FND_MSG_PUB.Add;
3585       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3586     END IF;
3587 
3588   --
3589   -- End of main API body.
3590 
3591   -- Standard check of p_commit.
3592   IF (FND_API.To_Boolean(p_commit)) THEN
3593     COMMIT WORK;
3594   END IF;
3595 
3596   -- Standard call to get message count and if count is 1, get message info.
3597   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
3598                             p_data    =>      x_msg_data,
3599                             p_encoded =>      'F');
3600 
3601 EXCEPTION
3602 
3603    WHEN FND_API.G_EXC_ERROR THEN
3604 --     ROLLBACK TO UPDATE_HIERARCHY_ITEM_PVT;
3605      x_return_status := FND_API.G_RET_STS_ERROR;
3606      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3607                                p_data       =>      x_msg_data,
3608                                p_encoded    =>      'F');
3609 
3610    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3611 --     ROLLBACK TO UPDATE_HIERARCHY_ITEM_PVT;
3612      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3613      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3614                                p_data       =>      x_msg_data,
3615                                p_encoded    =>      'F');
3616 
3617    WHEN OTHERS THEN
3618 --     ROLLBACK TO UPDATE_HIERARCHY_ITEM_PVT;
3619      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
3620      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
3621      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
3622      FND_MESSAGE.Set_Token('REASON', SQLERRM);
3623      FND_MSG_PUB.Add;
3624 
3625      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3626 
3627      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3628      THEN
3629        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3630      END IF;
3631 
3632      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3633                                p_data       =>      x_msg_data,
3634                                p_encoded    =>      'F');
3635 
3636 END Update_Hierarchy_Item;
3637 
3638 --
3639 -- Associate p_mini_site_ids with (p_inventory_item_id, p_organization_id).
3640 -- If there are any other mini-sites associated with (p_inventory_item_id,
3641 -- p_organization_id), they will be removed. At the end of this procedure,
3642 -- (p_inventory_item_id, p_organization_id) will be associated with only
3643 -- mini-sites specified in p_mini_site_ids.
3644 --
3645 PROCEDURE Associate_MSites_To_Item
3646   (
3647    p_api_version                    IN NUMBER,
3648    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
3649    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
3650    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
3651    p_inventory_item_id              IN NUMBER,
3652    p_organization_id                IN NUMBER,
3653    p_mini_site_ids                  IN JTF_NUMBER_TABLE,
3657   )
3654    x_return_status                  OUT NOCOPY VARCHAR2,
3655    x_msg_count                      OUT NOCOPY NUMBER,
3656    x_msg_data                       OUT NOCOPY VARCHAR2
3658 IS
3659   l_api_name                     CONSTANT VARCHAR2(30) :=
3660     'Associate_MSites_To_Item';
3661   l_api_version                  CONSTANT NUMBER       := 1.0;
3662   l_msg_count                    NUMBER;
3663   l_msg_data                     VARCHAR2(2000);
3664 
3665   l_found_flag                   BOOLEAN;
3666   l_counter                      NUMBER;
3667   l_row_id                       VARCHAR2(30);
3668   l_master_mini_site_id          NUMBER;
3669   l_master_root_section_id       NUMBER;
3670   l_mini_site_section_section_id NUMBER;
3671   l_mini_site_section_item_id    NUMBER;
3672   l_parent_mini_site_ids         JTF_NUMBER_TABLE;
3673   l_root_mini_site_ids           JTF_NUMBER_TABLE;
3674   l_old_mini_site_ids            JTF_NUMBER_TABLE;
3675 
3676   --
3677   -- Get the mini-sites to which the parent of (l_c_inventory_item_id,
3678   -- organization_id) belongs to and which does not include master mini-site id
3679   --
3680   CURSOR c1(l_c_inventory_item_id IN NUMBER,
3681             l_c_organization_id IN NUMBER,
3682             l_c_mini_site_id IN NUMBER,
3683             l_c_master_mini_site_id IN NUMBER)
3684   IS SELECT section_item_id FROM ibe_dsp_section_items
3685     WHERE inventory_item_id = l_c_inventory_item_id
3686     AND organization_id = l_c_organization_id
3687     AND EXISTS (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
3688                 WHERE child_section_id = section_id
3689                 AND mini_site_id = l_c_mini_site_id
3690                 AND mini_site_id <> l_c_master_mini_site_id);
3691 
3692 BEGIN
3693 
3694   -- Standard Start of API savepoint
3695   SAVEPOINT  ASSOCIATE_MSITES_TO_ITEM_PVT;
3696 
3697   -- Standard call to check for call compatibility.
3698   IF NOT FND_API.Compatible_API_Call(l_api_version,
3699                                      p_api_version,
3700                                      l_api_name,
3701                                      G_PKG_NAME)
3702   THEN
3703     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3704   END IF;
3705 
3706   -- Initialize message list if p_init_msg_list is set to TRUE.
3707   IF FND_API.to_Boolean(p_init_msg_list) THEN
3708     FND_MSG_PUB.initialize;
3709   END IF;
3710 
3711   -- Initialize API return status to success
3712   x_return_status := FND_API.G_RET_STS_SUCCESS;
3713 
3714   --
3715   -- Get master mini site id for the store
3716   --
3717   Get_Master_Mini_Site_Id(x_mini_site_id    => l_master_mini_site_id,
3718                           x_root_section_id => l_master_root_section_id);
3719 
3720 
3721   --
3722   -- Delete all the associations for mini-site and inventory item from
3723   -- ibe_dsp_msite_sct_items table
3724   --
3725   DELETE FROM ibe_dsp_msite_sct_items
3726     WHERE section_item_id IN
3727     (SELECT section_item_id FROM ibe_dsp_section_items
3728      WHERE inventory_item_id = p_inventory_item_id
3729      AND organization_id = p_organization_id);
3730 
3731   IF (sql%NOTFOUND) THEN
3732     -- ok, as there could be no data in ibe_dsp_msite_sct_sects
3733     NULL;
3734   END IF;
3735 
3736   --
3737   -- Make association for each mini-site in p_mini_site_ids to
3738   -- (p_inventory_item_id, p_organization_id)
3739   --
3740   FOR i IN 1..p_mini_site_ids.COUNT LOOP
3741 
3742     FOR r1 in c1(p_inventory_item_id, p_organization_id, p_mini_site_ids(i),
3743                  l_master_mini_site_id) LOOP
3744 
3745       IBE_DSP_MSITE_SCT_ITEM_PVT.Create_MSite_Section_Item
3746         (
3747         p_api_version                    => p_api_version,
3748         p_init_msg_list                  => FND_API.G_FALSE,
3749         p_commit                         => FND_API.G_FALSE,
3750         p_validation_level               => p_validation_level,
3751         p_mini_site_id                   => p_mini_site_ids(i),
3752         p_section_item_id                => r1.section_item_id,
3753         p_start_date_active              => sysdate, --col not used for value
3754         p_end_date_active                => FND_API.G_MISS_DATE,
3755         x_mini_site_section_item_id      => l_mini_site_section_item_id,
3756         x_return_status                  => x_return_status,
3757         x_msg_count                      => x_msg_count,
3758         x_msg_data                       => x_msg_data
3759         );
3760 
3761       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3762         RAISE FND_API.G_EXC_ERROR;
3763       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3764         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3765       END IF;
3766 
3767     END LOOP; -- end r1
3768 
3769   END LOOP; -- for i
3770 
3771   --
3772   -- End of main API body.
3773 
3774   -- Standard check of p_commit.
3775   IF (FND_API.To_Boolean(p_commit)) THEN
3776     COMMIT WORK;
3777   END IF;
3778 
3779   -- Standard call to get message count and if count is 1, get message info.
3780   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
3781                             p_data    =>      x_msg_data,
3782                             p_encoded =>      'F');
3783 
3784 EXCEPTION
3785 
3786     WHEN FND_API.G_EXC_ERROR THEN
3787       ROLLBACK TO ASSOCIATE_MSITES_TO_ITEM_PVT;
3791                                 p_encoded    =>      'F');
3788       x_return_status := FND_API.G_RET_STS_ERROR;
3789       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3790                                 p_data       =>      x_msg_data,
3792 
3793     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3794       ROLLBACK TO ASSOCIATE_MSITES_TO_ITEM_PVT;
3795       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3796       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3797                                 p_data       =>      x_msg_data,
3798                                 p_encoded    =>      'F');
3799 
3800     WHEN OTHERS THEN
3801       ROLLBACK TO ASSOCIATE_MSITES_TO_ITEM_PVT;
3802       FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
3803       FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
3804       FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
3805       FND_MESSAGE.Set_Token('REASON', SQLERRM);
3806       FND_MSG_PUB.Add;
3807 
3808       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3809 
3810       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3811       THEN
3812         FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3813       END IF;
3814 
3815       FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3816                                 p_data       =>      x_msg_data,
3817                                 p_encoded    =>      'F');
3818 
3819 END Associate_MSites_To_Item;
3820 
3821 --
3822 -- This procedure is called when a list of section-section associations is
3823 -- updated or any of the associations is deleted. If any section-section
3824 -- association is deleted, it is equivalent to deleting the child section
3825 -- of the association
3826 --
3827 PROCEDURE Update_Delete_Sct_Scts
3828   (
3829    p_api_version                    IN NUMBER,
3830    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
3831    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
3832    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
3833    p_msite_section_section_ids      IN JTF_NUMBER_TABLE,
3834    p_object_version_numbers         IN JTF_NUMBER_TABLE,
3835    p_start_date_actives             IN JTF_DATE_TABLE,
3836    p_end_date_actives               IN JTF_DATE_TABLE,
3837    p_sort_orders                    IN JTF_NUMBER_TABLE,
3838    p_delete_flags                   IN JTF_VARCHAR2_TABLE_300,
3839    x_return_status                  OUT NOCOPY VARCHAR2,
3840    x_msg_count                      OUT NOCOPY NUMBER,
3841    x_msg_data                       OUT NOCOPY VARCHAR2
3842   )
3843 IS
3844   l_api_name          CONSTANT VARCHAR2(30) := 'Update_Delete_Sct_Scts';
3845   l_api_version       CONSTANT NUMBER       := 1.0;
3846   l_msg_count         NUMBER;
3847   l_msg_data          VARCHAR2(2000);
3848 
3849   l_section_item_id   NUMBER;
3850   l_child_section_id  NUMBER;
3851 
3852   CURSOR c1(l_c_msite_section_section_id IN NUMBER)
3853   IS SELECT child_section_id FROM ibe_dsp_msite_sct_sects
3854     WHERE mini_site_section_section_id = l_c_msite_section_section_id;
3855 
3856 BEGIN
3857 
3858   -- Standard Start of API savepoint
3859   SAVEPOINT  UPDATE_DELETE_SCT_SCTS_PVT;
3860 
3861   -- Standard call to check for call compatibility.
3862   IF NOT FND_API.Compatible_API_Call(l_api_version,
3863                                      p_api_version,
3864                                      l_api_name,
3865                                      G_PKG_NAME)
3866   THEN
3867     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3868   END IF;
3869 
3870   -- Initialize message list if p_init_msg_list is set to TRUE.
3871   IF FND_API.to_Boolean(p_init_msg_list) THEN
3872     FND_MSG_PUB.initialize;
3873   END IF;
3874 
3875   -- Initialize API return status to success
3876   x_return_status := FND_API.G_RET_STS_SUCCESS;
3877 
3878   -- API body
3879   --  CALL FLOW :
3880   -- 1.
3881 
3882   FOR i IN 1..p_msite_section_section_ids.COUNT LOOP
3883 
3884     IF (p_delete_flags(i) = 'Y') THEN
3885 
3886       OPEN c1(p_msite_section_section_ids(i));
3887       FETCH c1 INTO l_child_section_id;
3888       IF (c1%NOTFOUND) THEN
3889         l_child_section_id := NULL;
3890       END IF;
3891       CLOSE c1;
3892 
3893       Delete_Hierarchy_Section
3894         (
3895         p_api_version                    => p_api_version,
3896         p_init_msg_list                  => FND_API.G_FALSE,
3897         p_commit                         => FND_API.G_FALSE,
3898         p_validation_level               => FND_API.G_VALID_LEVEL_FULL,
3899         p_section_id                     => l_child_section_id,
3900         p_access_name                    => FND_API.G_MISS_CHAR,
3901         x_return_status                  => x_return_status,
3902         x_msg_count                      => x_msg_count,
3903         x_msg_data                       => x_msg_data
3904         );
3905 
3906       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3907         RAISE FND_API.G_EXC_ERROR;
3908       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3909         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3910       END IF;
3911 
3912     ELSE
3913 
3914       IBE_DSP_MSITE_SCT_SECT_pvt.Update_Msite_Section_Section
3915         (
3916         p_api_version                    => p_api_version,
3920         p_mini_site_section_section_id   => p_msite_section_section_ids(i),
3917         p_init_msg_list                  => FND_API.G_FALSE,
3918         p_commit                         => FND_API.G_FALSE,
3919         p_validation_level               => p_validation_level,
3921         p_object_version_number          => p_object_version_numbers(i),
3922         p_mini_site_id                   => FND_API.G_MISS_NUM,
3923         p_parent_section_id              => FND_API.G_MISS_NUM,
3924         p_child_section_id               => FND_API.G_MISS_NUM,
3925         p_start_date_active              => p_start_date_actives(i),
3926         p_end_date_active                => p_end_date_actives(i),
3927         p_level_number                   => FND_API.G_MISS_NUM,
3928         p_sort_order                     => p_sort_orders(i),
3929         p_concat_ids                     => FND_API.G_MISS_CHAR,
3930         x_return_status                  => x_return_status,
3931         x_msg_count                      => x_msg_count,
3932         x_msg_data                       => x_msg_data
3933         );
3934 
3935       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
3936         RAISE FND_API.G_EXC_ERROR;
3937       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3938         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3939       END IF;
3940 
3941     END IF;
3942 
3943   END LOOP;
3944 
3945   --
3946   -- End of main API body.
3947 
3948   -- Standard check of p_commit.
3949   IF (FND_API.To_Boolean(p_commit)) THEN
3950     COMMIT WORK;
3951   END IF;
3952 
3953   -- Standard call to get message count and if count is 1, get message info.
3954   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
3955                             p_data    =>      x_msg_data,
3956                             p_encoded =>      'F');
3957 
3958 EXCEPTION
3959 
3960    WHEN FND_API.G_EXC_ERROR THEN
3961      ROLLBACK TO UPDATE_DELETE_SCT_SCTS_PVT;
3962      x_return_status := FND_API.G_RET_STS_ERROR;
3963      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3964                                p_data       =>      x_msg_data,
3965                                p_encoded    =>      'F');
3966 
3967    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3968      ROLLBACK TO UPDATE_DELETE_SCT_SCTS_PVT;
3969      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3970      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3971                                p_data       =>      x_msg_data,
3972                                p_encoded    =>      'F');
3973 
3974    WHEN OTHERS THEN
3975      ROLLBACK TO UPDATE_DELETE_SCT_SCTS_PVT;
3976 
3977      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
3978      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
3979      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
3980      FND_MESSAGE.Set_Token('REASON', SQLERRM);
3981      FND_MSG_PUB.Add;
3982 
3983      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3984 
3985      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3986      THEN
3987        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3988      END IF;
3989 
3990      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
3991                                p_data       =>      x_msg_data,
3992                                p_encoded    =>      'F');
3993 
3994 END Update_Delete_Sct_Scts;
3995 
3996 PROCEDURE Put_Section_Map
3997   (
3998    p_from_section_id                IN NUMBER,
3999    p_to_section_id                  IN NUMBER,
4000    px_section_map_list              IN OUT NOCOPY SECTION_MAP_list,
4001    x_return_status                  OUT NOCOPY VARCHAR2
4002   )
4003 IS
4004   l_api_name                     CONSTANT VARCHAR2(30) :=
4005     'Put_Section_Map';
4006 
4007   l_found                           BOOLEAN;
4008   l_index                           NUMBER;
4009 
4010 BEGIN
4011 
4012   -- Initialize API return status to success
4013   x_return_status := FND_API.G_RET_STS_SUCCESS;
4014 
4015   l_found := FALSE;
4016   FOR i IN 1..px_section_map_list.COUNT LOOP
4017 
4018     IF (px_section_map_list(i).from_section_id = p_from_section_id) THEN
4019       l_found := TRUE;
4020       EXIT;
4021     END IF;
4022 
4023   END LOOP;
4024 
4025   IF (l_found = FALSE) THEN
4026     l_index := px_section_map_list.COUNT + 1;
4027     px_section_map_list.EXTEND();
4028     px_section_map_list(l_index).from_section_id := p_from_section_id;
4029     px_section_map_list(l_index).to_section_id := p_to_section_id;
4030   END IF;
4031 
4032 EXCEPTION
4033 
4034    WHEN OTHERS THEN
4035      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4036      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
4037      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
4038      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
4039      FND_MESSAGE.Set_Token('REASON', SQLERRM);
4040      FND_MSG_PUB.Add;
4041      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4042 
4043 END Put_Section_Map;
4044 
4045 PROCEDURE Get_Section_Map
4046   (
4047    p_section_map_list               IN SECTION_MAP_LIST,
4048    p_from_section_id                IN NUMBER,
4049    x_to_section_id                  OUT NOCOPY NUMBER,
4050    x_return_status                  OUT NOCOPY VARCHAR2
4051   )
4052 IS
4056 
4053   l_api_name                     CONSTANT VARCHAR2(30) :=
4054     'Get_Section_Map';
4055 BEGIN
4057   -- Initialize API return status to error
4058   x_return_status := FND_API.G_RET_STS_ERROR;
4059 
4060   FOR i IN 1..p_section_map_list.COUNT LOOP
4061 
4062     IF (p_section_map_list(i).from_section_id = p_from_section_id) THEN
4063       x_to_section_id := p_section_map_list(i).to_section_id;
4064       x_return_status := FND_API.G_RET_STS_SUCCESS;
4065       EXIT;
4066     END IF;
4067 
4068   END LOOP;
4069 
4070 EXCEPTION
4071 
4072    WHEN OTHERS THEN
4073      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4074      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
4075      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
4076      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
4077      FND_MESSAGE.Set_Token('REASON', SQLERRM);
4078      FND_MSG_PUB.Add;
4079      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4080 
4081 END Get_Section_Map;
4082 
4083 ---
4084 --bug 2942525 (code for PROCEDURE Copy_And_Paste_Section removed on 05/07/2003)
4085 -- use PROCEDURE Copy_Section_Ref_Content instead
4086 --
4087 
4088 --
4089 -- This procedure cuts the source section p_src_section_id and pastes it
4090 -- under the destination section p_dst_parent_section_id. The source and
4091 -- destination section cannot be the same section. Also the destination section
4092 -- cannot be a descendant section of source section. Also the destination
4093 -- section should not have children as items and also cannot be a featured
4094 -- section. After validation, this procedure makes p_dst_parent_section_id
4095 -- as the parent of p_src_section_id. Then for all the descendant sections
4096 -- of p_src_section_id including p_src_section_id, the level_number and
4097 -- concat_ids is updated in table IBE_DSP_MSITE_SCT_SECTS for master mini-site.
4098 -- Lastly, the association of the (p_src_section_id and all it's descendants
4099 -- including sections and section-items) and mini-sites is updated.
4100 --
4101 PROCEDURE Cut_And_Paste_Section
4102   (
4103    p_api_version                    IN NUMBER,
4104    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
4105    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
4106    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
4107    p_src_section_id                 IN NUMBER,
4108    p_dst_parent_section_id          IN NUMBER,
4109    x_return_status                  OUT NOCOPY VARCHAR2,
4110    x_msg_count                      OUT NOCOPY NUMBER,
4111    x_msg_data                       OUT NOCOPY VARCHAR2
4112   )
4113 IS
4114   l_api_name                     CONSTANT VARCHAR2(30) :=
4115     'Cut_And_Paste_Section';
4116   l_api_version                  CONSTANT NUMBER       := 1.0;
4117 
4118   l_master_mini_site_id          NUMBER;
4119   l_master_root_section_id       NUMBER;
4120   l_section_item_id              NUMBER;
4121   l_tmp_id                       NUMBER;
4122   l_level_number                 NUMBER;
4123   l_counter                      NUMBER;
4124   l_mini_site_ids                JTF_NUMBER_TABLE;
4125   l_section_type_code            VARCHAR2(30);
4126   l_concat_ids                   VARCHAR2(2000);
4127 
4128 
4129   -- Get the section type code for the section
4130   CURSOR c1(l_c_section_id IN NUMBER)
4131   IS SELECT section_type_code
4132     FROM ibe_dsp_sections_b
4133     WHERE section_id = l_c_section_id;
4134 
4135   -- Get the section-item-ids for the section
4136   CURSOR c2(l_c_section_id IN NUMBER)
4137   IS SELECT section_item_id
4138     FROM ibe_dsp_section_items
4139     WHERE section_id = l_c_section_id;
4140 
4141   -- Get all the descendant sections including l_c_section_id, starting from
4142   -- l_c_section_id
4143   CURSOR c3(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
4144   IS SELECT parent_section_id, child_section_id FROM ibe_dsp_msite_sct_sects
4145     WHERE mini_site_id = l_c_master_mini_site_id
4146     START WITH child_section_id = l_c_section_id
4147     AND mini_site_id = l_c_master_mini_site_id
4148     CONNECT BY PRIOR child_section_id = parent_section_id
4149     AND PRIOR mini_site_id = l_c_master_mini_site_id
4150     AND mini_site_id = l_c_master_mini_site_id;
4151 
4152   -- Get all the mini-sites associated with the parent of l_c_section_id (from
4153   -- ibe_dsp_msite_sct_sects) and with l_c_section_id (from ibe_msites_b)
4154   -- where l_c_section_id is root section of mini-sites (excluding master
4155   -- mini-site)
4156   CURSOR c4(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
4157   IS SELECT mini_site_id FROM ibe_dsp_msite_sct_sects
4158     WHERE child_section_id =
4159     (SELECT parent_section_id FROM ibe_dsp_msite_sct_sects
4160     WHERE child_section_id = l_c_section_id
4161     AND mini_site_id = l_c_master_mini_site_id)
4162     AND mini_site_id <> l_c_master_mini_site_id
4163     UNION
4164     SELECT msite_id AS mini_site_id FROM ibe_msites_b
4165       WHERE msite_root_section_id = l_c_section_id
4166       AND msite_id <> l_c_master_mini_site_id;
4167 
4168     --
4169     -- Check if l_c_dst_parent_section_id is a descendant of l_c_src_section_id
4170     -- This cursor will return one row if l_c_dst_parent_section_id is a
4171     -- descendant of l_c_src_section_id, otherwise it will return 0 row.
4172     --
4173     CURSOR c5(l_c_src_section_id IN NUMBER,
4174       l_c_dst_parent_section_id IN NUMBER,
4175       l_c_master_mini_site_id IN NUMBER)
4179       START WITH child_section_id = l_c_src_section_id
4176     IS SELECT child_section_id FROM ibe_dsp_msite_sct_sects
4177       WHERE child_section_id = l_c_dst_parent_section_id
4178       AND mini_site_id = l_c_master_mini_site_id
4180       AND mini_site_id = l_c_master_mini_site_id
4181       CONNECT BY PRIOR child_section_id = parent_section_id
4182       AND PRIOR mini_site_id = l_c_master_mini_site_id
4183       AND mini_site_id = l_c_master_mini_site_id;
4184 
4185 BEGIN
4186 
4187   -- Standard Start of API savepoint
4188   SAVEPOINT CUT_AND_PASTE_SECTION_PVT;
4189 
4190   -- Standard call to check for call compatibility.
4191   IF NOT FND_API.Compatible_API_Call(l_api_version,
4192                                      p_api_version,
4193                                      l_api_name,
4194                                      G_PKG_NAME)
4195   THEN
4196     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4197   END IF;
4198 
4199   -- Initialize message list if p_init_msg_list is set to TRUE.
4200   IF FND_API.to_Boolean(p_init_msg_list) THEN
4201     FND_MSG_PUB.initialize;
4202   END IF;
4203 
4204   -- Initialize API return status to success
4205   x_return_status := FND_API.G_RET_STS_SUCCESS;
4206 
4207   --
4208   -- API logic
4209   --
4210 
4211   --
4212   -- Get master mini site id for the store
4213   --
4214   Get_Master_Mini_Site_Id
4215     (
4216     x_mini_site_id    => l_master_mini_site_id,
4217     x_root_section_id => l_master_root_section_id
4218     );
4219 
4220   -- Section to be cut should not be an invalid ID
4221   IF ((p_src_section_id IS NULL) OR
4222       (p_src_section_id <= 0) OR
4223       (p_src_section_id = FND_API.G_MISS_NUM))
4224   THEN
4225     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVLD_CUT_SRC_SCT');
4226     FND_MESSAGE.Set_Token('SRC_SECTION_ID', p_src_section_id);
4227     FND_MSG_PUB.Add;
4228     RAISE FND_API.G_EXC_ERROR;
4229   END IF;
4230 
4231   -- New parent section should not be an invalid ID
4232   IF ((p_dst_parent_section_id IS NULL) OR
4233       (p_dst_parent_section_id <= 0)    OR
4234       (p_dst_parent_section_id = FND_API.G_MISS_NUM))
4235   THEN
4236     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVLD_CUT_DST_SCT');
4237     FND_MESSAGE.Set_Token('DST_PARENT_SECTION_ID', p_dst_parent_section_id);
4238     FND_MSG_PUB.Add;
4239     RAISE FND_API.G_EXC_ERROR;
4240   END IF;
4241 
4242   --
4243   -- p_src_section_id and p_dst_parent_section_id cannot be equal.
4244   -- That is, you cannot cut and paste a section within itself
4245   --
4246   IF (p_src_section_id = p_dst_parent_section_id) THEN
4247     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_CUT_SAME_SCT_FAIL');
4248     FND_MSG_PUB.Add;
4249     RAISE FND_API.G_EXC_ERROR;
4250   END IF;
4251 
4252   --
4253   -- p_dst_parent_section_id cannot be a descendant section of p_src_section_id
4254   --
4255   OPEN c5(p_src_section_id, p_dst_parent_section_id, l_master_mini_site_id);
4256   FETCH c5 INTO l_tmp_id;
4257   IF (c5%FOUND) THEN
4258     CLOSE c5;
4259     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_CUT_DST_SCT_IS_DSC_SCT');
4260     FND_MESSAGE.Set_Token('DST_PARENT_SECTION_ID', p_dst_parent_section_id);
4261     FND_MESSAGE.Set_Token('SRC_SECTION_ID', p_src_section_id);
4262     FND_MSG_PUB.Add;
4263     RAISE FND_API.G_EXC_ERROR;
4264   END IF;
4265   CLOSE c5;
4266 
4267   --
4268   -- Verify if p_dst_parent_section_id section is a navigational section
4269   -- If it's not, then cannot add (or paste) sections under it
4270   OPEN c1(p_dst_parent_section_id);
4271   FETCH c1 INTO l_section_type_code;
4272   IF (c1%NOTFOUND) THEN
4273     CLOSE c1;
4274     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_NO_SCT_ID');
4275     FND_MESSAGE.Set_Token('SECTION_ID', p_dst_parent_section_id);
4276     FND_MSG_PUB.Add;
4277     RAISE FND_API.G_EXC_ERROR;
4278   END IF;
4279   CLOSE c1;
4280 
4281   IF (l_section_type_code <> 'N') THEN
4282     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_PRNT_SCT_NOT_NAV');
4283     FND_MESSAGE.Set_Token('SECTION_ID', p_dst_parent_section_id);
4284     FND_MSG_PUB.Add;
4285     RAISE FND_API.G_EXC_ERROR;
4286   END IF;
4287 
4288   -- Check if the destination parent section (which is navigational) doesn't
4289   -- have children as items. If there are child items for this section, then
4290   -- cannot add child section to it
4291   OPEN c2(p_dst_parent_section_id);
4292   FETCH c2 INTO l_section_item_id;
4293   IF (c2%FOUND) THEN
4294     CLOSE c2;
4295     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_PRNT_SCT_HAS_CHILD_ITM');
4296     FND_MESSAGE.Set_Token('SECTION_ID', p_dst_parent_section_id);
4297     FND_MSG_PUB.Add;
4298     RAISE FND_API.G_EXC_ERROR;
4299   END IF;
4300   CLOSE c2;
4301 
4302   --
4303   -- Make p_dst_parent_section_id parent of p_src_section_id by removing
4304   -- p_src_section_id as a child from its current parent at the same time
4305   --
4306   BEGIN
4307     UPDATE ibe_dsp_msite_sct_sects
4308       SET parent_section_id = p_dst_parent_section_id
4309       WHERE child_section_id = p_src_section_id
4310       AND mini_site_id = l_master_mini_site_id;
4311   EXCEPTION
4312      WHEN OTHERS THEN
4313        FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
4314        FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
4315        FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
4316        FND_MESSAGE.Set_Token('REASON', SQLERRM);
4317        FND_MSG_PUB.Add;
4321   --
4318        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4319   END;
4320 
4322   -- For all the descendant sections of p_src_section_id including
4323   -- p_src_section_id, update the level_number and concat_ids for them
4324   --
4325   FOR r3 IN c3(p_src_section_id, l_master_mini_site_id) LOOP
4326 
4327     BEGIN
4328 
4329       -- Get the concat_ids for the parent of r3.child_section_id
4330       Get_Concat_Ids
4331         (
4332         p_section_id          => r3.parent_section_id,
4333         p_master_mini_site_id => l_master_mini_site_id,
4334         x_concat_ids          => l_concat_ids,
4335         x_level_number        => l_level_number
4336         );
4337 
4338       UPDATE ibe_dsp_msite_sct_sects
4339         SET concat_ids = l_concat_ids,
4340         level_number = l_level_number + 1
4341         WHERE child_section_id = r3.child_section_id
4342         AND mini_site_id = l_master_mini_site_id;
4343 
4344     EXCEPTION
4345        WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4346          FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_GET_CONCAT_IDS_FAIL');
4347          FND_MESSAGE.Set_Token('SECTION_ID', r3.parent_section_id);
4348          FND_MSG_PUB.Add;
4349          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4350 
4351        WHEN OTHERS THEN
4352          FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
4353          FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
4354          FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
4355          FND_MESSAGE.Set_Token('REASON', SQLERRM);
4356          FND_MSG_PUB.Add;
4357          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4358     END;
4359 
4360   END LOOP; -- end loop r3
4361 
4362   --
4363   -- Associate the new set of mini-sites to p_src_section_id and its
4364   -- descendants including section-items. For each of these sections (starting
4365   -- from p_src_section_id), the list of mini-sites associated will be the
4366   -- union of mini-sites to which their respective parent belong and mini-sites
4367   -- to which the current section is the root section (ibe_msites_b). Since
4368   -- the association with start in top-down fashion, the query for c4 will
4369   -- return the updated results as the loop for c3 progresses.
4370   --
4371   -- For each descendant sections of p_src_section_id including
4372   -- p_src_section_id
4373   FOR r33 IN c3(p_src_section_id, l_master_mini_site_id) LOOP
4374 
4375     -- For each mini-site associated with parent of r33.child_section_id
4376     -- and with r33.child_section_id (thru ibe_msites_b)
4377     l_counter := 1;
4378     l_mini_site_ids := JTF_NUMBER_TABLE();
4379     FOR r4 IN c4(r33.child_section_id, l_master_mini_site_id) LOOP
4380       l_mini_site_ids.EXTEND();
4381       l_mini_site_ids(l_counter) := r4.mini_site_id;
4382       l_counter := l_counter + 1;
4383     END LOOP; -- end loop r4
4384 
4385     -- Associate the mini-sites to section, which will recursively associate
4386     -- the mini-sites to all descendant sections and section-items
4387     Associate_MSites_To_Section
4388       (
4389       p_api_version                    => p_api_version,
4390       p_init_msg_list                  => FND_API.G_FALSE,
4391       p_commit                         => FND_API.G_FALSE,
4392       p_validation_level               => p_validation_level,
4393       p_section_id                     => r33.child_section_id,
4394       p_mini_site_ids                  => l_mini_site_ids,
4395       x_return_status                  => x_return_status,
4396       x_msg_count                      => x_msg_count,
4397       x_msg_data                       => x_msg_data
4398       );
4399 
4400     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
4401       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_ASC_MSTS_TO_SCT_FAIL');
4402       FND_MSG_PUB.Add;
4403       RAISE FND_API.G_EXC_ERROR;
4404     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4405       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_ASC_MSTS_TO_SCT_FAIL');
4406       FND_MSG_PUB.Add;
4407       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4408     END IF;
4409 
4410   END LOOP; -- end loop r33
4411 
4412   -- Standard check of p_commit.
4413   IF (FND_API.To_Boolean(p_commit)) THEN
4414     COMMIT WORK;
4415   END IF;
4416 
4417   -- Standard call to get message count and if count is 1, get message info.
4418   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
4419                             p_data    =>      x_msg_data,
4420                             p_encoded =>      'F');
4421 
4422 EXCEPTION
4423 
4424    WHEN FND_API.G_EXC_ERROR THEN
4425      ROLLBACK TO CUT_AND_PASTE_SECTION_PVT;
4426      x_return_status := FND_API.G_RET_STS_ERROR;
4427      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
4428                                p_data       =>      x_msg_data,
4429                                p_encoded    =>      'F');
4430 
4431    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4432      ROLLBACK TO CUT_AND_PASTE_SECTION_PVT;
4433      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4434      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
4435                                p_data       =>      x_msg_data,
4436                                p_encoded    =>      'F');
4437 
4438    WHEN OTHERS THEN
4439      ROLLBACK TO CUT_AND_PASTE_SECTION_PVT;
4440      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
4441      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
4445      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4442      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
4443      FND_MESSAGE.Set_Token('REASON', SQLERRM);
4444      FND_MSG_PUB.Add;
4446 
4447      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4448      THEN
4449        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4450      END IF;
4451 
4452      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
4453                                p_data       =>      x_msg_data,
4454                                p_encoded    =>      'F');
4455 
4456 END Cut_And_Paste_Section;
4457 
4458 
4459 PROCEDURE Batch_Duplicate_Section(
4460 	    errbuf	OUT NOCOPY VARCHAR2,
4461 	    retcode OUT NOCOPY NUMBER,
4462 		p_source_section_id IN VARCHAR2,
4463 		p_dest_parent_section_id IN VARCHAR2,
4464 		p_new_sect_display_name IN VARCHAR2 ,
4465 		p_enable_trace  IN  VARCHAR2
4466 		)
4467 IS
4468 	x_return_status		VARCHAR2(1000);
4469 	x_msg_count		NUMBER;
4470 	x_msg_data		VARCHAR2(1000);
4471     x_new_src_section_id NUMBER;
4472 BEGIN
4473 
4474 	if  p_enable_trace = 'Y'  then
4475 		G_ENABLE_TRACE := 'Y';
4476 	end if;
4477     IF G_ENABLE_TRACE = 'Y' then
4478        fnd_file.put_line(fnd_file.log,'Calling copy_section_ref_content ');
4479        fnd_file.put_line(fnd_file.log,'section id:'||p_source_section_id);
4480        fnd_file.put_line(fnd_file.log,'dest section id:'||p_dest_parent_section_id);
4481     END IF;
4482 
4483 	copy_section_ref_content (
4484 		p_api_version   =>1.0,
4485 		p_init_msg_list =>FND_API.G_FALSE,
4486 		p_commit  => FND_API.G_FALSE,
4487 		p_validation_level => FND_API.G_VALID_LEVEL_FULL,
4488 		p_src_section_id   => to_number(p_source_section_id),
4489 		p_dst_parent_section_id => to_number(p_dest_parent_section_id),
4490 		x_new_src_section_id =>  x_new_src_section_id,
4491 		x_return_status  => x_return_status,
4492 		x_msg_count  => x_msg_count,
4493 		x_msg_data   => x_msg_data,
4494 		p_new_display_name => p_new_sect_display_name);
4495 
4496         if (x_return_status = FND_API.G_RET_STS_SUCCESS) then
4497           retcode := 0;
4498           errbuf := 'SUCCESS';
4499        else
4500             retcode := -1;
4501             errbuf := x_msg_data;
4502        end if;
4503      IF G_ENABLE_TRACE = 'Y' then
4504        fnd_file.put_line(fnd_file.log,'After Calling copy_section_ref_content ');
4505        fnd_file.put_line(fnd_file.log,'return Code:'||retcode);
4506        fnd_file.put_line(fnd_file.log,'Return Status:'||errbuf);
4507     END IF;
4508 END batch_duplicate_section;
4509 
4510 
4511 
4512 
4513 -- added by abhandar  apr-25-2002--
4514 --This procedure copies the section p_src_section_id under the section
4515 --p_dst_parent_section_id and references the content. It validates the ID's passed in for the
4516 --sections. The procedure first copies the p_src_section_id, references the content
4517 --,and then all its descendant sections are copied along with reference to the respective contents.
4518 --To do this, it uses the Create_Hierarchy_Section and the  Reference_Section_Content
4519 --APIs of this package. Also the mapping between old section ID and new section
4520 --ID is created to facilitate the logic. After the sections, all the
4521 --section-items are copied (using Associate_Items_To_Section API)
4522 --
4523 ---------------------------------------------------------------------------------------------
4524 ---------------------------------------------------------------------------------------------
4525 PROCEDURE Copy_Section_Ref_Content
4526   (
4527    p_api_version                    IN NUMBER,
4528    p_init_msg_list                  IN VARCHAR2 := FND_API.G_FALSE,
4529    p_commit                         IN VARCHAR2 := FND_API.G_FALSE,
4530    p_validation_level               IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
4531    p_src_section_id                 IN NUMBER,
4532    p_dst_parent_section_id          IN NUMBER,
4533    x_new_src_section_id             OUT NOCOPY NUMBER,
4534    x_return_status                  OUT NOCOPY VARCHAR2,
4535    x_msg_count                      OUT NOCOPY NUMBER,
4536    x_msg_data                       OUT NOCOPY VARCHAR2,
4537    p_new_display_name               IN VARCHAR2 := NULL
4538   )
4539 IS
4540   l_api_name                     CONSTANT VARCHAR2(30) :=
4541     'Copy_Section_Ref_Content';
4542   l_api_version                  CONSTANT NUMBER       := 1.0;
4543 
4544   l_master_mini_site_id          NUMBER;
4545   l_master_root_section_id       NUMBER;
4546   l_section_id                   NUMBER;
4547   l_parent_section_id            NUMBER;
4548   l_found                        BOOLEAN;
4549   l_section_map_list             SECTION_MAP_LIST;
4550   l_section_item_ids             JTF_NUMBER_TABLE;
4551   l_inventory_item_ids           JTF_NUMBER_TABLE;
4552   l_organization_ids             JTF_NUMBER_TABLE;
4553   l_start_date_actives           JTF_DATE_TABLE;
4554   l_end_date_actives             JTF_DATE_TABLE;
4555   l_sort_orders                  JTF_NUMBER_TABLE;
4556   l_association_reason_codes     JTF_VARCHAR2_TABLE_300;
4557   l_duplicate_association_status VARCHAR2(1);
4558   --bug 3303424
4559   l_count_langs                  NUMBER;
4560   l_debug                        VARCHAR2(1);
4561   -- Get the detail information of the section l_c_section_id
4562   CURSOR c1(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
4563   IS SELECT S.access_name, S.start_date_active, S.end_date_active,
4564     S.section_type_code, S.status_code, S.display_context_id, S.deliverable_id,
4568     S.attribute4, S.attribute5, S.attribute6, S.attribute7, S.attribute8,
4565     S.available_in_all_sites_flag, S.auto_placement_rule, S.order_by_clause,
4566     S.display_name, S.description, S.long_description, S.keywords,
4567     S.attribute_category, S.attribute1, S.attribute2, S.attribute3,
4569     S.attribute9, S.attribute10, S.attribute11, S.attribute12, S.attribute13,
4570     S.attribute14, S.attribute15, MSS.sort_order
4571     FROM ibe_dsp_sections_vl S, ibe_dsp_msite_sct_sects MSS
4572     WHERE S.section_id = l_c_section_id
4573     AND MSS.child_section_id = S.section_id
4574     AND MSS.mini_site_id = l_c_master_mini_site_id;
4575 
4576   -- Get the detail information of all descendants of l_c_section_id
4577   -- Need to do order by level_number so that the parents entries are returned
4578   -- before the children.
4579   CURSOR c2(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
4580   IS SELECT S.section_id, S.access_name, S.start_date_active,
4581     S.end_date_active, S.section_type_code, S.status_code,
4582     S.display_context_id, S.deliverable_id,
4583     S.available_in_all_sites_flag, S.auto_placement_rule, S.order_by_clause,
4584     S.display_name, S.description, S.long_description, S.keywords,
4585     S.attribute_category, S.attribute1, S.attribute2, S.attribute3,
4586     S.attribute4, S.attribute5, S.attribute6, S.attribute7, S.attribute8,
4587     S.attribute9, S.attribute10, S.attribute11, S.attribute12, S.attribute13,
4588     S.attribute14, S.attribute15, MSS.sort_order, MSS.parent_section_id
4589     FROM ibe_dsp_sections_vl S, ibe_dsp_msite_sct_sects MSS
4590     WHERE S.section_id = MSS.child_section_id
4591     AND MSS.mini_site_id = l_c_master_mini_site_id
4592     AND S.section_id IN
4593     (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
4594     WHERE mini_site_id = l_c_master_mini_site_id
4595     START WITH parent_section_id = l_c_section_id
4596     AND mini_site_id = l_c_master_mini_site_id
4597     CONNECT BY PRIOR child_section_id = parent_section_id
4598     AND mini_site_id = l_c_master_mini_site_id)
4599     ORDER BY MSS.level_number;
4600 
4601   --
4602   -- Get all the section-items which are descendants of l_c_section_id
4603   --
4604   CURSOR c3(l_c_section_id IN NUMBER, l_c_master_mini_site_id IN NUMBER)
4605   IS SELECT section_item_id, section_id, inventory_item_id, organization_id,
4606     start_date_active, end_date_active, sort_order, association_reason_code
4607     FROM ibe_dsp_section_items
4608     WHERE section_id = l_c_section_id
4609     OR section_id IN
4610     (SELECT child_section_id FROM ibe_dsp_msite_sct_sects
4611     WHERE mini_site_id = l_c_master_mini_site_id
4612     START WITH parent_section_id = l_c_section_id
4613     AND mini_site_id = l_c_master_mini_site_id
4614     CONNECT BY PRIOR child_section_id = parent_section_id
4615     AND mini_site_id = l_c_master_mini_site_id);
4616 
4617    -- Cursor to get the translated rows of the section  from ibe_Dsp_sections_tl table
4618   --bug 3303424
4619   CURSOR c4(l_c_section_id IN NUMBER)
4620   IS SELECT language,source_lang,display_name,description,long_description,keywords
4621   from ibe_dsp_sections_tl where section_id=l_c_section_id;
4622 
4623 BEGIN
4624 
4625     -- Standard Start of API savepoint
4626   SAVEPOINT COPY_SECTION_REF_CONTENT_PVT;
4627 l_debug  := NVL(FND_PROFILE.VALUE('IBE_DEBUG'),'N');
4628   -- Standard call to check for call compatibility.
4629   IF NOT FND_API.Compatible_API_Call(l_api_version,
4630                                      p_api_version,
4631                                      l_api_name,
4632                                      G_PKG_NAME)
4633   THEN
4634     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4635   END IF;
4636 
4637   -- Initialize message list if p_init_msg_list is set to TRUE.
4638   IF FND_API.to_Boolean(p_init_msg_list) THEN
4639     FND_MSG_PUB.initialize;
4640   END IF;
4641 
4642   -- Initialize API return status to success
4643   x_return_status := FND_API.G_RET_STS_SUCCESS;
4644 
4645   --
4646   -- API logic
4647   --
4648 
4649   --
4650   -- Get master mini site id for the store
4651   --
4652   Get_Master_Mini_Site_Id
4653     (
4654     x_mini_site_id    => l_master_mini_site_id,
4655     x_root_section_id => l_master_root_section_id
4656     );
4657 
4658   -- Section to be copied should not be an invalid ID
4659   IF ((p_src_section_id IS NULL) OR
4660       (p_src_section_id <= 0) OR
4661       (p_src_section_id = FND_API.G_MISS_NUM))
4662   THEN
4663 	if G_ENABLE_TRACE = 'Y' then
4664 		fnd_file.put_line(fnd_file.log,'Invalid duplicate source section');
4665   else
4666 		FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVLD_COPY_SRC_SCT');
4667 	   	FND_MESSAGE.Set_Token('SRC_SECTION_ID', p_src_section_id);
4668     	FND_MSG_PUB.Add;
4669 	end if;
4670     RAISE FND_API.G_EXC_ERROR;
4671   END IF;
4672 
4673   -- New parent section should not be an invalid ID
4674   IF ((p_dst_parent_section_id IS NULL) OR
4675       (p_dst_parent_section_id <= 0)    OR
4676       (p_dst_parent_section_id = FND_API.G_MISS_NUM))
4677   THEN
4678 
4679 
4680 	if G_ENABLE_TRACE = 'Y' then
4681 		fnd_file.put_line(fnd_file.log,'Invalid duplicate source section');
4682 	  else
4683     	FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_INVLD_COPY_DST_SCT');
4684     	FND_MESSAGE.Set_Token('DST_PARENT_SECTION_ID', p_dst_parent_section_id);
4685     	FND_MSG_PUB.Add;
4686 
4687 	end if;
4688     RAISE FND_API.G_EXC_ERROR;
4689   END IF;
4690 
4691   --
4695 
4692   -- Initialize the table of record which stores the section mappings
4693   --
4694   l_section_map_list := SECTION_MAP_LIST();
4696   --
4697   -- Copy the p_src_section_id first
4698   -- Get the detail information of the p_src_section_id and call the API
4699   -- to create similar new section as a child of p_dst_section_id
4700   -- The for loop will only loop once. For loop is used in place of
4701   -- open/ftech/close because need to get all the columns without creating
4702   -- a record for them
4703   --
4704   l_found := FALSE;
4705   --bug 3303424
4706   select count(*)into l_count_langs from fnd_languages where installed_flag in ('I','B');
4707 
4708   FOR r1 IN c1(p_src_section_id, l_master_mini_site_id) LOOP
4709     l_found := TRUE;
4710    IF (l_debug = 'Y') THEN
4711    IBE_UTIL.debug('Calling Create_Hierarchy_Section for immediate section ');
4712 
4713    IBE_UTIL.debug('parent section id:'||p_dst_parent_section_id);
4714   END IF;
4715    IF (G_ENABLE_TRACE= 'Y') THEN
4716    fnd_file.put_line(fnd_file.log,'Calling Create_Hierarchy_Section for immediate section ');
4717 
4718    fnd_file.put_line(fnd_file.log,'parent section id:'||p_dst_parent_section_id);
4719   END IF;
4720 
4721     Create_Hierarchy_Section
4722       (
4723       p_api_version                    => p_api_version,
4724       p_init_msg_list                  => FND_API.G_FALSE,
4725       p_commit                         => FND_API.G_FALSE,
4726       p_validation_level               => p_validation_level,
4727       p_parent_section_id              => p_dst_parent_section_id,
4728       p_parent_section_access_name     => FND_API.G_MISS_CHAR,
4729       p_access_name                    => FND_API.G_MISS_CHAR,
4730       p_start_date_active              => r1.start_date_active,
4731       p_end_date_active                => r1.end_date_active,
4732       p_section_type_code              => r1.section_type_code,
4733       p_status_code                    => r1.status_code,
4734       p_display_context_id             => r1.display_context_id,
4735       p_deliverable_id                 => r1.deliverable_id,
4736       p_available_in_all_sites_flag    => r1.available_in_all_sites_flag,
4737       p_auto_placement_rule            => r1.auto_placement_rule,
4738       p_order_by_clause                => r1.order_by_clause,
4739       p_sort_order                     => r1.sort_order,
4740       p_display_name                   => r1.display_name,
4741       p_description                    => r1.description,
4742       p_long_description               => r1.long_description,
4743       p_keywords                       => r1.keywords,
4744       p_attribute_category             => r1.attribute_category,
4745       p_attribute1                     => r1.attribute1,
4746       p_attribute2                     => r1.attribute2,
4747       p_attribute3                     => r1.attribute3,
4748       p_attribute4                     => r1.attribute4,
4749       p_attribute5                     => r1.attribute5,
4750       p_attribute6                     => r1.attribute6,
4751       p_attribute7                     => r1.attribute7,
4752       p_attribute8                     => r1.attribute8,
4753       p_attribute9                     => r1.attribute9,
4754       p_attribute10                    => r1.attribute10,
4755       p_attribute11                    => r1.attribute11,
4756       p_attribute12                    => r1.attribute12,
4757       p_attribute13                    => r1.attribute13,
4758       p_attribute14                    => r1.attribute14,
4759       p_attribute15                    => r1.attribute15,
4760 	  p_inherit_layout                 => FND_API.G_FALSE,
4761       x_section_id                     => x_new_src_section_id,
4762       x_return_status                  => x_return_status,
4763       x_msg_count                      => x_msg_count,
4764       x_msg_data                       => x_msg_data
4765       );
4766     IF (l_debug = 'Y') THEN
4767    IBE_UTIL.debug('After Calling Create_Hierarchy_Section for immediate section ');
4768    IBE_UTIL.debug('new section id:'||x_new_src_section_id);
4769 
4770   END IF;
4771    IF (G_ENABLE_TRACE= 'Y') THEN
4772    fnd_file.put_line(fnd_file.log,'After Calling Create_Hierarchy_Section for immediate section ');
4773    fnd_file.put_line(fnd_file.log,'new section id:'||x_new_src_section_id);
4774 
4775   END IF;
4776     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
4777 		if G_ENABLE_TRACE = 'Y' then
4778 			fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Create_Hierarchy_Section');
4779 
4780 		else
4781       		FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_CRT_HIER_SCT_FAIL');
4782       		FND_MSG_PUB.Add;
4783 
4784         end if;
4785       RAISE FND_API.G_EXC_ERROR;
4786     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4787     if G_ENABLE_TRACE = 'Y' then
4788        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Create_Hierarchy_Section');
4789 	else
4790       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_CRT_HIER_SCT_FAIL');
4791       FND_MSG_PUB.Add;
4792 
4793       end if;
4794       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4795     END IF;
4796 
4797 
4798   ---------------------------------------------------
4799  -- customer bug 3303424:
4800  -- update the ibe_dsp_section_tl table  of the duplicated section
4801  -- with the display name, shortdesc, longdesc and keywords of the source section.
4802  -- except for the session lang row
4803 -- customer bug 3303424:
4804 
4808          display_name= r4.display_name,
4805  if ( l_count_langs >1)then -- if more than one lang installed
4806    FOR r4 IN c4(p_src_section_id) LOOP
4807      update ibe_dsp_sections_tl set
4809          description = r4.description,
4810          long_description = r4.long_description,
4811          keywords= r4.keywords,
4812          source_lang = r4.source_lang
4813       where language=r4.language and section_id=x_new_src_section_id
4814       and language <>userenv('lang');
4815    END LOOP;
4816 end if;
4817 
4818 -- modify the display name for the sesion language.
4819 if  p_new_display_name is not null then
4820        update ibe_dsp_sections_tl
4821        set display_name = p_new_display_name
4822        where section_id = x_new_src_section_id
4823        and language= userenv('lang');
4824     end if;
4825 
4826  /*
4827    FOR r4 IN c4(p_src_section_id) LOOP
4828 
4829      IF p_new_display_name=r1.display_name  and l_count_langs >1 then
4830       -- if  multiple lang installed and the input display name for the duplicated section
4831       -- is same  as the src section display name then update the translated rows from src section
4832       -- except for the session lang row.
4833 
4834         update ibe_dsp_sections_tl set
4835          display_name = r4.display_name,
4836          description = r4.description,
4837          long_description = r4.long_description,
4838          keywords= r4.keywords,
4839          source_lang=r4.source_lang
4840          where language=r4.language
4841          and section_id=x_new_src_section_id
4842          and language <> userenv('lang');
4843 
4844     ELSIF p_new_display_name is not null and p_new_display_name <> r1.display_name then
4845 
4846     -- if new display name is not same as the src section name then
4847     -- update the duplicated section display name with the new display name
4848     -- for all rows, keeping the source_lang column same as the userenv(lang).
4849 
4850          update ibe_dsp_sections_tl set
4851          display_name = p_new_display_name,
4852          description = r4.description,
4853          long_description = r4.long_description,
4854          keywords= r4.keywords
4855          where language=r4.language
4856          and section_id=x_new_src_section_id;
4857     END IF;
4858   END LOOP;
4859 */
4860 
4861  -----------------------------------------------------------------
4862   ---------  Reference content for the copied  section
4863  -----------------------------------------------------------------
4864   IF (l_debug = 'Y') THEN
4865    IBE_UTIL.debug('Calling Reference_Section_Content ,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id);
4866 
4867 
4868   END IF;
4869    IF (G_ENABLE_TRACE= 'Y') THEN
4870    fnd_file.put_line(fnd_file.log,'Calling Reference_Section_Content,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id );
4871 
4872   END IF;
4873     Reference_Section_Content(
4874        p_old_section_id                 =>p_src_section_id,
4875        p_new_section_id                 =>x_new_src_section_id,
4876        x_return_status                  =>x_return_status,
4877        x_msg_count                      =>x_msg_count,
4878        x_msg_data                       =>x_msg_data);
4879 
4880     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
4881      if G_ENABLE_TRACE = 'Y' then
4882        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Reference_Section_Content');
4883 	 end if;
4884       RAISE FND_API.G_EXC_ERROR;
4885     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4886      if G_ENABLE_TRACE = 'Y' then
4887        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Reference_Section_Content');
4888 	 end if;
4889       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4890     END IF;
4891   IF (l_debug = 'Y') THEN
4892    IBE_UTIL.debug('Calling Put_Section_Map ,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id);
4893 
4894 
4895   END IF;
4896    IF (G_ENABLE_TRACE= 'Y') THEN
4897    fnd_file.put_line(fnd_file.log,'Calling Put_Section_Map,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id );
4898 
4899   END IF;
4900 
4901     Put_Section_Map
4902       (
4903       p_from_section_id                => p_src_section_id,
4904       p_to_section_id                  => x_new_src_section_id,
4905       px_section_map_list              => l_section_map_list,
4906       x_return_status                  => x_return_status
4907       );
4908 
4909     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
4910     if G_ENABLE_TRACE = 'Y' then
4911        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Put_Section_Map, with IBE_DSP_SCT_MAP_INSERT_FAIL error');
4912 	 end if;
4913       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_INSERT_FAIL');
4914       FND_MESSAGE.Set_Token('FROM_SECTION_ID', p_src_section_id);
4915       FND_MESSAGE.Set_Token('TO_SECTION_ID', x_new_src_section_id);
4916       FND_MSG_PUB.Add;
4917       RAISE FND_API.G_EXC_ERROR;
4918     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4919       if G_ENABLE_TRACE = 'Y' then
4920        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Put_Section_Map, with IBE_DSP_SCT_MAP_INSERT_FAIL error');
4921 	 end if;
4922       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_INSERT_FAIL');
4923       FND_MESSAGE.Set_Token('FROM_SECTION_ID', p_src_section_id);
4927     END IF;
4924       FND_MESSAGE.Set_Token('TO_SECTION_ID', x_new_src_section_id);
4925       FND_MSG_PUB.Add;
4926       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4928 
4929     -- 11.5.10, Copy layout component mapping during section  duplication
4930     -- including center display template
4931   IF (l_debug = 'Y') THEN
4932    IBE_UTIL.debug('Calling Copy_Layout_Comp_Mapping ,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id);
4933 
4934 
4935   END IF;
4936    IF (G_ENABLE_TRACE= 'Y') THEN
4937    fnd_file.put_line(fnd_file.log,'Calling Copy_Layout_Comp_Mapping,copying from p_src_section :'||p_src_section_id ||'to x_new_section_id:'||x_new_src_section_id );
4938 
4939   END IF;
4940     Copy_Layout_Comp_Mapping(
4941       p_api_version => 1.0,
4942 	 p_init_msg_list => FND_API.G_FALSE,
4943 	 p_commit => FND_API.G_FALSE,
4944 	 p_source_section_id => p_src_section_id,
4945 	 p_target_section_id => x_new_src_section_id,
4946 	 p_include_all => FND_API.G_TRUE,
4947 	 x_return_status => x_return_status,
4948 	 x_msg_count => x_msg_count,
4949 	 x_msg_data => x_msg_data);
4950     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
4951      if G_ENABLE_TRACE = 'Y' then
4952        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Copy_Layout_Comp_Mapping');
4953 	 end if;
4954 	 RAISE FND_API.G_EXC_ERROR;
4955     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4956       if G_ENABLE_TRACE = 'Y' then
4957        fnd_file.put_line(fnd_file.log,'get RET_STS_UNEXP_ERROR in Copy_Layout_Comp_Mapping');
4958 	 end if;
4959       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4960     END IF;
4961 
4962 
4963     EXIT;
4964    -- adding commit 11/20/03 ab :to avoid time out in case large number of sections duplicated
4965    COMMIT;
4966   END LOOP; -- end for r1 in c1
4967 
4968   IF (l_found = FALSE) THEN
4969        if G_ENABLE_TRACE = 'Y' then
4970        fnd_file.put_line(fnd_file.log,'get G_IBE_DSP_COPY_SRC_SCT_NOT_FOUND error');
4971 	 end if;
4972     FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_COPY_SRC_SCT_NOT_FOUND');
4973     FND_MESSAGE.Set_Token('SRC_SECTION_ID', p_src_section_id);
4974     FND_MSG_PUB.Add;
4975     RAISE FND_API.G_EXC_ERROR;
4976   END IF;
4977 
4978   --
4979   -- Copy all the descendants of p_src_section_id
4980   -- Get the detail information of the descendants of p_src_section_id
4981   -- and call the API to create similar new section
4982   --
4983   FOR r2 IN c2(p_src_section_id, l_master_mini_site_id) LOOP
4984 
4985     IF (r2.section_id = x_new_src_section_id) THEN
4986       -- do nothing. This might happen when p_src_section_id = p_dst_section_id
4987       -- In that case, don't want to re-copy the same section
4988       NULL;
4989     ELSE
4990 
4991       Get_Section_Map
4992         (
4993         p_section_map_list               => l_section_map_list,
4994         p_from_section_id                => r2.parent_section_id,
4995         x_to_section_id                  => l_parent_section_id,
4996         x_return_status                  => x_return_status
4997         );
4998 
4999       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5000       if G_ENABLE_TRACE = 'Y' then
5001        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR error in Get_Section_Map for descendants of parent section ');
5002 	    fnd_file.put_line(fnd_file.log,'get IBE_DSP_SCT_MAP_GET_FAIL error in Get_Section_Map for descendants of parent section ');
5003       end if;
5004         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_GET_FAIL');
5005         FND_MESSAGE.Set_Token('FROM_SECTION_ID', r2.parent_section_id);
5006         FND_MSG_PUB.Add;
5007         RAISE FND_API.G_EXC_ERROR;
5008       ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5009       if G_ENABLE_TRACE = 'Y' then
5010         fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR error in Get_Section_Map for descendants of parent section ');
5011 	    fnd_file.put_line(fnd_file.log,'get IBE_DSP_SCT_MAP_GET_FAIL error in Get_Section_Map for descendants of parent section ');
5012       end if;
5013         FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_GET_FAIL');
5014         FND_MESSAGE.Set_Token('FROM_SECTION_ID', r2.parent_section_id);
5015         FND_MSG_PUB.Add;
5016         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5017       END IF;
5018    IF (l_debug = 'Y') THEN
5019    IBE_UTIL.debug('Calling Create_Hierarchy_Section for immediate section ');
5020    IBE_UTIL.debug('section id:'||l_parent_section_id);
5021 
5022   END IF;
5023    IF (G_ENABLE_TRACE= 'Y') THEN
5024    fnd_file.put_line(fnd_file.log,'Calling Create_Hierarchy_Section for immediate section ');
5025    fnd_file.put_line(fnd_file.log,'section id:'||l_parent_section_id);
5026 
5027   END IF;
5028       Create_Hierarchy_Section
5029         (
5030         p_api_version                    => p_api_version,
5031         p_init_msg_list                  => FND_API.G_FALSE,
5032         p_commit                         => FND_API.G_FALSE,
5033         p_validation_level               => p_validation_level,
5034         p_parent_section_id              => l_parent_section_id,
5035         p_parent_section_access_name     => FND_API.G_MISS_CHAR,
5036         p_access_name                    => FND_API.G_MISS_CHAR,
5037         p_start_date_active              => r2.start_date_active,
5038         p_end_date_active                => r2.end_date_active,
5039         p_section_type_code              => r2.section_type_code,
5043         p_available_in_all_sites_flag    => r2.available_in_all_sites_flag,
5040         p_status_code                    => r2.status_code,
5041         p_display_context_id             => r2.display_context_id,
5042         p_deliverable_id                 => r2.deliverable_id,
5044         p_auto_placement_rule            => r2.auto_placement_rule,
5045         p_order_by_clause                => r2.order_by_clause,
5046         p_sort_order                     => r2.sort_order,
5047         p_display_name                   => r2.display_name,
5048         p_description                    => r2.description,
5049         p_long_description               => r2.long_description,
5050         p_keywords                       => r2.keywords,
5051         p_attribute_category             => r2.attribute_category,
5052         p_attribute1                     => r2.attribute1,
5053         p_attribute2                     => r2.attribute2,
5054         p_attribute3                     => r2.attribute3,
5055         p_attribute4                     => r2.attribute4,
5056         p_attribute5                     => r2.attribute5,
5057         p_attribute6                     => r2.attribute6,
5058         p_attribute7                     => r2.attribute7,
5059         p_attribute8                     => r2.attribute8,
5060         p_attribute9                     => r2.attribute9,
5061         p_attribute10                    => r2.attribute10,
5062         p_attribute11                    => r2.attribute11,
5063         p_attribute12                    => r2.attribute12,
5064         p_attribute13                    => r2.attribute13,
5065         p_attribute14                    => r2.attribute14,
5066         p_attribute15                    => r2.attribute15,
5067 	   p_inherit_layout                 => FND_API.G_FALSE,
5068         x_section_id                     => l_section_id,
5069         x_return_status                  => x_return_status,
5070         x_msg_count                      => x_msg_count,
5071         x_msg_data                       => x_msg_data
5072         );
5073     END IF;
5074    IF (l_debug = 'Y') THEN
5075    IBE_UTIL.debug('After Calling Create_Hierarchy_Section for immediate section ');
5076    IBE_UTIL.debug('new section id:'||l_section_id);
5077 
5078   END IF;
5079    IF (G_ENABLE_TRACE= 'Y') THEN
5080    fnd_file.put_line(fnd_file.log,'After Calling Create_Hierarchy_Section for immediate section ');
5081    fnd_file.put_line(fnd_file.log,'new section id:'||l_section_id);
5082 
5083   END IF;
5084     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5085     if G_ENABLE_TRACE = 'Y' then
5086 	   fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Create_Hierarchy_Section');
5087 	end if;
5088       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_CRT_HIER_SCT_FAIL');
5089       FND_MSG_PUB.Add;
5090       RAISE FND_API.G_EXC_ERROR;
5091     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5092     if G_ENABLE_TRACE = 'Y' then
5093 	   fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Create_Hierarchy_Section');
5094 	end if;
5095       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_CRT_HIER_SCT_FAIL');
5096       FND_MSG_PUB.Add;
5097       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5098     END IF;
5099 
5100 
5101           ---------------------------------------------------
5102  -- customer bug 3303424:
5103  -- update the ibe_dsp_section_tl table  of the duplicated child section
5104  -- with the display name, shortdesc, longdesc and keywords of the source child section.
5105 
5106 
5107  if ( l_count_langs >1)then -- if more than one lang installed
5108    FOR r4 IN c4(r2.section_id) LOOP
5109 
5110      update ibe_dsp_sections_tl set
5111         display_name= r4.display_name,
5112         description = r4.description,
5113         long_description = r4.long_description,
5114         keywords= r4.keywords,
5115         source_lang = r4.source_lang
5116        where language=r4.language and section_id=l_section_id
5117        and language <>userenv('lang');
5118    END LOOP;
5119 end if;
5120 
5121 ------------------------------------- ---------------------------------------------
5122  --------------------------Reference content for  the copied descendent sections
5123 --------------------------------------------------------------------------------------
5124   IF (l_debug = 'Y') THEN
5125    IBE_UTIL.debug('Calling Reference_Section_Content ,copying from p_src_section :'||r2.section_id ||'to x_new_section_id:'||l_section_id);
5126 
5127 
5128   END IF;
5129    IF (G_ENABLE_TRACE= 'Y') THEN
5130    fnd_file.put_line(fnd_file.log,'Calling Reference_Section_Content,copying from p_src_section :'||r2.section_id ||'to x_new_section_id:'||l_section_id );
5131 
5132   END IF;
5133     Reference_Section_Content(
5134        p_old_section_id                 =>r2.section_id,
5135        p_new_section_id                 =>l_section_id,
5136        x_return_status                  =>x_return_status,
5137        x_msg_count                      =>x_msg_count,
5138        x_msg_data                       =>x_msg_data);
5139 
5140        IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5141         if G_ENABLE_TRACE = 'Y' then
5142        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Reference_Section_Content');
5143 	 end if;
5144       RAISE FND_API.G_EXC_ERROR;
5145     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5146        if G_ENABLE_TRACE = 'Y' then
5147        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Reference_Section_Content');
5148 	 end if;
5149       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5150     END IF;
5151 
5152     Put_Section_Map
5153       (
5157       x_return_status                  => x_return_status
5154       p_from_section_id                => r2.section_id,
5155       p_to_section_id                  => l_section_id,
5156       px_section_map_list              => l_section_map_list,
5158       );
5159 
5160     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5161        if G_ENABLE_TRACE = 'Y' then
5162        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Put_Section_Map, with IBE_DSP_SCT_MAP_INSERT_FAIL error');
5163 	 end if;
5164       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_INSERT_FAIL');
5165       FND_MESSAGE.Set_Token('FROM_SECTION_ID', r2.section_id);
5166       FND_MESSAGE.Set_Token('TO_SECTION_ID', l_section_id);
5167       FND_MSG_PUB.Add;
5168       RAISE FND_API.G_EXC_ERROR;
5169     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5170      if G_ENABLE_TRACE = 'Y' then
5171        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Put_Section_Map, with IBE_DSP_SCT_MAP_INSERT_FAIL error');
5172 	 end if;
5173       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_INSERT_FAIL');
5174       FND_MESSAGE.Set_Token('FROM_SECTION_ID', r2.section_id);
5175       FND_MESSAGE.Set_Token('TO_SECTION_ID', l_section_id);
5176       FND_MSG_PUB.Add;
5177     END IF;
5178 
5179     -- 11.5.10, Copy layout component mapping during section  duplication
5180     -- including center display template
5181    IF (l_debug = 'Y') THEN
5182    IBE_UTIL.debug('Calling Copy_Layout_Comp_Mapping ,copying from p_src_section :'||r2.section_id ||'to x_new_section_id:'||l_section_id);
5183 
5184 
5185   END IF;
5186    IF (G_ENABLE_TRACE= 'Y') THEN
5187    fnd_file.put_line(fnd_file.log,'Calling Copy_Layout_Comp_Mapping,copying from p_src_section :'||r2.section_id ||'to x_new_section_id:'||l_section_id );
5188 
5189   END IF;
5190     Copy_Layout_Comp_Mapping(
5191       p_api_version => 1.0,
5192 	 p_init_msg_list => FND_API.G_FALSE,
5193 	 p_commit => FND_API.G_FALSE,
5194 	 p_source_section_id => r2.section_id,
5195 	 p_target_section_id => l_section_id,
5196 	 p_include_all => FND_API.G_TRUE,
5197 	 x_return_status => x_return_status,
5198 	 x_msg_count => x_msg_count,
5199 	 x_msg_data => x_msg_data);
5200     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5201        if G_ENABLE_TRACE = 'Y' then
5202        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Copy_Layout_Comp_Mapping');
5203 	 end if;
5204 	 RAISE FND_API.G_EXC_ERROR;
5205     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5206        if G_ENABLE_TRACE = 'Y' then
5207        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Copy_Layout_Comp_Mapping');
5208 	 end if;
5209       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5210     END IF;
5211 /* An idea ahead of its time ...
5212 	copy_segments (
5213 		p_api_version   =>1.0,
5214 		p_init_msg_list  => FND_API.G_FALSE,
5215 		p_commit     => FND_API.G_FALSE,
5216 		p_validation_level => FND_API.G_VALID_LEVEL_FULL,
5217 		p_source_section_id => r2.section_id,
5218 		p_target_section_id => l_section_id,
5219 		x_return_status =>x_return_status,
5220 		x_msg_count =>x_msg_count,
5221 		x_msg_data  =>x_msg_data);
5222 */
5223 
5224      -- adding commit 11/20/03 ab :to avoid time out in case large number of sections duplicated
5225    COMMIT;
5226   END LOOP;
5227 
5228   --
5229   -- Copy the section items
5230   --
5231   FOR r3 IN c3(p_src_section_id, l_master_mini_site_id) LOOP
5232 
5233     Get_Section_Map
5234       (
5235       p_section_map_list               => l_section_map_list,
5236       p_from_section_id                => r3.section_id,
5237       x_to_section_id                  => l_section_id,
5238       x_return_status                  => x_return_status
5239       );
5240 
5241     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5242       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_GET_FAIL');
5243       FND_MESSAGE.Set_Token('FROM_SECTION_ID', r3.section_id);
5244       FND_MSG_PUB.Add;
5245       RAISE FND_API.G_EXC_ERROR;
5246     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5247       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_SCT_MAP_GET_FAIL');
5248       FND_MESSAGE.Set_Token('FROM_SECTION_ID', r3.section_id);
5249       FND_MSG_PUB.Add;
5250       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5251     END IF;
5252 
5253     l_inventory_item_ids       := JTF_NUMBER_TABLE();
5254     l_organization_ids         := JTF_NUMBER_TABLE();
5255     l_start_date_actives       := JTF_DATE_TABLE();
5256     l_end_date_actives         := JTF_DATE_TABLE();
5257     l_sort_orders              := JTF_NUMBER_TABLE();
5258     l_association_reason_codes := JTF_VARCHAR2_TABLE_300();
5259 
5260     l_inventory_item_ids.EXTEND();
5261     l_organization_ids.EXTEND();
5262     l_start_date_actives.EXTEND();
5263     l_end_date_actives.EXTEND();
5264     l_sort_orders.EXTEND();
5265     l_association_reason_codes.EXTEND();
5266 
5267     l_inventory_item_ids(1) := r3.inventory_item_id;
5268     l_organization_ids(1) := r3.organization_id;
5269     l_start_date_actives(1) := r3.start_date_active;
5270     l_end_date_actives(1) := r3.end_date_active;
5271     l_sort_orders(1) := r3.sort_order;
5272     l_association_reason_codes(1) := r3.association_reason_code;
5273  IF (l_debug = 'Y') THEN
5274    IBE_UTIL.debug(' Calling Associate_Items_To_Section to copy section items to section :'||l_section_id);
5275 
5276   END IF;
5277    IF (G_ENABLE_TRACE= 'Y') THEN
5281     Associate_Items_To_Section
5278    fnd_file.put_line(fnd_file.log,' Calling Associate_Items_To_Section to copy section items to section :'||l_section_id);
5279 
5280   END IF;
5282       (
5283       p_api_version                    => p_api_version,
5284       p_init_msg_list                  => FND_API.G_FALSE,
5285       p_commit                         => FND_API.G_FALSE,
5286       p_validation_level               => p_validation_level,
5287       p_section_id                     => l_section_id,
5288       p_inventory_item_ids             => l_inventory_item_ids,
5289       p_organization_ids               => l_organization_ids,
5290       p_start_date_actives             => l_start_date_actives,
5291       p_end_date_actives               => l_end_date_actives,
5292       p_sort_orders                    => l_sort_orders,
5293       p_association_reason_codes       => l_association_reason_codes,
5294       x_section_item_ids               => l_section_item_ids,
5295       x_duplicate_association_status   => l_duplicate_association_status,
5296       x_return_status                  => x_return_status,
5297       x_msg_count                      => x_msg_count,
5298       x_msg_data                       => x_msg_data
5299       );
5300 
5301     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5302       if G_ENABLE_TRACE = 'Y' then
5303        fnd_file.put_line(fnd_file.log,'get G_RET_STS_ERROR in Associate_Items_To_Section');
5304 	 end if;
5305       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_ASC_ITMS_TO_SCT_FAIL');
5306       FND_MSG_PUB.Add;
5307       RAISE FND_API.G_EXC_ERROR;
5308     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5309       if G_ENABLE_TRACE = 'Y' then
5310        fnd_file.put_line(fnd_file.log,'get G_RET_STS_UNEXP_ERROR in Associate_Items_To_Section');
5311 	 end if;
5312       FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_ASC_ITMS_TO_SCT_FAIL');
5313       FND_MSG_PUB.Add;
5314       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5315     END IF;
5316 
5317     -- adding commit 11/20/03 ab :to avoid time out in case large number of sections duplicated
5318    COMMIT;
5319   END LOOP;
5320 
5321   -- Standard check of p_commit.
5322   --commented the following as we are already doing commit for each duplicated section
5323   --IF (FND_API.To_Boolean(p_commit)) THEN
5324    -- COMMIT WORK;
5325   --END IF;
5326 
5327   -- Standard call to get message count and if count is 1, get message info.
5328   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
5329                             p_data    =>      x_msg_data,
5330                             p_encoded =>      'F');
5331 
5332 EXCEPTION
5333     -- commenting the Rollback as we already commit for each duplicated section
5334     WHEN FND_API.G_EXC_ERROR THEN
5335     -- ROLLBACK TO COPY_SECTION_REF_CONTENT_PVT;
5336   IF (l_debug = 'Y') THEN
5337    IBE_UTIL.debug(' Calling Delete_Hierarchy_Section to delete sections if exception happens'||x_new_src_section_id );
5338 
5339   END IF;
5340    IF (G_ENABLE_TRACE= 'Y') THEN
5341    fnd_file.put_line(fnd_file.log,' Calling Delete_Hierarchy_Section to delete sections if exception happens '||x_new_src_section_id);
5342 
5343   END IF;
5344     Delete_Hierarchy_Section(p_api_version =>1.0,
5345                              p_init_msg_list=> FND_API.G_FALSE,
5346                              p_commit => FND_API.G_FALSE,
5347                              p_validation_level=> FND_API.G_VALID_LEVEL_FULL,
5348                              p_section_id => x_new_src_section_id,
5349                              p_access_name=> null,
5350                              x_return_status=>x_return_status,
5351                              x_msg_count=>x_msg_count,
5352                              x_msg_data=>x_msg_data);
5353 
5354      FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_DUP_HIER_SCT_FAIL');
5355      FND_MSG_PUB.Add;
5356      x_return_status := FND_API.G_RET_STS_ERROR;
5357      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
5358                                p_data       =>      x_msg_data,
5359                                p_encoded    =>      'F');
5360 
5361    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5362     -- ROLLBACK TO COPY_SECTION_REF_CONTENT_PVT;
5363   IF (l_debug = 'Y') THEN
5364    IBE_UTIL.debug(' Calling Delete_Hierarchy_Section when G_EXC_UNEXPECTED_ERROR'||x_new_src_section_id);
5365 
5366   END IF;
5367    IF (G_ENABLE_TRACE= 'Y') THEN
5368    fnd_file.put_line(fnd_file.log,' Calling Delete_Hierarchy_Section when G_EXC_UNEXPECTED_ERROR '||x_new_src_section_id);
5369 
5370   END IF;
5371       Delete_Hierarchy_Section(p_api_version =>1.0,
5372                              p_init_msg_list=> FND_API.G_FALSE,
5373                              p_commit => FND_API.G_FALSE,
5374                              p_validation_level=> FND_API.G_VALID_LEVEL_FULL,
5375                              p_section_id => x_new_src_section_id,
5376                              p_access_name=> null,
5377                              x_return_status=>x_return_status,
5378                              x_msg_count=>x_msg_count,
5379                              x_msg_data=>x_msg_data);
5380 
5381      FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_DUP_HIER_SCT_FAIL');
5382      FND_MSG_PUB.Add;
5383      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5384      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
5385                                p_data       =>      x_msg_data,
5386                                p_encoded    =>      'F');
5387 
5388    WHEN OTHERS THEN
5392   END IF;
5389   IF (l_debug = 'Y') THEN
5390    IBE_UTIL.debug(' Calling Delete_Hierarchy_Section when Other exception happens'||x_new_src_section_id);
5391 
5393    IF (G_ENABLE_TRACE= 'Y') THEN
5394    fnd_file.put_line(fnd_file.log,' Calling Delete_Hierarchy_Section when Other exception happens '||x_new_src_section_id);
5395 
5396   END IF;
5397    --  ROLLBACK TO COPY_SECTION_REF_CONTENT_PVT;
5398      Delete_Hierarchy_Section(p_api_version =>1.0,
5399                              p_init_msg_list=> FND_API.G_FALSE,
5400                              p_commit => FND_API.G_FALSE,
5401                              p_validation_level=> FND_API.G_VALID_LEVEL_FULL,
5402                              p_section_id => x_new_src_section_id,
5403                              p_access_name=> null,
5404                              x_return_status=>x_return_status,
5405                              x_msg_count=>x_msg_count,
5406                              x_msg_data=>x_msg_data);
5407 
5408      FND_MESSAGE.Set_Name('IBE', 'IBE_DSP_J_DUP_HIER_SCT_FAIL');
5409      FND_MSG_PUB.Add;
5410      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
5411      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
5412      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
5413      FND_MESSAGE.Set_Token('REASON', SQLERRM);
5414      FND_MSG_PUB.Add;
5415      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5416 
5417      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5418      THEN
5419        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5420      END IF;
5421 
5422      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
5423                                p_data       =>      x_msg_data,
5424                                p_encoded    =>      'F');
5425 
5426 
5427 
5428 END Copy_Section_Ref_Content;
5429 
5430 -----------------------------------------------------------------------------------------------------------
5431 --  Reference the contents of the old section to the new section.
5432 
5433 ---  Associate the new section with these  existing Logical Media and Mutimedia
5434 --- ---------------------------------------------------------------------------------
5435 
5436  PROCEDURE Reference_Section_Content
5437   (
5438    p_old_section_id                 IN NUMBER,
5439    p_new_section_id                 IN NUMBER,
5440    x_return_status                  OUT NOCOPY VARCHAR2,
5441    x_msg_count                      OUT NOCOPY NUMBER,
5442    x_msg_data                       OUT NOCOPY VARCHAR2
5443   )
5444 IS
5445 l_api_name                     CONSTANT VARCHAR2(30) :=
5446    'Reference_section_Content';
5447 l_api_version                  CONSTANT NUMBER    := 1.0;
5448 l_old_section_id               NUMBER;
5449 l_new_section_id               NUMBER;
5450 l_item_id                      NUMBER;
5451 l_new_item_id                  NUMBER;
5452 
5453 --get all the logical multimedia associated with the original Section
5454 
5455 CURSOR c1(l_old_section_id IN NUMBER)
5456     IS SELECT item_id,context_id from ibe_dsp_obj_lgl_ctnt where
5457     object_type='S' and object_id= l_old_section_id;
5458 
5459 
5460 
5461 BEGIN
5462   IF ((p_old_section_id is null) or (p_new_section_id is null))  then
5463         RAISE FND_API.g_exc_error;
5464   END IF;
5465   -- dbms_output.put_line('old_section_id=' || p_old_section_id);
5466 
5467    FOR r1 in c1(p_old_section_id) LOOP
5468 
5469           -- dbms_output.put_line('old media object=' || r1.item_id);
5470 
5471            --save the new section, old logical media ,old context in the ibe_dsp_lgl_ctnt table
5472            Save_Object_Logical_Content(   p_object_id     => p_new_section_id,
5473                                           p_context_id    => r1.context_id,
5474                                           p_object_type   => 'S',
5475                                           p_item_id       => r1.item_id,
5476                                           x_msg_count     => x_msg_count,
5477                                           x_return_status => x_return_status,
5478                                           x_msg_data      => x_msg_data);
5479 
5480              -- dbms_output.put_line('saved in the object logical content');
5481 
5482     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5483       RAISE FND_API.G_EXC_ERROR;
5484     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5485       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5486     END IF;
5487 
5488 
5489     END LOOP; -- End for r1 in c1
5490 
5491   END Reference_Section_Content;
5492 
5493 
5494 -----------------------------------------------------------------------------------------------------------
5495 --  DEPRECATED: Due to change in requirement from PMs.  : abhandar 14-Aug 2002
5496 -- Reference the contents of the old section to the new section.
5497 --
5498 ---step1:Retrieve all the Logical Media associated with the Old_Section
5499 -- step2:Create copy of all these Logical Media (jtf_amv_items_b/tl table)
5500 -- step3:Associate the new section with these new Logical Media ( ibe_dsp_obj_lgl_ctnt table)
5501 -- step4:For all the new Logical media, create equivalent  store mappings as existed for the Old Logical Media
5502 --   (ibe_dsp_lgl_phys_map)
5503 
5504 ---------------------------------------------------------------------------------------------------
5505 --** PROCEDURE Reference_Section_Content
5506 --**  (
5507 --**   p_old_section_id                 IN NUMBER,
5511 --**   x_msg_data                       OUT NOCOPY VARCHAR2
5508 --**   p_new_section_id                 IN NUMBER,
5509 --**   x_return_status                  OUT NOCOPY VARCHAR2,
5510 --**   x_msg_count                      OUT NOCOPY NUMBER,
5512 --**  )
5513 --** IS
5514 --** l_api_name                     CONSTANT VARCHAR2(30) :=
5515 --**    'Reference_section_Content';
5516 --** l_api_version                  CONSTANT NUMBER    := 1.0;
5517 --** l_old_section_id               NUMBER;
5518 --** l_new_section_id               NUMBER;
5519 --** l_item_id                      NUMBER;
5520 --** l_new_item_id                  NUMBER;
5521 
5522 --get all the logical multimedia associated with the original Section
5523 
5524 --** CURSOR c1(l_old_section_id IN NUMBER)
5525 --**     IS SELECT item_id,context_id from ibe_dsp_obj_lgl_ctnt where
5526 --**     object_type='S' and object_id= l_old_section_id;
5527 
5528 
5529 -- get all the mappings associated with the Media logical item
5530 
5531 --** CURSOR c2(l_item_id IN NUMBER)
5532 --**      IS SELECT msite_id,language_code,attachment_id,default_language,default_site
5533 --**      from  ibe_dsp_lgl_phys_map where item_id=l_item_id;
5534 
5535 --** BEGIN
5536 --**   IF ((p_old_section_id is null) or (p_new_section_id is null))  then
5537 --**         RAISE FND_API.g_exc_error;
5538 --**   END IF;
5539   -- dbms_output.put_line('old_section_id=' || p_old_section_id);
5540 
5541 --**   FOR r1 in c1(p_old_section_id) LOOP
5542 
5543            -- for each logical Media, create a copy of it
5544 --**            Copy_Logical_Media(p_item_id     => r1.item_id,
5545 --**                              p_object_id    => p_new_section_id,
5546 --**                              p_context_id   => r1.context_id,
5547 --**                              x_new_item_id  => l_new_item_id,
5548 --**                              x_msg_count    => x_msg_count,
5549 --**                              x_return_status=> x_return_status,
5550 --**                              x_msg_data     => x_msg_data);
5551 
5552           -- dbms_output.put_line('old media object=' || r1.item_id);
5553 
5554            --save the new section, new logical media ,old context in the ibe_dsp_lgl_ctnt table
5555 --**            Save_Object_Logical_Content(   p_object_id     => p_new_section_id,
5556 --**                                           p_context_id    => r1.context_id,
5557 --**                                           p_object_type   => 'S',
5558 --**                                           p_item_id       => l_new_item_id,
5559 --**                                           x_msg_count     => x_msg_count,
5560 --**                                           x_return_status => x_return_status,
5561 --**                                           x_msg_data      => x_msg_data);
5562 
5563              -- dbms_output.put_line('saved in the object logical content');
5564 
5565            -- now save all the mappings for the new Logical Media's
5566 
5567                -- get all the mapping for the old Logical Media
5568 --**                For r2 in c2(r1.item_id) LOOP
5569 
5570                   -- Add all the mappings in the ibe_dsp_lgl_phys_map table for the copied new Logical Item Id
5571 
5572 --**                     Save_Physical_Map(p_item_id          => l_new_item_id,
5573 --**                                      p_msite_id         => r2.msite_id,
5574 --**                                      p_language_code    =>r2.language_code,
5575 --**                                      p_attachment_id    =>r2.attachment_id,
5576 --** 				                     p_default_site     =>r2.default_site,
5577 --**                                      p_default_language =>r2.default_language,
5578 --**                                      x_return_status    =>x_return_status,
5579 --**                                      x_msg_count        =>x_msg_count,
5580 --**                                      x_msg_data	        =>x_msg_data);
5581 
5582 				 -- dbms_output.put_line('inserting into ibe_dsp_lgl_phys_map');
5583 
5584 --**     	     END LOOP; -- end for r2 in c2
5585 
5586 
5587 --**     END LOOP; -- End for r1 in c1
5588 
5589 --**   END Reference_Section_Content;
5590 
5591 ------------------------------------------------------------------------
5592   -- Procedure to Create a copy of the logical media item
5593   --
5594   --
5595   PROCEDURE Copy_Logical_Media(
5596        p_item_id        IN    NUMBER,
5597        p_object_id      IN    NUMBER,
5598        p_context_id     IN    NUMBER,
5599        x_new_item_id    OUT NOCOPY NUMBER,
5600        x_msg_count      OUT NOCOPY NUMBER,
5601        x_return_status  OUT NOCOPY VARCHAR2,
5602        x_msg_data       OUT NOCOPY VARCHAR2
5603    )
5604    IS
5605         l_api_name      CONSTANT VARCHAR2(30):='Copy_Logical_Media';
5606 
5607         l_api_version   CONSTANT NUMBER       := 1.0;
5608 
5609         l_deliverable_rec    IBE_DELIVERABLE_GRP.DELIVERABLE_REC_TYPE;
5610 
5611    BEGIN
5612 
5613      select access_name,item_name,deliverable_type_code,applicable_to_code,keyword,description
5614      into l_deliverable_rec.access_name,
5615           l_deliverable_rec.display_name,
5616           l_deliverable_rec.item_type,
5617           l_deliverable_rec.item_applicable_to,
5618           l_deliverable_rec.keywords,
5619           l_deliverable_rec.description
5620      from ibe_dsp_amv_items_v where item_id=p_item_id;
5621 
5622      if (SQL%NOTFOUND) then
5623         RAISE FND_API.g_exc_error;
5627      --l_deliverable_rec.display_name:= 'Copy of ' || l_deliverable_rec.display_name;
5624       END IF;
5625 
5626       -- change the item  display name to 'Copy of'  the old display name
5628 
5629 
5630      l_deliverable_rec.access_name := 'IBE_MO_'||p_object_id ||'_'||p_context_id;
5631 
5632      l_deliverable_rec.object_version_number:=1;
5633      l_deliverable_rec.x_action_status:=null;
5634 
5635       IBE_DELIVERABLE_GRP.save_deliverable (
5636                 p_api_version	        =>l_api_version,
5637                 p_init_msg_list	        =>FND_API.g_false,
5638                 p_commit	            =>FND_API.g_false,
5639                 x_return_status	        =>x_return_status,
5640                 x_msg_count		        =>x_msg_count,
5641                 x_msg_data		        =>x_msg_data,
5642                 p_deliverable_rec       =>l_deliverable_rec);
5643 
5644 
5645       x_new_item_id:= l_deliverable_rec.deliverable_id ;
5646      -- dbms_output.put_line('New media object=' || l_deliverable_rec.deliverable_id);
5647      -- dbms_output.put_line('Return Status' || x_return_status);
5648 
5649   EXCEPTION
5650        WHEN FND_API.g_exc_error then
5651          	IF x_return_status <> FND_API.g_ret_sts_unexp_error THEN
5652     			x_return_status := FND_API.g_ret_sts_error;
5653 	       END IF;
5654 
5655       WHEN OTHERS THEN
5656 			x_return_status := FND_API.g_ret_sts_unexp_error ;
5657 
5658   END Copy_Logical_Media;
5659 
5660 ---------------------------------------------------------------------------
5661 -- save the rows in the ibe_dsp_lgl_phys_map table for the logical item id.
5662 --
5663 --
5664 PROCEDURE Save_Physical_Map(p_item_id           IN  NUMBER,
5665                            p_msite_id           IN  NUMBER,
5666                            p_language_code      IN  VARCHAR2,
5667                            p_attachment_id      IN  NUMBER,
5668 				           p_default_site       IN  VARCHAR2,
5669                            p_default_language   IN  VARCHAR2,
5670                            x_return_status	    OUT NOCOPY VARCHAR2,
5671                            x_msg_count		    OUT NOCOPY NUMBER,
5672                            x_msg_data		    OUT NOCOPY VARCHAR2)
5673 
5674   IS
5675         l_api_name      CONSTANT VARCHAR2(30):='Save_Physical_Map';
5676         l_api_version   CONSTANT NUMBER       := 1.0;
5677         l_lgl_phys_map_id  NUMBER;
5678         l_language_code_tbl    ibe_physicalMap_grp.LANGUAGE_CODE_TBL_TYPE;
5679 
5680         CURSOR lgl_phys_map_id_seq IS
5681 		SELECT IBE_DSP_LGL_PHYS_MAP_S1.NEXTVAL FROM DUAL;
5682   BEGIN
5683 
5684          IF (p_item_id IS NULL)or (p_msite_id IS NULL) OR (p_attachment_id IS NULL)
5685           OR (p_language_code IS NULL ) or (p_default_site is null ) or (p_default_language is null) THEN
5686 		     RAISE FND_API.g_exc_error;
5687           END IF;
5688 
5689          OPEN lgl_phys_map_id_seq;
5690 	     FETCH lgl_phys_map_id_seq INTO l_lgl_phys_map_id;
5691 		 CLOSE lgl_phys_map_id_seq;
5692 
5693          INSERT INTO IBE_DSP_LGL_PHYS_MAP (
5694 				lgl_phys_map_id,
5695 				object_version_number,
5696 				last_update_date,
5697 				last_updated_by,
5698 				creation_date,
5699 				created_by,
5700 				last_update_login,
5701 				msite_id,
5702 				language_code,
5703 				attachment_id,
5704 				item_id,
5705 				default_site,
5706 				default_language
5707 			) VALUES (
5708 				l_lgl_phys_map_id,
5709 				1,
5710 				SYSDATE,
5711 				FND_GLOBAL.user_id,
5712 				SYSDATE,
5713 				FND_GLOBAL.user_id,
5714 				FND_GLOBAL.login_id,
5715 				p_msite_id,
5716 				p_language_code,
5717 				p_attachment_id,
5718 				p_item_id,
5719 				p_default_site,
5720 				p_default_language);
5721 
5722   EXCEPTION
5723            	WHEN FND_API.g_exc_error THEN
5724 					IF x_return_status <> FND_API.g_ret_sts_unexp_error THEN
5725 						x_return_status := FND_API.g_ret_sts_error;
5726 					END IF;
5727 
5728 				WHEN dup_val_on_index THEN
5729 
5730 					IF x_return_status <> FND_API.g_ret_sts_unexp_error THEN
5731 						x_return_status := FND_API.g_ret_sts_error;
5732 					END IF;
5733 
5734               WHEN OTHERS THEN
5735 
5736 					x_return_status := FND_API.g_ret_sts_unexp_error ;
5737 
5738   END Save_Physical_Map;
5739 
5740 -----------------------------------------------------------------------
5741 -- save the logical content for the Section
5742 ---
5743   PROCEDURE Save_Object_Logical_Content(
5744    p_object_id              IN  NUMBER,
5745    p_context_id             IN  NUMBER,
5746    p_item_id                IN  NUMBER,
5747    p_object_type            IN  VARCHAR2,
5748    x_return_status	    OUT NOCOPY VARCHAR2,
5749    x_msg_count		    OUT NOCOPY NUMBER,
5750    x_msg_data		    OUT NOCOPY VARCHAR2)
5751 
5752   IS
5753 
5754   l_api_name      CONSTANT VARCHAR2(30) :='Save Object Logical Content';
5755   l_api_version   CONSTANT NUMBER       := 1.0;
5756   l_obj_lgl_ctnt_rec_type  IBE_LOGICALCONTENT_GRP.obj_lgl_ctnt_rec_type;
5757   l_obj_lgl_ctnt_tbl_type  IBE_LOGICALCONTENT_GRP.obj_lgl_ctnt_tbl_type;
5758 
5759   BEGIN
5760 
5761     IF ((p_object_id is null) OR (p_context_id is null) or (p_item_id is null)
5762          or (p_object_type is null))  Then
5763          Raise FND_API.g_exc_error;
5767     l_obj_lgl_ctnt_rec_type.OBJ_lgl_ctnt_id:=       null;
5764     End if;
5765 
5766     l_obj_lgl_ctnt_rec_type.obj_lgl_ctnt_delete:=   FND_API.g_false;
5768     l_obj_lgl_ctnt_rec_type.Object_Version_Number:= 1.0;
5769     l_obj_lgl_ctnt_rec_type.Object_id:=             p_object_id;
5770     l_obj_lgl_ctnt_rec_type.Context_id:=            p_context_id;
5771     l_obj_lgl_ctnt_rec_type.deliverable_id:=        p_item_id;
5772 
5773     l_obj_lgl_ctnt_tbl_type(1):=l_obj_lgl_ctnt_rec_type;
5774 
5775     IBE_LOGICALCONTENT_GRP.save_delete_lgl_ctnt(
5776                     p_api_version         =>l_api_version,
5777                     p_init_msg_list       => FND_API.g_false,
5778                     p_commit              => FND_API.g_false,
5779                     x_return_status       => x_return_status,
5780                     x_msg_count           => x_msg_count,
5781                     x_msg_data            => x_msg_data,
5782                     p_object_type_code    => 'S',
5783                     p_lgl_ctnt_tbl        => l_obj_lgl_ctnt_tbl_type);
5784 
5785     EXCEPTION
5786            	WHEN FND_API.g_exc_error THEN
5787 					IF x_return_status <> FND_API.g_ret_sts_unexp_error THEN
5788 						x_return_status := FND_API.g_ret_sts_error;
5789 					END IF;
5790 
5791 				WHEN dup_val_on_index THEN
5792 
5793 					IF x_return_status <> FND_API.g_ret_sts_unexp_error THEN
5794 						x_return_status := FND_API.g_ret_sts_error;
5795 					END IF;
5796 
5797               WHEN OTHERS THEN
5798 
5799 					x_return_status := FND_API.g_ret_sts_unexp_error ;
5800 
5801 
5802    END Save_Object_Logical_Content;
5803    PROCEDURE  Batch_Cascade_Sec_Layout_Map(
5804     		errbuf	OUT NOCOPY VARCHAR2,
5805 	    	retcode OUT NOCOPY NUMBER,
5806 		p_section_id         IN VARCHAR2,
5807 		p_enable_trace_flag  IN VARCHAR2)
5808 
5809 		IS
5810     		x_return_status		VARCHAR2(1000);
5811 		x_msg_count		NUMBER;
5812 		x_msg_data		VARCHAR2(1000);
5813 		CURSOR c_get_child_section(
5814 			c_section_id NUMBER,
5815 			c_master_mini_site_id NUMBER) IS
5816 				SELECT child_section_id
5817 				FROM ibe_dsp_msite_sct_sects
5818 				WHERE mini_site_id = c_master_mini_site_id
5819 				START WITH parent_section_id = c_section_id
5820 					AND mini_site_id = c_master_mini_site_id
5821 				CONNECT BY PRIOR child_section_id = parent_section_id
5822 					AND mini_site_id = c_master_mini_site_id;
5823 
5824  		l_master_minisite_id NUMBER;
5825 		l_root_section_id NUMBER;
5826 		l_section_ids  JTF_NUMBER_TABLE ;
5827 		l_layout_comp_ids JTF_NUMBER_TABLE;
5828 		BEGIN
5829         	l_section_ids :=  JTF_NUMBER_TABLE();
5830         	l_layout_comp_ids := JTF_NUMBER_TABLE();
5831 		if  p_enable_trace_flag = 'Y'  then
5832 			G_ENABLE_TRACE := 'Y';
5833 		end if;
5834 
5835 		Get_Master_Mini_Site_Id(x_mini_site_id => l_master_minisite_id,
5836       							x_root_section_id => l_root_section_id);
5837 
5838 		FOR child_section IN c_get_child_section(to_number(p_section_id),l_master_minisite_id) LOOP
5839 		IF G_ENABLE_TRACE = 'Y' then
5840        		fnd_file.put_line(fnd_file.log,'Calling Cascade_Layout_Comp_Mapping ');
5841        		fnd_file.put_line(fnd_file.log,'section id:'||child_section.child_section_id);
5842     		END IF;
5843             Cascade_Layout_Comp_Mapping
5844 				(p_api_version   => 1.0,
5845 				p_init_msg_list => FND_API.G_FALSE,
5846 				p_commit        => FND_API.G_FALSE,
5847 				p_source_section_id => to_number(p_section_id),
5848 				p_target_section_id => child_section.child_section_id,
5849 				x_return_status => x_return_status,
5850 				x_msg_count => x_msg_count,
5851 				x_msg_data => x_msg_data,
5852 				x_section_ids => l_section_ids,
5853 				x_layout_comp_ids => l_layout_comp_ids);
5854 
5855 			IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
5856 				RAISE FND_API.G_EXC_ERROR;
5857 			ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
5858                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5859 			END IF;
5860 			COMMIT;
5861 		END LOOP;
5862        if (x_return_status = FND_API.G_RET_STS_SUCCESS) then
5863           retcode := 0;
5864           errbuf := 'SUCCESS';
5865        else
5866             retcode := -1;
5867             errbuf := x_msg_data;
5868 
5869        end if;
5870 
5871 	End Batch_Cascade_Sec_Layout_Map;
5872 
5873 
5874 PROCEDURE Cascade_Layout_Comp_Mapping
5875 (p_api_version       IN NUMBER,
5876  p_init_msg_list     IN VARCHAR2 := FND_API.G_FALSE,
5877  p_commit            IN VARCHAR2 := FND_API.G_FALSE,
5878  p_source_section_id IN NUMBER,
5879  p_target_section_id  IN NUMBER,
5880  x_return_status     OUT NOCOPY VARCHAR2,
5881  x_msg_count         OUT NOCOPY NUMBER,
5882  x_msg_data          OUT NOCOPY VARCHAR2,
5883  x_section_ids       IN OUT NOCOPY JTF_NUMBER_TABLE,
5884  x_layout_comp_ids   IN OUT NOCOPY JTF_NUMBER_TABLE)
5885 IS
5886  l_api_name    CONSTANT VARCHAR2(30) := 'cascade_layout_comp_mapping';
5887  l_api_version CONSTANT NUMBER := 1.0;
5888  l_full_name   CONSTANT VARCHAR2(60) := g_pkg_name ||'.'|| l_api_name;
5889 
5890  l_source_deliverable_id NUMBER;
5891  l_source_layout_type VARCHAR2(1);
5892  l_debug                        VARCHAR2(1);
5893  l_idx NUMBER;
5894  TYPE num_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5895  l_context_ids num_tbl;
5896  l_i NUMBER;
5897 
5898  -- Specific layout component templates are excluded
5899  -- for example, subsection, featured section, product section
5900  -- old process template
5901  CURSOR c_get_component_mapping(c_section_id NUMBER) IS
5902    SELECT obj.item_id, obj.context_id, obj.object_type
5903      FROM ibe_dsp_obj_lgl_ctnt obj,  ibe_dsp_context_b context
5904     WHERE obj.object_id = c_section_id
5905       AND obj.object_type = 'S'
5906       AND obj.context_id = context.context_id
5907       AND context.context_type_code = 'LAYOUT_COMPONENT'
5908       AND context.access_name <> 'CENTER';
5909 BEGIN
5910   SAVEPOINT cascade_layout_comp_mapping;
5911   l_debug  := NVL(FND_PROFILE.VALUE('IBE_DEBUG'),'N');
5912   IF NOT FND_API.compatible_api_call(l_api_version,
5913        p_api_version, l_api_name, g_pkg_name ) THEN
5914     RAISE FND_API.g_exc_unexpected_error;
5915   END IF;
5916   IF FND_API.to_boolean(p_init_msg_list) THEN
5917     FND_MSG_PUB.initialize;
5918   END IF;
5919   -- Initialize API return status to success
5920   x_return_status := FND_API.g_ret_sts_success;
5921 
5922   l_idx := x_section_ids.COUNT;
5923  IF (l_debug = 'Y') THEN
5924    IBE_UTIL.debug('Calling Get_Sect_Layout_Type');
5925    IBE_UTIL.debug('section id:'||p_source_section_id);
5926 
5927   END IF;
5928 
5929    IF (G_ENABLE_TRACE= 'Y') THEN
5930    fnd_file.put_line(fnd_file.log,'Calling Get_Sect_Layout_Type ');
5931    fnd_file.put_line(fnd_file.log,'section id:'||p_source_section_id);
5932 
5933   END IF;
5934   Get_Sect_Layout_Type(p_section_id => p_source_section_id,
5935     x_deliverable_id => l_source_deliverable_id,
5936     x_layout_type => l_source_layout_type);
5937   IF (l_debug = 'Y') THEN
5938    IBE_UTIL.debug('After Calling Get_Sect_Layout_Type');
5939    IBE_UTIL.debug('layout type:'||l_source_layout_type);
5940 
5941   END IF;
5942    IF (G_ENABLE_TRACE= 'Y') THEN
5943    fnd_file.put_line(fnd_file.log,'After Calling Get_Sect_Layout_Type ');
5944    fnd_file.put_line(fnd_file.log,'layout type:'||l_source_layout_type);
5945 
5946   END IF;
5947 
5948   IF (l_source_layout_type = 'C') THEN
5949     IF (l_debug = 'Y') THEN
5950      IBE_UTIL.debug('Delete from ibe_dsp_obj_lgl_cnt_obj for section'||p_target_section_id);
5951      END IF;
5952     IF (G_ENABLE_TRACE= 'Y') THEN
5953       fnd_file.put_line(fnd_file.log,'Delete from ibe_dsp_obj_lgl_cnt_obj for section '||p_target_section_id);
5954     END IF;
5955     DELETE FROM ibe_dsp_obj_lgl_ctnt obj
5956       WHERE obj.object_id = p_target_section_id
5957 	   AND obj.object_type = 'S'
5958 	   AND EXISTS (
5959 		SELECT 1
5960 		  FROM ibe_dsp_context_b context
5961            WHERE obj.context_id = context.context_id
5962 		   AND context.context_type_code = 'LAYOUT_COMPONENT')
5963         AND NOT EXISTS(
5964             SELECT 1
5965               FROM ibe_dsp_context_b context, ibe_dsp_obj_lgl_ctnt obj1
5966              WHERE obj1.context_id = obj.context_id
5967                AND obj1.context_id = context.context_id
5968                AND obj1.object_id = p_source_section_id
5969                AND obj1.object_type = 'S'
5970                AND context.context_type_code = 'LAYOUT_COMPONENT'
5971                AND context.component_type_code <> 'CENTER')
5972     RETURNING context_id BULK COLLECT INTO l_context_ids;
5973     IF (l_context_ids.count > 0) THEN
5974       FOR l_i IN 1..l_context_ids.COUNT LOOP
5975 	   x_section_ids.extend(1);
5976 	   x_layout_comp_ids.extend(1);
5977         l_idx := l_idx + 1;
5978 	   x_section_ids(l_idx) := p_target_section_id;
5979 	   x_layout_comp_ids(l_idx) := l_context_ids(l_i);
5980 	 END LOOP;
5981     END IF;
5985     IF (l_debug = 'Y') THEN
5982     -- Component mapping except old processing and center display template
5983     FOR mapping IN c_get_component_mapping(p_source_section_id) LOOP
5984 
5986       IBE_UTIL.debug('Layout component mapping  for section'||p_target_section_id);
5987     END IF;
5988      IF (G_ENABLE_TRACE= 'Y') THEN
5989       fnd_file.put_line(fnd_file.log,'Layout component mapping for section '||p_target_section_id);
5990      END IF;
5991       UPDATE ibe_dsp_obj_lgl_ctnt
5992          SET OBJECT_VERSION_NUMBER = OBJECT_VERSION_NUMBER + 1,
5993 	        ITEM_ID = mapping.item_id,
5994 	        CREATED_BY = FND_GLOBAL.user_id,
5995              CREATION_DATE = SYSDATE,
5996              LAST_UPDATED_BY = FND_GLOBAL.user_id,
5997              LAST_UPDATE_DATE = SYSDATE,
5998              LAST_UPDATE_LOGIN = FND_GLOBAL.login_id
5999        WHERE object_id = p_target_section_id
6000          AND object_type = 'S'
6001          AND context_id = mapping.context_id;
6002       IF sql%NOTFOUND THEN
6003         INSERT INTO ibe_dsp_obj_lgl_ctnt(OBJ_LGL_CTNT_ID,
6004           OBJECT_VERSION_NUMBER, CREATED_BY, CREATION_DATE,
6005           LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN,
6006           SECURITY_GROUP_ID, CONTEXT_ID, OBJECT_TYPE, OBJECT_ID,
6007           ITEM_ID)
6008         VALUES(ibe_dsp_obj_lgl_ctnt_s1.NEXTVAL,1,FND_GLOBAL.user_id,SYSDATE,
6009           FND_GLOBAL.user_id, SYSDATE, FND_GLOBAL.login_id, NULL,
6010           mapping.context_id, 'S', p_target_section_id, mapping.item_id);
6011       END IF;
6012 	 x_section_ids.extend(1);
6013 	 x_layout_comp_ids.extend(1);
6014       l_idx := l_idx + 1;
6015 	 x_section_ids(l_idx) := p_target_section_id;
6016 	 x_layout_comp_ids(l_idx) := mapping.context_id;
6017     END LOOP;
6018   END IF;
6019   --
6020   -- End of main API body.
6021   -- Standard check of p_commit.
6022   IF (FND_API.To_Boolean(p_commit)) THEN
6023     COMMIT;
6024   END IF;
6025   -- Standard call to get message count and if count is 1, get message info.
6026   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
6027                             p_data    =>      x_msg_data,
6028                             p_encoded =>      'F');
6029 EXCEPTION
6030   WHEN FND_API.G_EXC_ERROR THEN
6031 	if G_ENABLE_TRACE = 'Y' then
6032 		fnd_file.put_line(fnd_file.log,'get G_EXC_ERROR in Cascade_Layout_Comp_Mapping');
6033 	end if;
6034     ROLLBACK TO cascade_layout_comp_mapping;
6035     x_return_status := FND_API.G_RET_STS_ERROR;
6036     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6037       p_data  => x_msg_data,
6038       p_encoded => 'F');
6039   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6040    	if G_ENABLE_TRACE = 'Y' then
6041 		fnd_file.put_line(fnd_file.log,'get G_EXC_UNEXPECTED_ERROR in Cascade_Layout_Comp_Mapping');
6042 	end if;
6043     ROLLBACK TO cascade_layout_comp_mapping;
6044     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6045     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6046       p_data  => x_msg_data,
6047       p_encoded => 'F');
6048   WHEN OTHERS THEN
6049  	if G_ENABLE_TRACE = 'Y' then
6050 		fnd_file.put_line(fnd_file.log,'get OTHERS Exception in Cascade_Layout_Comp_Mapping');
6051 	end if;
6052 
6053     ROLLBACK TO cascade_layout_comp_mapping;
6054     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6055     IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6056       FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6057     END IF;
6058     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6059       p_data  => x_msg_data,
6060       p_encoded => 'F');
6061 END Cascade_Layout_Comp_Mapping;
6062 
6063 -- For 11.5.10, Layout Components Map
6064 -- 12/02/03 add x_section_ids and x_layout_comp_ids
6065 --   for layout component mapping cache refresh
6066 PROCEDURE Update_Hierarchy_Layout_Map
6067 (p_api_version      IN NUMBER,
6068  p_init_msg_list    IN VARCHAR2 := FND_API.G_FALSE,
6069  p_commit           IN VARCHAR2 := FND_API.G_FALSE,
6070  p_validation_level IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
6071  p_section_id       IN NUMBER,
6072  p_layout_id        IN NUMBER,
6073  p_layout_comp_id   IN JTF_NUMBER_TABLE,
6074  p_layout_temp_id   IN JTF_NUMBER_TABLE,
6075  p_object_versions  IN JTF_NUMBER_TABLE,
6076  p_actionflags      IN JTF_VARCHAR2_TABLE_100,
6077  p_cascading_flag   IN NUMBER := 0,
6078  x_return_status    OUT NOCOPY VARCHAR2,
6079  x_msg_count        OUT NOCOPY NUMBER,
6080  x_msg_data         OUT NOCOPY VARCHAR2,
6081  x_section_ids      OUT NOCOPY JTF_NUMBER_TABLE,
6082  x_layout_comp_ids  OUT NOCOPY JTF_NUMBER_TABLE)
6083 IS
6084  l_api_name    CONSTANT VARCHAR2(30) := 'Update_Hierarchy_Layout_Map';
6085  l_api_version CONSTANT NUMBER := 1.0;
6086  l_full_name   CONSTANT VARCHAR2(60) := g_pkg_name ||'.'|| l_api_name;
6087  l_return_status     VARCHAR2(1);
6088 
6089  l_msg_count NUMBER;
6090  l_msg_data VARCHAR2(4000);
6091 
6092  l_org_deliverable_id NUMBER;
6093  l_new_deliverable_id NUMBER;
6094  l_org_layout_type VARCHAR2(1);
6095  l_new_layout_type VARCHAR2(1);
6096 
6097  l_obj_lgl_ctnt_id NUMBER;
6098 
6099  l_master_minisite_id NUMBER;
6100  l_root_section_id NUMBER;
6101 
6102  CURSOR c_get_child_section(c_section_id NUMBER,
6103    c_master_mini_site_id NUMBER) IS
6104    SELECT child_section_id
6105      FROM ibe_dsp_msite_sct_sects
6106     WHERE mini_site_id = c_master_mini_site_id
6107     START WITH parent_section_id = c_section_id
6108       AND mini_site_id = c_master_mini_site_id
6109     CONNECT BY PRIOR child_section_id = parent_section_id
6110       AND mini_site_id = c_master_mini_site_id;
6111 
6112  l_debug VARCHAR2(1);
6113  l_idx NUMBER := 0;
6117     l_api_version,
6114 BEGIN
6115   SAVEPOINT UPDATE_HIERARCHY_LAYOUT_MAP;
6116   IF NOT FND_API.compatible_api_call(
6118     p_api_version,
6119     l_api_name,
6120     g_pkg_name )
6121   THEN
6122     RAISE FND_API.g_exc_unexpected_error;
6123   END IF;
6124   IF FND_API.to_boolean(p_init_msg_list)
6125   THEN
6126     FND_MSG_PUB.initialize;
6127   END IF;
6128   --- Initialize API return status to success
6129   x_return_status := FND_API.g_ret_sts_success;
6130   l_debug  := NVL(FND_PROFILE.VALUE('IBE_DEBUG'),'N');
6131   IF (l_debug = 'Y') THEN
6132    IBE_UTIL.debug('Calling Update_Hierarchy_Layout_Map');
6133    IBE_UTIL.debug('section id:'||p_section_id);
6134    IBE_UTIL.debug('layout id:'||p_layout_id);
6135    FOR l_i IN 1..p_layout_comp_id.COUNT LOOP
6136      IBE_UTIL.debug('layout component id '||l_i||':'||p_layout_comp_id(l_i));
6137    END LOOP;
6138    FOR l_i IN 1..p_layout_temp_id.COUNT LOOP
6139      IBE_UTIL.debug('layout template id '||l_i||':'||p_layout_temp_id(l_i));
6140    END LOOP;
6141    FOR l_i IN 1..p_object_versions.COUNT LOOP
6142      IBE_UTIL.debug('object version id '||l_i||':'||p_object_versions(l_i));
6143    END LOOP;
6144    FOR l_i IN 1..p_actionflags.COUNT LOOP
6145      IBE_UTIL.debug('action flags '||l_i||':'||p_actionflags(l_i));
6146    END LOOP;
6147    IBE_UTIL.debug('cascading flag:'||p_cascading_flag);
6148   END IF;
6149 
6150   -- Get the original layout of the section
6151   Get_Sect_Layout_Type(p_section_id => p_section_id,
6152     x_deliverable_id => l_org_deliverable_id,
6153     x_layout_type => l_org_layout_type);
6154   IF (l_debug = 'Y') THEN
6155    IBE_UTIL.debug('org deliverable id:'||l_org_deliverable_id);
6156    IBE_UTIL.debug('org layout type:'||l_org_layout_type);
6157   END IF;
6158   l_new_layout_type
6159     := Get_Layout_Type(p_deliverable_id => p_layout_id);
6160   IF (p_layout_id = -1) THEN
6161     l_new_deliverable_id := NULL;
6162   ELSE
6163     l_new_deliverable_id := p_layout_id;
6164   END IF;
6165   IF (l_debug = 'Y') THEN
6166     IBE_UTIL.debug('new deliverable id:'||l_new_deliverable_id);
6167     IBE_UTIL.debug('new layout type:'||l_new_layout_type);
6168   END IF;
6169   x_section_ids := JTF_NUMBER_TABLE();
6170   x_layout_comp_ids := JTF_NUMBER_TABLE();
6171   -- dbms_output.put_line('layout type:'||l_new_layout_type);
6172   -- New layout is associated with section
6173   IF (l_new_layout_type = 'C') THEN
6174     IF (l_debug = 'Y') THEN
6175       IBE_UTIL.debug('Updating section deliverable id');
6176     END IF;
6177     -- x_section_ids := JTF_NUMBER_TABLE();
6178     -- x_layout_comp_ids := JTF_NUMBER_TABLE();
6179     -- dbms_output.put_line('Before updating ibe_dsp_sections_b');
6180     UPDATE ibe_dsp_sections_b
6181        SET deliverable_id = l_new_deliverable_id,
6182 	      last_update_date = SYSDATE,
6183 		 last_updated_by = FND_GLOBAL.user_id,
6184 		 object_version_number = object_version_number + 1
6185      WHERE section_id = p_section_id;
6186     -- dbms_output.put_line('After updating ibe_dsp_sections_b');
6187     -------------------------------------
6188     -------------------------------------
6189     FOR l_i IN 1..p_layout_comp_id.COUNT LOOP
6190       IF (l_debug = 'Y') THEN
6191         IBE_UTIL.debug('p_actionflags '||l_i||':'||p_actionflags(l_i));
6192         IBE_UTIL.debug('p_layout_comp_id '||l_i||':'||p_layout_comp_id(l_i));
6193         IBE_UTIL.debug('p_layout_temp_id '||l_i||':'||p_layout_temp_id(l_i));
6194       END IF;
6195       IF (p_actionflags(l_i) = 'D') THEN
6196 	   x_section_ids.extend(1);
6197 	   x_layout_comp_ids.extend(1);
6198         l_idx := l_idx + 1;
6199 	   x_section_ids(l_idx) := p_section_id;
6200 	   x_layout_comp_ids(l_idx) := p_layout_comp_id(l_i);
6201 	   DELETE FROM ibe_dsp_obj_lgl_ctnt obj
6202 	     WHERE obj.object_id = p_section_id
6203 		  AND obj.object_type = 'S'
6204 		  AND obj.context_id = p_layout_comp_id(l_i);
6205 	 ELSIF (p_actionflags(l_i) = 'I') AND
6206 	    (p_layout_temp_id(l_i) IS NOT NULL) THEN
6207 	   x_section_ids.extend(1);
6208 	   x_layout_comp_ids.extend(1);
6209         l_idx := l_idx + 1;
6210 	   x_section_ids(l_idx) := p_section_id;
6211 	   x_layout_comp_ids(l_idx) := p_layout_comp_id(l_i);
6212 	   INSERT INTO ibe_dsp_obj_lgl_ctnt(OBJ_LGL_CTNT_ID,
6213 	     OBJECT_VERSION_NUMBER, CREATED_BY, CREATION_DATE,
6214 		LAST_UPDATED_BY, LAST_UPDATE_DATE, LAST_UPDATE_LOGIN,
6215 		SECURITY_GROUP_ID, CONTEXT_ID, OBJECT_TYPE, OBJECT_ID,
6216 		ITEM_ID)
6217         VALUES(ibe_dsp_obj_lgl_ctnt_s1.NEXTVAL, 1, FND_GLOBAL.user_id,
6218 	     SYSDATE, FND_GLOBAL.user_id, SYSDATE, FND_GLOBAL.login_id,
6219 		NULL, p_layout_comp_id(l_i), 'S', p_section_id,
6220 		p_layout_temp_id(l_i));
6221 	 ELSIF (p_actionflags(l_i) = 'U') AND
6222 	   (p_layout_temp_id(l_i) IS NOT NULL) THEN
6223 	   x_section_ids.extend(1);
6224 	   x_layout_comp_ids.extend(1);
6225         l_idx := l_idx + 1;
6226 	   x_section_ids(l_idx) := p_section_id;
6227 	   x_layout_comp_ids(l_idx) := p_layout_comp_id(l_i);
6228         UPDATE ibe_dsp_obj_lgl_ctnt
6229 	     SET OBJECT_VERSION_NUMBER = OBJECT_VERSION_NUMBER + 1,
6230 		    ITEM_ID = p_layout_temp_id(l_i),
6231 		    CREATED_BY = FND_GLOBAL.user_id,
6232 		    CREATION_DATE = SYSDATE,
6233 		    LAST_UPDATED_BY = FND_GLOBAL.user_id,
6234 		    LAST_UPDATE_DATE = SYSDATE,
6235 		    LAST_UPDATE_LOGIN = FND_GLOBAL.login_id
6236         WHERE object_id = p_section_id
6237 	     AND object_type = 'S'
6238 		AND context_id = p_layout_comp_id(l_i)
6239           AND object_version_number = p_object_versions(l_i);
6240 	 END IF;
6241     END LOOP;
6242     -- Commit the change to the database
6243     IF (l_debug = 'Y') THEN
6244       IBE_UTIL.debug('after updating base section layout and mapping');
6245     END IF;
6246     ---------------------------------------
6250 	 END IF;
6247     IF (p_cascading_flag = 1) AND (l_new_layout_type = 'C') THEN
6248       IF (l_debug = 'Y') THEN
6249 	   IBE_UTIL.debug('start cascading the layout mapping');
6251       Get_Master_Mini_Site_Id(x_mini_site_id => l_master_minisite_id,
6252 	   x_root_section_id => l_root_section_id);
6253       FOR child_section IN c_get_child_section(p_section_id,
6254         l_master_minisite_id) LOOP
6255         UPDATE ibe_dsp_sections_b
6256            SET deliverable_id = l_new_deliverable_id,
6257 	          last_update_date = SYSDATE,
6258 	 	     last_updated_by = FND_GLOBAL.user_id,
6259 		     object_version_number = object_version_number + 1
6260          WHERE section_id = child_section.child_section_id;
6261         -- Get the original layout of the section
6262 	   Cascade_Layout_Comp_Mapping
6263           (p_api_version => 1.0,
6264            p_init_msg_list => FND_API.G_FALSE,
6265            p_commit => FND_API.G_FALSE,
6266 		 p_source_section_id => p_section_id,
6267 		 p_target_section_id => child_section.child_section_id,
6268            x_return_status => x_return_status,
6269            x_msg_count => l_msg_count,
6270            x_msg_data => l_msg_data,
6271 		 x_section_ids => x_section_ids,
6272 		 x_layout_comp_ids => x_layout_comp_ids);
6273         IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
6274 	     RAISE FND_API.G_EXC_ERROR;
6275         ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
6276 	     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6277         END IF;
6278 	   COMMIT;
6279       END LOOP;
6280     END IF;
6281   ELSIF (l_new_layout_type = 'F') THEN
6282     IF (l_org_layout_type = 'C') THEN
6283       -- No cascading for standard layout
6284 	 l_org_deliverable_id := null;
6285 	 -- Set the section deliverable_id to old processing page
6286       UPDATE ibe_dsp_sections_b
6287          SET deliverable_id = l_org_deliverable_id
6288        WHERE section_id = p_section_id;
6289     END IF;
6290   END IF;
6291   IF (l_debug = 'Y') THEN
6292    IBE_UTIL.debug('After Calling Update_Hierarchy_Layout_Map');
6293   END IF;
6294   --
6295   -- End of main API body.
6296   -- Standard check of p_commit.
6297   IF (FND_API.To_Boolean(p_commit)) THEN
6298     COMMIT WORK;
6299   END IF;
6300   -- Standard call to get message count and if count is 1, get message info.
6301   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
6302                             p_data    =>      x_msg_data,
6303                             p_encoded =>      'F');
6304 EXCEPTION
6305   WHEN FND_API.G_EXC_ERROR THEN
6306     ROLLBACK TO UPDATE_HIERARCHY_LAYOUT_MAP;
6307     x_return_status := FND_API.G_RET_STS_ERROR;
6308     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6309       p_data  => x_msg_data,
6310       p_encoded => 'F');
6311   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6312     ROLLBACK TO UPDATE_HIERARCHY_LAYOUT_MAP;
6313     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6314     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6315       p_data  => x_msg_data,
6316       p_encoded => 'F');
6317   WHEN OTHERS THEN
6318     ROLLBACK TO UPDATE_HIERARCHY_LAYOUT_MAP;
6319     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6320     IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6321       FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6322     END IF;
6323     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6324       p_data  => x_msg_data,
6325       p_encoded => 'F');
6326 END Update_Hierarchy_Layout_Map;
6327 
6328 PROCEDURE Update_Section_Dlv_Ctx
6329 (p_api_version      IN NUMBER,
6330  p_init_msg_list    IN VARCHAR2 := FND_API.G_FALSE,
6331  p_commit           IN VARCHAR2 := FND_API.G_FALSE,
6332  p_validation_level IN NUMBER   := FND_API.G_VALID_LEVEL_FULL,
6333  p_section_id       IN NUMBER,
6334  p_deliverable_id   IN NUMBER,
6335  p_display_context_id IN NUMBER,
6336  p_object_version_number IN NUMBER,
6337  p_saveds_flag      IN NUMBER,
6338  x_return_status    OUT NOCOPY VARCHAR2,
6339  x_msg_count        OUT NOCOPY NUMBER,
6340  x_msg_data         OUT NOCOPY VARCHAR2)
6341 IS
6342  l_api_name    CONSTANT VARCHAR2(30) := 'Update_Section_Dlv_Ctx';
6343  l_api_version CONSTANT NUMBER := 1.0;
6344  l_full_name   CONSTANT VARCHAR2(60) := g_pkg_name ||'.'|| l_api_name;
6345  l_return_status     VARCHAR2(1);
6346 
6347  l_msg_count NUMBER;
6348  l_msg_data VARCHAR2(4000);
6349 
6350  l_org_deliverable_id NUMBER;
6351  l_org_layout_type VARCHAR2(1);
6352  l_obj_lgl_ctnt_id NUMBER;
6353  l_object_version_number NUMBER;
6354  l_center_main_id NUMBER;
6355  l_display_context_id NUMBER;
6356 
6357  l_lgl_ctnt_rec IBE_LogicalContent_GRP.OBJ_LGL_CTNT_REC_TYPE;
6358  l_lgl_ctnt_tbl IBE_LogicalContent_GRP.OBJ_LGL_CTNT_TBL_TYPE;
6359 
6360  l_deliverable_id NUMBER;
6361 
6362  CURSOR c_get_center_main_csr IS
6363    SELECT ctx.context_id
6364      FROM ibe_dsp_context_b ctx
6365     WHERE ctx.access_name = 'CENTER'
6366       AND ctx.context_type_code = 'LAYOUT_COMPONENT'
6367 	 AND ctx.component_type_code = 'SECTION';
6368 
6369  CURSOR c_get_center_map_csr(c_section_id NUMBER, c_context_id NUMBER) IS
6370    SELECT map.obj_lgl_ctnt_id, map.object_version_number
6371      FROM ibe_dsp_obj_lgl_ctnt map
6372     WHERE map.object_id = c_section_id
6373       AND map.object_type = 'S'
6374 	 AND map.context_id = c_context_id;
6375 
6376  l_debug VARCHAR2(1);
6377 BEGIN
6378   SAVEPOINT UPDATE_SECTION_DLV_CTX;
6379   IF NOT FND_API.compatible_api_call(
6380     l_api_version,
6381     p_api_version,
6382     l_api_name,
6383     g_pkg_name )
6384   THEN
6385     RAISE FND_API.g_exc_unexpected_error;
6386   END IF;
6387   IF FND_API.to_boolean(p_init_msg_list)
6388   THEN
6389     FND_MSG_PUB.initialize;
6390   END IF;
6394   IF (l_debug = 'Y') THEN
6391   --- Initialize API return status to success
6392   x_return_status := FND_API.g_ret_sts_success;
6393   l_debug  := NVL(FND_PROFILE.VALUE('IBE_DEBUG'),'N');
6395     IBE_UTIL.debug('Calling Update_Section_Dlv_Ctx starts');
6396     IBE_UTIL.debug('Parameters:');
6397     IBE_UTIL.debug('section id:'||p_section_id);
6398     IBE_UTIL.debug('deliverable id:'||p_deliverable_id);
6399     IBE_UTIL.debug('display context id:'||p_display_context_id);
6400     IBE_UTIL.debug('object version number:'|| p_object_version_number);
6401     IBE_UTIL.debug('save ds:'|| p_saveds_flag);
6402   END IF;
6403   -- Get the original layout of the section
6404   Get_Sect_Layout_Type(p_section_id => p_section_id,
6405     x_deliverable_id => l_org_deliverable_id,
6406     x_layout_type => l_org_layout_type);
6407   IF (l_debug = 'Y') THEN
6408     IBE_UTIL.debug('after calling Get_Sect_Layout_Type');
6409     IBE_UTIL.debug('deliverable id:'||l_org_deliverable_id);
6410     IBE_UTIL.debug('layout type:'||l_org_layout_type);
6411   END IF;
6412   l_deliverable_id := p_deliverable_id;
6413   IF (l_deliverable_id = -1) THEN
6414     l_deliverable_id := NULL;
6415   END IF;
6416 
6417   IF (l_org_layout_type = 'F') THEN
6418     IF (p_saveds_flag = 1) THEN
6419 	 l_display_context_id := p_display_context_id;
6420       IF (p_display_context_id = -1) THEN
6421 	   l_display_context_id := NULL;
6422       END IF;
6423       IF (l_debug = 'Y') THEN
6424 	   IBE_UTIL.debug('Before calling IBE_DSP_SECTION_GRP.Update_Section');
6425 	 END IF;
6426       IBE_DSP_SECTION_GRP.Update_Section
6427 	   ( p_api_version => 1.0,
6428 	     p_init_msg_list => FND_API.G_FALSE,
6429 		p_commit => FND_API.G_FALSE,
6430 		p_section_id => p_section_id,
6431 		p_object_version_number => p_object_version_number,
6432 		p_deliverable_id => l_deliverable_id,
6433 		p_display_context_id => l_display_context_id,
6434           x_return_status => x_return_status,
6435           x_msg_count => l_msg_count,
6436           x_msg_data => l_msg_data);
6437     ELSE
6438       IBE_DSP_SECTION_GRP.Update_Section
6439 	   ( p_api_version => 1.0,
6440 	     p_init_msg_list => FND_API.G_FALSE,
6441 		p_commit => FND_API.G_FALSE,
6442 		p_section_id => p_section_id,
6443 		p_object_version_number => p_object_version_number,
6444 		p_deliverable_id => l_deliverable_id,
6445           x_return_status => x_return_status,
6446           x_msg_count => l_msg_count,
6447           x_msg_data => l_msg_data);
6448     END IF;
6449     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
6450       RAISE FND_API.G_EXC_ERROR;
6451     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
6452       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6453     END IF;
6454   ELSIF (l_org_layout_type = 'C') THEN
6455     OPEN c_get_center_main_csr;
6456     FETCH c_get_center_main_csr INTO l_center_main_id;
6457     CLOSE c_get_center_main_csr;
6458     OPEN c_get_center_map_csr(p_section_id, l_center_main_id);
6459     FETCH c_get_center_map_csr INTO l_obj_lgl_ctnt_id, l_object_version_number;
6460     IF (c_get_center_map_csr%FOUND) THEN
6461       l_lgl_ctnt_rec.OBJ_lgl_ctnt_id := l_obj_lgl_ctnt_id;
6462       l_lgl_ctnt_rec.Object_Version_Number := l_object_version_number;
6463     ELSE
6464       l_lgl_ctnt_rec.OBJ_lgl_ctnt_id := NULL;
6465       l_lgl_ctnt_rec.Object_Version_Number := 1;
6466     END IF;
6467     CLOSE c_get_center_map_csr;
6468     l_lgl_ctnt_rec.Object_id := p_section_id;
6469     l_lgl_ctnt_rec.Context_id := l_center_main_id;
6470     l_lgl_ctnt_rec.deliverable_id := l_deliverable_id;
6471     l_lgl_ctnt_rec.obj_lgl_ctnt_delete := FND_API.G_FALSE;
6472     l_lgl_ctnt_tbl(1) := l_lgl_ctnt_rec;
6473     IF (l_debug = 'Y') THEN
6474       IBE_UTIL.debug('section id:'||l_lgl_ctnt_rec.Object_id);
6475     END IF;
6476     IBE_LogicalContent_GRP.save_delete_lgl_ctnt(
6477       p_api_version => 1.0,
6478 	 x_return_status => x_return_status,
6479       x_msg_count => l_msg_count,
6480 	 x_msg_data => l_msg_data,
6481 	 p_object_type_code => 'S',
6482 	 p_lgl_ctnt_tbl => l_lgl_ctnt_tbl);
6483     IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
6484       RAISE FND_API.G_EXC_ERROR;
6485     ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
6486       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6487     END IF;
6488     -- Display Style process
6489     IF (p_saveds_flag = 1) THEN
6490 	 l_display_context_id := p_display_context_id;
6491       IF (p_display_context_id = -1) THEN
6492 	   l_display_context_id := NULL;
6493 	 END IF;
6494       IBE_DSP_SECTION_GRP.Update_Section
6495 	   ( p_api_version => 1.0,
6496 	     p_init_msg_list => FND_API.G_FALSE,
6497 		p_commit => FND_API.G_FALSE,
6498 		p_section_id => p_section_id,
6499 		p_object_version_number => p_object_version_number,
6500 		p_display_context_id => l_display_context_id,
6501           x_return_status => x_return_status,
6502           x_msg_count => l_msg_count,
6503           x_msg_data => l_msg_data);
6504       IF (x_return_status = FND_API.G_RET_STS_ERROR) THEN
6505 	   IF (l_debug = 'Y') THEN
6506 	     FOR i in 1..l_msg_count loop
6507 	       l_msg_data := FND_MSG_PUB.get(i,FND_API.G_FALSE);
6508 		  IBE_UTIL.debug(l_msg_data);
6509 	     END LOOP;
6510 	   END IF;
6511         RAISE FND_API.G_EXC_ERROR;
6512 	 ELSIF (x_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
6513 	   IF (l_debug = 'Y') THEN
6514 	     FOR i in 1..l_msg_count loop
6515 	       l_msg_data := FND_MSG_PUB.get(i,FND_API.G_FALSE);
6516 		  IBE_UTIL.debug(l_msg_data);
6517 	     END LOOP;
6518 	   END IF;
6519         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6520       END IF;
6521     END IF;
6522   END IF;
6523 
6524   --
6525   -- End of main API body.
6526   -- Standard check of p_commit.
6530   -- Standard call to get message count and if count is 1, get message info.
6527   IF (FND_API.To_Boolean(p_commit)) THEN
6528     COMMIT;
6529   END IF;
6531   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
6532                             p_data    =>      x_msg_data,
6533                             p_encoded =>      'F');
6534 EXCEPTION
6535   WHEN FND_API.G_EXC_ERROR THEN
6536     ROLLBACK TO UPDATE_SECTION_DLV_CTX;
6537     x_return_status := FND_API.G_RET_STS_ERROR;
6538     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6539       p_data  => x_msg_data,
6540       p_encoded => 'F');
6541   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6542     ROLLBACK TO UPDATE_SECTION_DLV_CTX;
6543     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6544     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6545       p_data  => x_msg_data,
6546       p_encoded => 'F');
6547   WHEN OTHERS THEN
6548     ROLLBACK TO UPDATE_SECTION_DLV_CTX;
6549     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6550     IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6551       FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6552     END IF;
6553     FND_MSG_PUB.Count_And_Get ( p_count => x_msg_count,
6554       p_data  => x_msg_data,
6555       p_encoded => 'F');
6556 END Update_Section_Dlv_Ctx;
6557 
6558 /***************************************/
6559 /*  overloaded package for the public API
6560 /*******************************************/
6561 
6562 PROCEDURE Associate_Items_To_Section(
6563    p_api_version                    	IN NUMBER,
6564    p_init_msg_list                    	IN VARCHAR2 := FND_API.G_FALSE,
6565    p_commit                         	IN VARCHAR2 := FND_API.G_FALSE,
6566    p_validation_level                   IN VARCHAR2 := FND_API.G_VALID_LEVEL_FULL,
6567    x_return_status                  	OUT NOCOPY VARCHAR2,
6568    x_msg_count                      	OUT NOCOPY NUMBER,
6569    x_msg_data                       	OUT NOCOPY VARCHAR2,
6570    p_section_id                        	IN NUMBER,
6571    p_section_item_tbl               	IN IBE_DSP_HIERARCHY_SETUP_PUB.SECTION_ITEM_TBL_TYPE,
6572    x_section_item_out_tbl            	OUT NOCOPY IBE_DSP_HIERARCHY_SETUP_PUB.SECTION_ITEM_OUT_TBL_TYPE)
6573   IS
6574 
6575   l_api_name                CONSTANT VARCHAR2(30) :=
6576   'Associate_Items_To_Section';
6577   l_api_version             CONSTANT NUMBER   := 1.0;
6578   l_section_id_tbl              JTF_NUMBER_TABLE;
6579   l_inventory_item_id_tbl       JTF_NUMBER_TABLE;
6580   l_organization_id_tbl         JTF_NUMBER_TABLE;
6581   l_start_date_active_tbl       JTF_DATE_TABLE;
6582   l_end_date_active_tbl         JTF_DATE_TABLE;
6583   l_sort_order_tbl              JTF_NUMBER_TABLE;
6584   l_association_reason_code_tbl JTF_VARCHAR2_TABLE_300;
6585   l_counter NUMBER;
6586   l_section_item_id_tbl         JTF_NUMBER_TABLE;
6587   l_overall_return_status        VARCHAR2(1);
6588   l_duplicate_association_status VARCHAR2(1);
6589   l_debug                        VARCHAR2(1);
6590 BEGIN
6591 
6592     -- Standard Start of API savepoint
6593     SAVEPOINT  ASSOCIATE_ITEMS_TO_SECTION_PVT;
6594 
6595     -- Standard call to check for call compatibility.
6596     IF NOT FND_API.Compatible_API_Call(l_api_version,
6597                                      p_api_version,
6598                                      l_api_name,
6599                                      G_PKG_NAME)
6600     THEN
6601         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6602     END IF;
6603 
6604     -- Initialize message list if p_init_msg_list is set to TRUE.
6605     IF FND_API.to_Boolean(p_init_msg_list) THEN
6606         FND_MSG_PUB.initialize;
6607     END IF;
6608     l_debug  := NVL(FND_PROFILE.VALUE('IBE_DEBUG'),'N');
6609 
6610     IF (l_debug = 'Y') THEN
6611             IBE_UTIL.debug('start of Associate_Items_To_Section');
6612     END If;
6613     -- Initialize API return status to success
6614     x_return_status := FND_API.G_RET_STS_SUCCESS;
6615     l_duplicate_association_status := FND_API.G_RET_STS_SUCCESS;
6616     l_overall_return_status :=  FND_API.G_RET_STS_SUCCESS;
6617 
6618    -- call to IBE_DSP_HIERARCHY_SETUP_PVT.Associate_Items_To_Section API
6619    -- requires passing the parameters as JTF_xxxx_TABLE
6620 
6621    -- initialize the jtf number table variables
6622      l_inventory_item_id_tbl:=JTF_NUMBER_TABLE();
6623      l_organization_id_tbl:=JTF_NUMBER_TABLE();
6624      l_start_date_active_tbl:=JTF_DATE_TABLE();
6625      l_end_date_active_tbl:=JTF_DATE_TABLE();
6626      l_sort_order_tbl:=JTF_NUMBER_TABLE();
6627      l_association_reason_code_tbl:=JTF_VARCHAR2_TABLE_300();
6628 
6629      l_inventory_item_id_tbl.extend();
6630      l_organization_id_tbl.extend();
6631      l_start_date_active_tbl.extend();
6632      l_end_date_active_tbl.extend();
6633      l_sort_order_tbl.extend();
6634      l_association_reason_code_tbl.extend();
6635 
6636       -- convert to JTF NUMBER TABLE
6637      l_counter:=1;
6638      FOR l_counter in 1..p_section_item_tbl.count LOOP
6639         l_inventory_item_id_tbl(1):=p_section_item_tbl(l_counter).inventory_item_id;
6640         l_organization_id_tbl(1):=p_section_item_tbl(l_counter).organization_id;
6641         l_start_date_active_tbl(1):=p_section_item_tbl(l_counter).start_date_active;
6642         l_end_date_active_tbl(1):=p_section_item_tbl(l_counter).end_date_active;
6643         l_sort_order_tbl(1):=p_section_item_tbl(l_counter).sort_order;
6644         l_association_reason_code_tbl(1):=p_section_item_tbl(l_counter).association_reason_code;
6645         IF (l_debug = 'Y') THEN
6646             IBE_UTIL.debug('Parameters:l_counter='||l_counter||'inventory_item_id='||l_inventory_item_id_tbl(1)||
6647             'organization_id='||l_organization_id_tbl(1)||'start_date_active='||l_start_date_active_tbl(1)||
6648             'end_date_active='||l_end_date_active_tbl(1)||'sort_order='||l_sort_order_tbl(1)||
6649             'association_reason_code='||l_association_reason_code_tbl(1));
6650         END IF;
6651         -- Call private API to associate the items to the section
6652         IBE_DSP_HIERARCHY_SETUP_PVT.Associate_Items_To_Section(
6653         p_api_version                    => p_api_version,
6654         p_init_msg_list                  => p_init_msg_list,
6655         p_commit                         => p_commit,
6656         p_validation_level               => p_validation_level,
6657         p_section_id                     => p_section_id,
6658         p_inventory_item_ids             => l_inventory_item_id_tbl,
6659         p_organization_ids               => l_organization_id_tbl,
6660         p_start_date_actives             => l_start_date_active_tbl,
6661         p_end_date_actives               => l_end_date_active_tbl,
6662         p_sort_orders                    => l_sort_order_tbl,
6663         p_association_reason_codes       => l_association_reason_code_tbl,
6664         x_section_item_ids               => l_section_item_id_tbl,
6665         x_duplicate_association_status   => l_duplicate_association_status,
6666         x_return_status                  => x_return_status,
6667         x_msg_count                      => x_msg_count,
6668         x_msg_data                       => x_msg_data
6669         );
6670         --- get the individual section item row association status
6671         x_section_item_out_tbl(l_counter).x_return_status   :=x_return_status;
6672         x_section_item_out_tbl(l_counter).section_item_id   :=l_section_item_id_tbl(1);
6673         x_section_item_out_tbl(l_counter).inventory_item_id :=l_inventory_item_id_tbl(1);
6674         x_section_item_out_tbl(l_counter).organization_id   :=l_organization_id_tbl(1);
6675         if(l_debug='Y') then
6676               IBE_UTIL.debug('Internal API return_status='||x_return_status);
6677         end if;
6678          -- derive the API overall status
6679         IF (x_return_status <> FND_API.G_RET_STS_SUCCESS)then
6680               IF (l_overall_return_status=FND_API.G_RET_STS_SUCCESS) then
6681                     l_overall_return_status:= FND_API.G_RET_STS_ERROR;
6682               END IF;
6683               IF (l_debug = 'Y') THEN
6684 	            FOR i in 1..x_msg_count loop
6685 	              IBE_UTIL.debug(FND_MSG_PUB.get(i,FND_API.G_FALSE));
6686 	            END LOOP;
6687               END IF;
6688         END IF;
6689 
6690   END LOOP;
6691 
6692   if(l_debug='Y') then
6693      IBE_UTIL.debug('API overall status='||l_overall_return_status);
6694   end if;
6695   -- set the x_return status to the API overall status
6696   x_return_status:= l_overall_return_status;
6697   -- End of main API body.
6698     -- Standard check of p_commit.
6699   IF (FND_API.To_Boolean(p_commit)) THEN
6700     COMMIT WORK;
6701   END IF;
6702 
6703   -- Standard call to get message count and if count is 1, get message info.
6704   FND_MSG_PUB.Count_And_Get(p_count   =>      x_msg_count,
6705                             p_data    =>      x_msg_data,
6706                             p_encoded =>      'F');
6707 EXCEPTION
6708 
6709    WHEN FND_API.G_EXC_ERROR THEN
6710      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
6711      x_return_status := FND_API.G_RET_STS_ERROR;
6712      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
6713                                p_data       =>      x_msg_data,
6714                                p_encoded    =>      'F');
6715 
6716    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6717      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
6718      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6719      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
6720                                p_data       =>      x_msg_data,
6721                                p_encoded    =>      'F');
6722 
6723    WHEN OTHERS THEN
6724      ROLLBACK TO ASSOCIATE_ITEMS_TO_SECTION_PVT;
6725      FND_MESSAGE.Set_Name('FND', 'SQL_PLSQL_ERROR');
6726      FND_MESSAGE.Set_Token('ROUTINE', l_api_name);
6727      FND_MESSAGE.Set_Token('ERRNO', SQLCODE);
6728      FND_MESSAGE.Set_Token('REASON', SQLERRM);
6729      FND_MSG_PUB.Add;
6730      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6731 
6732      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6733      THEN
6734        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6735      END IF;
6736 
6737      FND_MSG_PUB.Count_And_Get(p_count      =>      x_msg_count,
6738                                p_data       =>      x_msg_data,
6739                                p_encoded    =>      'F');
6740 
6741  END Associate_Items_To_Section;
6742 
6743 END IBE_DSP_HIERARCHY_SETUP_PVT;
6744