CREATE OR REPLACE PACKAGE ACISTMS2000 IS

pkg_name varchar2(255) := \'TMS-ACIS\';

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

pkg_syn varchar2(255) := pkg_name;

ping varchar2(255) := pkg_name\|\|\' is alive\';

app_title varchar2(255) := \'ASD ESH Transcripts\';

\--

procedure login(i_pid in varchar2 default NULL);

procedure enter_criteria(i_pid in varchar2);

procedure get_class(i_pid in varchar2,i_badge in varchar2);

procedure find_badge (i_pid in varchar2,i_name in varchar2 default
NULL);

END;

/

CREATE OR REPLACE PACKAGE BODY acistms2000 IS

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Added 13-FEB-98 kem

Use view A2Z_APS_STAT_V1 kem 3/9/99

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

function authorized_access (i_personid in varchar2) return boolean is

begin

\--

declare

\--

cursor c_class_status(p_person_id in varchar2,p_course_no in varchar2)
is

select to_char(NEXT_REQD_DT,\'YYYYMMDD\')

from LOCAL_A2Z_APS_STAT_V1

where person_id = p_person_id

and course_no = p_course_no;

\--

cursor c_authorized is

select \*

from acis_access_class_table;

\--

temp_date varchar2(15);

result boolean;

\--

begin

result := TRUE;

for r_class in c_authorized loop

open c_class_status(i_personid, r_class.course_no);

fetch c_class_status into temp_date;

if c_class_status%NOTFOUND then

result := FALSE;

end if;

close c_class_status;

if temp_date \< to_char(sysdate,\'YYYYMMDD\') then

result := FALSE;

end if;

end loop;

return result;

end;

end;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Added 20-FEB-98 kem

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

function controlled_access (i_personid in varchar2) return boolean is

begin

\--

declare

\--

cursor c_class_status(p_person_id in varchar2,p_course_no in varchar2)
is

select to_char(NEXT_REQD_DT,\'YYYYMMDD\')

from LOCAL_A2Z_APS_STAT_V1

where person_id = p_person_id

and course_no = p_course_no;

\--

cursor c_authorized is

select \*

from acis_control_class_table;

\--

temp_date varchar2(15);

result boolean;

\--

begin

result := TRUE;

for r_class in c_authorized loop

open c_class_status(i_personid, r_class.course_no);

fetch c_class_status into temp_date;

if c_class_status%NOTFOUND then

result := FALSE;

end if;

close c_class_status;

if temp_date \< to_char(sysdate,\'YYYYMMDD\') then

result := FALSE;

end if;

end loop;

return result;

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'TMS-ACIS\';

result := log0002.is_valid_pid(i_pid,p_app_name);

return result;

end;

end;

\--

\--

procedure enter_criteria(i_pid in varchar2) is

begin

if is_valid_pid(i_pid) then

\--lib.prolog(\'ACIS TMS 2000 Selection Criteria\');

lib02.DisplayProlog(\'ACIS TMS 2000 Selection Criteria\', \'D0D0D0\');

htp.formOpen(\'acistms2000.get_class\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"
BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\' \|\| htf.img(\'/gen-img/apslogsm.gif\')
\|\| \'\<BR\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\"
COLOR=\"#000000\"\>&nbsp ACIS Profiles
&nbsp\</CENTER\>\',\'\',\'\',\'\',\'8\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial, Helvetica\"
COLOR=\"#FFFFFF\"\>Please enter badge number to examine ACIS
profile\</CENTER\>\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Badge No:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableData(htf.formText(\'i_badge\', 20, 5));

htp.formHidden(\'i_pid\',i_pid);

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.formSubmit(\'\', \'Get
Profile\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.formClose;

htp.formOpen(\'acistms2000.find_badge\');

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.bold(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial,
Helvetica\" COLOR=\"#FFFFFF\"\>- or
-\</CENTER\>\'),\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.p(\'\<TD ALIGN=LEFT COLSPAN=2\>\<FONT SIZE=\"2\" FACE=\"Arial,
Helvetica\" COLOR=\"#FFFFFF\"\>Enter full or partial surname to find
badge\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Last Name:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableData(htf.formText(\'i_name\', 20, 30));

htp.formHidden(\'i_pid\',i_pid);

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.formSubmit(\'\', \'Find
Badges\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableClose;

htp.formClose;

htp.centerClose;

lib02.DisplayEpilog;

end if;

end;

\--

procedure find_badge (i_pid in varchar2,i_name in varchar2 default NULL)
is

\--

cursor c_badges (p_name in varchar2) is

select person_id,per_name

from LOCAL_A2Z_PEOPLE

where upper(per_last_name) like upper(p_name) \|\| \'%\'

order by per_name;

type r_badge is RECORD

(person_id varchar2(10),

per_name varchar2(50));

rec_badge r_badge;

begin

if is_valid_pid (i_pid) then

lib02.DisplayProlog(\'ACIS TMS 2000 Find Badge\', \'D0D0D0\');

htp.formOpen(\'acistms2000.get_class\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"
BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\' \|\| htf.img(\'/gen-img/apslogsm.gif\')
\|\| \'\<BR\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\"
COLOR=\"#000000\"\>&nbsp ACIS Profiles
&nbsp\</CENTER\>\',\'\',\'\',\'\',\'8\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial, Helvetica\"
COLOR=\"#FFFFFF\"\>Please select a badge number to examine ACIS
profile\</CENTER\>\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>Badge No:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_badge\',null,\'15\');

open c_badges(i_name);

fetch c_badges into rec_badge;

while not c_badges%NOTFOUND loop

htp.formSelectOption(rec_badge.person_id \|\| \' - \' \|\|
rec_badge.per_name ,\'VALUES=\'\'\'\|\|rec_badge.person_id\|\|\'\'\'\');

fetch c_badges into rec_badge;

end loop;

close c_badges;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.formHidden(\'i_pid\',i_pid);

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.formSubmit(\'\', \'Get
Profile\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

htp.formClose;

end if;

lib02.DisplayEpilog(Null, \'acistms2000.enter_criteria?i_pid=\' \|\|
i_pid, \'New Profile\');

end;

\--

\-- Modification History

\-\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure login (i_pid in varchar2 default NULL) is

begin

log0002.login(\'TMS-ACIS\');

end;

\--

procedure get_class(i_pid in varchar2,i_badge in varchar2) is

begin

declare

class_desc varchar2(255);

cursor c_acis_dates (p_badge_no in varchar2,p_course_no in varchar2) is

select NVL(to_char(LAST_COMPL_DT,\'DD-MON-YYYY\'),\'Incomplete\'),

NVL(to_char(NEXT_REQD_DT,\'DD-MON-YYYY\'),\'Incomplete\'),

course_name

FROM LOCAL_A2Z_APS_STAT_V1 stat,

APS_A2Z_COURSE cour

WHERE stat.COURSE_NO=cour.COURSE_NO

AND person_id = p_badge_no

AND stat.course_no = p_course_no;

type r_acis_info is RECORD

(LAST_COMPL_DT varchar2(15),

NEXT_REQD_DT varchar2(15),

COURSE_NAME varchar2(255)

);

rec_acis r_acis_info;

cursor c_name (p_badge_no in varchar2) is

select per_name

from local_a2z_people

where person_id = p_badge_no;

\--acis control class table list includes all access classes and 2
more\...this is therefore

\--the complete list for consideration.

\--DPROD_ID is now course_no in the new TMS\...but no reason to change
our old lookup references

cursor c_class_list is

select \*

from ACIS_CONTROL_CLASS_TABLE

UNION

Select \'ASD124\',\'CONTROLLED ACCESS TRAINING FOR OPERATORS\'

FROM DUAL

order by 1;

certification_date varchar2(10);

expiration_date varchar2(10);

name a2z_people.per_name%TYPE;

badge_no badge_info.badge_no%TYPE;

l_badge varchar2(10);

bgcolor varchar2(20);

begin

l_badge := lpad(i_badge,10,\'0\');

open c_name (l_badge);

fetch c_name into name;

close c_name;

lib02.DisplayProlog(\'ACIS TMS 2000 Profile\', \'D0D0D0\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\"\',\'\',\'\',\'\',\'CELLSPACING=\"3\"
CELLPADDING=\"2\"\');

htp.tableRowOpen;

htp.tableData(\'&nbsp\',\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"\>ACIS
Classes for \' \|\| name);

htp.NL;

htp.p(\'Data refreshed nightly between 17:15 - 17:30\');

htp.NL;

if to_char(sysdate,\'HH24MI\') \< \'1730\' then

htp.bold(\'Last refresh: \' \|\| to_char(sysdate - 1,\'DD-MON-YYYY\')
\|\| \'\</FONT\>\');

else

htp.bold(\'Last refresh: \' \|\| to_char(sysdate,\'DD-MON-YYYY\') \|\|
\'\</FONT\>\');

end if;

htp.NL;

htp.centerClose;

htp.tableOpen(\'BORDER=\"0\"\',\'\',\'\',\'\',\'CELLSPACING=\"3\"
CELLPADDING=\"2\"\');

htp.tableRowOpen;

htp.tableData(\'\<FONT FACE=ARIAL\>\<B\>AUTHORIZED
ACCESS\</B\>\</FONT\>\',\'RIGHT\');

\--Get and display authorization information

if authorized_access(l_badge)then

htp.p(\'\<TD BGCOLOR=\"#40C040\"\>\<FONT FACE=ARIAL
COLOR=\"#FFFFFF\"\>GRANTED\</font\>\</TD\>\');

else

htp.p(\'\<TD BGCOLOR=\"#FF0000\"\>\<FONT FACE=ARIAL
COLOR=\"#FFFFFF\"\>DENIED\</font\>\</TD\>\');

end if;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT FACE=ARIAL\>\<B\>CONTROLLED
ACCESS\</B\>\</FONT\>\',\'RIGHT\');

if controlled_access(l_badge) then

htp.p(\'\<TD BGCOLOR=\"#40C040\"\>\<FONT FACE=ARIAL
COLOR=\"#FFFFFF\"\>GRANTED\</font\>\</TD\>\');

else

htp.p(\'\<TD BGCOLOR=\"#FF0000\"\>\<FONT FACE=ARIAL
COLOR=\"#FFFFFF\"\>DENIED\</font\>\</TD\>\');

end if;

htp.NL;

htp.tableRowClose;

htp.tableClose;

htp.tableOpen(\'Border\');

htp.tableHeader(\'\<FONT FACE=\"ARIAL\"\>Class\</FONT\>\');

htp.tableHeader(\'\<FONT FACE=\"ARIAL\"\>Certification Date\</FONT\>\');

htp.tableHeader(\'\<FONT FACE=\"ARIAL\"\>Expiration Date\</FONT\>\');

for r_class in c_class_list loop

open c_acis_dates(l_badge,r_class.COURSE_NO);

fetch c_acis_dates into rec_acis;

htp.tableRowOpen;

if r_class.COURSE_NO != \'ASD124\' then

htp.tableData(\'\<FONT FACE=\"ARIAL\"\>\' \|\| r_class.COURSE_NO \|\|
\' - \' \|\| r_class.COURSE_NAME \|\| \'\</FONT\>\');

bgcolor := \'BGCOLOR=\"#F0D000\"\';

else

htp.tableData(\'\<FONT FACE=\"ARIAL\"\>\* \' \|\| r_class.COURSE_NO \|\|
\' - \' \|\| r_class.COURSE_NAME \|\| \'\</FONT\>\');

bgcolor := \'BGCOLOR=\"#F0D000\"\';

end if;

if c_acis_dates%NOTFOUND then

htp.tableData(\'\<FONT FACE=\"ARIAL\"\>INCOMPLETE\</FONT\>\');

htp.tableData(\'\<FONT FACE=\"ARIAL\"
COLOR=\"#000000\"\>INCOMPLETE\</FONT\>\',\'\',\'\',\'\',\'\',\'\',bgcolor);

else

htp.tableData(rec_acis.LAST_COMPL_DT);

if to_char(to_date(rec_acis.NEXT_REQD_DT,\'DD-MON-YYYY\'),\'YYYYMMDD\')
\> to_char(SYSDATE,\'YYYYMMDD\') then

\--ok

if rec_acis.NEXT_REQD_DT=\'31-DEC-2222\' then

htp.tableData(\'\<FONT FACE=\"ARIAL\" COLOR=\"#FFFFFF\"\>Never
Expires\</FONT\>\',\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#40C040\"\');

else

htp.tableData(\'\<FONT FACE=\"ARIAL\"
COLOR=\"#FFFFFF\"\>\'\|\|rec_acis.NEXT_REQD_DT\|\|\'\</FONT\>\',\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#40C040\"\');

end if;

else

htp.tableData(\'\<FONT FACE=\"ARIAL\" COLOR=\"#FFFFFF\"\>\' \|\|
rec_acis.NEXT_REQD_DT \|\|
\'\</FONT\>\',\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FF0000\"\');

end if;

end if;

htp.tableRowClose;

close c_acis_dates;

end loop;

htp.tableClose;

htp.NL;

htp.p(\'\<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\"\>\');

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=\"LEFT\" BGCOLOR=\"#40C040\"\>&nbsp &nbsp
&nbsp\</TD\>\');

htp.p(\'\<TD\>\<FONT SIZE=\"2\" COLOR=\"#000000\" FACE=\"Tahoma, Arial,
Helvetica\"\> = Current &nbsp\</TD\>\');

htp.p(\'\<TD ALIGN=\"LEFT\" BGCOLOR=\"#FF0000\"\>&nbsp &nbsp
&nbsp\</TD\>\');

htp.p(\'\<TD\>\<FONT SIZE=\"2\" COLOR=\"#000000\" FACE=\"Tahoma, Arial,
Helvetica\"\> = Expired &nbsp\</TD\>\');

htp.p(\'\<TD ALIGN=\"LEFT\" BGCOLOR=\"#F0D000\"\>&nbsp &nbsp
&nbsp\</TD\>\');

htp.p(\'\<TD\>\<FONT SIZE=\"2\" COLOR=\"#000000\" FACE=\"Tahoma, Arial,
Helvetica\"\> = Incomplete\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.p (\'\<FONT FACE=\"ARIAL\"\>\* ASD 124 is only required for
operators\</FONT\>\');

htp.centerClose;

lib02.DisplayEpilog(Null, \'acistms2000.enter_criteria?i_pid=\' \|\|
i_pid, \'New Profile\');

exception when others then

htp.bold(\'Unable to retrieve data - Oracle Error \# \' \|\| sqlerrm);

end;

end;

END;

/

CREATE OR REPLACE PACKAGE CAL0001 IS

PROCEDURE display_page(i_pid IN VARCHAR2 DEFAULT null,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'),

i_month IN VARCHAR2 DEFAULT to_char(sysdate, \'MON\'));

PROCEDURE create_calendar(i_pid IN VARCHAR2 DEFAULT null,

i_year IN VARCHAR2,

i_month IN VARCHAR2);

END CAL0001;

/

CREATE OR REPLACE PACKAGE BODY CAL0001 IS

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Create frames to display calendar and schedule

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

PROCEDURE display_page(i_pid IN VARCHAR2 DEFAULT null, i_year IN
VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'), i_month IN VARCHAR2 DEFAULT
to_char(sysdate, \'MON\')) IS

TempDate DATE;

ErrorPos NUMBER(1);

TestNum NUMBER(4);

BEGIN

\-- Make sure year is valid and 4 digits in length

ErrorPos := 1;

TestNum := TO_NUMBER(i_year);

IF length(i_year) != 4 THEN

RAISE INVALID_NUMBER;

END IF;

\-- Parse date information

TempDate := to_date(\'01-\' \|\| i_month \|\| \'-\' \|\| i_year,
\'DD-MON-YYYY\');

\-- Create frames

ErrorPos := 2;

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.framesetOpen(\'245, \*\', \'\', \'\');

htp.frame(\'cal0001.create_calendar?i_pid=\' \|\| i_pid \|\|
\'&i_year=\' \|\| i_year \|\| \'&i_month=\' \|\| i_month, \'Calendar\',
\'0\', \'0\');

IF to_char(sysdate, \'YYYY\') = i_year AND to_char(sysdate, \'MON\') =
i_month THEN

htp.frame(\'cal0002.display_events?i_pid=\' \|\| i_pid \|\| \'&i_year=\'
\|\| i_year \|\| \'&i_month=\' \|\| to_char(TempDate, \'MM\') \|\| \'#\'
\|\| lpad(to_char(sysdate, \'DD\'), 2, \'0\'), \'Events\');

ELSE

htp.frame(\'cal0002.display_events?i_pid=\' \|\| i_pid \|\| \'&i_year=\'
\|\| i_year \|\| \'&i_month=\' \|\| to_char(TempDate, \'MM\') \|\|
\'#01\', \'Events\');

END IF;

htp.framesetClose;

htp.htmlClose;

\-- \*\*\* Error trap

exception when others then

if ErrorPos = 1 then

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The date you entered is
incorrect. Make sure the date format is correct and entered using the
full 4-digit year (Example: 01-JAN-1998). Click your browser\'\'s
\"Back\" button and correct the error.\');

else

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'Click your browser\'\'s
\"Back\" button and correct the error if necessary.\');

end if;

END;

\-- \*\*\* End display_page
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Create the calendar

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

PROCEDURE create_calendar(i_pid IN VARCHAR2 DEFAULT null, i_year IN
VARCHAR2, i_month IN VARCHAR2) IS

CURSOR cGetBadge IS

SELECT badge_no FROM ows_app_login

WHERE PID = i_pid;

rGetBadge cGetBadge%ROWTYPE;

TempDate DATE;

TempMonth VARCHAR2(3);

TempYear VARCHAR2(4);

StartDayOfWeek NUMBER(1);

Counter NUMBER(2);

ErrorPos NUMBER(2) := 0;

TestNum NUMBER(4);

Username VARCHAR2(50);

BEGIN

\-- Make sure year is valid and 4 digits in length

ErrorPos := 1;

TestNum := TO_NUMBER(i_year);

IF length(i_year) != 4 THEN

RAISE INVALID_NUMBER;

END IF;

\-- Parse date information

TempDate := to_date(\'01-\' \|\| i_month \|\| \'-\' \|\| i_year,
\'DD-MON-YYYY\');

TempMonth := to_char(TempDate, \'MON\');

TempYear := to_char(TempDate, \'YYYY\');

\-- Start the HTML Document

ErrorPos := 2;

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen(\'\', \'BGCOLOR=\"#D0D0D0\"\');

\-- Display titlebar

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"20\" CELLSPACING=\"0\"
CELLPADDING=\"0\" BGCOLOR=\"#0E2525\" WIDTH=\"100%\"\');

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"4\" COLOR=\"#FFFFFF\"\>&nbsp;APS Calendar &
Schedule\'),\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\"
BACKGROUND=\"/gen-img/apstext2.gif\"\');

htp.tableData(\'\<A NAME=\"Bottom\"
HREF=\"mailto:mis_mgrs@aps.anl.gov\"\>\<IMG
SRC=\"/gen-img/email_mis_button.gif\"
BORDER=\"0\"\>\</A\>\',\'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.tableData(\'\<A NAME=\"Bottom\" HREF=\"log0002.log_out\"
TARGET=\"\_top\"\>\<IMG SRC=\"/gen-img/logout_button.gif\"
BORDER=\"0\"\>\</A\>\',\'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.tableRowClose;

htp.tableClose;

htp.br;

\-- Center everything

htp.centerOpen;

\-- Get current user

/\*OPEN cGetBadge;

FETCH cGetBadge INTO rGetBadge;

CLOSE cGetBadge;

Username := initcap(lib02.GetUsername(rGetBadge.badge_no));\*/

\-- Open the main table that will contain the nav buttons, selecter and
the calendar

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\"
BGCOLOR=\"#B0B0B0\"\');

\--htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

\--htp.tableData(htf.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"2\" COLOR=\"#202020\"\>\' \|\|
Username),\'CENTER\',\'\',\'\',\'\',\'3\',\'BGCOLOR=\"#FFFFE0\"\');

\--htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD VALIGN=\"MIDDLE\" BGCOLOR=\"#F0F0F0\"\>\');

\-- Open the navigation button table and display it

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"\');

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0001.display_page?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(add_months(TempDate, -1), \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(add_months(TempDate, -1), \'MON\'), \'\<IMG
SRC=\"/gen-img/prev_month.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'),\'CENTER\'

,\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0001.display_page?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(sysdate, \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(sysdate, \'MON\'), \'\<IMG
SRC=\"/gen-img/today_button.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\'

);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0001.display_page?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(add_months(TempDate, 1), \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(add_months(TempDate, 1), \'MON\'), \'\<IMG
SRC=\"/gen-img/next_month.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'),\'CENTER\',\'

\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableRowClose;

htp.tableClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\>\');

\-- Open the selecter table

htp.formOpen(\'cal0001.display_page\', \'\', \'\_top\');

htp.formHidden(\'i_pid\', i_pid);

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\"\');

\-- Display the selecter fields and info

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<FONT SIZE=\"4\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>Navigation\'),\'CENTER\',\'\',\'\',\'\',\'2\',\'BGCOLOR=\"#303030\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Year:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.tableData(htf.formText(\'i_year\', 4, 4, i_year));

htp.tableRowClose;

htp.TableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>Month:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_month\', \'\', 1);

IF i_month = \'JAN\' THEN

htp.formSelectOption(\'January\', \'Y\', \'VALUE=\"JAN\"\');

ELSE

htp.formSelectOption(\'January\', NULL, \'VALUE=\"JAN\"\');

END IF;

IF i_month = \'FEB\' THEN

htp.formSelectOption(\'February\', \'Y\', \'VALUE=\"FEB\"\');

ELSE

htp.formSelectOption(\'February\', NULL, \'VALUE=\"FEB\"\');

END IF;

IF i_month = \'MAR\' THEN

htp.formSelectOption(\'March\', \'Y\', \'VALUE=\"MAR\"\');

ELSE

htp.formSelectOption(\'March\', NULL, \'VALUE=\"MAR\"\');

END IF;

IF i_month = \'APR\' THEN

htp.formSelectOption(\'April\', \'Y\', \'VALUE=\"APR\"\');

ELSE

htp.formSelectOption(\'April\', NULL, \'VALUE=\"APR\"\');

END IF;

IF i_month = \'MAY\' THEN

htp.formSelectOption(\'May\', \'Y\', \'VALUE=\"MAY\"\');

ELSE

htp.formSelectOption(\'May\', NULL, \'VALUE=\"MAY\"\');

END IF;

IF i_month = \'JUN\' THEN

htp.formSelectOption(\'June\', \'Y\', \'VALUE=\"JUN\"\');

ELSE

htp.formSelectOption(\'June\', NULL, \'VALUE=\"JUN\"\');

END IF;

IF i_month = \'JUL\' THEN

htp.formSelectOption(\'July\', \'Y\', \'VALUE=\"JUL\"\');

ELSE

htp.formSelectOption(\'July\', NULL, \'VALUE=\"JUL\"\');

END IF;

IF i_month = \'AUG\' THEN

htp.formSelectOption(\'August\', \'Y\', \'VALUE=\"AUG\"\');

ELSE

htp.formSelectOption(\'August\', NULL, \'VALUE=\"AUG\"\');

END IF;

IF i_month = \'SEP\' THEN

htp.formSelectOption(\'September\', \'Y\', \'VALUE=\"SEP\"\');

ELSE

htp.formSelectOption(\'September\', NULL, \'VALUE=\"SEP\"\');

END IF;

IF i_month = \'OCT\' THEN

htp.formSelectOption(\'October\', \'Y\', \'VALUE=\"OCT\"\');

ELSE

htp.formSelectOption(\'October\', NULL, \'VALUE=\"OCT\"\');

END IF;

IF i_month = \'NOV\' THEN

htp.formSelectOption(\'November\', \'Y\', \'VALUE=\"NOV\"\');

ELSE

htp.formSelectOption(\'November\', NULL, \'VALUE=\"NOV\"\');

END IF;

IF i_month = \'DEC\' THEN

htp.formSelectOption(\'December\', \'Y\', \'VALUE=\"DEC\"\');

ELSE

htp.formSelectOption(\'December\', NULL, \'VALUE=\"DEC\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<HR\>\' \|\| htf.formSubmit(\'\',
\'Display\'),\'RIGHT\',\'\',\'\',\'\',\'2\',\'\');

htp.tableRowClose;

\-- Close the selecter table

htp.tableClose;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\>\');

\-- Open the calendar table

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\"
BGCOLOR=\"303030\"\');

\-- Display calendar header

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"4\" FACE=\"Tahoma, Arial,
Helvetica\" COLOR=\"#FFFFFF\"\>\<B\>\' \|\| to_char(TempDate, \'MONTH\')
\|\| \' \' \|\| to_char(TempDate, \'YYYY\') \|\|
\'\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'7\',\'BGCOLOR=\"#303030\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Sun\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Mon\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Tue\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Wed\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Thu\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Fri\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"
COLOR=\"#FFFFFF\"\>\<B\>Sat\</B\>\</CENTER\>\',\'\',\'\',\'\',\'\',\'\',\'WIDTH=\"35\"
BGCOLOR=\"#808080\"\');

htp.tableRowClose;

\-- Blow through initial empty calendar cells

StartDayOfWeek := to_number(to_char(round(TempDate, \'W\'), \'D\'));

htp.tableRowOpen;

IF StartDayOfWeek \> 1 THEN

FOR Loop1 IN 1..StartDayOfWeek - 1 LOOP

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\"
COLOR=\"#000000\"\>-\',\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

END IF;

\-- Display calendar days in cells

Counter := StartDayOfWeek;

FOR Loop1 IN 1..to_number(to_char(last_day(TempDate), \'DD\')) LOOP

IF Loop1 = to_char(sysdate, \'DD\') THEN

IF to_char(sysdate, \'YYYY\') = i_year AND to_char(sysdate, \'MON\') =
i_month THEN

htp.tableData(htf.anchor2(\'cal0002.display_events?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(TempDate, \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(TempDate, \'MM\') \|\| \'#\' \|\| lpad(Loop1, 2, \'0\'),
htf.bold(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\" CO

LOR=\"#5050FF\"\>\' \|\| Loop1), \'\',
\'Events\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FFFFFF\"\');

ELSE

htp.tableData(htf.anchor2(\'cal0002.display_events?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(TempDate, \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(TempDate, \'MM\') \|\| \'#\' \|\| lpad(Loop1, 2, \'0\'),
\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\" COLOR=\"#303

030\"\>\' \|\| Loop1, \'\',
\'Events\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FFFFFF\"\');

END IF;

ELSE

htp.tableData(htf.anchor2(\'cal0002.display_events?i_pid=\' \|\| i_pid
\|\| \'&i_year=\' \|\| to_char(TempDate, \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(TempDate, \'MM\') \|\| \'#\' \|\| lpad(Loop1, 2, \'0\'),
\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\" COLOR=\"#303030\"

\>\' \|\| Loop1, \'\',
\'Events\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FFFFFF\"\');

END IF;

Counter := Counter + 1;

IF Counter = 8 THEN

Counter := 1;

htp.tableRowClose;

\-- Don\'t open a new row if last day of the month is on a Saturday

IF (TO_CHAR(last_day(TempDate), \'D\') \< 7 AND Loop1 \<\>
to_number(to_char(last_day(TempDate), \'DD\'))) THEN

htp.tableRowOpen;

END IF;

END IF;

END LOOP;

\-- Blow through remaining empty calendar cells

IF to_char(last_day(TempDate), \'D\') \< 7 THEN

FOR Loop1 IN 1..8 - Counter LOOP

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\"
COLOR=\"#000000\"\>-\',\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

htp.tableRowClose;

END IF;

\-- Close the calendar table

htp.tableClose;

\-- Close the main table

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

\-- Stop centering

htp.centerClose;

\-- Manually close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- \*\*\* Error trap

exception when others then

if ErrorPos = 1 then

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The date you entered is
incorrect. Make sure the date format is correct and entered using the
full 4-digit year (Example: 01-JAN-1998). Click your browser\'\'s
\"Back\" button and correct the error.\');

else

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'Click your browser\'\'s
\"Back\" button and correct the error if necessary.\');

end if;

htp.bodyClose;

htp.htmlClose;

END;

\-- \*\*\* End create_calendar
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

END CAL0001;

/

CREATE OR REPLACE PACKAGE cal0002 IS

PROCEDURE startPage (i_pid in varchar2 default \'NEW\');

PROCEDURE start_page (i_pid in varchar2 default \'NEW\');

PROCEDURE display_test(i_pid in varchar2 default NULL,i_year in varchar2
default NULL, i_month in varchar2 default NULL);

PROCEDURE display_events(i_pid in varchar2,i_year in varchar2,i_month in
varchar2);

PROCEDURE display_24mos(i_pid in varchar2);

PROCEDURE report_start_page (i_pid in varchar2 default \'NEW\');

END;

/

CREATE OR REPLACE PACKAGE BODY cal0002 IS

\-- 24-MAY-99 kem Restrict detail view to ALD_CAL_USER_PLUS (Dr.
Moncton, Rose, Kathy R.)

\--globals

g_OBJECTID DS_PERSON.OBJECTID%TYPE;

g_FIRSTNAME DS_PERSON.FIRSTNAME%TYPE;

g_LASTNAME DS_PERSON.LASTNAME%TYPE;

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'CAL0002\';

result := log0002.is_valid_pid(i_pid, p_app_name);

return result;

end;

end;

\--

function has_role (i_pid in varchar2, role_in in varchar2) return
boolean is

cursor get_username(p_pid varchar2) is

select \'OPS\$\' \|\| username as username

from ows_app_login

where pid = p_pid;

cursor get_role(user_name varchar2) is

select \*

from gen_role_privs

where grantee = user_name

and granted_role = role_in;

user_rec get_username%rowtype;

role_rec get_role%rowtype;

begin

open get_username(i_pid);

fetch get_username into user_rec;

\--htp.p(\'USERNAME=\' \|\| user_rec.username \|\| \' i_pid=\' \|\|
i_pid \|\| \' role=\' \|\| role_in);

for role_rec in get_role(user_rec.username) loop

if get_role%found then

close get_username;

return TRUE;

end if;

end loop;

return FALSE;

end;

\--get oo user

procedure get_oo_user_info(i_oo_user in varchar2) is

cursor c_oo_user is

select OBJECTID,FIRSTNAME,LASTNAME

from DS_PERSON

where username=upper(i_oo_user);

begin

open c_oo_user;

fetch c_oo_user into g_OBJECTID,g_FIRSTNAME,g_LASTNAME;

close c_oo_user;

end;

\--

function convertTime(i_BEGIN_T in NUMBER default NULL, i_END_T in NUMBER
default NULL) return VARCHAR2 is

beginHour number;

beginMin number;

endHour number;

endMin number;

beginH varchar2(2);

beginM varchar2(2);

endH varchar2(2);

endM varchar2(2);

l_BEGIN_T number;

l_BEGIN_D number;

l_END_T number;

l_END_D number;

beginTime varchar2(10);

endTime varchar2(10);

result varchar2(50);

begin

\--modify for day spanning

if i_END_T \> 1439 then

l_END_T := i_END_T - 1440;

else

l_END_T := i_END_T;

end if;

beginHour := floor(i_BEGIN_T/60);

beginMin := MOD(i_BEGIN_T,60);

endHour := floor(l_END_T/60);

endMin := MOD(l_END_T,60);

beginTime := to_char(to_date(beginHour \|\| \':\' \|\|
to_char(beginMin,\'09\'),\'HH24:MI\'),\'HH:MIam\');

endTime := to_char(to_date(endHour \|\| \':\' \|\|
to_char(endMin,\'09\'),\'HH24:MI\'),\'HH:MIam\');

result := beginTime \|\| \'-\' \|\| endTime;

return(result);

end;

\--

function printRecurOK(i_recurring in VARCHAR2,i_date IN DATE) return
boolean is

cursor inSide(p_recurring in varchar2,p_date in varchar2) is

select \'1\'

from DUAL

where INSTR(p_recurring,p_date) \> 0;

temp varchar2(1);

result BOOLEAN;

begin

open inSide(i_recurring,to_char(i_date,\'DD MM YYYY\'));

fetch inSide into temp;

if not inSide%NOTFOUND then

result := FALSE;

else

result := TRUE;

end if;

close inSide;

return (result);

end;

\--

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

startPage is the entry point for the package

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

PROCEDURE startPage (i_pid in varchar2 default \'NEW\') is

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'CAL0002\') then

log0002.login(\'CAL0002\',\'\',i_pid);

return;

end if;

\--

\-- Go to criteria page

\--

cal0001.display_page(i_pid,to_char(sysdate,\'YYYY\'),to_char(sysdate,\'MON\'));

\--

end;

\--

PROCEDURE report_start_page (i_pid in varchar2 default \'NEW\') is

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'CAL0002R\') then

log0002.login(\'CAL0002R\',\'\',i_pid);

return;

end if;

\--

\-- Go to criteria page

\--

cal0002.display_24mos(i_pid);

\--

end;

PROCEDURE start_page (i_pid in varchar2 default \'NEW\') is

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'CAL0002\') then

log0002.login(\'CAL0002\',\'\',i_pid);

return;

end if;

\--

\-- Go to criteria page

\--

cal0001.display_page(i_pid,to_char(sysdate,\'YYYY\'),to_char(sysdate,\'MON\'));

\--

end;

PROCEDURE display_test(i_pid in varchar2 default NULL,i_year in varchar2
default NULL, i_month in varchar2 default NULL) is

begin

htp.htmlOpen;

for ctr in 1..40 loop

htp.p(\'\<A NAME=\"\' \|\| to_char(ctr) \|\| \'\"\>Day=\' \|\|
to_char(ctr) \|\| \'\</A\> This is a jump point. It is \<BR\>\');

htp.p(\'Test point is numbered\<BR\>\');

htp.p(\'One second\<BR\>\');

htp.p(\'OK\...dumper \' \|\| to_char(ctr) \|\| \'\<BR\>\');

end loop;

htp.htmlClose;

end;

\--

PROCEDURE display_events(i_pid in varchar2,i_year in varchar2, i_month
in varchar2) is

\--EVENT TYPE 4000=Appointment

\-- 6000=Note

\-- No other active event type in Moncton\'s OO calendar

\-- thre are 14 rows of type 9000, the seem to be very old and
irrelevant

\-- Recurring Appointments are to be list as notes

cursor c_get_recurring(p_DAY in date,p_event_type in NUMBER) is

select

EVENT_ID,

SUBJECT,

BEGIN_D,

BEGIN_T,

END_D,

END_T,

EVENT_TYPE,

TIME_ZONE,

MSG_ID,

RECURRING

FROM OC_EVENT

WHERE CAL_ID=g_OBJECTID

AND EVENT_TYPE=p_event_type

AND HIDDEN_F IS NULL

AND RECURRING IS NOT NULL

AND ((p_DAY BETWEEN BEGIN_D and END_D)

OR SUBSTR(RECURRING,1,1)=to_char(p_DAY,\'D\'))

ORDER BY EVENT_TYPE desc, BEGIN_T;

cursor c_get_calendar(p_DAY in date,p_event_type in NUMBER) is

select

EVENT_ID,

SUBJECT,

BEGIN_D,

BEGIN_T,

END_D,

END_T,

EVENT_TYPE,

TIME_ZONE,

MSG_ID,

nvl(RECURRING,\'Not recurring\') AS RECURRING

FROM OC_EVENT

WHERE CAL_ID=g_OBJECTID

AND HIDDEN_F IS NULL

AND EVENT_TYPE=p_event_type

AND ((p_DAY BETWEEN BEGIN_D and END_D))

\--or p_DAY = END_D

\--or p_DAY = BEGIN_D)

\--OR SUBSTR(RECURRING,1,1)=to_char(p_DAY,\'D\'))

ORDER BY EVENT_TYPE desc, BEGIN_T, CREATE_DATE;

cursor c_NOTE(p_MSG_ID in NUMBER) is

select MSG_LINE

from OM_BODY

where MSG_ID=p_MSG_ID

AND PART=0;

r_EVENT OC_EVENT%ROWTYPE;

first_day date;

last_day date;

temp_date date;

displayEntry Boolean;

MSG_LINE OM_BODY.MSG_LINE%TYPE;

last_time varchar2(50);

this_time varchar2(50);

ctr number;

view_detail BOOLEAN;

begin

htp.htmlOpen;

htp.p(\'\<BODY BGCOLOR=\"#D0D0D0\"\>\');

view_detail := has_role(i_pid,\'ALD_CAL_USER_PLUS\');

if is_valid_pid(i_pid) then

get_oo_user_info(\'MONCTON\');

first_day := to_date(\'01-\' \|\| i_month \|\| \'-\' \|\|
i_year,\'DD-MM-YYYY\');

last_day := ADD_MONTHS(first_day,1) - 1;

temp_date := first_day;

while temp_date \<= last_day loop

htp.p(\'\<TABLE CELLSPACING=\"0\" CELLPADDING=\"2\" BORDER=\"0\"
WIDTH=\"100%\"\>\');

htp.p(\'\<TR BGCOLOR=\"#707070\"\>\');

htp.p(\'\<TD COLSPAN=\"2\"\>\<A NAME=\"\' \|\| to_char(temp_date,\'DD\')
\|\| \'\"\>\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>\<B\>\' \|\| to_char(temp_date,\'DD-MON-YYYY\') \|\|
\'\</A\>&nbsp&nbsp \' \|\| to_char(temp_date,\'Day\') \|\| \'
\</B\>\</FONT\>\</TD\>\</TR\>\');

\--display appointments

ctr := 0;

for r_get_calendar in c_get_calendar(temp_date,6000) loop

\--displayEntry;

htp.tableRowOpen;

If r_get_calendar.RECURRING = \'Not recurring\' then

if mod(ctr,2)=0 then

htp.p(\'\<TD BGCOLOR=\"#E0E0FF\" WIDTH=\"130\" NOWRAP\>\');

else

htp.p(\'\<TD BGCOLOR=\"#C9C9FF\" WIDTH=\"130\" NOWRAP\>\');

end if;

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T));

htp.p(\'\</FONT\>\</TD\>\');

htp.p(\'\<TD WIDTH=\"100%\" BGCOLOR=\"#FFFFFF\"\>\');

if view_detail then

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(r_get_calendar.SUBJECT);

end if; \--view detail

htp.p(\'\</FONT\>\</TD\>\');

end if;

htp.tableRowClose;

\--

ctr := ctr + 1;

end loop;

htp.tableClose;

\-- display notes

if view_detail then

htp.p(\'\<TABLE CELLSPACING=\"0\" CELLPADDING=\"1\" BORDER=\"0\"
WIDTH=\"100%\" BGCOLOR=\"#F0F0F0\"\>\');

for r_get_calendar in c_get_calendar(temp_date,4000) loop

\--displayEntry;

htp.tableRowOpen;

\--display image

htp.p(\'\<TD VALIGN=\"TOP\"\>\');

htp.p(\'\<IMG SRC=\"../../gen-img/bullet01.gif\"\>&nbsp\');

htp.p(\'\</TD\>\');

open C_NOTE(r_get_calendar.MSG_ID);

fetch C_NOTE into MSG_LINE;

close C_NOTE;

htp.p(\'\<TD VALIGN=\"TOP\" WIDTH=\"100%\"\>\');

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(nvl(r_get_calendar.SUBJECT,MSG_LINE));

htp.p(\'\</FONT\>\</TD\>\</TR\>\');

htp.tableRowClose;

\--

end loop;

htp.tableClose;

end if; \--view detail

htp.NL;

\-- display recurring appointments as notes before 4/1/1999. No
recurring display after 4/1/1999

\--display appointments

/\*if temp_date \< to_date(\'01-APR-1999\',\'DD-MON-YYYY\') then

last_time := \'\';

for r_get_calendar in c_get_calendar(temp_date,6000) loop

\--displayEntry;

htp.tableRowOpen;

If r_get_calendar.RECURRING != \'Not recurring\' then

\--htp.tableData(convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T));

if printRecurOK(r_get_calendar.RECURRING,temp_date) then

this_time := convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T);

\--if last_time != this_time then

htp.p(\'\<TD colspan=\"2\"\>\<UL\>\<LI\>\'
\|\|to_char(r_get_calendar.event_id) \|\| \' \' \|\|
r_get_calendar.SUBJECT \|\| \'\</LI\>\</UL\>\</TD\>\');

\--end if;

last_time := this_time;

end if;

end if;

htp.tableRowClose;

\--

end loop;

end if;\*/

temp_date := temp_date + 1;

end loop;

\--htp.p(\'VALID PID\...first day \' \|\| to_char(first_day));

\--htp.p(g_OBJECTID);

end if;

htp.bodyClose;

htp.htmlClose;

EXCEPTION

when others then

htp.p(\'Problem please report to mis_mgrs:\' \|\| sqlerrm);

end;

PROCEDURE display_24mos(i_pid in varchar2) is

\--EVENT TYPE 4000=Appointment

\-- 6000=Note

\-- No other active event type in Moncton\'s OO calendar

\-- thre are 14 rows of type 9000, the seem to be very old and
irrelevant

cursor c_get_calendar(p_DAY in date,p_event_type in NUMBER) is

select

EVENT_ID,

SUBJECT,

BEGIN_D,

BEGIN_T,

END_D,

END_T,

EVENT_TYPE,

TIME_ZONE,

MSG_ID,

nvl(RECURRING,\'Not recurring\') AS RECURRING

FROM OC_EVENT

WHERE CAL_ID=g_OBJECTID

AND HIDDEN_F IS NULL

AND EVENT_TYPE=p_event_type

AND ((p_DAY BETWEEN BEGIN_D and END_D))

\--or p_DAY = END_D

\--or p_DAY = BEGIN_D)

\--OR SUBSTR(RECURRING,1,1)=to_char(p_DAY,\'D\'))

ORDER BY EVENT_TYPE desc, BEGIN_T;

cursor c_NOTE(p_MSG_ID in NUMBER) is

select MSG_LINE

from OM_BODY

where MSG_ID=p_MSG_ID

AND PART=0;

r_EVENT OC_EVENT%ROWTYPE;

first_day date;

last_day date;

temp_date date;

displayEntry Boolean;

MSG_LINE OM_BODY.MSG_LINE%TYPE;

last_time varchar2(50);

this_time varchar2(50);

ctr number;

begin

htp.htmlOpen;

htp.p(\'\<BODY BGCOLOR=\"#D0D0D0\"\>\');

if is_valid_pid(i_pid) then

get_oo_user_info(\'MONCTON\');

first_day := to_date(\'01-\' \|\| to_char(sysdate,\'MM\') \|\| \'-\'
\|\| to_char(sysdate,\'YYYY\'),\'DD-MM-YYYY\');

last_day := ADD_MONTHS(first_day,24) - 1;

temp_date := first_day;

while temp_date \<= last_day loop

htp.p(\'\<TABLE CELLSPACING=\"0\" CELLPADDING=\"2\" BORDER=\"0\"
WIDTH=\"100%\"\>\');

htp.p(\'\<TR BGCOLOR=\"#707070\"\>\');

htp.p(\'\<TD COLSPAN=\"2\"\>\<A NAME=\"\' \|\| to_char(temp_date,\'DD\')
\|\| \'\"\>\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>\<B\>\' \|\| to_char(temp_date,\'DD-MON-YYYY\') \|\|
\'\</A\>&nbsp&nbsp \' \|\| to_char(temp_date,\'Day\') \|\| \'
\</B\>\</FONT\>\</TD\>\</TR\>\');

\--display appointments

ctr := 0;

for r_get_calendar in c_get_calendar(temp_date,6000) loop

\--displayEntry;

htp.tableRowOpen;

If r_get_calendar.RECURRING = \'Not recurring\' then

if mod(ctr,2)=0 then

htp.p(\'\<TD BGCOLOR=\"#E0E0FF\" WIDTH=\"130\" NOWRAP\>\');

else

htp.p(\'\<TD BGCOLOR=\"#C9C9FF\" WIDTH=\"130\" NOWRAP\>\');

end if;

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T));

htp.p(\'\</FONT\>\</TD\>\');

htp.p(\'\<TD WIDTH=\"100%\" BGCOLOR=\"#FFFFFF\"\>\');

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(r_get_calendar.SUBJECT);

htp.p(\'\</FONT\>\</TD\>\');

end if;

htp.tableRowClose;

\--

ctr := ctr + 1;

end loop;

htp.tableClose;

\-- display notes

htp.p(\'\<TABLE CELLSPACING=\"0\" CELLPADDING=\"1\" BORDER=\"0\"
WIDTH=\"100%\" BGCOLOR=\"#F0F0F0\"\>\');

for r_get_calendar in c_get_calendar(temp_date,4000) loop

\--displayEntry;

htp.tableRowOpen;

\--display image

htp.p(\'\<TD VALIGN=\"TOP\"\>\');

htp.p(\'\<IMG SRC=\"../../gen-img/bullet01.gif\"\>&nbsp\');

htp.p(\'\</TD\>\');

open C_NOTE(r_get_calendar.MSG_ID);

fetch C_NOTE into MSG_LINE;

close C_NOTE;

htp.p(\'\<TD VALIGN=\"TOP\" WIDTH=\"100%\"\>\');

htp.p(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"2\"
COLOR=\"#202020\"\>\');

htp.p(nvl(r_get_calendar.SUBJECT,MSG_LINE));

htp.p(\'\</FONT\>\</TD\>\</TR\>\');

htp.tableRowClose;

\--

end loop;

htp.tableClose;

htp.NL;

\-- display recurring appointments as notes before 4/1/1999. No
recurring display after 4/1/1999

\--display appointments

/\*if temp_date \< to_date(\'01-APR-1999\',\'DD-MON-YYYY\') then

last_time := \'\';

for r_get_calendar in c_get_calendar(temp_date,6000) loop

\--displayEntry;

htp.tableRowOpen;

If r_get_calendar.RECURRING != \'Not recurring\' then

\--htp.tableData(convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T));

if printRecurOK(r_get_calendar.RECURRING,temp_date) then

this_time := convertTime(r_get_calendar.BEGIN_T,r_get_calendar.END_T);

\--if last_time != this_time then

htp.p(\'\<TD colspan=\"2\"\>\<UL\>\<LI\>\'
\|\|to_char(r_get_calendar.event_id) \|\| \' \' \|\|
r_get_calendar.SUBJECT \|\| \'\</LI\>\</UL\>\</TD\>\');

\--end if;

last_time := this_time;

end if;

end if;

htp.tableRowClose;

\--

end loop;

end if;\*/

temp_date := temp_date + 1;

end loop;

\--htp.p(\'VALID PID\...first day \' \|\| to_char(first_day));

\--htp.p(g_OBJECTID);

end if;

htp.bodyClose;

htp.htmlClose;

EXCEPTION

when others then

htp.p(sqlerrm);

end;

END cal0002;

/

CREATE OR REPLACE PACKAGE CAL0003 IS

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\');

FUNCTION ConvertOracleTime(i_time in NUMBER DEFAULT NULL) RETURN
VARCHAR2;

PROCEDURE display_listview(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'),

i_month IN VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL,

i_time IN NUMBER DEFAULT NULL);

PROCEDURE display_toolbar(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_appointment_header(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_appointments(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_navigation(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_notes(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_small_calendar(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE change_color(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_color IN VARCHAR2);

PROCEDURE change_note_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_action IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL,

i_recurring IN VARCHAR2 DEFAULT \'N\');

PROCEDURE change_note(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_operation IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL,

i_subject IN VARCHAR2 DEFAULT NULL,

i_time IN VARCHAR2 DEFAULT NULL,

i_prev_position IN NUMBER DEFAULT NULL,

i_new_position IN NUMBER DEFAULT NULL,

i_color IN VARCHAR2 DEFAULT NULL,

i_begin_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_end_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_period_type IN VARCHAR2 DEFAULT NULL,

i_period IN VARCHAR2 DEFAULT NULL,

i_non_workday IN VARCHAR2 DEFAULT NULL,

i_day_of_week IN VARCHAR2 DEFAULT NULL,

i_week_of_month IN VARCHAR2 DEFAULT NULL,

i_day_of_month IN VARCHAR2 DEFAULT NULL,

i_date_of_year IN VARCHAR2 DEFAULT NULL,

i_recurring IN VARCHAR2 DEFAULT \'N\',

i_range IN VARCHAR2 DEFAULT NULL,

i_recur_id IN VARCHAR2 DEFAULT NULL);

PROCEDURE change_appointment_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_action IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL,

i_start_time IN VARCHAR2 DEFAULT NULL,

i_end_time IN VARCHAR2 DEFAULT NULL,

i_recurring IN VARCHAR2 DEFAULT \'N\');

PROCEDURE change_appointment(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_operation IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL,

i_subject IN VARCHAR2 DEFAULT NULL,

i_start_date IN VARCHAR2 DEFAULT NULL,

i_end_date IN VARCHAR2 DEFAULT NULL,

i_start_time IN VARCHAR2 DEFAULT NULL,

i_end_time IN VARCHAR2 DEFAULT NULL,

i_location IN VARCHAR2 DEFAULT NULL,

i_color IN VARCHAR2 DEFAULT NULL,

i_detail IN VARCHAR2 DEFAULT NULL,

i_timezone IN VARCHAR2 DEFAULT NULL,

i_period_type IN VARCHAR2 DEFAULT NULL,

i_period IN VARCHAR2 DEFAULT NULL,

i_non_workday IN VARCHAR2 DEFAULT NULL,

i_day_of_week IN VARCHAR2 DEFAULT NULL,

i_week_of_month IN VARCHAR2 DEFAULT NULL,

i_day_of_month IN VARCHAR2 DEFAULT NULL,

i_date_of_year IN VARCHAR2 DEFAULT NULL,

i_recurring IN VARCHAR2 DEFAULT \'N\',

i_range IN VARCHAR2 DEFAULT NULL,

i_recur_id IN VARCHAR2 DEFAULT NULL);

PROCEDURE display_legend(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE change_legend_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE change_legend(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_color IN lib.val_arr,

i_description IN lib.val_arr);

PROCEDURE set_default_calendar(i_calendar IN VARCHAR2,

i_badge IN VARCHAR2,

i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

END CAL0003;

/

CREATE OR REPLACE PACKAGE BODY CAL0003 IS

\-- \*\*\* Declare global constants/variables \*\*\*

CR VARCHAR2(1) := chr(13);

LF VARCHAR2(1) := chr(10);

ARGONNE_COLOR VARCHAR2(7) := \'C0C0FF\';

OAK_RIDGE_COLOR VARCHAR2(7) := \'FFFFC0\';

TRAVEL_COLOR VARCHAR2(7) := \'C0FFC0\';

PAGE_BACKGROUND_COLOR VARCHAR2(7) := \'#C0C0C0\';

TABLE_CELL_PRIMARY VARCHAR2(7) := \'#303030\';

TABLE_CELL_SECONDARY VARCHAR2(7) := \'#808080\';

TABLE_CELL_MOD VARCHAR2(7) := \'#3030C0\';

TABLE_CELL_DEFAULT VARCHAR2(7) := \'#C0C0C0\';

STYLE_ALTER_LINKS VARCHAR2(200) := \'A {text-decoration: none;} A:hover
{text-decoration: underline;}\';

STYLE_BOLD VARCHAR2(200) := \'B {font-weight: bold;}\';

STYLE_HEADING_01 VARCHAR2(200) := \'.Heading01 {font-family: Tahoma,
Arial, Helvetica; font-size: 13pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_HEADING_02 VARCHAR2(200) := \'.Heading02 {font-family: Tahoma,
Arial, Helvetica; font-size: 10pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_SMALL_01 VARCHAR2(200) := \'.Small01 {font-family: Tahoma, Arial,
Helvetica; font-size: 8pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_NORMAL VARCHAR2(200) := \'.Normal {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_TABLE_DATA VARCHAR2(200) := \'TD {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_FORMS VARCHAR2(200) := \'textarea {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

\-- \*\*\* Log the user in with a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\') IS

begin

IF (i_pid IS NULL) OR (i_pid = \'NEW\') OR (NOT
log0002.is_valid_pid(i_pid, \'CAL0003\')) THEN

log0002.login(\'CAL0003\', \'\', i_pid);

RETURN;

END IF;

\-- Go to default startup page

cal0003.display_listview(i_pid);

end;

\-- \*\*\* Make sure user has a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION is_valid_pid(i_pid IN VARCHAR2) RETURN BOOLEAN IS

result BOOLEAN;

p_app_name VARCHAR2(30);

BEGIN

p_app_name := \'CAL0003\';

result := log0002.is_valid_pid(i_pid, p_app_name);

RETURN result;

END;

\-- \*\*\* Convert Oracle Office times to real time \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION ConvertOracleTime(i_time in NUMBER DEFAULT NULL) RETURN
VARCHAR2 IS

\-- Declare constants/variables

TimeHour NUMBER;

TimeMin NUMBER;

NewTime NUMBER;

ConvertedTime VARCHAR2(10);

BEGIN

\-- Convert time

TimeHour := floor(i_time / 60);

TimeMin := mod(i_time, 60);

\-- Create time string

ConvertedTime := to_char(to_date(TimeHour \|\| \':\' \|\|
to_char(TimeMin, \'09\'), \'hh24:mi\'), \'hh:mi AM\');

\-- Return to calling procedure

RETURN(ConvertedTime);

END;

\-- \*\*\* Convert real times to Oracle Office times \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION ConvertRealTime(i_hour in NUMBER DEFAULT NULL, i_minute IN
NUMBER DEFAULT NULL) RETURN NUMBER IS

\-- Declare constants/variables

OracleTime NUMBER;

BEGIN

\-- Convert time

OracleTime := (i_hour \* 60) + i_minute;

\-- Return to calling procedure

RETURN(OracleTime);

END;

\-- \*\*\* Return a concatinated string of the user\'s privileges for
the passed calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION GetPrivs(i_calendar in VARCHAR2, i_badge IN VARCHAR2) RETURN
VARCHAR2 IS

\-- Declare cursors

CURSOR cGetPrivs(CalendarID IN varchar2, BadgeNo IN VARCHAR2) IS

SELECT privs

FROM pim_privs_table

WHERE pim_object_id = CalendarID AND

grantee_badge = BadgeNo;

\-- Declare constants/variables

UserPrivileges VARCHAR2(100) := \'\';

BEGIN

\-- Create privilege string

FOR Loop1 IN cGetPrivs(i_calendar, i_badge) LOOP

UserPrivileges := UserPrivileges \|\| Loop1.privs \|\| \', \';

END LOOP;

\-- Return to calling procedure

RETURN(UserPrivileges);

END;

\-- \*\*\* Pad single digit numbers in the comma delimited string to two
digits \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION PadDayOfMonth(i_string IN VARCHAR2) RETURN VARCHAR2 IS

\-- Declare constants/variables

PrevPos NUMBER := 0;

SepPos NUMBER := -1;

NewString VARCHAR2(256) := \'\';

BEGIN

\-- Build the new string

WHILE SepPos \<\> 0 LOOP

SepPos := instr(i_string, \',\', PrevPos + 1);

IF SepPos \<\> 0 THEN

NewString := NewString \|\| lpad(substr(i_string, PrevPos + 1, SepPos -
PrevPos - 1), 2, \'0\') \|\|\',\';

PrevPos := SepPos;

END IF;

END LOOP;

\-- Return to calling procedure

RETURN(rtrim(NewString, \',\'));

END;

\-- \*\*\* Make sure the comma delimited string contains only numbers
\*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION IsNumeric(i_string IN VARCHAR2) RETURN BOOLEAN IS

\-- Declare constants/variables

PrevPos NUMBER := 0;

SepPos NUMBER := -1;

NewString VARCHAR2(256) := \'\';

TestNum NUMBER;

BEGIN

\-- Build the new string

WHILE SepPos \<\> 0 LOOP

SepPos := instr(i_string, \',\', PrevPos + 1);

IF SepPos \<\> 0 THEN

NewString := NewString \|\| substr(i_string, PrevPos + 1, SepPos -
PrevPos - 1);

PrevPos := SepPos;

END IF;

END LOOP;

\-- Return to calling procedure

TestNum := to_number(NewString);

RETURN(TRUE);

\-- Error Trap

EXCEPTION

WHEN others THEN RETURN(FALSE);

END;

\-- \*\*\* Send an e-mail using Kevin\'s snappy SQR \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE run_print_it(i_type IN VARCHAR2, i_event_id in VARCHAR2,
i_time IN VARCHAR2,

i_email IN VARCHAR2) IS

\-- Declare variables

return_status VARCHAR2(255);

str VARCHAR2(255);

BEGIN

str := \'rascal/rascal\';

mis_util.utl_print_it(\'\$mis_reports/\',\'cal_update_email\',\'B\',\'mis3\',\'P\',\'SQR\',STR,\'NONE\',

i_type,i_event_id,i_time,i_email,\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

\--htp.p(i_type \|\| \' - \' \|\| i_event_id \|\| \' - \' \|\| i_time
\|\| \' - \' \|\| i_email \|\| \' - \' \|\| return_status);

END;

\-- \*\*\* Setup Listview display \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_listview(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'), i_month IN
VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL, i_time IN NUMBER DEFAULT NULL) IS

\-- Declare cursors

CURSOR cGetGrantedCalIDs(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'READ_ALL\' OR a.privs = \'WRITE\')
AND

a.inactive_flag = \'N\'

ORDER BY a.pim_object_id;

rGetGrantedCalIDs cGetGrantedCalIDs%ROWTYPE;

CURSOR cGetLastCalID IS

SELECT last_cal_pim_object_id

FROM pim_session_table

WHERE pid = i_pid;

rGetLastCalID cGetLastCalID%ROWTYPE;

CURSOR cSessionUpdateInsert IS

SELECT COUNT(pid)

FROM pim_session_table

WHERE pid = i_pid;

CURSOR cGetDefaultCalendar(BadgeNo IN VARCHAR2) IS

SELECT pim_object_default

FROM cal_user_prefs

WHERE badge_no = BadgeNo;

rGetDefaultCalendar cGetDefaultCalendar%ROWTYPE;

\-- Declare constants/variables

i_date VARCHAR2(11);

CurrentUser VARCHAR2(10) := \'\';

CalendarID VARCHAR2(9);

BrowserType VARCHAR2(255);

NewDay VARCHAR2(2);

TestVal NUMBER := 0;

ErrorPos NUMBER;

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the badge no for the current user

CurrentUser := lib02.GetBadge(i_pid);

\-- Exit if user does not have access to the selected calendar

ErrorPos := 1;

IF i_calendar IS NOT NULL AND GetPrivs(i_calendar,
lib02.GetBadge(i_pid)) IS NULL THEN

RAISE VALUE_ERROR;

RETURN;

END IF;

\-- Update session table

ErrorPos := 2;

IF i_calendar IS NOT NULL THEN

OPEN cSessionUpdateInsert;

FETCH cSessionUpdateInsert INTO TestVal;

CLOSE cSessionUpdateInsert;

IF (TestVal = 0) OR (TestVal IS NULL) THEN

INSERT INTO pim_session_table(

pid, tx_date, last_cal_pim_object_id)

VALUES(

i_pid, sysdate, i_calendar);

ELSE

UPDATE pim_session_table

SET tx_date = sysdate, last_cal_pim_object_id = i_calendar

WHERE pid = i_pid;

END IF;

END IF;

\-- Decide where to get the calendar ID to use

IF i_calendar IS NOT NULL THEN

\-- Use povided calendar ID

CalendarID := i_calendar;

ELSE

\-- Get last used calendar ID from session table (if available)

OPEN cGetLastCalID;

FETCH cGetLastCalID INTO rGetLastCalID;

IF rGetLastCalID.last_cal_pim_object_id IS NULL THEN

\-- Check to see if the user has set a default calendar

OPEN cGetDefaultCalendar(CurrentUser);

FETCH cGetDefaultCalendar INTO rGetDefaultCalendar;

IF cGetDefaultCalendar%NOTFOUND THEN

\-- Get the first available calendar

OPEN cGetGrantedCalIDs(CurrentUser);

FETCH cGetGrantedCalIDs INTO rGetGrantedCalIDs;

IF cGetGrantedCalIDs%NOTFOUND THEN

\-- User has no access;

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen;

lib02.DisplayError(\'\', \'No calendars available\', \'\', \'You do not
have privilages to view any calendars in this system.\');

htp.bodyClose;

htp.htmlClose;

RETURN;

ELSE

\-- Use first found calendar ID

CalendarID := rGetGrantedCalIDs.pim_object_id;

END IF;

CLOSE cGetGrantedCalIDs;

ELSE

\-- Use user selected default calendar

CalendarID := rGetDefaultCalendar.pim_object_default;

END IF;

CLOSE cGetDefaultCalendar;

ELSE

\-- Use last used calendar

CalendarID := rGetLastCalID.last_cal_pim_object_id;

END IF;

CLOSE cGetLastCalID;

END IF;

\-- Determine day to be used

IF i_day IS NULL THEN

IF (i_month = to_char(sysdate, \'MON\')) AND (i_year = to_char(sysdate,
\'YYYY\')) THEN

NewDay := ltrim(to_char(sysdate, \'DD\'), \'0\');

ELSE

NewDay := \'1\';

END IF;

ELSE

NewDay := i_day;

END IF;

\-- Combine individual date elements

i_date := NewDay \|\| \'-\' \|\| i_month \|\| \'-\' \|\| i_year;

\-- Open the HTML page

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

\-- Get the web browser type the user is using

BrowserType := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

\-- Create the Main/Toolbar frame

htp.framesetOpen(\'50, \*\', \'\', \'FRAMEBORDER=\"NO\" BORDER=\"0\"\');

htp.frame(\'cal0003.display_toolbar?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'Toolbar\', \'0\', \'0\');

\-- Create the Appointment and Navigation master frame

htp.framesetOpen(\'\', \'\*, 275\', \'\');

\-- Create the Appointment and Notes/Calendar frames

htp.framesetOpen(\'\*, 170\', \'\', \'\');

\-- Create the Appointment Header and Appointments frames

IF instr(BrowserType, \'MSIE\', 1) \> 0 THEN

htp.framesetOpen(\'51, \*\', \'\', \'\');

ELSE

htp.framesetOpen(\'56, \*\', \'\', \'\');

END IF;

htp.frame(\'cal0003.display_appointment_header?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'AppointmentHeader\', \'5\', \'5\');

IF i_time IS NULL THEN

htp.frame(\'cal0003.display_appointments?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date \|\|
\'#360\', \'Appointments\', \'5\', \'5\');

ELSE

htp.frame(\'cal0003.display_appointments?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date \|\|
\'#\' \|\| i_time, \'Appointments\', \'5\', \'5\');

END IF;

htp.framesetClose;

\-- Create the Notes and Calendar frames

htp.framesetOpen(\'\', \'\*, 225\', \'\');

htp.frame(\'cal0003.display_notes?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'Notes\', \'5\', \'5\');

htp.frame(\'cal0003.display_small_calendar?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'Calendar\', \'5\', \'5\');

htp.framesetClose;

htp.framesetClose;

\-- Create the Navigation frame

htp.frame(\'cal0003.display_navigation?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'Navigation\', \'5\', \'5\');

htp.framesetClose;

\-- Close the main frameset

htp.framesetClose;

\-- Close the HTML page

htp.htmlClose;

\-- End valid PID check

END IF;

\-- Error trap

EXCEPTION WHEN others THEN

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen;

IF ErrorPos = 1 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'You do not have access
rights to the selected calendar. Click your browser\'\'s \"Back\" button
and correct the error if necessary.\');

ELSE

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'Click your browser\'\'s
\"Back\" button and correct the error if necessary.\');

END IF;

htp.bodyClose;

htp.htmlClose;

END;

\-- \*\*\* Display the calendar application toolbar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_toolbar(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page

htp.htmlOpen;

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the main table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"0\"\');

\-- Display the toolbar buttons

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0006.report_page?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date, \'\<IMG
SRC=\"/gen-img/reports_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.tableData(htf.anchor2(\'cal0003.change_appointment_page?i_pid=\'
\|\| i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=NEW\', \'\<IMG
SRC=\"/gen-img/appt_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'Navigation\'), \'LEFT\', \'\', \'\', \'\',

\'\', \'\');

htp.tableData(htf.anchor2(\'cal0003.change_appointment_page?i_pid=\'
\|\| i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=NEW&i_recurring=Y\', \'\<IMG
SRC=\"/gen-img/recappt_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'Navigation\'), \'LE

FT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0003.change_note_page?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_action=NEW\', \'\<IMG SRC=\"/gen-img/note_toolbar_btn.gif\"
BORDER=\"0\"\>\', \'\', \'Navigation\'), \'LEFT\', \'\', \'\', \'\',
\'\', \'\')

;

htp.tableData(htf.anchor2(\'cal0003.change_note_page?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_action=NEW&i_recurring=Y\', \'\<IMG
SRC=\"/gen-img/recnote_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'Navigation\'), \'LEFT\', \'\'

, \'\', \'\', \'\', \'\');

END IF;

htp.tableData(htf.anchor2(\'cal0003.display_navigation?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date, \'\<IMG SRC=\"/gen-img/nav_toolbar_btn.gif\" BORDER=\"0\"\>\',
\'\', \'Navigation\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltr

im(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/monthview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0007.display_calendarview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|

ltrim(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/calview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0003.display_legend?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date,
\'\<IMG SRC=\"/gen-img/legend_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'Navigation\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'log0002.log_out\', \'\<IMG
SRC=\"/gen-img/logout_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'WIDTH=\"100%\"\');

htp.tableRowClose;

\-- Close the main table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display appointments header \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_appointment_header(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

DisplayName VARCHAR2(50);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Get the calendar\'s display name

SELECT display_name INTO DisplayName

FROM pim_object_table

WHERE pim_object_id = i_calendar;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_DEFAULT \|\| \'\"
LINK=\"#000000\" VLINK=\"#000000\" ALINK=\"#000000\"\');

\-- Open the table to display header information

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLPADDING=\"1\" CELLSPACING=\"0\"\');

htp.tableRowOpen;

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.tableData(htf.anchor2(\'cal0003.change_color?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_color=\' \|\| ARGONNE_COLOR, \'\<IMG HSPACE=\"0\"
ALIGN=\"ABSMIDDLE\" SRC=\"/gen-img/blue_color_btn.gif\"
BORDER=\"0\"\>\', \'\', \'\_top\'

), \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.change_color?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_color=\' \|\| OAK_RIDGE_COLOR, \'\<IMG HSPACE=\"0\"
ALIGN=\"ABSMIDDLE\" SRC=\"/gen-img/yellow_color_btn.gif\"
BORDER=\"0\"\>\', \'\', \'\_

top\'), \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.change_color?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_color=\' \|\| TRAVEL_COLOR, \'\<IMG HSPACE=\"0\"
ALIGN=\"ABSMIDDLE\" SRC=\"/gen-img/green_color_btn.gif\"
BORDER=\"0\"\>\', \'\', \'\_top\'

), \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.change_color?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_color=DEFAULT\', \'\<IMG HSPACE=\"0\" ALIGN=\"ABSMIDDLE\"
SRC=\"/gen-img/grey_color_btn.gif\" BORDER=\"0\"\>\', \'\', \'\_top\'),
\'\', \'\',

\'\', \'\', \'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

ELSE

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_PRIMARY \|\| \'\"\');

END IF;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
\'Appointments\', \'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_PRIMARY \|\| \'\" WIDTH=\"100%\"\');

IF DisplayName IS NOT NULL THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| DisplayName,
\'RIGHT\', \'\', \'\', \'\', \'\', \'NOWRAP BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

END IF;

htp.tableRowClose;

\-- Display the current date

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Time\',
\'CENTER\', \'\', \'\', \'\', \'4\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\|
rtrim(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'Day\')) \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \', Month DD, YYYY\'),
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"100%\"\');

IF DisplayName IS NOT NULL THEN

htp.tableData(\'&nbsp;\', \'CENTER\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"\' \|\| TABLE_CELL_SECONDARY \|\| \'\"\');

END IF;

htp.tableRowClose;

\-- Close the table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display appointments \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_appointments(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetCellProperties(CalendarID IN NUMBER, CalDate IN VARCHAR2) IS

SELECT /\*+ rule \*/color

FROM cal_display_properties

WHERE pim_object_id = CalendarID AND

display_date = to_date(CalDate, \'DD-MON-YYYY\');

rGetCellProperties cGetCellProperties%ROWTYPE;

CURSOR cGetEvents(CalendarID IN VARCHAR2, CalDate IN VARCHAR2,
CalBeginTime IN NUMBER, CalNextTime IN NUMBER) IS

SELECT subject, event_id, begin_time, end_time, color, recur_event_id

FROM cal_event

WHERE pim_object_id = CalendarID AND

begin_date = to_date(CalDate, \'DD-MON-YYYY\') AND

(begin_time between CalBeginTime AND CalNextTime) AND

inactive = \'N\' AND

(event_type = 6000 OR event_type = 9000)

ORDER BY begin_time;

\-- Declare constants/variables

ScheduleTime DATE := to_date(\'5:00 AM\', \'hh:mi AM\');

CellColor VARCHAR2(7);

UserPrivs VARCHAR2(100) := \'\';

TempBeginTime NUMBER;

TempNextTime NUMBER;

TempBegin NUMBER;

TempEnd NUMBER;

EventCount NUMBER(2);

RowsToSpan NUMBER(6);

Counter NUMBER := 0;

TempNum NUMBER;

RecurringEvent VARCHAR2(1);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Get the properties for this cell

OPEN cGetCellProperties(i_calendar, i_date);

FETCH cGetCellProperties INTO rGetCellProperties;

IF cGetCellProperties%NOTFOUND THEN

CellColor := \'DEFAULT\';

ELSE

CellColor := rGetCellProperties.color;

END IF;

CLOSE cGetCellProperties;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_ALTER_LINKS);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(\'\</STYLE\>\');

\--jslib.drag(\'Navigation\', \'cal0003.change_appointment_page?i_pid=\'
\|\| i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=NEW&i_start_time=\" + startTime +
\"&i_end_time=\" + endTime\');

IF CellColor \<\> \'DEFAULT\' THEN

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| CellColor \|\| \'\"
LINK=\"#000000\" VLINK=\"#000000\" ALINK=\"#000000\"\');

ELSE

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_DEFAULT \|\| \'\"
LINK=\"#000000\" VLINK=\"#000000\" ALINK=\"#000000\"\');

END IF;

\-- Open the table to display times and appointments

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"1\" WIDTH=\"100%\"
CELLPADDING=\"1\" CELLSPACING=\"3\"\');

\-- Display times and appointments

FOR Loop1 IN 1..38 LOOP

\-- Calculate event range

TempBeginTime := ConvertRealTime(to_char(ScheduleTime, \'hh24\'),
to_char(ScheduleTime, \'mi\'));

TempNextTime := ConvertRealTime(to_char(ScheduleTime + .02083,
\'hh24\'), to_char(ScheduleTime + .02083, \'mi\')) - 1;

\-- Display time

htp.tableRowOpen;

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.tableData(htf.anchor2(\'cal0003.change_appointment_page?i_pid=\'
\|\| i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=NEW&i_start_time=\' \|\|
ConvertRealTime(to_char(ScheduleTime, \'hh24\'), to_char(ScheduleTime,
\'mi\'))

, htf.bold(to_char(ScheduleTime, \'hh:mi AM\')), TempBeginTime,
\'Navigation\'), \'LEFT\', \'\', \'\', \'\', \'\', \'WIDTH=\"10%\"
NOWRAP VALIGN=\"TOP\"\');

\--htp.tableData(htf.anchor2(ConvertRealTime(to_char(ScheduleTime,
\'hh24\'), to_char(ScheduleTime, \'mi\')),
htf.bold(to_char(ScheduleTime, \'hh:mi AM\')), TempBeginTime,
\'Navigation\'), \'LEFT\', \'\', \'\', \'\', \'\', \'WIDTH=\"10%\"
NOWRAP VALIGN=\"TOP\"\');

ELSE

\--htp.tableData(htf.bold(to_char(ScheduleTime, \'hh:mi AM\')),
\'CENTER\', \'\', \'\', \'\', \'\', \'WIDTH=\"10%\" NOWRAP
VALIGN=\"TOP\"\');

htp.tableData(htf.anchor2(\'\', htf.bold(to_char(ScheduleTime, \'hh:mi
AM\')), TempBeginTime, \'Navigation\'), \'LEFT\', \'\', \'\', \'\',
\'\', \'WIDTH=\"10%\" NOWRAP VALIGN=\"TOP\"\');

END IF;

\-- Get events

FOR Loop2 IN cGetEvents(i_calendar, i_date, TempBeginTime, TempNextTime)
LOOP

\-- Determine number of rows to span

IF Loop2.end_time IS NOT NULL AND Loop2.begin_time IS NOT NULL THEN

IF Loop2.begin_time \> Loop2.end_time THEN

TempBegin := Loop2.begin_time;

TempEnd := 1440 + Loop2.end_time;

ELSE

TempBegin := Loop2.begin_time;

TempEnd := Loop2.end_time;

END IF;

RowsToSpan := ceil(TempEnd / 30) - floor(TempBegin / 30);

END IF;

\-- Determine if event is recurring or not

IF Loop2.recur_event_id IS NULL THEN

RecurringEvent := \'N\';

ELSE

RecurringEvent := \'Y\';

END IF;

\-- Display the event

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.tableData(htf.anchor2(\'cal0003.change_appointment_page?i_pid=\'
\|\| i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=EDIT&i_event=\' \|\| Loop2.event_id \|\|
\'&i_recurring=\' \|\| RecurringEvent, \'\<FONT COLOR=\"#\' \|\| Lo

op2.color \|\| \'\"\>\' \|\| lib02.SwapCrLf(Loop2.subject), \'\',
\'Navigation\'), \'LEFT\', \'\', \'\', RowsToSpan, \'\',
\'BGCOLOR=\"#FFFFFF\" VALIGN=\"TOP\"\');

ELSIF instr(UserPrivs, \'READ_ALL\', 1) \> 0 THEN

htp.tableData(\'\<FONT COLOR=\"#\' \|\| Loop2.color \|\| \'\"\>\' \|\|
Loop2.subject, \'LEFT\', \'\', \'\', RowsToSpan, \'\',
\'BGCOLOR=\"#FFFFFF\" VALIGN=\"TOP\"\');

ELSE

htp.tableData(\'\<FONT COLOR=\"#\' \|\| Loop2.color \|\|
\'\"\>Appointment: \' \|\|
to_char(to_date(ConvertOracleTime(Loop2.begin_time), \'hh:mi AM\'),
\'hh:mi AM\') \|\| \' to \' \|\|
to_char(to_date(ConvertOracleTime(Loop2.end_time), \'hh:mi AM\'),
\'hh:mi AM\'), \'

LEFT\', \'\', \'\', RowsToSpan, \'\', \'BGCOLOR=\"#FFFFFF\"
VALIGN=\"TOP\"\');

END IF;

\-- Increment counter

Counter := Counter + 1;

END LOOP;

\-- Move to next time slot

ScheduleTime := ScheduleTime + .02083; \-- Add 30 minutes (Use .01042 to
add 15 minutes)

htp.tableRowClose;

END LOOP;

\-- Add additional rows for end times past 12:00AM

SELECT /\*+ rule \*/

MAX(end_time) INTO TempNum

FROM cal_event

WHERE end_time \< begin_time AND

pim_object_id = i_calendar AND

begin_date = to_date(i_date, \'DD-MON-YYYY\') AND

inactive = \'N\' AND

(event_type = 6000 OR event_type = 9000);

IF TempNum IS NOT NULL THEN

RowsToSpan := floor(TempNum / 30);

IF (to_char(to_date(ConvertOracleTime(TempNum), \'hh:mi AM\'), \'mi\')
!= \'00\') AND (to_char(to_date(ConvertOracleTime(TempNum), \'hh:mi
AM\'), \'mi\') != \'30\') THEN

RowsToSpan := RowsToSpan + 1;

END IF;

FOR Loop1 IN 1..RowsToSpan LOOP

\-- Calculate event range

TempBeginTime := ConvertRealTime(to_char(ScheduleTime, \'hh24\'),
to_char(ScheduleTime, \'mi\'));

TempNextTime := ConvertRealTime(to_char(ScheduleTime + .02083,
\'hh24\'), to_char(ScheduleTime + .02083, \'mi\')) - 1;

\-- Display time

htp.tableRowOpen;

htp.tableData(htf.bold(to_char(ScheduleTime, \'hh:mi AM\')), \'CENTER\',
\'\', \'\', \'\', \'\', \'WIDTH=\"10%\" NOWRAP VALIGN=\"TOP\"\');

\-- Move to next time slot

ScheduleTime := ScheduleTime + .02083; \-- Add 30 minutes (Use .01042 to
add 15 minutes)

htp.tableRowClose;

END LOOP;

END IF;

\-- Display No Appointments message if necessary

IF Counter = 0 THEN

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'LEFT\', \'\', \'\', \'\', \'\',
\'VALIGN=\"TOP\"\');

htp.tableData(htf.bold(\'No appointments scheduled for this day.\'),
\'CENTER\', \'\', \'\', \'\', \'\', \'WIDTH=\"100%\" VALIGN=\"TOP\"\');

htp.tableRowClose;

END IF;

\-- Close the table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display navigation page \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_navigation(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetGrantedCalInfo(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id, b.name

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'READ_ALL\' OR a.privs = \'WRITE\')
AND

a.inactive_flag = \'N\'

ORDER BY b.name;

\-- Declare constants/variables

TempYear NUMBER(4) := to_number(to_char(sysdate, \'YYYY\'));

CurrentUser VARCHAR2(50);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the web form

htp.formOpen(\'cal0003.display_listview\', \'\', \'\_top\');

\-- Open the top half of the navigation page

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

\-- Display the header

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
\'Navigation\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

\-- Display dropdown calendar selector

htp.tableRowOpen;

htp.tableData(\'Name:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_calendar\', \'\', 1);

FOR Loop1 IN cGetGrantedCalInfo(lib02.GetBadge(i_pid)) LOOP

IF i_calendar = Loop1.pim_object_id THEN

htp.formSelectOption(Loop1.name, \'Y\', \'VALUE=\"\' \|\|
Loop1.pim_object_id \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.name, NULL, \'VALUE=\"\' \|\|
Loop1.pim_object_id \|\| \'\"\');

END IF;

END LOOP;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display dropdown year selection

htp.tableRowOpen;

htp.tableData(\'Year:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_year\', \'\', 1);

FOR Loop1 IN (TempYear - 1)..(TempYear + 2) LOOP

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') =
to_char(to_date(Loop1, \'YYYY\'), \'YYYY\') THEN

htp.formSelectOption(Loop1, \'Y\', \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1, NULL, \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

END IF;

END LOOP;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display dropdown month selection

htp.tableRowOpen;

htp.tableData(\'Month:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_month\', \'\', 1);

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JAN\' THEN

htp.formSelectOption(\'January\', \'Y\', \'VALUE=\"JAN\"\');

ELSE

htp.formSelectOption(\'January\', NULL, \'VALUE=\"JAN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'FEB\' THEN

htp.formSelectOption(\'February\', \'Y\', \'VALUE=\"FEB\"\');

ELSE

htp.formSelectOption(\'February\', NULL, \'VALUE=\"FEB\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAR\' THEN

htp.formSelectOption(\'March\', \'Y\', \'VALUE=\"MAR\"\');

ELSE

htp.formSelectOption(\'March\', NULL, \'VALUE=\"MAR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'APR\' THEN

htp.formSelectOption(\'April\', \'Y\', \'VALUE=\"APR\"\');

ELSE

htp.formSelectOption(\'April\', NULL, \'VALUE=\"APR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAY\' THEN

htp.formSelectOption(\'May\', \'Y\', \'VALUE=\"MAY\"\');

ELSE

htp.formSelectOption(\'May\', NULL, \'VALUE=\"MAY\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUN\' THEN

htp.formSelectOption(\'June\', \'Y\', \'VALUE=\"JUN\"\');

ELSE

htp.formSelectOption(\'June\', NULL, \'VALUE=\"JUN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUL\' THEN

htp.formSelectOption(\'July\', \'Y\', \'VALUE=\"JUL\"\');

ELSE

htp.formSelectOption(\'July\', NULL, \'VALUE=\"JUL\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'AUG\' THEN

htp.formSelectOption(\'August\', \'Y\', \'VALUE=\"AUG\"\');

ELSE

htp.formSelectOption(\'August\', NULL, \'VALUE=\"AUG\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'SEP\' THEN

htp.formSelectOption(\'September\', \'Y\', \'VALUE=\"SEP\"\');

ELSE

htp.formSelectOption(\'September\', NULL, \'VALUE=\"SEP\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'OCT\' THEN

htp.formSelectOption(\'October\', \'Y\', \'VALUE=\"OCT\"\');

ELSE

htp.formSelectOption(\'October\', NULL, \'VALUE=\"OCT\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'NOV\' THEN

htp.formSelectOption(\'November\', \'Y\', \'VALUE=\"NOV\"\');

ELSE

htp.formSelectOption(\'November\', NULL, \'VALUE=\"NOV\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'DEC\' THEN

htp.formSelectOption(\'December\', \'Y\', \'VALUE=\"DEC\"\');

ELSE

htp.formSelectOption(\'December\', NULL, \'VALUE=\"DEC\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

\-- Display the submit button

htp.tableRowOpen;

htp.tableData(\'\<HR\>\' \|\| htf.formSubmit(\'\', \'Display\') \|\|
\'\<HR\>\',\'RIGHT\',\'\',\'\',\'\',\'2\',\'\');

htp.tableRowClose;

\-- Close the top half of the navigation page

htp.tableClose;

\-- Open the portion of the navigation page

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"0\"\');

\-- Display the navigation buttons

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=\"CENTER\" BGCOLOR=\"#C0C0C0\" COLSPAN=\"2\"\>\');

htp.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), -1), \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'),
-1), \'MON\') \|\|

\'&i_day=01\', \'\<IMG SRC=\"/gen-img/prev_month_btn.gif\"
BORDER=\"0\"\>\', \'\', \'\_top\');

htp.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\') - 1, \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(to_date(i_date, \'DD-MON-YYYY\') - 1,
\'MON\') \|\| \'&i_day=\' \|\| to_char(to

\_date(i_date, \'DD-MON-YYYY\') - 1, \'DD\'), \'\<IMG
SRC=\"/gen-img/prev_day_btn.gif\" BORDER=\"0\"\>\', \'\', \'\_top\');

htp.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\| to_char(sysdate,
\'YYYY\') \|\| \'&i_month=\' \|\| to_char(sysdate, \'MON\') \|\|
\'&i_day=\' \|\| to_char(sysdate, \'DD\'), \'\<IMG
SRC=\"/gen-img/today_btn.gif\" BORDER=\"

0\"\>\', \'\', \'\_top\');

htp.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\') + 1, \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(to_date(i_date, \'DD-MON-YYYY\') + 1,
\'MON\') \|\| \'&i_day=\' \|\| to_char(to

\_date(i_date, \'DD-MON-YYYY\') + 1, \'DD\'), \'\<IMG
SRC=\"/gen-img/next_day_btn.gif\" BORDER=\"0\"\>\', \'\', \'\_top\');

htp.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), 1), \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'),
1), \'MON\') \|\| \'

&i_day=01\', \'\<IMG SRC=\"/gen-img/next_month_btn.gif\"
BORDER=\"0\"\>\', \'\', \'\_top\');

htp.p(\'\<HR\>\</TD\>\');

htp.tableRowClose;

\-- Close the navigation table

htp.tableClose;

\-- Close the web form

htp.formClose;

\-- Open the \"set default calendar\" web form

htp.formOpen(\'cal0003.set_default_calendar\', \'\', \'\_top\');

\-- Open the default button table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

\-- Display the message about the default button

htp.tableRowOpen;

htp.tableData(\'Click the button below to make the currently selected
calendar your default calendar when you first
logon.\',\'CENTER\',\'\',\'\',\'\',\'\',\'\');

htp.tableRowClose;

\-- Display the default button

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'\', \'Make Default\') \|\|
\'\<HR\>\',\'CENTER\',\'\',\'\',\'\',\'\',\'\');

htp.tableRowClose;

\-- Close the default calendar table

htp.tableClose;

\-- Add hidden form data

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_badge\', lib02.GetBadge(i_pid));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"set default calendar\" web form

htp.formClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display the notes page \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_notes(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar IN
VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetNotes(CalendarID IN VARCHAR2, CalDate IN VARCHAR2) IS

SELECT event_id, subject, color, recur_event_id

FROM cal_event

WHERE pim_object_id = CalendarID AND

begin_date = to_date(CalDate, \'DD-MON-YYYY\') AND

event_type = 4000 AND

inactive = \'N\' AND

recur_event_id IS NULL

ORDER BY viewing_order, subject;

CURSOR cGetRecurringNotes(CalendarID IN VARCHAR2, CalDate IN VARCHAR2)
IS

SELECT event_id, subject, color, recur_event_id

FROM cal_event

WHERE pim_object_id = CalendarID AND

begin_date = to_date(CalDate, \'DD-MON-YYYY\') AND

event_type = 4000 AND

inactive = \'N\' AND

recur_event_id IS NOT NULL;

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

RecurringNote VARCHAR2(1);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_ALTER_LINKS);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the main table to display notes

htp.tableOpen(\'\', \'\', \'\', \'\', \'BGCOLOR=\"#FFFFFF\" BORDER=\"0\"
WIDTH=\"100%\" CELLSPACING=\"0\"\');

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Notes\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" WIDTH=\"100%\"\');

htp.tableRowClose;

\-- Get & display the notes

IF (instr(UserPrivs, \'READ_ALL\', 1) \> 0) OR (instr(UserPrivs,
\'WRITE\', 1) \> 0) THEN

htp.tableRowOpen;

htp.p(\'\<TD\>\');

htp.olistOpen;

FOR Loop1 IN cGetNotes(i_calendar, i_date) LOOP

\-- Display the note

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.p(htf.listItem(htf.anchor2(\'cal0003.change_note_page?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=EDIT&i_event=\' \|\| Loop1.event_id \|\|
\'&i_recurring=N\', \'\<FONT COLOR=\"#\' \|\| Loop1.color \|\| \'\"\>\'
\|

\| Loop1.subject \|\| \'\</FONT\>\', \'\', \'Navigation\')));

ELSE

htp.p(htf.listItem(\'\<FONT COLOR=\"#\' \|\| Loop1.color \|\| \'\"\>\'
\|\| Loop1.subject \|\| \'\</FONT\>\'));

END IF;

END LOOP;

htp.olistClose;

htp.ulistOpen;

FOR Loop1 IN cGetRecurringNotes(i_calendar, i_date) LOOP

\-- Display the recurring note

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.p(htf.listItem(htf.anchor2(\'cal0003.change_note_page?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
i_date \|\| \'&i_action=EDIT&i_event=\' \|\| Loop1.event_id \|\|
\'&i_recurring=Y\', \'\<FONT COLOR=\"#\' \|\| Loop1.color \|\| \'\"\>\'
\|

\| Loop1.subject \|\| \'\</FONT\>\', \'\', \'Navigation\')));

ELSE

htp.p(htf.listItem(\'\<FONT COLOR=\"#\' \|\| Loop1.color \|\| \'\"\>\'
\|\| Loop1.subject \|\| \'\</FONT\>\'));

END IF;

END LOOP;

htp.ulistClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

ELSE

htp.tableRowOpen;

htp.tableData(\'You do not have access to note information.\',
\'CENTER\', \'\', \'\', \'\', \'\', \'WIDTH=\"100%\"\');

htp.tableRowClose;

END IF;

\-- Close the main table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display the small calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_small_calendar(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare constants/variables

StartDayOfWeek NUMBER(1);

Counter NUMBER(2);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the calendar table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" CELLSPACING=\"0\"
CELLPADDING=\"2\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

\-- Display calendar header

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\',
\'\', \'\', \'7\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Su\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Mo\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Tu\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'We\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Th\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Fr\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Sa\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableRowClose;

\-- Blow through initial empty calendar cells

StartDayOfWeek := to_number(to_char(round(to_date(i_date,
\'DD-MON-YYYY\'), \'W\'), \'D\'));

htp.tableRowOpen;

IF StartDayOfWeek \> 1 THEN

FOR Loop1 IN 1..StartDayOfWeek - 1 LOOP

htp.tableData(\'\<FONT COLOR=\"#303030\"\>-\', \'CENTER\', \'\', \'\',
\'\', \'\', \'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

END IF;

\-- Display calendar days in cells

Counter := StartDayOfWeek;

FOR Loop1 IN 1..to_number(to_char(last_day(to_date(i_date,
\'DD-MON-YYYY\')), \'DD\')) LOOP

IF Loop1 = to_char(sysdate, \'DD\') THEN

IF to_char(sysdate, \'YYYY\') = to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\') AND to_char(sysdate, \'MON\') =
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') THEN

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| Loop1, htf.bold(\'\<FONT COLOR=\"#5050FF\"\>\' \|\| Loop1),
\'\', \'\_top\'), \'CENTER\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\"\');

ELSE

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| Loop1, \'\<FONT COLOR=\"#303030\"\>\' \|\| htf.div(\'\',
\'CLASS=\"Small01\"\') \|\| Loop1, \'\', \'\_top\'), \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#FFFFFF\"\');

END IF;

ELSE

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|

Loop1, \'\<FONT COLOR=\"#303030\"\>\' \|\| htf.div(\'\',
\'CLASS=\"Small01\"\') \|\| Loop1, \'\', \'\_top\'), \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#FFFFFF\"\');

END IF;

Counter := Counter + 1;

IF Counter = 8 THEN

Counter := 1;

htp.tableRowClose;

\-- Don\'t open a new row if last day of the month is on a Saturday

IF (TO_CHAR(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 AND
Loop1 \<\> to_number(to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')),
\'DD\'))) THEN

htp.tableRowOpen;

END IF;

END IF;

END LOOP;

\-- Blow through remaining empty calendar cells

IF to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 THEN

FOR Loop1 IN 1..8 - Counter LOOP

htp.tableData(\'\<FONT COLOR=\"#303030\"\>-\',\'CENTER\', \'\', \'\',
\'\', \'\', \'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

htp.tableRowClose;

END IF;

\-- Close the calendar table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Insert/Update the cell color \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_color(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar IN
VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_color IN
VARCHAR2) IS

\-- Declare cursors

CURSOR cGetCellProperties(CalendarID IN VARCHAR2, CalDate IN VARCHAR2)
IS

SELECT cal_display_id

FROM cal_display_properties

WHERE pim_object_id = CalendarID AND

display_date = to_date(CalDate, \'DD-MON-YYYY\');

rGetCellProperties cGetCellProperties%ROWTYPE;

\-- Declare constants/variables

TempSeq NUMBER(9);

EntryExists NUMBER(1) := 0;

OracleColor VARCHAR2(12);

BEGIN

\-- Determine Oracle color to use (for Chris\' Oracle Report)

IF i_color \<\> \'DEFAULT\' THEN

SELECT oracle_color INTO OracleColor

FROM cal_color

WHERE color = i_color;

END IF;

\-- Check to see if cell already has existing properties

OPEN cGetCellProperties(i_calendar, i_date);

FETCH cGetCellProperties INTO rGetCellProperties;

\-- Perform the INSERT or UPDATE

IF cGetCellProperties%NOTFOUND AND i_color \<\> \'DEFAULT\' THEN

\-- Get the next sequence number

SELECT cal_display_prop_seq.nextval INTO TempSeq FROM dual;

\-- Insert the the new color for the cell

INSERT INTO cal_display_properties(

cal_display_id, pim_object_id, display_date, color, oracle_color)

VALUES(

TempSeq, i_calendar, to_date(i_date, \'DD-MON-YYYY\'), i_color,
OracleColor);

ELSE

IF i_color \<\> \'DEFAULT\' THEN

\-- Update the cell with the new color

UPDATE cal_display_properties

SET color = i_color, oracle_color = OracleColor

WHERE cal_display_id = rGetCellProperties.cal_display_id;

ELSE

UPDATE cal_display_properties

SET color = NULL, oracle_color = NULL

WHERE cal_display_id = rGetCellProperties.cal_display_id;

END IF;

END IF;

\-- Close the cursor

CLOSE cGetCellProperties;

\-- Refresh the frame set

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'));

END;

\-- \*\*\* Display the note change page \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_note_page(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_action
IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL, i_recurring IN VARCHAR2 DEFAULT \'N\')
IS

\-- Declare cursors

CURSOR cGetNoteInfo(EventID IN NUMBER) IS

SELECT subject, viewing_order, begin_time, begin_date, end_date, color,
recur_event_id

FROM cal_event

WHERE event_id = EventID;

rGetNoteInfo cGetNoteInfo%ROWTYPE;

CURSOR cGetRecurringInfo(RecurEventID IN NUMBER) IS

SELECT r_period_type, r_period, non_wd_skip, day_of_week, week_of_month,
day_of_month, date_of_year

FROM cal_recurring

WHERE recur_event_id = RecurEventID;

rGetRecurringInfo cGetRecurringInfo%ROWTYPE;

CURSOR cGetColors IS

SELECT color, color_name

FROM cal_color;

\-- Declare constants/variables

BrowserType VARCHAR2(255);

TotalNotes NUMBER;

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the web browser type the user is using

BrowserType := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

\-- Get note information if editing

IF i_action = \'EDIT\' THEN

OPEN cGetNoteInfo(i_event);

FETCH cGetNoteInfo INTO rGetNoteInfo;

CLOSE cGetNoteInfo;

\-- Get recurring note information

OPEN cGetRecurringInfo(rGetNoteInfo.recur_event_id);

FETCH cGetRecurringInfo INTO rGetRecurringInfo;

CLOSE cGetRecurringInfo;

END IF;

\-- Get total notes for the selected calendar

SELECT COUNT(event_id) INTO TotalNotes

FROM cal_event

WHERE pim_object_id = i_calendar AND

begin_date = to_date(i_date, \'DD-MON-YYYY\') AND

inactive = \'N\' AND

event_type = 4000 AND

recur_event_id IS NULL;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_FORMS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\| \'\"
OnLoad=\"document.Notes.i_subject.focus()\"\');

\-- Open the \"submit\" web form

htp.formOpen(\'cal0003.change_note\', \'POST\', \'\_top\', \'\',
\'NAME=\"Notes\"\');

\-- Open the main table to display note edit fields

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

IF i_action = \'EDIT\' THEN

IF i_recurring = \'N\' THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Edit/Delete
Note\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

ELSE

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Edit/Delete
Recurring Note\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

END IF;

ELSE

IF i_recurring = \'N\' THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Add New
Note\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

ELSE

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Add New
Recurring Note\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

END IF;

END IF;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'Note Text\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

\-- Display the text area

htp.tableRowOpen;

htp.p(\'\<TD COLSPAN=\"2\"\>\');

IF instr(BrowserType, \'MSIE\', 1) \> 0 THEN

htp.formTextareaOpen2(\'i_subject\', \'5\', \'37\', NULL, \'VIRTUAL\');

ELSE

htp.formTextareaOpen2(\'i_subject\', \'5\', \'19\', NULL, \'VIRTUAL\');

END IF;

IF i_action = \'EDIT\' THEN

htp.p(rGetNoteInfo.subject);

END IF;

htp.formTextareaClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the begin date textbox

IF i_recurring \<\> \'Y\' OR (i_recurring = \'Y\' AND i_action \<\>
\'EDIT\') THEN

htp.tableRowOpen;

htp.tableData(\'Start Date: \', \'\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formText(\'i_begin_date\', 11, 11,
to_char(rGetNoteInfo.begin_date, \'DD-MON-YYYY\')));

ELSE

htp.tableData(htf.formText(\'i_begin_date\', 11, 11,
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD-MON-YYYY\')));

END IF;

htp.tableRowClose;

ELSE

htp.formHidden(\'i_begin_date\', to_char(rGetNoteInfo.begin_date,
\'DD-MON-YYYY\'));

END IF;

\-- Display the end date textbox

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'End Date: \', \'\', \'\', \'\', \'\', \'\', \'NOWRAP\');

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formText(\'i_end_date\', 11, 11,
to_char(rGetNoteInfo.end_date, \'DD-MON-YYYY\')));

ELSE

htp.tableData(htf.formText(\'i_end_date\', 11, 11,
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD-MON-YYYY\')));

END IF;

htp.tableRowClose;

END IF;

\-- Display time textbox

htp.tableRowOpen;

htp.tableData(\'Note Time: \', \'\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

IF i_action = \'EDIT\' THEN

IF rGetNoteInfo.begin_time \> 0 THEN

htp.tableData(htf.formText(\'i_time\', 8, 8,
ConvertOracleTime(rGetNoteInfo.begin_time)));

ELSE

htp.tableData(htf.formText(\'i_time\', 8, 8, \'\'));

END IF;

ELSE

htp.tableData(htf.formText(\'i_time\', 8, 8, \'\'));

END IF;

htp.tableRowClose;

\-- Display the color selector dropdown list

htp.tableRowOpen;

htp.tableData(\'Text Color: \', \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_color\', \'\', 1);

FOR Loop1 IN cGetColors LOOP

IF rGetNoteInfo.color = Loop1.color THEN

htp.formSelectOption(Loop1.color_name, \'Y\', \'VALUE=\"\' \|\|
Loop1.color \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.color_name, NULL, \'VALUE=\"\' \|\|
Loop1.color \|\| \'\"\');

END IF;

END LOOP;

IF rGetNoteInfo.color IS NULL THEN

htp.formSelectOption(\'Default\', \'Y\', \'VALUE=\"\"\');

ELSE

htp.formSelectOption(\'Default\', NULL, \'VALUE=\"\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the note order dropdown

IF i_recurring \<\> \'Y\' THEN

htp.formHidden(\'i_prev_position\', rGetNoteInfo.viewing_order);

htp.tableRowOpen;

htp.tableData(\'Note Position: \', \'\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_new_position\', \'\', 1);

FOR Loop1 IN 1..TotalNotes LOOP

IF i_action = \'EDIT\' THEN

IF Loop1 = rGetNoteInfo.viewing_order THEN

htp.formSelectOption(Loop1, \'Y\', \'VALUE=\"\' \|\| to_char(Loop1) \|\|
\'\"\');

ELSE

htp.formSelectOption(Loop1, NULL, \'VALUE=\"\' \|\| to_char(Loop1) \|\|
\'\"\');

END IF;

ELSE

htp.formSelectOption(Loop1, NULL, \'VALUE=\"\' \|\| to_char(Loop1) \|\|
\'\"\');

END IF;

END LOOP;

IF i_action = \'NEW\' THEN

htp.formSelectOption(TotalNotes + 1, \'Y\', \'VALUE=\"\' \|\|
to_char(TotalNotes + 1) \|\| \'\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

END IF;

\-- Display period type for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Interval Type: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_period_type\', \'\', 1);

htp.formSelectOption(\'Daily\', NULL, \'VALUE=\"D\"\');

htp.formSelectOption(\'Weekly\', \'Y\', \'VALUE=\"W\"\');

htp.formSelectOption(\'Monthly\', NULL, \'VALUE=\"M\"\');

htp.formSelectOption(\'Yearly\', NULL, \'VALUE=\"Y\"\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

END IF;

\-- Display period textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Interval: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

\--htp.tableData(htf.formText(\'i_period\', 3, 3,
rGetRecurringInfo.r_period));

htp.tableData(htf.formText(\'i_period\', 3, 3, \'1\'));

htp.tableRowClose;

END IF;

\-- Display behavior for non-workdays for recurring events (if
necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Non-workday: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_non_workday\', \'\', 1);

htp.formSelectOption(\'Prev workday\', NULL, \'VALUE=\"-1\"\');

htp.formSelectOption(\'Do nothing\', \'Y\', \'VALUE=\"0\"\');

htp.formSelectOption(\'Allow\', NULL, \'VALUE=\"\"\');

htp.formSelectOption(\'Next workday\', NULL, \'VALUE=\"1\"\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

END IF;

\-- Display Day of Week textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Days of Week: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_day_of_week\', 10, 25,
rGetRecurringInfo.day_of_week));

htp.tableRowClose;

END IF;

\-- Display Weeks of Month textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Weeks of Month: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_week_of_month\', 10, 255,
rGetRecurringInfo.week_of_month));

htp.tableRowClose;

END IF;

\-- Display Days of Month textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Days of Month: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_day_of_month\', 10, 255,
rGetRecurringInfo.day_of_month));

htp.tableRowClose;

END IF;

\-- Display Month of Year textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Date of Year: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_date_of_year\', 10, 255,
rGetRecurringInfo.date_of_year));

htp.tableRowClose;

END IF;

\-- Display update/delete options

IF i_recurring = \'Y\' AND i_action = \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(htf.hr, \'CENTER\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'Apply this update/delete to:\', \'LEFT\', \'\', \'\',
\'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'Today\') \|\| \' This day
only\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'After\') \|\| \' This day and
after\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'Everything\', \'Y\') \|\| \'
Everything\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

END IF;

\-- Close the note edit table

htp.tableRowOpen;

htp.tableData(htf.hr,\'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableClose;

\-- Open the submit buttons table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"2\"\');

\-- Display the submit button

htp.tableRowOpen;

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formSubmit(\'i_operation\', \'Update\'),\'\', \'\',
\'\', \'\', \'\', \'\');

ELSE

htp.tableData(htf.formSubmit(\'i_operation\', \' Add \'),\'\', \'\',
\'\', \'\', \'\', \'\');

END IF;

\-- Add hidden form data

htp.formHidden(\'i_event\', i_event);

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

htp.formHidden(\'i_recurring\', i_recurring);

htp.formHidden(\'i_recur_id\', rGetNoteInfo.recur_event_id);

\-- Display the delete button (if necessary)

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formSubmit(\'i_operation\', \'Delete\'),\'\', \'\',
\'\', \'\', \'\', \'\');

END IF;

\-- Close the \"submit\" web form

htp.formClose;

\-- Open the \"Cancel\" web form

htp.formOpen(\'cal0003.display_navigation\', \'POST\', \'\');

\-- Display the cancel button

htp.tableData(htf.formSubmit(\'\', \'Cancel\'),\'RIGHT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"cancel\" web form

htp.formClose;

\-- Close the submit button table

htp.tableRowClose;

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Insert/Update the note \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_note(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar IN
VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),
i_operation IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL, i_subject IN VARCHAR2 DEFAULT NULL,

i_time IN VARCHAR2 DEFAULT NULL, i_prev_position IN NUMBER DEFAULT NULL,

i_new_position IN NUMBER DEFAULT NULL, i_color IN VARCHAR2 DEFAULT NULL,

i_begin_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_end_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_period_type IN VARCHAR2 DEFAULT NULL, i_period IN VARCHAR2 DEFAULT
NULL,

i_non_workday IN VARCHAR2 DEFAULT NULL, i_day_of_week IN VARCHAR2
DEFAULT NULL,

i_week_of_month IN VARCHAR2 DEFAULT NULL, i_day_of_month IN VARCHAR2
DEFAULT NULL,

i_date_of_year IN VARCHAR2 DEFAULT NULL, i_recurring IN VARCHAR2 DEFAULT
\'N\',

i_range IN VARCHAR2 DEFAULT NULL, i_recur_id IN VARCHAR2 DEFAULT NULL)
IS

\-- Declare cursors

CURSOR cGetNotes(CalendarID IN VARCHAR2, CalDate IN VARCHAR2) IS

SELECT event_id

FROM cal_event

WHERE pim_object_id = CalendarID AND

begin_date = to_date(CalDate, \'DD-MON-YYYY\') AND

event_type = 4000 AND

inactive = \'N\' AND

recur_event_id IS NULL

ORDER BY viewing_order;

\-- Declare constants/variables

TempSeq NUMBER(9);

EntryExists NUMBER(1) := 0;

NoteTime NUMBER(4);

NotePosition NUMBER(4,1);

Counter NUMBER(4) := 0;

UserBadge VARCHAR2(5);

TempTime VARCHAR2(9);

TempDateTime DATE;

TempNumber NUMBER(4);

TempNumber2 NUMBER(4);

ErrorPos NUMBER(2) := 0;

OracleColor VARCHAR2(12);

TotalNotes NUMBER := 0;

NewDayOfMonth VARCHAR2(256);

TempString VARCHAR2(3);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the current user\'s badge number

UserBadge := lib02.GetBadge(i_pid);

\-- Determine Oracle color to use (for Chris\' Oracle Report)

IF i_color IS NULL THEN

OracleColor := NULL;

ELSE

SELECT oracle_color INTO OracleColor

FROM cal_color

WHERE color = i_color;

END IF;

\-- Make sure the date is valid

ErrorPos := 1;

TempDateTime := to_date(i_begin_date, \'DD-MON-YYYY\');

TempNumber := to_number(substr(i_begin_date, length(i_begin_date) - 4,
4));

\-- Perform checks and other functions

IF i_operation = \' Add \' OR i_operation = \'Update\' THEN

\-- Make sure a subject has been entered

ErrorPos := 2;

IF i_subject IS NULL OR i_subject = \'\' THEN

RAISE VALUE_ERROR;

END IF;

\-- Make sure the time is valid

ErrorPos := 3;

IF i_time IS NOT NULL THEN

TempTime := ltrim(rtrim(i_time));

\-- Check for the full \'AM\' or \'PM\' marker

TempNumber := instr(UPPER(TempTime), \'AM\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'PM\', 1);

END IF;

\-- Check for only a \'A\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'A\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Check for only a \'P\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'P\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Convert military time

IF TempNumber = 0 THEN

TempString := substr(TempTime, 1, 2);

IF substr(TempString, 2, 1) \<\> \':\' THEN

IF to_number(TempString) \> 12 THEN

TempTime := to_char(to_number(TempString) - 12) \|\| substr(TempTime, 3,
length(TempTime) - 2) \|\| \' PM\';

ELSE

TempTime := TempTime \|\| \' AM\';

END IF;

END IF;

END IF;

\-- Add space between time and AM/PM marker (if necessary)

IF TempNumber \> 0 THEN

TempNumber2 := instr(TempTime, \' \', 1);

IF TempNumber2 = 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \' \' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

\-- Check for the colon seperator

TempNumber := instr(UPPER(TempTime), \':\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(TempTime, \' \', 1);

IF TempNumber \> 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \':00\' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

TempDateTime := to_date(to_char(sysdate, \'DD-MON-YYYY\') \|\| \' \'
\|\| TempTime, \'DD-MON-YYYY hh:mi AM\');

NoteTime := ConvertRealTime(to_char(TempDateTime, \'hh24\'),
to_char(TempDateTime, \'mi\'));

ELSE

NoteTime := NULL;

END IF;

\-- Determine note position

ErrorPos := 4;

IF i_recurring = \'Y\' AND i_range = \'Today\' THEN

SELECT MAX(viewing_order) INTO TotalNotes

FROM cal_event

WHERE begin_date = to_date(i_date, \'DD-MON-YYYY\') AND

recur_event_id IS NULL;

NotePosition := TotalNotes + 1;

ELSIF i_recurring = \'Y\' THEN

NotePosition := NULL;

ELSE

IF i_prev_position IS NULL THEN

NotePosition := i_new_position - 0.9;

ELSIF i_new_position \> i_prev_position THEN

NotePosition := i_new_position + 0.1;

ELSIF i_new_position \< i_prev_position THEN

NotePosition := i_new_position - 0.9;

ELSE

NotePosition := i_prev_position;

END IF;

END IF;

END IF;

\-- Make sure recurring data is valid

IF i_recurring = \'Y\' THEN

ErrorPos := 5;

IF IsNumeric(i_period \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 6;

IF IsNumeric(i_day_of_week \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 7;

IF IsNumeric(i_week_of_month \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 8;

IF IsNumeric(i_day_of_month \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

END IF;

\-- Make sure period is entered for recurring data

ErrorPos := 9;

IF i_recurring = \'Y\' AND i_operation = \' Add \' AND i_period IS NULL
THEN

RAISE VALUE_ERROR;

END IF;

\-- Make sure day, week and/or month data has been entered

IF i_recurring = \'Y\' AND i_operation = \' Add \' THEN

IF i_period_type = \'W\' THEN

ErrorPos := 10;

IF i_day_of_week IS NULL THEN

RAISE VALUE_ERROR;

END IF;

ELSIF i_period_type = \'M\' THEN

IF (i_day_of_week IS NOT NULL) AND (i_week_of_month IS NULL) THEN

ErrorPos := 11;

RAISE VALUE_ERROR;

ELSIF (i_day_of_week IS NULL) AND (i_week_of_month IS NOT NULL) THEN

ErrorPos := 12;

RAISE VALUE_ERROR;

ELSIF (i_day_of_week IS NULL) AND (i_week_of_month IS NULL) AND
(i_day_of_month IS NULL) THEN

ErrorPos := 13;

RAISE VALUE_ERROR;

END IF;

ELSIF i_period_type = \'Y\' THEN

ErrorPos := 14;

IF i_date_of_year IS NULL THEN

RAISE VALUE_ERROR;

END IF;

END IF;

END IF;

ErrorPos := 15;

\-- Get the current user\'s badge number

UserBadge := lib02.GetBadge(i_pid);

\-- Send an e-mail if D. E. Moncton\'s calendar had a deletion

IF i_calendar = \'115732\' AND i_operation = \'Delete\' THEN

IF UserBadge = \'25520\' THEN

\-- If user is Rose, send an e-mail to Cathy

run_print_it(\'Note - Delete\', i_event, NVL(i_time, \'None\'),
\'kfr@ornl.gov\');

ELSE

\-- If user is Cathy, send an e-mail to Rose

run_print_it(\'Note - Delete\', i_event, NVL(i_time, \'None\'),
\'rt@aps.anl.gov\');

END IF;

\-- Waste time to allow e-mail to be sent before it gets deleted

FOR Loop1 IN 1..100000 LOOP

NULL;

END LOOP;

END IF;

\-- Process the request

IF i_operation = \' Add \' THEN

\-- Determine whether to insert to CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Get the next sequence number

SELECT seq_event_id.nextval INTO TempSeq FROM dual;

\-- Insert the new note

INSERT INTO cal_event(

event_id, event_type, subject, create_date, created_by, begin_date,
begin_time, viewing_order,

inactive, pim_object_id, color, oracle_color)

VALUES(

TempSeq, \'4000\', rtrim(i_subject, CR \|\| LF), sysdate, UserBadge,
to_date(i_begin_date, \'DD-MON-YYYY\'),

NoteTime, NotePosition, \'N\', i_calendar, i_color, OracleColor);

ELSE

\-- Get the next recurring event sequence number

SELECT seq_recur_id.nextval INTO TempSeq FROM dual;

\-- Pad the Day of Month string

NewDayOfMonth := PadDayOfMonth(i_day_of_month \|\| \',\');

\-- Insert the new recurring note

INSERT INTO cal_recurring(

recur_event_id, event_type, subject, create_date, created_by,
r_begin_date, r_end_date, begin_time,

inactive, pim_object_id, color, r_period_type, r_period, non_wd_skip,
day_of_week, week_of_month,

day_of_month, date_of_year, oracle_color)

VALUES(

TempSeq, \'4000\', rtrim(i_subject, CR \|\| LF), sysdate, UserBadge,
to_date(i_begin_date, \'DD-MON-YYYY\'),

to_date(i_end_date, \'DD-MON-YYYY\'), NoteTime, \'N\', i_calendar,
i_color, i_period_type, i_period,

i_non_workday, i_day_of_week, i_week_of_month, NewDayOfMonth,
i_date_of_year, OracleColor);

\-- Expand the recurring appointment into the CAL_EVENT table

cal0008.expand_recurring_event(TempSeq);

END IF;

ELSIF i_operation = \'Update\' THEN

\-- Determine whether to insert to CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Update the selected note

UPDATE cal_event SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge, begin_time = NoteTime,

viewing_order = NotePosition, color = i_color, begin_date =
to_date(i_begin_date, \'DD-MON-YYYY\'),

oracle_color = OracleColor

WHERE event_id = i_event;

ELSE

\-- Update the event to CAL_RECURRING

IF i_range = \'Today\' THEN

UPDATE cal_event SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge, begin_time = NoteTime,

viewing_order = NotePosition, color = i_color,

oracle_color = OracleColor, recur_event_id = NULL

WHERE event_id = i_event;

ELSE

UPDATE cal_recurring SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge, begin_time = NoteTime,

color = i_color, oracle_color = OracleColor

WHERE recur_event_id = i_recur_id;

END IF;

\-- Expand the recurring appointment into the CAL_EVENT table

IF i_range = \'After\' THEN

cal0008.update_recurring(i_recur_id, to_date(i_begin_date,
\'DD-MON-YYYY\'));

ELSIF i_range = \'Everything\' THEN

cal0008.update_recurring(i_recur_id);

END IF;

END IF;

ELSIF i_operation = \'Delete\' THEN

\-- Determine whether to delete from CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Delete the selected note

DELETE FROM cal_event

WHERE event_id = i_event;

ELSE

IF i_range = \'Today\' THEN

\-- Delete the selected note

DELETE FROM cal_event

WHERE event_id = i_event;

ELSIF i_range = \'After\' THEN

\-- Call procedure to delete recurring note from CAL_EVENT

cal0008.remove_recurring(i_recur_id, to_date(i_begin_date,
\'DD-MON-YYYY\'));

ELSIF i_range = \'Everything\' THEN

\-- Call procedure to delete recurring note from CAL_EVENT

cal0008.remove_recurring(i_recur_id);

END IF;

END IF;

END IF;

\-- Resequence note \"viewing_order\"

IF i_recurring = \'N\' OR (i_recurring = \'Y\' AND i_range = \'Today\')
THEN

FOR Loop1 IN cGetNotes(i_calendar, i_date) LOOP

Counter := Counter + 1;

UPDATE cal_event SET

viewing_order = Counter

WHERE event_id = Loop1.event_id;

END LOOP;

END IF;

\-- Send an e-mail if D. E. Moncton\'s calendar had an addition or
update

IF i_calendar = \'115732\' THEN

IF UserBadge = \'25520\' THEN

\-- If user is Rose, send an e-mail to Cathy

IF i_operation = \' Add \' THEN

run_print_it(\'Note - New\', TempSeq, NVL(i_time, \'None\'),
\'kfr@ornl.gov\');

ELSIF i_operation = \'Update\' THEN

run_print_it(\'Note - Update\', i_event, NVL(i_time, \'None\'),
\'kfr@ornl.gov\');

END IF;

ELSE

\-- If user is Cathy, send an e-mail to Rose

IF i_operation = \' Add \' THEN

run_print_it(\'Note - New\', TempSeq, NVL(i_time, \'None\'),
\'rt@aps.anl.gov\');

ELSIF i_operation = \'Update\' THEN

run_print_it(\'Note - Update\', i_event, NVL(i_time, \'None\'),
\'rt@aps.anl.gov\');

END IF;

END IF;

END IF;

\-- Refresh the frame set

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'));

\-- End valid PID check

END IF;

\-- Error trap

EXCEPTION WHEN others THEN

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen;

IF ErrorPos = 1 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The date you entered is
incorrect. Make sure the format is correct, including the full 4-digit
year. (Example: 05-MAR-1999).\<P\>Click your browser\'\'s \"Back\"
button and correct the error if necessary.\');

ELSIF ErrorPos = 2 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The subject field
cannot be blank.\<P\>Click your browser\'\'s \"Back\" button and correct
the error.\');

ELSIF ErrorPos = 3 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The time you entered is
incorrect. Make sure the format is correct, including the AM/PM marker.
(Example: 10:30 AM).\<P\>Click your browser\'\'s \"Back\" button and
correct the error if necessary.\');

ELSIF ErrorPos = 5 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Interval\" you
entered is incorrect. Make sure you\'\'ve entered a valid
number.\<P\>Click your browser\'\'s \"Back\" button and correct the
error if necessary.\');

ELSIF ErrorPos = 6 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5)\<P\>Click your
browser\'\'s \"Back\" button and correct the error

if necessary.\');

ELSIF ErrorPos = 7 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Weeks of Month\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5)\<P\>Click your
browser\'\'s \"Back\" button and correct the err

or if necessary.\');

ELSIF ErrorPos = 8 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Month\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5,12)\<P\>Click your
browser\'\'s \"Back\" button and correct the e

rror if necessary.\');

ELSIF ErrorPos = 9 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The interval field must
be filled in.\<P\>Click your browser\'\'s \"Back\" button and correct
the error if necessary.\');

ELSIF ErrorPos = 10 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
field must be filled in.\<P\>Click your browser\'\'s \"Back\" button and
correct the error if necessary.\');

ELSIF ErrorPos = 11 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Weeks of Month\"
field must be filled in when also using the \"Days of Week\"
field.\<P\>Click your browser\'\'s \"Back\" button and correct the error
if necessary.\');

ELSIF ErrorPos = 12 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
field must be filled in when also using the \"Weeks of Month\"
field.\<P\>Click your browser\'\'s \"Back\" button and correct the error
if necessary.\');

ELSIF ErrorPos = 13 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'You must fill in the
\"Days of Month\" field or both the \"Days of Week\" and \"Weeks of
Month\" fields.\<P\>Click your browser\'\'s \"Back\" button and correct
the error if necessary.\');

ELSIF ErrorPos = 14 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Months of Year\"
field must be filled in.\<P\>Click your browser\'\'s \"Back\" button and
correct the error if necessary.\');

ELSE

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'Click your browser\'\'s
\"Back\" button and correct the error if necessary.\');

END IF;

htp.bodyClose;

htp.htmlClose;

END;

\-- \*\*\* Display the appointment change page \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_appointment_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_action
IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL, i_start_time IN VARCHAR2 DEFAULT NULL,

i_end_time IN VARCHAR2 DEFAULT NULL, i_recurring IN VARCHAR2 DEFAULT
\'N\') IS

\-- Declare cursors

CURSOR cGetAppointmentInfo(EventID IN NUMBER) IS

SELECT subject, begin_date, end_date, begin_time, end_time, location_id,
text_id, tzid, color, recur_event_id

FROM cal_event

WHERE event_id = EventID;

rGetAppointmentInfo cGetAppointmentInfo%ROWTYPE;

CURSOR cGetRecurringInfo(RecurEventID IN NUMBER) IS

SELECT r_period_type, r_period, non_wd_skip, day_of_week, week_of_month,
day_of_month, date_of_year

FROM cal_recurring

WHERE recur_event_id = RecurEventID;

rGetRecurringInfo cGetRecurringInfo%ROWTYPE;

CURSOR cGetLocationInfo IS

SELECT location_id, location, tzid

FROM cal_location

ORDER BY location;

CURSOR cGetTimezoneInfo IS

SELECT tzid, timezone

FROM cal_timezone

ORDER BY timezone;

CURSOR cGetDetailText(TextID IN NUMBER) IS

SELECT /\*+ rule \*/

text_line

FROM cal_text_dtl

WHERE text_id = TextID

ORDER BY line_no;

CURSOR cGetColors IS

SELECT color, color_name

FROM cal_color;

\-- Declare constants/variables

BrowserType VARCHAR2(255);

StartTime VARCHAR2(8);

EndTime VARCHAR2(8);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the web browser type the user is using

BrowserType := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

\-- Convert time (Can\'t pass normal time w/spaces due to bug in
Navigator w/frames)

IF i_start_time IS NOT NULL THEN

StartTime := ConvertOracleTime(i_start_time);

END IF;

IF i_end_time IS NOT NULL THEN

EndTime := ConvertOracleTime(i_end_time);

END IF;

\-- Get appointment information

IF i_action = \'EDIT\' THEN

OPEN cGetAppointmentInfo(i_event);

FETCH cGetAppointmentInfo INTO rGetAppointmentInfo;

CLOSE cGetAppointmentInfo;

\-- Get recurring appointment information

OPEN cGetRecurringInfo(rGetAppointmentInfo.recur_event_id);

FETCH cGetRecurringInfo INTO rGetRecurringInfo;

CLOSE cGetRecurringInfo;

END IF;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_FORMS);

htp.p(\'\</STYLE\>\');

\--htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\| \'\"
OnLoad=\"document.Subject.i_subject.focus()\"\');

\-- Open the \"submit\" web form

htp.formOpen(\'cal0003.change_appointment\', \'POST\', \'\_top\', \'\',
\'NAME=\"Subject\"\');

\-- Open the main table to display note edit fields

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

IF i_action = \'EDIT\' THEN

IF i_recurring = \'N\' THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Edit/Delete
Appointment\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

ELSE

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Edit/Delete
Recurring Appt.\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

END IF;

ELSE

IF i_recurring = \'N\' THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Add New
Appointment\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

ELSE

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'New
Recurring Appt.\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\'
\|\| TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

END IF;

END IF;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'Subject\', \'LEFT\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

\-- Display the subject text area

htp.tableRowOpen;

htp.p(\'\<TD COLSPAN=\"2\"\>\');

IF instr(BrowserType, \'MSIE\', 1) \> 0 THEN

htp.formTextareaOpen2(\'i_subject\', \'3\', \'37\', NULL, \'VIRTUAL\');

ELSE

htp.formTextareaOpen2(\'i_subject\', \'3\', \'19\', NULL, \'VIRTUAL\');

END IF;

IF i_action = \'EDIT\' THEN

htp.p(rGetAppointmentInfo.subject);

END IF;

htp.formTextareaClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the detail text area

htp.tableRowOpen;

htp.tableData(\'Detail\', \'LEFT\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD COLSPAN=\"2\"\>\');

IF instr(BrowserType, \'MSIE\', 1) \> 0 THEN

htp.formTextareaOpen2(\'i_detail\', \'4\', \'37\', NULL, \'VIRTUAL\');

ELSE

htp.formTextareaOpen2(\'i_detail\', \'4\', \'19\', NULL, \'VIRTUAL\');

END IF;

IF i_action = \'EDIT\' THEN

FOR Loop1 IN cGetDetailText(rGetAppointmentInfo.text_id) LOOP

htp.p(Loop1.text_line);

END LOOP;

END IF;

htp.formTextareaClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display appointment start date

htp.tableRowOpen;

IF i_recurring = \'N\' THEN

htp.tableData(\'Start Date: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

ELSIF i_action \<\> \'EDIT\' THEN

htp.tableData(\'Recurring Start Date: \', \'LEFT\', \'\', \'\', \'\',
\'\', \'NOWRAP\');

END IF;

IF i_action = \'EDIT\' THEN

IF i_recurring = \'N\' THEN

htp.tableData(htf.formText(\'i_start_date\', 11, 11,
to_char(rGetAppointmentInfo.begin_date, \'DD-MON-YYYY\')));

ELSE

htp.formHidden(\'i_start_date\', to_char(rGetAppointmentInfo.begin_date,
\'DD-MON-YYYY\'));

END IF;

ELSE

htp.tableData(htf.formText(\'i_start_date\', 11, 11, i_date));

END IF;

htp.tableRowClose;

\-- Display start time textbox

htp.tableRowOpen;

htp.tableData(\'Start Time: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formText(\'i_start_time\', 8, 8,
ConvertOracleTime(rGetAppointmentInfo.begin_time)));

ELSE

htp.tableData(htf.formText(\'i_start_time\', 8, 8, StartTime));

END IF;

htp.tableRowClose;

\-- Display appointment end date

htp.tableRowOpen;

IF i_recurring = \'N\' THEN

htp.tableData(\'End Date: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

ELSIF i_action \<\> \'EDIT\' THEN

htp.tableData(\'Recurring End Date: \', \'LEFT\', \'\', \'\', \'\',
\'\', \'NOWRAP\');

END IF;

IF i_action = \'EDIT\' THEN

IF i_recurring = \'N\' THEN

htp.tableData(htf.formText(\'i_end_date\', 11, 11,
to_char(rGetAppointmentInfo.end_date, \'DD-MON-YYYY\')));

ELSE

htp.formHidden(\'i_end_date\', to_char(rGetAppointmentInfo.end_date,
\'DD-MON-YYYY\'));

END IF;

ELSE

htp.tableData(htf.formText(\'i_end_date\', 11, 11, i_date));

END IF;

htp.tableRowClose;

\-- Display end time textbox

htp.tableRowOpen;

htp.tableData(\'End Time: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formText(\'i_end_time\', 8, 8,
ConvertOracleTime(rGetAppointmentInfo.end_time)));

ELSE

htp.tableData(htf.formText(\'i_end_time\', 8, 8, EndTime));

END IF;

htp.tableRowClose;

\-- Display the location dropdown list

htp.tableRowOpen;

htp.tableData(\'Location: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_location\', \'\', 1);

FOR Loop1 IN cGetLocationInfo LOOP

IF Loop1.location_id = rGetAppointmentInfo.location_id THEN

htp.formSelectOption(Loop1.location, \'Y\', \'VALUE=\"\' \|\|
Loop1.location_id \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.location, NULL, \'VALUE=\"\' \|\|
Loop1.location_id \|\| \'\"\');

END IF;

END LOOP;

IF rGetAppointmentInfo.location_id IS NULL THEN

htp.formSelectOption(\'Default\', \'Y\', \'VALUE=\"\"\');

ELSE

htp.formSelectOption(\'Default\', NULL, \'VALUE=\"\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the timezone dropdown list

htp.tableRowOpen;

htp.tableData(\'Timezone: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_timezone\', \'\', 1);

FOR Loop1 IN cGetTimezoneInfo LOOP

IF Loop1.tzid = rGetAppointmentInfo.tzid THEN

htp.formSelectOption(Loop1.timezone, \'Y\', \'VALUE=\"\' \|\| Loop1.tzid
\|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.timezone, NULL, \'VALUE=\"\' \|\| Loop1.tzid
\|\| \'\"\');

END IF;

END LOOP;

IF rGetAppointmentInfo.tzid IS NULL THEN

htp.formSelectOption(\'Default\', \'Y\', \'VALUE=\"\"\');

ELSE

htp.formSelectOption(\'Default\', NULL, \'VALUE=\"\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the color selector dropdown list

htp.tableRowOpen;

htp.tableData(\'Text Color: \', \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_color\', \'\', 1);

FOR Loop1 IN cGetColors LOOP

IF rGetAppointmentInfo.color = Loop1.color THEN

htp.formSelectOption(Loop1.color_name, \'Y\', \'VALUE=\"\' \|\|
Loop1.color \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.color_name, NULL, \'VALUE=\"\' \|\|
Loop1.color \|\| \'\"\');

END IF;

END LOOP;

IF rGetAppointmentInfo.color IS NULL THEN

htp.formSelectOption(\'Default\', \'Y\', \'VALUE=\"\"\');

ELSE

htp.formSelectOption(\'Default\', NULL, \'VALUE=\"\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display period type for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Interval Type: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_period_type\', \'\', 1);

htp.formSelectOption(\'Daily\', NULL, \'VALUE=\"D\"\');

htp.formSelectOption(\'Weekly\', \'Y\', \'VALUE=\"W\"\');

htp.formSelectOption(\'Monthly\', NULL, \'VALUE=\"M\"\');

htp.formSelectOption(\'Yearly\', NULL, \'VALUE=\"Y\"\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

END IF;

\-- Display period textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Interval: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

\--htp.tableData(htf.formText(\'i_period\', 3, 3,
rGetRecurringInfo.r_period));

htp.tableData(htf.formText(\'i_period\', 3, 3, \'1\'));

htp.tableRowClose;

END IF;

\-- Display behavior for non-workdays for recurring events (if
necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Non-workday: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_non_workday\', \'\', 1);

htp.formSelectOption(\'Prev workday\', NULL, \'VALUE=\"-1\"\');

htp.formSelectOption(\'Do nothing\', \'Y\', \'VALUE=\"0\"\');

htp.formSelectOption(\'Allow\', NULL, \'VALUE=\"\"\');

htp.formSelectOption(\'Next workday\', NULL, \'VALUE=\"1\"\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

END IF;

\-- Display Day of Week textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Days of Week: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_day_of_week\', 10, 25,
rGetRecurringInfo.day_of_week));

htp.tableRowClose;

END IF;

\-- Display Weeks of Month textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Weeks of Month: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_week_of_month\', 10, 255,
rGetRecurringInfo.week_of_month));

htp.tableRowClose;

END IF;

\-- Display Days of Month textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Days of Month: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_day_of_month\', 10, 255,
rGetRecurringInfo.day_of_month));

htp.tableRowClose;

END IF;

\-- Display Month of Year textbox for recurring events (if necessary)

IF i_recurring = \'Y\' AND i_action \<\> \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(\'Date of Year: \', \'LEFT\', \'\', \'\', \'\', \'\',
\'NOWRAP\');

htp.tableData(htf.formText(\'i_date_of_year\', 10, 255,
rGetRecurringInfo.date_of_year));

htp.tableRowClose;

END IF;

\-- Display update/delete options

IF i_recurring = \'Y\' AND i_action = \'EDIT\' THEN

htp.tableRowOpen;

htp.tableData(htf.hr, \'CENTER\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'Apply this update/delete to:\', \'LEFT\', \'\', \'\',
\'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'Today\') \|\| \' This day
only\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'After\') \|\| \' This day and
after\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'i_range\', \'Everything\', \'Y\') \|\| \'
Everything\', \'LEFT\', \'\', \'\', \'\', \'2\', \'NOWRAP\');

htp.tableRowClose;

END IF;

\-- Close the appointment edit table

htp.tableRowOpen;

htp.tableData(htf.hr,\'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableClose;

\-- Open the submit buttons table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"2\"\');

\-- Display the submit button

htp.tableRowOpen;

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formSubmit(\'i_operation\', \'Update\'),\'\', \'\',
\'\', \'\', \'\', \'\');

ELSE

htp.tableData(htf.formSubmit(\'i_operation\', \' Add \'),\'\', \'\',
\'\', \'\', \'\', \'\');

END IF;

\-- Add hidden form data

htp.formHidden(\'i_event\', i_event);

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

htp.formHidden(\'i_recurring\', i_recurring);

htp.formHidden(\'i_recur_id\', rGetAppointmentInfo.recur_event_id);

\-- Display the delete button (if necessary)

IF i_action = \'EDIT\' THEN

htp.tableData(htf.formSubmit(\'i_operation\', \'Delete\'),\'\', \'\',
\'\', \'\', \'\', \'\');

END IF;

\-- Close the Add/Update/Delete web form

htp.formClose;

\-- Open the \"Cancel\" web form

htp.formOpen(\'cal0003.display_navigation\', \'POST\', \'\');

\-- Display the cancel button

htp.tableData(htf.formSubmit(\'\', \'Cancel\'),\'RIGHT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"cancel\" web form

htp.formClose;

\-- Close the submit button table

htp.tableRowClose;

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Insert/Update the appointment \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_appointment(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),
i_operation IN VARCHAR2,

i_event IN NUMBER DEFAULT NULL, i_subject IN VARCHAR2 DEFAULT NULL,

i_start_date IN VARCHAR2 DEFAULT NULL, i_end_date IN VARCHAR2 DEFAULT
NULL,

i_start_time IN VARCHAR2 DEFAULT NULL, i_end_time IN VARCHAR2 DEFAULT
NULL,

i_location IN VARCHAR2 DEFAULT NULL, i_color IN VARCHAR2 DEFAULT NULL,

i_detail IN VARCHAR2 DEFAULT NULL, i_timezone IN VARCHAR2 DEFAULT NULL,

i_period_type IN VARCHAR2 DEFAULT NULL, i_period IN VARCHAR2 DEFAULT
NULL,

i_non_workday IN VARCHAR2 DEFAULT NULL, i_day_of_week IN VARCHAR2
DEFAULT NULL,

i_week_of_month IN VARCHAR2 DEFAULT NULL, i_day_of_month IN VARCHAR2
DEFAULT NULL,

i_date_of_year IN VARCHAR2 DEFAULT NULL, i_recurring IN VARCHAR2 DEFAULT
\'N\',

i_range IN VARCHAR2 DEFAULT NULL, i_recur_id IN VARCHAR2 DEFAULT NULL)
IS

\-- Declare cursors

CURSOR cGetNotes(CalendarID IN VARCHAR2, CalDate IN VARCHAR2) IS

SELECT event_id

FROM cal_event

WHERE pim_object_id = CalendarID AND

begin_date = to_date(CalDate, \'DD-MON-YYYY\') AND

event_type = 4000 AND

inactive = \'N\'

ORDER BY viewing_order;

\-- Declare constants/variables

TempEventSeq NUMBER;

TempTextSeq NUMBER;

TempTotEvents NUMBER;

StartTime NUMBER(4);

EndTime NUMBER(4);

UserBadge VARCHAR2(5);

TempTime VARCHAR2(9);

TempDateTime DATE;

TempNumber NUMBER(4);

TempNumber2 NUMBER(4);

ErrorPos NUMBER(2) := 0;

TextBlock VARCHAR2(2000);

NewDayOfMonth VARCHAR2(256);

OracleColor VARCHAR2(12);

TempString VARCHAR2(3);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Determine Oracle color to use (for Chris\' Oracle Report)

IF i_color IS NULL THEN

OracleColor := NULL;

ELSE

SELECT oracle_color INTO OracleColor

FROM cal_color

WHERE color = i_color;

END IF;

\-- Make sure date and times are valid (caught by error trap if invalid)

IF i_operation = \' Add \' OR i_operation = \'Update\' THEN

\-- Make sure subject is not blank

ErrorPos := 1;

IF i_subject IS NULL OR i_subject = \'\' THEN

RAISE VALUE_ERROR;

END IF;

\-- Make sure dates are valid

ErrorPos := 2;

TempDateTime := to_date(i_start_date, \'DD-MON-YYYY\');

TempNumber := to_number(substr(i_start_date, length(i_start_date) - 4,
4));

TempDateTime := to_date(i_end_date, \'DD-MON-YYYY\');

TempNumber := to_number(substr(i_end_date, length(i_end_date) - 4, 4));

\-- Make sure start time is valid

ErrorPos := 3;

IF i_start_time IS NOT NULL THEN

TempTime := ltrim(rtrim(i_start_time));

\-- Check for the full \'AM\' or \'PM\' marker

TempNumber := instr(UPPER(TempTime), \'AM\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'PM\', 1);

END IF;

\-- Check for only a \'A\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'A\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Check for only a \'P\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'P\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Convert military time

IF TempNumber = 0 THEN

TempString := substr(TempTime, 1, 2);

IF substr(TempString, 2, 1) \<\> \':\' THEN

IF to_number(TempString) \> 12 THEN

TempTime := to_char(to_number(TempString) - 12) \|\| substr(TempTime, 3,
length(TempTime) - 2) \|\| \' PM\';

ELSE

TempTime := TempTime \|\| \' AM\';

END IF;

END IF;

END IF;

\-- Add space between time and AM/PM marker (if necessary)

IF TempNumber \> 0 THEN

TempNumber2 := instr(TempTime, \' \', 1);

IF TempNumber2 = 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \' \' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

\-- Check for the colon seperator

TempNumber := instr(UPPER(TempTime), \':\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(TempTime, \' \', 1);

IF TempNumber \> 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \':00\' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

END IF;

TempDateTime := to_date(to_char(sysdate, \'DD-MON-YYYY\') \|\| \' \'
\|\| TempTime, \'DD-MON-YYYY hh:mi AM\');

StartTime := ConvertRealTime(to_char(TempDateTime, \'hh24\'),
to_char(TempDateTime, \'mi\'));

\-- Make sure end time is valid

ErrorPos := 4;

IF i_end_time IS NOT NULL THEN

TempTime := ltrim(rtrim(i_end_time));

\-- Check for the full \'AM\' or \'PM\' marker

TempNumber := instr(UPPER(TempTime), \'AM\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'PM\', 1);

END IF;

\-- Check for only a \'A\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'A\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Check for only a \'P\' and add the \'M\' (if necessary)

IF TempNumber = 0 THEN

TempNumber := instr(UPPER(TempTime), \'P\', 1);

IF TempNumber \> 0 THEN

TempTime := TempTime \|\| \'M\';

END IF;

END IF;

\-- Convert military time

IF TempNumber = 0 THEN

TempString := substr(TempTime, 1, 2);

IF substr(TempString, 2, 1) \<\> \':\' THEN

IF to_number(TempString) \> 12 THEN

TempTime := to_char(to_number(TempString) - 12) \|\| substr(TempTime, 3,
length(TempTime) - 2) \|\| \' PM\';

ELSE

TempTime := TempTime \|\| \' AM\';

END IF;

END IF;

END IF;

\-- Add space between time and AM/PM marker (if necessary)

IF TempNumber \> 0 THEN

TempNumber2 := instr(TempTime, \' \', 1);

IF TempNumber2 = 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \' \' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

\-- Check for the colon seperator

TempNumber := instr(UPPER(TempTime), \':\', 1);

IF TempNumber = 0 THEN

TempNumber := instr(TempTime, \' \', 1);

IF TempNumber \> 0 THEN

TempTime := substr(TempTime, 1, TempNumber - 1) \|\| \':00\' \|\|
substr(TempTime, TempNumber, length(TempTime) - TempNumber + 1);

END IF;

END IF;

END IF;

TempDateTime := to_date(to_char(sysdate, \'DD-MON-YYYY\') \|\| \' \'
\|\| TempTime, \'DD-MON-YYYY hh:mi AM\');

EndTime := ConvertRealTime(to_char(TempDateTime, \'hh24\'),
to_char(TempDateTime, \'mi\'));

END IF;

\-- Make sure recurring data is valid

IF i_recurring = \'Y\' THEN

ErrorPos := 5;

IF IsNumeric(i_period \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 6;

IF IsNumeric(i_day_of_week \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 7;

IF IsNumeric(i_week_of_month \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

ErrorPos := 8;

IF IsNumeric(i_day_of_month \|\| \',\') = FALSE THEN

RAISE VALUE_ERROR;

END IF;

END IF;

\-- Make sure period is entered for recurring data

ErrorPos := 9;

IF i_recurring = \'Y\' AND i_operation = \' Add \' AND i_period IS NULL
THEN

RAISE VALUE_ERROR;

END IF;

\-- Make sure day, week and/or month data has been entered

IF i_recurring = \'Y\' AND i_operation = \' Add \' THEN

IF i_period_type = \'W\' THEN

ErrorPos := 10;

IF i_day_of_week IS NULL THEN

RAISE VALUE_ERROR;

END IF;

ELSIF i_period_type = \'M\' THEN

IF (i_day_of_week IS NOT NULL) AND (i_week_of_month IS NULL) THEN

ErrorPos := 11;

RAISE VALUE_ERROR;

ELSIF (i_day_of_week IS NULL) AND (i_week_of_month IS NOT NULL) THEN

ErrorPos := 12;

RAISE VALUE_ERROR;

ELSIF (i_day_of_week IS NULL) AND (i_week_of_month IS NULL) AND
(i_day_of_month IS NULL) THEN

ErrorPos := 13;

RAISE VALUE_ERROR;

END IF;

ELSIF i_period_type = \'Y\' THEN

ErrorPos := 14;

IF i_date_of_year IS NULL THEN

RAISE VALUE_ERROR;

END IF;

END IF;

END IF;

ErrorPos := 15;

\-- Get the current user\'s badge number

UserBadge := lib02.GetBadge(i_pid);

\-- Send an e-mail if D. E. Moncton\'s calendar had a deletion

IF i_calendar = \'115732\' AND i_operation = \'Delete\' THEN

IF UserBadge = \'25520\' THEN

\-- If user is Rose, send an e-mail to Cathy

run_print_it(\'Appt. - Delete\', i_event, NVL(i_start_time, \'None\'),
\'kfr@ornl.gov\');

ELSE

\-- If user is Cathy, send an e-mail to Rose

run_print_it(\'Appt. - Delete\', i_event, NVL(i_start_time, \'None\'),
\'rt@aps.anl.gov\');

END IF;

\-- Waste time to allow e-mail to be sent before it gets deleted

FOR Loop1 IN 1..100000 LOOP

NULL;

END LOOP;

END IF;

\-- Process the request

IF i_operation = \' Add \' THEN

\-- Check for detail text to insert

IF i_detail IS NOT NULL THEN

\-- Get the next text detail sequence number

SELECT cal_text_id_seq.nextval INTO TempTextSeq FROM dual;

\-- Insert the detail text

FOR Loop1 IN 1..ceil(length(i_detail) / 2000) LOOP

TextBlock := substr(i_detail, (Loop1 - 1) \* 2000, 2000);

INSERT INTO cal_text_dtl(

text_id, line_no, text_line)

VALUES(

TempTextSeq, Loop1, TextBlock);

END LOOP;

ELSE

TempTextSeq := NULL;

END IF;

\-- Determine whether to insert to CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Get the next event sequence number

SELECT seq_event_id.nextval INTO TempEventSeq FROM dual;

\-- Insert the new event to CAL_EVENT

INSERT INTO cal_event(

event_id, event_type, subject, create_date, created_by, begin_date,
end_date, begin_time, end_time,

location_id, color, inactive, pim_object_id, text_id, tzid,
oracle_color)

VALUES(

TempEventSeq, \'6000\', rtrim(i_subject, CR \|\| LF), sysdate,
UserBadge, to_date(i_start_date, \'DD-MON-YYYY\'),

to_date(i_end_date, \'DD-MON-YYYY\'), StartTime,

EndTime, i_location, i_color, \'N\', i_calendar, TempTextSeq,
i_timezone, OracleColor);

ELSE

\-- Get the next recurring event sequence number

SELECT seq_recur_id.nextval INTO TempEventSeq FROM dual;

\-- Pad the Day of Month string

NewDayOfMonth := PadDayOfMonth(i_day_of_month \|\| \',\');

\-- Insert the new event to CAL_RECURRING

INSERT INTO cal_recurring(

recur_event_id, event_type, subject, create_date, created_by,
r_begin_date, r_end_date, begin_time,

end_time, location_id, color, inactive, pim_object_id, text_id, tzid,
r_period_type, r_period,

non_wd_skip, day_of_week, week_of_month, day_of_month, date_of_year,
oracle_color)

VALUES(

TempEventSeq, \'6000\', rtrim(i_subject, CR \|\| LF), sysdate,
UserBadge, to_date(i_start_date, \'DD-MON-YYYY\'),

to_date(i_end_date, \'DD-MON-YYYY\'), StartTime, EndTime, i_location,
i_color, \'N\', i_calendar,

TempTextSeq, i_timezone, i_period_type, i_period, i_non_workday,
i_day_of_week, i_week_of_month,

NewDayOfMonth, i_date_of_year, OracleColor);

\-- Expand the recurring appointment into the CAL_EVENT table

cal0008.expand_recurring_event(TempEventSeq);

END IF;

ELSIF i_operation = \'Update\' THEN

\-- Check if event already has a text ID

SELECT text_id INTO TempTextSeq

FROM cal_event

WHERE event_id = i_event;

IF TempTextSeq IS NOT NULL THEN

IF i_range = \'Today\' OR i_range = \'After\' THEN

\-- Get the next text detail sequence number

IF i_detail IS NOT NULL THEN

SELECT cal_text_id_seq.nextval INTO TempTextSeq FROM dual;

ELSE

TempTextSeq := NULL;

END IF;

ELSE

\-- Delete the existing detail text

DELETE FROM cal_text_dtl

WHERE text_id = TempTextSeq;

\-- Get the next text detail sequence number

IF i_detail IS NOT NULL THEN

SELECT cal_text_id_seq.nextval INTO TempTextSeq FROM dual;

ELSE

TempTextSeq := NULL;

END IF;

END IF;

\-- Insert the detail text

IF i_detail IS NOT NULL THEN

FOR Loop1 IN 1..ceil(length(i_detail) / 2000) LOOP

TextBlock := rtrim(substr(i_detail, (Loop1 - 1) \* 2000, 2000), CR \|\|
LF);

INSERT INTO cal_text_dtl(

text_id, line_no, text_line)

VALUES(

TempTextSeq, Loop1, rtrim(TextBlock, CR \|\| LF));

END LOOP;

END IF;

ELSE

IF i_detail IS NOT NULL THEN

\-- Get the next text detail sequence number

SELECT cal_text_id_seq.nextval INTO TempTextSeq FROM dual;

\-- Insert the detail text

FOR Loop1 IN 1..ceil(length(i_detail) / 2000) LOOP

TextBlock := rtrim(substr(i_detail, (Loop1 - 1) \* 2000, 2000), CR \|\|
LF);

INSERT INTO cal_text_dtl(

text_id, line_no, text_line)

VALUES(

TempTextSeq, Loop1, rtrim(TextBlock, CR \|\| LF));

END LOOP;

END IF;

END IF;

\-- Determine whether to insert to CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Update the event to CAL_EVENT

UPDATE cal_event SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge,

begin_date = to_date(i_start_date, \'DD-MON-YYYY\'), end_date =
to_date(i_end_date, \'DD-MON-YYYY\'),

begin_time = StartTime, end_time = EndTime, oracle_color = OracleColor,

location_id = i_location, color = i_color, text_id = TempTextSeq, tzid =
i_timezone

WHERE event_id = i_event;

ELSE

\-- Update the event to CAL_RECURRING

IF i_range = \'Today\' THEN

UPDATE cal_event SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge,

begin_date = to_date(i_start_date, \'DD-MON-YYYY\'), end_date =
to_date(i_end_date, \'DD-MON-YYYY\'),

begin_time = StartTime, end_time = EndTime, location_id = i_location,
color = i_color,

text_id = TempTextSeq, tzid = i_timezone, recur_event_id = NULL,
oracle_color = OracleColor

WHERE event_id = i_event;

ELSE

UPDATE cal_recurring SET

subject = rtrim(i_subject, CR \|\| LF), mod_date = sysdate, mod_by =
UserBadge,

begin_time = StartTime, end_time = EndTime, location_id = i_location,
color = i_color,

text_id = TempTextSeq, tzid = i_timezone, oracle_color = OracleColor

WHERE recur_event_id = i_recur_id;

END IF;

\-- Expand the recurring appointment into the CAL_EVENT table

IF i_range = \'After\' THEN

cal0008.update_recurring(i_recur_id, to_date(i_start_date,
\'DD-MON-YYYY\'));

ELSIF i_range = \'Everything\' THEN

cal0008.update_recurring(i_recur_id);

END IF;

END IF;

ELSIF i_operation = \'Delete\' THEN

\-- Get detail text for this event

SELECT text_id INTO TempTextSeq

FROM cal_event

WHERE event_id = i_event;

\-- Determine whether to delete from CAL_EVENT or CAL_RECURRING

IF i_recurring = \'N\' THEN

\-- Check to see if detail text is not being used by other events

\-- (can happen if this event was once part of a recurring event)

SELECT COUNT(event_id) INTO TempTotEvents

FROM cal_event

WHERE text_id = TempTextSeq;

\-- Delete the detail text (if necessary)

IF TempTotEvents \< 2 THEN

DELETE FROM cal_text_dtl

WHERE text_id = TempTextSeq;

END IF;

\-- Delete the selected event

DELETE FROM cal_event

WHERE event_id = i_event;

ELSE

IF i_range = \'Today\' THEN

\-- Check to see if there are more than one recurring event with this
recur ID

SELECT COUNT(event_id) INTO TempTotEvents

FROM cal_event

WHERE text_id = TempTextSeq;

\-- Delete the detail text (if necessary)

IF TempTotEvents \< 2 THEN

DELETE FROM cal_text_dtl

WHERE text_id = TempTextSeq;

END IF;

\-- Delete the event

DELETE FROM cal_event

WHERE event_id = i_event;

ELSIF i_range = \'After\' THEN

\-- Check to see if there are more than one recurring event with this
recur ID

SELECT COUNT(event_id) INTO TempTotEvents

FROM cal_event

WHERE text_id = TempTextSeq AND

begin_date \< to_date(i_start_date, \'DD-MON-YYYY\');

\-- Delete the detail text (if necessary)

IF TempTotEvents \< 1 THEN

DELETE FROM cal_text_dtl

WHERE text_id = TempTextSeq;

END IF;

\-- Call procedure to delete recurring information from CAL_EVENT

cal0008.remove_recurring(i_recur_id, to_date(i_start_date,
\'DD-MON-YYYY\'));

ELSIF i_range = \'Everything\' THEN

\-- Delete the detail text

DELETE FROM cal_text_dtl

WHERE text_id = TempTextSeq;

\-- Call procedure to delete recurring information from CAL_EVENT

cal0008.remove_recurring(i_recur_id);

END IF;

END IF;

END IF;

\-- Send an e-mail if D. E. Moncton\'s calendar had an addition or
update

IF i_calendar = \'115732\' THEN

IF UserBadge = \'25520\' THEN

\-- If user is Rose, send an e-mail to Cathy

IF i_operation = \' Add \' THEN

run_print_it(\'Appt. - New\', TempEventSeq, NVL(i_start_time, \'None\'),
\'kfr@ornl.gov\');

ELSIF i_operation = \'Update\' THEN

run_print_it(\'Appt. - Update\', i_event, NVL(i_start_time, \'None\'),
\'kfr@ornl.gov\');

END IF;

ELSE

\-- If user is Cathy, send an e-mail to Rose

IF i_operation = \' Add \' THEN

run_print_it(\'Appt. - New\', TempEventSeq, NVL(i_start_time, \'None\'),
\'rt@aps.anl.gov\');

ELSIF i_operation = \'Update\' THEN

run_print_it(\'Appt. - Update\', i_event, NVL(i_start_time, \'None\'),
\'rt@aps.anl.gov\');

END IF;

END IF;

END IF;

\-- Refresh the frame set

IF i_operation = \' Add \' OR i_operation = \'Update\' THEN

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), StartTime);

ELSE

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'));

END IF;

\-- End valid PID check

END IF;

\-- Error trap

EXCEPTION WHEN others THEN

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen;

IF ErrorPos = 1 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The subject field
cannot be blank.\<P\>Click your browser\'\'s \"Back\" button and correct
the error.\');

ELSIF ErrorPos = 2 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The date you entered is
incorrect. Make sure the format is correct, including the full 4-digit
year. (Example: 05-MAR-1999).\<P\>Click your browser\'\'s \"Back\"
button and correct the error if necessary.\');

ELSIF ErrorPos = 3 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The start time you
entered is incorrect. Make sure the format is correct, including the
AM/PM marker. (Example: 10:30 AM).\<P\>Click your browser\'\'s \"Back\"
button and correct the error if necessary.\');

ELSIF ErrorPos = 4 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The end time you
entered is incorrect. Make sure the format is correct, including the
AM/PM marker. (Example: 10:30 AM).\<P\>Click your browser\'\'s \"Back\"
button and correct the error if necessary.\');

ELSIF ErrorPos = 5 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Interval\" you
entered is incorrect. Make sure you\'\'ve entered a valid
number.\<P\>Click your browser\'\'s \"Back\" button and correct the
error if necessary.\');

ELSIF ErrorPos = 6 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5)\<P\>Click your
browser\'\'s \"Back\" button and correct the error

if necessary.\');

ELSIF ErrorPos = 7 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Weeks of Month\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5)\<P\>Click your
browser\'\'s \"Back\" button and correct the err

or if necessary.\');

ELSIF ErrorPos = 8 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Month\"
you entered is incorrect. Make sure you\'\'ve entered only valid numbers
separated by commas with no spaces. (Example: 1,3,5,12)\<P\>Click your
browser\'\'s \"Back\" button and correct the e

rror if necessary.\');

ELSIF ErrorPos = 9 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The interval field must
be filled in.\<P\>Click your browser\'\'s \"Back\" button and correct
the error if necessary.\');

ELSIF ErrorPos = 10 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
field must be filled in.\<P\>Click your browser\'\'s \"Back\" button and
correct the error if necessary.\');

ELSIF ErrorPos = 11 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Weeks of Month\"
field must be filled in when also using the \"Days of Week\"
field.\<P\>Click your browser\'\'s \"Back\" button and correct the error
if necessary.\');

ELSIF ErrorPos = 12 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Days of Week\"
field must be filled in when also using the \"Weeks of Month\"
field.\<P\>Click your browser\'\'s \"Back\" button and correct the error
if necessary.\');

ELSIF ErrorPos = 13 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'You must fill in the
\"Days of Month\" field or both the \"Days of Week\" and \"Weeks of
Month\" fields.\<P\>Click your browser\'\'s \"Back\" button and correct
the error if necessary.\');

ELSIF ErrorPos = 14 THEN

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'The \"Months of Year\"
field must be filled in.\<P\>Click your browser\'\'s \"Back\" button and
correct the error if necessary.\');

ELSE

\--lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'+\' \|\| StartTime
\|\| \'+Click your browser\'\'s \"Back\" button and correct the error if
necessary.\');

lib02.DisplayError(SQLCODE, SQLERRM, ErrorPos, \'Click your browser\'\'s
\"Back\" button and correct the error if necessary.\');

END IF;

htp.bodyClose;

htp.htmlClose;

END;

\-- \*\*\* Display the color legend \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_legend(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetColors IS

SELECT a.color, a.description, b.color_name

FROM cal_object_colors a, cal_color b

WHERE a.pim_object_id = i_calendar AND

a.color = b.color AND

a.description IS NOT NULL

ORDER BY b.color_name;

\-- Declare variables

UserPrivs VARCHAR2(100) := \'\';

Counter NUMBER := 0;

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_FORMS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the main table to display the colors

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Color
Legend\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

\-- Display the colors

FOR Loop1 IN cGetColors LOOP

htp.tableRowOpen;

htp.tableData(Loop1.color_name \|\| \':&nbsp;&nbsp;&nbsp;\', \'\', \'\',
\'\', \'\', \'\', \'NOWRAP\');

htp.tableData(\'&nbsp;&nbsp;&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'WIDTH=\"100%\" BGCOLOR=\"#\' \|\| Loop1.color \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<B\>Description: \</B\>\' \|\| Loop1.description, \'\',
\'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

Counter := Counter + 1;

END LOOP;

\-- Display \"no data\" message if no records found

IF Counter = 0 THEN

htp.tableRowOpen;

htp.tableData(\'\<B\>No Colors Defined\</B\>\', \'CENTER\', \'\', \'\',
\'\', \'2\', \'\');

htp.tableRowClose;

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

htp.tableRowOpen;

htp.tableData(\'Click the \"Edit\" button to create descriptions\',
\'CENTER\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

END IF;

END IF;

\-- Close the color table

htp.tableRowOpen;

htp.tableData(\'\<HR\>\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableClose;

\-- Open the button table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

\-- Display the Edit button

IF instr(UserPrivs, \'WRITE\', 1) \> 0 THEN

\-- Open the \"submit\" web form

htp.formOpen(\'cal0003.change_legend_page\', \'POST\', \'Navigation\',
\'\', \'\');

\-- Display the button

htp.tableData(htf.formSubmit(\'\', \' Edit \'),\'LEFT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"edit\" web form

htp.formClose;

END IF;

\-- Open the \"Cancel\" web form

htp.formOpen(\'cal0003.display_navigation\', \'POST\', \'\');

\-- Display the cancel button

htp.tableData(htf.formSubmit(\'\', \'Close\'),\'RIGHT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"cancel\" web form

htp.formClose;

\-- Close the button table

htp.tableRowClose;

htp.tableClose;

\-- Close the HTML document

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display the change legend page \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_legend_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetColors IS

SELECT b.color, a.description, b.color_name

FROM cal_object_colors a, cal_color b

WHERE a.pim_object_id(+) = i_calendar AND

a.color(+) = b.color

ORDER BY b.color_name;

\-- Declare variables

UserPrivs VARCHAR2(100) := \'\';

BrowserType VARCHAR2(255);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the web browser type the user is using

BrowserType := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_FORMS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the \"submit\" web form

htp.formOpen(\'cal0003.change_legend\', \'POST\', \'\_top\', \'\',
\'\');

\-- Open the main table to display the colors

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Edit Color
Legend\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_MOD \|\| \'\" WIDTH=\"100%\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

\-- Display the colors

FOR Loop1 IN cGetColors LOOP

htp.tableRowOpen;

htp.tableData(Loop1.color_name \|\| \': \', \'\', \'\', \'\', \'\',
\'\', \'NOWRAP\');

htp.tableData(\'&nbsp;&nbsp;&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'WIDTH=\"65%\" BGCOLOR=\"#\' \|\| Loop1.color \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

IF instr(BrowserType, \'MSIE\', 1) \> 0 THEN

htp.tableData(htf.formText(\'i_description\', 37, 255,
Loop1.description), \'LEFT\', \'\', \'\', \'\', \'2\', \'\');

ELSE

htp.tableData(htf.formText(\'i_description\', 20, 255,
Loop1.description), \'LEFT\', \'\', \'\', \'\', \'2\', \'\');

END IF;

htp.formHidden(\'i_color\', Loop1.color);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

END LOOP;

\-- Close the color table

htp.tableRowOpen;

htp.tableData(\'\<HR\>\', \'\', \'\', \'\', \'\', \'2\', \'\');

htp.tableRowClose;

htp.tableClose;

\-- Open the button table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\"\');

htp.tableRowOpen;

\-- Display the Update button

htp.tableData(htf.formSubmit(\'\', \'Update\'),\'LEFT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"edit\" web form

htp.formClose;

\-- Open the \"Cancel\" web form

htp.formOpen(\'cal0003.display_navigation\', \'POST\', \'\');

\-- Display the cancel button

htp.tableData(htf.formSubmit(\'\', \'Close\'),\'RIGHT\', \'\', \'\',
\'\', \'\', \'WIDTH=\"100%\"\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_date\', i_date);

\-- Close the \"cancel\" web form

htp.formClose;

\-- Close the button table

htp.tableRowClose;

htp.tableClose;

\-- Close the HTML document

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Change the legend \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE change_legend(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar IN
VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_color IN
lib.val_arr,

i_description IN lib.val_arr) IS

BEGIN

\-- Delete existing color descriptions

DELETE FROM cal_object_colors

WHERE pim_object_id = i_calendar;

\-- Insert new colors and descriptions

FOR Counter IN 1..i_color.count LOOP

INSERT INTO cal_object_colors(

pim_object_id, color, description)

VALUES(

i_calendar, i_color(Counter), i_description(Counter));

END LOOP;

\-- Refresh the frame set

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'));

END;

\-- \*\*\* Change the default calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE set_default_calendar(i_calendar IN VARCHAR2, i_badge IN
VARCHAR2,

i_pid IN VARCHAR2 DEFAULT \'NEW\', i_date IN VARCHAR2 DEFAULT
to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetDefaultCal IS

SELECT pim_object_default

FROM cal_user_prefs

WHERE badge_no = i_badge;

rGetDefaultCal cGetDefaultCal%ROWTYPE;

BEGIN

\-- Check to see if user already has a preference record

OPEN cGetDefaultCal;

FETCH cGetDefaultCal INTO rGetDefaultCal;

\-- Insert or Update the calendar preference

IF cGetDefaultCal%NOTFOUND THEN

INSERT INTO cal_user_prefs(

badge_no, pim_object_default)

VALUES(

i_badge, i_calendar);

ELSE

UPDATE cal_user_prefs SET

pim_object_default = i_calendar

WHERE badge_no = i_badge;

END IF;

\-- Close the cursor

CLOSE cGetDefaultCal;

\-- Refresh the frame set

cal0003.display_listview(i_pid, i_calendar, to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'MON\'), to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'));

END;

END CAL0003;

/

CREATE OR REPLACE package cal0004 is

\-- Package that works on generating PDF and CSV files

\-- Created: 25-MAY-1999 by fml

PROCEDURE startPage (i_pid in varchar2 default \'NEW\');

PROCEDURE start_page (i_pid in varchar2 default \'NEW\');

PROCEDURE run_calendar_pdf (i_pid in varchar2 default \'NEW\');

function Time2ASCII(i_TIME in NUMBER default NULL,

i_format in varchar2 default \'HH24:MI\') return VARCHAR2;

pragma restrict_references (Time2ASCII,WNDS);

pragma restrict_references (Time2ASCII,RNDS);

END;

/

CREATE OR REPLACE package body cal0004 is

return_status varchar2(255);

\-- str constant varchar2(50) :=
\'webdev\'\|\|\'/\'\|\|\'lay1lady1lay\';

\--

\--

\--

function has_role (i_pid in varchar2, role_in in varchar2) return
boolean is

cursor get_username(p_pid varchar2) is

select \'OPS\$\' \|\| username as username

from ows_app_login

where pid = p_pid;

cursor get_role(user_name varchar2) is

select \*

from gen_role_privs

where grantee = user_name

and granted_role = role_in;

user_rec get_username%rowtype;

role_rec get_role%rowtype;

begin

open get_username(i_pid);

fetch get_username into user_rec;

\--htp.p(\'USERNAME=\' \|\| user_rec.username \|\| \' i_pid=\' \|\|
i_pid \|\| \' role=\' \|\| role_in);

for role_rec in get_role(user_rec.username) loop

if get_role%found then

close get_username;

return TRUE;

end if;

end loop;

return FALSE;

end;

\--

\-- Time2ASCII - Convert TIME to ascii format (originally by KEM)

\--

function Time2ASCII(i_TIME in NUMBER default NULL,

i_format in varchar2 default \'HH24:MI\') return

VARCHAR2 is

\-- usage: l_time_str := Time2ASCII(the_oo_time, \'HH:MIam\')

theHour number;

theMin number;

theH varchar2(2);

theM varchar2(2);

theTime varchar2(10);

result varchar2(50);

\--

begin

result := \'00:00\';

if i_time is NOT NULL and i_format is NOT NULL then

theHour := floor(i_TIME/60);

theMin := MOD(i_TIME,60);

theTime := to_char(to_date(

to_char(theHour) \|\| \':\' \|\|

to_char(theMin,\'09\'),

\'HH24:MI\'),i_format);

result := theTIME;

end if;

return(result);

exception

when others then

return (result);

end;

\--

\--

\--

PROCEDURE startPage (i_pid in varchar2 default \'NEW\') is

\--

l_title varchar2(100) := \'Calendar and Rolodex Download Page\';

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'CAL0004\') then

log0002.login(\'CAL0004\',\'\',i_pid);

return;

end if;

\--

\-- Display Page

\--

htp.htmlOpen;

htp.headOpen;

htp.title(l_title);

htp.headClose;

htp.bodyOpen(\'\', \'BGCOLOR=\"#D0D0D0\"\');

\-- Display titlebar

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"20\" CELLSPACING=\"0\"
CELLPADDING=\"0\" BGCOLOR=\"#0E2525\" WIDTH=\"100%\"\');

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|l_title),\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\"
BACKGROUND=\"/gen-img/apstext2.gif\"\');

htp.tableData(\'\<A NAME=\"Bottom\"
HREF=\"mailto:mis_mgrs@aps.anl.gov\"\>\<IMG
SRC=\"/gen-img/email_mis_button.gif\"
BORDER=\"0\"\>\</A\>\',\'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.tableData(\'\<A NAME=\"Bottom\" HREF=\"log0002.log_out\"
TARGET=\"\_top\"\>\<IMG SRC=\"/gen-img/logout_button.gif\"
BORDER=\"0\"\>\</A\>\',\'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.tableRowClose;

htp.tableClose;

htp.br;

\-- Display Download lines

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"20\" CELLSPACING=\"5\"
CELLPADDING=\"3\" BGCOLOR=\"#0E2525\" WIDTH=\"100%\"\');

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor(\'/gen-bin/uncgi/sweb_reporter.pdf?i_report=MONCTON_CAL&i_pid=\'\|\|i_pid\|\|\'&i_ows_app=CAL0004\',

\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|

\'Download calendar.pdf\'\|\|

\'\</FONT\>\'));

htp.tableRowClose;

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor(\'/gen-bin/uncgi/sweb_reporter.pdf?i_report=ROLO_PDFEXPORT&i_pim_object_id=1&i_pid=\'\|\|i_pid\|\|\'&i_ows_app=CAL0004\',

\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|

\'Download rolodex.pdf\'\|\|

\'\</FONT\>\'));

htp.tableRowClose;

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor(\'cal0004.run_calendar_pdf\',

\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|

\'Download monthly_calendar.pdf\'\|\|

\'\</FONT\>\'));

htp.tableRowClose;

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor(\'/gen-bin/uncgi/sweb_reporter.txt?i_report=EXP_LOTUSORG5&i_exp_type=CALENDAR&i_pid=\'\|\|

i_pid\|\|\'&i_ows_app=CAL0004\',

\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|

\'Download lo_calendar.txt for Lotus Organizer 5\'\|\|

\'\</FONT\>\'));

htp.tableRowClose;

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor(\'/gen-bin/uncgi/sweb_reporter.txt?i_report=EXP_LOTUSORG5&i_exp_type=ROLODEX&i_pid=\'\|\|

i_pid\|\|\'&i_ows_app=CAL0004\',

\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"4\"
COLOR=\"#FFFFFF\"\>&nbsp;\'\|\|

\'Download lo_rolodex.txt for Lotus Organizer 5\'\|\|

\'\</FONT\>\'));

htp.tableRowClose;

htp.tableClose;

\-- Manually close the HTML page

htp.bodyClose;

htp.htmlClose;

\--

end;

\--

PROCEDURE start_page (i_pid in varchar2 default \'NEW\') is

begin

cal0004.startPage(i_pid);

end;

PROCEDURE run_calendar_pdf (i_pid in varchar2 default \'NEW\') is

l_user varchar2(100);

str varchar2(100);

Begin

\--

\-- Pass the webdev or webprod select user into l_user from dual; Pass
the pim_object_id

\--

select UPPER(user) into l_user from dual;

if l_user = \'WEBDEV\' then

str := \'webdev\'\|\|\'/\'\|\|\'lay1lady1lay\';

else

str := \'webprod\'\|\|\'/\'\|\|\'cripple1creek\';

end if;

mis_util.utl_rep_print_it(\'\$mis_reports/\',\'cal_report\',\'B\',\'view\',

\'P\',\'SQR\',STR,\'NONE\',

\'115732\',

l_user,

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

return_status);

end;

END;

/

CREATE OR REPLACE PACKAGE CAL0005 IS

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\');

PROCEDURE display_monthview(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'),

i_month IN VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL);

PROCEDURE display_header(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

PROCEDURE display_detail(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

END CAL0005;

/

CREATE OR REPLACE PACKAGE BODY CAL0005 IS

\-- \*\*\* Declare global constants/variables \*\*\*

CR VARCHAR2(1) := chr(13);

LF VARCHAR2(1) := chr(10);

ARGONNE_COLOR VARCHAR2(7) := \'C0C0FF\';

OAK_RIDGE_COLOR VARCHAR2(7) := \'FFFFC0\';

TRAVEL_COLOR VARCHAR2(7) := \'C0FFC0\';

PAGE_BACKGROUND_COLOR VARCHAR2(7) := \'#C0C0C0\';

TABLE_CELL_PRIMARY VARCHAR2(7) := \'#303030\';

TABLE_CELL_SECONDARY VARCHAR2(7) := \'#909090\';

TABLE_CELL_MOD VARCHAR2(7) := \'#3030C0\';

TABLE_CELL_DEFAULT VARCHAR2(7) := \'#C0C0C0\';

STYLE_ALTER_LINKS VARCHAR2(200) := \'A {text-decoration: none;} A:hover
{text-decoration: underline;}\';

STYLE_BOLD VARCHAR2(200) := \'B {font-weight: bold;}\';

STYLE_HEADING_01 VARCHAR2(200) := \'.Heading01 {font-family: Tahoma,
Arial, Helvetica; font-size: 13pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_HEADING_02 VARCHAR2(200) := \'.Heading02 {font-family: Tahoma,
Arial, Helvetica; font-size: 10pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_SMALL_01 VARCHAR2(200) := \'.Small01 {font-family: Tahoma, Arial,
Helvetica; font-size: 8pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_TABLE_DATA VARCHAR2(200) := \'TD {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_FORMS VARCHAR2(200) := \'textarea {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

\-- \*\*\* Log the user in with a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\') IS

begin

IF (i_pid IS NULL) OR (i_pid = \'NEW\') OR (NOT
log0002.is_valid_pid(i_pid, \'CAL0005\')) THEN

log0002.login(\'CAL0005\', \'\', i_pid);

RETURN;

END IF;

\-- Go to default startup page

cal0005.display_monthview(i_pid);

end;

\-- \*\*\* Make sure user has a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION is_valid_pid(i_pid IN VARCHAR2) RETURN BOOLEAN IS

result BOOLEAN;

p_app_name VARCHAR2(30);

BEGIN

p_app_name := \'CAL0005\';

result := log0002.is_valid_pid(i_pid, p_app_name);

RETURN result;

END;

\-- \*\*\* Convert Oracle Office times to real time \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION ConvertOracleTime(i_time in NUMBER DEFAULT NULL) RETURN
VARCHAR2 IS

\-- Declare constants/variables

TimeHour NUMBER;

TimeMin NUMBER;

NewTime NUMBER;

ConvertedTime VARCHAR2(10);

BEGIN

\-- Convert time

TimeHour := floor(i_time / 60);

TimeMin := mod(i_time, 60);

\-- Create time string

ConvertedTime := to_char(to_date(TimeHour \|\| \':\' \|\|
to_char(TimeMin, \'09\'), \'hh24:mi\'), \'hh:mi AM\');

\-- Return to calling procedure

RETURN(ConvertedTime);

END;

\-- \*\*\* Return a concatinated string of the user\'s privileges for
the passed calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION GetPrivs(i_calendar in VARCHAR2, i_badge IN VARCHAR2) RETURN
VARCHAR2 IS

\-- Declare cursors

CURSOR cGetPrivs(CalendarID IN varchar2, BadgeNo IN VARCHAR2) IS

SELECT privs

FROM pim_privs_table

WHERE pim_object_id = CalendarID AND

grantee_badge = BadgeNo;

\-- Declare constants/variables

UserPrivileges VARCHAR2(100) := \'\';

BEGIN

\-- Create privilege string

FOR Loop1 IN cGetPrivs(i_calendar, i_badge) LOOP

UserPrivileges := UserPrivileges \|\| Loop1.privs \|\| \', \';

END LOOP;

\-- Return to calling procedure

RETURN(UserPrivileges);

END;

\-- \*\*\* Setup monthview display \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_monthview(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'), i_month IN
VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL) IS

\--i_day IN VARCHAR2 DEFAULT ltrim(to_char(sysdate, \'DD\'), \'0\')) IS

\-- Declare cursors

CURSOR cGetGrantedCalIDs(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'READ_ALL\' OR a.privs = \'WRITE\')
AND

a.inactive_flag = \'N\'

ORDER BY a.pim_object_id;

rGetGrantedCalIDs cGetGrantedCalIDs%ROWTYPE;

\-- Declare constants/variables

i_date VARCHAR2(11);

CurrentUser VARCHAR2(10) := \'\';

CalendarID VARCHAR2(9);

BrowserType VARCHAR2(255);

NewDay VARCHAR2(2);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get a default i_calendar if none is provided

IF i_calendar IS NULL THEN

CurrentUser := lib02.GetBadge(i_pid);

OPEN cGetGrantedCalIDs(CurrentUser);

FETCH cGetGrantedCalIDs INTO rGetGrantedCalIDs;

IF cGetGrantedCalIDs%NOTFOUND THEN

\-- User has no access;

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

htp.bodyOpen;

lib02.DisplayError(\'\', \'No calendars available\', \'\', \'You do not
have privilages to view any calendars in this system.\');

htp.bodyClose;

htp.htmlClose;

RETURN;

ELSE

\-- Use first found calendar ID

CalendarID := rGetGrantedCalIDs.pim_object_id;

END IF;

CLOSE cGetGrantedCalIDs;

ELSE

\-- User povided calendar ID

CalendarID := i_calendar;

END IF;

\-- Determine day to be used

IF i_day IS NULL THEN

IF (i_month = to_char(sysdate, \'MON\')) AND (i_year = to_char(sysdate,
\'YYYY\')) THEN

NewDay := ltrim(to_char(sysdate, \'DD\'), \'0\');

ELSE

NewDay := \'1\';

END IF;

ELSE

NewDay := i_day;

END IF;

\-- Combine individual date elements

i_date := NewDay \|\| \'-\' \|\| i_month \|\| \'-\' \|\| i_year;

\-- Open the HTML page

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

\-- Create the Header and Detail frames

htp.framesetOpen(\'260, \*\', \'\');

htp.frame(\'cal0005.display_header?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date,
\'Header\', \'0\', \'0\');

htp.frame(\'cal0005.display_detail?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| CalendarID \|\| \'&i_date=\' \|\| i_date \|\|
\'#\' \|\| NewDay, \'Detail\', \'0\', \'0\');

htp.framesetClose;

\-- Close the main frameset

htp.framesetClose;

\-- Close the HTML page

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display header \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_header(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetGrantedCalInfo(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id, b.name

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'READ_ALL\' OR a.privs = \'WRITE\')
AND

a.inactive_flag = \'N\'

ORDER BY a.pim_object_id;

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

StartDayOfWeek NUMBER(1);

Counter NUMBER(2);

TempYear NUMBER(4) := to_number(to_char(sysdate, \'YYYY\'));

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the toolbar table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"0\"\');

\-- Display the toolbar buttons

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0006.report_page?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date, \'\<IMG
SRC=\"/gen-img/reports_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltri

m(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/apptview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0007.display_calendarview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|

ltrim(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/calview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'log0002.log_out\', \'\<IMG
SRC=\"/gen-img/logout_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'WIDTH=\"100%\"\');

htp.tableRowClose;

\-- Close the toolbar table

htp.tableClose;

\-- Open the main navigation & calendar table

htp.hr;

htp.tableOpen(\'\', \'\', \'\', \'\', \'ALIGN=\"CENTER\" BORDER=\"0\"
CELLSPACING=\"2\" CELLPADDING=\"2\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

htp.tableRowOpen;

\-- Display navigation

htp.p(\'\<TD BGCOLOR=\"#F0F0F0\"\>\');

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" CELLSPACING=\"0\"
CELLPADDING=\"0\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_year=\' \|\| to_char(add_months(to_date(i_date,
\'DD-MON-YYYY\'), -1), \'YYYY\') \|\| \'&i_month=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), -1), \'MON\') \|\|
\'&i_calendar=\' \|\| i

\_calendar, \'\<IMG SRC=\"/gen-img/prev_month.gif\" BORDER=\"0\"\>\',
\'\',
\'\_top\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_year=\' \|\| to_char(sysdate, \'YYYY\') \|\|
\'&i_month=\' \|\| to_char(sysdate, \'MON\') \|\| \'&i_calendar=\' \|\|
i_calendar, \'\<IMG SRC=\"/gen-img/today_button.gif\" BORDER=\"0\"\>\',
\'\', \'\_top\'),\'CE

NTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_year=\' \|\| to_char(add_months(to_date(i_date,
\'DD-MON-YYYY\'), 1), \'YYYY\') \|\| \'&i_month=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), 1), \'MON\') \|\|
\'&i_calendar=\' \|\| i_c

alendar, \'\<IMG SRC=\"/gen-img/next_month.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'),\'CENTER\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableRowClose;

\-- Close the nested navigation table

htp.tableClose;

htp.p(\'\</TD\>\');

\-- Open the web form

htp.formOpen(\'cal0005.display_monthview\', \'\', \'\_top\');

\-- Display dropdown calendar selector

htp.p(\'\<TD VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\>\');

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" CELLSPACING=\"0\"
CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
\'Navigation\', \'CENTER\',\'\',\'\',\'\',\'2\',\'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'Name:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_calendar\', \'\', 1);

FOR Loop1 IN cGetGrantedCalInfo(lib02.GetBadge(i_pid)) LOOP

IF i_calendar = Loop1.pim_object_id THEN

htp.formSelectOption(Loop1.name, \'Y\', \'VALUE=\"\' \|\|
Loop1.pim_object_id \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1.name, NULL, \'VALUE=\"\' \|\|
Loop1.pim_object_id \|\| \'\"\');

END IF;

END LOOP;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display dropdown year selection

htp.tableRowOpen;

htp.tableData(\'Year:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_year\', \'\', 1);

FOR Loop1 IN (TempYear - 1)..(TempYear + 2) LOOP

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') =
to_char(to_date(Loop1, \'YYYY\'), \'YYYY\') THEN

htp.formSelectOption(Loop1, \'Y\', \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1, NULL, \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

END IF;

END LOOP;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display dropdown month selection

htp.tableRowOpen;

htp.tableData(\'Month:\', \'RIGHT\',\'\',\'\',\'\',\'\',\'\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_month\', \'\', 1);

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JAN\' THEN

htp.formSelectOption(\'January\', \'Y\', \'VALUE=\"JAN\"\');

ELSE

htp.formSelectOption(\'January\', NULL, \'VALUE=\"JAN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'FEB\' THEN

htp.formSelectOption(\'February\', \'Y\', \'VALUE=\"FEB\"\');

ELSE

htp.formSelectOption(\'February\', NULL, \'VALUE=\"FEB\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAR\' THEN

htp.formSelectOption(\'March\', \'Y\', \'VALUE=\"MAR\"\');

ELSE

htp.formSelectOption(\'March\', NULL, \'VALUE=\"MAR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'APR\' THEN

htp.formSelectOption(\'April\', \'Y\', \'VALUE=\"APR\"\');

ELSE

htp.formSelectOption(\'April\', NULL, \'VALUE=\"APR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAY\' THEN

htp.formSelectOption(\'May\', \'Y\', \'VALUE=\"MAY\"\');

ELSE

htp.formSelectOption(\'May\', NULL, \'VALUE=\"MAY\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUN\' THEN

htp.formSelectOption(\'June\', \'Y\', \'VALUE=\"JUN\"\');

ELSE

htp.formSelectOption(\'June\', NULL, \'VALUE=\"JUN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUL\' THEN

htp.formSelectOption(\'July\', \'Y\', \'VALUE=\"JUL\"\');

ELSE

htp.formSelectOption(\'July\', NULL, \'VALUE=\"JUL\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'AUG\' THEN

htp.formSelectOption(\'August\', \'Y\', \'VALUE=\"AUG\"\');

ELSE

htp.formSelectOption(\'August\', NULL, \'VALUE=\"AUG\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'SEP\' THEN

htp.formSelectOption(\'September\', \'Y\', \'VALUE=\"SEP\"\');

ELSE

htp.formSelectOption(\'September\', NULL, \'VALUE=\"SEP\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'OCT\' THEN

htp.formSelectOption(\'October\', \'Y\', \'VALUE=\"OCT\"\');

ELSE

htp.formSelectOption(\'October\', NULL, \'VALUE=\"OCT\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'NOV\' THEN

htp.formSelectOption(\'November\', \'Y\', \'VALUE=\"NOV\"\');

ELSE

htp.formSelectOption(\'November\', NULL, \'VALUE=\"NOV\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'DEC\' THEN

htp.formSelectOption(\'December\', \'Y\', \'VALUE=\"DEC\"\');

ELSE

htp.formSelectOption(\'December\', NULL, \'VALUE=\"DEC\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

\-- Display the submit button

htp.tableRowOpen;

htp.tableData(\'\<HR\>\' \|\| htf.formSubmit(\'\',
\'Display\'),\'RIGHT\',\'\',\'\',\'\',\'2\',\'\');

htp.tableRowClose;

\-- Close the nested calendar/year/month table

htp.tableClose;

htp.p(\'\</TD\>\');

\-- Close the web form

htp.formClose;

\-- Display calendar header

htp.p(\'\<TD VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\>\');

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" CELLSPACING=\"0\"
CELLPADDING=\"2\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\',
\'\', \'\', \'7\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Su\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Mo\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Tu\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'We\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Th\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Fr\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Sa\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\" WIDTH=\"25\"\');

htp.tableRowClose;

\-- Blow through initial empty calendar cells

StartDayOfWeek := to_number(to_char(round(to_date(i_date,
\'DD-MON-YYYY\'), \'W\'), \'D\'));

htp.tableRowOpen;

IF StartDayOfWeek \> 1 THEN

FOR Loop1 IN 1..StartDayOfWeek - 1 LOOP

htp.tableData(\'\<FONT COLOR=\"#303030\"\>-\', \'CENTER\', \'\', \'\',
\'\', \'\', \'BGCOLOR=\"#F0F0F0\"\');

END LOOP;

END IF;

\-- Display calendar days in cells

Counter := StartDayOfWeek;

FOR Loop1 IN 1..to_number(to_char(last_day(to_date(i_date,
\'DD-MON-YYYY\')), \'DD\')) LOOP

IF Loop1 = to_char(sysdate, \'DD\') THEN

IF to_char(sysdate, \'YYYY\') = to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\') AND to_char(sysdate, \'MON\') =
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') THEN

htp.tableData(htf.anchor2(\'cal0005.display_detail?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD-MON-YYYY\') \|\| \'#\'
\|\| Loop1, htf.bold(\'\<FONT COLOR=\"#5050FF\"\>\' \|\| Loop1), \'\',
\'Deta

il\'), \'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"#F0F0F0\"\');

ELSE

htp.tableData(htf.anchor2(\'cal0005.display_detail?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD-MON-YYYY\') \|\| \'#\'
\|\| Loop1, \'\<FONT COLOR=\"#303030\"\>\' \|\| Loop1, \'\',
\'Detail\'), \'CEN

TER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"#F0F0F0\"\');

END IF;

ELSE

htp.tableData(htf.anchor2(\'cal0005.display_detail?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD-MON-YYYY\') \|\| \'#\'
\|\| Loop1, \'\<FONT COLOR=\"#303030\"\>\' \|\| Loop1, \'\',
\'Detail\'), \'CENTER\'

, \'\', \'\', \'\', \'\', \'BGCOLOR=\"#F0F0F0\"\');

END IF;

Counter := Counter + 1;

IF Counter = 8 THEN

Counter := 1;

htp.tableRowClose;

\-- Don\'t open a new row if last day of the month is on a Saturday

IF (TO_CHAR(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 AND
Loop1 \<\> to_number(to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')),
\'DD\'))) THEN

htp.tableRowOpen;

END IF;

END IF;

END LOOP;

\-- Blow through remaining empty calendar cells

IF to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 THEN

FOR Loop1 IN 1..8 - Counter LOOP

htp.tableData(\'\<FONT COLOR=\"#303030\"\>-\',\'CENTER\', \'\', \'\',
\'\', \'\', \'BGCOLOR=\"#F0F0F0\"\');

END LOOP;

htp.tableRowClose;

END IF;

\-- Close the calendar table

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

\-- Close the main navigation & calendar table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display detail \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_detail(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare cursors

CURSOR cGetEvents(iDay IN VARCHAR2) IS

SELECT subject, begin_time, end_time, color

FROM cal_event

WHERE pim_object_id = i_calendar AND

(event_type = 6000 OR event_type = 9000) AND

inactive = \'N\' AND

begin_date = to_date(iDay, \'DD-MON-YYYY\')

ORDER BY begin_time;

CURSOR cGetNotes(iDay IN VARCHAR2) IS

SELECT subject, color

FROM cal_event

WHERE pim_object_id = i_calendar AND

event_type = 4000 AND

inactive = \'N\' AND

begin_date = to_date(iDay, \'DD-MON-YYYY\') AND

recur_event_id IS NULL

ORDER BY viewing_order, begin_time;

CURSOR cGetRecurringNotes(iDay IN VARCHAR2) IS

SELECT subject, color

FROM cal_event

WHERE pim_object_id = i_calendar AND

event_type = 4000 AND

inactive = \'N\' AND

begin_date = to_date(iDay, \'DD-MON-YYYY\') AND

recur_event_id IS NOT NULL;

CURSOR cGetGrantedCalInfo(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id, b.name

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'WRITE\') AND

a.inactive_flag = \'N\'

ORDER BY a.pim_object_id;

CURSOR cGetCellProperties(CalendarID IN NUMBER, CalDate IN VARCHAR2) IS

SELECT color

FROM cal_display_properties

WHERE pim_object_id = CalendarID AND

display_date = to_date(CalDate, \'DD-MON-YYYY\');

rGetCellProperties cGetCellProperties%ROWTYPE;

\-- Declare constants/variables

Counter NUMBER := 0;

NewDate VARCHAR2(15);

UserPrivs VARCHAR2(100) := \'\';

DisplayName VARCHAR2(50);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Get the calendar\'s display name

SELECT display_name INTO DisplayName

FROM pim_object_table

WHERE pim_object_id = i_calendar;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the calendar name table

IF DisplayName IS NOT NULL THEN

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

htp.tableRowOpen;

\--htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Calender
for \' \|\| DisplayName, \'CENTER\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\" WIDTH=\"100%\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| DisplayName,
\'LEFT\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\" WIDTH=\"100%\"\');

htp.tableRowClose;

htp.tableClose;

END IF;

\-- Display appointments

FOR Loop1 IN 1..to_number(to_char(last_day(to_date(i_date,
\'DD-MON-YYYY\')), \'DD\')) LOOP

\-- Create date string

NewDate := to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\');

\-- Get properties for the calendar date

OPEN cGetCellProperties(i_calendar, NewDate);

FETCH cGetCellProperties INTO rGetCellProperties;

\-- Open the month view table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display date

htp.tableRowOpen;

IF (cGetCellProperties%NOTFOUND = TRUE) OR (rGetCellProperties.color IS
NULL) THEN

htp.tableData(\'\<A NAME=\"\' \|\| Loop1 \|\| \'\" TARGET=\"\_top\"
HREF=\"cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'

DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\' \|\| ltrim(to_char(Loop1,
\'09\')) \|\| \'\"\>\' \|\| htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
NewDate \|\| \'&nbsp;&nbsp;\' \|\| initcap(to_char(to_date(NewDate,
\'DD-MON-YYYY\'), \'DAY\')) \|\| \'\</A\>\', \'LEFT\', \'\', \'\', \'\',
\'2\', \'BGCOLOR=\"\' \|\| TABLE

\_CELL_SECONDARY \|\| \'\" WIDTH=\"100%\"\');

ELSE

htp.tableData(\'\<A NAME=\"\' \|\| Loop1 \|\| \'\" TARGET=\"\_top\"
HREF=\"cal0003.display_listview?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'

DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\' \|\| ltrim(to_char(Loop1,
\'09\')) \|\| \'\"\>\' \|\| htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
\'\<FONT COLOR=\"#000000\"\>\' \|\| NewDate \|\| \'&nbsp;&nbsp;\' \|\|
initcap(to_char(to_date(NewDate, \'DD-MON-YYYY\'), \'DAY\')) \|\|
\'\</A\>\</FONT\>\', \'LEFT\', \'\'

, \'\', \'\', \'2\', \'BGCOLOR=\"#\' \|\| rGetCellProperties.color \|\|
\'\" WIDTH=\"100%\"\');

END IF;

htp.tableRowClose;

\-- Close the cell property cursor

CLOSE cGetCellProperties;

\-- Display appointments for the current day

FOR Loop2 IN cGetEvents(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

\-- Display time

IF Counter = 0 THEN

htp.tableData(ConvertOracleTime(Loop2.begin_time) \|\| \'-\' \|\|
ConvertOracleTime(Loop2.end_time), \'LEFT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#E9E9E9\" WIDTH=\"125\" VALIGN=\"TOP\" NOWRAP\');

Counter := 1;

ELSE

htp.tableData(ConvertOracleTime(Loop2.begin_time) \|\| \'-\' \|\|
ConvertOracleTime(Loop2.end_time), \'LEFT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#D9D9D9\" WIDTH=\"125\" VALIGN=\"TOP\" NOWRAP\');

Counter := 0;

END IF;

\-- Display appointment

IF (instr(UserPrivs, \'READ_ALL\', 1) \> 0) OR (instr(UserPrivs,
\'WRITE\', 1) \> 0) THEN

htp.tableData(\'\<FONT COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\|
Loop2.subject \|\| \'\</FONT\>\', \'LEFT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\"\');

ELSE

htp.tableData(\'Appointment\', \'LEFT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\"\');

END IF;

htp.tableRowClose;

END LOOP;

Counter := 0;

\-- Close the month view table

htp.tableClose;

\-- Open the notes table

IF (instr(UserPrivs, \'READ_ALL\', 1) \> 0) OR (instr(UserPrivs,
\'WRITE\', 1) \> 0) THEN

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display notes for the current day

FOR Loop2 IN cGetNotes(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

htp.tableData(htf.img(\'/gen-img/bullet01.gif\') \|\| \'&nbsp;\', \'\',
\'\', \'\', \'\', \'\', \'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\');

htp.tableData(\'\<FONT COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\|
Loop2.subject \|\| \'\</FONT\>\', \'\', \'\', \'\', \'\', \'\',
\'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\" WIDTH=\"100%\"\');

htp.tableRowClose;

END LOOP;

\-- Display recurring notes for the current day

FOR Loop2 IN cGetRecurringNotes(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

htp.tableData(htf.img(\'/gen-img/bullet01.gif\') \|\| \'&nbsp;\', \'\',
\'\', \'\', \'\', \'\', \'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\');

htp.tableData(\'\<FONT COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\|
Loop2.subject \|\| \'\</FONT\>\', \'\', \'\', \'\', \'\', \'\',
\'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\" WIDTH=\"100%\"\');

htp.tableRowClose;

END LOOP;

\-- Close the notes table

htp.tableClose;

END IF;

\-- Insert a blank line between days

htp.br;

END LOOP;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

END CAL0005;

/

CREATE OR REPLACE PACKAGE CAL0006 IS

PROCEDURE report_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'));

procedure display_frame(i_pid in varchar2 default NULL,

i_operation in varchar2 default NULL,

i_pim_object_id in varchar2 default NULL);

procedure date_display(i_pid in varchar2 default NULL);

END CAL0006;

/

CREATE OR REPLACE PACKAGE BODY CAL0006 IS

\-- \*\*\* Declare global constants/variables \*\*\*

CR VARCHAR2(1) := chr(13);

LF VARCHAR2(1) := chr(10);

ARGONNE_COLOR VARCHAR2(7) := \'C0C0FF\';

OAK_RIDGE_COLOR VARCHAR2(7) := \'FFFFC0\';

TRAVEL_COLOR VARCHAR2(7) := \'C0FFC0\';

PAGE_BACKGROUND_COLOR VARCHAR2(7) := \'#C0C0C0\';

TABLE_CELL_PRIMARY VARCHAR2(7) := \'#303030\';

TABLE_CELL_SECONDARY VARCHAR2(7) := \'#808080\';

TABLE_CELL_MOD VARCHAR2(7) := \'#3030C0\';

TABLE_CELL_DEFAULT VARCHAR2(7) := \'#C0C0C0\';

STYLE_ALTER_LINKS VARCHAR2(200) := \'A {text-decoration: none;} A:hover
{text-decoration: underline;}\';

STYLE_BOLD VARCHAR2(200) := \'B {font-weight: bold;}\';

STYLE_HEADING_01 VARCHAR2(200) := \'.Heading01 {font-family: Tahoma,
Arial, Helvetica; font-size: 13pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_HEADING_02 VARCHAR2(200) := \'.Heading02 {font-family: Tahoma,
Arial, Helvetica; font-size: 10pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_SMALL_01 VARCHAR2(200) := \'.Small01 {font-family: Tahoma, Arial,
Helvetica; font-size: 8pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_TABLE_DATA VARCHAR2(200) := \'TD {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_FIXED VARCHAR2(200) := \'.Fixed{font-family: Courier New, Courier;
font-size: 8pt; font-weight: normal; font-style: normal; color:
#000000;}\';

STYLE_FORMS VARCHAR2(200) := \'textarea {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

\-- \*\*\* Return a concatinated string of the user\'s privileges for
the passed calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION GetPrivs(i_calendar in VARCHAR2, i_badge IN VARCHAR2) RETURN
VARCHAR2 IS

\-- Declare cursors

CURSOR cGetPrivs(CalendarID IN varchar2, BadgeNo IN VARCHAR2) IS

SELECT privs

FROM pim_privs_table

WHERE pim_object_id = CalendarID AND

grantee_badge = BadgeNo;

\-- Declare constants/variables

UserPrivileges VARCHAR2(100) := \'\';

BEGIN

\-- Create privilege string

FOR Loop1 IN cGetPrivs(i_calendar, i_badge) LOOP

UserPrivileges := UserPrivileges \|\| Loop1.privs \|\| \', \';

END LOOP;

\-- Return to calling procedure

RETURN(UserPrivileges);

END;

\-- \*\*\* Make sure user has a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION is_valid_pid(i_pid IN VARCHAR2) RETURN BOOLEAN IS

result BOOLEAN;

p_app_name VARCHAR2(30);

BEGIN

p_app_name := \'CAL0005\';

result := log0002.is_valid_pid(i_pid, p_app_name);

RETURN result;

END;

PROCEDURE report_page(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\')) IS

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

l_date varchar2(20);

cursor cur_sysdate is

select to_char(sysdate,\'YYYY\')

from dual;

l_sysdate varchar2(20);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Set l_date

l_date :=
to_char(last_day(add_months(to_date(i_date,\'DD-MON-YYYY\'),-1))+1,\'MON\');

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(STYLE_FIXED);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the toolbar table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"0\"\');

\-- Display the toolbar buttons

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltri

m(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/apptview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltr

im(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/monthview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0007.display_calendarview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|l

trim(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/calview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.anchor2(\'log0002.log_out\', \'\<IMG
SRC=\"/gen-img/logout_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\', \'WIDTH=\"100%\"\');

htp.tableRowClose;

\-- Close the toolbar table

htp.tableClose;

htp.hr;

htp.p(\'\<FORM ACTION=\"/gen-bin/uncgi/sweb_reporter.pdf\"
METHOD=\"GET\"\>\');

\-- !!! note to always use the GET method when using a form for this

\-- !!! to work properly in IE.

\-- Open the main table

htp.tableOpen(\'\', \'\', \'\', \'\', \'ALIGN=\"CENTER\" BORDER=\"0\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display header text

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Calendar
Report\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" NOWRAP\');

htp.tableRowClose;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Report Month:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_date_month\');

if l_date = \'JAN\' then

htp.formSelectOption(\'January\',\'default\');

else

htp.formSelectOption(\'January\');

end if;

if l_date = \'FEB\' then

htp.formSelectOption(\'February\',\'default\');

else

htp.formSelectOption(\'February\');

end if;

if l_date = \'MAR\' then

htp.formSelectOption(\'March\',\'default\');

else

htp.formSelectOption(\'March\');

end if;

if l_date = \'APR\' then

htp.formSelectOption(\'April\',\'default\');

else

htp.formSelectOption(\'April\');

end if;

if l_date = \'MAY\' then

htp.formSelectOption(\'May\',\'default\');

else

htp.formSelectOption(\'May\');

end if;

if l_date = \'JUN\' then

htp.formSelectOption(\'June\',\'default\');

else

htp.formSelectOption(\'June\');

end if;

if l_date = \'JUL\' then

htp.formSelectOption(\'July\',\'default\');

else

htp.formSelectOption(\'July\');

end if;

if l_date = \'AUG\' then

htp.formSelectOption(\'August\',\'default\');

else

htp.formSelectOption(\'August\');

end if;

if l_date = \'SEP\' then

htp.formSelectOption(\'September\',\'default\');

else

htp.formSelectOption(\'September\');

end if;

if l_date = \'OCT\' then

htp.formSelectOption(\'October\',\'default\');

else

htp.formSelectOption(\'October\');

end if;

if l_date = \'NOV\' then

htp.formSelectOption(\'November\',\'default\');

else

htp.formSelectOption(\'November\');

end if;

if l_date = \'DEC\' then

htp.formSelectOption(\'December\',\'default\');

else

htp.formSelectOption(\'December\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

open cur_sysdate;

fetch cur_sysdate into l_sysdate;

close cur_sysdate;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Report Year:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_date_year\');

if l_sysdate = \'1998\' then

htp.formSelectOption(\'1998\',\'default\');

else

htp.formSelectOption(\'1998\');

end if;

if l_sysdate = \'1999\' then

htp.formSelectOption(\'1999\',\'default\');

else

htp.formSelectOption(\'1999\');

end if;

if l_sysdate = \'2000\' then

htp.formSelectOption(\'2000\',\'default\');

else

htp.formSelectOption(\'2000\');

end if;

if l_sysdate = \'2001\' then

htp.formSelectOption(\'2001\',\'default\');

else

htp.formSelectOption(\'2001\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\-- Display the submit button

htp.tableRowOpen;

htp.tableData(htf.formSubmit, \'RIGHT\', \'\', \'\', \'\', \'2\',
\'BGCOLOR=\"#808080\"\');

htp.tableRowClose;

htp.formHidden(\'i_report\',\'CALENDAR_PDF\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_calendar\',i_calendar);

htp.formHidden(\'i_ows_app\',\'CAL0005\');

htp.p(\'\</FORM\>\');

\-- Close the main table

htp.tableClose;

htp.p(\'\<FORM ACTION=\"/gen-bin/uncgi/sweb_reporter.pdf\"
METHOD=\"GET\"\>\');

\-- !!! note to always use the GET method when using a form for this

\-- !!! to work properly in IE.

\-- Open the main table

htp.tableOpen(\'\', \'\', \'\', \'\', \'ALIGN=\"CENTER\" BORDER=\"0\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display header text

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Avery Index
Card\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" NOWRAP\');

htp.tableRowClose;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Date From:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData( htf.formText( cname =\> \'i_run_date_from\', csize =\>
\'12\', cmaxlength =\> \'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData(\'&nbsp;DD-MON-YYYY\', \'Left\');

htp.tableRowClose;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Date To:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData( htf.formText( cname =\> \'i_run_date_to\', csize =\>
\'12\', cmaxlength =\> \'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData(\'&nbsp;DD-MON-YYYY\', \'Left\');

htp.tableRowClose;

\-- Display the submit button

htp.tableRowOpen;

htp.tableData(htf.formSubmit, \'RIGHT\', \'\', \'\', \'\', \'2\',
\'BGCOLOR=\"#808080\"\');

htp.tableRowClose;

htp.formHidden(\'i_report\',\'CALCARD_PDF\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_calendar\',i_calendar);

htp.formHidden(\'i_ows_app\',\'CAL0005\');

htp.p(\'\</FORM\>\');

\-- Close the main table

htp.tableClose;

htp.p(\'\<FORM ACTION=\"/gen-bin/uncgi/sweb_reporter.pdf\"
METHOD=\"GET\"\>\');

\-- !!! note to always use the GET method when using a form for this

\-- !!! to work properly in IE.

\-- Open the main table

htp.tableOpen(\'\', \'\', \'\', \'\', \'ALIGN=\"CENTER\" BORDER=\"0\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display header text

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Individual
Index Card\', \'CENTER\', \'\', \'\', \'\', \'2\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" NOWRAP\');

htp.tableRowClose;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Date From:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData( htf.formText( cname =\> \'i_run_date_from\', csize =\>
\'12\', cmaxlength =\> \'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData(\'&nbsp;DD-MON-YYYY\', \'Left\');

htp.tableRowClose;

\-- Display the text box

htp.tableRowOpen;

htp.tableData(\'Date To:\', \'Right\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData( htf.formText( cname =\> \'i_run_date_to\', csize =\>
\'12\', cmaxlength =\> \'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'&nbsp;\', \'\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\" NOWRAP\');

htp.tableData(\'&nbsp;DD-MON-YYYY\', \'Left\');

htp.tableRowClose;

\-- Display the submit button

htp.tableRowOpen;

htp.tableData(htf.formSubmit, \'RIGHT\', \'\', \'\', \'\', \'2\',
\'BGCOLOR=\"#808080\"\');

htp.tableRowClose;

htp.formHidden(\'i_report\',\'CALCARDIND\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_calendar\',i_calendar);

htp.formHidden(\'i_ows_app\',\'CAL0005\');

htp.p(\'\</FORM\>\');

\-- Close the main table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

procedure display_frame(i_pid in varchar2 default NULL,

i_operation in varchar2 default NULL,

i_pim_object_id in varchar2 default NULL) is

BEGIN

htp.htmlOpen;

htp.headOpen;

htp.p(\'\<FRAMESET ROWS=\"100%\" FRAMEBORDER=NO FRAMESPACING=0
BORDER=\"0\"\>\');

htp.p(\'\<FRAME SRC=\'\|\|\'\"stat0004.header?i_pid=\'\|\|i_pid\|\|\'\"
NAME=\"HEADER\" SCROLLING=\"NO\" NORESIZE \>\');

htp.p(\'\<FRAMESET COLS=\"28%,\*\" FRAMEBORDER=NO FRAMESPACING=0
BORDER=\"0\"\>\');

htp.p(\'\<FRAME
SRC=\'\|\|\'\"cal0006.date_display?i_pid=\'\|\|i_pid\|\|\'\"
NAME=\"SEARCH_CRITERIA\" NORESIZE \>\');

htp.p(\'\<FRAME
SRC=\'\|\|\'\"cal0006.status_results?i_pid=\'\|\|i_pid\|\|\'\"
NAME=\"STATUS_RESULTS\" NORESIZE \>\');

htp.p(\'\</FRAMESET\>\');

htp.p(\'\</FRAMESET\>\');

htp.htmlclose;

END;

procedure date_display(i_pid in varchar2 default NULL) is

cursor cur_display_date is

select to_date(to_char(add_months(the_day,
-1)+1,\'MONYYYY\'),\'MONYYYY\') the_month

from cal_days

where the_day between add_months(sysdate,-12) and add_months(sysdate,24)

group by to_date(to_char(add_months(the_day,
-1)+1,\'MONYYYY\'),\'MONYYYY\')

order by 1;

\-- rec_display_date cur_display_date%ROWTYPE;

begin

htp.tableOpen;

for rec_display_date in cur_display_date loop

htp.tableRowOpen;

htp.tabledata(htf.anchor2(to_char(rec_display_date.the_month,\'MONYYYY\')\|\|\'.pdf\',to_char(rec_display_date.the_month,\'MONYYYY\')));

htp.tableRowClose;

end loop;

htp.tableClose;

end;

END CAL0006;

/

CREATE OR REPLACE PACKAGE CAL0007 IS

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\');

PROCEDURE display_calendarview(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'),

i_month IN VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL,

i_details IN VARCHAR2 DEFAULT NULL);

PROCEDURE display_header(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_details IN VARCHAR2 DEFAULT NULL);

PROCEDURE display_detail(i_pid IN VARCHAR2 DEFAULT \'NEW\',

i_calendar IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'),

i_details IN VARCHAR2 DEFAULT NULL);

END CAL0007;

/

CREATE OR REPLACE PACKAGE BODY CAL0007 IS

\-- \*\*\* Declare global constants/variables \*\*\*

CR VARCHAR2(1) := chr(13);

LF VARCHAR2(1) := chr(10);

ARGONNE_COLOR VARCHAR2(7) := \'C0C0FF\';

OAK_RIDGE_COLOR VARCHAR2(7) := \'FFFFC0\';

TRAVEL_COLOR VARCHAR2(7) := \'C0FFC0\';

PAGE_BACKGROUND_COLOR VARCHAR2(7) := \'#C0C0C0\';

TABLE_CELL_PRIMARY VARCHAR2(7) := \'#303030\';

TABLE_CELL_SECONDARY VARCHAR2(7) := \'#808080\';

TABLE_CELL_MOD VARCHAR2(7) := \'#3030C0\';

TABLE_CELL_DEFAULT VARCHAR2(7) := \'#C0C0C0\';

STYLE_ALTER_LINKS VARCHAR2(200) := \'A {text-decoration: none;} A:hover
{text-decoration: underline;}\';

STYLE_BOLD VARCHAR2(200) := \'B {font-weight: bold;}\';

STYLE_HEADING_01 VARCHAR2(200) := \'.Heading01 {font-family: Tahoma,
Arial, Helvetica; font-size: 13pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_HEADING_02 VARCHAR2(200) := \'.Heading02 {font-family: Tahoma,
Arial, Helvetica; font-size: 10pt; font-weight: bold; font-style:
normal; color: #FFFFFF;}\';

STYLE_SMALL_01 VARCHAR2(200) := \'.Small01 {font-family: Tahoma, Arial,
Helvetica; font-size: 8pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_TABLE_DATA VARCHAR2(200) := \'TD {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

STYLE_CALCELL VARCHAR2(200) := \'.CalCell{font-family: Arial, Helvetica;
font-size: 8pt; font-weight: normal; font-style: normal; color:
#000000;}\';

STYLE_FORMS VARCHAR2(200) := \'textarea {font-family: Tahoma, Arial,
Helvetica; font-size: 10pt; font-weight: normal; font-style: normal;
color: #000000;}\';

\-- \*\*\* Log the user in with a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE start_page(i_pid IN VARCHAR2 DEFAULT \'NEW\') IS

begin

IF (i_pid IS NULL) OR (i_pid = \'NEW\') OR (NOT
log0002.is_valid_pid(i_pid, \'CAL0005\')) THEN

log0002.login(\'CAL0005\', \'\', i_pid);

RETURN;

END IF;

\-- Go to default startup page

cal0007.display_calendarview(i_pid);

end;

\-- \*\*\* Make sure user has a valid PID \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION is_valid_pid(i_pid IN VARCHAR2) RETURN BOOLEAN IS

result BOOLEAN;

p_app_name VARCHAR2(30);

BEGIN

p_app_name := \'CAL0005\';

result := log0002.is_valid_pid(i_pid, p_app_name);

RETURN result;

END;

\-- \*\*\* Convert Oracle Office times to real time \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION ConvertOracleTime(i_time in NUMBER DEFAULT NULL) RETURN
VARCHAR2 IS

\-- Declare constants/variables

TimeHour NUMBER;

TimeMin NUMBER;

NewTime NUMBER;

ConvertedTime VARCHAR2(10);

BEGIN

\-- Convert time

TimeHour := floor(i_time / 60);

TimeMin := mod(i_time, 60);

\-- Create time string

ConvertedTime := to_char(to_date(TimeHour \|\| \':\' \|\|
to_char(TimeMin, \'09\'), \'hh24:mi\'), \'hh:mi AM\');

\-- Return to calling procedure

RETURN(ConvertedTime);

END;

\-- \*\*\* Return a concatinated string of the user\'s privileges for
the passed calendar \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION GetPrivs(i_calendar in VARCHAR2, i_badge IN VARCHAR2) RETURN
VARCHAR2 IS

\-- Declare cursors

CURSOR cGetPrivs(CalendarID IN varchar2, BadgeNo IN VARCHAR2) IS

SELECT privs

FROM pim_privs_table

WHERE pim_object_id = CalendarID AND

grantee_badge = BadgeNo;

\-- Declare constants/variables

UserPrivileges VARCHAR2(100) := \'\';

BEGIN

\-- Create privilege string

FOR Loop1 IN cGetPrivs(i_calendar, i_badge) LOOP

UserPrivileges := UserPrivileges \|\| Loop1.privs \|\| \', \';

END LOOP;

\-- Return to calling procedure

RETURN(UserPrivileges);

END;

\-- \*\*\* Setup calendar view display \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_calendarview(i_pid IN VARCHAR2 DEFAULT \'NEW\',
i_calendar IN VARCHAR2 DEFAULT NULL,

i_year IN VARCHAR2 DEFAULT to_char(sysdate, \'YYYY\'), i_month IN
VARCHAR2 DEFAULT to_char(sysdate, \'MON\'),

i_day IN VARCHAR2 DEFAULT NULL, i_details IN VARCHAR2 DEFAULT NULL) IS

\-- Declare constants/variables

i_date VARCHAR2(11);

NewDay VARCHAR2(2);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Determine day to be used

IF i_day IS NULL THEN

IF (i_month = to_char(sysdate, \'MON\')) AND (i_year = to_char(sysdate,
\'YYYY\')) THEN

NewDay := ltrim(to_char(sysdate, \'DD\'), \'0\');

ELSE

NewDay := \'1\';

END IF;

ELSE

NewDay := i_day;

END IF;

\-- Combine individual date elements

i_date := NewDay \|\| \'-\' \|\| i_month \|\| \'-\' \|\| i_year;

\-- Open the HTML page

htp.htmlOpen;

htp.headOpen;

htp.title(\'APS Calendar & Schedule\');

htp.headClose;

\-- Create the Header and Detail frames

htp.framesetOpen(\'60, \*\', \'\');

htp.frame(\'cal0007.display_header?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_details=\' \|\| i_details, \'Header\', \'0\', \'0\');

htp.frame(\'cal0007.display_detail?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date \|\|
\'&i_details=\' \|\| i_details \|\| \'#\' \|\| to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'DD\'), \'Detail\', \'0\', \'0\');

htp.framesetClose;

\-- Close the main frameset

htp.framesetClose;

\-- Close the HTML page

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display the calendar view toolbar header \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_header(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_details
IN VARCHAR2 DEFAULT NULL) IS

\-- Declare cursors

CURSOR cGetGrantedCalInfo(BadgeNo IN VARCHAR2) IS

SELECT DISTINCT(a.pim_object_id) AS pim_object_id, b.name

FROM pim_privs_table a, pim_object_table b

WHERE a.pim_object_id = b.pim_object_id AND

b.pim_type = \'C\' AND

a.grantee_badge = BadgeNo AND

(a.privs = \'READ\' OR a.privs = \'READ_ALL\' OR a.privs = \'WRITE\')
AND

a.inactive_flag = \'N\'

ORDER BY a.pim_object_id;

\-- Declare constants/variables

UserPrivs VARCHAR2(100) := \'\';

TempYear NUMBER(4) := to_number(to_char(sysdate, \'YYYY\'));

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Open the HTML page

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(STYLE_CALCELL);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the web form

htp.formOpen(\'cal0007.display_calendarview\', \'\', \'\_top\');

\-- Open the main table

htp.tableOpen(\'\', \'\', \'\', \'\', \'BORDER=\"0\" WIDTH=\"100%\"
CELLSPACING=\"0\" CELLPADDING=\"2\"\');

\-- Display the toolbar buttons, date and links

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0006.report_page?i_pid=\' \|\| i_pid \|\|
\'&i_calendar=\' \|\| i_calendar \|\| \'&i_date=\' \|\| i_date, \'\<IMG
SRC=\"/gen-img/reports_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'2\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltri

m(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/apptview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'2\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0005.display_monthview?i_pid=\' \|\|
i_pid \|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\| ltr

im(to_char(to_date(i_date, \'DD-MON-YYYY\'), \'DD\'), \'0\'), \'\<IMG
SRC=\"/gen-img/monthview_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'2\', \'\', \'\');

htp.tableData(htf.anchor2(\'log0002.log_out\', \'\<IMG
SRC=\"/gen-img/logout_toolbar_btn.gif\" BORDER=\"0\"\>\', \'\',
\'\_top\'), \'LEFT\', \'\', \'\', \'2\', \'\', \'\');

htp.tableData(htf.anchor2(\'cal0007.display_calendarview?i_pid=\' \|\|
i_pid \|\| \'&i_year=\' \|\| to_char(add_months(to_date(i_date,
\'DD-MON-YYYY\'), -1), \'YYYY\') \|\| \'&i_month=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), -1), \'MON\') \|\|
\'&i_calendar=\' \|

\| i_calendar \|\| \'&i_details=\' \|\| i_details, htf.div(\'\',
\'CLASS=\"Heading02\"\') \|\| \'Previous Month\', \'\', \'\_top\'),
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" NOWRAP\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\',
\'\', \'2\', \'\', \'WIDTH=\"100%\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

htp.tableData(\'\<FONT COLOR=\"#FFFFFF\"\>Month\</FONT\>\',
\'LEFT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#303030\"\');

htp.tableData(\'\<FONT COLOR=\"#FFFFFF\"\>Year\</FONT\>\',
\'LEFT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#303030\"\');

htp.tableData(htf.formCheckbox(\'i_details\', \'Y\', i_details) \|\|
\'\<FONT COLOR=\"#FFFFFF\"\>Details?\',
\'LEFT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#303030\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.anchor2(\'cal0007.display_calendarview?i_pid=\' \|\|
i_pid \|\| \'&i_year=\' \|\| to_char(add_months(to_date(i_date,
\'DD-MON-YYYY\'), 1), \'YYYY\') \|\| \'&i_month=\' \|\|
to_char(add_months(to_date(i_date, \'DD-MON-YYYY\'), 1), \'MON\') \|\|
\'&i_calendar=\' \|\|

i_calendar \|\| \'&i_details=\' \|\| i_details, htf.div(\'\',
\'CLASS=\"Heading02\"\') \|\| \'Next Month\', \'\', \'\_top\'),
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\" NOWRAP\');

\-- Display dropdown month selection

htp.p(\'\<TD BGCOLOR=\"#303030\"\>\');

htp.formSelectOpen(\'i_month\', \'\', 1);

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JAN\' THEN

htp.formSelectOption(\'January\', \'Y\', \'VALUE=\"JAN\"\');

ELSE

htp.formSelectOption(\'January\', NULL, \'VALUE=\"JAN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'FEB\' THEN

htp.formSelectOption(\'February\', \'Y\', \'VALUE=\"FEB\"\');

ELSE

htp.formSelectOption(\'February\', NULL, \'VALUE=\"FEB\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAR\' THEN

htp.formSelectOption(\'March\', \'Y\', \'VALUE=\"MAR\"\');

ELSE

htp.formSelectOption(\'March\', NULL, \'VALUE=\"MAR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'APR\' THEN

htp.formSelectOption(\'April\', \'Y\', \'VALUE=\"APR\"\');

ELSE

htp.formSelectOption(\'April\', NULL, \'VALUE=\"APR\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'MAY\' THEN

htp.formSelectOption(\'May\', \'Y\', \'VALUE=\"MAY\"\');

ELSE

htp.formSelectOption(\'May\', NULL, \'VALUE=\"MAY\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUN\' THEN

htp.formSelectOption(\'June\', \'Y\', \'VALUE=\"JUN\"\');

ELSE

htp.formSelectOption(\'June\', NULL, \'VALUE=\"JUN\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'JUL\' THEN

htp.formSelectOption(\'July\', \'Y\', \'VALUE=\"JUL\"\');

ELSE

htp.formSelectOption(\'July\', NULL, \'VALUE=\"JUL\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'AUG\' THEN

htp.formSelectOption(\'August\', \'Y\', \'VALUE=\"AUG\"\');

ELSE

htp.formSelectOption(\'August\', NULL, \'VALUE=\"AUG\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'SEP\' THEN

htp.formSelectOption(\'September\', \'Y\', \'VALUE=\"SEP\"\');

ELSE

htp.formSelectOption(\'September\', NULL, \'VALUE=\"SEP\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'OCT\' THEN

htp.formSelectOption(\'October\', \'Y\', \'VALUE=\"OCT\"\');

ELSE

htp.formSelectOption(\'October\', NULL, \'VALUE=\"OCT\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'NOV\' THEN

htp.formSelectOption(\'November\', \'Y\', \'VALUE=\"NOV\"\');

ELSE

htp.formSelectOption(\'November\', NULL, \'VALUE=\"NOV\"\');

END IF;

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') = \'DEC\' THEN

htp.formSelectOption(\'December\', \'Y\', \'VALUE=\"DEC\"\');

ELSE

htp.formSelectOption(\'December\', NULL, \'VALUE=\"DEC\"\');

END IF;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\-- Display dropdown year selection

htp.p(\'\<TD BGCOLOR=\"#303030\"\>\');

htp.formSelectOpen(\'i_year\', \'\', 1);

FOR Loop1 IN (TempYear - 1)..(TempYear + 2) LOOP

IF to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') =
to_char(to_date(Loop1, \'YYYY\'), \'YYYY\') THEN

htp.formSelectOption(Loop1, \'Y\', \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

ELSE

htp.formSelectOption(Loop1, NULL, \'VALUE=\"\' \|\| Loop1 \|\| \'\"\');

END IF;

END LOOP;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\-- Add hidden form data

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_calendar\', i_calendar);

htp.formHidden(\'i_day\', to_char(to_date(i_date, \'DD-MON-YYYY\'),
\'DD\'));

\-- Display the submit button

htp.tableData(htf.formSubmit(\'\',
\'Display\'),\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#303030\"\');

htp.tableRowClose;

\-- Close the main table

htp.tableClose;

\-- Close the web form

htp.formClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

\-- \*\*\* Display the calendar view detail \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE display_detail(i_pid IN VARCHAR2 DEFAULT \'NEW\', i_calendar
IN VARCHAR2,

i_date IN VARCHAR2 DEFAULT to_char(sysdate, \'DD-MON-YYYY\'), i_details
IN VARCHAR2 DEFAULT NULL) IS

\-- Declare cursors

CURSOR cGetEvents(iDay IN VARCHAR2) IS

SELECT subject, begin_time, end_time, color, text_id

FROM cal_event

WHERE pim_object_id = i_calendar AND

(event_type = 6000 OR event_type = 9000) AND

inactive = \'N\' AND

\--to_char(begin_date, \'DD-MON-YYYY\') = to_char(to_date(iDay,
\'DD-MON-YYYY\'), \'DD-MON-YYYY\')

begin_date = to_date(iDay, \'DD-MON-YYYY\')

ORDER BY begin_time;

CURSOR cGetNotes(iDay IN VARCHAR2) IS

SELECT subject, color

FROM cal_event

WHERE pim_object_id = i_calendar AND

event_type = 4000 AND

inactive = \'N\' AND

begin_date = to_date(iDay, \'DD-MON-YYYY\') AND

recur_event_id IS NULL

ORDER BY viewing_order, begin_time;

CURSOR cGetRecurringNotes(iDay IN VARCHAR2) IS

SELECT subject, color

FROM cal_event

WHERE pim_object_id = i_calendar AND

event_type = 4000 AND

inactive = \'N\' AND

begin_date = to_date(iDay, \'DD-MON-YYYY\') AND

recur_event_id IS NOT NULL;

CURSOR cGetCellProperties(CalendarID IN NUMBER, CalDate IN VARCHAR2) IS

SELECT color

FROM cal_display_properties

WHERE pim_object_id = CalendarID AND

\--to_char(display_date, \'DD-MON-YYYY\') = to_char(to_date(CalDate,
\'DD-MON-YYYY\'), \'DD-MON-YYYY\');

display_date = to_date(CalDate, \'DD-MON-YYYY\');

rGetCellProperties cGetCellProperties%ROWTYPE;

CURSOR cGetDetails(iTextID IN VARCHAR2) IS

SELECT text_line

FROM cal_text_dtl

WHERE text_id = iTextID

ORDER BY line_no;

\-- Declare constants/variables

TempDate VARCHAR2(15);

UserPrivs VARCHAR2(100) := \'\';

NewDay VARCHAR2(2);

StartDayOfWeek NUMBER(1);

Counter NUMBER(2);

CellColor VARCHAR2(6);

ApptCount NUMBER;

ColorCount NUMBER(1) := 0;

WeekCounter NUMBER(1) := 1;

JumpName VARCHAR2(2) := \'\';

DetailCount NUMBER;

DisplayName VARCHAR2(50);

BEGIN

\-- Make sure PID is valid

IF is_valid_pid(i_pid) THEN

\-- Get the user\'s privileges for the current calendar

UserPrivs := GetPrivs(i_calendar, lib02.GetBadge(i_pid));

\-- Get the calendar\'s display name

SELECT display_name INTO DisplayName

FROM pim_object_table

WHERE pim_object_id = i_calendar;

\-- Open the HTML page/setup Style Sheets

htp.htmlOpen;

htp.p(\'\<STYLE\>\');

htp.p(STYLE_TABLE_DATA);

htp.p(STYLE_BOLD);

htp.p(STYLE_HEADING_01);

htp.p(STYLE_HEADING_02);

htp.p(STYLE_SMALL_01);

htp.p(STYLE_ALTER_LINKS);

htp.p(STYLE_CALCELL);

htp.p(\'\</STYLE\>\');

htp.bodyOpen(\'\', \'BGCOLOR=\"\' \|\| PAGE_BACKGROUND_COLOR \|\|
\'\"\');

\-- Open the claendar header table

htp.tableOpen(\'\', \'\', \'\', \'\', \'WIDTH=\"100%\" ALIGN=\"CENTER\"
BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\" BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

\-- Display calendar header

htp.tableRowOpen;

\--IF DisplayName IS NOT NULL THEN

\-- htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| \'Calendar
for \' \|\| DisplayName \|\| \' - \' \|\| to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\| to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\', \'\', \'\', \'7\',
\'WIDTH=\"100%\" BGCOLO

R=\"\' \|\| TABLE_CELL_PRIMARY \|\| \'\"\');

\--ELSE

\-- htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\',
\'\', \'\', \'\', \'WIDTH=\"100%\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

\--END IF;

IF DisplayName IS NOT NULL THEN

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\| DisplayName,
\'LEFT\', \'\', \'\', \'\', \'\', \'NOWRAP BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

END IF;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading01\"\') \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\'), \'CENTER\', \'\',
\'\', \'\', \'\', \'WIDTH=\"100%\" BGCOLOR=\"\' \|\| TABLE_CELL_PRIMARY
\|\| \'\"\');

htp.tableRowClose;

htp.tableClose;

\-- Open the main navigation & calendar table

htp.tableOpen(\'\', \'\', \'\', \'\', \'WIDTH=\"100%\" ALIGN=\"CENTER\"
BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\" BGCOLOR=\"\' \|\|
TABLE_CELL_PRIMARY \|\| \'\"\');

\-- Display calendar header

htp.tableRowOpen;

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Sunday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Monday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Tuesday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Wednesday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Thursday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Friday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"Heading02\"\') \|\| \'Saturday\',
\'CENTER\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"\' \|\|
TABLE_CELL_SECONDARY \|\| \'\"\');

htp.tableRowClose;

\-- Blow through initial empty calendar cells

StartDayOfWeek := to_number(to_char(round(to_date(i_date,
\'DD-MON-YYYY\'), \'W\'), \'D\'));

htp.tableRowOpen;

IF StartDayOfWeek \> 1 THEN

FOR Loop1 IN 1..StartDayOfWeek - 1 LOOP

htp.tableData(\'&nbsp;\', \'CENTER\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

END IF;

\-- Display calendar cells

Counter := StartDayOfWeek;

FOR Loop1 IN 1..to_number(to_char(last_day(to_date(i_date,
\'DD-MON-YYYY\')), \'DD\')) LOOP

\--Create date string

TempDate := to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\');

\-- Add jump to specific week

IF WeekCounter \> 1 THEN

JumpName := ltrim(to_char(Loop1, \'09\'));

ELSE

JumpName := \'\';

END IF;

\--Get properties for the current day\'s calendar cell

OPEN cGetCellProperties(i_calendar, TempDate);

FETCH cGetCellProperties INTO rGetCellProperties;

IF (cGetCellProperties%NOTFOUND = FALSE) AND (rGetCellProperties.color
IS NOT NULL) THEN

CellColor := rGetCellProperties.color;

ELSE

CellColor := \'E0E0E0\';

END IF;

CLOSE cGetCellProperties;

\-- Display the day

htp.p(\'\<TD BGCOLOR=\"#FFFFFF\" VALIGN=\"TOP\"\>\');

htp.tableOpen(\'\', \'\', \'\', \'\', \'WIDTH=\"100%\" ALIGN=\"CENTER\"
BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\" BGCOLOR=\"#FFFFFF\"\');

htp.tableRowOpen;

IF Loop1 = to_char(sysdate, \'DD\') THEN

IF to_char(sysdate, \'YYYY\') = to_char(to_date(i_date,
\'DD-MON-YYYY\'), \'YYYY\') AND to_char(sysdate, \'MON\') =
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') THEN

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| ltrim(to_char(Loop1, \'09\')), htf.bold(\'\<FONT
COLOR=\"#5050FF\"\>\' \|\| substr(initcap(to_char(to_date(TempDate,
\'DD-MON-YYYY\'), \'DAY\')), 1, 3)), JumpName, \'\_top\'), \'LEFT\',
\'\', \'\', \'\', \'\', \'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| ltrim(to_char(Loop1, \'09\')), htf.bold(\'\<FONT
COLOR=\"#5050FF\"\>\' \|\| Loop1), JumpName, \'\_top\'), \'RIGHT\',
\'\', \'\', \'\', \'\', \'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

ELSE

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| ltrim(to_char(Loop1, \'09\')), \'\<FONT COLOR=\"#303030\"\>\'
\|\| substr(initcap(to_char(to_date(TempDate, \'DD-MON-YYYY\'),
\'DAY\')), 1, 3), JumpName, \'\_top\'), \'LEFT\', \'\', \'\', \'\',
\'\', \'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=

\' \|\| ltrim(to_char(Loop1, \'09\')), \'\<FONT COLOR=\"#303030\"\>\'
\|\| Loop1, JumpName, \'\_top\'), \'RIGHT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

END IF;

ELSE

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|

ltrim(to_char(Loop1, \'09\')), \'\<FONT COLOR=\"#303030\"\>\' \|\|
substr(initcap(to_char(to_date(TempDate, \'DD-MON-YYYY\'), \'DAY\')), 1,
3), JumpName, \'\_top\'), \'LEFT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

htp.tableData(htf.anchor2(\'cal0003.display_listview?i_pid=\' \|\| i_pid
\|\| \'&i_calendar=\' \|\| i_calendar \|\| \'&i_year=\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'&i_month=\'
\|\| to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON\') \|\| \'&i_day=\'
\|\|

ltrim(to_char(Loop1, \'09\')), \'\<FONT COLOR=\"#303030\"\>\' \|\|
Loop1, JumpName, \'\_top\'), \'RIGHT\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#\' \|\| CellColor \|\| \'\"\');

END IF;

htp.tableRowClose;

\-- Display appointments for the current day

FOR Loop2 IN cGetEvents(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

\-- Display the time

IF ColorCount = 0 THEN

ColorCount := 1;

htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\|
ltrim(rtrim(to_char(to_date(ConvertOracleTime(Loop2.begin_time),
\'hh:miam\'), \'hh:miam\'), \'m\'), \'0\'), \'RIGHT\', \'\', \'\', \'\',
\'\', \'VALIGN=\"TOP\" BGCOLOR=\"#C0C0C0\" NOWRAP\');

ELSE

ColorCount := 0;

htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\|
ltrim(rtrim(to_char(to_date(ConvertOracleTime(Loop2.begin_time),
\'hh:miam\'), \'hh:miam\'), \'m\'), \'0\'), \'RIGHT\', \'\', \'\', \'\',
\'\', \'VALIGN=\"TOP\" BGCOLOR=\"#E0E0E0\" NOWRAP\');

END IF;

\-- Display the appointment

IF (instr(UserPrivs, \'READ_ALL\', 1) \> 0) OR (instr(UserPrivs,
\'WRITE\', 1) \> 0) THEN

\--htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\| \'\<FONT
COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\| Loop2.subject \|\|
\'\</FONT\>\', \'LEFT\', \'\', \'\', \'\', \'\', \'BGCOLOR=\"#FFFFFF\"
WIDTH=\"100%\"\');

htp.p(\'\<TD ALIGN=\"LEFT\" BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\"\');

htp.p(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\| \'\<FONT COLOR=\"\' \|\|
Loop2.color \|\| \'\"\>\' \|\| Loop2.subject \|\| \'\</FONT\>\');

\-- Display details if requested

IF i_details = \'Y\' THEN

SELECT COUNT(text_line) INTO DetailCount

FROM cal_text_dtl

WHERE text_id = Loop2.text_id;

\-- Don\'t display if no detail records exist

IF DetailCount \> 0 THEN

htp.br;

htp.p(htf.bold(\'Details: \'));

FOR Loop3 IN cGetDetails(Loop2.text_id) LOOP

htp.p(Loop3.text_line);

END LOOP;

END IF;

END IF;

htp.p(\'\</TD\>\');

ELSE

htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\| \'Appointment:
\' \|\| ltrim(rtrim(to_char(to_date(ConvertOracleTime(Loop2.begin_time),
\'hh:miam\'), \'hh:miam\'), \'m\'), \'0\') \|\| \' to \' \|\|
ltrim(rtrim(to_char(to_date(ConvertOracleTime(Loop2.end_tim

e), \'hh:miam\'), \'hh:miam\'), \'m\'), \'0\'), \'LEFT\', \'\', \'\',
\'\', \'\', \'BGCOLOR=\"#FFFFFF\" WIDTH=\"100%\"\');

END IF;

htp.tableRowClose;

END LOOP;

ColorCount := 0;

\-- Close the nested table

htp.tableClose;

\-- Display notes

IF (instr(UserPrivs, \'READ_ALL\', 1) \> 0) OR (instr(UserPrivs,
\'WRITE\', 1) \> 0) THEN

htp.tableOpen(\'\', \'\', \'\', \'\', \'WIDTH=\"100%\" ALIGN=\"CENTER\"
BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\" BGCOLOR=\"#FFFFFF\"\');

\-- Display notes for the current day

FOR Loop2 IN cGetNotes(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

htp.tableData(htf.img(\'/gen-img/bullet01.gif\') \|\| \'&nbsp;\', \'\',
\'\', \'\', \'\', \'\', \'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\| \'\<FONT
COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\| Loop2.subject \|\|
\'\</FONT\>\', \'\', \'\', \'\', \'\', \'\', \'VALIGN=\"TOP\"
BGCOLOR=\"#F0F0F0\" WIDTH=\"100%\"\');

htp.tableRowClose;

END LOOP;

\-- Display recurring notes for the current day

FOR Loop2 IN cGetRecurringNotes(to_char(Loop1, \'09\') \|\| \'-\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MON-YYYY\')) LOOP

htp.tableRowOpen;

htp.tableData(htf.img(\'/gen-img/bullet01.gif\') \|\| \'&nbsp;\', \'\',
\'\', \'\', \'\', \'\', \'VALIGN=\"TOP\" BGCOLOR=\"#F0F0F0\"\');

htp.tableData(htf.div(\'\', \'CLASS=\"CalCell\"\') \|\| \'\<FONT
COLOR=\"\' \|\| Loop2.color \|\| \'\"\>\' \|\| Loop2.subject \|\|
\'\</FONT\>\', \'\', \'\', \'\', \'\', \'\', \'VALIGN=\"TOP\"
BGCOLOR=\"#F0F0F0\" WIDTH=\"100%\"\');

htp.tableRowClose;

END LOOP;

htp.tableClose;

END IF;

\-- Close the cell

htp.p(\'\</TD\>\');

\-- Close (and open) a new row if necessary

Counter := Counter + 1;

IF Counter = 8 THEN

Counter := 1;

htp.tableRowClose;

WeekCounter := WeekCounter + 1;

\-- Don\'t open a new row if last day of the month is on a Saturday

IF (TO_CHAR(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 AND
Loop1 \<\> to_number(to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')),
\'DD\'))) THEN

htp.tableRowOpen;

END IF;

END IF;

END LOOP;

WeekCounter := 1;

\-- Blow through remaining empty calendar cells

IF to_char(last_day(to_date(i_date, \'DD-MON-YYYY\')), \'D\') \< 7 THEN

FOR Loop1 IN 1..8 - Counter LOOP

htp.tableData(\'&nbsp;\',\'CENTER\', \'\', \'\', \'\', \'\',
\'BGCOLOR=\"#FFFFFF\"\');

END LOOP;

htp.tableRowClose;

END IF;

\-- Display the bottom calendar footer

htp.tableRowOpen;

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Sunday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Monday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Tuesday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Wednesday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Thursday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Friday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableData(\'\<FONT COLOR=\"#B0B0B0\"\>Saturday\', \'CENTER\', \'\',
\'\', \'\', \'\', \'BGCOLOR=\"#E9E9E9\"\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"4\" COLOR=\"#A0A0A0\"\>\<B\>\' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'MONTH\') \|\| \' \' \|\|
to_char(to_date(i_date, \'DD-MON-YYYY\'), \'YYYY\') \|\| \'\</B\>\',
\'CENTER\', \'\', \'\', \'\', \'7\', \'WIDTH=\"100%\"
BGCOLOR=\"#C9C9C9\"\');

htp.tableRowClose;

\-- Close the main calendar table

htp.tableClose;

\-- Close the HTML page

htp.bodyClose;

htp.htmlClose;

\-- End valid PID check

END IF;

END;

END CAL0007;

/

CREATE OR REPLACE PACKAGE CAL0008 as

type recur_arr is table of varchar2(255) index by binary_integer;

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER);

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE;

FUNCTION is_non_wd (i_date in DATE) RETURN DATE;

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE temp;

PRAGMA restrict_references (is_non_wd,\'WNDS\');

END CAL0008;

/

CREATE OR REPLACE PACKAGE BODY CAL0008 is

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Determines if date passed is non workday

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION is_non_wd (i_date in DATE) RETURN DATE IS

CURSOR c_holiday IS

SELECT \'1\'

FROM CAL_HOLIDAYS

WHERE to_char(HOLIDAY,\'DD-MON-YYYY\')=to_char(i_date,\'DD-MON-YYYY\');

CURSOR c_today IS

SELECT TO_CHAR(i_date,\'D\')

FROM DUAL;

l_temp VARCHAR2(1);

l_today NUMBER(1);

l_result DATE;

BEGIN

l_result := i_date;

\--is this a holiday ?

OPEN c_holiday;

FETCH c_holiday INTO l_temp;

IF NOT c_holiday%NOTFOUND THEN

l_result := null;

END IF;

CLOSE C_HOLIDAY;

\-- is this a weekend day

OPEN c_today;

FETCH c_today INTO l_today;

IF l_today = 1 OR l_today = 7 THEN

l_result := NULL;

END IF;

CLOSE c_today;

RETURN l_result;

END;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Returns date of appointment for specified event

Takes into account the CAL_HOLIDAYS, and whether to get

the next or previous workday if this is a holiday or a

weekend day.

Return date of 31-DEC-1980 or 31-DEC-2999 means DO NOT INSERT

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE IS

l_result DATE;

BEGIN

SELECT DECODE
(nvl(i_non_wd_skip,999),-1,GREATEST(nvl(is_non_wd(i_date),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 1),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 2),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 3),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 4),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 5),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\'))),

1,LEAST(nvl(is_non_wd(i_date),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 1),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 2),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 3),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 4),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 5),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\'))),

0,is_non_wd(i_date),

999,i_date)

INTO l_result

FROM DUAL;

RETURN l_result;

END;

\--

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

This procedure does the actual insertion, given

the recurring ID and date

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

PROCEDURE insert_cal_event (i_recur_event IN NUMBER, i_date IN DATE) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

CURSOR c_collision IS

SELECT \'1\'

FROM CAL_EVENT

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE=i_date;

l_temp VARCHAR2(1);

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

\--htp.p(\'INSERT CAL EVENT\');

OPEN c_collision;

FETCH c_collision INTO l_temp;

IF c_collision%NOTFOUND THEN

\--htp.p(\'NO COLLISION\');

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

INSERT INTO CAL_EVENT

(EVENT_ID,EVENT_TYPE,SUBJECT,CREATE_DATE,CREATED_BY,BEGIN_DATE,END_DATE,BEGIN_TIME,

END_TIME,PRIORITY,STATUS,VIEWING_ORDER,INACTIVE,MAIL_STATUS,MAIL_TIME_UNITS,MAIL_TIME_VALUE,MAIL_TO,

LOCATION_TZID,TEXT_ID,OBJECT_ID,CONTACT_BADGE_NO,COLOR,PIM_OBJECT_ID,LOCATION_ID,RECUR_EVENT_ID,TZID)

VALUES

(seq_event_id.NEXTVAL,r_rec.EVENT_TYPE,r_rec.SUBJECT,sysdate,\'RECUR\',i_date,i_date,

r_rec.BEGIN_TIME,r_rec.END_TIME,r_rec.PRIORITY,r_rec.STATUS,r_rec.VIEWING_ORDER,r_rec.INACTIVE,

r_rec.MAIL_STATUS,r_rec.MAIL_TIME_UNITS,r_rec.MAIL_TIME_VALUE,r_rec.MAIL_TO,

r_rec.LOCATION_TZID,r_rec.TEXT_ID,r_rec.OBJECTID,r_rec.CONTACT_BADGE_NO,r_rec.COLOR,

r_rec.PIM_OBJECT_ID,r_rec.LOCATION_ID,i_recur_event,r_rec.TZID);

END IF;

CLOSE c_recur;

END IF;

CLOSE c_collision;

END;

\--

\-- To be removed after new proc tested 8/11/99 kem

/\*PROCEDURE expand_weekly(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

l_period NUMBER;

l_day_of_week VARCHAR2(1);

l_event_day VARCHAR2(1);

FIRST_DAY BOOLEAN;

BEGIN

\--htp.p(\'EXPAND DAILY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

l_event_day := SUBSTR (r_recurring.DAY_OF_WEEK,1);

l_period := r_recurring.R_PERIOD \* 7;

FIRST_DAY := FALSE;

\--increment to first day before entering next loop

WHILE l_date \<= r_recurring.R_END_DATE and not FIRST_DAY LOOP

IF l_event_day = to_char(l_date,\'D\') THEN

FIRST_DAY := TRUE;

\--adjust for increment

l_date := l_date - 1;

END IF;

l_date := l_date + 1;

END LOOP;

\--

WHILE l_date \<= r_recurring.R_END_DATE LOOP

IF MOD(l_ctr,l_period)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'NEW expand weekly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP;

END;\*/

PROCEDURE expand_weekly(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

l_period NUMBER;

l_day_of_week VARCHAR2(1);

l_event_day VARCHAR2(1);

l_chr VARCHAR2(1);

err_pnt varchar2(10);

len_days NUMBER;

FIRST_DAY BOOLEAN;

BEGIN

\--htp.p(\'EXPAND DAILY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--iterate through DAY_OF_WEEK string

\--htp.p(\'DAY_OF_WEEK=\' \|\| r_recurring.day_of_week);

\--htp.NL;

len_days := length(r_recurring.day_of_week);

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

\--htp.p(\'Evaluating character=\' \|\| l_chr);

IF l_chr != \',\' THEN

err_pnt := \'0\';

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

l_event_day := l_chr;

l_period := r_recurring.R_PERIOD \* 7;

FIRST_DAY := FALSE;

err_pnt :=\'1\';

\--increment to first day before entering next loop

WHILE l_date \<= r_recurring.R_END_DATE and not FIRST_DAY LOOP

IF l_event_day = to_char(l_date,\'D\') THEN

FIRST_DAY := TRUE;

\--adjust for increment

l_date := l_date - 1;

END IF;

l_date := l_date + 1;

END LOOP;

\--

WHILE l_date \<= r_recurring.R_END_DATE LOOP

IF MOD(l_ctr,l_period)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'NEW expand weekly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP; \--while loop

END IF;

END LOOP; \--for loop

END IF;

END;

\--

PROCEDURE expand_daily(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

BEGIN

\--htp.p(\'EXPAND DAILY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

IF MOD(l_ctr,r_recurring.R_PERIOD)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand daily INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_monthly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

month_ctr NUMBER;

last_month VARCHAR2(2);

l_week_of_month VARCHAR2(1);

l_day_of_week VARCHAR2(1);

l_weeks_of_month RECUR_ARR;

l_days_of_week RECUR_ARR;

len_days NUMBER;

len_weeks NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND MONTHLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build arrays l_weeks_of_month, l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

len_weeks := LENGTH(NVL(r_recurring.week_of_month,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

\-- check week of month, add to array if exists

IF len_weeks \>= i THEN

l_chr := SUBSTR(r_recurring.week_of_month,i,1);

IF l_chr != \',\' THEN

l_weeks_of_month(l_arr_idx) := l_chr;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

\--htp.p(\'l_days_of_week\');

\--htp.NL;

FOR i IN 1..l_arr_idx LOOP

\--htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

\--htp.p(l_weeks_of_month(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

month_ctr := 0;

last_month := \'00\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

\--Expand for day of month inclusions

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

IF INSTR (r_recurring.day_of_month,l_day_number) \> 0 THEN

\--insert it per instructions

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END IF;

\--Expand for week of month

\-- Get this week of month, day of week

l_week_of_month := to_char(l_date,\'W\');

l_day_of_week := to_char(l_date,\'D\');

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check arrays CAL_RECURRING.day_of_week and CAL_RECURRING.day_of_month
match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) AND
(l_weeks_of_month(i)=l_week_of_month) THEN

\--this is a hit

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

IF last_month != to_char(l_date,\'MM\') THEN

month_ctr := month_ctr + 1;

END IF;

last_month := to_char(l_date,\'MM\');

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_weekly_old (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

last_week VARCHAR2(2);

week_ctr NUMBER;

l_day_of_week VARCHAR2(1);

l_days_of_week RECUR_ARR;

len_days NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND WEEKLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build array l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

\--htp.p(\'l_days_of_week\');

\--htp.NL;

FOR i IN 1..l_arr_idx LOOP

\--htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

\--htp.p(l_weeks_of_month(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

week_ctr := 0;

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

last_week := to_char(l_date,\'WW\');

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

\-- Get this day of week

l_day_of_week := to_char(l_date,\'D\');

IF MOD(week_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check array CAL_RECURRING.day_of_week for match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) THEN

\--this is a hit

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand weekly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

IF last_week != to_char(l_date,\'WW\') THEN

week_ctr := week_ctr + 1;

END IF;

l_date := l_date + 1;

last_week := to_char(l_date,\'WW\');

END LOOP;

END;

\--

PROCEDURE expand_yearly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_date_number VARCHAR2(5);

year_ctr NUMBER;

last_year VARCHAR2(4);

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND YEARLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

err_pnt :=\'11\';

year_ctr := 0;

last_year := \'0000\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_date_number := to_char(l_date,\'MM/DD\');

\--Expand for day of year inclusions

IF MOD(year_ctr,r_recurring.R_PERIOD)=0 THEN

IF INSTR (r_recurring.date_of_year,l_date_number) \> 0 THEN

\--insert it per instructions

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand yearly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END IF;

IF last_year != to_char(l_date,\'YYYY\') THEN

year_ctr := year_ctr + 1;

END IF;

last_year := to_char(l_date,\'YYYY\');

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER) IS

CURSOR C_RECUR_TYPE IS

SELECT R_PERIOD_TYPE

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID = i_recur_event;

NO_RECUR_EVENT EXCEPTION;

INVALID_EVENT_TYPE EXCEPTION;

l_period_type CAL_RECURRING.R_PERIOD_TYPE%TYPE;

BEGIN

OPEN C_RECUR_TYPE;

FETCH C_RECUR_TYPE INTO l_period_type;

IF NOT C_RECUR_TYPE%NOTFOUND THEN

\-- call appropriate procedure to expand, based on recurring type

IF l_period_type=\'D\' THEN

expand_daily (i_recur_event);

ELSIF l_period_type = \'M\' THEN

expand_monthly (i_recur_event);

ELSIF l_period_type=\'W\' THEN

expand_weekly (i_recur_event);

ELSIF l_period_type=\'Y\' THEN

expand_yearly (i_recur_event);

ELSE

RAISE INVALID_EVENT_TYPE;

END IF;

ELSE

RAISE NO_RECUR_EVENT;

END IF;

END;

\--

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE recur_event_id=i_recur_event;

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END IF;

CLOSE c_recur;

END;

\--

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

BEGIN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END;

\--

PROCEDURE temp IS

l_temp varchar2(255);

BEGIN

\--htp.htmlOpen;

lib.no_cache;

\-\-\--htp.p(get_work_day(1,to_date(\'06-JUL-1999\',\'DD-MON-YYYY\')));

expand_recurring_event(1);

\--htp.htmlClose;

END;

END CAL0008;

/

CREATE OR REPLACE PACKAGE CAL0009 as

type recur_arr is table of varchar2(255) index by binary_integer;

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER);

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE;

FUNCTION is_non_wd (i_date in DATE) RETURN DATE;

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE temp(i_recur in NUMBER);

PRAGMA restrict_references (is_non_wd,\'WNDS\');

END CAL0009;

/

CREATE OR REPLACE PACKAGE BODY CAL0009 is

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Determines if date passed is non workday

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION is_non_wd (i_date in DATE) RETURN DATE IS

CURSOR c_holiday IS

SELECT \'1\'

FROM CAL_HOLIDAYS

WHERE to_char(HOLIDAY,\'DD-MON-YYYY\')=to_char(i_date,\'DD-MON-YYYY\');

CURSOR c_today IS

SELECT TO_CHAR(i_date,\'D\')

FROM DUAL;

l_temp VARCHAR2(1);

l_today NUMBER(1);

l_result DATE;

BEGIN

l_result := i_date;

\--is this a holiday ?

OPEN c_holiday;

FETCH c_holiday INTO l_temp;

IF NOT c_holiday%NOTFOUND THEN

l_result := null;

END IF;

CLOSE C_HOLIDAY;

\-- is this a weekend day

OPEN c_today;

FETCH c_today INTO l_today;

IF l_today = 1 OR l_today = 7 THEN

l_result := NULL;

END IF;

CLOSE c_today;

RETURN l_result;

END;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Returns date of appointment for specified event

Takes into account the CAL_HOLIDAYS, and whether to get

the next or previous workday if this is a holiday or a

weekend day.

Return date of 31-DEC-1980 or 31-DEC-2999 means DO NOT INSERT

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE IS

l_result DATE;

BEGIN

SELECT DECODE
(i_non_wd_skip,-1,GREATEST(nvl(is_non_wd(i_date),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 1),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 2),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 3),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 4),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 5),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\'))),

1,LEAST(nvl(is_non_wd(i_date),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 1),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 2),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 3),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 4),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 5),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\'))),

0,is_non_wd(i_date))

INTO l_result

FROM DUAL;

RETURN l_result;

END;

\--

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

This procedure does the actual insertion, given

the recurring ID and date

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

PROCEDURE insert_cal_event (i_recur_event IN NUMBER, i_date IN DATE) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

CURSOR c_collision IS

SELECT \'1\'

FROM CAL_EVENT_TEMP

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE=i_date;

l_temp VARCHAR2(1);

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

htp.p(\'INSERT CAL EVENT\');

OPEN c_collision;

FETCH c_collision INTO l_temp;

IF c_collision%NOTFOUND THEN

htp.p(\'NO COLLISION\');

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

INSERT INTO CAL_EVENT_TEMP

(EVENT_ID,EVENT_TYPE,SUBJECT,CREATE_DATE,CREATED_BY,BEGIN_DATE,END_DATE,BEGIN_TIME,

END_TIME,PRIORITY,STATUS,VIEWING_ORDER,INACTIVE,MAIL_STATUS,MAIL_TIME_UNITS,MAIL_TIME_VALUE,MAIL_TO,

LOCATION_TZID,TEXT_ID,OBJECT_ID,CONTACT_BADGE_NO,COLOR,PIM_OBJECT_ID,LOCATION_ID,RECUR_EVENT_ID,TZID)

VALUES

(seq_event_id.NEXTVAL,r_rec.EVENT_TYPE,r_rec.SUBJECT,sysdate,\'RECUR\',i_date,i_date,

r_rec.BEGIN_TIME,r_rec.END_TIME,r_rec.PRIORITY,r_rec.STATUS,r_rec.VIEWING_ORDER,r_rec.INACTIVE,

r_rec.MAIL_STATUS,r_rec.MAIL_TIME_UNITS,r_rec.MAIL_TIME_VALUE,r_rec.MAIL_TO,

r_rec.LOCATION_TZID,r_rec.TEXT_ID,r_rec.OBJECTID,r_rec.CONTACT_BADGE_NO,r_rec.COLOR,

r_rec.PIM_OBJECT_ID,r_rec.LOCATION_ID,i_recur_event,r_rec.TZID);

END IF;

CLOSE c_recur;

ELSE

htp.p(\'COLLISION FOUND\');

END IF;

CLOSE c_collision;

END;

\--

PROCEDURE expand_daily(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

BEGIN

htp.p(\'EXPAND DAILY\' \|\| \' \' \|\| to_chaR(i_recur_event));

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

\--htp.NL;

\--htp.p(to_char(r_recurring.R_BEGIN_DATE,\'DD-MON-YYYY\'));

\--.NL;

\--htp.p(to_char(r_recurring.R_END_DATE,\'DD-MON-YYYY\'));

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--htp.p(\'ldate is \' \|\| to_char(l_date));

IF MOD(l_ctr,r_recurring.R_PERIOD)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'expand daily INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--insert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_monthly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

month_ctr NUMBER;

last_month VARCHAR2(2);

l_week_of_month VARCHAR2(1);

l_day_of_week VARCHAR2(1);

l_weeks_of_month RECUR_ARR;

l_days_of_week RECUR_ARR;

len_days NUMBER;

len_weeks NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

err_pnt varchar2(3);

BEGIN

htp.p(\'EXPAND MONTHLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build arrays l_weeks_of_month, l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

len_weeks := LENGTH(NVL(r_recurring.week_of_month,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

\-- check week of month, add to array if exists

IF len_weeks \>= i THEN

l_chr := SUBSTR(r_recurring.week_of_month,i,1);

IF l_chr != \',\' THEN

l_weeks_of_month(l_arr_idx) := l_chr;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

htp.p(\'l_days_of_week\');

htp.NL;

FOR i IN 1..l_arr_idx LOOP

htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

htp.NL;

htp.p(l_weeks_of_month(i) \|\| \' i=\' \|\| to_char(i));

htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

month_ctr := 0;

last_month := \'00\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

IF last_month != to_char(l_date,\'MM\') THEN

month_ctr := month_ctr + 1;

END IF;

\--Expand for day of month inclusions

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

IF INSTR (r_recurring.day_of_month,l_day_number) \> 0 THEN

\--insert it per instructions

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END IF;

\--Expand for week of month

\-- Get this week of month, day of week

l_week_of_month := to_char(l_date,\'W\');

l_day_of_week := to_char(l_date,\'D\');

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check arrays CAL_RECURRING.day_of_week and CAL_RECURRING.day_of_month
match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) AND
(l_weeks_of_month(i)=l_week_of_month) THEN

\--this is a hit

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

last_month := to_char(l_date,\'MM\');

l_date := l_date + 1;

END LOOP;

EXCEPTION

WHEN OTHERS THEN

htp.p(\'Error at pint : \' \|\| err_pnt \|\| \' \' \|\| sqlerrm);

htp.NL;

htp.p(to_char(len_days));

END;

\--

PROCEDURE expand_weekly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

last_week VARCHAR2(2);

week_ctr NUMBER;

l_day_of_week VARCHAR2(1);

l_days_of_week RECUR_ARR;

len_days NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

err_pnt varchar2(3);

BEGIN

htp.p(\'EXPAND WEEKLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build array l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

htp.p(\'l_days_of_week\');

htp.NL;

FOR i IN 1..l_arr_idx LOOP

htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

week_ctr := 0;

last_week := \'00\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

IF last_week != to_char(l_date,\'WW\') THEN

week_ctr := week_ctr + 1;

END IF;

\-- Get this day of week

l_day_of_week := to_char(l_date,\'D\');

IF MOD(week_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check array CAL_RECURRING.day_of_week for match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) THEN

\--this is a hit

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'expand weekly INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

last_week := to_char(l_date,\'WW\');

l_date := l_date + 1;

END LOOP;

EXCEPTION

WHEN OTHERS THEN

htp.p(\'Error at pint : \' \|\| err_pnt \|\| \' \' \|\| sqlerrm);

htp.NL;

htp.p(to_char(len_days));

END;

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER) IS

CURSOR C_RECUR_TYPE IS

SELECT R_PERIOD_TYPE

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID = i_recur_event;

NO_RECUR_EVENT EXCEPTION;

INVALID_EVENT_TYPE EXCEPTION;

l_period_type CAL_RECURRING.R_PERIOD_TYPE%TYPE;

BEGIN

OPEN C_RECUR_TYPE;

FETCH C_RECUR_TYPE INTO l_period_type;

IF NOT C_RECUR_TYPE%NOTFOUND THEN

\-- call appropriate procedure to expand, based on recurring type

IF l_period_type=\'D\' THEN

expand_daily (i_recur_event);

ELSIF l_period_type = \'M\' THEN

expand_monthly (i_recur_event);

ELSIF l_period_type=\'W\' THEN

htp.p(\'Expand weekly\');

expand_weekly (i_recur_event);

ELSE

RAISE INVALID_EVENT_TYPE;

END IF;

ELSE

RAISE NO_RECUR_EVENT;

END IF;

NULL;

EXCEPTION

WHEN NO_RECUR_EVENT THEN

htp.p(\'No recurring event matches id \' \|\| i_recur_event);

WHEN INVALID_EVENT_TYPE THEN

htp.p(\'Event type match not found for \' \|\| i_recur_event);

WHEN OTHERS THEN

htp.p(\'cal0008.expand_recurring_event error: \' \|\| sqlerrm);

END;

\--

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE recur_event_id=i_recur_event;

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT_TEMP

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT_TEMP

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END IF;

CLOSE c_recur;

END;

\--

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE recur_event_id=i_recur_event;

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT_TEMP

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT_TEMP

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END IF;

CLOSE c_recur;

END;

\--

PROCEDURE temp(i_recur IN NUMBER) IS

l_temp varchar2(255);

BEGIN

htp.htmlOpen;

lib.no_cache;

\--htp.p(get_work_day(1,to_date(\'06-JUL-1999\',\'DD-MON-YYYY\')));

expand_recurring_event(i_recur);

htp.htmlClose;

END;

END CAL0009;

/

CREATE OR REPLACE PACKAGE CAL0010 as

type recur_arr is table of varchar2(255) index by binary_integer;

PROCEDURE expand_migrated_events;

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER);

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE;

FUNCTION is_non_wd (i_date in DATE) RETURN DATE;

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL);

PROCEDURE temp (i_recur IN NUMBER);

PRAGMA restrict_references (is_non_wd,\'WNDS\');

END CAL0010;

/

CREATE OR REPLACE PACKAGE BODY CAL0010 is

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Determines if date passed is non workday

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION is_non_wd (i_date in DATE) RETURN DATE IS

CURSOR c_holiday IS

SELECT \'1\'

FROM CAL_HOLIDAYS

WHERE to_char(HOLIDAY,\'DD-MON-YYYY\')=to_char(i_date,\'DD-MON-YYYY\');

CURSOR c_today IS

SELECT TO_CHAR(i_date,\'D\')

FROM DUAL;

l_temp VARCHAR2(1);

l_today NUMBER(1);

l_result DATE;

BEGIN

l_result := i_date;

\--is this a holiday ?

OPEN c_holiday;

FETCH c_holiday INTO l_temp;

IF NOT c_holiday%NOTFOUND THEN

l_result := null;

END IF;

CLOSE C_HOLIDAY;

\-- is this a weekend day

OPEN c_today;

FETCH c_today INTO l_today;

IF l_today = 1 OR l_today = 7 THEN

l_result := NULL;

END IF;

CLOSE c_today;

RETURN l_result;

END;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Returns date of appointment for specified event

Takes into account the CAL_HOLIDAYS, and whether to get

the next or previous workday if this is a holiday or a

weekend day.

Return date of 31-DEC-1980 or 31-DEC-2999 means DO NOT INSERT

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

FUNCTION get_work_day (i_non_wd_skip IN NUMBER, i_date in DATE) RETURN
DATE IS

l_result DATE;

BEGIN

SELECT DECODE
(nvl(i_non_wd_skip,999),-1,GREATEST(nvl(is_non_wd(i_date),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 1),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 2),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 3),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 4),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date - 5),to_date(\'31-DEC-1980\',\'DD-MON-YYYY\'))),

1,LEAST(nvl(is_non_wd(i_date),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 1),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 2),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 3),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 4),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\')),

nvl(is_non_wd(i_date + 5),to_date(\'31-DEC-2999\',\'DD-MON-YYYY\'))),

0,is_non_wd(i_date),

999,i_date)

INTO l_result

FROM DUAL;

RETURN l_result;

END;

\--

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

This procedure does the actual insertion, given

the recurring ID and date

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

PROCEDURE insert_cal_event (i_recur_event IN NUMBER, i_date IN DATE) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

CURSOR c_collision IS

SELECT \'1\'

FROM FML_EVENT

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE=i_date;

l_temp VARCHAR2(1);

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

\--htp.p(\'INSERT CAL EVENT\');

OPEN c_collision;

FETCH c_collision INTO l_temp;

IF c_collision%NOTFOUND THEN

\--htp.p(\'NO COLLISION\');

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

/\*

INSERT INTO FML_EVENT

(EVENT_ID,EVENT_TYPE,SUBJECT,CREATE_DATE,CREATED_BY,BEGIN_DATE,END_DATE,BEGIN_TIME,

END_TIME,PRIORITY,STATUS,VIEWING_ORDER,INACTIVE,MAIL_STATUS,MAIL_TIME_UNITS,MAIL_TIME_VALUE,MAIL_TO,

LOCATION_TZID,TEXT_ID,OBJECT_ID,CONTACT_BADGE_NO,COLOR,PIM_OBJECT_ID,LOCATION_ID,RECUR_EVENT_ID,TZID)

VALUES

(seq_event_id.NEXTVAL,r_rec.EVENT_TYPE,r_rec.SUBJECT,sysdate,\'RECUR\',i_date,i_date,

r_rec.BEGIN_TIME,r_rec.END_TIME,r_rec.PRIORITY,r_rec.STATUS,r_rec.VIEWING_ORDER,r_rec.INACTIVE,

r_rec.MAIL_STATUS,r_rec.MAIL_TIME_UNITS,r_rec.MAIL_TIME_VALUE,r_rec.MAIL_TO,

r_rec.LOCATION_TZID,r_rec.TEXT_ID,r_rec.OBJECTID,r_rec.CONTACT_BADGE_NO,r_rec.COLOR,

r_rec.PIM_OBJECT_ID,r_rec.LOCATION_ID,i_recur_event,r_rec.TZID);

commit;\*/

null;

END IF;

CLOSE c_recur;

END IF;

CLOSE c_collision;

END;

\--

PROCEDURE expand_daily(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

BEGIN

\--htp.p(\'EXPAND DAILY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

IF MOD(l_ctr,r_recurring.R_PERIOD)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand daily INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_weekly(i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_ctr NUMBER;

l_period NUMBER;

l_day_of_week VARCHAR2(1);

l_event_day VARCHAR2(1);

l_chr VARCHAR2(1);

err_pnt varchar2(10);

len_days NUMBER;

FIRST_DAY BOOLEAN;

BEGIN

\--htp.p(\'EXPAND DAILY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--iterate through DAY_OF_WEEK string

htp.p(\'DAY_OF_WEEK=\' \|\| r_recurring.day_of_week);

htp.NL;

len_days := length(r_recurring.day_of_week);

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

htp.p(\'Evaluating character=\' \|\| l_chr);

IF l_chr != \',\' THEN

err_pnt := \'0\';

l_ctr := 0;

l_date := r_recurring.R_BEGIN_DATE;

l_event_day := l_chr;

l_period := r_recurring.R_PERIOD \* 7;

FIRST_DAY := FALSE;

err_pnt :=\'1\';

\--increment to first day before entering next loop

WHILE l_date \<= r_recurring.R_END_DATE and not FIRST_DAY LOOP

IF l_event_day = to_char(l_date,\'D\') THEN

FIRST_DAY := TRUE;

\--adjust for increment

l_date := l_date - 1;

END IF;

l_date := l_date + 1;

END LOOP;

\--

WHILE l_date \<= r_recurring.R_END_DATE LOOP

IF MOD(l_ctr,l_period)=0 THEN

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'NEW expand weekly INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--uinsert_cal_event(i_recur_event,work_day);

END IF;

END IF;

l_ctr := l_ctr + 1;

l_date := l_date + 1;

END LOOP; \--while loop

END IF;

END LOOP; \--for loop

END IF;

EXCEPTION

when others then

htp.p(\'Expand weekly error point=\' \|\| err_pnt \|\| \'\<BR\>\' \|\|
sqlerrm);

END;

\--

PROCEDURE expand_monthly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

month_ctr NUMBER;

last_month VARCHAR2(2);

l_week_of_month VARCHAR2(1);

l_day_of_week VARCHAR2(1);

l_weeks_of_month RECUR_ARR;

l_days_of_week RECUR_ARR;

len_days NUMBER;

len_weeks NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND MONTHLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build arrays l_weeks_of_month, l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

len_weeks := LENGTH(NVL(r_recurring.week_of_month,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

\-- check week of month, add to array if exists

IF len_weeks \>= i THEN

l_chr := SUBSTR(r_recurring.week_of_month,i,1);

IF l_chr != \',\' THEN

l_weeks_of_month(l_arr_idx) := l_chr;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

ELSE

l_weeks_of_month(l_arr_idx) := \'0\';

END IF;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

\--htp.p(\'l_days_of_week\');

\--htp.NL;

FOR i IN 1..l_arr_idx LOOP

\--htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

\--htp.p(l_weeks_of_month(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

month_ctr := 0;

last_month := \'00\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

\--Expand for day of month inclusions

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

IF INSTR (r_recurring.day_of_month,l_day_number) \> 0 THEN

\--insert it per instructions

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END IF;

\--Expand for week of month

\-- Get this week of month, day of week

l_week_of_month := to_char(l_date,\'W\');

l_day_of_week := to_char(l_date,\'D\');

IF MOD(month_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check arrays CAL_RECURRING.day_of_week and CAL_RECURRING.day_of_month
match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) AND
(l_weeks_of_month(i)=l_week_of_month) THEN

\--this is a hit

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand monthly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

IF last_month != to_char(l_date,\'MM\') THEN

month_ctr := month_ctr + 1;

END IF;

last_month := to_char(l_date,\'MM\');

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_weekly_old (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_day_number VARCHAR2(2);

last_week VARCHAR2(2);

week_ctr NUMBER;

l_day_of_week VARCHAR2(1);

l_days_of_week RECUR_ARR;

len_days NUMBER;

i NUMBER;

l_chr VARCHAR2(1);

l_arr_idx NUMBER;

relevant_day BOOLEAN;

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND WEEKLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

\--Build array l_days_of_week

len_days := LENGTH(NVL(r_recurring.day_of_week,\'\'));

l_arr_idx := 0;

IF len_days \> 0 THEN

FOR i IN 1..len_days LOOP

l_chr := SUBSTR(r_recurring.day_of_week,i,1);

IF l_chr != \',\' THEN

l_arr_idx := l_arr_idx + 1;

l_days_of_week(l_arr_idx) := l_chr;

END IF;

END LOOP;

END IF;

\--end build arrays

err_pnt:=\'11\';

/\*\--TEMP DISPLAY ARRAYS

If len_days \> 0 THEN

\--htp.p(\'l_days_of_week\');

\--htp.NL;

FOR i IN 1..l_arr_idx LOOP

\--htp.p(l_days_of_week(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

\--htp.p(l_weeks_of_month(i) \|\| \' i=\' \|\| to_char(i));

\--htp.NL;

END LOOP;

END IF;

\--END TEMP\*/

week_ctr := 0;

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

last_week := to_char(l_date,\'WW\');

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_day_number := to_char(l_date,\'DD\');

\-- Get this day of week

l_day_of_week := to_char(l_date,\'D\');

htp.p(\'\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--\');

htp.NL;

htp.p(to_char(week_ctr) \|\| \' MOD \' \|\|
to_char(r_recurring.R_PERIOD));

htp.NL;

htp.p(\'\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--\');

htp.NL;

IF MOD(week_ctr,r_recurring.R_PERIOD)=0 THEN

\--

\--Check array CAL_RECURRING.day_of_week for match

FOR i IN 1..l_arr_idx LOOP

IF (l_days_of_week(i)=l_day_of_week) THEN

\--this is a hit

relevant_day := TRUE;

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

htp.p(\'expand weekly INSERTS for \' \|\| to_char(work_day));

htp.NL;

\--insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END LOOP;

\--

END IF;

htp.p(\'LAST WEEK=\' \|\| last_week \|\| \' AND to_charldate is \' \|\|
to_char(l_date,\'WW\'));

htp.NL;

\--Week 53 (DEC 31 and sometimes 30 (leap yr) would cause extra
increment, first ensure

\--this day falls on week 53 before llowing 53 to increment unncessarily

IF to_char(l_date,\'WW\') = \'53\' THEN

If relevant_day then

IF last_week != to_char(l_date,\'WW\') THEN

week_ctr := week_ctr + 1;

htp.p(\'WEEK CTR INCREMENTED 53.\');

htp.NL;

END IF;

END IF;

ELSE \--all other week treat normally

IF last_week != to_char(l_date,\'WW\') THEN

week_ctr := week_ctr + 1;

htp.p(\'WEEK CTR INCREMENTED.\');

htp.NL;

END IF;

END IF;

relevant_day := FALSE;

last_week := to_char(l_date,\'WW\');

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_yearly (i_recur_event IN NUMBER) IS

l_date DATE;

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID=i_recur_event;

r_recurring CAL_RECURRING%ROWTYPE;

work_day DATE;

l_date_number VARCHAR2(5);

year_ctr NUMBER;

last_year VARCHAR2(4);

err_pnt varchar2(3);

BEGIN

\--htp.p(\'EXPAND YEARLY\');

OPEN c_recur;

FETCH c_recur INTO r_recurring;

CLOSE c_recur;

err_pnt :=\'11\';

year_ctr := 0;

last_year := \'0000\';

err_pnt :=\'21\';

l_date := r_recurring.R_BEGIN_DATE;

WHILE l_date \<= r_recurring.R_END_DATE LOOP

\--is this day in the string day_of_month

l_date_number := to_char(l_date,\'MM/DD\');

\--Expand for day of year inclusions

IF MOD(year_ctr,r_recurring.R_PERIOD)=0 THEN

IF INSTR (r_recurring.date_of_year,l_date_number) \> 0 THEN

\--insert it per instructions

work_day := get_work_day(r_recurring.non_wd_skip,l_date);

IF work_day IS NOT NULL THEN

\--htp.p(\'expand yearly INSERTS for \' \|\| to_char(work_day));

\--htp.NL;

insert_cal_event(i_recur_event,work_day);

END If;

END IF;

END IF;

IF last_year != to_char(l_date,\'YYYY\') THEN

year_ctr := year_ctr + 1;

END IF;

last_year := to_char(l_date,\'YYYY\');

l_date := l_date + 1;

END LOOP;

END;

\--

PROCEDURE expand_recurring_event (i_recur_event IN NUMBER) IS

CURSOR C_RECUR_TYPE IS

SELECT R_PERIOD_TYPE

FROM CAL_RECURRING

WHERE RECUR_EVENT_ID = i_recur_event;

NO_RECUR_EVENT EXCEPTION;

INVALID_EVENT_TYPE EXCEPTION;

l_period_type CAL_RECURRING.R_PERIOD_TYPE%TYPE;

BEGIN

OPEN C_RECUR_TYPE;

FETCH C_RECUR_TYPE INTO l_period_type;

IF NOT C_RECUR_TYPE%NOTFOUND THEN

\-- call appropriate procedure to expand, based on recurring type

IF l_period_type=\'D\' THEN

expand_daily (i_recur_event);

ELSIF l_period_type = \'M\' THEN

expand_monthly (i_recur_event);

ELSIF l_period_type=\'W\' THEN

expand_weekly (i_recur_event);

ELSIF l_period_type=\'Y\' THEN

expand_yearly (i_recur_event);

ELSE

RAISE INVALID_EVENT_TYPE;

END IF;

ELSE

RAISE NO_RECUR_EVENT;

END IF;

END;

\--

PROCEDURE update_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE recur_event_id=i_recur_event;

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT

SET EVENT_TYPE=r_rec.EVENT_TYPE,

SUBJECT=r_rec.SUBJECT,

MOD_DATE=sysdate,

MOD_BY=\'RECUR\',

BEGIN_TIME=r_rec.BEGIN_TIME,

END_TIME=r_rec.END_TIME,

PRIORITY=r_rec.PRIORITY,

STATUS=r_rec.STATUS,

VIEWING_ORDER=r_rec.VIEWING_ORDER,

INACTIVE=r_rec.INACTIVE,

MAIL_STATUS=r_rec.MAIL_STATUS,

MAIL_TIME_UNITS=r_rec.MAIL_TIME_UNITS,

MAIL_TIME_VALUE=r_rec.MAIL_TIME_VALUE,

MAIL_TO=r_rec.MAIL_TO,

LOCATION_TZID=r_rec.LOCATION_TZID,

TEXT_ID=r_rec.TEXT_ID,

OBJECT_ID=r_rec.OBJECTID,

CONTACT_BADGE_NO=r_rec.CONTACT_BADGE_NO,

COLOR=r_rec.COLOR,

PIM_OBJECT_ID=r_rec.PIM_OBJECT_ID,

LOCATION_ID=r_rec.LOCATION_ID,

TZID=r_rec.TZID

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END IF;

CLOSE c_recur;

END;

\--

PROCEDURE remove_recurring (i_recur_event IN NUMBER, i_date IN DATE
DEFAULT NULL) IS

CURSOR c_recur IS

SELECT \*

FROM CAL_RECURRING

WHERE recur_event_id=i_recur_event;

r_rec CAL_RECURRING%ROWTYPE;

BEGIN

OPEN c_recur;

FETCH c_recur INTO r_rec;

IF NOT c_recur%NOTFOUND THEN

\--NULL i_date = do all records

IF i_date IS NULL THEN

\--do all

UPDATE CAL_EVENT

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event;

ELSE

\--do from i_date forward

UPDATE CAL_EVENT

SET INACTIVE=\'Y\'

WHERE RECUR_EVENT_ID=i_recur_event

AND BEGIN_DATE \>= i_date;

END IF;

END IF;

CLOSE c_recur;

END;

\--

PROCEDURE temp(i_recur in numbeR) IS

l_temp varchar2(255);

BEGIN

htp.p(\'TEMP\');

\--htp.htmlOpen;

lib.no_cache;

\-\-\--htp.p(get_work_day(1,to_date(\'06-JUL-1999\',\'DD-MON-YYYY\')));

expand_recurring_event(i_recur);

\--htp.htmlClose;

END;

PROCEDURE expand_migrated_events IS

cursor c1 is

select RECUR_EVENT_ID

from cal_recurring

where recur_event_id not in

(select nvl(recur_event_id,0) from fml_event)

and created_by = \'N0250\'

and event_type != 9000

order by recur_event_id;

begin

for r1 in c1 loop

cal0010.expand_recurring_event(r1.recur_event_id);

commit;

end loop;

end;

END CAL0010;

/

CREATE OR REPLACE PACKAGE CAL_LIB IS

function get_week(i_date_parm in varchar2) return varchar2;

pragma restrict_references(get_week,WNDS,RNDS,WNPS,RNPS);

END;

/

CREATE OR REPLACE PACKAGE BODY CAL_LIB IS

\--

\-- Calculates the report needed the 5 row of 6 row. This is called from
the

\-- cal_report.sqr.

\--

function get_week(i_date_parm in varchar2) return varchar2 is

l_date date;

begin

l_date :=
to_date(to_char(to_date(i_date_parm,\'MonthYYYY\'),\'DD-MON-YYYY\'),\'DD-MON-YYYY\');

if to_number(to_char(last_day(l_date),\'DD\')) \>= 30 and

(

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'MONDAY\' or

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'TUESDAY\' or

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'WEDNESDAY\' or

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'THURSDAY\' or

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'FRIDAY\') then

return(\'5\');

elsif

to_number(to_char(last_day(l_date),\'DD\')) \>= 30 and

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'SUNDAY\' then

return(\'6\');

elsif

to_number(to_char(last_day(l_date),\'DD\')) = 30 and

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'SATURDAY\' then

return(\'5\');

elsif

to_number(to_char(last_day(l_date),\'DD\')) = 31 and

rtrim(to_char(last_day(add_months(l_date,-1)) + 1, \'DAY\'),\' \') =
\'SATURDAY\' then

return(\'6\');

else

return(\'5\');

end if;

exception

when others then

return(null);

end;

END CAL_LIB;

/

CREATE OR REPLACE PACKAGE cat0001 IS

pkg_name varchar2(255) := \'cat0001\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

pkg_syn varchar2(255) := pkg_name; \-- \|\|\'s\';

ping varchar2(255) := pkg_name\|\|\' is alive\';

fancy_background boolean := false;

\--

cursor c_cat_id (p_pid in varchar2) is

select c.\*

from tm_sro_cat_table c,ows_app_pid_xref x,ows_app_login a

where c.cat_name = a.username

and x.pid = a.pid

and a.pid = p_pid

and x.app_name = \'SRO_CAT\';

\--

override_authentication boolean := true;

\--

procedure login(isubmit in varchar2 default null,i_pid in varchar2
default NULL);

procedure validate_user (i_badge in varchar2,i_pass in varchar2,i_pid in
varchar2,

i_operation in varchar2 default null);

procedure login_accepted(i_pid in varchar2);

procedure sro_selection(i_badge in varchar2,i_pid in varchar2);

procedure sro_contract_detail (isearchstr in varchar2,i_pid in
varchar2);

procedure sro_summary (i_pid in varchar2,Z_START in varchar2,Z_ACTION in
varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'100\',Z_TOTAL_ROWS in varchar2
default NULL);

procedure sro_invoice_detail (i_sro_no in varchar2,i_invoice in
varchar2,i_pid in varchar2);

procedure sro_labor_summary_detail (i_sro_no in varchar2,i_pid in
varchar2,i_operation in varchar2 default null);

END;

/

CREATE OR REPLACE PACKAGE BODY cat0001 IS

prolog_done boolean;

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

MAX_ROWS constant number(4) := 1000;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|
\') returned\');

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

function is_me (who in varchar2) return boolean is

begin

if who = upper(owa_util.get_cgi_env(\'remote_user\')) then

return true;

end if;

return false;

end;

\--

function is_webstation return boolean is

begin

if owa_util.get_cgi_env(\'http_user_agent\') like

\'%WebStation%\' then

return true;

end if;

return false;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'SRO_CAT\';

result := log0002.is_valid_pid(i_pid,p_app_name);

return result;

end;

end;

\--

/\*\--

function is_valid_pid (i_pid in number) return boolean is

begin

declare

\--time limit in hours

time_limit constant number := 4;

temp varchar2(1);

cursor c_pid(p_pid in number,p_addr in varchar2) is

select \'1\' from

ows_app_login

where pid = p_pid

and ip = p_addr

and (sysdate - timestamp) \< (time_limit/24);

begin

open c_pid(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_pid into temp;

if not c_pid%NOTFOUND then

update ows_app_login

set timestamp=sysdate

where pid=i_pid;

return TRUE;

else

htp.print(\'This session is no longer valid. Sorry.\');

return FALSE;

end if;

close c_pid;

end;

end;

\--\*/

function ip_allowed_access (i_pid in varchar2) return boolean is

begin

declare

cursor c_find_ip (p_pid in varchar2,p_this_ip in varchar2) is

select instr(p_this_ip,cat_ip)

from ows_app_login l, tm_sro_cat_table c

where l.username = c.cat_name

and l.pid = p_pid;

temp number;

result boolean;

begin

\--htp.print(i_pid \|\| \' \' \|\|
owa_util.get_cgi_env(\'REMOTE_ADDR\'));

htp.NL;

result := FALSE;

open c_find_ip(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_find_ip into temp;

while not c_find_ip%NOTFOUND loop

if temp = 1 then

result := TRUE;

exit;

end if;

fetch c_find_ip into temp;

end loop;

close c_find_ip;

if result=TRUE then

return TRUE;

else

htp.print(\'This workstation is not privileged to view the requested
information.\');

return FALSE;

end if;

end;

end;

\--

procedure log_cat_access (i_pid in varchar2,i_cat_id in varchar2,i_query
in varchar2,i_sro_no in varchar2) is

begin

declare

cursor c_pid_cat (p_pid in varchar2) is

select cat_id

from tm_sro_cat_table a, ows_app_login b

where a.cat_name = b.username

and b.pid = p_pid;

pid_cat_id varchar2(4);

ip varchar2(25);

browser varchar2(50);

path varchar2(50);

begin

open c_pid_cat(i_pid);

fetch c_pid_cat into pid_cat_id;

close c_pid_cat;

ip := owa_util.get_cgi_env(\'REMOTE_ADDR\');

browser := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

path := owa_util.get_owa_service_path \|\|
owa_util.get_cgi_env(\'PATH_INFO\');

insert into ows_cat_log

values
(i_pid,pid_cat_id,i_cat_id,i_query,i_sro_no,ip,sysdate,browser,path);

end;

end;

\--

function webstation_hook (c in varchar2) return varchar2 is

begin

if is_webstation then

return \'method=\"csp:script\" action=\"c:\\travel\\\'

\|\| c \|\| \'\"\';

end if;

return null;

end;

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure login(isubmit in varchar2 default null,i_pid in varchar2
default NULL) is

begin

lib.no_cache;

\--lib.prolog(\'CAT SRO Management System\');

log0002.login(\'SRO_CAT\',pkg_name,\'NEW\',NULL,\'N\');

htp.print(\'\<CENTER\>\');

htp.anchor(\'http://www.aps.anl.gov/mis/tm/catsro.html\',\'Web User\'\'s
Guide\');

htp.nl;

htp.nl;

htp.print(\'\<i\>\<Strong\>If you have any concerns about this
information or its presentation please contact Bob
Ferry\</i\>\</strong\>\');

htp.nl;

htp.anchor(\'mailto:bferry@aps.anl.gov,mis_mgrs@aps.anl.gov\',\'Send
mail to Bob Ferry\');

lib.epilog;

htp.NL;

htp.print(\'\</CENTER\>\');

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure validate_user (i_badge in varchar2,i_pass in varchar2,i_pid in
varchar2,

i_operation in varchar2 default null) is

begin

lib.validate_user(i_badge,i_pass,i_pid,i_operation,\'SRO-CAT\',pkg_name);

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure login_accepted (i_pid in varchar2) is

begin

sro_selection(\'00000\',i_pid);

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure sro_selection (i_badge in varchar2,i_pid in varchar2)is

begin

declare

cursor c_org_name (p_pid in varchar2) is

select username

from ows_app_login a, ows_app_pid_xref x

where a.pid=x.pid

and a.pid = i_pid

and x.app_name = \'SRO_CAT\';

user_name varchar2(50);

user_type varchar2(5);

temp varchar2(1);

temp_text varchar2(255);

org_inst tm.tm_sro_header.organization%TYPE;

user_level varchar2(5);

seq_id varchar2(2);

result BOOLEAN;

begin

htp.NL;

result := is_valid_pid(i_pid);

if is_valid_pid(i_pid) and ip_allowed_access(i_pid) then

log_cat_access (i_pid,\'\',\'\',\'\');

lib.prolog(\'SRO Report Selection Criteria\');

htp.print(\'\<CENTER\>\');

user_name := \'NONE\';

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_summary\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.bold(\'CAT Name:\'));

open c_org_name(i_pid);

fetch c_org_name into temp_text;

htp.tableData(nvl(temp_text,\'\'));

close c_org_name;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'View listing in groups of:\'));

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',\'3\',\'3\',\'100\'));

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formSubmit;

htp.formClose;

end if;

htp.print(\'\</CENTER\>\');

lib.epilog;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- Modification History

\--

procedure sro_contract_detail (isearchstr in varchar2,i_pid in varchar2)
is

begin

declare

cursor c_sro_header(p_sro_no in varchar2) is

select \* from tm.tm_sro_header

where sro_no=p_sro_no;

cursor c_money_committed(p_sro_no in varchar2) is

select \* from tm.tm_timesheet

where sro_no = p_sro_no

order by tm_date desc;

cursor c_sum_money_spent(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet ts

where sro_no = p_sro_no

and matched = \'Y\';

cursor c_sum_money_committed(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet ts

where sro_no = p_sro_no;

cursor c_rates(p_type in varchar2) is

select \*

from tm.tm_rates

where type=p_type;

cursor c_cost_codes(p_sro_no in varchar2) is

select \* from tm.tm_sro_cost_codes

where sro_no = p_sro_no;

cursor c_labor_hours(p_sro_no in varchar2) is

select sum(hours)

from tm.tm_timesheet ts,tm.tm_rates tr

where sro_no = p_sro_no

and ts.labor_type = tr.type

and matched=\'Y\'

and equipment=\'N\';

cursor c_dollars(p_sro_no in varchar2,

p_rental in varchar) is

select sum(amount)

from tm.tm_timesheet ts,tm.tm_rates tr

where ts.labor_type = tr.type

and sro_no = p_sro_no

and nvl(equipment,\'N\') like p_rental \|\| \'%\'

and matched = \'Y\';

cursor c_material_dollars(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where sro_no = p_sro_no

and material=\'Y\'

and matched = \'Y\';

estimated tm.tm_sro_header.estimate%TYPE;

remain tm.tm_sro_header.estimate%TYPE;

running_total

tm.tm_sro_header.estimate%TYPE;

labor_cost tm.tm_sro_header.estimate%TYPE;

r_sh tm.tm_sro_header%ROWTYPE;

r_rates tm.tm_rates%ROWTYPE;

temp varchar2(255);

temp_total tm.tm_sro_header.estimate%TYPE;

debug_ind varchar2(50);

cost_code_string varchar2(60);

cursor c_cont (p_contract_no in varchar2) is

select company_name

from tm.tm_contractors_table

where contract_no=p_contract_no;

last_mod date;

\--Java test code

\-- months number;

\-- display_month varchar2(8);

temp_amt number;

\-- i number;

\-- max_amt number;

total_hours number;

temp_text varchar2(255);

temp_anchor varchar2(255);

begin

\--lib.no_cache;

if (is_valid_pid(i_pid) and ip_allowed_access(i_pid))then

log_cat_access (i_pid,\'\',\'\',isearchstr);

select max(last_mod_date) into last_mod from tm.tm_timesheet where
sro_no=isearchstr;

lib.prolog(\'SRO Money Spent \');

debug_ind := \'bef tm_sro_header\';

select nvl(sum(estimate),-1) into estimated from tm.tm_sro_header where
sro_no = isearchstr;

remain := estimated;

open c_sro_header(substr(isearchstr,1,14));

fetch c_sro_header into r_sh;

close c_sro_header;

htp.Print(\'\<CENTER\>\');

\--

open c_sum_money_committed(isearchstr);

fetch c_sum_money_committed into running_total;

close c_sum_money_committed;

\--

running_total := nvl(running_total,0);

if running_total \> 0 then

remain := running_total / estimated \* 100;

else

remain := 0;

end if;

\--

if (remain \>= r_sh.percent_committed and
nvl(r_sh.warning_flag,\'Y\')=\'Y\') then

temp := \'\<h2\>\<blink\>\<i\>\' \|\| to_char(remain,999) \|\| \'% of
estimated money has been used.\';

htp.Print(temp);

htp.NL;

temp := \' Warning requested at or above \' \|\|
to_char(r_sh.percent_committed,\'999\') \|\| \'%.
\</I\>\</blink\>\</h2\>\' ;

htp.Print(temp);

htp.Print(\'\<HR\>\');

end if;

running_total := 0;

remain := estimated;

htp.Print (\'\</CENTER\>\');

\--

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'SRO No:\'));

htp.tableData(r_sh.sro_no);

htp.tableRowClose;

htp.tableData(htf.Bold(\'Last updated:\'));

htp.tableData(last_mod);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Organization:\'));

htp.tableData(r_sh.organization);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Open Date:\'));

htp.tableData(r_sh.request_date);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Close Date:\'));

htp.tableData(r_sh.close_date);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Financially closed:\'));

htp.tableData(r_sh.financially_closed);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Cost codes:\'));

\-- get cost code information

for r_cost in c_cost_codes(r_sh.sro_no) loop

cost_code_string := r_cost.account \|\| \'-\' \|\| r_cost.cost_center
\|\| \'-\' \|\| r_cost.cost_element \|\| \' \<i\>\<strong\> \' \|\|
r_cost.percent_allocated \|\| \' %\</strong\>\</i\>\';

htp.tableData(cost_code_string);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\');

end loop;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Description:\'));

htp.tableData(r_sh.description);

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total Estimated:\'));

htp.tableData(to_char(estimated,\'\$9,999,999,990.99\'),\'RIGHT\');

htp.tableRowClose;

open c_sum_money_committed(isearchstr);

fetch c_sum_money_committed into running_total;

close c_sum_money_committed;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Amount Committed:\'));

htp.tableData(htf.Bold(to_char(running_total,\'\$9,999,999,990.99\')),\'RIGHT\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total Remaining:\'));

remain := estimated - running_total;

htp.tableData(to_char(remain,\'\$9,999,999,990.99\'),\'RIGHT\');

htp.tableRowClose;

htp.tableRowOpen;

remain := running_total/estimated \* 100;

htp.tableData(htf.Bold(\'% Committed:\'));

htp.tableData(htf.Bold(to_char(remain,\'999999\') \|\| \' %\')); \--
formerly \'999\'; fml 11/13/96

htp.tableRowClose;

htp.Print(\'\<HR\>\');

htp.tableRowOpen;

open c_sum_money_spent(isearchstr);

fetch c_sum_money_spent into temp_total;

close c_sum_money_spent;

running_total := nvl(running_total,0);

temp_total := nvl(temp_total,0);

running_total := running_total + temp_total ;

htp.tableData(htf.Bold(\'Amount Invoiced:\'));

htp.tableData(to_char(temp_total,\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

remain := nvl(temp_total/estimated \* 100,0);

htp.tableData(htf.Bold(\'% Invoiced:\'));

htp.tableData(to_char(remain,\'999999\') \|\| \' %\'); \-- formerly
\'999\'; fml 11/13/96

htp.tableRowClose;

htp.tableClose;

htp.Print (\'\<HR\>\');

htp.Print (\'\<CENTER\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Date\');

htp.tableHeader(\'Hours\');

htp.tableHeader(\'Type\');

htp.tableHeader(\'Material\');

htp.tableHeader(\'Amount\');

htp.tableHeader(\'Invoice No.\');

htp.tableHeader(\'Invoice matched\');

for r_time in c_money_committed(isearchstr)

loop

htp.tableRowOpen;

htp.tableData(r_time.tm_date);

open c_rates(r_time.labor_type);

fetch c_rates into r_rates;

close c_rates;

if r_time.material = \'N\' or r_time.material is null then

htp.tableData(r_time.hours \|\| \' \' \|\|
substr(r_rates.frequency,1,1));

htp.tableData(r_time.labor_type);

htp.tableData(\'.\');

else

htp.tableData (\'.\');

htp.tableData (\'.\');

htp.tableData(nvl(substr(r_time.description,1,12),\'Material\'));

end if;

htp.tableData(nvl(to_char(r_time.amount,\'\$9,999,999,990.99\'),\'-\'),\'RIGHT\');

\--htp.tableData(nvl(r_time.invoice_no,\'-\'));

\--temp_anchor :=
get_service\|\|pkg_syn\|\|\'.sro_invoice_detail?i_sro_no=\' \|\|
isearchstr \|\| \'&i_invoice=\' \|\| r_time.invoice_no;

if nvl(r_time.invoice_no,\'-\') = \'-\' then

\-- temp_text := \'-\';

htp.tableData(\'-\');

else

\-- temp_text := htf.anchor(temp_anchor,r_time.invoice_no);

htp.formOpen(get_service\|\|pkg_syn\|\| \'.sro_invoice_detail\');

htp.tableData(htf.formSubmit(\'i_invoice\',r_time.invoice_no));

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_sro_no\',r_time.sro_no);

htp.formClose;

end if;

\--htp.tableData(temp_text);

htp.tableData(nvl(r_time.matched,\'N\'));

htp.tableRowClose;

end loop;

htp.tableClose;

htp.NL;

htp.Print(\'\<HR\>\');

htp.Bold(\'Break Down of Money Spent\');

htp.NL;

htp.Print(\'\<I\>Invoiced amounts only\</I\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total labor:\'));

open c_labor_hours(isearchstr);

fetch c_labor_hours into total_hours;

close c_labor_hours;

htp.tableData(to_char(NVL(total_hours,0),\'9,999,990\') \|\| \'
hours\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total labor:\'));

open c_dollars(isearchstr,\'N\');

fetch c_dollars into temp_amt;

close c_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total materials:\'));

open c_material_dollars(isearchstr);

fetch c_material_dollars into temp_amt;

close c_material_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total rental fees:\'));

open c_dollars(isearchstr,\'Y\');

fetch c_dollars into temp_amt;

close c_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.NL;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_labor_summary_detail\');

htp.formSubmit(\'i_operation\',\'View Totals by Labor Type\');

htp.formHidden(\'i_sro_no\',isearchstr);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

\--htp.Print(\'\</CENTER\>\');

htp.NL;

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

exception

when no_data_found then

htp.print(\' No data found.(\'\|\|debug_ind\|\|\')\');

end;

end;

\-- Modification History

\--

\-- Date Initials Remarks

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

procedure sro_summary (i_pid in varchar2,Z_START in varchar2,Z_ACTION in
varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'100\',Z_TOTAL_ROWS in varchar2
default NULL

) is

begin

declare

cursor c_sro (p_sro_type in varchar2,p_sro_status in
varchar2,p_coordinator in varchar2,p_organization in varchar2) is

select \*

from tm.tm_sro_header

where revision_no=0

and substr(sro_no,3,22) like \'%\' \|\| upper(p_coordinator) \|\| \'%\'

and sro_no like upper(p_sro_type) \|\| \'%\'

and organization like upper(p_organization) \|\| \'%\'

order by old_sro asc,sro_no desc,revision_no asc;

cursor c_committed(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where sro_no = p_sro_no;

cursor c_spent(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where matched = \'Y\'

and sro_no = p_sro_no;

temp_anchor varchar2(255);

temp_text varchar2(255);

temp_sro_type varchar2(255);

temp_org tm.tm_sro_header.organization%TYPE;

temp_coordinator tm.tm_contract_coordinator_table.seq_id%TYPE;

spent tm.tm_sro_header.estimate%TYPE;

committed tm.tm_sro_header.estimate%TYPE;

temp tm.tm_sro_header.estimate%TYPE;

estimated tm.tm_sro_header.estimate%TYPE;

diff tm.tm_sro_header.estimate%TYPE;

threshold number(9,2); \-- formerly number(5,2), modified 11/13/96 fml

warning varchar2(1);

temp_sro_status varchar2(10);

user_level number(1);

user_type varchar2(20);

match varchar2(1);

debug_loc varchar2(20);

lvl varchar2(5);

supervisor varchar2(1);

temp_cost_element tm.tm_sro_cost_codes.cost_element%TYPE;

temp_cost_center tm.tm_sro_cost_codes.cost_center%TYPE;

temp_cost_account tm.tm_sro_cost_codes.account%TYPE;

\--Next N

r_sro tm.tm_sro_header%ROWTYPE;

\--r_stock stock.stock_header%ROWTYPE;

est_print varchar2(50);

sro_print varchar2(255);

committed_amt number;

remaining number;

commit_print varchar2(50);

remain_print varchar2(50);

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number;

total_pages number;

cur_cnt number;

r_cat tm_sro_cat_table%ROWTYPE;

begin

if (is_valid_pid(i_pid) and ip_allowed_access(i_pid)) then

libs.prolog(\'SRO Status Summary\');

htp.print(\'\<CENTER\>\');

htp.Print(\'\<h4\>\<I\>Flashing Red \"75% spent\" indicates committed
money is at or exceeds 75% of the estimated amount for that
SRO.\</I\>\</h4\>\');

open c_cat_id(i_pid);

fetch c_cat_id into r_cat;

close c_cat_id;

I_QUERY := \'select tm.tm_sro_header.sro_no,organization, estimate,
tm.tm_sro_header.description,0,warning_flag,status,percent_committed
from tm.tm_sro_header \';

i_where := \'where tm.tm_sro_header.cat_id =\'\'\' \|\| r_cat.cat_id
\|\| \'\'\'\' \|\|

\' group by
tm.tm_sro_header.sro_no,organization,estimate,tm.tm_sro_header.description,old_sro,revision_no,warning_flag,status,percent_committed\'
\|\|

\' order by old_sro asc,tm.tm_sro_header.sro_no desc,revision_no asc\';

i_query := i_query \|\|\' \'\|\| i_where;

\-- BLIBBLE

log_cat_access (i_pid,r_cat.cat_id,i_query,\'\');

htp.nl;

debug_loc :=\'a1\';

I_CURSOR := dbms_sql.open_cursor;

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1, r_sro.sro_no,25);

dbms_sql.define_column(I_CURSOR, 2, r_sro.organization,20);

dbms_sql.define_column(I_CURSOR, 3, r_sro.estimate);

dbms_sql.define_column(I_CURSOR, 4, r_sro.description,255);

dbms_sql.define_column(I_CURSOR, 5, committed);

dbms_sql.define_column(I_CURSOR, 6, r_sro.warning_flag,1);

dbms_sql.define_column(I_CURSOR, 7, r_sro.status,5);

dbms_sql.define_column(I_CURSOR, 8, r_sro.percent_committed);

I_VOID := dbms_sql.execute(I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if I_ROWS_FETCHED = 0 then

htp.nl;

htp.bold(\'No records returned\');

dbms_sql.close_cursor(I_CURSOR);

lib.epilog;

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

Y_TOTAL_ROWS := I_TOTAL_ROWS;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

htp.nl;

htp.nl;

debug_loc := \'a2\';

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'SRO No.\');

htp.tableHeader(\'75% spent\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Estimate\');

htp.tableHeader(\'Committed\');

htp.tableHeader(\'Remaining\');

debug_loc := \'b2\';

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1, r_sro.sro_no);

dbms_sql.column_value(I_CURSOR, 2, r_sro.organization);

dbms_sql.column_value(I_CURSOR, 3, r_sro.estimate);

dbms_sql.column_value(I_CURSOR, 4, r_sro.description);

dbms_sql.column_value(I_CURSOR, 5, committed);

dbms_sql.column_value(I_CURSOR, 6, r_sro.warning_flag);

dbms_sql.column_value(I_CURSOR, 7, r_sro.status);

dbms_sql.column_value(I_CURSOR, 8, r_sro.percent_committed);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or I_TOTAL_ROWS \>= 1)

) then

htp.tableRowOpen;

if r_sro.estimate is null then

est_print := \'.\';

else

est_print := to_char(r_sro.estimate,\'\$999,990.99\');

end if;

open c_committed(r_sro.sro_no);

fetch c_committed into committed_amt;

if not c_committed%NOTFOUND and committed_amt is not null then

commit_print := to_char(committed_amt,\'\$9,999,990.99\');

else

commit_print := \'.\';

committed_amt := 0;

end if;

close c_committed;

temp_anchor :=
get_service\|\|pkg_syn\|\|\'.sro_contract_detail?isearchstr=\' \|\|
r_sro.sro_no \|\| \'&i_pid=\' \|\| i_pid;

sro_print := htf.anchor(temp_anchor,r_sro.sro_no); \-- \'\<a href\>\'
\|\| temp_anchor \|\| \'\</a\>\' \|\| r_sro.sro_no;

htp.tableData(sro_print);

if r_sro.estimate = 0 then

threshold := 0;

else

threshold := (committed_amt / r_sro.estimate) \* 100;

end if;

if (threshold \>= r_sro.percent_committed) then

warning := \'Y\';

else

warning := \'N\';

end if;

if (warning = \'Y\' and nvl(r_sro.warning_flag,\'Y\') = \'Y\') then

temp_text := \'\<font color=#ff0000\> \<BLINK\>75%
Spent\</BLINK\>\</font\>\';

else

temp_text := \'\<font color=#006010\>OK\</font\>\';

end if;

sro_print := r_sro.sro_no;

htp.tableData(temp_text);

htp.tableData(nvl(r_sro.description,\'-\'));

if r_sro.status = \'OPEN\' then

htp.tableData(\'Open\');

elsif r_sro.status = \'CLOSE\' then

htp.tableData(\'Closed\');

else

htp.tableData(\'.\');

end if;

remaining := r_sro.estimate - committed_amt;

htp.tableData(est_print,\'RIGHT\');

htp.tableData(commit_print,\'RIGHT\');

if remaining is null then

remain_print := \'.\';

else

remain_print := to_char(remaining,\'\$9,999,990.99\');

htp.tableData(nvl(remain_print,\'.\'),\'RIGHT\');

end if;

end if;

htp.tableRowClose;

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

end loop;

htp.tableClose;

dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_summary\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'Z_START\', to_char(I_START));

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

htp.para;

if I_PREV_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(PREV_BUT_CAPTION));

end if;

if I_NEXT_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(NEXT_BUT_CAPTION));

end if;

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formClose;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p( MAX_ROWS_MESSAGE);

end if;

\-- Just in case reload button was pressed

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

libs.epilog;

end if;

exception

when value_error then

htp.print(\'Error encountered in code: sro_summary;
debug_loc:\'\|\|debug_loc\|\|\'.\');

end;

end;

procedure sro_labor_summary_detail(i_sro_no in varchar2,i_pid in
varchar2,i_operation in varchar2 default null) is

begin

declare

cursor c_man_hours(p_sro_no in varchar2) is

select sum(amount),sum(hours),labor_type

from tm.tm_timesheet ts,tm.tm_rates tr

where ts.labor_type = tr.type

and sro_no = p_sro_no

and matched = \'Y\'

and nvl(equipment,\'N\') = \'N\'

and nvl(material,\'N\') = \'N\'

group by labor_type

order by labor_type;

type man_hours is record(

amount number(12,2),

hours number,

labor_type varchar2(50));

descrip tm.tm_rates.description%TYPE;

r_man_hours man_hours;

begin

lib.prolog (\'Summary of Man Hours by Type\');

if (is_valid_pid(i_pid) and ip_allowed_access(i_pid)) then

log_cat_access (i_pid,\'\',\'\',i_sro_no);

htp.Print(\'\<CENTER\>\');

htp.Print(htf.Bold(\'Sro No.: \') \|\| i_sro_no);

htp.NL;

htp.NL;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Type\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Hours\');

htp.tableHeader(\'Amount\');

open c_man_hours(i_sro_no);

fetch c_man_hours into r_man_hours;

while not c_man_hours%NOTFOUND

loop

htp.tableRowOpen;

htp.tableData(r_man_hours.labor_type);

select description into descrip from tm.tm_rates where
type=r_man_hours.labor_type;

htp.tableData(descrip);

htp.tableData(r_man_hours.hours);

htp.tableData(to_char(r_man_hours.amount,\'\$9,999,990.99\'));

htp.tableRowClose;

fetch c_man_hours into r_man_hours;

end loop;

close c_man_hours;

htp.tableClose;

htp.Print (\'\</CENTER\>\');

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

end;

end;

procedure sro_invoice_detail (i_sro_no in varchar2,i_invoice in
varchar2,i_pid in varchar2) is

begin

declare

display_text tm.tm_timesheet.description%TYPE;

begin

if (is_valid_pid(i_pid) and ip_allowed_access(i_pid)) then

log_cat_access (i_pid,\'\',\'\',i_sro_no);

lib.Prolog(\'Additional Invoice Detail\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'Invoice No.:\');

htp.tableData(i_invoice);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'SRO No.:\');

htp.tableData(i_sro_no);

htp.tableRowClose;

select max(description) into display_text from tm.tm_timesheet

where sro_no = i_sro_no and invoice_no = i_invoice

and description is not null;

htp.tableRowOpen;

htp.tableData(\'Description:\');

if display_text is not null then

htp.tableData(display_text);

else

htp.tableData(\'No description is available.\');

end if;

htp.tableRowClose;

htp.tableClose;

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

end;

end;

begin

prolog_done := false;

END;

/

CREATE OR REPLACE PACKAGE gen0001 IS

pkg_name varchar2(255) := \'gen0001\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

fancy_background boolean := false;

override_authentication boolean := false;

type FormImageVar is record

( x varchar2(20),

y varchar2(20));

\--

procedure login(login_message in varchar2 default NULL);

procedure request_list (i_operation in varchar2 default NULL,

p_structure in varchar2,

p_badge_no in varchar2,

p_just_roles in varchar2);

END;

/

CREATE OR REPLACE PACKAGE BODY gen0001 IS

prolog_done boolean;

G_JUST_PRINT_ROLES boolean := TRUE;

\--G_JUST_PRINT_ROLES boolean := FALSE;

\--

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

RECORD_SET_SIZE constant number(4) := 10;

SLIDER_WIDTH constant number(4) := 10;

MAX_ROWS constant number(4) := 500;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|

\') returned\');

\--

function check_pid(ipid in number default NULL) return number is

\--

begin

if ipid is NULL or ipid = 0 then

return(9999);

else

return(ipid + 1);

end if;

end;

\--

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

\-- Modification History

\--

\-- Date Initials Remarks

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- 7 - MAR - 1997 fml Initial Coding

\--

procedure login(login_message in varchar2 default null) is

begin

declare

cursor c_gst is select \* from gen_structure_table

order by 1;

r_gst gen_structure_table%ROWTYPE;

p_badge_no varchar2(10);

p_structure varchar2(50);

begin

lib.prolog(\'APS Application Role Scope Query\');

htp.formOpen(pkg_name\|\|\'.request_list\');

\--

if login_message is null then

htp.em( \'Please enter the following information\');

else

htp.em(login_message);

end if;

htp.para;

htp.NL;

htp.formSelectOpen(\'p_structure\', htf.bold(\'Structure: \'));

open c_gst;

while 1=1 loop

fetch c_gst into r_gst;

if c_gst%NOTFOUND then

exit;

end if;

htp.formSelectOption(r_gst.description,\'\',

\'VALUE = \'\|\|r_gst.structure_code);

end loop;

close c_gst;

htp.formSelectClose;

htp.nl;

\-- htp.bold(\'Structure: \' \|\| htf.formText(\'p_structure\',

\-- 25,255,p_structure));

htp.NL;

htp.bold(\'Badge No: \' \|\| htf.formText(\'p_badge_no\',

10,10,p_badge_no));

htp.NL;

/\*

htp.formSelectOpen(\'subproject_name\', htf.bold(\'Sub Project: \'));

htp.formSelectOption(\'ALL\');

open subproject;

while 1=1 loop

fetch subproject into subproject_name;

if subproject%NOTFOUND then

exit;

end if;

htp.formSelectOption(subproject_name);

end loop;

close subproject;

htp.formSelectClose;

htp.nl;

\*/

htp.NL;

htp.bold(\'Display Roles Only: \');

htp.formRadio (\'p_just_roles\',\'N\',\'checked\');

htp.p(\'No \');

htp.formRadio (\'p_just_roles\',\'Y\');

htp.p(\'Yes \');

htp.NL;

htp.NL;

htp.formHidden(\'i_operation\',\'Submit\'); \-- default button

htp.formSubmit(\'i_operation\',\'Submit\');

htp.formReset;

htp.formClose;

htp.em(\' Query may take a few seconds to execute. Please be
patient.\');

lib.epilog;

end;

end;

function get_user_info (p_username in varchar2,

p_badge_no in varchar2 default null)

return varchar2 is

begin

declare

cursor c_gut(p_username in varchar2) is

select \* from gen_user_table

where username = p_username;

r_gut gen_user_table%ROWTYPE;

\--

cursor c_apv (p_badge_no in varchar2) is

select \* from all_personnel_comp_view

where badge_no = p_badge_no

order by inactive desc; \-- note multiple recs possible

r_apv all_personnel_comp_view%ROWTYPE;

l_inactive varchar2(25);

begin

if p_username is null then

open c_apv(p_badge_no);

fetch c_apv into r_apv;

if c_apv%NOTFOUND then

close c_apv;

return(NULL);

else

close c_apv;

if NVL(r_apv.inactive,\'N\') = \'N\' then

l_inactive := NULL;

else

l_inactive := \'Inactive: \';

end if;

return(l_inactive \|\|r_apv.name\|\|\' \'\|\|

r_apv.grp);

end if;

else

open c_gut(p_username);

fetch c_gut into r_gut;

if c_gut%NOTFOUND then

close c_gut;

return NULL;

end if;

close c_gut;

open c_apv(r_gut.badge_no);

fetch c_apv into r_apv;

if c_apv%NOTFOUND then

close c_apv;

return(NULL);

else

close c_apv;

if NVL(r_apv.inactive,\'N\') = \'N\' then

l_inactive := NULL;

else

l_inactive := \'Inactive: \';

end if;

return(l_inactive\|\| r_apv.name\|\|\' \'\|\|

r_apv.grp);

end if;

end if;

end;

end;

procedure get_role_members (p_structure in varchar2,

p_role_id in varchar2) is

begin

declare

cursor c_gur (p_structure in varchar2, p_role_id in varchar2) is

select a.\*

\--from all_personnel_comp_view b, gen_user_table c, gen_user_roles a

from all_personnel_view b, gen_user_table c, gen_user_roles a

where b.badge_no(+) = c.badge_no

and c.username = a.username

and a.structure_code = upper(p_structure)

and a.granted_role = upper(p_role_id)

order by b.name;

\-- select \* from gen_user_roles

\-- where structure_code = upper(p_structure)

\-- and granted_role = upper(p_role_id);

r_gur gen_user_roles%ROWTYPE;

l_count number := 0;

begin

open c_gur(p_structure, p_role_id);

\--htp.em (p_role_id);

while 1=1 loop

fetch c_gur into r_gur;

if c_gur%NOTFOUND then

close c_gur;

exit;

else

if l_count = 0 then

\--htp.bold(\'\[\');

\--

\-- Display the role scope

\--htp.nl;

\--htp.p(htf.bold(\'\<font size=\"-3\"\>\'\|\|

\-- \'\*\*\* \'\|\|p_role_id \|\|\' \*\*\*\'\|\|

\-- \'\</font\>\'));

null;

end if;

l_count := l_count + 1;

\--

\-- Start a list for this group

if l_count = 1 then

\-- htp.ulistOpen;

htp.listHeader(htf.bold(\'\<font size=\"-3\"\>\'\|\|

\'\*\*\* \'\|\|p_role_id \|\|\' \*\*\*\'\|\|

\'\</font\>\'));

end if;

\-- htp.print(htf.bold(\'\[\')\|\|r_gur.username\|\|\' \'\|\|

\-- get_user_info(r_gur.username)\|\|htf.bold(\'\]\'));

\-- htp.print(get_user_info(r_gur.username));

\--htp.nl;

if not G_JUST_PRINT_ROLES then

htp.listItem(htf.bold(\'\<font size=\"-3\"\>\'\|\|

get_user_info(r_gur.username)\|\|

\'\</font\>\'));

end if;

end if;

end loop;

\--

\-- End the list for this group

if l_count \> 0 then

\-- htp.bold(\'\]\');

\--htp.ulistClose;

null;

end if;

end;

end;

\--

procedure traverse_list (p_structure in varchar2,

p_parent_id in varchar2,

p_order in out number,

p_level in number) is

begin

declare

j_query varchar2(2000);

j_cursor integer;

j_void integer;

j_rows_fetched integer := 0;

l_node_id varchar2(50);

l_count number;

l_level number;

l_user_info varchar2(255);

begin

l_level := p_level + 1;

\-- sort by name ascending

j_query := \' select z.node \'\|\|

\' from gen_role_table a, \'\|\|

\' (select a.name, b.username \'\|\|

\' from all_personnel_view a, \'\|\|

\' gen_user_table b \'\|\|

\' where a.badge_no = b.badge_no) ab , \'\|\|

\' gen_role_scope z \'\|\|

\' where z.node = a.role_id(+) \'\|\|

\' and z.node = ab.username(+) \'\|\|

\' and z.structure_code = upper(
\'\|\|\'\'\'\'\|\|p_structure\|\|\'\'\'\'\|\|\')\'\|\|

\' and z.linked_to_node = upper(
\'\|\|\'\'\'\'\|\|p_parent_id\|\|\'\'\'\'\|\|\')\'\|\|

\'order by
decode(a.role_id,null,\'\|\|\'\'\'\'\|\|\'\~\'\|\|\'\'\'\'\|\|\',a.role_id),
ab.name\';

/\*

\-- random sort order

j_query := \'select node from gen_role_scope \'\|\|

\' where structure_code =upper(
\'\|\|\'\'\'\'\|\|p_structure\|\|\'\'\'\'\|\|\')\'\|\|

\' and linked_to_node = upper(
\'\|\|\'\'\'\'\|\|p_parent_id\|\|\'\'\'\'\|\|\')\';

\*/

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor, j_query, dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,l_node_id,50);

j_void := dbms_sql.execute(j_cursor);

l_count := 0;

\--htp.ulistOpen(\'\',\'\',\'o\');

while 1=1 loop

j_rows_fetched := dbms_sql.fetch_rows(j_cursor);

if j_rows_fetched \<= 0 then

dbms_sql.close_cursor(j_cursor);

exit;

else

dbms_sql.column_value(j_cursor,1,l_node_id);

l_count := l_count + 1;

\-- htp.print (lpad(l_node_id,(2\*p_level) +
length(l_node_id)+2,\'=\'));

\-- htp.print (l_node_id);

\--

\-- Start a list for this group

if l_count = 1 then

htp.ulistOpen;

end if;

\--

\-- display the name

l_user_info := get_user_info(l_node_id);

if l_user_info is NOT NULL then

\--htp.nl;

if not G_JUST_PRINT_ROLES then

htp.listItem(\'\<font size=\"-3\"\>\'\|\|

l_user_info\|\|

\'\</font\>\');

end if;

else

\-- Must be a role (scope)

\--htp.bold(\'\<font size=\"-3\"\>\*\*\* \'\|\|

\-- l_node_id\|\|\' \*\*\*\'\|\|

\-- \'\</font\>\');

null;

get_role_members(p_structure, l_node_id);

end if;

\--get_role_members(p_structure, l_node_id);

\-- htp.nl;

p_order := p_order + 1;

traverse_list(p_structure,l_node_id,p_order,l_level);

end if;

end loop;

\--

\-- Close the list for this group

if l_count \> 0 then

htp.ulistClose;

end if;

\--htp.ulistClose;

end;

end;

\--

procedure traverse_list2 (p_structure in varchar2,

p_parent_id in varchar2) is

begin

declare

cursor c_grs (p_structure in varchar2,

p_root in varchar2) is

select level, node from gen_role_scope

start with node = p_root

connect by prior node = linked_to_node;

l_node_id varchar2(50);

l_level number;

begin

open c_grs(p_structure, p_parent_id);

while 1=1 loop

fetch c_grs into l_level, l_node_id;

if c_grs%NOTFOUND then

close c_grs;

exit;

end if;

htp.print (lpad(l_node_id,(2\*l_level) + length(l_node_id)+2,\'=\'));

htp.print(get_user_info(l_node_id));

get_role_members(p_structure, l_node_id);

htp.nl;

end loop;

end;

end;

\--

function login_ok (i_user in varchar2,i_pass in varchar2) return BOOLEAN
is

begin

declare

result varchar2(1);

cursor c_login (p_user in varchar2,p_pass in varchar2) is

select \'1\'

from gen_user_table

where username = p_user

and breaker = p_pass;

begin

open c_login (i_user,i_pass);

fetch c_login into result;

if not c_login%NOTFOUND then

return(TRUE);

else

return(FALSE);

end if;

close c_login;

end;

end;

\--

procedure request_list (i_operation in varchar2 default NULL,

p_structure in varchar2,

p_badge_no in varchar2,

p_just_roles in varchar2) is

begin

declare

cursor c_gst (p_structure in varchar2) is

select \* from gen_structure_table where structure_code = p_structure;

r_gst gen_structure_table%ROWTYPE;

\--

cursor c_gut (p_badge_no in varchar2 ) is

select \* from gen_user_table

where badge_no = p_badge_no;

r_gut gen_user_table%ROWTYPE;

\--

cursor c_gur02 (p_structure in varchar2, p_badge_no in varchar2) is

select a.granted_role

from gen_user_table b,

gen_user_roles a

where a.structure_code = upper(p_structure)

and b.username = a.username

and b.badge_no = upper(p_badge_no);

r_gur gen_user_roles%ROWTYPE;

l_node_id varchar2(50);

tmp_cnt number;

p_order number;

exit_now exception;

begin

\--

if p_just_roles = \'Y\' then

G_JUST_PRINT_ROLES := TRUE;

else

G_JUST_PRINT_ROLES := FALSE;

end if;

\-- get structure description

open c_gst(p_structure);

fetch c_gst into r_gst;

close c_gst;

\-\--

open c_gut(p_badge_no);

fetch c_gut into r_gut;

if p_badge_no is null or c_gut%NOTFOUND then

close c_gut;

htp.print(\'\<html\>\<head\>\');

htp.print(

\'\<meta http-equiv=\"refresh\" content=\"0;URL=\'\|\|

pkg_name\|\|\'.login?login_message=\'\|\|

\'Please+enter+a+valid+badge+number.\'\|\|\'\"\');

htp.print(\'\</head\>\</html\>\');

raise EXIT_NOW;

end if;

close c_gut;

lib.prolog(\'APS Application Role Scope Query Results\');

\-- htp.br;

htp.bold(\'Structure: \'\|\|r_gst.description);

htp.nl;

htp.bold(\'For: \'\|\| get_user_info(NULL,p_badge_no));

htp.nl;

htp.nl;

open c_gur02 (p_structure, p_badge_no);

tmp_cnt := 0;

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

htp.bold(\'Can access the following profiles.\');

htp.nl;

htp.em(\'Note: Names are listed in alphabetical order.\');

\--htp.hr;

while 1=1 loop

fetch c_gur02 into l_node_id;

if c_gur02%NOTFOUND then

close c_gur02;

exit;

end if;

htp.hr;

tmp_cnt := tmp_cnt + 1;

\--

\-- start a list for this group

if tmp_cnt = 1 then

htp.ulistOpen;

end if;

\-- traverse_list2 (p_structure,

\--htp.listHeader(get_user_info(l_node_id));

get_role_members(p_structure, l_node_id);

traverse_list(p_structure,l_node_id,p_order,0);

end loop;

if tmp_cnt \> 0 then

htp.ulistClose;

else

raise NO_DATA_FOUND;

end if;

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

htp.anchor(pkg_name\|\|\'.login\',\'Return to Query Page\');

libs.epilog;

\-\--

exception

when NO_DATA_FOUND then

htp.hr;

htp.nl;

htp.bold(\'Can only access own profile.\');

htp.nl;

when exit_now then

null;

when others then

htp.nl;

htp.print(to_char(SQLCODE)\|\|\' \'\|\| SQLERRM);

libs.epilog;

end;

end;

\--

begin

\-- prolog_done := false;

null;

end;

/

CREATE OR REPLACE PACKAGE GEN0002

IS

pkg_name varchar2(255) := \'gen0002\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

fancy_background boolean := false;

override_authentication boolean := false;

type FormImageVar is record

( x varchar2(20),

y varchar2(20));

\--

procedure start_page(i_pid in varchar2 default \'NEW\');

procedure request_list (p_names in varchar2 default \'1\',

i_pid in varchar2);

procedure add_page(action in varchar2,

p_username in varchar2,

p_from_role in varchar2 default null,

p_to_role in varchar2 default null,

i_pid in varchar2);

procedure add_role(i_pid in varchar2);

procedure role_added(new_role in varchar2,

in_role in varchar2,

description in varchar2,

division in varchar2,

group_c in varchar2,

i_pid in varchar2);

END GEN0002;

/

CREATE OR REPLACE PACKAGE BODY gen0002 IS

prolog_done boolean;

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

RECORD_SET_SIZE constant number(4) := 10;

SLIDER_WIDTH constant number(4) := 10;

MAX_ROWS constant number(4) := 500;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|

\') returned\');

\--

function check_pid(ipid in number default NULL) return number is

\--

begin

if ipid is NULL or ipid = 0 then

return(9999);

else

return(ipid + 1);

end if;

end;

\--

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

\-- Modification History

\--

\-- Date Initials Remarks

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- 7 - MAR - 1997 fml Initial Coding

\--

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'GEN0002\';

result := chmlog0001.is_valid_pid(i_pid,p_app_name);

return result;

end;

end;

\--

procedure start_page(i_pid in varchar2 default \'NEW\') is

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT is_valid_pid (i_pid) then

chmlog0001.login(\'GEN0002\',\'\',i_pid);

return;

end if;

request_list(\'1\',i_pid);

end;

\--

function get_user_info (p_username in varchar2,

p_badge_no in varchar2 default null)

return varchar2 is

begin

declare

cursor c_gut(p_username in varchar2) is

select \* from chm_user_table

where username = p_username;

r_gut chm_user_table%ROWTYPE;

\--

cursor c_apv (p_badge_no in varchar2) is

select \* from chm_badge_info

where badge_no = p_badge_no;

r_apv chm_badge_info%ROWTYPE;

begin

if p_username is null then

open c_apv(p_badge_no);

fetch c_apv into r_apv;

if c_apv%NOTFOUND then

close c_apv;

return(NULL);

else

close c_apv;

return(r_apv.name\|\|\' \'\|\|

r_apv.aps_level\|\|\'-\'\|\|r_apv.aps_group);

end if;

else

open c_gut(p_username);

fetch c_gut into r_gut;

if c_gut%NOTFOUND then

close c_gut;

return NULL;

end if;

close c_gut;

open c_apv(r_gut.badge_no);

fetch c_apv into r_apv;

if c_apv%NOTFOUND then

close c_apv;

return(NULL);

else

close c_apv;

return(r_apv.name\|\|\' \'\|\|

r_apv.aps_level\|\|\'-\'\|\|r_apv.aps_group);

end if;

end if;

end;

end;

procedure get_role_members (p_structure in varchar2,

p_role_id in varchar2) is

begin

declare

cursor c_gur (p_structure in varchar2, p_role_id in varchar2) is

select a.\*

from chm_badge_info b, chm_user_table c, chm_user_roles a

where b.badge_no = c.badge_no

and c.username = a.username

and a.structure_code = upper(p_structure)

and a.granted_role = upper(p_role_id)

order by b.name;

r_gur chm_user_roles%ROWTYPE;

l_count number := 0;

begin

open c_gur(p_structure, p_role_id);

while 1=1 loop

fetch c_gur into r_gur;

if c_gur%NOTFOUND then

close c_gur;

exit;

else

if l_count = 0 then

\--htp.bold(\'\[\');

null;

end if;

l_count := l_count + 1;

htp.nl;

htp.bold(get_user_info(r_gur.username));

end if;

end loop;

if l_count \> 0 then

\-- htp.bold(\'\]\');

null;

end if;

end;

end;

\--

procedure traverse_list (p_structure in varchar2,

p_parent_id in varchar2,

p_order in out number,

p_level in number,

p_names in varchar2,

i_pid in varchar2) is

begin

declare

cursor c_badge (p_username in varchar2) is

select badge_no

from chm_badge_info

where username = p_username;

cursor c_name (p_username in varchar2) is

select name

from chm_badge_info

where username = p_username;

j_query varchar2(2000);

j_cursor integer;

j_void integer;

j_rows_fetched integer := 0;

l_node_id varchar2(50);

l_count number;

l_level number;

r_badge varchar2(5);

r_name varchar(25);

begin

if is_valid_pid(i_pid) then

l_level := p_level + 1;

\-- sort by name ascending

j_query := \' select z.node \'\|\|

\' from chm_role_table a, \'\|\|

\' (select a.name, b.username \'\|\|

\' from chm_badge_info a, \'\|\|

\' chm_user_table b \'\|\|

\' where a.badge_no = b.badge_no) ab , \'\|\|

\' chm_role_scope z \'\|\|

\' where z.node = a.role_id(+) \'\|\|

\' and z.node = ab.username(+) \'\|\|

\' and z.structure_code = upper(
\'\|\|\'\'\'\'\|\|p_structure\|\|\'\'\'\'\|\|\')\'\|\|

\' and z.linked_to_node = upper(
\'\|\|\'\'\'\'\|\|p_parent_id\|\|\'\'\'\'\|\|\')\'\|\|

\' and z.inactive is null \'\|\|

\'order by
decode(a.role_id,null,\'\|\|\'\'\'\'\|\|\'\~\'\|\|\'\'\'\'\|\|\',a.role_id),
ab.name\';

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor, j_query, dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,l_node_id,50);

j_void := dbms_sql.execute(j_cursor);

l_count := 0;

while 1=1 loop

j_rows_fetched := dbms_sql.fetch_rows(j_cursor);

if j_rows_fetched \<= 0 then

dbms_sql.close_cursor(j_cursor);

exit;

else

dbms_sql.column_value(j_cursor,1,l_node_id);

l_count := l_count + 1;

if l_node_id like \'%\_TMS\' then

htp.p(\'dbAdd( true , \"\' \|\| l_node_id \|\| \'\",\"\",\' \|\|
to_char(l_level) \|\| \',\"\",0)\');

else

if p_names = \'1\' then

open c_name(l_node_id);

fetch c_name into r_name;

close c_name;

open c_badge(l_node_id);

fetch c_badge into r_badge;

close c_badge;

htp.p(\'dbAdd( false , \"\' \|\| initcap(r_name) \|\|
\'\",\"http://www.aps.anl.gov/aps/APS_Directory/htmls/\' \|\| r_badge
\|\|\'.html\",\' \|\| to_char(l_level) \|\| \',\"\",0)\');

end if;

end if;

p_order := p_order + 1;

traverse_list(p_structure,l_node_id,p_order,l_level,p_names,i_pid);

end if;

end loop;

end if;

end;

end;

\--

function login_ok (i_user in varchar2,i_pass in varchar2) return BOOLEAN
is

begin

declare

result varchar2(1);

cursor c_login (p_user in varchar2,p_pass in varchar2) is

select \'1\'

from chm_user_table

where username = p_user

and breaker = p_pass;

begin

open c_login (i_user,i_pass);

fetch c_login into result;

if not c_login%NOTFOUND then

return(TRUE);

else

return(FALSE);

end if;

close c_login;

end;

end;

\--

\--

procedure request_list (p_names in varchar2 default \'1\',

i_pid in varchar2) is

begin

declare

p_structure varchar2(5) := \'TMS\';

p_badge_no varchar2(6) := \'37267\';

cursor c_root is

select distinct (linked_to_node)

from chm_role_scope

where linked_to_node

not in (select node

from chm_role_scope)

and structure_code=\'TMS\';

r_root varchar2(50);

\--

cursor c_linked_to_root(r_root in varchar2) is

select username

from chm_user_roles

where granted_role = r_root;

r_linked_to_root varchar2(50);

\--

cursor c_root_names(r_linked_to_root in varchar2) is

select name

from chm_badge_info

where badge_no = r_linked_to_root;

r_root_names varchar2(25);

\--

cursor c_gst (p_structure in varchar2) is

select \* from chm_structure_table where structure_code = p_structure;

r_gst chm_structure_table%ROWTYPE;

\--

cursor c_gut (p_badge_no in varchar2 ) is

select \* from chm_user_table

where badge_no = p_badge_no;

r_gut chm_user_table%ROWTYPE;

\--

cursor c_gur02 (p_structure in varchar2, p_badge_no in varchar2) is

select a.granted_role

from chm_user_table b,

chm_user_roles a

where a.structure_code = upper(p_structure)

and b.username = a.username

and b.badge_no = upper(p_badge_no);

r_gur chm_user_roles%ROWTYPE;

\--

cursor c_roles is

select role_id

from chm_role_table

where role_id like \'%\_TMS\'

order by role_id;

r_roles varchar2(50);

\--

cursor c_names is

select name,username

from chm_badge_info

where inactive is null

and username is not null

order by name;

r_names varchar2(25);

\--

l_node_id varchar2(50);

tmp_cnt number;

p_order number;

exit_now exception;

begin

if is_valid_pid(i_pid) then

\-- get root role

open c_root;

fetch c_root into r_root;

close c_root;

\-- get structure description

open c_gst(p_structure);

fetch c_gst into r_gst;

close c_gst;

\-\--

open c_gut(p_badge_no);

fetch c_gut into r_gut;

if p_badge_no is null or c_gut%NOTFOUND then

close c_gut;

htp.print(\'\<html\>\<head\>\');

htp.print(

\'\<meta http-equiv=\"refresh\" content=\"0;URL=\'\|\|

pkg_name\|\|\'.login?login_message=\'\|\|

\'Please+enter+a+valid+badge+number.\'\|\|\'\"\');

htp.print(\'\</head\>\</html\>\');

raise EXIT_NOW;

end if;

close c_gut;

htp.p(\'\<html\>\<head\>

\<title\>APS Traing Management System\</title\>

\<script LANGUAGE=\"JavaScript\"\>

\<!\--

var total=1;

var db = new Array();

dbAdd( true , \"\' \|\| r_root \|\| \'\",\"\",0,\"\",0)\');

open c_gur02 (p_structure, p_badge_no);

tmp_cnt := 0;

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

while 1=1 loop

fetch c_gur02 into l_node_id;

if c_gur02%NOTFOUND then

close c_gur02;

exit;

end if;

tmp_cnt := tmp_cnt + 1;

traverse_list(p_structure,l_node_id,p_order,0,p_names,i_pid);

end loop;

if p_names = \'1\' then

for r_linked_to_root in c_linked_to_root(r_root)

loop

open c_root_names(r_linked_to_root.username);

fetch c_root_names into r_root_names;

htp.p(\'dbAdd( false , \"\' \|\| initcap(r_root_names) \|\|
\'\",\"http://www.aps.anl.gov/aps/APS_Directory/htmls/\' \|\|
r_linked_to_root.username \|\|\'.html\",1,\"\",0)\');

close c_root_names;

end loop;

end if;

htp.p(\'

// Get current cookie setting

var current=getCurrState()

function getCurrState() {

var label = \"currState=\"

var labelLen = label.length

var cLen = document.cookie.length

var i = 0

while (i \< cLen) {

var j = i + labelLen

if (document.cookie.substring(i,j) == label) {

var cEnd = document.cookie.indexOf(\";\",j)

if (cEnd == -1) { cEnd = document.cookie.length }

return unescape(document.cookie.substring(j,cEnd))

}

i++

}

return \"\"

}

// Add an entry to the database

function dbAdd(mother,display,URL,indent,top,newitem) {

db\[total\] = new Object;

db\[total\].mother = mother

db\[total\].display = display

db\[total\].URL = URL

db\[total\].indent = indent

db\[total\].top = top

db\[total\].newitem = newitem

total++

}

// Record current settings in cookie

function setCurrState(setting) {

var expire = new Date();

expire.setTime(expire.getTime() + ( 7\*24\*60\*60\*1000 ) ); // expire
in 1 week

document.cookie = \"currState=\" + escape(setting) + \"; expires=\" +
expire.toGMTString();

}

// toggles an outline mother entry, storing new value in the cookie

function toggle(n) {

if (n != 0) {

var newString = \"\"

var expanded = current.substring(n-1,n) // of clicked item

newString += current.substring(0,n-1)

newString += expanded \^ 1 // Bitwise XOR clicked item

newString += current.substring(n,current.length)

setCurrState(newString) // write new state back to cookie

}

}

// returns padded spaces (in mulTIPles of 2) for indenting

function pad(n) {

var result = \"\"

for (var i = 1; i \<= n; i++) { result += \"&nbsp;&nbsp;&nbsp;&nbsp;\" }

return result

}

// Expand everything

function explode() {

current = \"\";

initState=\"\";

for (var i = 1; i \< db.length; i++) {

initState += \"1\"

current += \"1\"

}

setCurrState(initState);

history.go(0);

}

// Collapse everything

function contract() {

current = \"\";

initState=\"\";

for (var i = 1; i \< db.length; i++) {

initState += \"0\"

current += \"0\"

}

setCurrState(initState);

history.go(0);

}

function tree_close() {

window.parent.location = window.parent.content.location;

}

//\--\>\</script\>\</head\>\<body\>

\<table width=100% cellspacing=0 cellpadding=3 border=0\>

\<tr\>

\<td align=left bgcolor=\"#006666\" width=100%\>\<font color=\"#fffffe\"
face=\"arial\"\>\<b\>Training Management System\</b\>\</font\>\</td\>

\<td align=right bgcolor=\"#006666\"\>\<a
href=\"javascript:contract();\"\>\<IMG
SRC=\"../../gen-img/minimize.gif\" WIDTH=16 HEIGHT=14
BORDER=0\>\</a\>\<a href=\"javascript:explode();\"\>\<IMG
SRC=\"../../gen-img/maximize.gif\" WIDTH=16 HEIGHT=14 BORDER=0
\>\</a\>\</td\>

\</tr\>

\</table\>\');

htp.p(\'\<table align=\"right\"\>\');

htp.formOpen(pkg_name\|\|\'.add_page\');

htp.formHidden(\'action\',\'move\');

htp.p(\'\<tr\>

\<td align=\"right\"\>

\<b\>Move: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_username\');

htp.formSelectOption(\'Select Name\',\'TRUE\');

for r_names in c_names

loop

htp.formSelectOption(initcap(r_names.name),\'\',\'value=\' \|\|
r_names.username);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>From: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_from_role\');

htp.formSelectOption(\'Select Role\',\'TRUE\');

for r_roles in c_roles

loop

htp.formSelectOption(r_roles.role_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>To: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_to_role\');

htp.formSelectOption(\'Select Role\',\'TRUE\');

htp.formHidden(\'i_pid\',i_pid);

for r_roles in c_roles

loop

htp.formSelectOption(r_roles.role_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td colspan=\"2\" align=\"center\"\>\');

htp.formSubmit(\'\',\'Move\');

htp.p(\'\<hr\>\</td\>\</tr\>

\</form\>

\<tr\>\');

htp.formOpen(pkg_name\|\|\'.add_page\');

htp.formHidden(\'action\',\'add\');

htp.formHidden(\'p_from_role\',\'\');

htp.formHidden(\'i_pid\',i_pid);

htp.p(\'\<td align=\"right\"\>

\<b\>Add: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_username\');

htp.formSelectOption(\'Select Name\',\'TRUE\');

for r_names in c_names

loop

htp.formSelectOption(initcap(r_names.name),\'\',\'value=\' \|\|
r_names.username);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>To: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_to_role\');

htp.formSelectOption(\'Select Role\',\'TRUE\');

for r_roles in c_roles

loop

htp.formSelectOption(r_roles.role_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td colspan=\"2\" align=\"center\"\>\');

htp.formSubmit(\'\',\'Add\');

htp.p(\'\<hr\>\</td\>

\</form\>

\</tr\>

\<tr\>\');

htp.formOpen(pkg_name\|\|\'.add_page\');

htp.formHidden(\'action\',\'remove\');

htp.formHidden(\'p_to_role\',\'\');

htp.formHidden(\'i_pid\',i_pid);

htp.p(\'\<td align=\"right\"\>

\<b\>Remove: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_username\');

htp.formSelectOption(\'Select Name\',\'TRUE\');

for r_names in c_names

loop

htp.formSelectOption(initcap(r_names.name),\'\',\'value=\' \|\|
r_names.username);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>From: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'p_from_role\');

htp.formSelectOption(\'Select Role\',\'TRUE\');

for r_roles in c_roles

loop

htp.formSelectOption(r_roles.role_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td colspan=\"2\" align=\"center\"\>\');

htp.formSubmit(\'\',\'Remove\');

htp.p(\'\<hr\>\</td\>

\</form\>

\</tr\>

\<tr\>\<td colspan=\"2\" align=\"center\"\>\');

htp.formOpen(pkg_name\|\|\'.add_role\');

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit(\'\',\'Add role\');

htp.hr;

htp.formClose;

htp.p(\'\</td\>\</tr\>

\</table\>

\<script\>

\<!\--

// Set the initial state if no current state or length changed

if (current == \"\" \|\| current.length != (db.length-1)) {

current = \"\"

initState = \"\"

for (i = 1; i \< db.length; i++) {

initState += \"0\"

current += \"0\"

}

setCurrState(initState)

}

var prevIndentDisplayed = 0

var showMyDaughter = 0

// end \--\>

\<!\--

var Outline=\"\"

// cycle through each entry in the outline array

for (var i = 1; i \< db.length; i++) {

var currIndent = db\[i\].indent // get the indent level

var expanded = current.substring(i-1,i) // current state

var top = db\[i\].top

if (top == \"\") { top=\"content\" }

// display entry only if it meets one of three criteria

if ((currIndent == 0 \|\| currIndent \<= prevIndentDisplayed \|\|
(showMyDaughter == 1 && (currIndent - prevIndentDisplayed == 1)))) {

Outline += pad(currIndent)

// Insert the appropriate GIF and HREF

newitem = \"\";

if (db\[i\].newitem) { newitem=\"\_new\"; }

if (!(db\[i\].mother)) {

Outline += \"\<IMG SRC=\\\"../../gen-img/document\" + newitem +
\".gif\\\" WIDTH=16 HEIGHT=16 BORDER=0\>\<IMG
SRC=\\\"../../gen-img/blank.gif\\\" WIDTH=16 HEIGHT=16 BORDER=0\>\"

}

else {

if (current.substring(i-1,i) == 1) {

Outline += \"\<A HREF=\\\"javascript:history.go(0)\\\"
onMouseOver=\\\"window.parent.status=\\\'\'Click to
collapse\\\'\';return true;\\\" onClick=\\\"toggle(\" + i + \")\\\"\>\"

Outline += \"\<IMG SRC=\\\"../../gen-img/minus.gif\\\" WIDTH=16
HEIGHT=16 BORDER=0\>\<IMG SRC=\\\"../../gen-img/open\" + newitem +
\".gif\\\" WIDTH=16 HEIGHT=16 BORDER=0\>\"

Outline += \"\</A\>\"

}

else {

Outline += \"\<A HREF=\\\"javascript:history.go(0)\\\"
onMouseOver=\\\"window.parent.status=\\\'\'Click to expand\\\'\';return
true;\\\" onClick=\\\"toggle(\" + i + \")\\\"\>\"

Outline += \"\<IMG SRC=\\\"../../gen-img/plus.gif\\\" WIDTH=16 HEIGHT=16
BORDER=0\>\<IMG SRC=\\\"../../gen-img/closed\" + newitem + \".gif\\\"
WIDTH=16 HEIGHT=16 BORDER=0\>\"

Outline += \"\</A\>\"

}

}

Outline += \"&nbsp;\";

if (db\[i\].URL == \"\" \|\| db\[i\].URL == null) {

Outline += \" \" + db\[i\].display // no link, just a listed item

}

else {

Outline += \" \<A HREF=\\\"\" + db\[i\].URL + \"\\\" TARGET=\\\"\" +
top + \"\\\"\>\" + db\[i\].display + \"\</A\>\"

}

// Bold if parent

if (db\[i\].mother) {

Outline = \"\<B\>\" + Outline + \"\</B\>\"

}

Outline += \"\<BR\>\"

prevIndentDisplayed = currIndent

showMyDaughter = expanded

// if (i == 1) { Outline = \"\"}

if (db.length \> 25) {

document.write(Outline)

Outline = \"\"

}

}

}

document.write(Outline)

// end \--\>

\</script\>\');

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

if tmp_cnt = 0 then

raise NO_DATA_FOUND;

end if;

htp.formOpen(pkg_name\|\|\'.request_list\');

htp.formHidden(\'i_pid\',i_pid);

if p_names = \'1\' then

htp.formHidden(\'p_names\',\'0\');

htp.formSubmit(\'\',\'View Roles Only\');

end if;

if p_names = \'0\' then

htp.formHidden(\'p_names\',\'1\');

htp.formSubmit(\'\',\'View Roles and People\');

end if;

htp.formClose;

libs.epilog;

end if;

\-\--

exception

when NO_DATA_FOUND then

htp.hr;

htp.nl;

htp.bold(\'Can only access own profile.\');

htp.nl;

when exit_now then

null;

when others then

htp.nl;

htp.print(to_char(SQLCODE)\|\|\' \'\|\| SQLERRM);

libs.epilog;

end;

end;

\--

function role_exists (p_username varchar2, p_to_role varchar2) return
varchar2 is

begin

declare

cursor c_role_exists(p_username varchar2, p_to_role varchar2) is

select inactive

from chm_role_scope

where node = p_username

and linked_to_node = p_to_role;

r_role_exists varchar2(15);

begin

open c_role_exists(p_username,p_to_role);

fetch c_role_exists into r_role_exists;

if c_role_exists%NOTFOUND then

close c_role_exists;

return(\'1\');

else

close c_role_exists;

return(r_role_exists);

end if;

end;

end;

\--

procedure add_page(action in varchar2,

p_username in varchar2,

p_from_role in varchar2 default null,

p_to_role in varchar2 default null,

i_pid in varchar2) is

begin

declare

cursor c_role_check(p_username varchar2, p_from_role varchar2) is

select inactive

from chm_role_scope

where node = p_username

and linked_to_node = p_from_role;

r_role_check varchar2(15);

begin

if is_valid_pid(i_pid) then

if action = \'add\' then

if role_exists(p_username,p_to_role)=\'1\' then

insert into chm_role_scope

(structure_code,node,linked_to_node)

values (\'TMS\',p_username,p_to_role);

htp.p(\'\<html\>\<body\>\');

htp.p(p_username \|\| \' successfully added to \' \|\| p_to_role \|\|
\'.\');

else

if role_exists(p_username,p_to_role)=\'Y\' then

update chm_role_scope

set inactive = \'\'

where node = p_username and

linked_to_node = p_to_role;

htp.p(\'\<html\>\<body\>\');

htp.p(p_username \|\| \' successfully added to \' \|\| p_to_role \|\|
\'.\');

else

if role_exists(p_username,p_to_role) is null then

htp.p(\'\<html\>\<body\>\');

htp.p(\'Add could not be performed.\<br\>\');

htp.p(p_username \|\| \' already exists in \' \|\| p_to_role \|\|
\'.\');

end if;

end if;

end if;

else

open c_role_check(p_username,p_from_role);

fetch c_role_check into r_role_check;

if c_role_check%NOTFOUND or r_role_check=\'Y\' then

close c_role_check;

htp.p(\'\<html\>\<body\>\');

htp.p(initcap(action) \|\| \' could not be performed.\<br\>\');

htp.p(p_username \|\| \' does not exist in \' \|\| p_from_role \|\|
\'.\');

else

close c_role_check;

if action = \'move\' then

if role_exists(p_username,p_to_role)=\'1\' then

insert into chm_role_scope

(structure_code,node,linked_to_node)

values (\'TMS\',p_username,p_to_role);

update chm_role_scope

set inactive = \'Y\'

where node = p_username and

linked_to_node = p_from_role;

htp.p(\'\<html\>\<body\>\');

htp.p(p_username \|\| \' successfully moved from \' \|\| p_from_role
\|\| \' to \' \|\| p_to_role \|\| \'.\');

else

if role_exists(p_username,p_to_role)=\'Y\' then

update chm_role_scope

set inactive = \'\'

where node = p_username and

linked_to_node = p_to_role;

update chm_role_scope

set inactive = \'Y\'

where node = p_username and

linked_to_node = p_from_role;

htp.p(\'\<html\>\<body\>\');

htp.p(p_username \|\| \' successfully moved from \' \|\| p_from_role
\|\| \' to \' \|\| p_to_role \|\| \'.\');

else

if role_exists(p_username,p_to_role) is null then

htp.p(\'\<html\>\<body\>\');

htp.p(\'Move could not be performed.\<br\>\');

htp.p(p_username \|\| \' already exists in \' \|\| p_from_role \|\|
\'.\');

end if;

end if;

end if;

end if;

if action = \'remove\' then

update chm_role_scope

set inactive = \'Y\'

where node = p_username and

linked_to_node = p_from_role;

htp.p(\'\<html\>\<body\>\');

htp.p(p_username \|\| \' successfully removed from \' \|\| p_from_role
\|\| \'.\');

end if;

end if;

end if;

htp.p(\'\<br\>Back to \<a href=\"\' \|\| pkg_name \|\|
\'.request_list\"\>TMS\</a\>.

\</body\>\</html\>\');

end if;

end;

end;

\--

procedure add_role(i_pid in varchar2) is

begin

declare

cursor c_roles is

select role_id

from chm_role_table

where role_id like \'%\_TMS\'

order by role_id;

r_roles varchar2(50);

begin

if is_valid_pid(i_pid) then

htp.p(\'\<html\>\<head\>

\<title\>Add Role\</title\>

\</head\>

\<body bgcolor=\"#FFFFFF\"\>

\<table border=\"0\"\>\');

htp.formOpen(pkg_name \|\| \'.role_added\');

htp.formHidden(\'i_pid\',i_pid);

htp.p(\'\<tr\>\<td align=\"right\"\>

\<b\>Add role: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formText(\'new_role\',25,50);

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>In role: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formSelectOpen(\'in_role\');

htp.formSelectOption(\'Select Role\',\'TRUE\');

for r_roles in c_roles

loop

htp.formSelectOption(r_roles.role_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>Description: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formText(\'description\',25,255);

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>Division: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formText(\'division\',6,5);

htp.p(\'\</td\>\</tr\>\<tr\>\<td align=\"right\"\>

\<b\>Group Code: \</b\>

\</td\>\<td align=\"left\"\>\');

htp.formText(\'group_c\',10,9);

htp.p(\'\</td\>\</tr\>\<tr\>\<td colspan=\"2\" align=\"center\"\>\');

htp.formSubmit(\'\',\'Add\');

htp.p(\'\</td\>\</tr\>

\</form\>\</table\>

\</body\>\</html\>\');

end if;

end;

end;

\--

procedure role_added(new_role in varchar2,

in_role in varchar2,

description in varchar2,

division in varchar2,

group_c in varchar2,

i_pid in varchar2) is

begin

declare

cursor c_role_exists(p_role_id in varchar2) is

select division from chm_role_table

where role_id = p_role_id;

r_role varchar2(50);

p_role varchar2(50);

begin

if is_valid_pid(i_pid) then

if new_role not like \'%\_TMS\' then

p_role := new_role \|\| \'\_TMS\';

else

p_role := new_role;

end if;

open c_role_exists(p_role);

fetch c_role_exists into r_role;

if c_role_exists%NOTFOUND then

close c_role_exists;

insert into chm_role_table

(role_id,description,division,group_code)

values(p_role,description,division,group_c);

insert into chm_role_scope

(structure_code,node,linked_to_node)

values (\'TMS\',p_role,in_role);

htp.p(\'\<html\>\<body\>\');

htp.p(p_role \|\| \' successfully added to \' \|\| in_role \|\| \'.\');

else

close c_role_exists;

htp.p(\'\<html\>\<body\>\');

htp.p(p_role \|\| \' could not be added to \' \|\| in_role \|\| \'.\');

end if;

htp.p(\'\<br\>Back to \<a href=\"\' \|\| pkg_name \|\|
\'.request_list\"\>TMS\</a\>.

\</body\>\</html\>\');

end if;

end;

end;

\--

begin

\--prolog_done := false;

null;

end;

/

CREATE OR REPLACE PACKAGE gen0003 IS

service_name varchar2(255) := \'tms0001\';

pkg_name varchar2(255) := \'gen0003\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

\--

\--

prod_user varchar2(255) := \'WEBPROD:\';

dev_user varchar2(255) := \':WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|service_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|service_name\|\|\'w/owa/\';

pkg_syn varchar2(255) := pkg_name; \--\|\|\'s\';

ping varchar2(255) := pkg_name\|\|\' is alive\';

\--

fancy_background boolean := false;

override_authentication boolean := false;

type FormImageVar is record

( x varchar2(20),

y varchar2(20));

\--TYPE PIDIndex is TABLE OF Number

\-- INDEX BY BINARY_INTEGER;

\--TYPE AppIndex is Table of varchar2(50)

\-- INDEX BY BINARY_INTEGER;

TYPE ValuesIndex is Table of varchar2(50)

INDEX BY BINARY_INTEGER;

\--PID_tab PIDIndex;

\--App_tab AppIndex;

Val_tab ValuesIndex;

TabRows Number;

\--

cursor c_badge (p_username in varchar2) is

select badge_no

from gen_user_table

where username=p_username;

gen_badge varchar2(10);

function login_ok (i_user in varchar2,i_pass in varchar2) return
BOOLEAN;

\--

procedure request_list (i_operation in varchar2 default NULL,

p_structure in varchar2,

p_badge_no in varchar2,i_pid in varchar2 default null);

END;

/

CREATE OR REPLACE PACKAGE BODY gen0003 IS

prolog_done boolean;

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

RECORD_SET_SIZE constant number(4) := 10;

SLIDER_WIDTH constant number(4) := 10;

MAX_ROWS constant number(4) := 500;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|

\') returned\');

\--

\--

\--

\--

function check_pid(ipid in number default NULL) return number is

\--

begin

if ipid is NULL or ipid = 0 then

return(9999);

else

return(ipid + 1);

end if;

end;

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

\-- Modification History

\--

\-- Date Initials Remarks

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- 10-JUL-96 kem Initial Coding

\-- 22-JUL-96 kem Add code to search by designer or engineer

\-- Add designer to group header

procedure login is

begin

declare

p_username varchar2(50);

p_structure varchar2(50);

begin

lib.prolog(\'APS Application Role Scope Query\');

htp.formOpen(get_service\|\|pkg_syn\|\|\'.request_list\');

\--

htp.para;

htp.NL;

htp.bold(\'Structure: \' \|\| htf.formText(\'p_structure\',

25,255,p_structure));

htp.NL;

htp.bold(\'Username: \' \|\| htf.formText(\'p_username\',

25,255,p_username));

htp.NL;

/\*

htp.formSelectOpen(\'subproject_name\', htf.bold(\'Sub Project: \'));

htp.formSelectOption(\'ALL\');

open subproject;

while 1=1 loop

fetch subproject into subproject_name;

if subproject%NOTFOUND then

exit;

end if;

htp.formSelectOption(subproject_name);

end loop;

close subproject;

htp.formSelectClose;

htp.nl;

\*/

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_TOTAL_ROWS\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.NL;

htp.NL;

htp.formSubmit;

htp.formReset;

htp.formClose;

lib.epilog;

end;

end;

function get_badge(p_username in varchar2) return VARCHAR2 is

begin

gen_badge := \'00000\';

open c_badge(p_username);

fetch c_badge into gen_badge;

close c_badge;

return gen_badge;

end;

function login_ok (i_user in varchar2,i_pass in varchar2) return BOOLEAN
is

begin

declare

result varchar2(1);

cursor c_login (p_user in varchar2,p_pass in varchar2) is

select \'1\'

from gen_user_table

where username = p_user

and breaker = p_pass;

begin

\--htp.print (\'user = \' \|\| i_user \|\| \' pass = \' \|\| i_pass);

open c_login (i_user,i_pass);

fetch c_login into result;

if not c_login%NOTFOUND then

return(TRUE);

else

return(FALSE);

end if;

close c_login;

end;

end;

function get_user_info (p_username in varchar2) return varchar2 is

begin

declare

cursor c_gut(p_username in varchar2) is

select \* from gen_user_table

where username = p_username;

r_gut gen_user_table%ROWTYPE;

\--

cursor c_apv (p_badge_no in varchar2) is

select \* from all_personnel_view

where badge_no = p_badge_no;

r_apv all_personnel_view%ROWTYPE;

begin

open c_gut(p_username);

fetch c_gut into r_gut;

if c_gut%NOTFOUND then

close c_gut;

return NULL;

end if;

close c_gut;

open c_apv(r_gut.badge_no);

fetch c_apv into r_apv;

if c_apv%NOTFOUND then

close c_apv;

return(NULL);

else

close c_apv;

\-- return(r_apv.badge_no\|\|\' \'\|\|

\-- r_apv.name\|\|\' \'\|\|

\-- r_apv.grp);

return(r_apv.name\|\|\' \'\|\|

r_apv.grp);

end if;

end;

end;

procedure get_role_members (p_structure in varchar2,p_role_id in
varchar2,p_badge_no in varchar2) is

begin

declare

cursor c_gur (p_structure in varchar2, p_role_id in varchar2) is

select a.\*

from all_personnel_view b, gen_user_table c, gen_user_roles a

where b.badge_no = c.badge_no

and c.username = a.username

and a.structure_code = upper(p_structure)

and a.granted_role = upper(p_role_id)

order by b.name;

\-- select \* from gen_user_roles

\-- where structure_code = upper(p_structure)

\-- and granted_role = upper(p_role_id);

r_gur gen_user_roles%ROWTYPE;

l_count number := 0;

temp_badge varchar2(10);

begin

open c_gur(p_structure, p_role_id);

while 1=1 loop

fetch c_gur into r_gur;

if c_gur%NOTFOUND then

close c_gur;

exit;

else

if l_count = 0 then

\--htp.bold(\'\[\');

null;

end if;

l_count := l_count + 1;

\-- htp.print(htf.bold(\'\[\')\|\|r_gur.username\|\|\' \'\|\|

\-- get_user_info(r_gur.username)\|\|htf.bold(\'\]\'));

\-- htp.print(get_user_info(r_gur.username));

\-- htp.nl;

\-- htp.bold(get_user_info(r_gur.username));

temp_badge := get_badge(r_gur.username);

insert into ows_tms_priv

values(p_badge_no,temp_badge,r_gur.username);

end if;

end loop;

if l_count \> 0 then

\-- htp.bold(\'\]\');

null;

end if;

end;

end;

procedure read_plsql_table is

begin

declare

i BINARY_INTEGER;

j BINARY_INTEGER;

k BINARY_INTEGER;

tempi varchar2(50);

tempj varchar2(50);

temp varchar2(50);

begin

for i in 1..TabRows LOOP

\--htp.print(to_char(i) \|\| \' \' \|\| val_tab(i));

htp.NL;

END LOOP;

\--sort table

\<\<A\>\>

for i in 1..(TabRows - 1) LOOP

tempi := substr(val_tab(i),7,50);

\<\<B\>\>

for j in (1 + 1)..TabRows LOOP

tempj := substr(val_tab(j),7,50);

if (tempi \>= tempj) then

temp := val_tab(i);

val_tab(i) := val_tab(j);

val_tab(j) := temp;

end if;

END LOOP B;

END LOOP A;

htp.NL;

\--htp.print(\'Sorted\');

for i in 1..TabRows LOOP

\--htp.print(to_char(i) \|\| \' \' \|\| val_tab(i));

htp.NL;

END LOOP;

end;

end;

procedure traverse_list (p_structure in varchar2,

p_parent_id in varchar2,

p_badge_no in varchar2) is

begin

declare

cursor c_grs (p_structure in varchar2,

p_root in varchar2) is

select level, node from gen_role_scope

where structure_code = p_structure

start with linked_to_node = p_root

connect by prior node = linked_to_node;

l_node_id varchar2(50);

l_level number;

temp_badge varchar2(10);

node_value varchar2(50);

begin

open c_grs(p_structure, p_parent_id);

while 1=1 loop

fetch c_grs into l_level, l_node_id;

if c_grs%NOTFOUND then

close c_grs;

exit;

end if;

\-- htp.print (lpad(l_node_id,(2\*l_level) +
length(l_node_id)+2,\'=\'));

\-- htp.print(get_user_info(l_node_id));

node_value := get_user_info(l_node_id);

if length(node_value) \> 0 then

temp_badge := get_badge(l_node_id);

insert into ows_tms_priv

values(p_badge_no,temp_badge,l_node_id);

else

get_role_members(p_structure, l_node_id,p_badge_no);

end if;

\-- htp.nl;

end loop;

end;

end;

\--

procedure request_list (i_operation in varchar2 default NULL,

p_structure in varchar2,

p_badge_no in varchar2,

i_pid in varchar2 default null) is

begin

declare

cursor c_gut (p_badge_no in varchar2 ) is

select \* from gen_user_table

where badge_no = p_badge_no;

r_gut gen_user_table%ROWTYPE;

\--

cursor c_gur02 (p_structure in varchar2, p_badge_no in varchar2) is

select a.granted_role

from gen_user_table b,

gen_user_roles a

where a.structure_code = upper(p_structure)

and b.username = a.username

and b.badge_no = upper(p_badge_no);

r_gur gen_user_roles%ROWTYPE;

l_node_id varchar2(50);

tmp_cnt number;

p_order number;

exit_now exception;

temp_badge varchar2(10);

begin

\-- lib.prolog(\'APS Application Role Scope Query Results\');

\-- htp.br;

\--htp.bold(p_structure\|\|\':\'\|\|p_badge_no);

\--htp.nl;

open c_gur02 (p_structure, p_badge_no);

tmp_cnt := 0;

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

while 1=1 loop

fetch c_gur02 into l_node_id;

if c_gur02%NOTFOUND then

close c_gur02;

exit;

end if;

\-- htp.hr;

tmp_cnt := tmp_cnt + 1;

\-- traverse_list2 (p_structure,

\-- l_node_id);

\-- htp.print (l_node_id);

\-- htp.print(get_user_info(l_node_id));

get_role_members(p_structure, l_node_id,p_badge_no);

\-- traverse_list(p_structure,l_node_id,p_order,0);

traverse_list(p_structure,l_node_id, p_badge_no);

\-- htp.nl;

end loop;

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

if tmp_cnt = 0 then

raise NO_DATA_FOUND;

end if;

\--htp.anchor(get_service\|\|pkg_syn\|\|\'.login\',\'Return to Query
Page\');

\--libs.epilog;

\-\--

exception

when NO_DATA_FOUND then

\-- htp.nl;

\-- htp.bold(\'Can only see own profile.\');

\-- htp.nl;

insert into ows_tms_priv

values (p_badge_no,p_badge_no,NULL);

when exit_now then

null;

when others then

htp.nl;

htp.print(to_char(SQLCODE)\|\|\' \'\|\| SQLERRM);

\-- libs.epilog;

end;

end;\--

begin

prolog_done := false;

end;

/

CREATE OR REPLACE PACKAGE lib IS

type val_arr is table of varchar2(2000) index by binary_integer;

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/apsweb/owa/\';

dev_service varchar2(255) := \'/misweb/owa/\';

pkg_syn varchar2(255) := \'libs\';

ping varchar2(255) := \'alive\';

fancy_background boolean := false;

override_authentication boolean := true;

type FormImageVar is record

( x varchar2(20),

y varchar2(20));

procedure prolog(c in varchar2, lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL);

\-- added 080699 mtm so that I can include my javascript

PROCEDURE prolog3(c IN VARCHAR2,

lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL);

\--added 12/8/98 kem

procedure prolog2(c in varchar2, browser_title_line in varchar2,

lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL);

\-- added 08131999 kem

procedure err_msg (err_code in varchar2, err_str in varchar2);

procedure one_row(nam in varchar2,val in varchar2);

procedure epilog(lineattr IN VARCHAR2 DEFAULT NULL,

msg in varchar2 default NULL,

footer_id in number default null,

DisplayLogout IN BOOLEAN DEFAULT NULL);

procedure no_cache;

function get_anl_people_info(ibadge_no in varchar2,

ifield in varchar2 DEFAULT NULL) return varchar2;

function get_node_info (i_ip_address in varchar2,

ifield in varchar2 DEFAULT NULL) return varchar2;

function random_int(r in number) return number;

function increment_seq (seq_name in varchar2,i_operation in varchar2
default \'NEXT\') return integer;

procedure login (i_app_name in varchar2,i_src_pkg in varchar2 default
null,

i_operation in varchar2 default null);

procedure validate_user (i_badge in varchar2,i_pass in varchar2,i_pid in
varchar2,

i_operation in varchar2 default null,i_app_name in varchar2 default
null,

i_src_pkg in varchar2 default null);

PROCEDURE eq_row(nam IN VARCHAR2,val IN VARCHAR2);

function fix_name(i_name in varchar2) return varchar2;

function dm_convert (value_in IN VARCHAR2) RETURN DATE;

pragma restrict_references(dm_convert,WNDS);

END;

/

CREATE OR REPLACE PACKAGE BODY LIB IS

prolog_done boolean;

\--values for random number generator

m constant number := 100000000;

m1 constant number := 10000;

b constant number := 31415821;

\--private utility function for random number generator

function mult (p in number, q in number) return number is

begin

declare

p1 number;

p0 number;

q1 number;

q0 number;

begin

p1 := trunc(p/m1);

p0 := mod(p,m1);

q1 := trunc (q/m1);

q0 := mod (q,m1);

return(mod((mod(p0\*q1+p1\*q0,m1)\*m1+p0\*q0),m));

end;

end;

function random_int(r in number) return number is

a number;

the_date date;

days number;

secs number;

begin

\--generate a new seed

the_date := sysdate;

days := to_number(to_char(the_date,\'J\'));

secs := to_number(to_char(the_date,\'SSSSS\'));

a := days \* 24 \* 3600 + secs;

a := mod(mult(a,b) +1,m);

return(trunc((trunc(a/m1) \* r)/ m1));

end random_int;

function get_node_info (i_ip_address in varchar2,

ifield in varchar2 DEFAULT NULL) return varchar2 is

begin

declare

cursor c_ntn (p_ip in varchar2) is

select a.\*

from nt_network a, nt_network_address b

where a.node_name = b.node_name and

to_char(ip_addr_1)\|\|\'.\'\|\|

to_char(ip_addr_2)\|\|\'.\'\|\|

to_char(ip_addr_3)\|\|\'.\'\|\|

to_char(ip_addr_4) = p_ip;

r_ntn nt_network%ROWTYPE;

l_field varchar2(50);

begin

open c_ntn(i_ip_address);

fetch c_ntn into r_ntn;

if c_ntn%NOTFOUND then

close c_ntn;

return(NULL);

end if;

close c_ntn;

l_field := upper(nvl(ifield,\'NODE_NAME\'));

if l_field = \'NODE_NAME\' then

return(r_ntn.NODE_NAME);

elsif l_field = \'LOCATION\' then

return(r_ntn.LOCATION);

elsif l_field = \'CUSTODIAN\' then

return(r_ntn.CUSTODIAN);

else

return(NULL);

end if;

end;

end;

function get_anl_people_info(ibadge_no in varchar2,

ifield in varchar2 DEFAULT NULL) return varchar2 is

begin

declare

cursor c_apv (p_badgeno in varchar2) is

select \* from all_personnel_view

where badge_no = p_badgeno;

cursor c_oapt (p_badgeno in varchar2) is

select \* from other_anl_people_table

where badge_no = p_badgeno;

r_bi all_personnel_view%ROWTYPE;

l_field varchar2(15);

begin

open c_apv(ibadge_no);

fetch c_apv into r_bi;

if c_apv%NOTFOUND then

close c_apv;

open c_oapt(ibadge_no);

fetch c_oapt into r_bi;

if c_oapt%NOTFOUND then

close c_oapt;

return(NULL);

else

close c_oapt;

end if;

else

close c_apv;

end if;

l_field := nvl(upper(ifield),\'NAME\');

if l_field = \'NAME\' then

return(r_bi.NAME);

elsif l_field = \'EXTENSION\' then

return(r_bi.EXTENSION);

elsif l_field = \'BUILDING\' then

return(r_bi.BUILDING);

elsif l_field = \'LOCATION\' then

return(r_bi.LOCATION);

elsif l_field = \'USERNAME\' then

return(r_bi.USERNAME);

elsif l_field = \'GRP\' then

return(r_bi.GRP);

elsif l_field = \'EMAIL\' then

return(r_bi.EMAIL);

else

return(NULL);

end if;

end;

end;

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

function check_pid(ipid in number default NULL) return number is

\--

begin

if ipid is NULL or ipid = 0 then

return(9999);

else

return(ipid + 1);

end if;

end;

\--

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

function increment_seq (seq_name in varchar2,i_operation in varchar2
default \'NEXT\') return integer is

\--some dormant lines were commented out to allow this function

\--to serve as an example of dbms_sql usage

begin

declare

I_QUERY varchar2(2000) := \'\';

I_WHERE varchar2(2000) := \'\';

\--I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

seq_val integer;

I_ROWS_FETCHED integer := 0;

\--I_TOTAL_ROWS integer := 0;

\--I_START number(6) := to_number(Z_START);

\--I_NEXT_BUT boolean;

\--I_PREV_BUT boolean;

j_query varchar2(2000) := \'\';

\--j_where varchar2(2000) := \'\';

j_cursor integer;

\--j_rows_fetched integer := 0;

begin

if i_operation = \'NEXT\' then

j_query := \'select \' \|\| seq_name \|\| \'.nextval from dual\';

else

j_query := \'select \' \|\| seq_name \|\| \'.currval from dual\';

end if;

\--j_where := \'\';

\--j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,seq_val);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,seq_val);

dbms_sql.close_cursor(j_cursor);

return (seq_val);

end;

exception

when others then

return -1;

end;

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

procedure no_cache is

begin

htp.p(\'\<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"\>\');

end;

\--

procedure prolog(c in varchar2, lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL) is

begin

\--if not prolog_done then

htp.htmlOpen;

htp.headOpen;

htp.title(c);

htp.base;

htp.headClose;

\--if fancy_background then

\-- htp.bodyOpen(image_dir \|\|\'chalk.jpg\',

\-- \'link=#cd0000 vlink=#483d8b alink=#ff3300\');

\--else

IF lower(bgcolorattr) = \'white\' THEN

htp.print(\'\<BODY BGCOLOR=\"#FFFFFF\"\>\');

ELSif bgcolorattr is not null then

htp.p(\'\<BODY BGCOLOR=\"\' \|\| bgcolorattr \|\| \'\"\>\');

else

htp.bodyOpen;

END IF;

\--end if;

inline(\'apslogsm.gif\');

htp.p(\'\<H1\>\'\|\|c\|\|\'\</H1\>\');

\-- taken out 9/17/96 fml

\--htp.anchor(main_menu,\'\[Main Menu\]\');

\--htp.print(\'\<H1\>\');

\--htp.bold(\'Advanced Photon Source\');

\--htp.print(\'\</H1\>\');

IF lineattr = \'noline\' THEN

htp.nl;

ELSE

htp.hr;

END IF;

\--htp.nl;

\--htp.p(\'qwury string=\' \|\| owa_util.get_cgi_env(\'REMOTE_ADDR\'));

prolog_done := true;

\--end if;

end;

\--

PROCEDURE prolog3(c IN VARCHAR2,

lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL) IS

BEGIN

\--if not prolog_done then

htp.htmlOpen;

htp.headOpen;

htp.title(c);

htp.base;

htp.p(\'\<script language=\"JavaScript\"\>\');

htp.p(\'function jsonLoad() {\');

htp.p(\' searchScreen.i_selOrderBy.length = 0;\');

htp.p(\'}//jsOnLoad\');

htp.p(\'function jsSelectAll() {\');

htp.p(\' for (j=0;j\<searchScreen.i_selOrderBy.length;j++) {//for#1\');

htp.p(\' searchScreen.i_selOrderBy\[j\].selected = true;\');

htp.p(\' }//end for\');

htp.p(\'
searchScreen.i_selItems\[searchScreen.i_selItems.length-1\].selected =
true;\');

htp.p(\' return;\');

\--searchScreen.

htp.p(\'}//jsSelectAll\');

htp.p(\'function
jsCopyListItems(oSelectList1,oSelectList2,bDupSwitch,bEmptySwitch) {\');

htp.p(\' var bDoCopy;\');

htp.p(\' var i;\');

htp.p(\' var j;\');

htp.p(\' var nCounter = 0;\');

htp.p(\' var nSelectList1Length = oSelectList1.length;\');

htp.p(\' //use the duplicates switch to control checking for
duplicates\');

htp.p(\' for (i=oSelectList1.length-1;i\>=0;i\--) {\');

\-- htp.p(\' if (oSelectList1\[i\].value != \"xoxoxoxo\") { //if#1a\');

\-- htp.p(\' continue; }\');

htp.p(\' bDoCopy = true;\');

htp.p(\' //check for duplicates if switch is set\');

htp.p(\' if (!bDupSwitch)\');

htp.p(\' for (j=0;j\<oSelectList2.length;j++)\');

htp.p(\' if (oSelectList2\[j\].value == oSelectList1\[i\].value)\');

htp.p(\' bDoCopy = false;\');

htp.p(\' //check for empty value if switch is set\');

htp.p(\' if (oSelectList1\[i\].selected && bDoCopy)\');

htp.p(\' {\');

htp.p(\' //the following line will change oSelectlist2.length!!!\');

htp.p(\' oSelectList2\[oSelectList2.length\] = new
Option(oSelectList1\[i\].text,\');

htp.p(\'
oSelectList1\[i\].value,oSelectList1\[i\].defaultSelected,false);\');

htp.p(\' //setting an item (itself) to null should remove it from the
list\');

htp.p(\' oSelectList1\[i\] = null;\');

htp.p(\' }//if item is selected & copy switch = true\');

\-- htp.p(\' }//if item is selected & copy switch = true\');

htp.p(\' }//for i\');

htp.p(\'}//jsCopyListItems\');

htp.p(\'function jsMoveListItems(oSelectList2,vInType) {\');

htp.p(\' var bDoCopy = true;\');

htp.p(\' var i;\');

htp.p(\' var j;\');

htp.p(\' var nCounter = 0;\');

htp.p(\' for (j=0;j\<oSelectList2.length;j++) {//for#1\');

htp.p(\' if (oSelectList2\[j\].selected) {//if#1\');

htp.p(\' var vValueDn = j+1;\');

htp.p(\' var vValueUp = j-1;\');

htp.p(\' if (vInType == \"UP\") {//if#2\');

htp.p(\' if (oSelectList2.selectedIndex != \"0\") {//if#3 check to see
if at first option\');

htp.p(\' //move item before selected item down one\');

htp.p(\' var newObj = new Option(oSelectList2\[j-1\].text,\');

htp.p(\'
oSelectList2\[j-1\].value,oSelectList2\[j-1\].defaultSelected,false);\');

\-- htp.p(\' oSelectList2\[oSelectList2.length\] = new
Option(oSelectList2\[j-1\].text,\');

\-- htp.p(\'
oSelectList2\[j-1\].value,oSelectList2\[j-1\].defaultSelected,false);\');

htp.p(\' //move selected item up one\');

htp.p(\' oSelectList2\[j-1\] = new Option(oSelectList2\[j\].text,\');

htp.p(\'
oSelectList2\[j\].value,oSelectList2\[j\].defaultSelected,false);\');

htp.p(\' //move item after selected item up one\');

htp.p(\' oSelectList2\[j\] = newObj;\');

htp.p(\' //select item selected to move\');

htp.p(\' oSelectList2\[vValueUp\].selected = true;\');

\-- htp.p(\' oSelectList2\[j\] = null;\');

htp.p(\' }//end if#3\');

htp.p(\' }//end if#2\');

htp.p(\' if (vInType == \"DOWN\" && bDoCopy) {//if#4\');

htp.p(\' if (oSelectList2.selectedIndex != oSelectList2.length-1)
{//if#5 check to see if at last option\');

htp.p(\' bDoCopy = false;\');

htp.p(\' //save item after selected item\');

htp.p(\' var newObj = new Option(oSelectList2\[j+1\].text,\');

htp.p(\'
oSelectList2\[j+1\].value,oSelectList2\[j+1\].defaultSelected,false);\');

htp.p(\' //move selected item down one\');

htp.p(\' oSelectList2\[j+1\] = new Option(oSelectList2\[j\].text,\');

htp.p(\'
oSelectList2\[j\].value,oSelectList2\[j\].defaultSelected,false);\');

htp.p(\' //move item after selected item up one\');

htp.p(\' oSelectList2\[j\] = newObj;\');

htp.p(\' //select item selected to move\');

htp.p(\' oSelectList2\[vValueDn\].selected = true;\');

htp.p(\' }//end if#5\');

htp.p(\' }//end if#4\');

htp.p(\' }//end if#1\');

htp.p(\' }//end for#1\');

htp.p(\'}//end jsMoveListItems\');

htp.p(\'\</script\> \');

htp.headClose;

\--if fancy_background then

\-- htp.bodyOpen(image_dir \|\|\'chalk.jpg\',

\-- \'link=#cd0000 vlink=#483d8b alink=#ff3300\');

\--else

IF (LOWER(bgcolorattr) = \'white\')

THEN

htp.print(\'\<BODY BGCOLOR=\"#FFFFFF\" onLoad=\"jsonLoad();\"\>\');

ELSIF (bgcolorattr IS NOT NULL)

THEN

htp.p(\'\<BODY BGCOLOR=\"\' \|\| bgcolorattr \|\| \'\"
onLoad=\"jsonLoad();\"\>\');

ELSE

htp.print(\'\<BODY onLoad=\"jsonLoad();\"\>\');

\-- htp.bodyOpen;

END IF;

\--end if;

inline(\'apslogsm.gif\');

htp.p(\'\<H1\>\'\|\|c\|\|\'\</H1\>\');

\-- taken out 9/17/96 fml

\--htp.anchor(main_menu,\'\[Main Menu\]\');

\--htp.print(\'\<H1\>\');

\--htp.bold(\'Advanced Photon Source\');

\--htp.print(\'\</H1\>\');

IF (lineattr = \'noline\')

THEN

htp.nl;

ELSE

htp.hr;

END IF;

\--htp.nl;

\--htp.p(\'qwury string=\' \|\| owa_util.get_cgi_env(\'REMOTE_ADDR\'));

prolog_done := TRUE;

\--end if;

END;

\--

procedure prolog2(c in varchar2, browser_title_line in varchar2,

lineattr IN VARCHAR2 DEFAULT NULL,

bgcolorattr IN VARCHAR2 DEFAULT NULL) is

begin

\--if not prolog_done then

htp.htmlOpen;

htp.headOpen;

htp.title(browser_title_line);

htp.base;

htp.headClose;

\--if fancy_background then

\-- htp.bodyOpen(image_dir \|\|\'chalk.jpg\',

\-- \'link=#cd0000 vlink=#483d8b alink=#ff3300\');

\--else

IF lower(bgcolorattr) = \'white\' THEN

htp.print(\'\<BODY BGCOLOR=\"#FFFFFF\"\>\');

ELSIF bgcolorattr is not null then

htp.p(\'\<BODY BGCOLOR=\"\' \|\| bgcolorattr \|\| \'\"\>\');

ELSE

htp.bodyOpen;

END IF;

\--end if;

inline(\'apslogsm.gif\');

htp.p(\'\<H1\>\'\|\|c\|\|\'\</H1\>\');

\-- taken out 9/17/96 fml

\--htp.anchor(main_menu,\'\[Main Menu\]\');

\--htp.print(\'\<H1\>\');

\--htp.bold(\'Advanced Photon Source\');

\--htp.print(\'\</H1\>\');

IF lineattr = \'noline\' THEN

htp.nl;

ELSE

htp.hr;

END IF;

htp.nl;

prolog_done := true;

\--end if;

end;

\--

procedure epilog(lineattr IN VARCHAR2 DEFAULT NULL,

msg in varchar2 default NULL,

footer_id in number default null,

DisplayLogout IN BOOLEAN DEFAULT NULL) is

begin

declare

cursor c_footer(p_msg in number) is

select message

from wam_web_footers

where footer_id=p_msg;

temp wam_web_footers.message%TYPE;

begin

IF lineattr = \'noline\' THEN

htp.nl;

ELSE

htp.hr;

END IF;

\--inline(\'tag1.gif\');

htp.nl;

htp.centerOpen;

if footer_id is not null then

open c_footer (footer_id);

fetch c_footer into temp;

if not c_footer%NOTFOUND then

htp.p(temp);

else

htp.mailto(\'mis_mgrs@aps.anl.gov\',\'Send comments and/or suggestions
to MIS_MGRS\');

if msg is not null then

htp.NL;

htp.print(msg);

end if;

end if;

else

htp.mailto(\'mis_mgrs@aps.anl.gov\',\'Send comments and/or suggestions
to MIS_MGRS\');

end if;

if nvl(DisplayLogout,TRUE) then

htp.formOpen(\'log0002.log_out\');

htp.formSubmit(\'\',\'Log Out\');

htp.formClose;

end if;

htp.centerClose;

htp.bodyClose;

htp.htmlClose;

end;

end;

\--

function change_pw (i_badge in varchar2) return boolean is

begin

declare

temp varchar2(1);

cursor c_password(p_badge in varchar2) is

select must_change_pwd

from gen_user_table

where badge_no = p_badge;

begin

open c_password(i_badge);

fetch c_password into temp;

if c_password%NOTFOUND then

temp:=\'N\';

end if;

close c_password;

\--htp.print (\'PW CHANGE VALUYE is \' \|\| temp);

if temp = \'Y\' then

return TRUE;

else

return FALSE;

end if;

end;

end;

\--

procedure login(i_app_name in varchar2,i_src_pkg in varchar2 default
null,

i_operation in varchar2 default null) is

begin

declare

NewPID Number;

Temp_PID Number;

remote_addr varchar2(50);

remote_user varchar2(50);

server_name varchar2(50);

http_user_agent varchar2(50);

cursor c_pid (p_pid in varchar2) is

select pid from ows_app_login

where pid = p_pid;

cursor c_tms_people is

select distinct person_id,per_name

from aps_a2z_people

order by per_name;

begin

lib.no_cache;

\--lib.prolog(\'APS Web Application Log On\');

if i_operation=\'RETRY\' then

lib.prolog(\'Access Denied\');

htp.print(\'\<CENTER\>\');

htp.print (\'\<h3\>\<i\>Sorry, access denied. Please try
again.\</i\>\</h3\>\');

htp.print(\'\</CENTER\>\');

end if;

\-- all access attempts recorded, don\'t reset old attempt

\-- generate PID

NewPID := lib.random_int(100000);

\--check pid existence in table

open c_pid(NewPID);

fetch c_pid into temp_pid;

while not c_pid%NOTFOUND loop

NewPID :=lib.random_int(100000);

close c_pid;

open c_pid(NewPID);

fetch c_pid into temp_pid;

end loop;

close c_pid;

remote_addr := owa_util.get_cgi_env(\'REMOTE_ADDR\');

server_name := owa_util.get_cgi_env(\'SERVER_NAME\');

remote_user := owa_util.get_cgi_env(\'REMOTE_USER\');

http_user_agent := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

insert into ows_app_login

(PID,APP_NAME,BADgE_NO,USERNAME,ACCESS_LEVEL,IP,TIMESTAMP,LAST_PAGE,HTTP_USER_AGENT,REMOTE_USER,SERVER_NAME)

values(NewPID,i_app_name,\'\',\'\',\'\',remote_addr,sysdate,\'LOGIN\',http_user_agent,remote_user,server_name);

\-- get user name

htp.print(\'\<CENTER\>\');

htp.formOpen(i_src_pkg \|\|\'.validate_user\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Login:\'));

htp.tableData(htf.formText(\'i_badge\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Password:\'));

htp.tableData(htf.formPassword(\'i_pass\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',NewPID);

\--htp.formHidden(\'i_src_pkg\',i_src_pkg);

htp.formSubmit(\'i_operation\',\'Login\');

\--htp.formHidden(\'i_app_name\',i_app_name);

\--htp.formSubmit(\'i_operation\',\'Change Password\');

htp.formReset;

htp.formClose;

htp.NL;

htp.NL;

if i_operation = \'RETRY\' then

lib.epilog;

end if;

htp.NL;

htp.print(\'\</CENTER\>\');

end;

end;

\--

procedure validate_user (i_badge in varchar2,i_pass in varchar2,i_pid in
varchar2,

i_operation in varchar2 default null,i_app_name in varchar2 default
null,

i_src_pkg in varchar2 default null) is

begin

declare

cursor c_user (p_badge in varchar2) is

select username

from all_oraweb_view

where badge_no = p_badge;

temp_user varchar2(15);

must_change varchar2(1);

temp_badge varchar2(10);

temp_badge2 varchar2(10);

local_operation varchar2(20);

begin

\--validate pid

\--temp_badge := lpad(i_badge,5,\'0\');

open c_user(i_badge);

fetch c_user into temp_user;

close c_user;

local_operation := i_operation;

if not gen0003.login_ok(temp_user,i_pass) then

update ows_app_login

set badge_no = i_badge,

username = temp_user,

access_level = \'DENIED\'

where pid = i_pid;

htp.NL;

login(i_app_name,i_src_pkg,\'RETRY\');

else

update ows_app_login

set username = temp_user,

badge_no = temp_badge,

access_level = \'GRANTED\'

where pid = i_pid;

\--return to calling package

\--this information probably belongs in an x-ref table

/\*if i_app_name = \'ETS-PS\' then

ps0001.login_accepted(i_pid);

elsif i_app_name = \'ETS-XFD-SR\' then

ets0003.login_accepted(i_pid);

end if;\*/

htp.htmlOpen;

htp.print(\'\<meta http-equiv=\"refresh\" content=\"0;

URL=../owa/\' \|\| i_src_pkg \|\| \'.login_accepted?i_pid=\' \|\| i_pid
\|\| \'\"\>\');

htp.NL;

htp.NL;

htp.NL;

htp.NL;

htp.print(\'\<h2\>\<strong\>\<center\>Validating user\... One moment
please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end if;

end;

end;

\--

PROCEDURE eq_row(nam IN VARCHAR2,val IN VARCHAR2) IS

BEGIN

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(nvl(val,\'.\')));

htp.tableRowClose;

END;

\--

function dm_convert (value_in IN VARCHAR2) RETURN DATE

/\*

\|\| Summary: Validate and convert date input of most any format.

\|\| dm_convert stands for \"date manager conversion\". Accepts

\|\| a character string and returns a fully-parsed and validated

\|\| date. If the string does not specify a valid date, the function

\|\| returns NULL.

\|\|

\|\| NOTE: if you get a parser stack overflow, then you need to

\|\| cut down on the number of nested blocks! PL/SQL in Oracle

\|\| Forms seems to be able to handle more than PL/SQL V2 on

\|\| the server side!

\*/

IS

/\* Internal, upper-cased version of date string \*/

value_int CHAR(100) := UPPER (value_in);

/\* The value returned by the function \*/

return_value DATE := NULL;

/\* Transfer SYSDATE to local variable to avoid repetitive calls \*/

today DATE := SYSDATE;

BEGIN

/\*

\|\| Handle the short-cut logic before checking for specific date

formats.

\|\| Supported short-cuts include:

\|\| EW - end of week

\|\| BW - beginning of week

\|\| EM - end of month

\|\| BM - beginning of month

\|\|

\|\| You might want to add shortcuts for quarters specific to your site.

\*/

IF value_int = \'EW\'

THEN

/\* End of week in this case is Friday of the week \*/

return_value := TRUNC (today, \'DAY\') + 5;

ELSIF value_int = \'BW\'

THEN

/\* Beginning of week in this case is Monday of the week \*/

return_value := TRUNC (today, \'DAY\') + 1;

ELSIF value_int = \'BM\'

THEN

return_value := TRUNC (today, \'MONTH\');

ELSIF value_int = \'EM\'

THEN

return_value := LAST_DAY (today);

ELSIF value_int IS NOT NULL

THEN

/\* No known short-cut. The user must have entered a date string for

\|\| conversion. Now attempt to convert the value using a sequence

\|\| of calls to TO_DATE. If one attempt fails, pass it to the next

\|\| TO_DATE and format mask within a (very) nested exception section.

\*/

BEGIN return_value := TO_DATE (value_int, \'DD\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MM/DD\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MM/DD/RR\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MM/DD/YYYY\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'DD-MON\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'DD-MON-RR\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'DD-MON-YYYY\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MON\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MON-DD\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MON-DD-RR\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MON-DD-YYYY\');

EXCEPTION WHEN OTHERS THEN

BEGIN return_value := TO_DATE (value_int, \'MON-YYYY\');

EXCEPTION WHEN OTHERS THEN return_value := NULL;

END; END; END; END; END; END;

END; END; END; END; END; END;

END IF;

/\* Whether NULL or a real date, return the value \*/

RETURN (return_value);

END;

\-- Re-added 8/13/99 kem adapted from safe0001

procedure err_msg (err_code in varchar2, err_str in varchar2) is

begin

lib02.DisplayProlog(\'Error Trapped - please fix\');

htp.p(\'\<center\>\');

htp.tableOpen(\'border=2\');

htp.tableHeader(\'ERROR NO:\');

htp.tableHeader(\'ERROR MESSAGE:\');

htp.tableRowOpen;

htp.tableData(err_code);

htp.tableData(err_str);

htp.tableRowOpen;

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.p(\'Use the \'\|\|\'\'\'BACK\'\'\'\|\|\' button\');

htp.p(\'\</center\>\');

lib02.displayEpilog;

end;

\--

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This function fixes the case of names like McDonald,
O\'malley, etc.

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

function fix_name(i_name in varchar2) return varchar2 is

\-- Declare cursors/variables

NewName varchar(30);

\-- Function body

begin

if i_name IS NOT NULL then

if UPPER(substr(i_name, 1, 2)) = \'MC\' then

NewName := initcap(substr(i_name, 1, 2)) \|\| initcap(substr(i_name, 3,
LENGTH(i_name) - 2));

elsif UPPER(substr(i_name, 1, 3)) = \'MAC\' then

NewName := initcap(substr(i_name, 1, 3)) \|\| initcap(substr(i_name, 4,
LENGTH(i_name) - 3));

elsif UPPER(substr(i_name, 1, 2)) = \'O\'\'\' then

NewName := \'O\'\'\' \|\| initcap(substr(i_name, 3, LENGTH(i_name) -
2));

else

NewName := i_name;

end if;

else

NewName := NULL;

end if;

\-- Return the modified name to the calling procedure

return NewName;

end;

\-- \*\*\* End function fix_name
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

END;

/

CREATE OR REPLACE PACKAGE LIB02 IS

PROCEDURE Show_Error(vTheObject IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheLocation IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheError IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheText IN VARCHAR2 DEFAULT \'NONE\',

bTheCommit IN BOOLEAN DEFAULT FALSE,

vUserID IN VARCHAR2 DEFAULT \'WEBUSER\');

procedure DisplayProlog(TitleMessage in varchar2 default NULL,

BGColor in varchar2 default NULL);

procedure DisplayEpilog(MainMenuPath in varchar2 default NULL,

Alt1Path in varchar2 default NULL,

Alt1Text in varchar2 default NULL,

Alt2Path in varchar2 default NULL,

Alt2Text in varchar2 default NULL,

Alt3Path in varchar2 default NULL,

Alt3Text in varchar2 default NULL,

Alt4Path in varchar2 default NULL,

Alt4Text in varchar2 default NULL,

Alt5Path in varchar2 default NULL,

Alt5Text in varchar2 default NULL,

DisplayLogout IN BOOLEAN DEFAULT NULL);

procedure DisplayError(ErrorNumber in number,

ErrorMessage in varchar2,

ErrorPosition in number,

DisplayMessage in varchar2);

FUNCTION GetUsername(PassedID IN VARCHAR2) RETURN VARCHAR2;

FUNCTION GetBadge(PassedPID IN VARCHAR2) RETURN VARCHAR2;

FUNCTION SwapCrLf(PassedText in VARCHAR2) RETURN VARCHAR2;

END LIB02;

/

CREATE OR REPLACE PACKAGE BODY LIB02 IS

\-- \*\*\* Declare global constants/variables \*\*\*

CR VARCHAR2(1) := chr(13);

LF VARCHAR2(1) := chr(10);

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- prodecure usage

\-- LIB02.Show_Error(TheObject, \-- package.procedure name

\-- 0, \-- error location

\-- TO_CHAR(SQLCODE)\|\|\' \'\|\| SQLERRM, \-- error code and message

\-- \'nothing\', \-- additional user-provided error information

\-- TRUE); \-- commit true/false default false

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- This procedure shows errors to the screen for error handling

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

PROCEDURE Show_Error(vTheObject IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheLocation IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheError IN VARCHAR2 DEFAULT \'UNKNOWN\',

vTheText IN VARCHAR2 DEFAULT \'NONE\',

bTheCommit IN BOOLEAN DEFAULT FALSE,

vUserID IN VARCHAR2 DEFAULT \'WEBUSER\') IS

BEGIN

lib02.DisplayProlog(\'Error Message\');

IF (bTheCommit)

THEN

COMMIT;

ELSE

ROLLBACK;

END IF;

htp.br;

htp.p(\'\<b\>\');

htp.p(\'\-- An error has occured in \'\|\|vTheObject\|\|\' on
\'\|\|SYSDATE\|\|\' \--\');

htp.br;

IF (vTheLocation \<\> \'UNKNOWN\')

THEN

htp.p(\'The error is: \'\|\|vTheError\|\|\'at this spot:
\'\|\|vTheLocation);

ELSE

htp.p(\'The error is: \'\|\|vTheError);

END IF;

htp.br;

IF (vTheText \<\> \'NONE\')

THEN

htp.p(\'Additional error data:\'\|\|vTheText);

htp.br;

END IF;

\-- htp.p(\'Please check the system_errors table for a more detailed
description.\');

htp.p(\'\</b\>\');

lib02.displayEpilog;

END Show_Error;

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Display prolog

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure DisplayProlog(TitleMessage in varchar2, BGColor in varchar2
default NULL) is

begin

\-- Start the HTML Document

htp.htmlOpen;

htp.headOpen;

htp.title(TitleMessage);

htp.headClose;

if BGColor IS NULL then

htp.bodyOpen(\'\', \'BGCOLOR=\"#FFFFFF\"\');

else

htp.bodyOpen(\'\', \'BGCOLOR=\"#\' \|\| BGColor \|\| \'\"\');

end if;

\-- Add JavaScript

htp.p(\'\<SCRIPT LANGUAGE=\"JavaScript\"\>\');

htp.p(\'var DownBtnOn = new Image();\');

htp.p(\'DownBtnOn.src = \"/gen-img/down_on.gif\";\');

htp.p(\'var MainMenuOn = new Image();\');

htp.p(\'MainMenuOn.src = \"/gen-img/mnubtnon.gif\";\');

htp.p(\'var AltBtnOn = new Image();\');

htp.p(\'AltBtnOn.src = \"/gen-img/altbtnon.gif\";\');

htp.p(\'function ChangeImage(ImageToChange, NewImage)\');

htp.p(\' {document.images\[ImageToChange\].src = NewImage}\');

htp.p(\'\</SCRIPT\>\');

\-- Display titlebar

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"35\" CELLSPACING=\"0\"
CELLPADDING=\"2\" BGCOLOR=\"#0E2525\" WIDTH=\"100%\"\');

htp.tableRowOpen(\'\', \'\', \'\', \'\', \'\');

htp.tableData(htf.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"5\" COLOR=\"#FFFFFF\"\>\' \|\|
TitleMessage),\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\"
BACKGROUND=\"/gen-img/apstext1.gif\"\');

htp.tableData(\'\<A HREF=\"#Bottom\"
OnMouseOver=\"ChangeImage(\'\'TopButton\'\',\'\'/gen-img/down_on.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'TopButton\'\',\'\'/gen-img/down_off.gif\'\');\"\>\<IMG
NAME=\"TopButton\" SRC=\"/gen-img/down_off.gif\" ALT=\"Bottom of Page\"
BORDER=\"0\"\>\</A\>\'

,\'CENTER\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\"\');

htp.tableRowClose;

htp.tableClose;

htp.para;

\--htp.br;

end;

\-- \*\*\* END DisplayProlog \*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Display epilog

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure DisplayEpilog(MainMenuPath in varchar2 default NULL, Alt1Path
in varchar2 default NULL,

Alt1Text in varchar2 default NULL, Alt2Path in varchar2 default NULL,

Alt2Text in varchar2 default NULL, Alt3Path in varchar2 default NULL,

Alt3Text in varchar2 default NULL, Alt4Path in varchar2 default NULL,

Alt4Text in varchar2 default NULL, Alt5Path in varchar2 default NULL,

Alt5Text in varchar2 default NULL, DisplayLogout IN BOOLEAN DEFAULT
NULL) is

begin

\-- Display footer

htp.para;

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"35\" CELLSPACING=\"0\"
CELLPADDING=\"0\" BGCOLOR=\"#0E2525\" WIDTH=\"100%\"\');

htp.tableRowOpen;

\-- Display Alt button 1

if Alt1Path IS NOT NULL then

htp.tableData(\'\<A HREF=\"\' \|\| Alt1Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt1Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt1Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt1Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/altb

tnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt1Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'NOWRAP\');

else

htp.tableData(\'&nbsp\');

end if;

\-- Display Alt button 2

if Alt2Path IS NOT NULL then

IF MainMenuPath IS NOT NULL OR Alt3Path IS NOT NULL THEN

htp.tableData(\'\<A HREF=\"\' \|\| Alt2Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt2Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt2Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt2Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/

altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt2Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'NOWRAP\');

ELSE

htp.tableData(\'\<A HREF=\"\' \|\| Alt2Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt2Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt2Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt2Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/

altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt2Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\" NOWRAP\');

END IF;

else

htp.tableData(\'&nbsp\');

end if;

\-- Display Alt button 3

if Alt3Path IS NOT NULL then

IF MainMenuPath IS NOT NULL OR Alt4Path IS NOT NULL THEN

htp.tableData(\'\<A HREF=\"\' \|\| Alt3Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt3Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt3Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt3Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/

altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt3Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'NOWRAP\');

ELSE

htp.tableData(\'\<A HREF=\"\' \|\| Alt3Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt3Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt3Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt3Btn\" HSPACE=\"3\" VSPACE=\"3\" SRC=\"/ge

n-img/altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt3Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\" NOWRAP\');

END IF;

else

htp.tableData(\'&nbsp\');

end if;

\-- Display Alt button 4

if Alt4Path IS NOT NULL then

IF MainMenuPath IS NOT NULL OR Alt5Path IS NOT NULL THEN

htp.tableData(\'\<A HREF=\"\' \|\| Alt4Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt4Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt4Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt4Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/

altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt4Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'NOWRAP\');

ELSE

htp.tableData(\'\<A HREF=\"\' \|\| Alt4Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt4Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt4Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt4Btn\" HSPACE=\"3\" VSPACE=\"3\" SRC=\"/ge

n-img/altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt4Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\" NOWRAP\');

END IF;

else

htp.tableData(\'&nbsp\');

end if;

\-- Display Alt button 5

if Alt5Path IS NOT NULL then

IF MainMenuPath IS NOT NULL THEN

htp.tableData(\'\<A HREF=\"\' \|\| Alt5Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt5Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt5Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt5Btn\" HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/

altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt5Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'NOWRAP\');

ELSE

htp.tableData(\'\<A HREF=\"\' \|\| Alt5Path \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'Alt5Btn\'\',\'\'/gen-img/altbtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'Alt5Btn\'\',\'\'/gen-img/altbtnof.gif\'\');\"\>\<IMG
ALIGN=\"ABSMIDDLE\" NAME=\"Alt5Btn\" HSPACE=\"3\" VSPACE=\"3\" SRC=\"/ge

n-img/altbtnof.gif\" BORDER=\"0\"\>\</A\>\<FONT FACE=\"Tahoma, Arial,
Helvetica\" SIZE=\"2\" COLOR=\"#FFFFFF\"\>\' \|\| Alt5Text,
\'LEFT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\" NOWRAP\');

END IF;

else

htp.tableData(\'&nbsp\');

end if;

\-- Display Main Menu button

if MainMenuPath IS NOT NULL then

htp.tableData(\'\<A HREF=\"\' \|\| MainMenuPath \|\| \'\"
OnMouseOver=\"ChangeImage(\'\'MainMenuBtn\'\',\'\'/gen-img/mnubtnon.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'MainMenuBtn\'\',\'\'/gen-img/mnubtnof.gif\'\');\"\>\<IMG
NAME=\"MainMenuBtn\" HSPACE=\"3\" VSPACE=\"3\" SRC=\"/gen-img/mnubtn

of.gif\" BORDER=\"0\"\>\</A\>\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'WIDTH=\"100%\"\');

else

htp.tableData(\'&nbsp\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.tableOpen(\'BORDER=\"0\" HEIGHT=\"30\" CELLSPACING=\"0\"
CELLPADDING=\"0\" BGCOLOR=\"#0E2525\"\');

htp.tableRowOpen;

htp.tableData(\'\<A NAME=\"Bottom\" HREF=\"mailto:mis_mgrs@aps.anl.gov\"
OnMouseOver=\"ChangeImage(\'\'EmailTab\'\',\'\'/gen-img/etab_on.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'EmailTab\'\',\'\'/gen-img/etab_off.gif\'\');\"\>\<IMG
NAME=\"EmailTab\" SRC=\"/gen-img/etab_off.gif\" BORDER

=\"0\"\>\</A\>\', \'LEFT\',\'\',\'\',\'\',\'\',\'\');

IF DisplayLogout = TRUE OR DisplayLogout IS NULL THEN

htp.tableData(\'\<A NAME=\"Bottom\" HREF=\"log0002.log_out\"
OnMouseOver=\"ChangeImage(\'\'LogoutTab\'\',\'\'/gen-img/logout_on.gif\'\');\"
OnMouseOut=\"ChangeImage(\'\'LogoutTab\'\',\'\'/gen-img/logout_off.gif\'\');\"\>\<IMG
NAME=\"LogoutTab\" SRC=\"/gen-img/logout_off.gif\" BORDE

R=\"0\"\>\</A\>\', \'LEFT\',\'\',\'\',\'\',\'\',\'\');

END IF;

htp.tableRowClose;

htp.tableClose;

htp.para;

\-- End the HTML Document

htp.bodyClose;

htp.htmlClose;

\-- Return to calling procedure

return;

end;

\-- \*\*\* END DisplayEpilog \*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Error trap

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure DisplayError(ErrorNumber in number, ErrorMessage in varchar2,
ErrorPosition in number,

DisplayMessage in varchar2) is

\-- Declare variables

NewErrorPosition varchar2(7);

begin

\-- Determine error position

if ErrorPosition IS NULL or ErrorPosition = 0 then

NewErrorPosition := \'Unknown\';

else

NewErrorPosition := TO_CHAR(ErrorPosition);

end if;

\-- Display the error box

htp.centerOpen;

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"
BGCOLOR=\"#F0F0F0\" WIDTH=\"60%\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"2\" COLOR=\"#FFFFFF\"\>\<CENTER\>&nbsp Error!
&nbsp\</CENTER\>\'),\'\',\'\',\'\',\'\',\'2\',\'BGCOLOR=\"#FF0000\"\');

htp.tableRowClose;

htp.tableRowOpen;

\-- Display the message

htp.tableData(\'\<IMG HSPACE=\"3\" VSPACE=\"3\"
SRC=\"/gen-img/stpsign.gif\"\>\',\'\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

if ErrorNumber = 1 then

\-- User-defined error

htp.tableData(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"2\"\>\<B\>An error has occurred:\</B\>\<P\>\' \|\|
DisplayMessage);

else

\-- System generated error

htp.tableData(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\"
SIZE=\"2\"\>\<B\>An error has occurred: \[\' \|\| TO_CHAR(ErrorNumber)
\|\| \'\] \' \|\| ErrorMessage \|\| \'\</B\>\<P\>\' \|\|
DisplayMessage);

end if;

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableData(\'\<FONT FACE=\"Tahoma, Arial, Helvetica\" SIZE=\"1\"
COLOR=\"#F0F0F0\"\>Error Position: \' \|\| NewErrorPosition,
\'RIGHT\',\'\',\'\',\'\',\'2\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

htp.para;

htp.br;

\-- Return to calling procedure

return;

end;

\-- \*\*\* END DisplayError \*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Get user name using badge ID

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

FUNCTION GetUsername(PassedID IN VARCHAR2) RETURN VARCHAR2 IS

UserName VARCHAR2(40);

BEGIN

IF PassedID \<\> \'\*\' THEN

SELECT name INTO UserName

FROM badge_info

WHERE badge_no = PassedID;

ELSE

UserName := NULL;

END IF;

RETURN Username;

END;

\-- \*\*\* END FUNCTION GetUsername

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* Get badge using PID

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

FUNCTION GetBadge(PassedPID IN VARCHAR2) RETURN VARCHAR2 IS

BadgeNo VARCHAR2(5);

BEGIN

SELECT badge_no INTO BadgeNo

FROM ows_app_login

WHERE PID = PassedPID;

RETURN BadgeNo;

END;

\-- \*\*\* END FUNCTION GetBadge

\-- \*\*\* Swap CrLf to \<BR\> for display in HTML \*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

FUNCTION SwapCrLf(PassedText in VARCHAR2) RETURN VARCHAR2 IS

\-- Declare constants/variables

Position NUMBER(5) := 1;

NewText VARCHAR2(3000);

BEGIN

NewText := PassedText;

WHILE Position \<\> 0 LOOP

Position := instr(NewText, CR \|\| LF, Position + 1);

IF Position \<\> 0 THEN

NewText := substr(NewText, 1, Position) \|\| \'\<BR\>\' \|\|
substr(NewText, Position + 2);

END IF;

END LOOP;

RETURN NewText;

END;

END LIB02;

/

CREATE OR REPLACE PACKAGE log0002 IS

pkg_name varchar2(255) := \'ps0001\';

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

temp varchar2(2000);

err_pnt varchar2(500);

\--global web user variables

web_user_badge varchar2(10);

oracle_web_user varchar2(50);

web_user_ip varchar2(25);

\--for cookie processing

pid_cookie owa_cookie.cookie;

cookie_arr owa_cookie.vc_arr;

l_pid varchar2(255);

global_pid varchar(255);

procedure get_cookie;

procedure log_out;

procedure login (i_app_name in varchar2,

i_operation in varchar2 default null,

i_pid in varchar2 default NULL,

i_attrib in varchar2 default NULL,

i_use_cookie in varchar2 default NULL);

procedure validate_user (i_badge in varchar2,

i_pass in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_group in varchar2 default \'FALSE\',

i_attrib in varchar2 default NULL);

procedure validate_last_name (i_badge in varchar2,

i_pass in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_group in varchar2 default \'FALSE\',

i_attrib in varchar2 default NULL) ;

procedure record_pub_user (i_last_name in varchar2 default null,

i_first_name in varchar2 default null,

i_company in varchar2 default null,

i_phone in varchar2 default null,

i_ss in varchar2 default null,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_attrib in varchar2 default NULL);

procedure validate_anl_user (i_badge in varchar2,

i_last_name in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_attrib in varchar2 default NULL);

\--password change application

procedure get_new_pw(i_pid in varchar2,

i_attrib in varchar2 default NULL);

procedure change_password (i_operation in varchar2,

i_pid in varchar2,

i_new_pw in varchar2,

i_new_pw2 in varchar2,

i_attrib in varchar2 default NULL);

procedure post_pwd_change (i_pid in varchar2,

i_attrib in varchar2 default NULL);

function is_valid_pid_lower_level(i_pid in varchar2,

i_timeout in varchar2 default \'4\',

i_app_name in varchar2,

i_remote_addr in varchar2) return BOOLEAN;

function is_valid_pid (i_pid in varchar2,

i_app_name in varchar2,

i_timeout in varchar2 default \'4\',

i_use_header in varchar2 default \'TRUE\',

i_attrib in varchar2 default NULL,

i_external_call in varchar2 default \'N\') return boolean;

\--open pid for apps the get hit with DHCP originating IP is ignored

function is_valid_open_pid_lower_level(i_pid in varchar2,

i_timeout in varchar2 default \'4\',

i_app_name in varchar2,

i_remote_addr in varchar2) return BOOLEAN;

function is_valid_open_pid (i_pid in varchar2,

i_app_name in varchar2,

i_timeout in varchar2 default \'4\',

i_use_header in varchar2 default \'TRUE\',

i_attrib in varchar2 default NULL,

i_external_call in varchar2 default \'N\') return boolean;

\--

function valid_machine (i_app_name in varchar2) return boolean ; \--
made public, fml 21-AUG-97

function user_in_group (i_group in varchar2,i_user in varchar2) return
boolean; \-- made pub, fml 21-AUG-97

function chk_user_in_group (i_group in varchar2,i_user in varchar2)
return number;

\--allow for use as inline function

\-- pragma restrict_references (user_in_group,WNDS);

\-- pragma restrict_references(chk_user_in_group,WNDS);

END;

/

CREATE OR REPLACE PACKAGE BODY log0002 is

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

else

return(prod_service);

end if;

end;

\--

function package_name (i_pid in varchar2) return varchar2 is

begin

declare

cursor c_pkg_name (p_pid in varchar2) is

select pkg_name

from ows_nt_package_priv priv,ows_app_login app

where app.app_name=priv.ows_package

and app.pid = p_pid;

temp varchar2(20);

begin

open c_pkg_name (i_pid);

fetch c_pkg_name into temp;

close c_pkg_name;

return(temp);

end;

end;

\--

function pwd_change_ok(i_pid in varchar2,

i_new_pw in varchar2,

i_new_pw2 in varchar2)

return boolean

is

cursor c_recent_pwd(p_encrypted_pw in VARCHAR2) is

SELECT \'1\'

FROM OWS_PWD_HIST h, OWS_APP_LOGIN a

WHERE a.USERNAME=h.USERNAME

AND pid=i_pid

AND pwd=p_encrypted_pw

AND MOD_DATE \> SYSDATE - 90;

cursor c_badge is

SELECT BADGE_NO

FROM OWS_APP_LOGIN

WHERE PID=i_pid;

temp varchar2(1);

l_badge OWS_APP_LOGIN.BADGE_NO%TYPE;

l_encrypted_pw GEN_USER_TABLE.BREAKER%TYPE;

result boolean;

begin

l_encrypted_pw:=log2000.prepare_pwd(i_new_pw);

result := TRUE;

open c_recent_pwd(l_encrypted_pw);

fetch c_recent_pwd into temp;

if not c_recent_pwd%NOTFOUND then

result := FALSE;

end if;

close c_recent_pwd;

if (i_new_pw != i_new_pw2) then

result := FALSE;

end if;

open c_badge;

fetch c_badge into l_badge;

close c_badge;

if i_new_pw=l_badge then

result := FALSE;

end if;

return result;

end;

\--

function return_to_proc (i_pid in varchar2) return varchar2 is

begin

declare

cursor c_pkg_proc (p_pid in varchar2) is

select return_to_proc

from ows_nt_package_priv priv,ows_app_login app

where app.app_name=priv.ows_package

and app.pid = p_pid;

temp varchar2(20);

begin

open c_pkg_proc (i_pid);

fetch c_pkg_proc into temp;

close c_pkg_proc;

return(temp);

end;

end;

\--

\--

function package_name2 (i_app_name in varchar2) return varchar2 is

begin

declare

cursor c_pkg_name is

select pkg_name

from ows_nt_package_priv

where ows_package=i_app_name;

temp varchar2(20);

begin

open c_pkg_name;

fetch c_pkg_name into temp;

close c_pkg_name;

return(temp);

end;

end;

\--

\--

function return_to_proc2 (i_app_name in varchar2) return varchar2 is

begin

declare

cursor c_pkg_proc is

select return_to_proc

from ows_nt_package_priv

where ows_package=i_app_name;

temp varchar2(20);

begin

open c_pkg_proc;

fetch c_pkg_proc into temp;

close c_pkg_proc;

return(temp);

end;

end;

\--

function badge_for_this_pid(i_pid in varchar2) return varchar2 is

cursor c_badge is

select badge_no

from ows_app_login

where pid=i_pid;

result ows_app_login.BADGE_NO%TYPE;

begin

open c_badge;

fetch c_badge into result;

if c_badge%NOTFOUND then

result:=\'NONE\';

end if;

close c_badge;

return(result);

end;

\--

function validate_app (i_pid in varchar2, i_app_name in varchar2) return
boolean is

begin

declare

cursor c_user (p_pid in varchar2) is

select username from

ows_app_login

where pid=p_pid;

machine_ok boolean;

group_ok boolean;

user_group varchar2(50);

result boolean;

security number(1);

temp_user varchar2(30);

cursor c_security (p_app_name in varchar2) is

select security_level,ows_user_group

from ows_nt_package_priv

where ows_package=p_app_name;

begin

\-- get security level

result := FALSE;

\--INSERT INTO WEB_ERROR_LOG

\--VALUES(\'Security check for \' \|\| i_app_name);

open c_security(i_app_name);

fetch c_security into security,user_group;

close c_security;

\--htp.p (\'Check user\');

open c_user (i_pid);

fetch c_user into temp_user;

close c_user;

\--

if security=1 or security=9 then \--both mean ip protection 1 requires
valid pw. 9 does not

machine_ok := valid_machine(i_app_name);

result := machine_ok;

elsif security=2 then

group_ok := user_in_group(i_app_name,temp_user);

result := group_ok;

elsif security=3 then

machine_ok := valid_machine(i_app_name);

group_ok := user_in_group(i_app_name,temp_user);

result := machine_ok and group_ok;

elsif security=4 then

machine_ok := valid_machine(i_app_name);

group_ok := user_in_group(i_app_name,temp_user);

result := machine_ok or group_ok;

elsif security=5 then

\--5=world open

result := TRUE;

end if;

\--htp.p(\'Debug point 3\');

if result = TRUE then

insert into ows_app_pid_xref

values (i_pid,i_app_name);

\--htp.p (\'App switch result TRUE is pid = \' \|\| i_pid \|\| \' and
app_name = \' \|\| i_app_name);

else

insert into ows_app_pid_xref

values (i_pid,\'FALSE RESULT in log0002\');

\--htp.p (\'App switch result FALSE is pid = \' \|\| i_pid \|\| \' and
app_name = \' \|\| i_app_name);

end if;

return (result);

exception

when others then

\--htp.p(\'Exception in validate_app\');

\--INSERT INTO WEB_ERROR_LOG

\--VALUES(\'Exception in validate app\');

null;

end;

end;

\--

procedure get_cookie is

begin

declare

l_pid varchar2(255);

begin

OWA_UTIL.MIME_HEADER(\'text/html\',false);

pid_cookie := owa_cookie.get(\'PIDCOOKIE\');

OWA_UTIL.HTTP_HEADER_CLOSE;

l_pid := pid_cookie.vals(1);

htp.htmlOpen;

htp.htmlClose;

end;

end;

\--

\--

\--nothing fancy. validates only. no swtich checking (see is_valid_pid)

function is_valid_pid_lower_level(i_pid in varchar2,

i_timeout in varchar2 default \'4\',

i_app_name in varchar2,

i_remote_addr in varchar2) return BOOLEAN is

\--time limit in hours

time_limit constant number := to_number(i_timeout);

temp varchar2(1);

cursor c_pid(p_pid in number,p_addr in varchar2) is

select \'1\' from

ows_app_login

where pid = p_pid

and ip = p_addr

and (sysdate - timestamp) \< (time_limit/24)

and ACCESS_LEVEL=\'GRANTED\'

and LOG_OUT_DATE is NULL;

cursor c_pid2(p_pid in number,p_app_name in varchar2) is

select \'1\' from

ows_app_pid_xref

where pid = p_pid

and app_name = p_app_name;

result boolean;

begin

open c_pid(i_pid,i_remote_addr);

fetch c_pid into temp;

if not c_pid%NOTFOUND then

update ows_app_login

set timestamp=sysdate

where pid=i_pid;

commit;

result := TRUE;

else

result := FALSE;

end if;

close c_pid;

if (result=TRUE and i_app_name != \'ANY\') then

open c_pid2(i_pid,i_app_name);

fetch c_pid2 into temp;

\-- if app not found, check security

if c_pid2%NOTFOUND then

result := validate_app (i_pid,i_app_name);

end if;

end if;

return (result);

end;

\--

function is_valid_pid (i_pid in varchar2,i_app_name in
varchar2,i_timeout in varchar2 default \'4\',

i_use_header in varchar2 default \'TRUE\',i_attrib in varchar2 default
NULL,

i_external_call in varchar2 default \'N\') return boolean is

begin

declare

\--time limit in hours

time_limit constant number := to_number(i_timeout);

temp varchar2(1);

\--

temp_app_name varchar2(30);

result boolean;

err_pnt varchar2(255);

\--

begin

\--reject logged out sessions - shouldnt even get here

\--INSERT INTO WEB_ERROR_LOG values (\'Entering LOG0002.IS_VALID_PID
app=\' \|\| i_app_name);

if i_pid = \'TERMINATE\' then

result := FALSE;

return (result);

end if;

\--htp.p(\'IN IS VALID PID\');

err_pnt := \'0 ipid\' \|\| i_pid ;

\--insert into WEB_ERROR_LOG

\--values (\'STARTING log0002.is_valid_pid\');

\--

result := is_valid_pid_lower_level(i_pid,

i_timeout,

i_app_name,

owa_util.get_cgi_env(\'REMOTE_ADDR\'));

\--

err_pnt := \'2\';

\--insert into WEB_ERROR_LOG VALUES

\--(\'htp.p (\'\'Validation point 2 \'\' \|\| i_pid \|\| \' \|\| i_pid
\|\|\' \' \|\| i_app_name\|\|\')\');

\--if pid ok, check for specific app

err_pnt := \'3\';

\-- Initialize global variables

web_user_badge := badge_for_this_pid(i_pid); \--\'TEST\';

\--

return(result);

exception

when others then

temp := \'Session validation failure. Sorry. Please notify
mis_mgrs@aps.anl.gov \' \|\| SQLERRM

\|\| \' ERROR POINT : \' \|\| err_pnt \|\| \' \' \|\| to_char(sysdate)
\|\| \' pid=\' \|\| i_pid;

htp.p(temp);

\--INSERT INTO WEB_ERROR_LOG

\--VALUES (temp);

return(FALSE);

end;

end;

\--

\--open pid functions for DHCP connections - origating ip is ignored

function is_valid_open_pid_lower_level(i_pid in varchar2,

i_timeout in varchar2 default \'4\',

i_app_name in varchar2,

i_remote_addr in varchar2) return BOOLEAN is

\--time limit in hours

time_limit constant number := to_number(i_timeout);

temp varchar2(1);

cursor c_pid(p_pid in number,p_addr in varchar2) is

select \'1\' from

ows_app_login

where pid = p_pid

\--and ip = p_addr

and (sysdate - timestamp) \< (time_limit/24)

and ACCESS_LEVEL=\'GRANTED\'

and LOG_OUT_DATE is NULL;

cursor c_pid2(p_pid in number,p_app_name in varchar2) is

select \'1\' from

ows_app_pid_xref

where pid = p_pid

and app_name = p_app_name;

result boolean;

begin

open c_pid(i_pid,i_remote_addr);

fetch c_pid into temp;

if not c_pid%NOTFOUND then

update ows_app_login

set timestamp=sysdate

where pid=i_pid;

commit;

result := TRUE;

else

result := FALSE;

end if;

close c_pid;

if (result=TRUE and i_app_name != \'ANY\') then

open c_pid2(i_pid,i_app_name);

fetch c_pid2 into temp;

\-- if app not found, check security

if c_pid2%NOTFOUND then

result := validate_app (i_pid,i_app_name);

end if;

end if;

return (result);

end;

\--

function is_valid_open_pid (i_pid in varchar2,i_app_name in
varchar2,i_timeout in varchar2 default \'4\',

i_use_header in varchar2 default \'TRUE\',i_attrib in varchar2 default
NULL,

i_external_call in varchar2 default \'N\') return boolean is

begin

declare

\--time limit in hours

time_limit constant number := to_number(i_timeout);

temp varchar2(1);

\--

temp_app_name varchar2(30);

result boolean;

err_pnt varchar2(255);

\--

begin

\--reject logged out sessions - shouldnt even get here

\--INSERT INTO WEB_ERROR_LOG values (\'Entering LOG0002.IS_VALID_PID
app=\' \|\| i_app_name);

if i_pid = \'TERMINATE\' then

result := FALSE;

return (result);

end if;

\--htp.p(\'IN IS VALID PID\');

err_pnt := \'0 ipid\' \|\| i_pid ;

\--insert into WEB_ERROR_LOG

\--values (\'STARTING log0002.is_valid_pid\');

\--

result := is_valid_pid_lower_level(i_pid,

i_timeout,

i_app_name,

owa_util.get_cgi_env(\'REMOTE_ADDR\'));

\--

err_pnt := \'2\';

\--insert into WEB_ERROR_LOG VALUES

\--(\'htp.p (\'\'Validation point 2 \'\' \|\| i_pid \|\| \' \|\| i_pid
\|\|\' \' \|\| i_app_name\|\|\')\');

\--if pid ok, check for specific app

err_pnt := \'3\';

\-- Initialize global variables

web_user_badge := badge_for_this_pid(i_pid); \--\'TEST\';

\--

return(result);

exception

when others then

temp := \'Session validation failure. Sorry. Please notify
mis_mgrs@aps.anl.gov \' \|\| SQLERRM

\|\| \' ERROR POINT : \' \|\| err_pnt \|\| \' \' \|\| to_char(sysdate)
\|\| \' pid=\' \|\| i_pid;

htp.p(temp);

\--INSERT INTO WEB_ERROR_LOG

\--VALUES (temp);

return(FALSE);

end;

end;

\--end of is_valid_open_pid functions

\--

function anl_login_ok (i_badge in varchar2,i_last_name in varchar2)
return BOOLEAN is

begin

declare

cursor c_login (p_badge in varchar2,p_last_name in varchar2) is

select \'1\'

from anl_people_v1

where upper(per_last_name) = upper(i_last_name)

and per_unq_id = to_number(p_badge);

result boolean;

temp varchar2(1);

begin

open c_login (i_badge,i_last_name);

fetch c_login into temp;

if not c_login%NOTFOUND then

result := TRUE;

\--htp.p(\'ok is true\');

else

result := FALSE;

\--htp.p (\'ok is false\');

end if;

close c_login;

return result;

end;

end;

\--

function valid_machine (i_app_name in varchar2) return boolean is

begin

declare

\--

cursor c_group (p_app_name in varchar2,p_service in varchar2,p_subnet in
varchar2,p_node in varchar2) is

select \'1\'

from ows_ip_nt_link l, ows_nt_package_priv p

where p.ows_ip_group = l.ows_ip_group

and l.port = p_service

and p.ows_package=i_app_name

and (subnet_name=p_subnet

or node_name=p_node)

and inactive is null;

\--

cursor c_subnet_ip (p_ip in varchar2) is

select subnet_name

from ows_nt_subnet_view

where instr(p_ip,ip_addr\|\|\'.\') = 1;

\--

cursor c_whole_ip (p_ip in varchar2) is

select node_name

from ows_nt_view

where ip_addr = p_ip;

\--

ip varchar2(15);

temp_node varchar2(20);

temp_sub varchar2(20);

result BOOLEAN;

found NUMBER(1);

port varchar2(15);

begin

ip := owa_util.get_cgi_env(\'REMOTE_ADDR\');

port := get_service;

if port = dev_service then

port := \'MISWEB\';

else

port := \'APSWEB\';

end if;

result := FALSE;

\-- get node,subnet names

\--get node name

open c_whole_ip (ip);

fetch c_whole_ip into temp_node;

if c_whole_ip%NOTFOUND then

temp_node := \'\';

end if;

close c_whole_ip;

\-- subnet and level2 access, so looping

\-- ie. REMOTE_ADDR=164.54.48.230 .. \"subnet\" is 164.54.48

\-- but some applications use 164.54

\-- get_subnet_name

open c_subnet_ip (ip);

fetch c_subnet_ip into temp_sub;

while not c_subnet_ip%NOTFOUND loop

\-- htp.p(\'Subnet = \' \|\| temp_sub \|\| \'\<BR\>Node=\' \|\|
temp_node \|\| \'\<BR\>Service =\' \|\| port);

open c_group (i_app_name,port,temp_sub,temp_node);

fetch c_group into found;

if not c_group%NOTFOUND then

result := TRUE;

exit; \-- end while loop

end if;

close c_group;

fetch c_subnet_ip into temp_sub;

end loop;

close c_subnet_ip;

\-- if result then

\-- htp.p (\'MACHINE is valid for \' \|\| i_app_name);

\-- else

\-- htp.p (\'Invalid machine for \' \|\| i_app_name);

\-- end if;

return result;

end;

end;

\--

procedure log_out is

log_out_pid varchar2(255);

begin

owa_util.MIME_HEADER(\'text/html\',FALSE);

pid_cookie := owa_cookie.get(\'PIDCOOKIE33\');

if pid_cookie.num_vals \> 0 then

for ctr in 1..pid_cookie.num_vals loop

log_out_pid := pid_cookie.vals(pid_cookie.num_vals);

update OWS_APP_LOGIN

SET LOG_OUT_DATE=sysdate

WHERE PID=to_number(l_pid);

OWA_COOKIE.remove(\'PIDCOOKIE33\',pid_cookie.vals(ctr),\'/\');

end loop;

end if;

OWA_COOKIE.SEND(\'PIDCOOKIE33\',\'TERMINATE\',sysdate - 1,\'/\');

OWA_UTIL.HTTP_HEADER_CLOSE;

htp.htmlOpen;

htp.p(\'Your session is now closed \' \|\| l_pid \|\| \' id=\' \|\|
to_char(pid_cookie.num_vals));

htp.htmlClose;

EXCEPTION

when others then

temp:= \'Log out error. Please notify mis_mgrs@aps.anl.gov\...\' \|\|
sqlerrm;

htp.p(temp);

\--INSERT INTO WEB_ERROR_LOG

\--VALUES (temp);

end;

\--

procedure validate_anl_user (i_badge in varchar2,

i_last_name in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_attrib in varchar2 default NULL) is

begin

\--

declare

cursor c_anl_user (p_badge in varchar2) is

select per_last_name

from anl_people_v1

where per_unq_id = to_number(p_badge);

cursor c_retry(p_pid in varchar2) is

select ATTRIB,USE_COOKIE

from OWS_APP_LOGIN

where PID=p_pid;

l_attrib OWS_APP_LOGIN.ATTRIB%TYPE;

l_use_cookie OWS_APP_LOGIN.USE_COOKIE%TYPE;

temp_user varchar2(15);

must_change varchar2(1);

temp_badge varchar2(10);

temp_badge2 varchar2(10);

local_operation varchar2(20);

revalidate boolean;

\--l_pid varchar2(512);

begin

\--validate pid

l_pid := i_pid;

local_operation := i_operation;

if not (anl_login_ok(i_badge,i_last_name)) then

update ows_app_login

set badge_no = i_badge,

username = i_last_name,

access_level = \'DENIED\'

where pid = i_pid;

htp.NL;

open c_retry(i_pid);

fetch c_retry into l_attrib,l_use_cookie;

close c_retry;

lib.prolog(\'Sorry, Authorization Failed\');

htp.centerOpen;

htp.p(\'\<FONT SIZE=+3\>To try again, please click the link
below:\</font\>\');

htp.NL;

htp.NL;

htp.p(\'\<A HREF=\"log0002.login?i_app_name=\' \|\| i_app_name \|\|
\'&i_operation=Login&i_attrib=\' \|\| l_attrib \|\| \'&i_use_cookie=\'
\|\| l_use_cookie \|\| \'\"\> Click here to return to login screen.\');

htp.centerClose;

htp.p(\'\</BODY\>\</HMTL\>\');

\--login(i_app_name,\'RETRY\');

else

update ows_app_login

set username = i_last_name,

badge_no = i_badge,

access_level = \'GRANTED\'

where pid = l_pid;

\--return to calling package

\--htp.p (\'User authenticated\');

if i_operation=\'Login\' then

htp.htmlOpen;

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\| i_pid

\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\| i_pid \|\|
\'\"\>\');

end if;

htp.NL;

htp.NL;

htp.NL;

htp.NL;

htp.print(\'\<h2\>\<strong\>\<center\>Authenticating user privileges\...
One moment please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end if;

end if;

end;

end;

\--

procedure record_pub_user (i_last_name in varchar2 default null,

i_first_name in varchar2 default null,

i_company in varchar2 default null,

i_phone in varchar2 default null,

i_ss in varchar2 default null,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_attrib in varchar2 default NULL) is

begin

\--

declare

temp_user varchar2(15);

must_change varchar2(1);

temp_badge varchar2(10);

temp_badge2 varchar2(10);

local_operation varchar2(20);

revalidate boolean;

l_pid varchar2(512);

begin

\--store public access information

l_pid := i_pid;

update ows_app_login

set username = i_last_name,

badge_no = \'PUBLIC\',

last_name = i_last_name,

first_name = i_first_name,

ss_no = i_ss,

phone = i_phone,

company = i_company,

access_level = \'GRANTED\'

where pid = l_pid;

\--return to calling package

\--htp.p (\'User authenticated\');

if i_operation=\'Continue\' then

htp.htmlOpen;

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\|
l_pid\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\| l_pid \|\|
\'\"\>\');

end if;

htp.NL;

htp.NL;

htp.NL;

htp.NL;

htp.print(\'\<h2\>\<strong\>\<center\>One moment
please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end if;

end;

end;

\--

procedure login(i_app_name in varchar2,

i_operation in varchar2 default null,

i_pid in varchar2 default NULL,

i_attrib in varchar2 default NULL,

i_use_cookie in varchar2 default NULL) is

begin

declare

NewPID Number;

Temp_PID Number;

remote_addr varchar2(50);

remote_user varchar2(50);

server_name varchar2(50);

http_user_agent varchar2(255);

cursor c_pid (p_pid in varchar2) is

select pid from ows_app_login

where pid = p_pid;

machine_ok boolean;

get_user_group boolean;

user_group varchar2(50);

continue boolean;

make_new_pid boolean;

security number(1);

profile_id varchar2(20);

l_gif varchar2(255);

r_gif varchar2(255);

NewPIDExtended varchar2(255);

validation_required boolean;

last_name_validate boolean;

anl_login boolean;

pub_login boolean;

quick_refresh boolean;

cursor c_security (p_app_name in varchar2) is

select
security_level,title,browser_title_bar,ows_user_group,nvl(profile_id,\'1\')

from ows_nt_package_priv

where ows_package=p_app_name;

cursor c_profile (p_profile_id in varchar2) is

select \*

from ows_app_profiles p

where profile_id = p_profile_id;

cursor c_gif (p_gif_id in varchar2) is

select path

from ows_profile_gifs g

where gif_id = p_gif_id;

r_profile ows_app_profiles%ROWTYPE;

temp varchar2(2000);

temp2 varchar2(255);

freshPID boolean;

err_pnt varchar2(3);

begin

\--start of real, re-developed PID cookie 3/12/1999

\--INSERT INTO WEB_ERROR_LOG VALUES

\--(\'login procedure starts i pid is \' \|\| nvl(i_pid,\'empty\'));

if (i_pid is null or i_pid = \'NEW\') and nvl(i_operation,\'.\')
!=\'RETRY\' then

if nvl(i_use_cookie,\'Y\') != \'N\' then

\--acquire PID from cookie\....create and send NEW PID if no current pid
found

owa_util.MIME_HEADER(\'text/html\',FALSE);

pid_cookie := owa_cookie.get(\'PIDCOOKIE33\');

if pid_cookie.num_vals \> 0 then

l_pid := pid_cookie.vals(pid_cookie.num_vals);

end if;

\--for testing \... remove cookie on demand

\--OWA_COOKIE.SEND(\'PIDCOOKIE33\',l_pid,sysdate - 1);

\-- INSERT INTO WEB_ERROR_LOG VALUES

\-- (\'login procedure l_pid is \' \|\| nvl(l_pid,\'empty\'));

\--if not Pid found or is invalid\...generate pid & send cookie now

if NOT is_valid_pid(l_pid,i_app_name) then

NewPID := lib.random_int(100000) + lib.random_int(10);

NewPIDExtended := to_char(sysdate,\'MM\') \|\|

to_char(NewPID) \|\|

to_char(sysdate,\'DDYYSSSSS\');

NewPID := to_number(NewPIDExtended);

make_new_pid := TRUE;

\--store PID in cookie, even if it later proves to be invalid

OWA_COOKIE.SEND(\'PIDCOOKIE33\',to_char(NewPID),sysdate + .33,\'/\');

l_pid := NewPID;

\--store in global static var

pid_cookie.num_vals := 1;

pid_cookie.vals(1) := l_pid;

else

make_new_pid := FALSE;

end if;

OWA_UTIL.HTTP_HEADER_CLOSE;

else

\-- non-cookie apps always make new pid

NewPID := lib.random_int(100000) + lib.random_int(10);

NewPIDExtended := to_char(sysdate,\'MM\') \|\|

to_char(NewPID) \|\|

to_char(sysdate,\'DDYYSSSSS\');

NewPID := to_number(NewPIDExtended);

l_pid := NewPID;

make_new_pid := TRUE;

\--INSERT INTO WEB_ERROR_LOG

\--values (\'Non cookie pid made =\' \|\| l_pid \|\| \' app_name=\' \|\|
i_app_name);

end if;

htp.bodyOpen;

end if;

global_pid := l_pid;

lib.no_cache;

/\* htp.p(\'L pid nvl is \' \|\| nvl(l_pid,\'MONKEYSWING\'));

if make_new_pid then

htp.p(\'New pid created \' \|\| NewPID);

else

htp.p(\'Current pid OK \' \|\| l_pid);

end if\*/

\-- get security level

open c_security(i_app_name);

fetch c_security into security,temp,temp2,user_group,profile_id;

close c_security;

\--get app login profile

open c_profile (profile_id);

fetch c_profile into r_profile;

close c_profile;

\--get gif paths

open c_gif(r_profile.left_gif_id);

fetch c_gif into l_gif;

if c_gif%NOTFOUND then

l_gif := \'NONE\';

end if;

close c_gif;

open c_gif(r_profile.right_gif_id);

fetch c_gif into r_gif;

if c_gif%NOTFOUND then

r_gif := \'NONE\';

end if;

close c_gif;

\--first get security privilege requirements for requested package

validation_required := TRUE; \--unless security=5

last_name_validate := FALSE; \-- except for 8

\--neither of these require validation

anl_login := FALSE; \--unless security=6

pub_login := FALSE; \--unless security=7

\--

quick_refresh := FALSE; \--except for security = 5,9

if security=1 then

machine_ok := valid_machine(i_app_name);

continue :=machine_ok;

get_user_group := FALSE;

elsif security=2 then

machine_ok := TRUE;

get_user_group := TRUE;

continue := TRUE;

elsif security=3 then

machine_ok := valid_machine(i_app_name);

get_user_group := TRUE;

continue := machine_ok;

elsif security=4 then

machine_ok := valid_machine(i_app_name);

if machine_ok then

get_user_group := FALSE;

else

get_user_group := TRUE;

end if;

continue := TRUE;

elsif security=5 then \--\"5\"= open to the world\...

machine_ok := TRUE;

get_user_group := FALSE;

quick_refresh := TRUE;

continue := TRUE;

validation_required := FALSE;

\--else 6,7 reserved for wbt

elsif security=6 then \--\"6\" - ANL people login, name validation

machine_ok := TRUE;

get_user_group := FALSE;

continue := TRUE;

validation_required := FALSE;

anl_login := TRUE;

elsif security=7 then \--\"7\"- open, but sign in required - no
validation

machine_ok := TRUE;

get_user_group := FALSE;

continue := TRUE;

validation_required := FALSE;

pub_login := TRUE;

\--end wbt

elsif security=8 then\--badge no/last name matching

validation_required := FALSE;

last_name_validate := TRUE;

continue := TRUE;

\-- no validation required \... so continue

\-- htp.p(\'NO VALIDAITON REQUIRED\');

elsif security=9 then \-- same as security=1, but no log in required

validation_required := FALSE;

quick_refresh := TRUE;

machine_ok := valid_machine(i_app_name);

continue :=machine_ok;

end if;

\--

\--INSERT INTO WEB_ERROR_LOG VALUES (\'Security=\' \|\| security);

if not continue then

htp.print(\'The system you requested is unavailable from this
workstation\');

else

if i_operation=\'RETRY\' then

lib.prolog(\'Sorry, Access Denied. Please Try Again\');

\--htp.print(\'\<CENTER\>\');

\--htp.print (\'\<h3\>\<i\>Sorry, access denied. Please try
again.\</i\>\</h3\>\');

\--htp.print(\'\</CENTER\>\');

end if;

\--all access attempts recorded, don\'t reset old attempt

\--create new PID only if fresh login, otherwise re-use

if make_new_pid then

\--Meta tags wont work for non-validation if header already printer
5/24/99 kem

\-- but the psuedo validation of 6,7 necessitate security level explicit
here

if security != 5 and security != 9 then

lib.prolog2(temp,temp2,NULL,r_profile.BGCOLOR);

end if;

remote_addr := owa_util.get_cgi_env(\'REMOTE_ADDR\');

server_name := owa_util.get_cgi_env(\'SERVER_NAME\');

remote_user := owa_util.get_cgi_env(\'REMOTE_USER\');

http_user_agent := owa_util.get_cgi_env(\'HTTP_USER_AGENT\');

\--if i_pid is null then

err_pnt := \'1\';

insert into ows_app_login

(PID,APP_NAME,BADGE_NO,USERNAME,ACCESS_LEVEL,IP,TIMESTAMP,LAST_PAGE,HTTP_USER_AGENT,REMOTE_USER,SERVER_NAME,ATTRIB,USE_COOKIE)

values(NewPID,i_app_name,\'\',\'\',\'\',remote_addr,sysdate,\'LOGIN\',http_user_agent,remote_user,server_name,i_attrib,i_use_cookie);

insert into ows_app_pid_xref

values(NewPID,i_app_name);

err_pnt := \'1A\';

\--INSERT INTO WEB_ERROR_LOG

\--VALUES (\'OWS_APP_LOGIN RECORD CREATED for pid=\' \|\| NewPid);

else

\--redirect to application now

err_pnt := \'1B\';

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"0;URL=../owa/\' \|\|
package_name2(i_app_name)

\|\| \'.\' \|\| return_to_proc2(i_app_name) \|\| \'?i_pid=\' \|\| l_pid

\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

htp.p(\'NO VALIDATION - ATTRIB FOUND\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"0;URL=../owa/\' \|\|
package_name2(i_app_name)

\|\| \'.\' \|\| return_to_proc2(i_app_name) \|\| \'?i_pid=\' \|\| l_pid
\|\| \'\"\>\');

\--tp.p(\'PID is \' \|\| l_pid);

\--tp.p(\'This would refresh here.\');

end if;

return;

end if;

\--end if;

err_pnt := \'2\';

if not validation_required then

\--INSERT INTO WEB_ERROR_LOG values (\'No validation required\');

\--update OWS_APP_LOGIN so IS_VALID_PID works

UPDATE OWS_APP_LOGIN

set ACCESS_LEVEL=\'GRANTED\'

where PID=l_pid;

/\*if last_name_validate then

htp.p(\'last name validate AAA\');

else

htp.p(\'NOT LAST NAME BBB\');

end if;

if anl_login then

htp.p(\'anl login AAA\');

else

htp.p(\'not ANL BBB\');

end if;

if pub_login then

htp.p(\'pub login AAA\');

else

htp.p(\'NOT PUB BBB\');

end if;\*/

if quick_refresh then

\--INSERT INTO WEB_ERROR_LOG VALUES (\'Quick refresh is TRUE\');

null;

else

\--INSERT INTO WEB_ERROR_LOG VALUES (\'Quick refresh is FALSE\');

null;

end if;

if quick_refresh then \--not last_name_validate and not anl_login and
not pub_login then

temp := \'Callling refresh of \' \|\| package_name(l_pid) \|\| \'.\'
\|\| return_to_proc(l_pid);

if i_attrib is NOT NULL then

\--INSERT INTO WEB_ERROR_LOG values (temp);

htp.p(\'\<meta http-equiv=\"refresh\" content=\"0;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\| l_pid

\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

htp.p(\'NO VALIDATION - ATTRIB FOUND\');

else

\--INSERT INTO WEB_ERROR_LOG values (\'No attrib, but calling\' \|\|
temp);

htp.p(\'\<meta http-equiv=\"refresh\" content=\"0;URL=../owa/\' \|\|
package_name(l_pid)

\|\| \'.\' \|\| return_to_proc(l_pid) \|\| \'?i_pid=\' \|\| l_pid \|\|
\'\"\>\');

end if;

htp.p(\'\</BODY\>\');

htp.p(\'\</HTML\>\');

return;

else

\--last name validate

if last_name_validate then

htp.print(\'\<CENTER\>\');

if l_gif != \'NONE\' then

htp.p(\'\<IMG BORDER=0 ALIGN=TOP SRC=\"\' \|\| l_gif \|\| \'\"\>\');

end if;

\--htp.p(r_profile.top_msg);

if r_gif != \'NONE\' then

htp.p(\'\<IMG BORDER=0 ALIGN=TOP SRC=\"\' \|\| r_gif \|\| \'\"\>\');

end if;

htp.formOpen(\'log0002.validate_last_name\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(r_profile.prompt));

htp.tableData(htf.formText(\'i_badge\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Last Name:\'));

htp.tableData(htf.formPassword(\'i_pass\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',NewPID);

htp.formSubmit(\'i_operation\',\'Login\');

htp.formHidden(\'i_app_name\',i_app_name); \--

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

htp.formReset;

htp.formClose;

htp.NL;

htp.NL;

htp.NL;

end if; \-- last name validate

if anl_login then

\--INSERT INTO WEB_ERROR_LOG values (\'ANL LOGIN ATTEMPT\');

htp.formOpen(\'log0002.validate_anl_user\');

htp.centerOpen;

htp.formHidden(\'i_pid\',l_pid);

htp.formHidden(\'i_app_name\',i_app_name);

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'ANL Badge No:\'));

htp.tableData(htf.formText(\'i_badge\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Last Name\'));

htp.tableData(htf.formText(\'i_last_name\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Login\');

\--end if; \--anl login

elsif pub_login then

htp.formOpen(\'log0002.record_pub_user\');

htp.centerOpen;

htp.formHidden(\'i_pid\',l_pid);

htp.formHidden(\'i_app_name\',i_app_name);

htp.formHidden(\'i_attrib\',i_attrib);

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'First Name\'));

htp.tableData(htf.formText(\'i_first_name\',\'30\',\'30\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Last Name\'));

htp.tableData(htf.formText(\'i_last_name\',\'30\',\'30\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Company:\'));

htp.tableData(htf.formText(\'i_company\',\'20\',\'20\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'SS#:\'));

htp.tableData(htf.formText(\'i_ss\',\'20\',\'20\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Phone:\'));

htp.tableData(htf.formText(\'i_phone\',\'20\',\'20\'));

htp.tableRowClose;

\--

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Continue\');

htp.formClose;

\--end if; \--pub login

end if;

\--

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

if not anl_login and not pub_login and r_profile.password_flag=\'Y\'
then

htp.formSubmit(\'i_operation\',\'Change Password\');

end if;

htp.formReset;

htp.formClose;

htp.NL;

htp.NL;

htp.NL;

htp.NL;

\--htp.mailto(\'mis_mgrs@aps.anl.gov\',\'If you have forgotten your web
password, please contact mis_mgrs\');

htp.p(r_profile.bottom_msg);

end if;

else

\-- get user name

htp.print(\'\<CENTER\>\');

if l_gif != \'NONE\' then

htp.p(\'\<IMG BORDER=0 ALIGN=TOP SRC=\"\' \|\| l_gif \|\| \'\"\>\');

end if;

htp.p(r_profile.top_msg);

if r_gif != \'NONE\' then

htp.p(\'\<IMG BORDER=0 ALIGN=TOP SRC=\"\' \|\| r_gif \|\| \'\"\>\');

end if;

\--kem 7/13/99 htp.formOpen(\'log0002.validate_user\');

htp.p(\'\<FORM NAME=\"validate\" ACTION=\"log0002.validate_user\"
METHOD=\"POST\"\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(r_profile.prompt));

\--kem 7/13/99 htp.tableData(htf.formText(\'i_badge\',\'20\',\'20\'));

htp.p(\'\<TD\>\<INPUT NAME=\"i_badge\" TYPE=\"TEXT\" MAXLENGTH=\"20\"
SIZE=\"20\" onExit=document.validate.i_pass.SetFocus\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Password:\'));

htp.tableData(htf.formPassword(\'i_pass\',\'20\',\'20\'));

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',NewPID);

htp.formSubmit(\'i_operation\',\'Login\');

htp.formHidden(\'i_app_name\',i_app_name);

if get_user_group then

htp.formHidden(\'i_group\',user_group);

else

htp.formHidden(\'i_group\',\'FALSE\');

end if;

\--

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

if r_profile.password_flag=\'Y\' then

htp.formSubmit(\'i_operation\',\'Change Password\');

end if;

htp.formReset;

htp.formClose;

htp.NL;

htp.NL;

htp.NL;

\--htp.mailto(\'mis_mgrs@aps.anl.gov\',\'If you have forgotten your web
password, please contact mis_mgrs\');

htp.p(r_profile.bottom_msg);

htp.NL;

htp.NL;

\-- temporary reference for cookies kem 03/22/1999

htp.tableRowOpen;

if nvl(i_use_cookie,\'Y\') != \'N\' then

htp.tableData(\'\<A HREF=\"../../gen-doc/cookiefaq.html\"\>\<FONT
COLOR=\"#0000FF\"\>\<B\>Click Here for Important Notice Regarding
Cookies\</B\>\</FONT\>\</A\>\');

else

htp.tableData(\'This web application does not use cookies.\');

htp.tableRowClose;

end if;

\-- end temporary reference

end if;

if i_operation = \'RETRY\' then

lib.epilog;

end if;

htp.NL;

htp.print(\'\</CENTER\>\');

end if;

exception when others then

temp := \'Unplanned execution aberration in LOGIN at :\' \|\| err_pnt
\|\| \' \' \|\| sqlerrm \|\| \' Date=\' \|\| to_char(sysdate) \|\|\'
Newpid=\' \|\| NEWpid \|\| \' l_pid=\' \|\| l_pid;

htp.p(temp);

\--INSERT INTO WEB_ERROR_LOG

\--values (temp);

end;

end;

\--

function login_ok (i_user in varchar2,i_pass in varchar2) return BOOLEAN
is

begin

declare

cursor c_login (p_user in varchar2,p_pass in varchar2) is

select \'1\'

from GEN_USER_TABLE

where username = p_user

and breaker = p_pass;

result boolean;

temp varchar2(1);

temp_pwd varchar2(255);

begin

\--htp.print (\'user = \' \|\| i_user \|\| \' pass = \' \|\| i_pass);

temp_pwd := log2000.prepare_pwd(i_pass);

\--htp.nl;

\--htp.p(temp_pwd);

open c_login (i_user,temp_pwd);

fetch c_login into temp;

if not c_login%NOTFOUND then

result := TRUE;

\--htp.p(\'ok is true\');

else

result := FALSE;

\--htp.p (\'ok is false\');

end if;

close c_login;

return result;

end;

end;

\--

function last_name_login_ok (i_user in varchar2,i_pass in varchar2)
return BOOLEAN is

begin

declare

/\*cursor c_login (p_user in varchar2,p_pass in varchar2) is

select \'1\'

from VIEW_BADGE_LAST_NAME

where badge_no = p_user

and upper(last_name) = upper(p_pass);\*/

result boolean;

temp varchar2(1);

temp_pwd varchar2(255);

begin

\--htp.print (\'user = \' \|\| i_user \|\| \' pass = \' \|\| i_pass);

/\*open c_login (i_user,i_pass);

fetch c_login into temp;

if not c_login%NOTFOUND then

result := TRUE;

\--htp.p(\'ok is true\');

else

result := FALSE;

\--htp.p (\'ok is false\');

end if;

close c_login;\*/

result := TRUE;

return result;

end;

end;

/\*

function user_in_group (i_group in varchar2,i_user in
varchar2,i_app_name in varchar2 default NULL) return boolean is

begin

declare

cursor c_user_group (p_group in varchar2,p_user in varchar2) is

select \'1\'

from ows_nt_user_group_xref

where username=p_user

and ows_user_group = p_group;

temp varchar2(1);

result boolean;

begin

open c_user_group (i_group,i_user);

fetch c_user_group into temp;

if not c_user_group%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_user_group;

return result;

end;

end;\*/

\--

\--i_user can be a badge number or a unix user name

\--i_group can be the name of the GRANTED_ROLE

\-- or OWS_NT_PACKAGE_PRIV.OWS_PACKAGE value

function user_in_group (i_group in varchar2,i_user in varchar2) return
boolean is

begin

declare

cursor c_get_user (p_badge in varchar2) is

select ltrim(username,\'OPS\$\')

from oracle_badge_numbers

where badge_no = p_badge;

temp_user varchar2(30);

temp_role varchar2(30);

temp varchar2(30);

result boolean;

cursor c_get_role(p_group in varchar2) is

select ows_user_group

from ows_nt_package_priv

where ows_package=p_group;

cursor c_role_ok (p_group in varchar2,p_user in varchar2) is

select \'1\'

from gen_role_privs

where grantee = p_user

and granted_role = p_group;

\--

cursor c_get_gen_user(p_user in varchar2) is

select username

from gen_user_table

where badge_no=p_user;

\--

use_OPS_account boolean;

\--start with granted_role = p_group

\--connect by prior grantee=granted_role;

begin

err_pnt := \'UG1\';

use_OPS_account:=TRUE;

\--get user name if badge number passed, otherwise leave alone

open c_get_user (i_user);

fetch c_get_user into temp_user;

if c_get_user%NOTFOUND then

\--temp_user := i_user;

\--else

\--get username from gen_user_table if not in ORACLE_BADGE_NUMBERS

open c_get_gen_user(i_user);

fetch c_get_gen_user into temp_user;

if not c_get_gen_user%NOTFOUND then

use_OPS_account:=FALSE;

end if;

close c_get_gen_user;

end if;

close c_get_user;

if temp_user is NULL then

temp_user := i_user;

end if;

err_pnt := \'UG2\';

\--get ROLE name if application name was passed

open c_get_role (i_group);

fetch c_get_role into temp_role;

if c_get_role%NOTFOUND then

temp_role := i_group;

end if;

close c_get_role;

err_pnt := \'UG3 temp_role=\' \|\| temp_role \|\| \' temp_user=\' \|\|
temp_user;

if temp_role != \'PUBLIC\' then

\--concatenate the OPS\$ to the name for the gen_role_privs search

if use_OPS_account then

temp_user := \'OPS\$\' \|\| temp_user;

end if;

\--htp.p(\'TEMP ROLE=\' \|\| temp_role \|\| \' temp_user=\' \|\|
temp_user);

open c_role_ok(temp_role,temp_user);

fetch c_role_ok into temp;

if c_role_ok%NOTFOUND then

result := FALSE;

else

result := TRUE;

end if;

close c_role_ok;

else

result := TRUE;

end if;

err_pnt := \'UG4\';

return (result);

EXCEPTION WHEN OTHERS THEN

temp := \'function err: user in group \' \|\| sqlerrm \|\| \' err
point:\' \|\| err_pnt \|\| \' \' \|\| to_char(sysdate);

\--htp.p(temp);

\--INSERT INTO WEB_ERROR_LOG

\--VALUES (temp);

end;

end;

function chk_user_in_group (i_group in varchar2,i_user in varchar2)
return number is

begin

if user_in_group(i_group,i_user) then

return 1;

else

return 0;

end if;

end;

\--

function change_pw (i_pid in varchar2) return boolean is

begin

declare

temp varchar2(1);

cursor c_password(p_pid in varchar2) is

select must_change_pwd

from GEN_USER_TABLE g,ows_app_login a

where a.badge_no = g.badge_no

and a.pid = i_pid;

begin

open c_password(i_pid);

fetch c_password into temp;

if c_password%NOTFOUND then

temp:=\'N\';

end if;

close c_password;

\--htp.print (\'PW CHANGE VALUYE is \' \|\| temp);

if temp = \'Y\' then

return TRUE;

else

return FALSE;

end if;

end;

end;

\--

procedure validate_user (i_badge in varchar2,

i_pass in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_group in varchar2 default \'FALSE\',

i_attrib in varchar2 default NULL) is

begin

declare

cursor c_user (p_badge in varchar2) is

select username

from GEN_USER_TABLE

where badge_no = p_badge;

cursor c_revalidate_user (p_pid in varchar2) is

select v.username,l.badge_no

from GEN_USER_TABLE v,ows_app_login l

where v.username = l.username

and l.pid = p_pid;

cursor c_retry(p_pid in varchar2) is

select ATTRIB,USE_COOKIE

from OWS_APP_LOGIN

where PID=p_pid;

temp_user varchar2(15);

must_change varchar2(1);

temp_badge varchar2(10);

temp_badge2 varchar2(10);

local_operation varchar2(20);

grp_authenticated boolean;

revalidate boolean;

l_attrib OWS_APP_LOGIN.ATTRIB%TYPE;

l_use_cookie OWS_APP_LOGIN.USE_COOKIE%TYPE;

begin

\--validate pid

\--temp_badge := lpad(i_badge,5,\'0\');

if i_badge is null or i_pass is NULL then

htp.p(\'Please enter your badge number and web password before
attempting to access this system.\');

htp.NL;

htp.p(\'Your web password is not your unix password. \');

htp.NL;

htp.p(\'Please contact \<A
HREF=\"mailto:mis_mgrs@aps.anl.gov\"\>mis_mgrs\</a\> if you do not know
it or do not remember it.\');

htp.NL;

htp.NL;

htp.p(\'\<h3\>Click \[BACK\] to return to the login screen.\</h3\>\');

else

err_pnt := \'VU1\';

if i_operation != \'REVALIDATE\' then

open c_user(i_badge);

fetch c_user into temp_user;

close c_user;

revalidate := FALSE;

temp_badge := i_badge;

else

open c_revalidate_user(i_pid);

fetch c_revalidate_user into temp_user,temp_badge;

close c_revalidate_user;

revalidate := TRUE;

end if;

err_pnt := \'VU2\';

if i_group != \'FALSE\' then

grp_authenticated := user_in_group(i_app_name,temp_user);

end if;

err_pnt := \'VU3\';

if (i_group=\'FALSE\' or grp_authenticated) then

local_operation := i_operation;

if not (login_ok(temp_user,i_pass) or revalidate) then

update ows_app_login

set badge_no = i_badge,

username = temp_user,

access_level = \'DENIED\',

log_out_date=sysdate

where pid = i_pid;

htp.NL;

\--remove cookie

\--login(i_app_name,\'RETRY\');

\--i_app_name in varchar2,

\-- i_operation in varchar2 default null,

\-- i_pid in varchar2 default NULL,

\-- i_attrib in varchar2 default NULL,

\-- i_use_cookie in varchar2 default NULL);

open c_retry(i_pid);

fetch c_retry into l_attrib,l_use_cookie;

close c_retry;

lib.prolog(\'Sorry, Authorization Failed\');

htp.centerOpen;

htp.p(\'\<FONT SIZE=+3\>To try again, please click the link
below:\</font\>\');

htp.NL;

htp.NL;

htp.p(\'\<A HREF=\"log0002.login?i_app_name=\' \|\| i_app_name \|\|
\'&i_operation=Login&i_attrib=\' \|\| l_attrib \|\| \'&i_use_cookie=\'
\|\| l_use_cookie \|\| \'\"\> Click here to return to login screen.\');

htp.centerClose;

htp.p(\'\</BODY\>\</HMTL\>\');

else

update ows_app_login

set username = temp_user,

badge_no = temp_badge,

access_level = \'GRANTED\'

where pid = i_pid;

\--return to calling package

\--htp.p (\'User authenticated\');

if (i_operation=\'Login\' and not change_pw(i_pid)) or revalidate then

htp.htmlOpen;

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\| \'?i_pid=\' \|\| i_pid

\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\| \'?i_pid=\' \|\| i_pid \|\|
\'\"\>\');

end if;

\-- htp.NL;

\--htp.NL;

\--htp.NL;

\--htp.NL;

\--htp.print(\'\<h2\>\<strong\>\<center\>Authenticating user
privileges\... One moment please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end if;

err_pnt := \'VU4\';

if change_pw(i_pid) or i_operation=\'Change Password\' then

\--htp.p(\'get new pw\');

get_new_pw(i_pid,i_attrib);

end if;

end if;

else

err_pnt := \'VU5\';

htp.p(\'User name is \' \|\| temp_user);

htp.p(\'Group is \' \|\| i_group);

htp.p(\'You are not on the user list for the requested system.\');

end if;

end if; \-- if i_badge is null

EXCEPTION when others then

temp := sqlerrm \|\| \'\...Err pnt=\' \|\| err_pnt \|\| \' \' \|\|
to_char(sysdate);

\--htp.p(\'EXCEPTION in VALIDATE_USER:\' \|\| temp);

\--INSERT INTO WEB_ERROR_LOG

\--values (\'Validate user exception:\' \|\| temp);

end;

end;

\--

procedure validate_last_name (i_badge in varchar2,

i_pass in varchar2,

i_pid in varchar2,

i_operation in varchar2 default null,

i_app_name in varchar2 default null,

i_group in varchar2 default \'FALSE\',

i_attrib in varchar2 default NULL) is

begin

declare

cursor c_user (p_badge in varchar2) is

select username

from GEN_USER_TABLE

where badge_no = p_badge;

cursor c_revalidate_user (p_pid in varchar2) is

select v.username,l.badge_no

from GEN_USER_TABLE v,ows_app_login l

where v.username = l.username

and l.pid = p_pid;

temp_user varchar2(15);

must_change varchar2(1);

temp_badge varchar2(10);

temp_badge2 varchar2(10);

local_operation varchar2(20);

grp_authenticated boolean;

revalidate boolean;

begin

\--validate pid

\--temp_badge := lpad(i_badge,5,\'0\');

if i_operation != \'REVALIDATE\' then

\--open c_user(i_badge);

\--fetch c_user into temp_user;

\--close c_user;

revalidate := FALSE;

\--temp_badge := i_badge;

\--else

\--open c_revalidate_user(i_pid);

\--fetch c_revalidate_user into temp_user,temp_badge;

\--close c_revalidate_user;

revalidate := TRUE;

end if;

/\*if i_group != \'FALSE\' then

grp_authenticated := user_in_group(i_app_name,temp_user);

end if;\*/

\--if (i_group=\'FALSE\' or grp_authenticated) then

local_operation := i_operation;

if not (last_name_login_ok(i_badge,i_pass)) then \--or revalidate then

update ows_app_login

set badge_no = i_badge,

username = temp_user,

access_level = \'DENIED\'

where pid = i_pid;

htp.NL;

login(i_app_name,\'RETRY\');

else

update ows_app_login

set username = temp_user,

badge_no = temp_badge,

access_level = \'GRANTED\'

where pid = i_pid;

\--return to calling package

if (i_operation=\'Login\') then

htp.htmlOpen;

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\| \'?i_pid=\' \|\| i_pid

\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\| \'?i_pid=\' \|\| i_pid \|\|
\'\"\>\');

end if;

htp.NL;

htp.NL;

htp.NL;

htp.NL;

htp.print(\'\<h2\>\<strong\>\<center\>Authenticating user privileges\...
One moment please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end if;

end if;

\--else

\--htp.p(\'User name is \' \|\| temp_user);

\--htp.p(\'Group is \' \|\| i_group);

\--htp.p(\'You are not on the user list for the requested system.\');

\--end if;

end;

end;

\--

\-- post password change

procedure post_pwd_change (i_pid in varchar2,

i_attrib in varchar2 default NULL) is

begin

htp.htmlOpen;

if i_attrib is NOT NULL then

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\|
\'?i_pid=\'\|\|i_pid\|\|\'&i_attrib=\'\|\|i_attrib\|\|\'\"\>\');

else

htp.p(\'\<meta http-equiv=\"refresh\" content=\"2;URL=../owa/\' \|\|
package_name(i_pid)

\|\| \'.\' \|\| return_to_proc(i_pid) \|\| \'?i_pid=\' \|\| i_pid \|\|
\'\"\>\');

end if;

htp.NL;

htp.NL;

htp.NL;

htp.print(\'\<h2\>\<strong\>\<center\>One moment
please\...\</center\>\</strong\>\</h2\>\');

htp.htmlClose;

end;

\--

\--user already validated before this procedure

procedure get_new_pw (i_pid in varchar2,

i_attrib in varchar2 default NULL) is

begin

if is_valid_pid(i_pid,\'ANY\') then

lib.Prolog(\'Change Password\');

htp.print(\'\<CENTER\>\');

htp.formOpen(\'../owa/log0002.change_password\');

if change_pw(i_pid) then

htp.p(\'\<h2\>\<font color=#ff0000\>Your password has been
reset.\</font\>\');

htp.NL;

htp.p(\'\<font color=#006010\>Please select a new password
now.\</font\>\</h2\>\');

end if;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'New password:\'));

htp.tableData(htf.formPassword(\'i_new_pw\',\'15\',\'15\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Re-enter new password:\'));

htp.tableData(htf.formPassword(\'i_new_pw2\',\'15\',\'15\'));

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

htp.formSubmit(\'i_operation\',\'Change\');

htp.formSubmit(\'i_operation\',\'Cancel\');

htp.formClose;

htp.print(\'\</CENTER\>\');

lib.epilog;

end if;

end;

procedure change_password (i_operation in varchar2,

i_pid in varchar2,

i_new_pw in varchar2,

i_new_pw2 in varchar2,

i_attrib in varchar2 default NULL) is

begin

declare

upd_badge varchar2(10);

cursor c_badge (p_pid in varchar2) is

select \*

from ows_app_login

where pid=p_pid;

cursor c_must_change is

select MUST_CHANGE_PWD

from GEN_USER_TABLE gut, OWS_APP_LOGIN oal

where gut.USERNAME=oal.USERNAME

and pid=i_pid;

r_badge c_badge%ROWTYPE;

temp_badge varchar2(20);

l_breaker GEN_USER_TABLE.BREAKER%TYPE;

temp varchar2(1);

l_must_change BOOLEAN;

begin

open c_badge(i_pid);

fetch c_badge into r_badge;

close c_badge;

temp_badge := r_badge.BADGE_NO;

if is_valid_pid(i_pid,\'ANY\') then

lib.prolog(\'Password Change Confirmation\');

htp.centerOpen;

htp.TableOpen;

htp.TableRowOpen;

l_must_change := FALSE;

\--set must change flag if necessary

open c_must_change;

fetch c_must_change into temp;

if temp=\'Y\' then

l_must_change := TRUE;

end if;

close c_must_change;

\--validate change within rules (no repeat pwd from 90 days..must
change)

if i_operation = \'Change\' and pwd_change_ok(i_pid,i_new_pw,i_new_pw2)
then \--(i_new_pw = i_new_pw2) then

\--HTP.P(\'BADGE NO is \' \|\| temp_badge);

l_breaker := log2000.prepare_pwd(i_new_pw);

update GEN_USER_TABLE

set breaker=l_breaker,

must_change_pwd = \'N\'

where badge_no = temp_badge;

COMMIT;

\--update pwd history

INSERT INTO OWS_PWD_HIST

(PWD_HIST_ID,USERNAME,BADGE_NO,PWD,MOD_DATE)

VALUES

(ows_pwd_hist_seq.NEXTVAL,r_badge.USERNAME,r_badge.BADGE_NO,l_breaker,sysdate);

htp.print(\'Your password has been successfully changed.\');

l_must_change := FALSE;

htp.NL;

htp.NL;

else

htp.p(\'\<FONT FACE=\"ARIAL,HELVETICA,TACOMA\" size=\"4\"\>Your password
has\</font\> \');

htp.p(\'\<FONT FACE=\"ARIAL,HELVETICA,TACOMA\" size=\"4\"
COLOR=\"#FF0000\"\>NOT \</font\>\');

htp.p(\'\<FONT FACE=\"ARIAL,HELVETICA,TACOMA\" size=\"4\"\>been
changed.\</font\>\');

htp.NL;

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=\"LEFT\"\>\<FONT FACE=\"ARIAL,HELVETICA,TACOMA\"
size=\"4\" COlOR=\"#000000\"\>\<UL\>Please note the following rules for
choosing your password:\</font\>\</TD\>\</TR\>\');

htp.p(\'\<TR\>\<TD ALIGN=\"LEFT\"\>\<FONT
FACE=\"ARIAL,HELVETICA,TACOMA\" size=\"4\"
COlOR=\"#0000FF\"\>\<LI\>Please don\'\'t re-use your current
password.\');

htp.p(\'\<LI\>Recently used passwords may not be used.\');

htp.p(\'\<LI\>Please do not use your UNIX or NT password.\');

htp.p(\'\<LI\>Please enter the same password in each box on the previous
screen.\');

htp.p(\'\<LI\>Your password must differ from your badge
number.\</FONT\>\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.NL;

htp.tableOpen;

htp.tableRowOpen;

htp.formOpen(\'../owa/log0002.get_new_pw\');

htp.formHidden(\'i_pid\',i_pid);

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

htp.tableData(

htf.formSubmit(\'\',\'Try Again\'));

htp.formClose;

end if;

if NOT l_must_change then

htp.formOpen(\'../owa/log0002.post_pwd_change\');

htp.formHidden(\'i_pid\',i_pid);

if i_attrib is NOT NULL then

htp.formHidden(\'i_attrib\',i_attrib);

end if;

htp.tableData(htf.formSubmit(\'\',\'Continue\'));

end if; \-- change ok

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

/\*

if i_attrib is NOT NULL then

htp.formHidden(

htp.anchor(\'../owa/\' \|\| package_name(i_pid) \|\| \'.\' \|\|
return_to_proc(i_pid) \|\|\'?i_pid=\'

\|\| i_pid \|\|\'&\' \|\| i_attrib,\'Continue\');

else

htp.anchor(\'../owa/\' \|\| package_name(i_pid) \|\| \'.\' \|\|
return_to_proc(i_pid) \|\|\'?i_pid=\'

\|\| i_pid,\'Continue\');

end if;

\*/

lib.epilog;

end if;

end;

end;

END;

/

CREATE OR REPLACE PACKAGE log2000

IS

pkg_name varchar2(255) := \'ps0001\';

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

function omzetten (source_text in varchar2,mask in varchar2) return
varchar2;

pragma restrict_references(omzetten,WNDS);

function afkode (source_text in varchar2,mask in varchar2) return
varchar2;

pragma restrict_references(afkode,WNDS);

function prepare_pwd (i_source_text in varchar2) return varchar2;

pragma restrict_references(prepare_pwd,WNDS);

function return_pwd (i_source_text in varchar2) return varchar2;

pragma restrict_references(return_pwd,WNDS);

function reset_pwd (i_badge_no in varchar2) return varchar2;

\--pragma restrict_references(reset_pwd,WNDS);

function prepare_pid (i_source_text in varchar2) return varchar2;

pragma restrict_references(prepare_pid,WNDS);

function return_pid (i_source_text in varchar2) return varchar2;

pragma restrict_references(return_pid,WNDS);

function prepare_badge (i_source_text in varchar2) return varchar2;

pragma restrict_references(prepare_badge,WNDS);

function return_badge (i_source_text in varchar2) return varchar2;

pragma restrict_references(return_badge,WNDS);

END log2000;

/

CREATE OR REPLACE PACKAGE BODY log2000 IS

MASK constant varchar2(25) := \'14MONKey7Snif29b3q\';

pwd_mask constant varchar2(255)
:=\'t%h\$er23t\$#@Stren34gth\*()%chi\$#&;gung58669\';

pid_mask constant varchar2(255) :=
\'gfd8435%dfg0\<\"234453098432sdfsew28923fsdfwe\';

badge_mask constant varchar2(255) := \'h\*oun\*&@#%d0g\';

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

\--

function hexchar(hexdigit in number) return varchar2 is

result varchar2(2);

temp number;

begin

temp := floor(hexdigit/16);

if (temp \<= 9) then

result := to_char(temp);

elsif temp=10 then

result := \'A\';

elsif temp=11 then

result := \'B\';

elsif temp=12 then

result := \'C\';

elsif temp=13 then

result := \'D\';

elsif temp=14 then

result:=\'E\';

else

result := \'F\';

end if;

temp := mod(hexdigit,16);

if (temp \<= 9) then

result := result \|\| to_char(temp);

elsif temp=10 then

result := result \|\| \'A\';

elsif temp=11 then

result := result \|\| \'B\';

elsif temp=12 then

result := result \|\| \'C\';

elsif temp=13 then

result := result \|\| \'D\';

elsif temp=14 then

result:= result \|\|\'E\';

else

result := result \|\| \'F\';

end if;

return(result);

end;

\--

function string_to_ascii(string in varchar2) return varchar2 is

ctr number;

result varchar2(255);

thischar varchar2(3);

thisnum number;

hex varchar2(2);

begin

result := \'\';

for ctr in 1..length(string) loop

thisnum := ascii(substr(string,ctr,1));

hex := hexchar(thisnum);

result := result \|\| hex;

end loop;

return(result);

end;

\--

function to_decimal(hexstring in varchar2) return number is

char_result varchar2(3);

temp number;

result number;

begin

char_result:= substr(hexstring,1,1);

if char_result = \'F\' then

temp := 15;

elsif char_result =\'E\' then

temp :=14;

elsif char_result = \'D\' then

temp :=13;

elsif char_result = \'C\' then

temp := 12;

elsif char_result =\'B\' then

temp := 11;

elsif char_result =\'A\' then

temp := 10;

else

temp := to_number(char_result);

end if;

result := temp \* 16;

char_result := substr(hexstring,2,1);

if char_result = \'F\' then

temp := 15;

elsif char_result =\'E\' then

temp :=14;

elsif char_result = \'D\' then

temp :=13;

elsif char_result = \'C\' then

temp := 12;

elsif char_result =\'B\' then

temp := 11;

elsif char_result =\'A\' then

temp :=10;

else

temp := to_number(char_result);

end if;

result := result + temp;

return(result);

end;

\--

function ascii_to_string(string in varchar2) return varchar2 is

ctr number;

thischar varchar2(2);

thischar2 varchar2(2);

thisnum number;

result varchar2(255);

begin

for ctr in 1..length(string) loop

if MOD(ctr,2) = 1 then

thischar := substr(string,ctr,1);

else

\--mod 0 so this is the 16\'s place, not the 16 \^ 2 digit

thischar := thischar \|\| substr(string,ctr,1);

thischar2 := chr(to_decimal(thischar));

result := result \|\| thischar2;

end if;

end loop;

return (result);

end;

\--

function convbin(c1 in varchar2) return varchar2 is

loop1 number;

value number;

divis number;

r1 varchar2(30);

begin

r1 := \'\';

value := ascii(c1);

divis := 128;

for loop1 in 0..7 loop

if trunc(value/divis) = 1 then

r1 := r1 \|\| \'1\';

else

r1 := r1 \|\| \'0\';

end if;

value := value mod divis;

divis := divis / 2;

end loop;

return r1;

end;

\--

function binrep (hex in varchar2) return varchar2 is

result varchar2(4);

begin

if hex=\'F\' then

result := \'1111\';

elsif hex=\'E\' then

result :=\'1110\';

elsif hex=\'D\' then

result := \'1101\';

elsif hex=\'C\' then

result:=\'1100\';

elsif hex=\'B\' then

result :=\'1011\';

elsif hex=\'A\' then

result := \'1010\';

elsif hex =\'9\' then

result :=\'1001\';

elsif hex=\'8\' then

result := \'1000\';

elsif hex=\'7\' then

result := \'0111\';

elsif hex=\'6\' then

result :=\'0110\';

elsif hex=\'5\' then

result :=\'0101\';

elsif hex=\'4\' then

result := \'0100\';

elsif hex=\'3\' then

result :=\'0011\';

elsif hex=\'2\' then

result :=\'0010\';

elsif hex=\'1\' then

result := \'0001\';

else

result := \'0000\';

end if;

return(result);

end;

\--

function bintohex(binstring in varchar2) return varchar2 is

\--get decimal then convert decimal to hex with hexchar

temp number;

result varchar2(1);

begin

temp := 0;

if substr(binstring,1,1) = \'1\'

then temp := temp + 8;

end if;

if substr(binstring,2,1) = \'1\'

then temp := temp + 4;

end if;

if substr(binstring,3,1) = \'1\'

then temp := temp + 2;

end if;

if substr(binstring,4,1) = \'1\'

then temp := temp + 1;

end if;

if (temp \<= 9) then

result := to_char(temp);

elsif temp=10 then

result := \'A\';

elsif temp=11 then

result := \'B\';

elsif temp=12 then

result := \'C\';

elsif temp=13 then

result := \'D\';

elsif temp=14 then

result:=\'E\';

else

result := \'F\';

end if;

return (result);

end;

\--recieves two hex \"digits\" and XORs them (0..F)

function XORCHAR(c1 in varchar2, c2 in varchar2) return varchar2 is

i number;

bin1 varchar2(4);

bin2 varchar2(4);

together varchar2(2);

binresult varchar2(4);

result varchar2(1);

begin

bin1 := binrep(c1);

bin2 := binrep(c2);

binresult := \'\';

for i in 1..4 loop

together := substr(bin1,i,1) \|\| substr(bin2,i,1);

if together = \'01\' or together = \'10\' then

binresult := binresult \|\| \'1\';

else

binresult := binresult \|\| \'0\';

end if;

end loop;

result := bintohex(binresult);

return(result);

end;

\--

function XORBIN (c1 in varchar2,c2 in varchar2,c1_convert in varchar2
default NULL) return varchar2 is

i number;

j number;

ascii1 varchar2(255);

ascii2 varchar2(255);

result varchar2(512);

tempchar varchar2(2);

begin

if nvl(c1_convert,\'Y\')=\'Y\' then

ascii1 := string_to_ascii(c1);

else

ascii1 := c1;

end if;

ascii2 := string_to_ascii(c2);

/\*htp.NL;

htp.p(\'ascii1 is \' \|\| ascii1);

htp.NL;

htp.p(\'ascii2 is \' \|\| ascii2);

htp.NL;\*/

for i in 1..length(ascii1) loop

tempchar := XORCHAR(substr(ascii1,i,1),substr(ascii2,i,1));

result := result \|\| tempchar;

end loop;

\--htp.p(\'XORed RESULT is \' \|\| result);

return (result);

end;

\--

\--

function convertPID(i_pid in varchar2) return varchar2 is

begin

declare

len number;

temp_pid varchar2(512);

l_pid varchar2(512);

begin

\-- htp.p(\'PID CONVERSION beginning\');

len := length(i_pid);

\--temp_pid := substr(i_pid,1,len - 5);

len := length(temp_pid);

\--temp_pid := substr(temp_pid,6,len-5);

\--now remove mask

\--\_pid := XORBIN(temp_pid,MASK);

\--l_pid := ascii_to_string(XORBIN(i_pid,MASK));

\--l_pid := ascii_to_string(i_pid);

l_pid := XORBIN(i_pid,MASK,\'Y\');

\--htp.p(\'Decoded PID is \' \|\| l_pid);

\--htp.NL;

return(l_pid);

exception

when others then

htp.p(\'Exception in PID cnversion\');

end;

end;

\--

function omzetten (source_text in varchar2, mask in varchar2) return
varchar2 is

\--omzetten is Dutch for hide or encode or something

begin

declare

result varchar2(512);

begin

result := XORBIN(source_text,mask,\'Y\');

return result;

end;

end;

\--

function afkode (source_text in varchar2, mask in varchar2) return
varchar2 is

\--afkode is Danish for decode

begin

declare

result varchar2(512);

begin

result:= ascii_to_string(XORBIN(source_text,mask,\'N\'));

\--result:= XORBIN(source_text,mask,\'N\');

return result;

end;

end;

\--

function return_pwd (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := afkode(i_source_text,pwd_mask);

return result;

end;

end;

\--

function prepare_pwd (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := omzetten(i_source_text,pwd_mask);

return result;

end;

end;

\--

function return_pid (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := afkode(i_source_text,pid_mask);

return result;

end;

end;

\--

function prepare_pid (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := omzetten(i_source_text,pid_mask);

return result;

end;

end;

\--

function return_badge (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := afkode(i_source_text,badge_mask);

return result;

end;

end;

\--

function prepare_badge (i_source_text in varchar2) return varchar2 is

begin

declare

result varchar2(255);

begin

result := omzetten(i_source_text,badge_mask);

return result;

end;

end;

\--

procedure test1 is

begin

htp.p(\'\<HTML\>\');

htp.formOpen(\'log2000.test2\');

htp.formText(\'i_value\');

htp.formSubmit;

htp.formClose;

htp.p(\'\</HTML\>\');

end;

\--

procedure test2 (i_value in varchar2) is

begin

declare

mask varchar2(512);

temp varchar2(512);

err_pnt varchar2(128);

begin

mask := \'0000000000000\';

htp.p(\'\<HTML\>\');

htp.p(\'Original: \' \|\| i_value);

htp.NL;

err_pnt := \'No point\';

temp := omzetten(i_value,mask);

err_pnt := \'Omzetten OK\';

htp.p(\'Encoded: \'\|\| temp);

htp.NL;

htp.p(\'Decoded: \' \|\| afkode(temp,mask));

err_pnt := \'Over done with\';

htp.p(\'\</HTML\>\');

exception

when others then

htp.p(\'Error point is \' \|\| err_pnt);

end;

end;

\--

function deConvertPID(i_pid in varchar2) return varchar2 is

begin

declare

len number;

temp_pid varchar2(512);

l_pid varchar2(512);

begin

htp.p(\'in deConvert\');

htp.NL;

len := length(i_pid);

htp.p(\'PID is \' \|\| i_pid);

\--len := length(temp_pid);

l_pid := XORBIN(i_pid,MASK,\'N\');

htp.p(\'l_pid is \' \|\| l_pid);

l_pid := ascii_to_string(l_pid);

\--htp.NL;

return(l_pid);

exception

when others then

htp.p(sqlerrm);

htp.NL;

htp.p(\'Exception in PID conversion (1)\');

end;

end;

/\* function change_pw (i_pid in varchar2) return boolean is

begin

declare

temp varchar2(1);

cursor c_password(p_pid in varchar2) is

select must_change_pwd

from TEMP_USER_TABLE g,ows_app_login a

where a.badge_no = g.badge_no

and a.pid = i_pid;

begin

open c_password(convertPID(i_pid));

fetch c_password into temp;

if c_password%NOTFOUND then

temp:=\'N\';

end if;

close c_password;

\--htp.print (\'PW CHANGE VALUYE is \' \|\| temp);

if temp = \'Y\' then

return TRUE;

else

return FALSE;

end if;

end;

end;\*/

\--

function reset_pwd (i_badge_no in varchar2) return varchar2 is

begin

update GEN_USER_TABLE

set breaker=prepare_pwd(i_badge_no),

must_change_pwd=\'Y\'

where badge_no=i_badge_no;

return (i_badge_no \|\| \' has been reset,\');

end;

\--

END;

/

CREATE OR REPLACE PACKAGE tm0002 IS

\--

\-- Modification History

\--

\-- Date Initials Remarks

\--
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- 25-SEP-96 kem Initial Coding

\-- 10-JAN-97 kem Added coordinator to search

\-- 13-JAN-97 kem Explicitly state labor and material separately

\-- 21-JAN-97 kem Added 75% switch for Technical Supervisors

\-- 06-FEB-97 kem Fix open/closed SRO selection

\-- 03-MAR-97 kem Next-N capability. Converted query to dbms_sql.

\-- 16-APR-97 kem Add cost code as selection criteria if badge in
TM_SRO_FINANCE_ACCESS

\-- 16-APR-97 kem Cost code selection criteria for financial people

\-- 04-DEC-98 kem Convert to standard web security mechanuim

\-- 07-APR-99 kem Security per SRO for RF SRO records\...SRO_RF_ADMIN is
unrestricted

\-- SRO_RF_USER can see RF records they create themselves, no one else

\-- can see any RF records Added is_sro_visible functionality

\-- 20-JUL-99 kem Modify to allow for new sequences: KB, JH and TO

\-- 23-AUG-99 kem Extend security to look at new field COORDINATOR badge
as well as

\-- REQUESTER_BADGE

\-- 26-AUG-99 kem Add procedure RUN_INVOICE_SUMMARY to replace Menu 50
report runner

\-- and accomodate new sequences

pkg_name varchar2(255) := \'tm0002\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

pkg_syn varchar2(255) := pkg_name; \-- \|\|\'s\';

ping varchar2(255) := pkg_name\|\|\' is alive\';

fancy_background boolean := false;

\--

override_authentication boolean := true;

\--

\--function is_coordinator (i_pid in number) return boolean;

\--

\--login procedure remains for backward compatibility with bookmarks &
links

\-- official start point is now start_page 4/8/99 kem

procedure login(i_pid in varchar2 default \'NEW\');

procedure start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL);

procedure sro_selection(i_pid in varchar2);

procedure sro_contract_detail (isearchstr in varchar2,i_pid in
varchar2);

procedure sro_summary (i_sro_type in varchar2,i_sro_status in
varchar2,i_badge in varchar2 default null,

i_coordinator in varchar2,i_organization in varchar2,i_pid in
varchar2,i_user_type in varchar2 default \'USER\',

i_password in varchar2 default null,i_75_switch in varchar2 default
null,i_sro_no in varchar2 default null,

Z_START in varchar2,Z_ACTION in varchar2,Z_RECORD_SET_SIZE in varchar2
default \'100\',

Z_TOTAL_ROWS in varchar2 default NULL,i_cost_account in varchar2 default
NULL,

i_cost_center in varchar2 default NULL,i_cost_element in varchar2
default NULL);

procedure sro_invoice_detail (i_sro_no in varchar2,i_invoice in
varchar2,i_pid in varchar2);

procedure sro_labor_summary_detail (i_sro_no in varchar2,i_pid in
varchar2,i_operation in varchar2 default null);

procedure run_print_it (i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,i_type in varchar2,

i_start_mo in varchar2,i_start_yr in varchar2,

i_end_mo in varchar2,i_end_yr in varchar2,i_pid in varchar2);

procedure sro_report_selection (i_pid in varchar2);

procedure run_invoice_summary (i_printer in varchar2 default
\'werther\',

i_operation in varchar2 default NULL,i_sro_type in varchar2 default
\'ALL\',

i_contract in varchar2 default \'ALL\',

i_sro_seq in varchar2 default \'ALL\',

i_pid in varchar2);

END;

/

CREATE OR REPLACE PACKAGE BODY tm0002 IS

prolog_done boolean;

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

MAX_ROWS constant number(4) := 1000;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|
\') returned\');

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

\--

function is_me (who in varchar2) return boolean is

begin

if who = upper(owa_util.get_cgi_env(\'remote_user\')) then

return true;

end if;

return false;

end;

\--

function is_webstation return boolean is

begin

if owa_util.get_cgi_env(\'http_user_agent\') like

\'%WebStation%\' then

return true;

end if;

return false;

end;

\--

function webstation_hook (c in varchar2) return varchar2 is

begin

if is_webstation then

return \'method=\"csp:script\" action=\"c:\\travel\\\'

\|\| c \|\| \'\"\';

end if;

return null;

end;

\--

function badge_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(5);

cursor c_badge(p_pid in varchar2) is

select badge_no

from ows_app_login

where pid=p_pid;

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'?????\';

end if;

close c_badge;

return result;

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

return(log0002.is_valid_pid(i_pid,\'SRO_COORD\',1));

end;

\--

function has_role (i_pid in varchar2, role_in in varchar2) return
boolean is

\--

cursor c_username(p_badge in varchar2) is

select username

from oracle_badge_numbers

where badge_no=p_badge;

\--

cursor c_role(user_name in varchar2) is

select \'1\'

from gen_role_privs

where grantee = user_name

and granted_role = role_in;

\--

username varchar2(25);

temp varchar2(1);

l_badge varchar2(10);

result boolean;

begin

result := FALSE;

l_badge := badge_for_this_pid(i_pid);

open c_username(l_badge);

fetch c_username into username;

if not c_username%NOTFOUND then

open c_role(username);

fetch c_role into temp;

if not c_role%NOTFOUND then

result := TRUE;

end if;

close c_role;

end if;

close c_username;

return result;

end;

\--

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

function has_view_role (i_pid in varchar2, role_in in varchar2) return
boolean is

cursor get_username(pid varchar2) is

select username

from oracle_badge_numbers

where badge_no = pid

and rollup is null;

cursor get_role(user_name varchar2) is

select \*

from gen_role_privs

where grantee = user_name

and granted_role = role_in;

user_rec get_username%rowtype;

role_rec get_role%rowtype;

begin

open get_username(i_pid);

fetch get_username into user_rec;

for role_rec in get_role(user_rec.username) loop

if get_role%found then

close get_username;

return TRUE;

end if;

end loop;

return FALSE;

end;

\--

\-- 23-AUG-99 REQUESTER_BADGE is author - extneded for COORDINATOR badge
too

function is_sro_author(i_pid in varchar2,i_sro_no in varchar2) return
boolean is

cursor c_author_badge is

select REQUESTER_BADGE

from TM_SRO_HEADER

where SRO_NO=i_sro_no;

cursor c_coord_badge is

select COORDINATOR_BADGE

from TM_SRO_HEADER

where sro_no=i_sro_no;

l_badge varchar2(10);

author_badge varchar2(10);

coord_badge varchar2(10);

result boolean;

begin

l_badge := badge_for_this_pid(i_pid);

\--only turns true if COORD or REQUESTER

result := FALSE;

open c_author_badge;

fetch c_author_badge into author_badge;

if c_author_badge%NOTFOUND then

author_badge := \'\';

end if;

close c_author_badge;

open c_coord_badge;

fetch c_coord_badge into coord_badge;

if c_coord_badge%NOTFOUND then

coord_badge := \'\';

end if;

close c_coord_badge;

if (l_badge=author_badge) or (l_badge=coord_badge) then

result := TRUE;

end if;

return(result);

end;

\--

function is_sro_visible(i_pid in varchar2,i_sro_no in varchar2) return
boolean is

l_sro_type varchar2(2);

l_coord_badge varchar2(10);

result boolean;

begin

result := FALSE;

l_sro_type := substr(i_sro_no,1,2);

if l_sro_type=\'FO\' or l_sro_type=\'TO\' or l_sro_type=\'JH\' then

result := TRUE;

else \--RF SRO security feature for RF and KB SRO\'s

if has_role(i_pid,\'SRO_RF_ADMIN\') then

result := TRUE;

else

if has_role(i_pid,\'SRO_RF_USER\') and is_sro_author(i_pid,i_sro_no)
then

result := TRUE;

end if;

end if;

end if;

return(result);

end;

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

PROCEDURE run_print_it (i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,i_type in varchar2,

i_start_mo in varchar2,i_start_yr in varchar2,

i_end_mo in varchar2,i_end_yr in varchar2,i_pid in varchar2) IS

begin

declare

STR varchar2(255);

return_status varchar2(255);

tmp_cs varchar2(2000);

begin

lib.prolog (\'SRO Print Chart\');

if is_valid_pid(i_pid) then

STR := \'tm/tm\';

mis_util.utl_print_it(\'\$mis_reports/\',\'tm_charts\',\'B\',\'NONE\',\'P\',\'SQR\',STR,\'NONE\',

i_type,i_start_mo,i_start_yr,i_end_mo,i_end_yr,\'NONE\',\'NONE\',\'NONE\',return_status);

\--message(\'return_status:\'\|\|return_status);

if return_status = \'status:0\' then

htp.print (\' Chart successfully sent to printer \"\' \|\| i_printer
\|\| \'\"\');

else

htp.print (\'Print Request Failed. Print daemon may be down.\');

end if;

else

htp.Print (\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

end;

END;

\--

function is_coord (i_pid in varchar2) return BOOLEAN is

begin

return(has_role(i_pid,\'SRO_USER\'));

end;

\--

function is_admin(i_pid in varchar2) return BOOLEAN is

begin

return(has_role(i_pid,\'SRO_ADMIN\'));

end;

\--

procedure login (i_pid in varchar2 default \'NEW\') is

begin

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'SRO_COORD\') then

log0002.login(\'SRO_COORD\',\'\',i_pid);

return;

end if;

sro_selection(i_pid);

end;

end;

\--

procedure start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, \'SRO_COORD2\') then

log0002.login(\'SRO_COORD2\',\'\',i_pid,i_attrib);

return;

end if;

\--

\-- Goes to the single sro viewing procedure

\-- if iattrib is empty, go to selection screen

\-- otherwise go drectly to detail screen

if i_attrib is not null then

htp.p(\'\<meta http-equiv=\"refresh\"
content=\"2;URL=tm0002.sro_contract_detail?isearchstr=\'\|\| i_attrib

\|\| \'&\' \|\| \'i_pid=\' \|\| i_pid\|\|\'\"\>\');

else

sro_selection(i_pid);

end if;

\--

end;

\--

procedure sro_selection (i_pid in varchar2)is

begin

declare

cursor c_aps_coord(p_badge in varchar2 default null) is

select init

from tm.tm_aps_coordinator_table t

where badge_no like p_badge \|\| \'%\'

and inactive=\'N\'

order by ord_by;

cursor c_badge(p_badge in varchar2) is

select name

from all_personnel_view

where badge_no=p_badge;

cursor c_coord_list(p_badge in varchar2 default null,p_seq_id in
varchar2 default null) is

select distinct \*

from tm.tm_contract_coordinator_table

where badge_no like p_badge \|\|\'%\'

and seq_id like p_seq_id \|\|\'%\'

order by init;

cursor c_org (p_coord in varchar2) is

select distinct(UPPER(organization)) as org_inst

from tm.tm_sro_header

where organization is not null

\--and sro_no like p_coord \|\| \'%\'

order by 1;

r_org c_org%ROWTYPE;

cursor c_finance(p_badge in varchar2) is

select \'1\'

from tm.tm_sro_finance_access

where badge_no = p_badge;

cursor c_cost_account is

select distinct account

from tm.tm_sro_cost_codes

order by 1;

cursor c_cost_center is

select distinct cost_center

from tm.tm_sro_cost_codes

order by 1;

cursor c_cost_element is

select distinct cost_element

from tm.tm_sro_cost_codes

order by 1;

user_name varchar2(50);

user_type varchar2(5);

temp varchar2(1);

r_coord tm.tm_contract_coordinator_table%ROWTYPE;

r_coord_current tm.tm_contract_coordinator_table%ROWTYPE;

is_coord varchar2(2);

is_cont_coord varchar2(2);

temp_text varchar2(255);

org_inst tm.tm_sro_header.organization%TYPE;

\-- user_level varchar2(5);

seq_id varchar2(2);

\--name saved for transititon ease

i_badge varchar2(10);

begin

i_badge := badge_for_this_pid(i_pid);

\--lib.no_cache;

if is_valid_pid(i_pid) then

lib.prolog(\'SRO Report Selection Criteria\');

htp.print(\'\<CENTER\>\');

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_summary\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Technical Rep.:\'));

open c_coord_list(i_badge);

fetch c_coord_list into r_coord;

close c_coord_list;

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_sro_type\');

open c_aps_coord(i_badge);

fetch c_aps_coord into is_coord;

if not (c_aps_coord%NOTFOUND) then

is_coord := \'Y\';

else

is_coord := \'N\';

end if;

close c_aps_coord;

\--

htp.formSelectOption(\'ALL\');

for r_init in c_aps_coord

loop

if (r_init.init = r_coord.seq_id) then

htp.formSelectOption(r_init.init,\'SELECTED\');

seq_id := r_init.init;

else

htp.formSelectOption(r_init.init);

end if;

end loop;

end if;

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Coordinator:\'));

htp.Print(\'\<TD\>\');

open c_coord_list(i_badge);

fetch c_coord_list into r_coord_current;

close c_coord_list;

htp.formSelectOpen(\'i_coordinator\');

if (is_coord = \'Y\' or is_cont_coord=\'Y\') then

htp.formSelectOption(\'ALL\',\'SELECTED\');

else

htp.formSelectOption(\'ALL\');

end if;

for r_coord in c_coord_list(\'\',seq_id)

loop

if (r_coord.INIT = r_coord_current.INIT and is_coord = \'N\') then

htp.formSelectOption(r_coord.init,\'SELECTED\');

else

htp.formSelectOption(r_coord.init);

end if;

end loop;

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Organization:\'));

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_organization\');

for r_org in c_org(seq_id) loop

htp.formSelectOption(r_org.org_inst);

end loop;

htp.formSelectOption(\'ALL\',\'SELECTED\');

htp.formSelectClose;

htp.tableRowClose;

htp.Print(\'\</TD\>\');

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Status:\'));

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_sro_status\');

htp.formSelectOption(\'Open\',\'\',\'VALUE=OPEN\');

htp.formSelectOption(\'Closed\',\'\',\'VALUE=CLOSE\');

htp.formSelectOption(\'All\',\'\',\'VALUE=%\');

htp.formSelectClose;

htp.Print (\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'View listing in groups of:\'));

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',\'3\',\'3\',\'100\'));

htp.tableRowClose;

open c_finance(i_badge);

fetch c_finance into temp;

if not c_finance%NOTFOUND then

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Cost Code:\'));

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_cost_account\');

for r_cost_account in c_cost_account loop

htp.formSelectOption(r_cost_account.account);

end loop;

htp.formSelectOption(\'ALL\',\'SELECTED\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_cost_center\');

for r_cost_center in c_cost_center loop

htp.formSelectOption(r_cost_center.cost_center);

end loop;

htp.formSelectOption(\'ALL\',\'SELECTED\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_cost_element\');

for r_cost_element in c_cost_element loop

htp.formSelectOption(r_cost_element.cost_element);

end loop;

htp.formSelectOption(\'ALL\',\'SELECTED\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

end if;

close c_finance;

htp.tableClose;

htp.formHidden(\'i_badge\',i_badge);

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formSubmit;

\--update pid table

update tm.ows_tm_login

set badge_no=i_badge

where pid=i_pid;

\--

htp.formClose;

\--ADMIN ONLY REPORT OPTIONS

if is_admin(i_pid) then

htp.p(\'Administrative Reports - this section only visible to SRO
Administration Group\');

htp.NL;

htp.formOpen(\'tm0002.sro_report_selection\');

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit(\'\',\'Go To Printed Report Critieria\');

htp.formClose;

end if;

\--

htp.listHeader(\'Other Links\',null);

htp.nl;

htp.listItem(htf.anchor(\'http://www.aps.anl.gov/mis/tm/sroguide.html\',\'SRO
System User Guide\'));

htp.ulistClose;

\--end if;

htp.p(\'\</CENTER\>\');

lib.epilog;

end;

end;

\--

procedure sro_contract_detail (isearchstr in varchar2,i_pid in varchar2)
is

begin

declare

cursor c_sro_header(p_sro_no in varchar2) is

select \* from tm.tm_sro_header

where sro_no=p_sro_no;

cursor c_money_committed(p_sro_no in varchar2) is

select \* from tm.tm_timesheet

where sro_no = p_sro_no

order by tm_date desc;

cursor c_sum_money_spent(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet ts

where sro_no = p_sro_no

and matched = \'Y\';

cursor c_sum_money_committed(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet ts

where sro_no = p_sro_no;

cursor c_rates(p_type in varchar2) is

select \*

from tm.tm_rates

where type=p_type;

cursor c_cost_codes(p_sro_no in varchar2) is

select \* from tm.tm_sro_cost_codes

where sro_no = p_sro_no;

cursor c_labor_hours(p_sro_no in varchar2) is

select sum(hours)

from tm.tm_timesheet ts,tm.tm_rates tr

where sro_no = p_sro_no

and ts.labor_type = tr.type

and matched=\'Y\'

and equipment=\'N\';

cursor c_dollars(p_sro_no in varchar2,

p_rental in varchar) is

select sum(amount)

from tm.tm_timesheet ts,tm.tm_rates tr

where ts.labor_type = tr.type

and sro_no = p_sro_no

and nvl(equipment,\'N\') like p_rental \|\| \'%\'

and matched = \'Y\';

cursor c_material_dollars(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where sro_no = p_sro_no

and material=\'Y\'

and matched = \'Y\';

estimated tm.tm_sro_header.estimate%TYPE;

remain tm.tm_sro_header.estimate%TYPE;

running_total

tm.tm_sro_header.estimate%TYPE;

labor_cost tm.tm_sro_header.estimate%TYPE;

r_sh tm.tm_sro_header%ROWTYPE;

r_rates tm.tm_rates%ROWTYPE;

temp varchar2(255);

temp_total tm.tm_sro_header.estimate%TYPE;

debug_ind varchar2(50);

cost_code_string varchar2(60);

cursor c_cont (p_contract_no in varchar2) is

select company_name

from tm.tm_contractors_table

where contract_no=p_contract_no;

last_mod date;

\--Java test code

\-- months number;

\-- display_month varchar2(8);

temp_amt number;

\-- i number;

\-- max_amt number;

total_hours number;

temp_text varchar2(255);

temp_anchor varchar2(255);

begin

\--lib.no_cache;

if is_sro_visible(i_pid,isearchstr) then

if (is_valid_pid(i_pid) and is_coord(i_pid)) then

select max(last_mod_date) into last_mod from tm.tm_timesheet where
sro_no=isearchstr;

lib.prolog(\'SRO Money Spent \');

debug_ind := \'bef tm_sro_header\';

select nvl(sum(estimate),-1) into estimated from tm.tm_sro_header where
sro_no = isearchstr;

remain := estimated;

open c_sro_header(substr(isearchstr,1,14));

fetch c_sro_header into r_sh;

close c_sro_header;

htp.Print(\'\<CENTER\>\');

\--

open c_sum_money_committed(isearchstr);

fetch c_sum_money_committed into running_total;

close c_sum_money_committed;

\--

running_total := nvl(running_total,0);

if running_total \> 0 then

remain := running_total / estimated \* 100;

else

remain := 0;

end if;

\--

if (remain \>= r_sh.percent_committed and r_sh.warning_flag=\'Y\') then

temp := \'\<h2\>\<blink\>\<i\>\' \|\| to_char(remain,999) \|\| \'% of
estimated money has been used.\';

htp.Print(temp);

htp.NL;

temp := \' Warning requested at or above \' \|\|
to_char(r_sh.percent_committed,\'999\') \|\| \'%.
\</I\>\</blink\>\</h2\>\' ;

htp.Print(temp);

htp.Print(\'\<HR\>\');

end if;

running_total := 0;

remain := estimated;

htp.Print (\'\</CENTER\>\');

\--

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'SRO No:\'));

htp.tableData(r_sh.sro_no);

htp.tableRowClose;

htp.tableData(htf.Bold(\'Last updated:\'));

htp.tableData(last_mod);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Organization:\'));

htp.tableData(r_sh.organization);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Contractor:\'));

debug_ind := \'bef tm_contractors_table\';

open c_cont(r_sh.contract_no);

fetch c_cont into temp;

if c_cont%NOTFOUND then

temp := \'Not Available\';

end if;

close c_cont;

htp.tableData(temp);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Open Date:\'));

htp.tableData(r_sh.request_date);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Close Date:\'));

htp.tableData(r_sh.close_date);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Financially closed:\'));

htp.tableData(r_sh.financially_closed);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Cost codes:\'));

\-- get cost code information

for r_cost in c_cost_codes(r_sh.sro_no) loop

cost_code_string := r_cost.account \|\| \'-\' \|\| r_cost.cost_center
\|\| \'-\' \|\| r_cost.cost_element \|\| \' \<i\>\<strong\> \' \|\|
r_cost.percent_allocated \|\| \' %\</strong\>\</i\>\';

htp.tableData(cost_code_string);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\');

end loop;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Description:\'));

htp.tableData(r_sh.description);

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total Estimated:\'));

htp.tableData(to_char(estimated,\'\$9,999,999,990.99\'));

htp.tableRowClose;

open c_sum_money_committed(isearchstr);

fetch c_sum_money_committed into running_total;

close c_sum_money_committed;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Amount Committed:\'));

htp.tableData(htf.Bold(to_char(running_total,\'\$9,999,999,990.99\')));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total Remaining:\'));

remain := estimated - running_total;

htp.tableData(to_char(remain,\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

remain := running_total/estimated \* 100;

htp.tableData(htf.Bold(\'% Committed:\'));

htp.tableData(htf.Bold(to_char(remain,\'999999\') \|\| \' %\')); \--
formerly \'999\'; fml 11/13/96

htp.tableRowClose;

htp.Print(\'\<HR\>\');

htp.tableRowOpen;

open c_sum_money_spent(isearchstr);

fetch c_sum_money_spent into temp_total;

close c_sum_money_spent;

running_total := nvl(running_total,0);

temp_total := nvl(temp_total,0);

running_total := running_total + temp_total ;

htp.tableData(htf.Bold(\'Amount Invoiced:\'));

htp.tableData(to_char(temp_total,\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

remain := nvl(temp_total/estimated \* 100,0);

htp.tableData(htf.Bold(\'% Invoiced:\'));

htp.tableData(to_char(remain,\'999999\') \|\| \' %\'); \-- formerly
\'999\'; fml 11/13/96

htp.tableRowClose;

htp.tableClose;

htp.Print (\'\<HR\>\');

htp.Print (\'\<CENTER\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Date\');

htp.tableHeader(\'Hours\');

htp.tableHeader(\'Type\');

htp.tableHeader(\'Material\');

htp.tableHeader(\'Amount\');

htp.tableHeader(\'Invoice No.\');

htp.tableHeader(\'Invoice matched\');

for r_time in c_money_committed(isearchstr)

loop

htp.tableRowOpen;

htp.tableData(r_time.tm_date);

open c_rates(r_time.labor_type);

fetch c_rates into r_rates;

close c_rates;

if r_time.material = \'N\' or r_time.material is null then

htp.tableData(r_time.hours \|\| \' \' \|\|
substr(r_rates.frequency,1,1));

htp.tableData(r_time.labor_type);

htp.tableData(\'.\');

else

htp.tableData (\'.\');

htp.tableData (\'.\');

htp.tableData(nvl(substr(r_time.description,1,12),\'Material\'));

end if;

htp.tableData(nvl(to_char(r_time.amount,\'\$9,999,999,990.99\'),\'-\'));

\--htp.tableData(nvl(r_time.invoice_no,\'-\'));

\--temp_anchor :=
get_service\|\|pkg_syn\|\|\'.sro_invoice_detail?i_sro_no=\' \|\|
isearchstr \|\| \'&i_invoice=\' \|\| r_time.invoice_no;

if nvl(r_time.invoice_no,\'-\') = \'-\' then

\-- temp_text := \'-\';

htp.tableData(\'-\');

else

\-- temp_text := htf.anchor(temp_anchor,r_time.invoice_no);

htp.formOpen(get_service\|\|pkg_syn\|\| \'.sro_invoice_detail\');

htp.tableData(htf.formSubmit(\'i_invoice\',r_time.invoice_no));

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_sro_no\',r_time.sro_no);

htp.formClose;

end if;

\--htp.tableData(temp_text);

htp.tableData(nvl(r_time.matched,\'N\'));

htp.tableRowClose;

end loop;

htp.tableClose;

htp.NL;

htp.Print(\'\<HR\>\');

htp.Bold(\'Break Down of Money Spent\');

htp.NL;

htp.Print(\'\<I\>Invoiced amounts only\</I\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total labor:\'));

open c_labor_hours(isearchstr);

fetch c_labor_hours into total_hours;

close c_labor_hours;

htp.tableData(to_char(NVL(total_hours,0),\'9,999,990\') \|\| \'
hours\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total labor:\'));

open c_dollars(isearchstr,\'N\');

fetch c_dollars into temp_amt;

close c_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total materials:\'));

open c_material_dollars(isearchstr);

fetch c_material_dollars into temp_amt;

close c_material_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Total rental fees:\'));

open c_dollars(isearchstr,\'Y\');

fetch c_dollars into temp_amt;

close c_dollars;

htp.tableData(to_char(NVL(temp_amt,0),\'\$9,999,999,990.99\'));

htp.tableRowClose;

htp.NL;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_labor_summary_detail\');

htp.formSubmit(\'i_operation\',\'View Totals by Labor Type\');

htp.formHidden(\'i_sro_no\',isearchstr);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

\--htp.Print(\'\</CENTER\>\');

htp.NL;

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

end if;

lib.epilog;

exception

when no_data_found then

htp.print(\' No data found.(\'\|\|debug_ind\|\|\')\');

end;

end;

\--

procedure sro_summary (i_sro_type in varchar2,i_sro_status in
varchar2,i_badge in varchar2 default null,

i_coordinator in varchar2,i_organization in varchar2,i_pid in
varchar2,i_user_type in varchar2 default \'USER\',

i_password in varchar2 default null,i_75_switch in varchar2 default
null,i_sro_no in varchar2 default null,

Z_START in varchar2,Z_ACTION in varchar2,Z_RECORD_SET_SIZE in varchar2
default \'100\',

Z_TOTAL_ROWS in varchar2 default NULL,i_cost_account in varchar2 default
NULL,

i_cost_center in varchar2 default NULL,i_cost_element in varchar2
default NULL) is

begin

declare

cursor c_sro (p_sro_type in varchar2,p_sro_status in
varchar2,p_coordinator in varchar2,p_organization in varchar2) is

select \*

from tm.tm_sro_header

where revision_no=0

and substr(sro_no,3,22) like \'%\' \|\| upper(p_coordinator) \|\| \'%\'

and sro_no like upper(p_sro_type) \|\| \'%\'

and organization like upper(p_organization) \|\| \'%\'

and status like upper(p_sro_status) \|\| \'%\'

order by old_sro asc,sro_no desc,revision_no asc;

cursor c_committed(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where sro_no = p_sro_no;

cursor c_spent(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where matched = \'Y\'

and sro_no = p_sro_no;

temp_anchor varchar2(255);

temp_text varchar2(255);

temp_sro_type varchar2(255);

temp_org tm.tm_sro_header.organization%TYPE;

temp_coordinator tm.tm_contract_coordinator_table.seq_id%TYPE;

spent tm.tm_sro_header.estimate%TYPE;

committed tm.tm_sro_header.estimate%TYPE;

temp tm.tm_sro_header.estimate%TYPE;

estimated tm.tm_sro_header.estimate%TYPE;

diff tm.tm_sro_header.estimate%TYPE;

threshold number(9,2); \-- formerly number(5,2), modified 11/13/96 fml

warning varchar2(1);

temp_sro_status varchar2(10);

\--user_level number(1);

user_type varchar2(20);

match varchar2(1);

debug_loc varchar2(20);

lvl varchar2(5);

supervisor varchar2(1);

temp_cost_element tm.tm_sro_cost_codes.cost_element%TYPE;

temp_cost_center tm.tm_sro_cost_codes.cost_center%TYPE;

temp_cost_account tm.tm_sro_cost_codes.account%TYPE;

\--Next N

r_sro tm.tm_sro_header%ROWTYPE;

\--r_stock stock.stock_header%ROWTYPE;

est_print varchar2(50);

sro_print varchar2(255);

committed_amt number;

remaining number;

commit_print varchar2(50);

remain_print varchar2(50);

l_admin boolean;

l_coord boolean;

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number;

total_pages number;

cur_cnt number;

begin

l_admin := is_admin(i_pid);

l_coord := is_coord(i_pid);

if is_valid_pid(i_pid) then

libs.prolog(\'SRO Status Summary\');

htp.print(\'\<CENTER\>\');

if l_coord then

htp.Print(\'\<h4\>\<I\>Flashing Red \"Organization\" indicates committed
money nearing or beyond estimated amount for that SRO.\</I\>\</h4\>\');

temp_anchor := get_service\|\|\'tm0003\'\|\|\'.get_invoice?i_pid=\' \|\|
i_pid;

htp.NL;

htp.print(htf.anchor(temp_anchor,\'Match an invoice to an SRO\'));

htp.NL;

end if;

if i_75_switch is not null then

update tm.tm_sro_header

set warning_flag = decode(i_75_switch,\'ON\',\'Y\',\'OFF\',\'N\')

where sro_no = i_sro_no;

\--select access_level into lvl from tm.ows_tm_login where pid=i_pid;

end if;

debug_loc := \'x9\';

if upper(i_sro_status)=\'ALL\' then

temp_sro_status := \'\';

else

temp_sro_status := i_sro_status;

end if;

if upper(i_sro_type)=\'ALL\' then

temp_sro_type := \'\';

else

temp_sro_type := i_sro_type;

end if;

if upper(i_organization)=\'ALL\' then

temp_org := \'\';

else

temp_org:= i_organization;

end if;

if upper(i_coordinator) = \'ALL\' then

temp_coordinator := \'\';

else

temp_coordinator := i_coordinator;

end if;

if i_cost_account is null or upper(i_cost_account) = \'ALL\' then

temp_cost_account := \'\';

else

temp_cost_account := i_cost_account;

end if;

if i_cost_element is null or upper(i_cost_element) = \'ALL\' then

temp_cost_element := \'\';

else

temp_cost_element := i_cost_element;

end if;

if i_cost_center is null or upper(i_cost_center) = \'ALL\' then

temp_cost_center := \'\';

else

temp_cost_center := i_cost_center;

end if;

if temp_cost_account=\'\' and temp_cost_center=\'\' and
temp_cost_element=\'\' then

I_QUERY := \'select tm.tm_sro_header.sro_no,organization, estimate,
tm.tm_sro_header.description,0,warning_flag,status,percent_committed
from tm.tm_sro_header \';

i_where := \'where tm.tm_sro_header.sro_no like \'\'\' \|\|
upper(temp_sro_type) \|\| \'%\'\'\'

\|\| \' and status like \'\'\' \|\| upper(temp_sro_status) \|\| \'%\'\'
and substr(tm.tm_sro_header.sro_no,3,22) like \'\'%\' \|\|

upper(temp_coordinator) \|\| \'%\'\' and organization like \'\'%\' \|\|
upper (temp_org) \|\|

\'%\'\' group by
tm.tm_sro_header.sro_no,organization,estimate,tm.tm_sro_header.description,old_sro,revision_no,warning_flag,status,percent_committed\'
\|\|

\' order by old_sro asc,tm.tm_sro_header.sro_no desc,revision_no asc\';

else

I_QUERY := \'select tm.tm_sro_header.sro_no,organization, estimate,
tm.tm_sro_header.description,0,warning_flag,status,percent_committed
from tm.tm_sro_header,tm.tm_sro_cost_codes \';

i_where := \'where tm.tm_sro_header.sro_no =
tm.tm_sro_cost_codes.sro_no\'

\|\| \' and tm.tm_sro_header.sro_no like \'\'\' \|\|
upper(temp_sro_type) \|\| \'%\'\'\'

\|\| \' and tm.tm_sro_cost_codes.account like \'\'%\' \|\|
temp_cost_account \|\| \'%\'\'\'

\|\| \' and tm.tm_sro_cost_codes.cost_element like \'\'%\' \|\|
temp_cost_element \|\| \'%\'\'\'

\|\| \' and tm.tm_sro_cost_codes.cost_center like \'\'%\' \|\|
temp_cost_center \|\| \'%\'\'\'

\|\| \' and tm.tm_sro_header.sro_no like \'\'\' \|\|
upper(temp_sro_type) \|\| \'%\'\'\'

\|\| \' and status like \'\'\' \|\| upper(temp_sro_status) \|\| \'%\'\'
and substr(tm.tm_sro_header.sro_no,3,22) like \'\'%\' \|\|

upper(temp_coordinator) \|\| \'%\'\' and organization like \'\'%\' \|\|
upper (temp_org) \|\|

\'%\'\' group by
tm.tm_sro_header.sro_no,organization,estimate,tm.tm_sro_header.description,old_sro,revision_no,warning_flag,status,percent_committed\'
\|\|

\' order by old_sro asc,tm.tm_sro_header.sro_no desc,revision_no asc\';

end if;

i_query := i_query \|\|\' \'\|\| i_where;

\--htp.Bold(i_query);

\--htp.nl;

debug_loc :=\'a1\';

\--F1 OPEN THE CURSOR

I_CURSOR := dbms_sql.open_cursor;

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1, r_sro.sro_no,25);

dbms_sql.define_column(I_CURSOR, 2, r_sro.organization,20);

dbms_sql.define_column(I_CURSOR, 3, r_sro.estimate);

dbms_sql.define_column(I_CURSOR, 4, r_sro.description,255);

dbms_sql.define_column(I_CURSOR, 5, committed);

dbms_sql.define_column(I_CURSOR, 6, r_sro.warning_flag,1);

dbms_sql.define_column(I_CURSOR, 7, r_sro.status,5);

dbms_sql.define_column(I_CURSOR, 8, r_sro.percent_committed);

\--F2 EXECUTE CURSOR

I_VOID := dbms_sql.execute(I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if I_ROWS_FETCHED = 0 then

htp.nl;

htp.bold(\'No records returned\');

dbms_sql.close_cursor(I_CURSOR);

lib.epilog;

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

Y_TOTAL_ROWS := I_TOTAL_ROWS;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\--F3 END OF CURSOR SET UP/OPEN

htp.nl;

htp.nl;

debug_loc := \'a2\';

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Funding Source\');

if is_admin(i_pid) then

htp.tableHeader(\'75% Warning\');

end if;

htp.tableHeader(\'SRO No.\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Status\');

if is_coord(i_pid) then

htp.tableHeader(\'Estimate\');

end if;

htp.tableHeader(\'Committed\');

if l_coord then

htp.tableHeader(\'Remaining\');

end if;

debug_loc := \'b2\';

\--F4 RETRIEVE VALUES

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1, r_sro.sro_no);

dbms_sql.column_value(I_CURSOR, 2, r_sro.organization);

dbms_sql.column_value(I_CURSOR, 3, r_sro.estimate);

dbms_sql.column_value(I_CURSOR, 4, r_sro.description);

dbms_sql.column_value(I_CURSOR, 5, committed);

dbms_sql.column_value(I_CURSOR, 6, r_sro.warning_flag);

dbms_sql.column_value(I_CURSOR, 7, r_sro.status);

dbms_sql.column_value(I_CURSOR, 8, r_sro.percent_committed);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or I_TOTAL_ROWS \>= 1)

) then

if is_sro_visible(i_pid,r_sro.sro_no) then

htp.tableRowOpen;

\-- temp_anchor :=
get_service\|\|pkg_syn\|\|\'.request_detail?i_request_no=\' \|\|
r_stock.request_no;

debug_loc := \'b1\';

if r_sro.estimate is null then

est_print := \'.\';

else

est_print := to_char(r_sro.estimate,\'\$999,990.99\');

end if;

open c_committed(r_sro.sro_no);

fetch c_committed into committed_amt;

if not c_committed%NOTFOUND and committed_amt is not null then

commit_print := to_char(committed_amt,\'\$9,999,990.99\');

else

commit_print := \'.\';

committed_amt := 0;

end if;

close c_committed;

if l_coord then

temp_anchor :=
get_service\|\|pkg_syn\|\|\'.sro_contract_detail?isearchstr=\' \|\|
r_sro.sro_no \|\| \'&i_pid=\' \|\| i_pid;

debug_loc := \'next\';

sro_print := htf.anchor(temp_anchor,r_sro.sro_no); \-- \'\<a href\>\'
\|\| temp_anchor \|\| \'\</a\>\' \|\| r_sro.sro_no;

if r_sro.estimate = 0 then

threshold := 0;

else

threshold := (committed_amt / r_sro.estimate) \* 100;

end if;

debug_loc := \'x.2.4\';

if (threshold \>= r_sro.percent_committed) then

warning := \'Y\';

else

warning := \'N\';

end if;

DEBUG_LOC := \'X.2.5\';

if (warning = \'Y\' and nvl(r_sro.warning_flag,\'Y\') = \'Y\') then

temp_text := \'\<font color=#ff0000\> \<BLINK\>\' \|\|
nvl(r_sro.organization,\'\-\--\') \|\| \'\</BLINK\>\</font\>\';

else

temp_text := \'\<font color=#006010\>\' \|\|
nvl(r_sro.organization,\'\-\--\') \|\| \'\</font\>\';

end if;

DEBUG_LOC := \'X.2.6\';

\--htp.tableData(nvl(r_sro.organization,\'-\'));

else

sro_print := r_sro.sro_no;

temp_text := nvl(r_sro.organization,\'\-\--\');

end if;

debug_loc := \'c3P0\';

htp.tableData(temp_text);

if l_coord then

if l_admin then

if warning = \'Y\' then

if nvl(r_sro.warning_flag,\'Y\') = \'Y\' then

temp_text := \'\<font color=#006010\>ON\' \|\|
htf.formSubmit(\'i_75_switch\',\'OFF\');

else

temp_text := htf.formSubmit(\'i_75_switch\',\'ON\') \|\| \'\<font
color=#ff0000\>OFF\';

end if;

htp.formOpen(get_service\|\|pkg_syn\|\| \'.sro_summary#\'\|\|
r_sro.sro_no );

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_sro_type\',i_sro_type);

htp.formHidden(\'i_sro_status\',i_sro_status);

htp.formHidden(\'i_badge\',i_badge);

htp.formHidden(\'i_coordinator\',i_coordinator);

htp.formHidden(\'i_organization\',i_organization);

htp.formHidden(\'i_sro_no\',r_sro.sro_no);

htp.formHidden(\'Z_START\',Z_START);

htp.formHidden(\'Z_ACTION\',Z_ACTION);

htp.formHidden(\'Z_TOTAL_ROWS\',Z_TOTAL_ROWS);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.tableData(temp_text);

htp.formClose;

else \-- warning = \'N\'

htp.tableData(\'.\'); end if;

end if;

end if;

htp.tableData(sro_print);

\--htp.tableData(nvl(r_sro.description,\'.\'));

htp.tableData(\'\<a name=\"\' \|\| r_sro.sro_no \|\| \'\"\>\'
\|\|nvl(r_sro.description,\'-\') \|\| \'\</a\>\');

if r_sro.status = \'OPEN\' then

htp.tableData(\'Open\');

elsif r_sro.status = \'CLOSE\' then

htp.tableData(\'Closed\');

else

htp.tableData(\'.\');

end if;

/\*if committed is null then

commit_print := \'.\';

else

commit_print := to_char(committed,\'\$9,999,990.99\');

end if;\*/

if not l_coord then

htp.tableData(commit_print);

end if;

if l_coord then

remaining := r_sro.estimate - committed_amt;

htp.tableData(est_print);

htp.tableData(commit_print);

if remaining is null then

remain_print := \'.\';

else

remain_print := to_char(remaining,\'\$9,999,990.99\');

end if;

htp.tableData(remain_print);

end if;

\--end if;

end if;

htp.tableRowClose;

end if; \--if sro is visible

\--F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

end loop;

htp.tableClose;

\--F6 END OF RETRIEVAL

\-- Java charts de-activated

\--if l_coord then

\-- htp.formOpen(get_service\|\|\'tm0003.select_chart\');

\-- htp.formHidden(\'i_pid\',i_pid);

\-- htp.formSubmit(\'i_operation\',\'Charts\');

\-- htp.formClose;

\--htp.Print (\'\</CENTER\>\');

\--end if;

\--F7 BOTTOM OF PAGE, CURSOR CLEAN UP

dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formOpen(get_service\|\|pkg_syn\|\|\'.sro_summary\');

htp.formHidden(\'i_sro_type\',i_sro_type);

htp.formHidden(\'i_sro_status\',i_sro_status);

htp.formHidden(\'i_coordinator\',i_coordinator);

htp.formHidden(\'i_organization\',i_organization);

htp.formHidden(\'i_badge\',i_badge);

\--htp.formHidden(\'i_user_type\',i_user_type);

\--htp.formHidden(\'i_password\',\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'Z_START\', to_char(I_START));

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

htp.para;

if I_PREV_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(PREV_BUT_CAPTION));

end if;

if I_NEXT_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(NEXT_BUT_CAPTION));

end if;

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formClose;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p( MAX_ROWS_MESSAGE);

end if;

\--F8 END OF CURSOR CODE

\-- Just in case reload button was pressed

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

libs.epilog;

end if;

exception

when value_error then

htp.print(\'Error encountered in code: sro_summary;
debug_loc:\'\|\|debug_loc\|\|\'.\');

end;

end;

procedure sro_labor_summary_detail(i_sro_no in varchar2,i_pid in
varchar2,i_operation in varchar2 default null) is

begin

declare

cursor c_man_hours(p_sro_no in varchar2) is

select sum(amount),sum(hours),labor_type

from tm.tm_timesheet ts,tm.tm_rates tr

where ts.labor_type = tr.type

and sro_no = p_sro_no

and matched = \'Y\'

and nvl(equipment,\'N\') = \'N\'

and nvl(material,\'N\') = \'N\'

group by labor_type

order by labor_type;

type man_hours is record(

amount number(12,2),

hours number,

labor_type varchar2(50));

descrip tm.tm_rates.description%TYPE;

r_man_hours man_hours;

begin

lib.prolog (\'Summary of Man Hours by Type\');

if is_sro_visible(i_pid,i_sro_no) then

if (is_valid_pid(i_pid) and is_coord(i_pid)) then

htp.Print(\'\<CENTER\>\');

htp.Print(htf.Bold(\'Sro No.: \') \|\| i_sro_no);

htp.NL;

htp.NL;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Type\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Hours\');

htp.tableHeader(\'Amount\');

open c_man_hours(i_sro_no);

fetch c_man_hours into r_man_hours;

while not c_man_hours%NOTFOUND

loop

htp.tableRowOpen;

htp.tableData(r_man_hours.labor_type);

select description into descrip from tm.tm_rates where
type=r_man_hours.labor_type;

htp.tableData(descrip);

htp.tableData(r_man_hours.hours);

htp.tableData(to_char(r_man_hours.amount,\'\$9,999,990.99\'));

htp.tableRowClose;

fetch c_man_hours into r_man_hours;

end loop;

close c_man_hours;

htp.tableClose;

htp.Print (\'\</CENTER\>\');

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

end if;

lib.epilog;

end;

end;

procedure sro_invoice_detail (i_sro_no in varchar2,i_invoice in
varchar2,i_pid in varchar2) is

begin

declare

display_text tm.tm_timesheet.description%TYPE;

begin

if is_sro_visible(i_pid,i_sro_no) then

if (is_valid_pid(i_pid) and is_coord(i_pid)) then

lib.Prolog(\'Additional Invoice Detail\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'Invoice No.:\');

htp.tableData(i_invoice);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'SRO No.:\');

htp.tableData(i_sro_no);

htp.tableRowClose;

select max(description) into display_text from tm.tm_timesheet

where sro_no = i_sro_no and invoice_no = i_invoice

and description is not null;

htp.tableRowOpen;

htp.tableData(\'Description:\');

if display_text is not null then

htp.tableData(display_text);

else

htp.tableData(\'No description is available.\');

end if;

htp.tableRowClose;

htp.tableClose;

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

end if;

lib.epilog;

end;

end;

\--FOLLOWING PROCS aded 8/26/99

procedure sro_report_selection (i_pid in varchar2) is

begin

declare

cursor c_aps_coord(p_badge in varchar2 default null) is

select init

from tm.tm_aps_coordinator_table t

where badge_no like p_badge \|\| \'%\'

and inactive=\'N\'

order by ord_by;

begin

\-- i_badge := badge_for_this_pid(i_pid);

\--lib.no_cache;

if is_valid_pid(i_pid) and is_admin(i_pid) then

lib.prolog(\'SRO Printed Report Selection Criteria\');

htp.print(\'\<CENTER\>\');

htp.formOpen(get_service\|\|pkg_syn\|\|\'.run_invoice_summary\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Technical Rep.:\'));

\--

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_sro_type\');

for r_aps_coord in c_aps_coord loop

htp.formSelectOption(r_aps_coord.INIT,NULL,r_aps_coord.INIT);

end loop;

htp.formSelectOption(\'ALL\');

htp.formSelectClose;

htp.p(\'\</TD\>\</TR\>\');

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Contract:\'));

\--

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_contract\');

htp.formSelectOption(\'418\');

htp.formSelectOption(\'402\');

htp.formSelectOption(\'401\');

htp.formSelectOption(\'253\');

htp.formSelectOption(\'252\');

htp.formSelectOption(\'ALL\');

htp.formSelectClose;

htp.p(\'\</TD\>\</TR\>\');

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Sro #:\'));

htp.p(\'\<TD\>\<INPUT TYPE=\"TEXT\" NAME=\"i_sro_seq\" MAXLENGTH=\"4\"
SIZE=\"4\" VALUE=\"ALL\"\>\</TD\>\');

htp.p(\'\</TR\>\');

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Printer:\'));

htp.p(\'\<TD\>\<INPUT TYPE=\"TEXT\" NAME=\"i_printer\" MAXLENGTH=\"25\"
SIZE=\"10\" VALUE=\"apo1\"\>\</TD\>\');

htp.p(\'\</TR\>\');

\--

htp.tableClose;

htp.formSubmit(\'\',\'Print Report\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</CENTER\>\');

end if;

lib.epilog;

end;

end;

\--

procedure run_invoice_summary (i_printer in varchar2 default \'apo1\',

i_operation in varchar2 default NULL,i_sro_type in varchar2 default
\'ALL\',

i_contract in varchar2 default \'ALL\',

i_sro_seq in varchar2 default \'ALL\',

i_pid in varchar2) is

STR varchar2(10);

return_status varchar2(25);

begin

if is_valid_pid(i_pid) and is_admin(i_pid) then

lib.prolog (\'SRO Print Summary\');

STR := \'tm/tm\';

mis_util.utl_print_it(\'\$mis_reports/\',\'tm_invoices\',\'B\',i_printer,\'P\',\'SQR\',STR,\'NONE\',

i_sro_type,i_contract,i_sro_seq,\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

htp.p(\'return_status:\'\|\|return_status);

if return_status = \'status:0\' then

htp.print (\' Report successfully sent to printer \"\' \|\| i_printer
\|\| \'\"\');

else

htp.print (\'Print Request Failed. Print daemon may be down.\');

end if;

lib.epilog;

end if;

end;

\--

begin

null;

end;

/

CREATE OR REPLACE PACKAGE tm0003 IS

pkg_name varchar2(255) := \'tm0002\';

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

pkg_syn varchar2(255) := pkg_name\|\|\'s\';

ping varchar2(255) := pkg_name\|\|\' is alive\';

fancy_background boolean := false;

override_authentication boolean := true;

\--

procedure get_invoice(i_pid in varchar2);

procedure find_sro(i_invoice in varchar2,i_pid in varchar2);

procedure select_chart (i_pid in varchar2,i_operation in varchar2
default null);

procedure draw_chart (i_pid in varchar2,i_type in varchar2,i_start_mo in
varchar2,i_start_yr in varchar2,i_end_mo in varchar2,i_end_yr in
varchar2,i_operation in varchar2 default null);

END;

/

CREATE OR REPLACE PACKAGE BODY tm0003 IS

prolog_done boolean;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

return(log0002.is_valid_pid(i_pid,\'SRO_COORD\',1));

end;

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

function inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) return varchar2 is

begin

return htf.img(image_dir \|\| img,null,nvl(alt,img),

null,nvl(attr,\'border=0\'));

end;

\--

procedure inline (img in varchar2, alt in varchar2 := null,

attr in varchar2 := null) is

begin

htp.p(inline(img,alt,attr));

end;

\--

function is_me (who in varchar2) return boolean is

begin

if who = upper(owa_util.get_cgi_env(\'remote_user\')) then

return true;

end if;

return false;

end;

\--

function is_webstation return boolean is

begin

if owa_util.get_cgi_env(\'http_user_agent\') like

\'%WebStation%\' then

return true;

end if;

return false;

end;

\--

function webstation_hook (c in varchar2) return varchar2 is

begin

if is_webstation then

return \'method=\"csp:script\" action=\"c:\\travel\\\'

\|\| c \|\| \'\"\';

end if;

return null;

end;

\--

procedure one_row(nam in varchar2,val in varchar2) is

begin

htp.tableRowOpen;

htp.tableData(nam,\'right\');

htp.tableData(htf.bold(val));

htp.tableRowClose;

end;

procedure get_invoice (i_pid in varchar2) is

begin

\--lib.no_cache;

lib.prolog(\'Match Invoice to an SRO\');

if is_valid_pid(i_pid) then

htp.Print(\'\<center\>\');

htp.formOpen(get_service\|\|\'tm0003\'\|\|\'.find_sro\');

htp.Print(htf.Bold(\'Please enter the invoice number or pattern to
match: \') \|\| htf.formText(\'i_invoice\',10,255));

htp.NL;

htp.NL;

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit;

htp.formClose;

htp.print(\'\</center\>\');

else

htp.print(\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

end;

procedure find_sro(i_invoice in varchar2,i_pid in varchar2) is

begin

declare

cursor c_invoice(p_invoice in varchar2) is

select distinct sro_no, invoice_no

from tm.tm_timesheet

where invoice_no = p_invoice;

TYPE inv_rec is RECORD

(sro_no tm.tm_timesheet.sro_no%TYPE,

invoice_no tm.tm_timesheet.invoice_no%TYPE);

r_invoice inv_rec;

begin

lib.prolog(\'Invoice to SRO Match\');

if is_valid_pid(i_pid) then

htp.print (\'\<CENTER\>\');

htp.tableOpen(\'BORDER\');

open c_invoice(i_invoice);

fetch c_invoice into r_invoice;

if not c_invoice%NOTFOUND then

htp.print(\'\<h2\>\<strong\>Invoice \# \' \|\| i_invoice \|\| \' is on
SRO \# \' \|\| r_invoice.sro_no \|\| \'\</h2\>\</strong\>\');

else

htp.print(\'\<h2\>\<strong\>No SRO found for invoice \# \' \|\|
i_invoice \|\| \'\</h2\>\</strong\>\');

end if;

close c_invoice;

htp.tableClose;

htp.print (\'\</CENTER\>\');

else

htp.print(\'This session is no longer valid. Please login again.\');

end if;

lib.epilog;

end;

end;

procedure select_chart (i_pid in varchar2,i_operation in varchar2
default null) is

begin

declare

x varchar2(1);

begin

if is_valid_pid(i_pid) then

lib.Prolog(\'Chart Criteria Selection\');

htp.Print(\'\<CENTER\>\');

htp.tableOpen;

\--select chart type

htp.formOpen(get_service\|\|\'tm0003.draw_chart\');

htp.formHidden(\'i_pid\',i_pid);

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Chart Type:\'));

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_type\');

htp.formSelectOption(\'Expenditures by Month\',\'\',\'VALUE=SPEND\');

htp.formSelectOption(\'Man Hours by Month\',\'\',\'VALUE=HOURS\');

htp.formSelectOption(\'Jobs Opened by Month\',\'\',\'VALUE=JOBSOPEN\');

htp.formSelectOption(\'Jobs Closed by Month\',\'\',\'VALUE=JOBSCLOSE\');

htp.formSelectClose;

htp.Print (\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

\--select begin month, year

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Starting Month/Year:\'));

htp.Print(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_start_mo\');

htp.formSelectOption(\'JAN\');

htp.formSelectOption(\'FEB\');

htp.formSelectOption(\'MAR\');

htp.formSelectOption(\'APR\');

htp.formSelectOption(\'MAY\');

htp.formSelectOption(\'JUN\');

htp.formSelectOption(\'JUL\');

htp.formSelectOption(\'AUG\');

htp.formSelectOption(\'SEP\');

htp.formSelectOption(\'OCT\');

htp.formSelectOption(\'NOV\');

htp.formSelectOption(\'DEC\');

htp.formSelectClose;

htp.Print (\'\</TD\>\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_start_yr\');

htp.formSelectOption(\'1996\');

htp.formSelectOption(\'1997\');

htp.formSelectOption(\'1998\');

htp.formSelectOption(\'1999\');

htp.formSelectOption(\'2000\');

htp.formSelectOption(\'2001\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Ending Month/Year:\'));

htp.Print(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_end_mo\');

htp.formSelectOption(\'JAN\');

htp.formSelectOption(\'FEB\');

htp.formSelectOption(\'MAR\');

htp.formSelectOption(\'APR\');

htp.formSelectOption(\'MAY\');

htp.formSelectOption(\'JUN\');

htp.formSelectOption(\'JUL\');

htp.formSelectOption(\'AUG\');

htp.formSelectOption(\'SEP\');

htp.formSelectOption(\'OCT\');

htp.formSelectOption(\'NOV\');

htp.formSelectOption(\'DEC\');

htp.formSelectClose;

htp.Print (\'\</TD\>\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_end_yr\');

htp.formSelectOption(\'1996\');

htp.formSelectOption(\'1997\');

htp.formSelectOption(\'1998\');

htp.formSelectOption(\'1999\');

htp.formSelectOption(\'2000\');

htp.formSelectOption(\'2001\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

\--select end month, year

htp.tableClose;

htp.formSubmit(\'i_operation\',\'View Chart\');

htp.formClose;

htp.Print(\'\</CENTER\>\');

lib.epilog;

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

end;

end;

procedure draw_chart (i_pid in varchar2,i_type in varchar2,i_start_mo in
varchar2,i_start_yr in varchar2,i_end_mo in varchar2,i_end_yr in
varchar2,i_operation in varchar2 default null) is

begin

declare

TYPE Array is TABLE of NUMBER NOT NULL INDEX BY BINARY_INTEGER;

ColValues Array;

ColLabels Array;

Type LabelArray is TABLE of VARCHAR2(25) NOT NULL INDEX BY
BINARY_INTEGER;

Labels LabelArray;

Colors LabelArray;

max_amt number;

temp_amt number;

begin_date date;

chart_label varchar2(255);

end_date date;

months number;

i integer;

j integer;

temp varchar2(255);

iterate_month date;

temp_value number;

max_value number;

max_display number;

height_divider number;

color_value number;

label_divider number;

p_type varchar2(1);

java_height number;

begin

if is_valid_pid(i_pid) then

if i_type = \'SPEND\' then

lib.prolog (\'Total SRO Expenditures\');

height_divider := 4000;

label_divider := 1000;

java_height := 167;

chart_label := \'SRO Spending By Month (in thousands)\';

p_type := \'1\';

elsif i_type = \'HOURS\' then

lib.prolog (\'Total SRO Man Hours\');

chart_label := \'SRO Man Hours By Month (in hundreds)\';

height_divider := 100;

label_divider := 100;

java_height := 167;

p_type := \'2\';

elsif i_type = \'JOBSOPEN\' then

lib.prolog (\'SRO Jobs Opened\');

chart_label := \'SRO Jobs Opened By Month\';

p_type := \'3\';

height_divider := 1;

label_divider := 1;

java_height := 100;

elsif i_type = \'JOBSCLOSE\' then

lib.prolog (\'SRO Jobs Closed\');

chart_label := \'SRO Jobs Closed By Month\';

p_type := \'4\';

height_divider := 1;

label_divider := 1;

java_height := 100;

end if;

\--get \# months

begin_date := to_date(\'01-\' \|\| i_start_mo \|\| \'-\' \|\|
i_start_yr,\'DD-MON-YYYY\');

end_date := to_date(\'01-\' \|\| i_end_mo \|\| \'-\' \|\|
i_end_yr,\'DD-MON-YYYY\');

months := ceil(months_between(end_date,begin_date)) + 1;

\--get max value

iterate_month := begin_date;

i := 0;

max_value := 0;

while (iterate_month \<= end_date) loop

\--select values

if i_type = \'SPEND\' then

select sum(amount) into temp_value from tm.tm_timesheet where
to_char(invoice_date,\'MON-YY\') = to_char(iterate_month,\'MON-YY\');

elsif i_type = \'HOURS\' then

select sum(hours) into temp_value from tm.tm_timesheet ts,tm.tm_rates tr
where tr.type = ts.labor_type and to_char(invoice_date,\'MON-YY\') =
to_char(iterate_month,\'MON-YY\') and (equipment = \'N\' or equipment is
null);

elsif i_type = \'JOBSOPEN\' then

select count(sro_no) into temp_value from tm.tm_sro_header where
to_char(request_date,\'MON-YY\') = to_char(iterate_month,\'MON-YY\');

else

select count(sro_no) into temp_value from tm.tm_sro_header where
to_char(close_date,\'MON-YY\') = to_char(iterate_month,\'MON-YY\');

end if;

\--update max

if temp_value \> max_value then

max_value := nvl(temp_value,0);

max_display := nvl(temp_value,0) / height_divider;

end if;

ColValues (i) := nvl(temp_value,0) / height_divider;

ColLabels(i) := nvl(temp_value,0) / label_divider;

Labels(i) := to_char(iterate_month,\'Mon YY\');

i := i + 1;

iterate_month := add_months(iterate_month,1);

end loop;

max_value := ceil(max_value) / label_divider;

htp.Print(\'\<CENTER\>\');

j := 0;

Colors (1) := \'red\';

Colors (2) := \'yellow\';

Colors (3) := \'blue\';

Colors (4) := \'orange\';

Colors (5) := \'green\';

temp := \'\<applet code=\"ChartMod.class\" width=\' \|\| to_char(months
\* 75) \|\| \' height=\' \|\| (to_char(java_height)) \|\| \'
codebase=\"http://ra.aps1.anl.gov:5001/ows-java/\"\>\';

htp.Print(temp);

while (j \< i) loop

color_value := (j mod 5) + 1;

temp := \'\<param name=c\' \|\| to_char(j+1) \|\| \'\_color value=\"\'
\|\| Colors(color_value) \|\|\'\"\>\';

htp.Print(temp);

temp := \'\<param name=c\' \|\| to_char(j+1) \|\| \'\_label value=\"\'
\|\| Labels(j) \|\|\'\"\>\';

htp.Print(temp);

temp := \'\<param name=c\' \|\| to_char(j+1) \|\| \'\_style
value=\"solid\"\>\';

htp.Print(temp);

temp := \'\<param name=c\' \|\| to_char(j+1) \|\| \' value=\"\' \|\|
to_char(ColValues(j)) \|\|\'\"\>\';

htp.print(temp);

temp := \'\<param name=cl\' \|\| to_char(j+1) \|\| \' value=\"\' \|\|
to_char(ColLabels(j),\'999,990.9\') \|\|\'\"\>\';

htp.Print(temp);

j:=j+1;

end loop;

temp := \'\<param name=y_max value=\"\' \|\|
ltrim(to_char(ceil(max_display),\'999999\'),\' \')\|\|\'\"\>\';

htp.Print(temp);

temp := \'\<param name=y_max_display value=\"\' \|\|
ltrim(to_char(ceil(max_value),\'999999\'),\' \') \|\| \'\"\>\';

htp.Print(temp);

htp.Print(\'\<param name=title value=\" \|\| chart_label \|\| \"\>\');

temp := \'\<param name=columns value=\"\' \|\| to_char(months)
\|\|\'\"\>\';

htp.Print(temp);

htp.Print(\'\<param name=orientation value=\"vertical\"\>\');

htp.Print(\'\<param name=scale value=\"1\"\>\');

htp.Print(\'\</applet\>\');

htp.NL;

htp.Bold(chart_label);

htp.HR;

htp.formOpen(get_service\|\|pkg_syn\|\| \'.run_print_it\');

htp.formHidden(\'i_type\',p_type);

htp.formHidden(\'i_start_yr\',i_start_yr);

htp.formHidden(\'i_start_mo\',i_start_mo);

htp.formHidden(\'i_end_yr\',i_end_yr);

htp.formHidden(\'i_end_mo\',i_end_mo);

htp.formHidden(\'i_pid\',i_pid);

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'Printer:\');

htp.tableData(htf.formText(\'i_printer\',\'10\',\'15\'));

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Print\');

htp.formClose;

htp.Print(\'\</CENTER\>\');

else

htp.Print(\'This session is no longer valid. Please login again.\');

end if;

end;

end;

begin

prolog_done := false;

END;

/

CREATE OR REPLACE PACKAGE tm0004 IS

G_MENU_START_PAGE constant varchar2(50) := \'wam0002.SRO_MAIN_MENU\';

G_QUERY_START_PAGE_APP constant varchar2(50) := \'SRO_QUERY\';

G_QUERY_START_PAGE constant varchar2(50) := \'QUERY_START_PAGE\';

G_QUERY_OP constant varchar2(50) := \'Query\';

G_RETURN_TO_QUERY constant varchar2(50) := \' Return to Query Page \';

G_RETURN_TO_UPDATE constant varchar2(50) := \' Update Drawing Title \';

G_BACK_TO_MENU constant varchar2(50) := \' Back to Main Menu \';

G_ONLINE_HELP constant varchar2(50) := \'Online Help\';

G_ONLINE_HELP_FILE constant varchar2(50) := \'/dcc-doc/dcn_help.html\';

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \' \> \';

PREV_BUT_CAPTION constant varchar2(100) := \' \< \';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\>\>\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\<\<\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'!\<\<\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\>\>!\';

\--

function get_pid_info(i_pid in number,

i_attrib in varchar2) return varchar2;

procedure query_start_page (i_pid in varchar2 default \'NEW\');

\--

procedure query_result_page (m_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_org in varchar2 default NULL,

i_sro_type in varchar2 default NULL,

i_open_date in varchar2 default NULL,

i_close_date in varchar2 default NULL,

i_sro_status in varchar2 default NULL,

Z_START in varchar2 default NULL,

Z_ACTION in varchar2 default NEXT_BUT_CAPTION,

Z_RECORD_SET_SIZE in varchar2 default \'10\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

END;

/

CREATE OR REPLACE PACKAGE BODY tm0004 IS

/\*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

DATE: INITIALS: REMARKS:

\-\-\-\-- \-\-\-\-\-\-\-\-- \-\-\-\-\-\-\--

01-DEC-97 KEM Created tm0004 from dcc0006

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\*/

\--

\-- GLOBAL NEXT N settings

\--

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 10;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'Maximimum number
of records (\'\|\|to_char(MAX_ROWS)\|\| \') returned\');

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

function get_pid_info (i_pid in number,i_attrib in varchar2) return
varchar2 is

\--

cursor c_ows_app_login (i_pid in number) is

select \* from ows_app_login

where pid = i_pid;

\--

r_ows_app_login c_ows_app_login%ROWTYPE;

\--

begin

open c_ows_app_login(i_pid);

fetch c_ows_app_login into r_ows_app_login;

if c_ows_app_login%NOTFOUND then

close c_ows_app_login;

return (NULL);

else

close c_ows_app_login;

if i_attrib = \'BADGE_NO\' then

return(r_ows_app_login.badge_no);

else

return (NULL);

end if;

end if;

end;

\--

\-- This procedure allows the user to enter in parameters to query off
of.

\--

procedure enter_criteria (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_org in varchar2 default NULL,

i_sro_type in varchar2 default NULL,

i_open_date in varchar2 default NULL,

i_close_date in varchar2 default NULL,

i_sro_status in varchar2 default NULL,

i_size in varchar2 default NULL) is

begin

declare

cursor c_org is

select distinct(UPPER(organization))

from tm.tm_sro_header

where organization is not null

order by 1;

cursor c_coord_list(p_badge in varchar2 default null,p_seq_id in
varchar2 default null) is

select distinct \*

from tm.tm_contract_coordinator_table

where badge_no like p_badge \|\|\'%\'

and seq_id like p_seq_id \|\|\'%\'

order by init;

cursor c_aps_coord is

select distinct(init) as init

from tm.tm_aps_coordinator_table t

order by init desc;

org_inst varchar2(25);

begin

lib.prolog(\'Enter SRO Search Criteria: \');

\--

\--

if p_msg is NOT NULL then

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.em(p_msg));

htp.tableRowClose;

htp.tableClose;

end if;

\--

\-- Sets up the first page in order to enter in fields to query off of.

\--

htp.centerOpen;

htp.formOpen(\'tm0004.query_result_page\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Funding Source:\'),\'Right\');

htp.print(\'\<TD\>\');

htp.formSelectOpen(\'i_org\');

open c_org;

fetch c_org into org_inst;

while (not c_org%NOTFOUND)

loop

htp.formSelectOption(org_inst);

fetch c_org into org_inst;

end loop;

close c_org;

htp.formSelectOption(\'ALL\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Technical Rep.:\'),\'Right\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_sro_type\');

for r_init in c_aps_coord

loop

htp.formSelectOption(r_init.init);

end loop;

htp.formSelectOption(\'ALL\');

htp.formSelectClose;

htp.Print(\'\</TD\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Opened between: \',\'Right\');

htp.tableData(htf.formText(\'i_open_date\',\'11\',\'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData;

htp.tableData(\'DD-MON-YYYY\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'and: \',\'Right\');

htp.tableData(htf.formText(\'i_close_date\',\'11\',\'11\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData;

htp.tableData(\'DD-MON-YYYY\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Status:\'),\'Right\');

htp.Print(\'\<TD\>\');

htp.formSelectOpen(\'i_sro_status\');

htp.formSelectOption(\'Open\',\'\',\'VALUE=OPEN\');

htp.formSelectOption(\'Closed\',\'\',\'VALUE=CLOSE\');

htp.formSelectOption(\'All\',\'\',\'VALUE=ALL\');

htp.formSelectClose;

htp.Print (\'\</TD\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Number of records to view at a time:\',\'Right\');

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',\'4\',\'4\',\'10\'));

htp.tableRowClose;

\--

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'m_pid\',m_pid);

htp.formClose;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

/\*htp.para;

htp.para;

htp.p(\'\[\');

htp.anchor(dcc0005.G_ONLINE_HELP_FILE,G_ONLINE_HELP);

htp.p(\'\|\');

htp.anchor(\'wam0002.dcn_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

htp.p(\'\]\');\*/

htp.centerClose;

lib.epilog;

exception

when others then

htp.p(sqlerrm);

end;

end;

\--

\-- Checks to see if its a valid PID

\--

procedure query_start_page (i_pid in varchar2 default \'NEW\') is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid);

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\--

\--TEMPORARY: Link to TM PID system currently separate from general pid
system,

\-- this allows calls to TM0002 for item detail.

commit;

insert into tm.ows_tm_login

(PID,BADGE_NO,ACCESS_LEVEL,REMOTE_ADDR,TIMESTAMP)

(select pid,badge_no,\'COORD\',IP,TIMESTAMP

from ows_app_login where pid=m_pid);

\--end of temporary code - to be removed when the tm0002 package is
migrated

\--to the general security using OWS_APP_LOGIN

enter_criteria(m_pid,G_QUERY_OP);

\--

end;

\--

\-- This procedure populates the second page of the application.

\--

procedure query_result_page (m_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_org in varchar2 default NULL,

i_sro_type in varchar2 default NULL,

i_open_date in varchar2 default NULL,

i_close_date in varchar2 default NULL,

i_sro_status in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'10\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL) is

\--

cursor c_committed(p_sro_no in varchar2) is

select sum(amount)

from tm.tm_timesheet

where sro_no = p_sro_no;

\--

\-- Set up the cursors for your detail page (Page 2).

\--

\-- Local variables for the second page (the query_result_page
procedure).

\--

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

I_NEXT_SET_BUT boolean;

I_PREV_SET_BUT boolean;

I_FIRST_SET_BUT boolean;

I_LAST_SET_BUT boolean;

L_HOLD_PAGE number;

X_TEMP number;

Y_TEMP number;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number := 10;

total_pages number;

cur_cnt number;

rec_counter number := 0;

temp_anchor varchar2(512);

\--

j_query varchar2(2000) := \'\';

j_where varchar2(2000) := \'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned number := 0;

l_pre_cri varchar2(2000);

r_sro tm.tm_sro_header%ROWTYPE;

est_print varchar2(50);

commit_print varchar2(50);

committed_amt number;

remaining number;

remain_print varchar2(50);

warning varchar2(1);

threshold number;

temp_text varchar2(512);

sro_print varchar2(255);

\--

total_committed number;

total_remaining number;

total_estimate number;

\--

begin

\--

\-- Checks to see if there is a valid PID

\--

if i_operation = G_QUERY_OP then

if NOT log0002.is_valid_pid(m_pid,G_QUERY_START_PAGE_APP) then

return;

end if;

end if;

\-- Set the total counters to 0

total_committed := 0;

total_remaining := 0;

total_estimate :=0 ;

\--

\-- Builds the dynamic select statement to retrieve the
complete_document_no which is a

\-- unique field that can retrieve any other fields needed via cursors.

\--

I_QUERY := \'select
sro_no,organization,estimate,description,warning_flag,status,

percent_committed,old_sro,request_date from tm.tm_sro_header\';

\-- Begins to build the dynamic where clause

\-- This initial part is static while the following if\'s add onto the
where clause

\-- when the conditions are met.

\--

if i_org is NOT NULL and i_org != \'ALL\' then

l_pre_cri := \' WHERE \';

i_where := l_pre_cri\|\|\'organization like \'

\|\|\'\'\'\'\|\|upper(i_org)\|\|\'%\'\|\|\'\'\'\';

end if;

\--

if i_sro_type is NOT NULL and i_sro_type != \'ALL\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' sro_no like \'

\|\|\'\'\'\'\|\|upper(i_sro_type)\|\|\'%\'\|\|\'\'\'\';

end if;

\--

if i_sro_status is NOT NULL and upper(i_sro_status) != \'ALL\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' status = \'

\|\|\'\'\'\'\|\|upper(i_sro_status)\|\|\'\'\'\';

end if;

\--

if i_open_date is NOT NULL then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' request_date \>=
to_date(\'\'\'\|\|upper(i_open_date)\|\|\'\'\',\'\'DD-MON-YYYY\'\')\';

end if;

\--

if i_close_date is NOT NULL then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' request_date \<=
to_date(\'\'\'\|\|upper(i_close_date)\|\|\'\'\',\'\'DD-MON-YYYY\'\')\';

end if;

\--

\-- This counts the number of records returned in order to place the

\-- correct number of buttons on the bottom of the page.

\--

if Z_TOTAL_ROWS is NULL then

j_query := \'select count( distinct sro_no) \'

\|\|\' from \'\|\|\' tm.tm_sro_header\' ;

j_where := i_where;

j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\--

\--

\--

I_CURSOR := dbms_sql.open_cursor;

i_query := i_query \|\|\' \'\|\| i_where\|\|\' order by old_sro,sro_no
desc\';

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1, r_sro.sro_no,25);

dbms_sql.define_column(I_CURSOR, 2, r_sro.organization,30);

dbms_sql.define_column(I_CURSOR, 3, r_sro.estimate);

dbms_sql.define_column(I_CURSOR, 4, r_sro.description,255);

dbms_sql.define_column(I_CURSOR, 5, r_sro.warning_flag,1);

dbms_sql.define_column(I_CURSOR, 6, r_sro.status,5);

dbms_sql.define_column(I_CURSOR, 7, r_sro.percent_committed);

dbms_sql.define_column(I_CURSOR, 8, r_sro.old_sro,1);

dbms_sql.define_column(I_CURSOR, 9, r_sro.request_date);

htp.formOpen(\'tm0004.query_result_page\');

I_VOID := dbms_sql.execute (I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

\--

\-- Checks to see if there were any rows retrieved from the parameters
entered. If none

\-- then it will display the message with the values entered.

\--

if I_ROWS_FETCHED = 0 then

dbms_sql.close_cursor(I_CURSOR);

enter_criteria(m_pid,i_operation,\'No records matching that criteria
found. \',

i_org ,

i_sro_type ,

i_open_date ,

i_close_date ,

i_sro_status ,

Z_RECORD_SET_SIZE);

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

\--

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

\--

if Z_START is null then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -
1)/SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

I_START := ((l_hold_page -1) \* record_set_size) + 1;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

I_START := ((l_hold_page -1) \* record_set_size) - 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

I_START := 1;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

\--

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

\--

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\-- Puts the viewable \"Header\" portion on page two.

\--

lib.prolog(\'Query Results \');

\--

\-- Places the header fields on the begining of the report. Note:
tableHeader

\-- automaticly bolds the text for you.

\--

htp.centerOpen;

htp.tableOpen(\'border\');

htp.tableHeader(\'Funding Source\');

htp.tableHeader(\'SRO No.\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Date Opened\');

htp.tableHeader(\'Status \');

htp.tableHeader(\'Estimate\');

htp.tableHeader(\'Committed\');

htp.tableHeader(\'Remaining\');

\-- htp.tableClose;

\--

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1, r_sro.sro_no);

dbms_sql.column_value(I_CURSOR, 2, r_sro.organization);

dbms_sql.column_value(I_CURSOR, 3, r_sro.estimate);

dbms_sql.column_value(I_CURSOR, 4, r_sro.description);

dbms_sql.column_value(I_CURSOR, 5, r_sro.warning_flag);

dbms_sql.column_value(I_CURSOR, 6, r_sro.status);

dbms_sql.column_value(I_CURSOR, 7, r_sro.percent_committed);

dbms_sql.column_value(I_CURSOR, 8, r_sro.old_sro);

dbms_sql.column_value(I_CURSOR, 9, r_sro.request_date);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or

I_TOTAL_ROWS \>= 1)) then

\--

\-- Starts to retrieve the data requested for the page.

\--

htp.tableRowOpen;

open c_committed(r_sro.sro_no);

fetch c_committed into committed_amt;

if not c_committed%NOTFOUND and committed_amt is not null then

commit_print := to_char(committed_amt,\'\$9,999,990.99\');

total_committed := total_committed + committed_amt;

else

commit_print := \'.\';

committed_amt := 0;

end if;

close c_committed;

if r_sro.estimate = 0 then

threshold := 0;

else

threshold := (committed_amt / r_sro.estimate) \* 100;

end if;

if (threshold \>= r_sro.percent_committed) then

warning := \'Y\';

else

warning := \'N\';

end if;

if (warning = \'Y\' and r_sro.warning_flag = \'Y\') then

temp_text := \'\<font color=#ff0000\> \<BLINK\>\' \|\|
nvl(r_sro.organization,\'\-\--\') \|\| \'\</BLINK\>\</font\>\';

else

temp_text := \'\<font color=#006010\>\' \|\|
nvl(r_sro.organization,\'\-\--\') \|\| \'\</font\>\';

end if;

htp.tableData(temp_text,\'LEFT\');

\--htp.tableData(r_sro.sro_no,\'LEFT\');

temp_anchor := \'tm0002.sro_contract_detail?isearchstr=\' \|\|
r_sro.sro_no \|\| \'&i_pid=\' \|\| m_pid;

sro_print := htf.anchor(temp_anchor,r_sro.sro_no); \-- \'\<a href\>\'
\|\| temp_anchor \|\| \'\</a\>\' \|\| r_sro.sro_no;

htp.tableData(sro_print);

htp.tableData(r_sro.description,\'LEFT\');

htp.tableData(to_char(r_sro.request_date,\'DD-MON-YYYY\'));

if r_sro.status = \'OPEN\' then

htp.tableData(\'Open\');

elsif r_sro.status = \'CLOSE\' then

htp.tableData(\'Closed\');

else

htp.tableData(\'.\');

end if;

if r_sro.estimate is null then

est_print := \'.\';

else

est_print := to_char(r_sro.estimate,\'\$999,990.99\');

total_estimate := total_estimate + r_sro.estimate;

end if;

remaining := r_sro.estimate - committed_amt;

htp.tableData(est_print);

htp.tableData(commit_print);

if remaining is null then

remain_print := \'.\';

else

remain_print := to_char(remaining,\'\$9,999,990.99\');

total_remaining := total_remaining + remaining;

end if;

htp.tableData(remain_print);

htp.tableRowClose;

\--

end if;

\-- F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

\--

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

end loop;

\--

htp.tableRowOpen;

htp.tableData;

htp.tableData(htf.bold(\'Total SRO\'\'s: \') \|\|
to_char(I_TOTAL_ROWS));

htp.tableData(htf.bold(\'Totals for this
page:\'),\'RIGHT\',\'\',\'\',\'\',\'3\');

htp.tableData(to_char(total_estimate,\'\$9,999,990.99\'));

htp.tableData(to_char(total_committed,\'\$9,999,990.99\'));

htp.tableData(to_char(total_remaining,\'\$9,999,990.99\'));

htp.tableRowClose;

htp.tableClose;

\--

dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formHidden(\'m_pid\',m_pid);

htp.formHidden(\'Z_START\', to_char(I_START));\--

htp.formHidden(\'i_operation\',i_operation);\--

htp.formHidden(\'i_org\',i_org);

htp.formHidden(\'i_sro_type\',i_sro_type);

htp.formHidden(\'i_open_date\',i_open_date);

htp.formHidden(\'i_close_date\',i_close_date);

htp.formHidden(\'i_sro_status\',i_sro_status);

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

\--

htp.para;

\--

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

\--

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

\--

\-- For toggle buttons \*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\--

\-- This is where the buttons are built for the application.

\--

if Z_ACTION = NEXT_BUT_CAPTION then

l_hold_page := TO_NUMBER(NVL(Z_PAGE_NO,\'0\')) +1;

elsif Z_ACTION = PREV_BUT_CAPTION then

l_hold_page := TO_NUMBER(Z_PAGE_NO) -1;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -1) /
SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

else

l_hold_page := to_number(nvl(Z_ACTION,\'1\'));

end if;

\--

htp.tableOpen;

\--

I_NEXT_SET_BUT := FALSE;

I_PREV_SET_BUT := FALSE;

I_FIRST_SET_BUT := FALSE;

I_LAST_SET_BUT := FALSE;

\--

if l_hold_page \> SLIDER_WIDTH then

I_PREV_SET_BUT := TRUE;

I_FIRST_SET_BUT := TRUE;

end if;

\--

\-- Displaying the NEXT SET BUTTOn

\--

if trunc((nvl(l_hold_page,1) - 1) / SLIDER_WIDTH) \< trunc((Y_TOTAL_ROWS
/ (Z_RECORD_SET_SIZE \* SLIDER_WIDTH)))

then

I_NEXT_SET_BUT := TRUE;

I_LAST_SET_BUT := TRUE;

end if;

\--

\-- ADDING THE PREVIOUS SET BUTTON FUNC.

\--

htp.tableRowOpen;

\--

y_temp := mod(l_hold_page,SLIDER_WIDTH);

\--

if y_temp = 0 then

x_temp := SLIDER_WIDTH;

else

x_temp := y_temp;

end if;

\--

\--temp

if l_hold_page is null then

l_hold_page := 1;

end if;

\--

htp.formHidden(\'Z_PAGE_NO\',l_hold_page);

cur_cnt := 1 + (l_hold_page - x_temp);

\--

\-- Creates the numeric toggle buttons on the bottom of the page.

\--

while cur_cnt \<= total_pages loop

if cur_cnt = l_hold_page then

htp.tableData(htf.bold(to_char(l_hold_page)));

else

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(\'
\'\|\|to_char(cur_cnt)\|\|\' \')));

end if;

\--

if mod(cur_cnt,SLIDER_WIDTH) = 0 then

exit;

end if;

cur_cnt := cur_cnt + 1;

end loop;

htp.tableRowClose;

htp.tableClose;

\--

\-- Creates the buttons on the bottom of the page to toggle from one
page, one set, or

\-- last set of buttons.

\--

htp.tableOpen(\'border\');

htp.tableRowOpen;

\--

\-- Creates the !\<\< button. The else condition on all of the following
buttons \"disables\"

\-- the button when the condition cannot be done.

\--

if I_FIRST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(FIRST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(FIRST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \<\< button.

\--

if I_PREV_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_SET_BUT_CAPTION\|\|\'&\'\|\|\'nbsp\'));

end if;

\--

\-- Creates the \< button.

\--

if I_PREV_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \> button.

\--

if I_NEXT_BUT then

htp.tableData(htf.bold(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_BUT_CAPTION))));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\> button.

\--

if I_NEXT_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\>! button.

\--

if I_LAST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(LAST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(LAST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p(MAX_ROWS_MESSAGE);

end if;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

/\* htp.p(\'\[\');

htp.anchor(G_ONLINE_HELP_FILE,G_ONLINE_HELP);

htp.p(\'\|\');

htp.anchor(\'wam0002.dcn_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

htp.p(\'\]\');\*/

lib.epilog;

htp.centerClose;

exception

when others then htp.p (SQLERRM);

end;

\--

\-- This procedure populates the third page of the application. It is
called from

\-- the link off of the wbs_no on the second page.

\--

END;

/

CREATE OR REPLACE PACKAGE webgen0001

IS

G_MENU_START_PAGE constant varchar2(50) := \'wam0002.DCN_MAIN_MENU\';

G_QUERY_START_PAGE_APP constant varchar2(50) := \'WEBGEN\';

G_QUERY_START_PAGE constant varchar2(50) := \'QUERY_START_PAGE\';

G_QUERY_OP constant varchar2(50) := \'Query\';

G_NEW_START_PAGE_APP constant varchar2(50) := \'DCN_NEW\';

G_NEW_START_PAGE constant varchar2(50) := \'NEW_START_PAGE\';

G_NEW_OP constant varchar2(50) := \'New\';

G_ADD_OP constant varchar2(50) := \'Add Another\';

G_REVISE_START_PAGE_APP constant varchar2(50) := \'DCN_REVISE\';

G_REVISE_START_PAGE constant varchar2(50) := \'REVISE_START_PAGE\';

G_REVISE_OP constant varchar2(50) := \'Revise\';

G_UPDATE_START_PAGE_APP constant varchar2(50) := \'DCN_UPDATE\';

G_UPDATE_START_PAGE constant varchar2(50) := \'UPDATE_START_PAGE\';

G_UPDATE_OP constant varchar2(50) := \'Update\';

G_RETURN_TO_QUERY constant varchar2(50) := \' Return to Query Page \';

G_RETURN_TO_NEW constant varchar2(50) := \' Request DCN-New Drawing \';

G_RETURN_TO_REVISE constant varchar2(50) := \' Request DCN-Revise
Drawing \';

G_RETURN_TO_UPDATE constant varchar2(50) := \' Update Drawing Title \';

G_BACK_TO_MENU constant varchar2(50) := \' Back to Main Menu \';

G_ONLINE_HELP constant varchar2(50) := \'Online Help\';

G_ONLINE_HELP_FILE constant varchar2(50) := \'/dcc-doc/dcn_help.html\';

\--

procedure query_start_page (i_pid in varchar2 default \'NEW\');

\--

procedure sign_off_page (i_pid in varchar2,

i_operation in varchar2 default NULL,

i_proc_detail_id in varchar2,

i_machine in varchar2 default NULL,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

\--

procedure query_result_page (m_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

i_machine in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

\--

procedure shop_list_page(i_pid in varchar2 default NULL,

i_proc_detail_id in varchar2 default NULL);

\--

procedure process_sign_off (i_pid in varchar2,

i_operation in varchar2 default \'Cancel\',

i_badge in varchar2 default null,

i_sign_off_date in varchar2 default null,

i_comments in varchar2 default null,

i_sub_sys_ready in varchar2 default null,

i_machine in varchar2 default NULL,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

i_proc_detail_id in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

\--Actual procedures for O P P (Oraweb Package Producer)

procedure start_page (i_pid in varchar2 default \'NEW\');

procedure tableSelectionPage (i_pid in varchar2,

i_table_name in varchar2 default NULL,

i_owner in varchar2 default NULL,

i_title in varchar2 default NULL);

procedure packageGenerator (i_pid in varchar2,

i_table_name in varchar2,

i_owner in varchar2,

i_title in varchar2,

i_display_cols in lib.val_arr,

i_criteria_cols in lib.val_arr,

i_package_name in varchar2);

END webgen0001;

/

CREATE OR REPLACE PACKAGE BODY webgen0001

IS

/\*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

DATE: INITIALS: REMARKS:

\-\-\-\-- \-\-\-\-\-\-\-\-- \-\-\-\-\-\-\--

14 AUG 98 KEM Create WEBGEN0001

Automates creation of Next-N

\*/

\--

\-- GLOBAL NEXT N settings

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \' \> \';

PREV_BUT_CAPTION constant varchar2(100) := \' \< \';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\>\>\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\<\<\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'!\<\<\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\>\>!\';

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 5;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'Maximimum number
of records (\'\|\|to_char(MAX_ROWS)\|\| \') returned\');

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

function badge_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(5);

cursor c_badge(p_pid in varchar2) is

select badge_no

from ows_app_login

where pid=p_pid;

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'?????\';

end if;

close c_badge;

return result;

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

return TRUE;

end;

end;

\--BEGIN OPP

function getColumnDataType (i_table_name in varchar2,i_column_name in
varchar2,i_owner in varchar2) return varchar2 is

begin

declare

cursor c_col_type (p_table_name in varchar2, p_column_name in varchar2,
p_owner in varchar2) is

select upper(DATA_TYPE)

from ALL_TAB_COLUMNS

where table_name = p_table_name

and column_name = p_column_name

and owner = p_owner;

result varchar2(20);

begin

open c_col_type(i_table_name, i_column_name, i_owner);

fetch c_col_type into result;

if c_col_type%NOTFOUND then

result := \'VARCHAR2\';

end if;

close c_col_type;

htp.p(\'\--Column type = \' \|\| result);

return(result);

end;

end getColumnDataType;

\--

function getColumnDataLength (i_table_name in varchar2,i_column_name in
varchar2,i_owner in varchar2) return number is

begin

declare

cursor c_col_length (p_table_name in varchar2, p_column_name in
varchar2, p_owner in varchar2) is

select DATA_LENGTH

from ALL_TAB_COLUMNS

where table_name = p_table_name

and column_name = p_column_name

and owner = p_owner;

result number;

begin

open c_col_length(i_table_name, i_column_name, i_owner);

fetch c_col_length into result;

if c_col_length%NOTFOUND then

result := 0;

end if;

close c_col_length;

return(result);

end;

end getColumnDataLength;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Select TABLE or VIEW for which to develop package

Table must be SELECTABLE from web enabled schema

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

procedure tableSelectionPage (i_pid in varchar2,

i_table_name in varchar2 default NULL,

i_owner in varchar2 default NULL,

i_title in varchar2 default NULL) is

begin

declare

\--ALL_TAB_COLUMNS contains columns from both TABLES and VIEWS

cursor c_cols(p_table_name in varchar2, p_owner in varchar2) is

select \*

from all_tab_columns

where table_name=p_table_name

and owner=p_owner;

l_operation varchar2(15);

begin

if is_valid_pid(i_pid) then

\--

lib.prolog(\'OPP Data Source Selection\');

htp.centerOpen;

htp.tableOpen;

\--

if i_table_name is null then

\--

htp.formOpen(\'webgen0001.tableSelectionPage\');

\--

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=RIGHT\>Displayed Title:\</TD\>\');

htp.tableData(htf.formText(\'i_title\',20,50));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=RIGHT\>Schema:\</TD\>\');

htp.tableData(htf.formText(\'i_owner\',20,50));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=RIGHT\>Table or view source:\</TD\>\');

htp.tableData(htf.formText(\'i_table_name\',20,50));

l_operation := \'Get Columns\';

htp.tableRowClose;

\--

else

\--

htp.formOpen(\'webgen0001.packageGenerator\');

\--

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=RIGHT\>\<B\>Table or view source:\</B\>\</TD\>\');

htp.tableData(UPPER(i_table_name));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Criteria Columns\'));

htp.tableData(htf.bold(\'Display Columns\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

\--

htp.p(\'\<TD\>\');

htp.formHidden(\'i_criteria_cols\',\'Empty\');

htp.formSelectOpen(\'i_criteria_cols\',\'\',\'10\',\'MULTIPLE\');

for r_cols in c_cols(i_table_name,i_owner) loop

htp.formSelectOption(r_cols.column_name);

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD\>\');

htp.formHidden(\'i_display_cols\',\'Empty\');

htp.formSelectOpen(\'i_display_cols\',\'\',\'10\',\'MULTIPLE\');

for r_cols in c_cols(i_table_name,i_owner) loop

htp.formSelectOption(r_cols.column_name);

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.tableRowClose;

\--

l_operation := \'Generate\';

htp.formHidden(\'i_table_name\',i_table_name);

htp.formHidden(\'i_owner\',i_owner);

htp.formHidden(\'i_title\',i_title);

\--

htp.tableRowOpen;

htp.p(\'\<TD ALIGN=RIGHT\>\<B\>Enter package name:\</B\>\</TD\>\');

htp.tableData(htf.formText(\'i_package_name\',25,50));

htp.tableRowClose;

\--

end if;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit(\'\',l_operation);

htp.centerClose;

htp.formClose;

lib.epilog;

end if;

end;

end;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

This is it. This procedure generates the new Next-N drill down

secure (eventually) package)

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

procedure packageGenerator (i_pid in varchar2,

i_table_name in varchar2,

i_owner in varchar2,

i_title in varchar2,

i_display_cols in lib.val_arr,

i_criteria_cols in lib.val_arr,

i_package_name in varchar2) is

begin

declare

cursor c_not_nullable(p_owner in varchar2,p_table_name in varchar2) is

select column_name

from all_tab_columns

where table_name = p_table_name

and owner=p_owner

order by column_id;

temp varchar2(50);

l_parameter varchar2(255);

l_data_type varchar2(50);

counter number;

l_package_name varchar2(10);

l_query_string varchar2(4000);

l_temp_string varchar2(2000);

begin

\-- Create security and login record in OWS_NT_PACKAGE_PRIV

select to_char(opp_seq.NextVal) into l_package_name from DUAL;

l_package_name := \'OPP\' \|\| l_package_name;

INSERT INTO OWS_NT_PACKAGE_PRIV

(OWS_PACKAGE,OWS_IP_GROUP,SECURITY_LEVEL,TITLE,PKG_NAME,RETURN_TO_PROC,USES_I_PID,PROFILE_ID)

VALUES

(l_package_name,\'IP_APS\',1,i_title,i_package_name,\'startPage\',\'Y\',1);

\--Create PACKAGE SPEC

htp.p(\'\<PRE\>\');

htp.p(\'CREATE OR REPLACE PACKAGE \' \|\| i_package_name \|\| \' IS\');

htp.p(\'PROCEDURE startPage (i_pid in varchar2 default \'\'NEW\'\');\');

htp.p(\'

PROCEDURE queryResultsPage (i_pid in varchar2,

i_operation in varchar2,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'\'10\'\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL,\');

\--dynamically include criteria columns

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_data_type :=
lower(getColumnDataType(i_table_name,l_parameter,i_owner));

if upper(l_data_type)=\'DATE\' then

l_data_type := \'varchar2\';

end if;

if cnt \< i_criteria_cols.count then

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL,\';

else

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL\';

end if;

htp.p(l_parameter);

end if;

end loop;

htp.p(\');\');

htp.p(\'END;\');

htp.p(\'/\');

\-- Create PACKAGE BODY

\-- ADD SECURITY TABLE INSERTS\....start w/level 5 open then add
development\...

htp.p(\'CREATE OR REPLACE PACKAGE BODY \' \|\| i_package_name \|\| \'
IS\');

\-- \* Include global constants for dbms_sql Next N \*

htp.p(\'

\--

\-- GLOBAL NEXT N settings

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'\'Clear\'\';

NEXT_BUT_CAPTION constant varchar2(100) := \'\' \> \'\';

PREV_BUT_CAPTION constant varchar2(100) := \'\' \< \'\';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\'\>\>\'\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\'\<\<\'\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'\'!\<\<\'\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\'\>\>!\'\';

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 5;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'\'Maximimum
number of records (\'\'\|\|to_char(MAX_ROWS)\|\| \'\') returned\'\');

\--Another global constant (for security and login)

G_QUERY_START_PAGE_APP constant varchar2(50) := \'\'\' \|\|
l_package_name \|\| \'\'\';

\');

\-- \* MAKE WEBGEN DYNAMIC PACKAGE NAME IN ABOVE LINE KM 8/14/98

htp.NL;

\-- \* End of global constants \*

htp.p(\'

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'\'\' \|\| l_package_name \|\| \'\'\';

result := log0002.is_valid_pid(i_pid, p_app_name);

return result;

end;

end;

\');

\-- \* End of functions

htp.NL;

htp.p(\'/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Enter criteria page

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\');

\-- \* Start criteria page procedure listing .. purposely private..not
in spec \*

htp.p (\'

procedure criteriaPage (i_pid in varchar2,

i_operation in varchar2,

i_msg in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL,\');

\--dynamically include criteria columns

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_data_type :=
lower(getColumnDataType(i_table_name,l_parameter,i_owner));

if upper(l_data_type)=\'DATE\' then

l_data_type := \'varchar2\';

end if;

if cnt \< i_criteria_cols.count then

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL,\';

else

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL\';

end if;

htp.p(l_parameter);

end if;

end loop;

htp.p(\') IS \');

htp.p(\'begin

declare\');

\-- Create look up cursors and local variables for drop down boxes

\-- If type is varchar2

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_data_type :=
lower(getColumnDataType(i_table_name,l_parameter,i_owner));

if l_data_type = \'varchar2\' then

htp.p(\'CURSOR c\_\' \|\| l_parameter \|\| \' is

select distinct \' \|\| l_parameter \|\|

\' from \' \|\| i_table_name \|\| \';\');

htp.NL;

htp.p (\'l\_\' \|\| l_parameter \|\| \' \' \|\| i_table_name \|\| \'.\'
\|\| l_parameter \|\| \'%TYPE;\');

htp.NL;

end if;

end if;

end loop;

htp.p(\'

begin

htp.formOpen(\'\'\' \|\| i_package_name \|\| \'.queryResultsPage\'\');

lib.prolog(\'\'Enter Criteria\'\');

htp.centerOpen;

htp.tableOpen;\');

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_data_type :=
lower(getColumnDataType(i_table_name,l_parameter,i_owner));

if l_data_type = \'varchar2\' then

\-- create drop down selection box

htp.p(\'htp.tableRowOpen;\');

htp.p(\'htp.tableData(\'\'\' \|\| l_parameter \|\| \':\'\');\');

htp.p(\'htp.p(\'\'&\' \|\| \'#60TD\' \|\| \'&\' \|\| \'gt\'\');\');

htp.p(\'htp.formSelectOpen(\'\'i\_\' \|\| l_parameter \|\| \'\'\');\');

htp.p(\'open c\_\' \|\| l_parameter \|\| \';\');

htp.p(\'htp.formSelectOption(NULL);\');

htp.p(\'fetch c\_\' \|\| l_parameter \|\| \' into l\_\' \|\| l_parameter
\|\| \';\');

htp.p(\'while not c\_\' \|\| l_parameter \|\| \'%NOTFOUND loop\');

htp.p(\' htp.formSelectOption(l\_\' \|\| l_parameter \|\| \');\');

htp.p(\' fetch c\_\' \|\| l_parameter \|\| \' into l\_\' \|\|
l_parameter \|\| \';\');

htp.p(\'end loop;\');

htp.p(\'close c\_\' \|\| l_parameter \|\| \';\');

htp.p(\'htp.formSelectClose;\');

htp.p(\'htp.p(\'\'&lt/TD&gt\'\');\');

htp.p(\'htp.tableRowClose;\');

htp.NL;

end if;

end if;

end loop;

htp.p(\'htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'\'Search\'\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'\'Z_START\'\', NULL);

htp.formHidden(\'\'Z_ACTION\'\',NEXT_BUT_CAPTION);

htp.formHidden(\'\'i_operation\'\',i_operation);

htp.formHidden(\'\'i_pid\'\',i_pid);

htp.formClose;

\--

\');

htp.p(\'lib.epilog;

end;

end;\');

\-- \* End criteria page procedure listing \*

\-- \* startPage code begins \*

htp.p(\'

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

startPage is the entry point for the package

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\');

htp.p(\'PROCEDURE startPage (i_pid in varchar2 default \'\'NEW\'\') is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'\'NEW\'\' or

NOT is_valid_pid (m_pid) then

log0002.login(G_QUERY_START_PAGE_APP,\'\'\'\',m_pid);

return;

end if;

\--

\-- Go to criteria page

\--

criteriaPage(i_pid,\'\'START\'\');

\--

end;\');

\-- \* end of startPage \*

\--

\-- Results page

\--

\-- This procedure list results of search using Dynamic SQL (dbms_sql)

\--

htp.p(\'

PROCEDURE queryResultsPage (i_pid in varchar2,

i_operation in varchar2,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'\'10\'\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL,\');

\--dynamically include criteria columns

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_data_type :=
lower(getColumnDataType(i_table_name,l_parameter,i_owner));

if upper(l_data_type)=\'DATE\' then

l_data_type := \'varchar2\';

end if;

if cnt \< i_criteria_cols.count then

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL,\';

else

l_parameter := \'i\_\' \|\| l_parameter \|\| \' in \' \|\| l_data_type
\|\| \' default NULL\';

end if;

htp.p(l_parameter);

end if;

end loop;

htp.p(\') IS\');

htp.p(\'BEGIN

DECLARE

\--

\-- Local variables for the second page (the query_result_page
procedure).

\--

I_QUERY varchar2(2000) := \'\'\'\';

i_where varchar2(2000) := \'\'\'\';

I_URL varchar2(2000) := \'\'\'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

I_NEXT_SET_BUT boolean;

I_PREV_SET_BUT boolean;

I_FIRST_SET_BUT boolean;

I_LAST_SET_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number := 10;

total_pages number;

cur_cnt number;

rec_counter number := 0;

temp_anchor varchar2(512);

err_pnt varchar2(255);

cnt number;

l_pre_cri varchar2(50);

l_page_no number;

l_hold_page number;

x_temp number;

y_temp number;

\--

j_query varchar2(2000) := \'\'\'\';

j_where varchar2(2000) := \'\'\'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned number := 0;

\');

htp.p(\'

r\_\' \|\| i_table_name \|\| \' \' \|\| i_table_name \|\|
\'%ROWTYPE;\');

htp.p(\'

\--

BEGIN

\--

if is_valid_pid(i_pid) then

\--

\-- start building the dynamic query

\--

\');

l_query_string := \'i_query := \'\'select\';

\--dynamically include display columns

for cnt in 1..i_display_cols.count loop

if i_display_cols(cnt) != \'Empty\' then

l_parameter := i_display_cols(cnt);

if cnt \< i_display_cols.count then

l_query_string := l_query_string \|\| \' \' \|\| i_table_name \|\| \'.\'
\|\| l_parameter \|\| \',\';

else

l_query_string := l_query_string \|\| \' \' \|\| i_table_name \|\| \'.\'
\|\| l_parameter ;

end if;

end if;

end loop;

l_query_string := l_query_string \|\| \' FROM \' \|\| i_table_name \|\|
\'\'\';\';

htp.p(l_query_string);

htp.p(\'

\--

\-- Begins to build the dynamic where clause

\-- This initial part is static while the following if\'\'s add onto the
where clause

\-- when the conditions are met.

\--

i_where := \'\'\'\';

\--

\-- The following series of if\'\'s dynamicly add to the where clause
when the conditions

\-- are met.

\--

\');

\--dynamically include display columns

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

if cnt \<= i_criteria_cols.count then

htp.NL;

l_temp_string := \' if i\_\' \|\| i_criteria_cols(cnt) \|\| \' is NOT
NULL then\';

htp.p(l_temp_string);

htp.p(\'

if i_where is NULL then

l_pre_cri := \'\' WHERE \'\';

else

l_pre_cri := \'\' AND \'\';

end if;\');

l_temp_string := \'i_where := i_where \|\| l_pre_cri \|\| \'\'\' \|\|
i_table_name \|\| \'.\' \|\| i_criteria_cols(cnt) \|\| \' = \'\'\'\'\'\'
\|\| i\_\' \|\| i_criteria_cols(cnt) \|\| \' \|\| \'\'\'\'\'\'\'\';\';

htp.p(l_temp_string);

htp.p(\'end if;\');

end if;

end if;

end loop;

htp.p(\'\--

\-- This counts the number of records returned in order to place the

\-- correct number of buttons on the bottom of the page.

\--

\--

htp.p(\'\'Where CLAUSE = \'\' \|\| i_where);

\');

\-- Find a not null column in table for a count

open c_not_nullable(i_owner,i_table_name);

fetch c_not_nullable into temp;

close c_not_nullable;

\-- IF NOT FOUND CREATE EXCEPTION\...Next -N requires PK

htp.p(\'

if Z_TOTAL_ROWS is NULL then

j_query := \'\'select count(\' \|\| temp \|\| \') FROM \' \|\|
i_table_name \|\| \'\'\';

j_where := i_where;

j_query := j_query \|\|\'\' \'\'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\');

htp.p(\' htp.p(\'\'Total Rows = \'\' \|\| Y_TOTAL_ROWS);\');

\--

htp.p(\' I_CURSOR := dbms_sql.open_cursor;\');

htp.p(\' i_query := i_query \|\|\'\' \'\'\|\| i_where\|\| \'\' order by
\' \|\| temp \|\| \'\'\';\');

htp.p(\' htp.p(i_query);\');

\--

htp.p(\' dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);\');

for cnt in 1..i_display_cols.count loop

if i_display_cols(cnt) != \'Empty\' then

\-- if vc include size, else not

if getColumnDataType(i_table_name,i_display_cols(cnt),i_owner) =
\'VARCHAR2\' then

htp.p(\' dbms_sql.define_column(I_CURSOR,\' \|\| to_char(cnt - 1) \|\|
\', r\_\' \|\| i_table_name \|\| \'.\'\|\| i_display_cols(cnt) \|\|
\',\' \|\|
to_char(getColumnDataLength(i_table_name,i_display_cols(cnt),i_owner))
\|\| \');\');

else

htp.p(\' dbms_sql.define_column(I_CURSOR,\' \|\| to_char(cnt - 1) \|\|
\', r\_\' \|\| i_table_name \|\| \'.\'\|\| i_display_cols(cnt) \|\|
\');\');

end if;

end if;

end loop;

\--

htp.p(\'I_VOID := dbms_sql.execute (I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);\');

htp.p(\'

\--

\-- Checks to see if there were any rows retrieved from the parameters
entered. If none

\-- then it will display the message with the values entered.

\--

if I_ROWS_FETCHED = 0 then

dbms_sql.close_cursor(I_CURSOR);

\--enter_criteria (m_pid,

\-- i_operation,

\-- \'\'No records were found matching those criteria.\'\',

\-- i_machine,

\-- i_subsystem,

\-- i_components,

\-- i_system,

\-- i_range_from,

\-- i_range_to,

\-- Z_RECORD_SET_SIZE);

htp.p(\'\'Not found\'\');

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

htp.formHidden(\'\'Z_TOTAL_ROWS\'\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -
1)/SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

I_START := ((l_hold_page -1) \* record_set_size) + 1;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

I_START := 1;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\');

htp.p(\'

lib.prolog(\'\'Results Page\'\');

\--

\-- Places the header fields on the begining of the report. Note:
tableHeader

\-- automaticly bolds the text for you.

\--

htp.centerOpen;

htp.tableOpen(\'\'border\'\');\');

for cnt in 1..i_display_cols.count loop

if i_display_cols(cnt) != \'Empty\' then

htp.p(\'htp.tableHeader(\'\'\' \|\| i_display_cols(cnt) \|\|
\'\'\');\');

end if;

end loop;

htp.p(\'while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then\');

for cnt in 1..i_display_cols.count loop

if i_display_cols(cnt) != \'Empty\' then

htp.p(\'dbms_sql.column_value(I_CURSOR, \' \|\| to_char(cnt - 1) \|\|
\',r\_\' \|\| i_table_name \|\| \'.\' \|\| i_display_cols(cnt) \|\|
\');\');

end if;

end loop;

htp.p(\'I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or

I_TOTAL_ROWS \>= 1)) then

\--

\-- Starts to retrieve the data requested for the page.

\-- \');

htp.p(\'htp.tableRowOpen;\');

for cnt in 1..i_display_cols.count loop

if i_display_cols(cnt) != \'Empty\' then

htp.p(\'htp.tableData(r\_\'\|\|i_table_name\|\|\'.\'\|\|i_display_cols(cnt)\|\|\');\');

end if;

end loop;

htp.p(\'htp.tableRowClose;

else

htp.p(\'\' \*\*\*\*\* \'\');

htp.br;

end if;\');

htp.p(\'

\--

\-- F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

\--

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

end loop;

\--

htp.tableClose;\');

\--BEGIN 9/3/98

htp.p(\'htp.formOpen(\'\'\'\|\| i_package_name \|\|
\'.queryResultsPage\'\');\');

htp.p(\'

\-- dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formHidden(\'\'i_pid\'\',i_pid);

htp.formHidden(\'\'Z_START\'\',to_char(I_START));

htp.formHidden(\'\'i_operation\'\',i_operation);\');

\--dynamically include criteria columns as formHiddens

for cnt in 1..i_criteria_cols.count loop

if i_criteria_cols(cnt) != \'Empty\' then

l_parameter := i_criteria_cols(cnt);

l_parameter := \'htp.formHidden(\'\'i\_\' \|\| l_parameter \|\|
\'\'\',i\_\' \|\| l_parameter \|\| \');\';

htp.p(l_parameter);

end if;

end loop;

htp.p(\'

if I_START = I_TOTAL_ROWS then

htp.p(\'\'Record \'\'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'\'Records \'\'\|\|to_char(I_START) \|\|

\'\' to \'\'\|\|to_char(I_TOTAL_ROWS));

end if;

\--

htp.para;\');

htp.p(\'

\--

\-- Just in case reload button was pressed

\-- htp.formHidden(\'\'Z_ACTION\'\',NEXT_BUT_CAPTION);

\--

htp.formHidden(\'\'Z_RECORD_SET_SIZE\'\',Z_RECORD_SET_SIZE);

\--

\-- For toggle buttons \*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\--

\-- This is where the buttons are built for the application.

\--

if Z_ACTION = NEXT_BUT_CAPTION then

l_hold_page := TO_NUMBER(NVL(Z_PAGE_NO,\'\'0\'\')) +1;

elsif Z_ACTION = PREV_BUT_CAPTION then

l_hold_page := TO_NUMBER(Z_PAGE_NO) -1;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -1) /
SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

else

l_hold_page := to_number(nvl(Z_ACTION,\'\'1\'\'));

end if;

\--

htp.tableOpen;

\--

I_NEXT_SET_BUT := FALSE;

I_PREV_SET_BUT := FALSE;

I_FIRST_SET_BUT := FALSE;

I_LAST_SET_BUT := FALSE;

\--

if l_hold_page \> SLIDER_WIDTH then

I_PREV_SET_BUT := TRUE;

I_FIRST_SET_BUT := TRUE;

end if;

\--

\-- Displaying the NEXT SET BUTTON

\--

if trunc((nvl(l_hold_page,1) - 1) / SLIDER_WIDTH) \< trunc((Y_TOTAL_ROWS
/ (Z_RECORD_SET_SIZE \* SLIDER_WIDTH)))

then

I_NEXT_SET_BUT := TRUE;

I_LAST_SET_BUT := TRUE;

end if;

\--

\-- ADDING THE PREVIOUS SET BUTTON FUNC.

\--

htp.tableRowOpen;

\--

y_temp := mod(l_hold_page,SLIDER_WIDTH);

\--

if y_temp = 0 then

x_temp := SLIDER_WIDTH;

else

x_temp := y_temp;

end if;

\--

htp.formHidden(\'\'Z_PAGE_NO\'\',l_hold_page);

cur_cnt := 1 + (l_hold_page - x_temp);

\--

\-- Creates the numeric toggle buttons on the bottom of the page.

\--

while cur_cnt \<= total_pages loop

if cur_cnt = l_hold_page then

htp.tableData(htf.bold(to_char(l_hold_page)));

else

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(\'\'
\'\'\|\|to_char(cur_cnt)\|\|\'\' \'\')));

end if;

\--

if mod(cur_cnt,SLIDER_WIDTH) = 0 then

exit;

end if;

cur_cnt := cur_cnt + 1;

end loop;

htp.tableRowClose;

htp.tableClose;

\--

\-- Creates the buttons on the bottom of the page to toggle from one
page, one set, or

\-- last set of buttons.

htp.tableOpen(\'\'border\'\');

htp.tableRowOpen;

\-- Creates the !\<\< button. The else condition on all of the following
buttons \"disables\"

\-- the button when the condition cannot be done.

\--

if I_FIRST_SET_BUT then

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(FIRST_SET_BUT_CAPTION)));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(FIRST_SET_BUT_CAPTION)\|\|\'\'&\'\'\|\|\'\'nbsp\'\');

end if;

\--

\-- Creates the \<\< button.

\--

if I_PREV_SET_BUT then

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(PREV_SET_BUT_CAPTION)));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(PREV_SET_BUT_CAPTION\|\|\'\'&\'\'\|\|\'\'nbsp\'\'));

end if;

\--

\-- Creates the \< button.

\--

if I_PREV_BUT then

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(PREV_BUT_CAPTION)));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(PREV_BUT_CAPTION)\|\|\'\'&\'\'\|\|\'\'nbsp\'\');

end if;

\--

\-- Creates the \> button.

\--

if I_NEXT_BUT then

htp.tableData(htf.bold(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(NEXT_BUT_CAPTION))));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(NEXT_BUT_CAPTION)\|\|\'\'&\'\'\|\|\'\'nbsp\'\');

end if;

\--

\-- Creates the \>\> button.

\--

if I_NEXT_SET_BUT then

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(NEXT_SET_BUT_CAPTION)));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(NEXT_SET_BUT_CAPTION)\|\|\'\'&\'\'\|\|\'\'nbsp\'\');

end if;

\--

\-- Creates the \>\>! button.

\--

if I_LAST_SET_BUT then

htp.tableData(htf.formSubmit(\'\'Z_ACTION\'\',htf.escape_sc(LAST_SET_BUT_CAPTION)));

else

htp.tableData(\'\'&\'\'\|\|\'\'nbsp\'\'\|\|htf.bold(LAST_SET_BUT_CAPTION)\|\|\'\'&\'\'\|\|\'\'nbsp\'\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p(MAX_ROWS_MESSAGE);

end if;

\--\');

htp.p(\'end if;

EXCEPTION

when others then

htp.p(\'\'i_query = \'\' \|\| i_query);

htp.nl;

htp.p(\'\'j_query = \'\' \|\| j_query);

htp.nl;

htp.p(SQLERRM);

end;

end;\');

\-- End Results Page

\--

htp.p(\'END \' \|\| i_package_name \|\| \';\');

htp.p(\'/\');

htp.p(\'\</PRE\>\');

Exception when others then

htp.p(sqlerrm);

end;

end;

\--

procedure start_page (i_pid in varchar2 default \'NEW\') is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid);

return;

end if;

\--

\-- Goes to the table and column selection procedure.

\--

tableSelectionPage(i_pid);

\--

end;

\--END of OPP

procedure enter_criteria (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_machine in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_component in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL) is

cursor c_machine is

select \* from

rf_machine_table;

cursor c_system is

select \* from

rf_system_table;

cursor c_components is

select \* from

rf_component_table;

cursor c_sub_components is

select distinct(sub_system) sub_system

from rf_maint_sub_system;

cursor c_subsystem (p_machine_id in number) is

select \*

from rf_subsystem_table

where machine_id=p_machine_id;

cursor c_task_grouping is

select distinct(abbreviation) abbreviation

from rf_maint_prod_header;

\--

l_range_from varchar2(20);

l_range_to varchar2(20);

temp_idx number(2);

temp varchar2(255);

\--

begin

\--Javascript begin

htp.p(\'\<SCRIPT LANGUAGE=Javascript\>\');

htp.p(\'// BOI, followed by one or more digits, followed by EOI.

var reInteger = /\^\\d+\$/;

var reSignedInteger = /\^\\d+\$/

select_lists = new Object;

var bc=0;

var fc=0;

var daysInMonth = makeArray(12);

daysInMonth\[1\] = 31;

daysInMonth\[2\] = 29; // must programmatically check this

daysInMonth\[3\] = 31;

daysInMonth\[4\] = 30;

daysInMonth\[5\] = 31;

daysInMonth\[6\] = 30;

daysInMonth\[7\] = 31;

daysInMonth\[8\] = 31;

daysInMonth\[9\] = 30;

daysInMonth\[10\] = 31;

daysInMonth\[11\] = 30;

daysInMonth\[12\] = 31;

var monthDelimiter = \"\|\";

var
monthArray=\"JAN\|FEB\|MAR\|APR\|MAY\|JUN\|JUL\|AUG\|SEP\|OCT\|NOV\|DEC\";

\');

\-- populate dynamic javascript arrays from database

htp.p(\'

//define Constructor for select list objects

function List()

{

this.text = new Array;

this.value = new Array;

}\');

for r_machine in c_machine loop

temp_idx := 0;

temp := \'select_lists.\' \|\| r_machine.web_ref_name \|\| \' = new
List();\';

htp.p(temp);

for r_sub in c_subsystem(r_machine.machine_id) loop

temp := \'select_lists.\' \|\| r_machine.web_ref_name \|\| \'.text\[\'
\|\| to_char(temp_idx) \|\| \'\]=\"\' \|\| r_sub.subsys_name \|\|
\'\";\';

htp.p(\' \' \|\| temp);

temp := \'select_lists.\' \|\| r_machine.web_ref_name \|\| \'.value\[\'
\|\| to_char(temp_idx) \|\| \'\]=\"\' \|\| to_char(r_sub.subsystem_id)
\|\| \'\";\';

htp.p(\' \' \|\| temp);

temp_idx := temp_idx + 1;

end loop;

end loop;

htp.p(\'//copy the select list from the select_list object to the form
field

function copy_select_list(field_obj,value_char)

{ // alert (\"COPY SELECT LIST FUCTION\\n\");

field_obj.length = select_lists\[value_char\].text.length;

for (i=0;i\<field_obj.length;i++)

{

if (i \< field_obj.length)

{

field_obj.options\[i\].text = select_lists\[value_char\].text\[i\];

field_obj.options\[i\].value = select_lists\[value_char\].value\[i\];

}

else

{

field_obj.options\[i\].text = \"\";

field_obj.options\[i\].value = \"\";

}

// field_obj.options\[0\].selected = true;

}

}//copy_select_list

function onBlur_select_list(field_obj,list_obj)

{

bc = bc + 1;

if (bc == 1)

{//alert (\"ON BLUR SELECT LIST\\n\");

copy_select_list(field_obj,list_obj);

bc = bc - 1};

}//onblur_select_list

function onFocus_select_list(field_obj,value_char)

{

fc = fc + 1;

if (fc == 1)

{

if (value_char == \"\")

{

alert(\"Correlating value is not set\");

document.lists.clist.focus();

}

}

fc = fc - 1;

}//list_focus\');

\-- end of javascript dynamic drop down section\...begin date validation
code

htp.p(\' function checkform(form){

//allow empty dates if both empty

if (isEmpty(form.i_range_from.value) && isEmpty(form.i_range_to.value))
return true;

//

if (!isOracleDate(form.i_range_from.value)){

alert (\"Not a FROM valid date. Please use format: DD-MON-YYYY\");

return false;}

if (!isOracleDate(form.i_range_to.value)){

alert (\"Not a TO valid date. Please use format: DD-MON-YYYY\");

return false;}

return true;}

// Check whether string s is empty.

function isEmpty(s)

{ return ((s == null) \|\| (s.length == 0))

}

//

// Date validation code\...portions adapted from netscape site

// isOracleDate - original code

function isOracleDate(oracle_date) {

day=oracle_date.substring(0,2);

month=oracle_date.substring(3,6);

monthUpper=month.toUpperCase();

monthVal=monthArray.indexOf(monthUpper);

month_number=parseInt(monthVal,10) / 4 + 1;

year=oracle_date.substring(7,11);

dash1=oracle_date.substring(2,3);

dash2=oracle_date.substring(6,7);

//check for dashes

if (dash1!=\"-\") return false;

if (dash2!=\"-\") return false;

if (!isYear(year)){

alert(\"Not a valid year.\");

return false;}

if (!isDay(day)) {

alert(\"Not a valid day\");

return false;}

if (!isMonth(month_number)){

alert(\"Not a valid month\");

return false;}

var intYear = parseInt(year,10);

var intMonth = month_number;

var intDay = parseInt(day,10);

// catch invalid days, except for February

if (intDay \> daysInMonth\[intMonth\]) return false;

if ((intMonth == 2) && (intDay \> daysInFebruary(intYear))) return
false;

return true;

}

//

function daysInFebruary (year)

{// February has 29 days in any year evenly divisible by four,

// EXCEPT for centurial years which are not also divisible by 400.

return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) \|\| (year % 400 ==
0) ) ) ? 29 : 28 );

}

//

function isInteger(s) {

return reSignedInteger.test(s);

};

//

function isIntegerInRange(s,a,b){

var num = parseInt (s,10);

return ((num \>= a) && (num \<= b));}

//

function isYear(year){

if (!isInteger(year)) return false;

return (year.length == 4);}

//

function isMonth(month){

return isIntegerInRange (month, 1, 12);}

//

function isDay(day){

return isIntegerInRange(day,1,31);}

//

function makeArray(n) {

for (var i = 1; i \<= n; i++) {

this\[i\] = 0 }

return this

}

\');

htp.p(\'\</SCRIPT\>\');

\--End Javascript

\--l_range_from :=
to_char(to_date(i_from_year\|\|i_from_month\|\|i_from_day,\'YYYYMMDD\'));

\--l_range_to :=
to_char(to_date(i_to_year\|\|i_to_month\|\|i_to_day,\'YYYYMMDD\'));

\--

lib.prolog(\'Enter Search Criteria: \');

\--

\-- if p_msg is NOT NULL then

\-- htp.tableOpen;

\-- htp.tableRowOpen;

\-- htp.tableData(htf.em(p_msg));

\-- htp.tableRowClose;

\-- htp.tableClose;

\-- end if;

\--

\-- Sets up the first page in order to enter in fields to query off of.

\--

htp.centerOpen;

if p_msg is not null then

htp.p(\'\<font type=arial size=4 color=#0000FF\>\' \|\| p_msg \|\|
\'\</font\>\');

end if;

htp.p(\'\<FORM ACTION=\"webgen0001.query_result_page\" METHOD=\"POST\"
NAME=\"lists\" onSubmit=\"return checkform(this)\"\>\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableHeader(\'System By Machine: \',\'Right\');

htp.p(\'\<td\>\');

\--htp.formSelectOpen(\'i_machine\');

htp.p(\'\<select NAME=\"i_machine\"

onChange=\"onBlur_select_list(lists.i_subsystem,this.options\[this.selectedIndex\].value)\"\>;\');

\--htp.formSelectOption(\'All\');

for r_machine in c_machine LOOP

htp.formSelectOption(r_machine.machine_name,null,\'VALUE=\' \|\|
r_machine.web_ref_name);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'RF System: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_system\');

\--htp.formSelectOption(\'All\');

for r_system in c_system LOOP

htp.formSelectOption(r_system.system_name,null,\'VALUE=\'\|\|r_system.system_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Components: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_components\');

\--htp.formSelectOption(\'All\');

for r_components in c_components LOOP

htp.formSelectOption(r_components.COMP_NAME,null,\'VALUE=\' \|\|
r_components.comp_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Sub-systems: \',\'Right\');

htp.p(\'\<td\>\');

htp.p(\'\<SELECT NAME=\"i_subsystem\" SIZE=5\>\');

\--htp.formSelectOption(\'All\');

for r_subsystem in c_subsystem(1) LOOP

htp.formSelectOption(r_subsystem.subsys_name,null,\'VALUE=\' \|\|
r_subsystem.subsystem_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Date Range: From \',\'Right\');

htp.tabledata(htf.formText(\'i_range_from\',\'11\',\'11\',i_range_from)
\|\|

htf.Bold(\' To \') \|\|

htf.formText(\'i_range_to\',\'11\',\'11\',i_range_to));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'DD-MON-YYYY\'),\'Right\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'View records in groups of:\'));

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',\'2\',\'2\',nvl(Z_RECORD_SET_SIZE,\'10\')));

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'m_pid\',m_pid);

htp.formClose;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

htp.para;

htp.para;

htp.p(\'\[\');

\-- htp.anchor(dcc0005.G_ONLINE_HELP_FILE,G_ONLINE_HELP);

\-- htp.p(\'\|\');

htp.anchor(\'wam0002.rfm_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

htp.p(\'\]\');

htp.centerClose;

lib.epilog;

end;

\--

\-- Checks to see if its a valid PID

\--

procedure query_start_page (i_pid in varchar2 default \'NEW\') is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid);

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\--

enter_criteria(m_pid,G_QUERY_OP);

\--

end;

\--

\-- This procedure list results of search using Dynamic SQL (dbms_sql)

\--

procedure query_result_page (m_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

i_machine in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL) is

\-- Set up the cursors for your detail page (Page 2).

\--

cursor cur_signoff_view(p_rf_proc_detail_id in number) is

select \*

from eq_rf_last_signoff_view

where RF_PROC_DETAIL_ID = p_rf_proc_detail_id;

\--

cursor c_machine (p_machine_name in varchar2) is

select initcap(machine_name)

from rf_machine_table

where web_ref_name = p_machine_name;

cursor c_component (p_comp_id in number) is

select initcap(comp_name)

from rf_component_table

where comp_id = p_comp_id;

cursor c_system (p_system_id in number) is

select initcap(system_name)

from rf_system_table

where system_id=p_system_id;

cursor c_subsystem (p_subsystem_id in number) is

select subsys_name

from rf_subsystem_table

where subsystem_id=p_subsystem_id;

\--

\-- Local variables for the second page (the query_result_page
procedure).

\--

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

I_NEXT_SET_BUT boolean;

I_PREV_SET_BUT boolean;

I_FIRST_SET_BUT boolean;

I_LAST_SET_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number := 10;

total_pages number;

cur_cnt number;

rec_counter number := 0;

temp_anchor varchar2(512);

dcc_print varchar2(512);

l_range_from varchar2(20);

l_range_to varchar2(20);

err_pnt varchar2(255);

\--

type rf_maint_proc_detail_type is

record(rf_proc_detail_id rf_maint_proc_detail.rf_proc_detail_id%type,

step_number rf_maint_proc_detail.step_number%type,

description rf_maint_proc_detail.description%type,

month_interval rf_maint_proc_detail.month_interval%type,

link rf_maint_proc_detail.link%type,

comments rf_sign_off.comments%type,

completed rf_sign_off.completed%type);

r_rf_maint_proc_detail rf_maint_proc_detail_type;

r_signoff_view cur_signoff_view%rowtype;

temp_cae_in varchar2(25);

temp_wbs_in varchar2(25);

temp_title_in varchar2(2000);

temp_dbadge_in varchar2(25);

temp_ebadge_in varchar2(25);

temp_ldn_in varchar2(25);

temp_dcn_in varchar2(25);

l_title varchar2(2000);

l_pre_cri varchar2(50);

l_dwg_no varchar2(100);

l_page_no number;

l_hold_page number;

x_temp number;

y_temp number;

\--

j_query varchar2(2000) := \'\';

j_where varchar2(2000) := \'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned number := 0;

instructions varchar2(255);

\--

title varchar2(255);

l_machine rf_machine_table.machine_name%TYPE;

l_components rf_component_table.comp_name%TYPE;

l_subsystem rf_subsystem_table.subsys_name%TYPE;

l_system rf_system_table.system_name%TYPE;

\--

begin

\--

if is_valid_pid(m_pid) then

\--

l_range_from := i_range_from;

l_range_to := i_range_to;

\--the dynamic select statement to retrieve the complete_document_no
which is a

\-- unique field that can retrieve any other fields needed via cursors.

\--

i_query := \'select pd.rf_proc_detail_id, pd.step_number,
initcap(pd.description), pd.month_interval, pd.link, so.comments,
so.completed \' \|\|

\' from rf_maint_proc_header ph, rf_maint_proc_detail pd,
rf_machine_table mt, eq_rf_last_signoff_view so \' ;

\--

\-- Begins to build the dynamic where clause

\-- This initial part is static while the following if\'s add onto the
where clause

\-- when the conditions are met.

\--

i_where := \'where pd.rf_proc_id = ph.rf_proc_id and
so.rf_proc_detail_id(+) = pd.rf_proc_detail_id and mt.machine_id =
ph.machine_id\';

\--

\-- The following series of if\'s dynamicly add to the where clause when
the conditions

\-- are met.

\--

err_pnt := \'FIRST ERROR POINT\';

if i_machine is NOT NULL and i_machine != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\'mt.web_ref_name = \'\'\'
\|\| i_machine \|\| \'\'\'\';

end if;

if i_components is NOT NULL and i_components != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\'comp_id = \'\'\' \|\|
i_components \|\| \'\'\'\';

end if;

if i_system is NOT NULL and i_system != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\'system_id = \'\'\' \|\|
i_system \|\| \'\'\'\';

end if;

if i_subsystem is NOT NULL and i_subsystem != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\'rf_subsys_id = \'\'\' \|\|
i_subsystem \|\| \'\'\'\';

end if;

\--if i_range_from is NOT NULL and i_range_to is NOT NULL then

if l_range_from is NOT NULL and l_range_to is NOT NULL then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' (so.sign_off_date is null
or (so.sign_off_date + to_number(pd.month_interval)) between
to_date(\'\'\'\|\|l_range_from\|\|\'\'\',\'\'DD-MON-YYYY\'\') and
to_date(\'\'\'\|\|l_range_to\|\|\'\'\',\'\'DD-MON-YYYY\'\'))\';

end if;

\--

\-- This counts the number of records returned in order to place the

\-- correct number of buttons on the bottom of the page.

\--

\--

\-- \*\*\*\* This is where the invalid column field is coming from. Once
the dynamic

\-- where clause is uncommented the invalid column comes up.

\--

if Z_TOTAL_ROWS is NULL then

j_query := \' select count(pd.rf_proc_detail_id) \'

\|\|\' from \'\|\|\' rf_maint_proc_header ph, rf_maint_proc_detail pd,
rf_machine_table mt, eq_rf_last_signoff_view so \' ;

j_where := i_where;

j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\--

I_CURSOR := dbms_sql.open_cursor;

i_query := i_query \|\|\' \'\|\| i_where\|\|\' order by
pd.rf_proc_detail_id\';

\-- htp.p(i_query);

\--

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1,
r_rf_maint_proc_detail.rf_proc_detail_id);

dbms_sql.define_column(I_CURSOR, 2, r_rf_maint_proc_detail.step_number);

dbms_sql.define_column(I_CURSOR, 3,
r_rf_maint_proc_detail.description,255);

dbms_sql.define_column(I_CURSOR, 4,
r_rf_maint_proc_detail.month_interval);

dbms_sql.define_column(I_CURSOR, 5, r_rf_maint_proc_detail.link,255);

dbms_sql.define_column(I_CURSOR, 6,
r_rf_maint_proc_detail.comments,255);

dbms_sql.define_column(I_CURSOR, 7, r_rf_maint_proc_detail.completed,1);

\--

I_VOID := dbms_sql.execute (I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

\--

\-- Checks to see if there were any rows retrieved from the parameters
entered. If none

\-- then it will display the message with the values entered.

\--

if I_ROWS_FETCHED = 0 then

dbms_sql.close_cursor(I_CURSOR);

enter_criteria (m_pid,

i_operation,

\'No records were found matching those criteria.\',

i_machine,

i_subsystem,

i_components,

i_system,

i_range_from,

i_range_to,

Z_RECORD_SET_SIZE);

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -
1)/SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

I_START := ((l_hold_page -1) \* record_set_size) + 1;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

I_START := 1;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\-- Puts the viewable \"Header\" portion on page two.

\--

open c_machine (i_machine);

fetch c_machine into l_machine;

close c_machine;

open c_component(i_components);

fetch c_component into l_components;

close c_component;

open c_subsystem(i_subsystem);

fetch c_subsystem into l_subsystem;

close c_subsystem;

open c_system(i_system);

fetch c_system into l_system;

close c_system;

title := l_machine \|\| \' Maintenance: \' \|\| l_subsystem \|\| \' (\'
\|\| l_components \|\| \', \' \|\| l_system \|\| \')\';

lib.prolog(title);

\--

\-- Places the header fields on the begining of the report. Note:
tableHeader

\-- automaticly bolds the text for you.

\--

htp.centerOpen;

htp.tableOpen(\'border\');

htp.tableHeader(\'Step \');

htp.tableHeader(\'Desc Of Work \');

htp.tableHeader(\'Last Sign Off\');

htp.tableHeader(\'Interval \');

htp.tableHeader(\'Maint. Due by \');

htp.tableHeader(\'Instructions \');

htp.tableHeader(\'Comments \');

htp.tableHeader(\'Sub Sys Ready \');

htp.tableHeader(\'Sign Off \');

htp.tableHeader(\'Shop List \');

\--

err_pnt := \'2.4444\';

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1,
r_rf_maint_proc_detail.rf_proc_detail_id);

err_pnt := \'2.45\';

dbms_sql.column_value(I_CURSOR, 2, r_rf_maint_proc_detail.step_number);

err_pnt := \'2.46\';

dbms_sql.column_value(I_CURSOR, 3, r_rf_maint_proc_detail.description);

err_pnt := \' 2.47\';

dbms_sql.column_value(I_CURSOR, 4,
r_rf_maint_proc_detail.month_interval);

dbms_sql.column_value(I_CURSOR, 5, r_rf_maint_proc_detail.link);

dbms_sql.column_value(I_CURSOR, 6, r_rf_maint_proc_detail.comments);

dbms_sql.column_value(I_CURSOR, 7, r_rf_maint_proc_detail.completed);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or

I_TOTAL_ROWS \>= 1)) then

\--

\-- Starts to retrieve the data requested for the page.

\--

htp.tableRowOpen;

htp.tableData(r_rf_maint_proc_detail.step_number,\'Center\');

htp.tableData(r_rf_maint_proc_detail.description,\'Center\');

\--

err_pnt := \'2.5555\';

open cur_signoff_view(r_rf_maint_proc_detail.rf_proc_detail_id);

fetch cur_signoff_view into r_signoff_view;

if cur_signoff_view%NOTFOUND then

htp.tableData(\'None yet\');

else

htp.tableData(to_char(r_signoff_view.sign_off_date,\'DD-MON-YYYY\'),\'Center\');

end if;

htp.tableData(r_rf_maint_proc_detail.month_interval,\'Center\');

if cur_signoff_view%NOTFOUND then

htp.tableData(\';\');

else

htp.tableData(to_char((r_signoff_view.sign_off_date +
r_rf_maint_proc_detail.month_interval),\'DD-MON-YYYY\'),\'Center\');

end if;

close cur_signoff_view;

err_pnt := \'THIRD ERROR POINT\';

temp_anchor := \'http://www.aps.anl.gov\';

instructions := htf.anchor(temp_anchor,\'Link\');

htp.tableData(instructions,\'Center\');

\--

htp.tableData(nvl(r_rf_maint_proc_detail.comments,\'\'),\'Center\');

htp.tableData(nvl(r_rf_maint_proc_detail.completed,\'\'),\'Center\');

htp.p(\'\<td\>\');

htp.formOpen(\'webgen0001.sign_off_page\');

htp.formHidden(\'i_pid\',m_pid);

htp.formHidden(\'i_proc_detail_id\',r_rf_maint_proc_detail.rf_proc_detail_id);

htp.formHidden(\'i_system\',i_system);

htp.formHidden(\'i_subsystem\',i_subsystem);

htp.formHidden(\'i_components\',i_components);

htp.formHidden(\'i_machine\',i_machine);

htp.formHidden(\'i_range_from\',i_range_from);

htp.formHidden(\'i_range_to\',i_range_to);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formHidden(\'Z_TOTAL_ROWS\',Z_TOTAL_ROWS);

htp.formHidden(\'Z_PAGE_NO\',Z_PAGE_NO);

\--OK for quick sign off \... date=sysdate,

\-- badge=current user badge, sys ok = Y

\-- per meeting 28-FEB-98 w/ G. Pile

\-- kem 28-FEB-98

htp.formSubmit(\'i_operation\',\'OK\');

htp.formSubmit(\'i_operation\',\'Comments\');

\--

htp.formClose;

htp.p(\'\</td\>\');

htp.p(\'\<td\>\');

htp.formOpen(\'webgen0001.shop_list_page\');

htp.formHidden(\'i_pid\',m_pid);

htp.formHidden(\'i_proc_detail_id\',r_rf_maint_proc_detail.rf_proc_detail_id);

htp.formSubmit(NULL,\'Shop List\');

htp.formClose;

htp.p(\'\</td\>\');

\--

\--

htp.tableRowClose;

else

htp.p(\' \*\*\*\*\* \');

htp.br;

end if;

\--

\-- F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

\--

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

end loop;

\--

htp.tableClose;

\--

htp.formOpen(\'webgen0001.query_result_page\');

\--

dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formHidden(\'m_pid\',m_pid);

htp.formHidden(\'i_range_from\',i_range_from);

htp.formHidden(\'i_range_to\',i_range_to);

htp.formHidden(\'i_machine\',i_machine);

htp.formHidden(\'i_components\',i_components);

htp.formHidden(\'i_system\',i_system);

htp.formHidden(\'i_subsystem\',i_subsystem);

htp.formHidden(\'Z_START\', to_char(I_START));\--

htp.formHidden(\'i_operation\',i_operation);\--

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

\--

htp.para;

\--

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

\--

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

\--

\-- For toggle buttons \*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\--

\-- This is where the buttons are built for the application.

\--

if Z_ACTION = NEXT_BUT_CAPTION then

l_hold_page := TO_NUMBER(NVL(Z_PAGE_NO,\'0\')) +1;

elsif Z_ACTION = PREV_BUT_CAPTION then

l_hold_page := TO_NUMBER(Z_PAGE_NO) -1;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -1) /
SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

else

l_hold_page := to_number(nvl(Z_ACTION,\'1\'));

end if;

\--

htp.tableOpen;

\--

I_NEXT_SET_BUT := FALSE;

I_PREV_SET_BUT := FALSE;

I_FIRST_SET_BUT := FALSE;

I_LAST_SET_BUT := FALSE;

\--

if l_hold_page \> SLIDER_WIDTH then

I_PREV_SET_BUT := TRUE;

I_FIRST_SET_BUT := TRUE;

end if;

\--

\-- Displaying the NEXT SET BUTTON

\--

if trunc((nvl(l_hold_page,1) - 1) / SLIDER_WIDTH) \< trunc((Y_TOTAL_ROWS
/ (Z_RECORD_SET_SIZE \* SLIDER_WIDTH)))

then

I_NEXT_SET_BUT := TRUE;

I_LAST_SET_BUT := TRUE;

end if;

\--

\-- ADDING THE PREVIOUS SET BUTTON FUNC.

\--

htp.tableRowOpen;

\--

y_temp := mod(l_hold_page,SLIDER_WIDTH);

\--

if y_temp = 0 then

x_temp := SLIDER_WIDTH;

else

x_temp := y_temp;

end if;

\--

htp.formHidden(\'Z_PAGE_NO\',l_hold_page);

cur_cnt := 1 + (l_hold_page - x_temp);

\--

\-- Creates the numeric toggle buttons on the bottom of the page.

\--

while cur_cnt \<= total_pages loop

if cur_cnt = l_hold_page then

htp.tableData(htf.bold(to_char(l_hold_page)));

else

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(\'
\'\|\|to_char(cur_cnt)\|\|\' \')));

end if;

\--

if mod(cur_cnt,SLIDER_WIDTH) = 0 then

exit;

end if;

cur_cnt := cur_cnt + 1;

end loop;

htp.tableRowClose;

htp.tableClose;

\--

\-- Creates the buttons on the bottom of the page to toggle from one
page, one set, or

\-- last set of buttons.

htp.tableOpen(\'border\');

htp.tableRowOpen;

\-- Creates the !\<\< button. The else condition on all of the following
buttons \"disables\"

\-- the button when the condition cannot be done.

\--

if I_FIRST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(FIRST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(FIRST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \<\< button.

\--

if I_PREV_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_SET_BUT_CAPTION\|\|\'&\'\|\|\'nbsp\'));

end if;

\--

\-- Creates the \< button.

\--

if I_PREV_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \> button.

\--

if I_NEXT_BUT then

htp.tableData(htf.bold(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_BUT_CAPTION))));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\> button.

\--

if I_NEXT_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\>! button.

\--

if I_LAST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(LAST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(LAST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p(MAX_ROWS_MESSAGE);

end if;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

\-- htp.p(\'\[\');

\-- htp.anchor(G_ONLINE_HELP_FILE,G_ONLINE_HELP);

\-- htp.p(\'\|\');

\-- htp.anchor(\'wam0002.rfm_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

\-- htp.p(\'\]\');

\-- lib.epilog;

\-- htp.centerClose;

end if;

exception

when others then

htp.p(\'Error point \' \|\| err_pnt \|\| \' \' \|\| SQLERRM);

htp.nl;

htp.p(i_query);

end;

\--

procedure sign_off_page (i_pid in varchar2,

i_operation in varchar2 default NULL,

i_proc_detail_id in varchar2,

i_machine in varchar2 default NULL,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL) is

begin

declare

cursor c_last_signoff (p_proc_id in varchar2) is

select \*

from rf_sign_off

where rf_proc_detail_id = to_number(p_proc_id)

and sign_off_date = (select max(sign_off_date)

from rf_sign_off

where rf_proc_detail_id = to_number(p_proc_id));

cursor c_signoff_def (p_proc_id in varchar2) is

select \*

from rf_maint_proc_detail

where rf_proc_detail_id = p_proc_id;

r_last_signoff rf_sign_off%ROWTYPE;

r_signoff_detail rf_maint_proc_detail%ROWTYPE;

temp_badge varchar2(10);

begin

if is_valid_pid(i_pid) then

\--check if quick signoff

if i_operation = \'OK\' then

temp_badge := badge_for_this_pid(i_pid);

insert into rf_sign_off

(RF_SIGN_OFF_ID,

RF_PROC_DETAIL_ID,

COMMENTS,

COMPLETED,

BADGE,

SIGN_OFF_DATE)

values

(ets.RF_SIGN_OFF_SEQ.NextVal,

i_proc_detail_id,

NULL,

\'Y\',

temp_badge,

sysdate);

query_result_page (i_pid,

\'Query\',

i_components,

i_subsystem,

i_system,

i_range_from,

i_range_to,

i_machine,

NULL,

NEXT_BUT_CAPTION,

Z_RECORD_SET_SIZE);

else

\--otherwise prompt for all information\...no default

htp.p(\'\<SCRIPT LANGUAGE=Javascript\>\');

htp.p(\'// BOI, followed by one or more digits, followed by EOI.

var reInteger = /\^\\d+\$/;

var reSignedInteger = /\^(+\|-)?\\d+\$/

var daysInMonth = makeArray(12);

daysInMonth\[1\] = 31;

daysInMonth\[2\] = 29; // must programmatically check this

daysInMonth\[3\] = 31;

daysInMonth\[4\] = 30;

daysInMonth\[5\] = 31;

daysInMonth\[6\] = 30;

daysInMonth\[7\] = 31;

daysInMonth\[8\] = 31;

daysInMonth\[9\] = 30;

daysInMonth\[10\] = 31;

daysInMonth\[11\] = 30;

daysInMonth\[12\] = 31;

var monthDelimiter = \"\|\";

var
monthArray=\"JAN\|FEB\|MAR\|APR\|MAY\|JUN\|JUL\|AUG\|SEP\|OCT\|NOV\|DEC\";

\');

htp.p(\' function checkform(form){

if (!isFiveChar(form.i_badge)) {

alert(\"Please enter five digits for badge number\");

return false;}

if (!isNumeric(form.i_badge)){

alert(\"Please enter numbers only for the badge number.\");

return false;}

if (!isOracleDate(form.i_sign_off_date.value)){

alert (\"Not a valid date. Please use format: DD-MON-YYYY\");

return false;}

return true;}

//

function check_badge(form){

continueOK=true;

if (!isFiveChar(form.i_badge)) {

alert(\"Please enter five digits for badge number\");

continueOK=false;}

if (!isNumeric(form.i_badge)){

alert(\"Please enter numbers only for the badge number.\");

continueOK=false}

return continueOK;}

//

function isFiveChar(theField){

inStr = theField.value;

inLen = inStr.length;

if (inLen==5)

return true;

else

return false;}

//

// Date validation code\...adapted from netscape site

//

function isOracleDate(oracle_date) {

day=oracle_date.substring(0,2);

month=oracle_date.substring(3,6);

monthUpper=month.toUpperCase();

monthVal=monthArray.indexOf(monthUpper);

month_number=parseInt(monthVal,10) / 4 + 1;

year=oracle_date.substring(7,11);

dash1=oracle_date.substring(2,3);

dash2=oracle_date.substring(6,7);

//check for dashes

if (dash1!=\"-\") return false;

if (dash2!=\"-\") return false;

if (!isYear(year)){

alert(\"Not a valid year.\");

return false;}

if (!isDay(day)) {

alert(\"Not a valid day\");

return false;}

if (!isMonth(month_number)){

alert(\"Not a valid month\");

return false;}

var intYear = parseInt(year,10);

var intMonth = month_number;

var intDay = parseInt(day,10);

// catch invalid days, except for February

if (intDay \> daysInMonth\[intMonth\]) return false;

if ((intMonth == 2) && (intDay \> daysInFebruary(intYear))) return
false;

return true;

}

//

function daysInFebruary (year)

{// February has 29 days in any year evenly divisible by four,

// EXCEPT for centurial years which are not also divisible by 400.

return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) \|\| (year % 400 ==
0) ) ) ? 29 : 28 );

}

//

function isInteger(s) {

return reSignedInteger.test(s);

};

//

function isIntegerInRange(s,a,b){

var num = parseInt (s,10);

return ((num \>= a) && (num \<= b));}

//

function isYear(year){

if (!isInteger(year)) return false;

return (year.length == 4);}

//

function isMonth(month){

return isIntegerInRange (month, 1, 12);}

//

function isDay(day){

return isIntegerInRange(day,1,31);}

//

function isNumeric(theField){

inStr=theField.value;

inLen=inStr.length;

result=true;

for(var i=0; i\<inLen; i++) {

var ch = inStr.substring(i,i+1)

if (ch \< \"0\" \|\| \"9\" \< ch)

result=false;

}

return result;}

//

function makeArray(n) {

for (var i = 1; i \<= n; i++) {

this\[i\] = 0 }

return this

}

\');

htp.p(\'\</SCRIPT\>\');

\--if is_valid_pid(i_pid) then

lib.prolog(\'RF Maintenance Sign Off\');

\--retrieve signoff definiton

open c_signoff_def(i_proc_detail_id);

fetch c_signoff_def into r_signoff_detail;

if not c_signoff_def%NOTFOUND then

\--display defintion

htp.tableOpen(\'Border\');

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Step:\'),\'Right\');

htp.tableData(to_char(r_signoff_detail.step_number));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Description:\'),\'Right\');

htp.tableData(r_signoff_detail.description);

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Last Sign Off:\'),\'Right\');

\--retrieve last signoff date

open c_last_signoff(i_proc_detail_id);

fetch c_last_signoff into r_last_signoff;

if not c_last_signoff%NOTFOUND then

htp.tableData(to_char(r_last_signoff.sign_off_date,\'DD-MON-YYYY\'));

else

htp.tableData(\'No sign off records yet in database\');

end if;

htp.tableRowClose;

close c_last_signoff;

\--

htp.tableClose;

else

htp.p(\'\<font face=arial size=4 color=#FF0000\>No procedure
found\</font\>\');

end if;

close c_signoff_def;

\--

\--htp.formOpen(\'webgen0001.process_sign_off\');

htp.p(\'\<FORM ACTION=\"webgen0001.process_sign_off\" METHOD=\"POST\"
onSubmit=\"return checkform(this)\"\>\');

\--get data entry values

htp.tableOpen(\'BORDER\');

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Badge:\'),\'Right\');

htp.tableData(htf.formText(\'i_badge\',\'5\',\'5\',null,\'onBlur=\"check_badge(this.form)\"\'));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Sign Off Date (DD-MON-YYYY):\'),\'Right\');

htp.tableData(htf.formText(\'i_sign_off_date\',11,11));

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Comments:\'),\'Right\',cattributes=\>\'valign=\"Top\"\');

htp.print(\'\<TD\>\');

htp.formTextAreaOpen(\'i_comments\',\'5\',\'50\',\'LEFT\',\'WRAP\');

htp.formTextAreaClose;

htp.print(\'\</TD\>\');

htp.tablerowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Subsystem Ready:\'),\'Right\');

htp.tableData(htf.formCheckBox(\'i_sub_sys_ready\',\'Y\'));

htp.tableRowClose;

\--

htp.tableClose;

\--buttons

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\',\'Save\'));

\--htp.tableData(\'\<INPUT TYPE=\"button\" Name=\"i_operation\"
VALUE=\"Save\" onClick=\"submit_signoff_page(this.form)\"\>\');

\--send query parameters

htp.formHidden(\'i_machine\',i_machine);

htp.formHidden(\'i_components\',i_components);

htp.formHidden(\'i_system\',i_system);

htp.formHidden(\'i_subsystem\',i_subsystem);

htp.formHidden(\'i_range_from\',i_range_from);

htp.formHidden(\'i_range_to\',i_range_to);

htp.formHidden(\'i_proc_detail_id\',i_proc_detail_id);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formHidden(\'Z_TOTAL_ROWS\',Z_TOTAL_ROWS);

htp.formHidden(\'Z_PAGE_NO\',Z_PAGE_NO);

htp.formHidden(\'i_pid\',i_pid);

\--

htp.formClose;

\--open a new form - that doesn\'t require javascript validation for
cancel

\--otherwise one form open would suffice

htp.p(\'\<FORM ACTION=\"webgen0001.process_sign_off\"
METHOD=\"POST\"\');

htp.formHidden(\'i_machine\' ,i_machine);

htp.formHidden(\'i_components\',i_components);

htp.formHidden(\'i_system\',i_system);

htp.formHidden(\'i_subsystem\',i_subsystem);

htp.formHidden(\'i_range_from\',i_range_from);

htp.formHidden(\'i_range_to\',i_range_to);

htp.formHidden(\'i_proc_detail_id\',i_proc_detail_id);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formHidden(\'Z_TOTAL_ROWS\',Z_TOTAL_ROWS);

htp.formHidden(\'Z_PAGE_NO\',Z_PAGE_NO);

htp.formHidden(\'i_pid\',i_pid);

htp.tableData(htf.formSubmit(\'i_operation\',\'Cancel\'));

htp.tableRowClose;

htp.tableClose;

\--

\--send query parameters

htp.formHidden(\'i_machine\' ,i_machine);

htp.formHidden(\'i_components\',i_components);

htp.formHidden(\'i_system\',i_system);

htp.formHidden(\'i_subsystem\',i_subsystem);

htp.formHidden(\'i_range_from\',i_range_from);

htp.formHidden(\'i_range_to\',i_range_to);

htp.formHidden(\'i_proc_detail_id\',i_proc_detail_id);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formHidden(\'Z_TOTAL_ROWS\',Z_TOTAL_ROWS);

htp.formHidden(\'Z_PAGE_NO\',Z_PAGE_NO);

htp.formHidden(\'i_pid\',i_pid);

\--

htp.formClose;

lib.epilog;

end if;

end if;

exception

when others then

htp.p(\'There is a problem. Please report it to mis_mgrs. \' \|\|
SQLERRM);

end;

end;

\--

procedure shop_list_page(i_pid in varchar2 default NULL,

i_proc_detail_id in varchar2 default NULL) is

cursor cur_shopping_list(p_proc_detail_id in varchar2) is

select \*

from shopping_list

where rf_proc_detail_id = to_number(p_proc_detail_id);

Begin

lib.prolog(\'Shopping List\');

htp.tableOpen(\'Border\');

htp.tableRowOpen;

htp.tableHeader(\'Quantity\',\'Center\');

htp.tableHeader(\'Description\',\'Left\');

htp.tableRowClose;

for rec_shopping_list in cur_shopping_list(i_proc_detail_id) loop

htp.tableRowOpen;

htp.tableData(to_char(rec_shopping_list.quantity)\|\|\';\'\|\|rec_shopping_list.uom,\'Center\');

htp.tableData(rec_shopping_list.description,\'Left\');

htp.tableRowClose;

end loop;

htp.tableClose;

htp.nl;

lib.epilog;

End;

\-- NEEDS ALOT OF ERROR CHECKING ETC !! 2/6/98 km.

procedure process_sign_off (i_pid in varchar2,

i_operation in varchar2 default \'Cancel\',

i_badge in varchar2 default null,

i_sign_off_date in varchar2 default null,

i_comments in varchar2 default null,

i_sub_sys_ready in varchar2 default null,

i_machine in varchar2 default NULL,

i_components in varchar2 default NULL,

i_subsystem in varchar2 default NULL,

i_system in varchar2 default NULL,

i_range_from in varchar2 default NULL,

i_range_to in varchar2 default NULL,

i_proc_detail_id in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL)

is

begin

if is_valid_pid(i_pid) then

if i_operation=\'Save\' then

insert into rf_sign_off

(RF_SIGN_OFF_ID,

RF_PROC_DETAIL_ID,

COMMENTS,

COMPLETED,

BADGE,

SIGN_OFF_DATE)

values

(ets.RF_SIGN_OFF_SEQ.NextVal,

i_proc_detail_id,

i_comments,

i_sub_sys_ready,

i_badge,

to_date(i_sign_off_date,\'DD-MON-YYYY\'));

end if;

query_result_page (i_pid,

\'Query\',

i_components,

i_subsystem,

i_system,

i_range_from,

i_range_to,

i_machine,

NULL,

NEXT_BUT_CAPTION,

Z_RECORD_SET_SIZE);

end if;

exception

when value_error then

htp.p(\'Please check for a valid date.\');

when others then

htp.p(\'Unable to store data. Please report problem to mis_mgrs:\');

htp.nl;

htp.p(sqlerrm);

end;

\--

END webgen0001;

/

CREATE OR REPLACE PACKAGE wbt0001

IS

procedure startPage (i_pid in varchar2 default \'NEW\',

i_attrib in varchar2 default NULL) ;

procedure startPageANL (i_pid in varchar2 default \'NEW\',

i_attrib in varchar2 default NULL) ;

procedure testPage (i_pid in varchar2 default \'NEW\',

i_attrib in varchar2 default NULL) ;

procedure updateWhichClass (i_pid in varchar2,i_attrib in varchar2);

procedure processTest(i_pid in varchar2,i_class_id in varchar2,

q1 in varchar2 default NULL,

q2 in varchar2 default NULL,

q3 in varchar2 default NULL,

q4 in varchar2 default NULL,

q5 in varchar2 default NULL,

q6 in varchar2 default NULL,

q7 in varchar2 default NULL,

q8 in varchar2 default NULL,

q9 in varchar2 default NULL,

q10 in varchar2 default NULL,

q11 in varchar2 default NULL,

q12 in varchar2 default NULL,

q13 in varchar2 default NULL,

q14 in varchar2 default NULL,

q15 in varchar2 default NULL,

q16 in varchar2 default NULL,

q17 in varchar2 default NULL,

q18 in varchar2 default NULL,

q19 in varchar2 default NULL,

q20 in varchar2 default NULL,

q21 in varchar2 default NULL,

q22 in varchar2 default NULL,

q23 in varchar2 default NULL,

q24 in varchar2 default NULL,

q25 in varchar2 default NULL,

q26 in varchar2 default NULL,

q27 in varchar2 default NULL,

q28 in varchar2 default NULL,

q29 in varchar2 default NULL,

q30 in varchar2 default NULL,

q31 in varchar2 default NULL,

q32 in varchar2 default NULL);

procedure processRetryTest(i_pid in varchar2,i_class_id in varchar2,

q1 in varchar2 default NULL,

q2 in varchar2 default NULL,

q3 in varchar2 default NULL,

q4 in varchar2 default NULL,

q5 in varchar2 default NULL,

q6 in varchar2 default NULL,

q7 in varchar2 default NULL,

q8 in varchar2 default NULL,

q9 in varchar2 default NULL,

q10 in varchar2 default NULL,

q11 in varchar2 default NULL,

q12 in varchar2 default NULL,

q13 in varchar2 default NULL,

q14 in varchar2 default NULL,

q15 in varchar2 default NULL,

q16 in varchar2 default NULL,

q17 in varchar2 default NULL,

q18 in varchar2 default NULL,

q19 in varchar2 default NULL,

q20 in varchar2 default NULL,

q21 in varchar2 default NULL,

q22 in varchar2 default NULL,

q23 in varchar2 default NULL,

q24 in varchar2 default NULL,

q25 in varchar2 default NULL,

q26 in varchar2 default NULL,

q27 in varchar2 default NULL,

q28 in varchar2 default NULL,

q29 in varchar2 default NULL,

q30 in varchar2 default NULL,

q31 in varchar2 default NULL,

q32 in varchar2 default NULL);

END wbt0001;

/

CREATE OR REPLACE PACKAGE BODY WBT0001

IS

\--

G_QUERY_START_PAGE_APP varchar2(10) := \'WBT0001\';

MASK constant varchar2(25) := \'14MONKey7Snif29b3q\';

NO_TEST_SPECIFIED exception;

\--

function get_badge_no (i_pid in varchar2) return varchar2 is

begin

declare

cursor c_badge(p_pid in varchar2) is

select badge_no

from OWS_APP_LOGIN

where pid=p_pid;

result varchar2(10);

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'NONE\';

end if;

close c_badge;

return(result);

end;

end;

\--

function get_correct_answer(i_class_id in number,i_question_id in
number) return varchar2 is

begin

declare

cursor c_correct_answer(p_class_id in number,p_question_id in number) is

select CORRECT_ANSWER

from WBT_QUESTIONS

where class_id=p_class_id

and question_id=p_question_id;

result varchar2(5);

begin

open c_correct_answer(i_class_id,i_question_id);

fetch c_correct_answer into result;

close c_correct_answer;

return(result);

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

begin

\--HTP.p(\'WBT IS VALID PID\');

result := log0002.is_valid_pid(i_pid,\'WBT0001\') or

log0002.is_valid_pid(i_pid,\'WBT0001_ANL\') or

log0002.is_valid_pid(i_pid,\'WBT0001_PUB\');

\--htp.p(\'WBT IS VALID PID DONE\');

return result;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure retryQuestionsPage(i_pid in varchar2,i_class_id in varchar2)
is

begin

declare

cursor c_student_answers(p_class_id in number,p_pid in varchar2) is

select \*

from WBT_STUDENT_ANSWERS

where class_id = p_class_id

and pid = p_pid

order by question_id;

cursor c_wbt_questions (p_class_id in number) is

select \*

from WBT_QUESTIONS

where class_id=p_class_id;

cursor c_question (p_class_id in number,p_question_id in number) is

select \*

from wbt_questions

where class_id=p_class_id

and question_id=p_question_id

order by question_id;

cursor c_question_choices (p_question_id in number,p_class_id in number)
is

select \*

from wbt_question_choices

where question_id=p_question_id

and class_id=p_class_id;

cursor c_class_header(p_class_id in number) is

select title

from wbt_class_header

where class_id = p_class_id;

l_correct_answer WBT_QUESTIONS.CORRECT_ANSWER%TYPE;

r_question WBT_QUESTIONS%ROWTYPE;

l_title varchar2(255);

temp varchar2(512);

l_pid varchar2(255);

l_question_hint_text varchar2(2000);

begin

if is_valid_pid(i_pid) then

\--dynamic javascript section

htp.p(\'\<script language=\"JavaScript\"\>

helpArray=new Array;

\');

\--build javascript material array

for r_wbt_questions in c_wbt_questions (i_class_id) loop

\--if r_wbt_questions.question_id \< 4 then FOR DEBUGGIN ARRAY PROBLEMS
BASED ON RECORD CONTENT

l_question_hint_text :=
REPLACE(r_wbt_questions.hint_text,\'\"\',\'\\\"\');

\--l_question_hint_text :=
REPLACE(r_wbt_questions.hint_text,\'\'\'\',\'\'\'\'\'\');

\--l_question_hint_text := r_wbt_questions.hint_text;

htp.p(\'helpArray\[\' \|\| to_char(r_wbt_questions.question_id) \|\|
\'\]=\"\' \|\| l_question_hint_text \|\| \'\";\');

\--htp.p(\'helpArray\[\' \|\| to_char(r_wbt_questions.question_id) \|\|
\'\]=\"\' \|\| r_wbt_questions.hint_text \|\| \'\";\');

\--htp.p(\'var testString=\"\' \|\| r_wbt_questions.hint_text \|\|
\'\";\');

\--htp.p(\'helpArray\[\' \|\| to_char(r_wbt_questions.question_id) \|\|
\'\]=\"\' \|\| r_wbt_questions.hint_text \|\| \'\";\');

\--htp.p(\'helpArray\[\' \|\| to_char(r_wbt_questions.question_id) \|\|
\'\]=testString;\');

\--end if;

end loop;

htp.p(\'

//helpArray\[1\]=\'\'\' \|\| \'\<HTML\>\<B\>Item 1\</B\>\</HTML\>\'\';\'
\|\|\'

function helpq(q){

helpWindow=window.open(\"\",\"displayWindow\",\"width=500,height=150\");

helpWindow.close();

helpWindow=window.open(\"\",\"displayWindow\",\"menubar=yes,scrollbars=yes,width=500,height=150\")

helpWindow.document.write(\"\<html\>\<head\>\<title\>Help
Window\</title\>\</head\>\<body bgcolor=\\\"#FFFFFF\\\"
onBlur=\\\"self.focus()\\\"\>\");

//helpWindow.document.write(helpArray\[q\]);

helpWindow.document.write(helpArray\[q\]);

helpWindow.document.write(\"\</body\>\</html\>\");

return false;

}

\</script\>\');

\--end javascript section

\--l_pid := deConvertPID(i_pid);

l_pid := i_pid;

open c_class_header(i_class_id);

fetch c_class_header into l_title;

close c_class_header;

lib.prolog(l_title \|\| \' Test\');

htp.nl;

htp.p(\'\<h3\>The following questions have not yet been answered
correctly.\</h3\>\');

htp.formOpen(\'wbt0001.processRetryTest\');

\--grade test

htp.tableOpen;

for r_student_answers in c_student_answers(i_class_id,l_pid) loop

\-- get correct answer

l_correct_answer :=
get_correct_answer(i_class_id,r_student_answers.question_id);

if l_correct_answer != r_student_answers.CHOSEN_ANSWER then

\--display question w/ help button

htp.tableRowOpen;

htp.p(\'\<TD\>\');

\--get question text

open c_question(i_class_id,r_student_answers.question_id);

fetch c_question into r_question;

close c_question;

\--display question

if r_question.HINT_TEXT is not null then

htp.p(to_char(r_student_answers.question_id) \|\| \'.) \' \|\|
r_question.text \|\| \'&nbsp&nbsp&nbsp\<INPUT TYPE=\"submit\"
value=\"Hint\" onClick=\"return helpq(\' \|\|
to_char(r_student_answers.question_id) \|\| \')\"\>\');

else

htp.p(to_char(r_student_answers.question_id) \|\| \'.) \' \|\|
r_question.text);

end if;

htp.p(\'\<TR\>\<TD\>\');

htp.tableOpen;

for r_choices in
c_question_choices(r_student_answers.question_id,i_class_id) loop

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'q\' \|\|
r_student_answers.question_id,r_choices.RESULT_VALUE ) \|\|
r_choices.RESULT_VALUE \|\| \' ). \' \|\| r_choices.text);

htp.tableRowClose;

end loop;

htp.tableClose;

htp.p(\'\</TD\>\');

htp.p(\'\</TD\>\</TR\>\');

htp.tableRowClose;

end if;

end loop;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_class_id\',i_class_id);

htp.formSubmit;

htp.formClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure successPage(i_pid in varchar2,i_class_id in varchar2) is

cursor c_title(i_class_id in number) is

select TITLE

from WBT_CLASS_HEADER

where class_id=i_class_id;

l_title WBT_CLASS_HEADER.TITLE%TYPE;

l_pid varchar2(255);

return_status varchar2(255);

begin

\--l_pid := deConvertPID(i_pid);

l_pid := i_pid;

if is_valid_pid(i_pid) then

\--update log \... END_DATE

update WBT_STUDENT_LOG

set END_TIME=sysdate

where pid=l_pid;

lib.prolog(\'Congratulations!\');

open c_title(i_class_id);

fetch c_title into l_title;

close c_title;

htp.p(\'\<FONT SIZE=5 COLOR=#006010\>You have successfully completed \'
\|\| l_title \|\| \'.\</FONT\>\');

lib.epilog;

\--send email acknowledgement

mis_util.utl_print_it(\'\$mis_reports/\',\'wbt_test_passed\',\'B\',\'mis3\',\'P\',\'SQR\',\'ESH/ESH\',\'NONE\',i_pid,

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

\'NONE\',

return_status);

\--force logout of this pid to prevent industrious users from useing the
cache and changing the names under the same

\--pid

UPDATE OWS_APP_LOGIN set LOG_OUT_DATE=SYSDATE where PID=l_pid;

end if;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure processTest(i_pid in varchar2,i_class_id in varchar2,

q1 in varchar2 default NULL,

q2 in varchar2 default NULL,

q3 in varchar2 default NULL,

q4 in varchar2 default NULL,

q5 in varchar2 default NULL,

q6 in varchar2 default NULL,

q7 in varchar2 default NULL,

q8 in varchar2 default NULL,

q9 in varchar2 default NULL,

q10 in varchar2 default NULL,

q11 in varchar2 default NULL,

q12 in varchar2 default NULL,

q13 in varchar2 default NULL,

q14 in varchar2 default NULL,

q15 in varchar2 default NULL,

q16 in varchar2 default NULL,

q17 in varchar2 default NULL,

q18 in varchar2 default NULL,

q19 in varchar2 default NULL,

q20 in varchar2 default NULL,

q21 in varchar2 default NULL,

q22 in varchar2 default NULL,

q23 in varchar2 default NULL,

q24 in varchar2 default NULL,

q25 in varchar2 default NULL,

q26 in varchar2 default NULL,

q27 in varchar2 default NULL,

q28 in varchar2 default NULL,

q29 in varchar2 default NULL,

q30 in varchar2 default NULL,

q31 in varchar2 default NULL,

q32 in varchar2 default NULL) is

begin

declare

l_correct_answer varchar2(5);

l_expected_count number;

l_current_count number;

i_ans_arr lib.val_arr;

l_pid varchar2(255);

cursor c_q_count(p_class_id in varchar2) is

select count(\*)

from wbt_questions

where class_id=p_class_id;

cursor c_student_answers(p_class_id in number,p_pid in varchar2) is

select \*

from WBT_STUDENT_ANSWERS

where class_id = p_class_id

and pid = p_pid;

ctr integer;

NOT_ENOUGH_ANSWERS exception;

WRONG_ANSWERS exception;

begin

\--build an array from the answers

i_ans_arr(0) := \'NONE\';

i_ans_arr(1) := nvl(q1,\'NA\');

i_ans_arr(2) := nvl(q2,\'NA\');

i_ans_arr(3) := nvl(q3,\'NA\');

i_ans_arr(4) := nvl(q4,\'NA\');

i_ans_arr(5) := nvl(q5,\'NA\');

i_ans_arr(6) := nvl(q6,\'NA\');

i_ans_arr(7) := nvl(q7,\'NA\');

i_ans_arr(8) := nvl(q8,\'NA\');

i_ans_arr(9) := nvl(q9,\'NA\');

i_ans_arr(10) := nvl(q10,\'NA\');

i_ans_arr(11) := nvl(q11,\'NA\');

i_ans_arr(12) := nvl(q12,\'NA\');

i_ans_arr(13) := nvl(q13,\'NA\');

i_ans_arr(14) := nvl(q14,\'NA\');

i_ans_arr(15) := nvl(q15,\'NA\');

i_ans_arr(16) := nvl(q16,\'NA\');

i_ans_arr(17) := nvl(q17,\'NA\');

i_ans_arr(18) := nvl(q18,\'NA\');

i_ans_arr(19) := nvl(q19,\'NA\');

i_ans_arr(20) := nvl(q20,\'NA\');

i_ans_arr(21) := nvl(q21,\'NA\');

i_ans_arr(22) := nvl(q22,\'NA\');

i_ans_arr(23) := nvl(q23,\'NA\');

i_ans_arr(24) := nvl(q24,\'NA\');

i_ans_arr(25) := nvl(q25,\'NA\');

i_ans_arr(26) := nvl(q26,\'NA\');

i_ans_arr(27) := nvl(q27,\'NA\');

i_ans_arr(28) := nvl(q28,\'NA\');

i_ans_arr(29) := nvl(q29,\'NA\');

i_ans_arr(30) := nvl(q30,\'NA\');

i_ans_arr(31) := nvl(q31,\'NA\');

i_ans_arr(32) := nvl(q32,\'NA\');

\--

\--l_pid := deConvertPID(i_pid);

l_pid := i_pid;

\--get expected count

\--count answers sent, ensure all questions attempted

open c_q_count(i_class_id);

fetch c_q_count into l_expected_count;

close c_q_count;

for cnt in 0..l_expected_count loop

if i_ans_arr(cnt) = \'NA\' then

raise NOT_ENOUGH_ANSWERS;

end if;

end loop;

\--clear previous attempts

delete from WBT_STUDENT_ANSWERS

where pid=l_pid

and class_id=i_class_id;

\-- if all questions attempted, store answers in database

for cnt in 0..l_expected_count loop

if cnt \> 0 then

insert into WBT_STUDENT_ANSWERS

(PID,QUESTION_ID,ANSWER_ID,CHOSEN_ANSWER,CLASS_ID)

values

(l_pid,cnt,wbt_ans_seq.nextval,i_ans_arr(cnt),i_class_id);

end if;

end loop;

\--grade test

for r_student_answers in c_student_answers(i_class_id,l_pid) loop

\-- get correct answer

l_correct_answer :=
get_correct_answer(i_class_id,r_student_answers.question_id);

if l_correct_answer != r_student_answers.CHOSEN_ANSWER then

raise WRONG_ANSWERS;

end if;

\--htp.nl;

\--htp.p(\'Correct, Current = \' \|\| l_correct_answer \|\| \', \' \|\|
r_student_answers.CHOSEN_ANSWER);

\--htp.nl;

end loop;

\--success if no wrong answers

successPage(i_pid,i_class_id);

EXCEPTION

when NOT_ENOUGH_ANSWERS then

lib.prolog(\'Incomplete Test\');

htp.p(\'Please attempt to answer all questions \');

htp.NL;

htp.p(\'Click \[BACK\] to return to questions\');

htp.NL;

lib.epilog;

when WRONG_ANSWERS then

retryQuestionsPage(i_pid,i_class_id);

when others then

htp.p(sqlerrm);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure processRetryTest(i_pid in varchar2,i_class_id in varchar2,

q1 in varchar2 default NULL,

q2 in varchar2 default NULL,

q3 in varchar2 default NULL,

q4 in varchar2 default NULL,

q5 in varchar2 default NULL,

q6 in varchar2 default NULL,

q7 in varchar2 default NULL,

q8 in varchar2 default NULL,

q9 in varchar2 default NULL,

q10 in varchar2 default NULL,

q11 in varchar2 default NULL,

q12 in varchar2 default NULL,

q13 in varchar2 default NULL,

q14 in varchar2 default NULL,

q15 in varchar2 default NULL,

q16 in varchar2 default NULL,

q17 in varchar2 default NULL,

q18 in varchar2 default NULL,

q19 in varchar2 default NULL,

q20 in varchar2 default NULL,

q21 in varchar2 default NULL,

q22 in varchar2 default NULL,

q23 in varchar2 default NULL,

q24 in varchar2 default NULL,

q25 in varchar2 default NULL,

q26 in varchar2 default NULL,

q27 in varchar2 default NULL,

q28 in varchar2 default NULL,

q29 in varchar2 default NULL,

q30 in varchar2 default NULL,

q31 in varchar2 default NULL,

q32 in varchar2 default NULL) is

begin

declare

l_correct_answer varchar2(5);

l_expected_count number;

l_current_count number;

i_ans_arr lib.val_arr;

l_pid varchar2(255);

cursor c_q_count(p_class_id in varchar2) is

select count(\*)

from wbt_questions

where class_id=p_class_id;

cursor c_student_answers(p_class_id in number,p_pid in varchar2) is

select \*

from WBT_STUDENT_ANSWERS

where class_id = p_class_id

and pid = p_pid;

ctr integer;

err_pnt varchar2(10);

WRONG_ANSWERS exception;

begin

\--build an array from the answers

i_ans_arr(0) := \'NONE\';

i_ans_arr(1) := nvl(q1,\'NA\');

i_ans_arr(2) := nvl(q2,\'NA\');

i_ans_arr(3) := nvl(q3,\'NA\');

i_ans_arr(4) := nvl(q4,\'NA\');

i_ans_arr(5) := nvl(q5,\'NA\');

i_ans_arr(6) := nvl(q6,\'NA\');

i_ans_arr(7) := nvl(q7,\'NA\');

i_ans_arr(8) := nvl(q8,\'NA\');

i_ans_arr(9) := nvl(q9,\'NA\');

i_ans_arr(10) := nvl(q10,\'NA\');

i_ans_arr(11) := nvl(q11,\'NA\');

i_ans_arr(12) := nvl(q12,\'NA\');

i_ans_arr(13) := nvl(q13,\'NA\');

i_ans_arr(14) := nvl(q14,\'NA\');

i_ans_arr(15) := nvl(q15,\'NA\');

i_ans_arr(16) := nvl(q16,\'NA\');

i_ans_arr(17) := nvl(q17,\'NA\');

i_ans_arr(18) := nvl(q18,\'NA\');

i_ans_arr(19) := nvl(q19,\'NA\');

i_ans_arr(20) := nvl(q20,\'NA\');

i_ans_arr(21) := nvl(q21,\'NA\');

i_ans_arr(22) := nvl(q22,\'NA\');

i_ans_arr(23) := nvl(q23,\'NA\');

i_ans_arr(24) := nvl(q24,\'NA\');

i_ans_arr(25) := nvl(q25,\'NA\');

i_ans_arr(26) := nvl(q26,\'NA\');

i_ans_arr(27) := nvl(q27,\'NA\');

i_ans_arr(28) := nvl(q28,\'NA\');

i_ans_arr(29) := nvl(q29,\'NA\');

i_ans_arr(30) := nvl(q30,\'NA\');

i_ans_arr(31) := nvl(q31,\'NA\');

i_ans_arr(32) := nvl(q32,\'NA\');

\--

\--l_pid := deConvertPID(i_pid);

l_pid := i_pid;

\-- update changed answers

for cnt in 0..32 loop

if cnt \> 0 and i_ans_arr(cnt) != \'NA\' then

update WBT_STUDENT_ANSWERS

set CHOSEN_ANSWER=i_ans_arr(cnt)

where pid=l_pid

and class_id=i_class_id

and question_id=cnt;

end if;

end loop;

\--grade test

for r_student_answers in c_student_answers(i_class_id,l_pid) loop

\-- get correct answer

l_correct_answer :=
get_correct_answer(i_class_id,r_student_answers.question_id);

if l_correct_answer != r_student_answers.CHOSEN_ANSWER then

raise WRONG_ANSWERS;

end if;

end loop;

\--success if no wrong answers

successPage(i_pid,i_class_id);

EXCEPTION

when WRONG_ANSWERS then

retryQuestionsPage(i_pid,i_class_id);

when others then

htp.p(sqlerrm);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure questionPage(i_pid in varchar2,i_class_id in varchar2) is

begin

declare

cursor c_class_header(p_class_id in number) is

select title

from wbt_class_header

where class_id = p_class_id;

cursor c_questions (p_class_id in number) is

select \*

from wbt_questions

where class_id=p_class_id

order by question_id;

cursor c_question_choices (p_question_id in number,p_class_id in number)
is

select \*

from wbt_question_choices

where question_id=p_question_id

and class_id=p_class_id;

l_title varchar2(255);

begin

if is_valid_pid(i_pid) then

open c_class_header(i_class_id);

fetch c_class_header into l_title;

close c_class_header;

lib.prolog(l_title \|\| \' Test\');

htp.formOpen(\'wbt0001.processTest\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_class_id\',i_class_id);

htp.tableOpen;

\--display questions for test specified by class id

for r_question in c_questions(i_class_id) loop

htp.tableRowOpen;

htp.p(\'\<TD\>\');

htp.p(to_char(r_question.question_id) \|\| \'.) \' \|\| r_question.text
);

htp.p(\'\<TR\>\<TD\>\');

htp.tableOpen;

for r_choices in c_question_choices(r_question.question_id,i_class_id)
loop

htp.tableRowOpen;

htp.tableData(htf.formRadio(\'q\' \|\|
r_question.question_id,r_choices.RESULT_VALUE ) \|\|
r_choices.RESULT_VALUE \|\| \' ). \' \|\| r_choices.text);

htp.tableRowClose;

end loop;

htp.tableClose;

htp.p(\'\</TD\>\');

htp.p(\'\</TD\>\</TR\>\');

htp.tableRowClose;

end loop;

htp.tableClose;

end if;

htp.formSubmit;

htp.formClose;

lib.epilog;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure updateWhichClass (i_pid in varchar2,i_attrib in varchar2) is

begin

if is_valid_pid(i_pid) then

UPDATE WBT_STUDENT_LOG

SET CLASS_ID=i_attrib,

START_TIME=sysdate,

END_TIME=Null

WHERE PID=i_pid;

questionPage (i_pid,i_attrib);

end if;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure selectTest (i_pid in varchar2) is

cursor c_test is

select \* from wbt_class_header

order by title;

begin

lib.prolog(\'Test Selection\');

htp.centerOpen;

htp.p(\'\<FONT SIZE=5 COLOR=\"#FF0000\"\>\');

htp.p(\'No class for which to administer this test was indicated.\');

htp.p(\'\</FONT\>\<BR\>\<BR\>\<FONT SIZE=5 COLOR=\"#000000\"\>\');

htp.p(\'Please select a class:\');

htp.formOpen(\'wbt0001.updateWhichClass\');

htp.formSelectOpen(\'i_attrib\');

for r_test in c_test loop

htp.formSelectOption(r_test.title,null,\'VALUE=\'\'\' \|\|
to_char(r_test.class_id) \|\| \'\'\'\');

end loop;

htp.formSelectClose;

htp.formSubmit(\'\',\'Take Test\');

htp.p(\'\</FONT\>\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.centerClose;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure startPage (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(512);

l_badge varchar2(10);

err_pnt varchar2(5);

\--

begin

err_pnt := \'W0\';

if i_pid is NULL or

i_pid = \'NEW\' or

\-- NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

NOT is_valid_pid(i_pid) then

err_pnt := \'W000\';

\--add msg to eplain to save email

htp.htmlOpen;

htp.centerOpen;

htp.p(\'\<FONT COLOR=\"FF0000\" SIZE=+2\>\*\*\*\*\*\*\*\*\* IMPORTANT
\*\*\*\*\*\*\*\*\*\</FONT\>\');

htp.NL;

htp.p(\'You should receive a confirmation email upon successful
completion of this course.\');

htp.NL;

htp.p(\'Please save this email for your records, to ensure you receive
proper credit.\');

htp.NL;

htp.p(\'If you do not receive an email message after completing this
test (or need any other assistance i.e. password help),\');

htp.p(\'please contact \<A
HREF=\"mailto:mis_mgrs@aps.anl.gov\"\>mis_mgrs\</A\>.\');

htp.NL;

htp.NL;

htp.p(\'\</FONT\>\');

htp.centerClose;

log0002.login(\'WBT0001\',\'NEW\',null,i_attrib,\'N\');

err_pnt := \'W0001\';

return;

null;

end if;

err_pnt := \'W00\';

\-- initialize test taking information

\--

err_pnt := \'W1\';

\--m_pid := deConvertPID(i_pid);

m_pid := i_pid;

l_badge := get_badge_no(i_pid);

INSERT INTO WBT_STUDENT_LOG

(PID,BADGE_NO,CLASS_ID,START_TIME)

values (i_pid,l_badge,i_attrib,sysdate);

err_pnt :=\'W2\';

if i_attrib is null then

raise NO_TEST_SPECIFIED;

end if;

\-- Go to the test specified by i_attrib, default to 1

questionPage(i_pid,i_attrib);

\--

EXCEPTION

when NO_TEST_SPECIFIED then

\--htp.p(\'No test was specified.\');

selectTest (i_pid);

when DUP_VAL_ON_INDEX then

startPage(\'NEW\',i_attrib);

when others then

htp.p(\'WBT startPage at \' \|\| err_pnt);

htp.p(sqlerrm);

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure startPageANL (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(512);

l_badge varchar2(10);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT is_valid_pid (m_pid) then

\--add msg to eplain to save email

htp.htmlOpen;

htp.centerOpen;

htp.p(\'\<FONT COLOR=\"FF0000\" SIZE=+2\>\*\*\*\*\*\*\*\*\* IMPORTANT
\*\*\*\*\*\*\*\*\*\</FONT\>\');

htp.NL;

htp.p(\'You should receive a confirmation email upon successful
completion of this course.\');

htp.NL;

htp.p(\'Please save this email for your records, to ensure you receive
proper credit.\');

htp.NL;

htp.p(\'If you do not receive an email message after completing this
test (or need any other assistance),\');

htp.p(\'please contact \<A
HREF=\"mailto:mis_mgrs@aps.anl.gov\"\>mis_mgrs\</A\>.\');

htp.NL;

htp.NL;

htp.p(\'\</FONT\>\');

htp.centerClose;

log0002.login(\'WBT0001_ANL\',\'\',m_pid,i_attrib,\'N\');

return;

end if;

\-- initialize test taking information

\--m_pid := deConvertPID(i_pid);

m_pid:=i_pid;

l_badge := get_badge_no(m_pid);

INSERT INTO WBT_STUDENT_LOG

(PID,BADGE_NO,CLASS_ID,START_TIME)

values (m_pid,l_badge,i_attrib,sysdate);

if i_attrib is null then

raise NO_TEST_SPECIFIED;

end if;

\-- Go to the test specified by i_attrib, default to 1

questionPage(i_pid,i_attrib);

\--

EXCEPTION

when NO_TEST_SPECIFIED then

\--htp.p(\'No test was specified.\');

selectTest(i_pid);

when DUP_VAL_ON_INDEX then

startPageANL(\'NEW\',i_attrib);

when others then

htp.p(sqlerrm);

end;\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure testPage (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(512);

r_LOGIN OWS_APP_LOGIN%ROWTYPE;

cursor c_OWS_APP_LOGIN(i_pid in varchar2) is

select \*

from OWS_APP_LOGIN

where pid=i_pid;

\--

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT is_valid_pid (i_pid) then

log0002.login(\'WBT0001_PUB\',\'\',i_pid,i_attrib,\'N\');

return;

end if;

\-- initialize test taking information

\--m_pid := deConvertPID(i_pid);

m_pid := i_pid;

\--

open c_OWS_APP_LOGIN(i_pid);

fetch c_OWS_APP_LOGIN into r_LOGIN;

close c_OWS_APP_LOGIN;

INSERT INTO WBT_STUDENT_LOG

(PID,BADGE_NO,CLASS_ID,START_TIME,FIRST_NAME,LAST_NAME,SS_NO,COMPANY,PHONE)

values
(m_pid,\'PUBLIC\',i_attrib,sysdate,r_LOGIN.FIRST_NAME,r_login.LAST_NAME,r_login.SS_NO,r_login.COMPANY,r_login.PHONE);

if i_attrib is null then

raise NO_TEST_SPECIFIED;

end if;

\-- Go to the test specified by i_attrib, default to 1

questionPage(i_pid,i_attrib);

\--

EXCEPTION

when NO_TEST_SPECIFIED then

\-- htp.p(\'No test was specified.\');

selectTest(i_pid);

when DUP_VAL_ON_INDEX then

testPage(\'NEW\',i_attrib);

when others then

htp.p(sqlerrm);

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

END wbt0001;

/

CREATE OR REPLACE PACKAGE webtms2000 IS

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Project: WEB TMS

What: TMS Profile Management

Revised By: Matt Malcheski-TUSC

Revised Date: 082499

\-\-\-\-\-\-\-\-\-\-\-\-\-\--

Revisions

\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\-- mtm082499 added search criteria in javascript to go right to the
name that you wanted

\-- the formatting of the plsql code was already here

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|\'webtms0098\'\|\|\'/owa/\';

dev_service varchar2(255) := \'/\'\|\|\'webtms0098\'\|\|\'w/owa/\';

app_title varchar2(255) := \'APS Training Profiles\';

\--

cursor c_badge(p_pid in varchar2) is

select badge_no

from ows_app_login

where pid=p_pid;

tms_badge varchar2(10);

header_on boolean;

\--procedure login(isubmit in varchar2 default null,i_pid in varchar2
default NULL);

procedure login(i_pid in varchar2 default \'NEW\');

procedure generate_profile(ibadge_no in varchar2, i_pid in
varchar2,i_printer in varchar2,i_operation in varchar2 default NULL);

procedure process_reports(i_pid in varchar2,i_report in varchar2);

function run_print_it (i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,ibadge_no in varchar2,i_pid in
varchar2) return boolean;

\--procedure validate_user (i_badge in varchar2,i_pass in varchar2,i_pid
in varchar2,i_operation in varchar2 default null);

\--procedure change_password (i_operation in varchar2,i_pid in
varchar2,i_new_pw in varchar2,i_new_pw2 in varchar2);

PROCEDURE confirm_print(i_pid IN VARCHAR2,

i_search IN VARCHAR2 DEFAULT NULL,

i_options IN VARCHAR2,

ibadge_noS IN VARCHAR2 DEFAULT NULL,

ibadge_no IN VARCHAR2 DEFAULT NULL,

i_printer IN VARCHAR2 DEFAULT NULL,

i_operation IN VARCHAR2 DEFAULT NULL);

procedure print_all (i_pid in varchar2,i_operation in varchar2,i_printer
in varchar2);

procedure selection_criteria (i_pid in varchar2,i_operation in varchar2
default null,i_printer in varchar2 default null);

procedure course_list_frames(i_pid in varchar2);

procedure course_list_index(i_pid in varchar2);

procedure course_names(i_letter in varchar2,i_pid in varchar2);

procedure list_students(i_pid in varchar2,i_course in varchar2);

procedure view_expired_courses_page(i_pid in varchar2,i_report_type in
varchar2);

procedure login_accepted(i_pid in varchar2);

procedure selection_criteria;

procedure validate_user;

procedure confirm_print;

procedure course_list_frames;

END webtms2000;

/

CREATE OR REPLACE PACKAGE BODY webtms2000 IS

\--

FUNCTION GetBadge(p_name IN VARCHAR2) RETURN VARCHAR2 IS

CURSOR Get_Badge IS

SELECT DISTINCT person_id

FROM new_aps_a2z_people,ows_tms_priv

WHERE new_aps_a2z_people.person_id =\'00000\' \|\|
ows_tms_priv.can_see_badge

AND UPPER(name) = UPPER(p_name);

vNameHold VARCHAR2(200) := NULL;

BEGIN

OPEN Get_Badge;

FETCH Get_Badge INTO vNameHold;

CLOSE Get_Badge;

RETURN vNameHold;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

END GetBadge;

\--

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end get_service;

\--

function is_valid_pid(i_pid in varchar2) return boolean is

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'WEBTMS2\';

result := log0002.is_valid_pid(i_pid,p_app_name);

\--htp.p (wam0001.get_application_name(\'ISIMENU\'));

return result;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end is_valid_pid;

\--

function view_ok(i_pid in varchar2,i_viewed in varchar2) return boolean
is

cursor c_ok(p_badge in varchar2,p_viewed in varchar2) is

select \'1\'

from ows_tms_priv

where login_badge_no = p_badge

and \'00000\' \|\| can_see_badge = p_viewed;

temp varchar2(1);

begin

open c_badge(i_pid);

fetch c_badge into tms_badge;

close c_badge;

\--htp.print(\'PID=\' \|\| i_pid);

\--htp.print (\' badge 1,2 are \' \|\| tms_badge \|\| \' and \' \|\|
i_viewed);

open c_ok (tms_badge,i_viewed);

fetch c_ok into temp;

if not c_ok%NOTFOUND then

return TRUE;

else

htp.print(\'Not privileged to view this information. If you should be
able to, please login and try again.\');

return FALSE;

end if;

close c_ok;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end view_ok;

\-- Modification History

\--

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
information

\-- Modification history

\-- 05-MAR-97 kem Initial coding

FUNCTION run_print_it(i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,ibadge_no in varchar2,i_pid in
varchar2) return BOOLEAN IS

STR varchar2(255);

return_status varchar2(255);

tmp_cs varchar2(2000);

begin

if not header_on then

lib02.DisplayProlog (\'Print Training Profile\',\'D0D0D0\');

header_on := TRUE;

end if;

if is_valid_pid(i_pid) and view_ok(i_pid,ibadge_no) then

\-- validate access privileges for print requester

\-- STR := \'ESH/ESH@aps1\';

STR := \'esh/esh\';

\--htp.print (\'printer: \' \|\| i_printer);

\--htp.print (\'badge: \' \|\| ibadge_no);

mis_util.utl_print_it(\'\$mis_reports/\',\'tms_profile2000\',\'B\',i_printer,\'P\',\'SQR\',STR,\'NONE\',

ibadge_no,\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

\--message(\'return_status:\'\|\|return_status);

\-- log all print requests to tracking table \"ows_tms_login\"

if return_status = \'status:0\' then

\--htp.print (\'Training profile successfully sent to printer \"\' \|\|
i_printer \|\| \'\"\');

insert into esh.ows_tms_print_log

values (i_pid,ibadge_no,\'PRINTED\',sysdate,i_printer);

return TRUE;

else

insert into esh.ows_tms_print_log

values (i_pid,ibadge_no,\'FAILED\',sysdate,i_printer);

return FALSE;

\--htp.print (return_status);

end if;

end if;

htp.NL;

\-- lib.epilog;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

END run_print_it;

\--

procedure selection_criteria(i_pid in varchar2,i_operation in varchar2
default null,i_printer in varchar2 default null) is

cursor c_names(p_badge in varchar2) is

select distinct person_id,name

from new_aps_a2z_people,ows_tms_priv

where new_aps_a2z_people.person_id =\'00000\' \|\|
ows_tms_priv.can_see_badge

and login_badge_no = p_badge

order by name;

cursor c_name_count(p_pid in varchar2) is

select count(distinct(can_see_badge))

from ows_tms_priv p,ows_app_login l

where l.badge_no = p.login_badge_no

and pid = p_pid;

cursor c_scope (p_badge in varchar2) is

select \'1\'

from gen_user_roles roles, gen_user_table users

where roles.username = users.username

and badge_no = p_badge;

options number;

options2 number;

temp varchar2(1);

isLeader boolean;

begin

open c_badge(i_pid);

fetch c_badge into tms_badge;

close c_badge;

lib02.DisplayProlog (\'APS TMS Profile Selection\',\'D0D0D0\');

htp.p(\'\<script language=\"JavaScript\"\>\');

htp.p(\'function jsClearIt() {\');

htp.p(\' document.tms.ibadge_noS.selectedIndex = -1;\');

\-- htp.p(\' document.tms.ibadge_noS\[0\].selected = true;\');

htp.p(\'}//jsClearIt\');

htp.p(\'function jsClearIt2() {\');

htp.p(\' document.tms.ibadge_no.selectedIndex = -1;\');

\-- htp.p(\' document.tms.ibadge_no\[ibadge_no.length-1\].selected =
true;\');

htp.p(\'}//jsClearIt2\');

htp.p(\'function jsOnFind(oSelectList1) {\');

htp.p(\' var strIndex = -1;\');

htp.p(\' for (j=0;j\<oSelectList1.length;j++) {//for#1\');

htp.p(\' var strSearchHold = oSelectList1\[j\].value;\');

htp.p(\' var strSearch = strSearchHold.toUpperCase();\');

htp.p(\' var strHold = document.tms.i_search.value;\');

htp.p(\' strIndex = strSearch.indexOf(strHold.toUpperCase());\');

htp.p(\' if (strIndex == 0) {\');

htp.p(\' oSelectList1\[j\].selected = true;\');

htp.p(\' document.tms.ibadge_no.selectedIndex = -1;\');

\-- htp.p(\' document.tms.ibadge_no\[ibadge_no.length-1\].selected =
true;\');

htp.p(\' break; }\');

htp.p(\' }//end for\');

htp.p(\' if (strIndex == -1)\');

htp.p(\' alert(\"No matches found.\");\');

htp.p(\'}//jsOnLoad\');

\-- htp.p(\' if (oSelectList1\[index3\].value ==
document.tms.i_search.value)\');

\-- htp.p(\' alert(\"i am working\");\');

\-- htp.p(\' oSelectList1\[j\].defaultSelected = true;\');

\-- htp.p(\' document.tms.ibadge_no\[j\].selected = true;\');

\-- htp.p(\' alert(\"i am working\");\');

\-- htp.p(\' var index3 = oSelectList1.selectedIndex;\');

\-- htp.p(\' document.searchScreen.i_selOrderBy.length = 0;\');

\-- htp.p(\' var strSearch = oSelectList1\[index3\].value;\');

\-- htp.p(\' strIndex =
strSearch.indexOf(document.tms.i_search.value);\');

\-- htp.p(\' if (strIndex == -1)\');

\-- htp.p(\' if (oSelectList1\[index3\].value ==
document.tms.i_search.value)\');

\-- htp.p(\' alert(\"i am working\");\');

\-- htp.p(\' oSelectList1\[2\].selected = true;\');

htp.p(\'\</script\> \');

htp.print(\'\<CENTER\>\');

if is_valid_pid(i_pid) then

htp.print(\'\<h4\>\<i\>Disclaimer: Information presented in this system
can be verified by your TMS representative.\</h4\>\</i\>\');

htp.anchor(\'http://www.aps.anl.gov/mis/tms/tmsuser.html\',\'Web TMS
User\'\'s Guide\');

open c_scope(tms_badge);

fetch c_scope into temp;

\--if not c_scope%NOTFOUND then

isLeader := TRUE;

\-- htp.NL;

\-- htp.anchor(\'../owa/webtms2000.course_list_frames?i_pid=\' \|\|
i_pid,\'View By Course\');

\-- htp.NL;

\-- htp.HR;

\-- htp.NL;

else

isLeader := FALSE;

end if;

close c_scope;

open c_name_count(i_pid);

fetch c_name_count into options;

if c_name_count%NOTFOUND then

options := 1;

end if;

close c_name_count;

if options \> 15 then

options2 := 15;

else

options2 := options;

end if;

htp.formOpen(\'webtms2000.confirm_print\', cattributes=\>\'name=tms\');

htp.NL;

htp.NL;

/\*htp.p(htf.Bold(\'Printer name: \' ) \|\|
htf.formText(\'i_printer\',\'15\',\'15\',i_printer));

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\',\'View Profile\'));

\--htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_options\',to_char(options));

htp.tableData(htf.formSubmit(\'i_operation\',\'Print Profile\'));

htp.tableData(htf.formSubmit(\'i_operation\',\'Print All Profiles\'));

htp.tableRowClose;

htp.tableClose;

htp.NL;

\--htp.anchor(\'../owa/\' \|\| pkg_syn \|\| \'.login\',\'Return to Login
Screen\');

end if;\*/

htp.tableOpen(\'BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"
BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\' \|\| htf.img(\'/gen-img/apslogsm.gif\')
\|\| \'\<BR\>\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial, Helvetica\"
COLOR=\"#000000\"\>&nbsp TMS Profiles
&nbsp\</CENTER\>\',\'\',\'\',\'\',\'12\',\'\',\'BGCOLOR=\"#F0F0F0\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial, Helvetica\"
COLOR=\"#FFFFFF\"\>Please select a
profile\</CENTER\>\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Search:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableData(htf.formText(\'i_search\',\'15\',\'15\',NULL)\|\|

\'&nbsp;&nbsp;\<INPUT type=\"button\" value=\"Find\"
onClick=\"jsOnFind(ibadge_noS);\"\>\',

cattributes=\>\'BGCOLOR=\"#C0C0C0\" valign=middle\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Search Name:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.p(\'\<TD BGCOLOR=\"#C0C0C0\"\>\');

htp.formSelectOpen(\'ibadge_noS\',\'\',1,\'onChange=\"jsClearIt2()\"\');

\-- htp.formSelectOpen(\'ibadge_noS\',\'\',1);

htp.formSelectOption(\'\',\'SELECTED\',\'VALUE=\"\"\');

for r_name in c_names(tms_badge)

loop

\-- if r_name.person_id = \'00000\' \|\| tms_badge then

htp.formSelectOption(initcap(r_name.name),NULL,\'VALUE=\"\' \|\|
initcap(r_name.name)\|\|\'\"\');

\-- else

\-- htp.formSelectOption(initcap(r_name.name),\'\',\'VALUE=\' \|\|
initcap(r_name.name));

\-- end if;

end loop;

htp.formSelectClose;

\-- htp.formHidden(\'ibadge_noS\',\'\');

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

\--htp.formHidden(\'i_pid\',i_pid);

\-- htp.formHidden(\'i_options\',to_char(options));

\--htp.formHidden(\'i_operation\',\'View Profile\');

htp.tableData(\'&nbsp;\');

htp.tableData(\'\<b\>OR\</b\>\',\'center\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Name:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.p(\'\<TD BGCOLOR=\"#C0C0C0\"\>\');

htp.formSelectOpen(\'ibadge_no\',\'\',to_char(options2),\'onChange=\"jsClearIt()\"\');

\-- htp.formSelectOpen(\'ibadge_no\',\'\',to_char(options2));

for r_name in c_names(tms_badge)

loop

if r_name.person_id = \'00000\' \|\| tms_badge then

\-- htp.formSelectOption(initcap(r_name.name),\'SELECTED\',\'VALUE=\"\'
\|\| initcap(r_name.name)\|\|\'\"\');

htp.formSelectOption(initcap(r_name.name),\'SELECTED\',\'VALUE=\"\' \|\|
initcap(r_name.name)\|\|\'\"\');

else

htp.formSelectOption(initcap(r_name.name),\'\',\'VALUE=\"\' \|\|
initcap(r_name.name)\|\|\'\"\');

end if;

end loop;

htp.formSelectOption(\'\',\'SELECTED\',\'VALUE=\"\"\');

htp.formSelectClose;

\-- htp.formHidden(\'ibadge_no\',\'\');

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

\--htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_options\',to_char(options));

\--htp.formHidden(\'i_operation\',\'View Profile\');

htp.tableData(htf.formSubmit(\'i_operation\', \'View
Profile\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Printer:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.tableData(htf.formText(\'i_printer\',\'15\',\'15\',i_printer),cattributes=\>\'BGCOLOR=\"#C0C0C0\"\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.formHidden(\'i_pid\',i_pid);

htp.tableData(htf.formSubmit(\'i_operation\', \'Print Profile\')
\|\|htf.formSubmit(\'i_operation\', \'Print All Profiles\')
,\'RIGHT\',\'\',\'\',\'\',\'2\');

\--htp.tableData(htf.formSubmit(\'i_operation\', \'Print All
Profiles\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.formClose;

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial, Helvetica\"
COLOR=\"#FFFFFF\"\>- or -\</CENTER\>\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(\'\<CENTER\>\<FONT SIZE=\"2\" FACE=\"Arial, Helvetica\"
COLOR=\"#FFFFFF\"\>Please select a
report\</CENTER\>\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

if isLeader then

htp.formOpen(\'webtms2000.process_reports\');

htp.tableRowOpen;

htp.tableData(\'\<FONT SIZE=\"2\" FACE=\"Tahoma, Arial,
Helvetica\"\>&nbsp Report:\',
\'RIGHT\',\'\',\'\',\'\',\'\',\'BGCOLOR=\"#C0C0C0\"\');

htp.p(\'\<TD BGCOLOR=\"#C0C0C0\"\>\');

htp.formSelectOpen(\'i_report\',\'\',\'3\');\--to_char(options2));

htp.formSelectOption(\'Specific Course, Any
Status\',\'\',\'VALUE=ALL_COURSES\');

htp.formSelectOption(\'Expired Courses By
Name\',\'\',\'VALUE=BY_NAME\');

htp.formSelectOption(\'Expired Courses By Course\'
,\'\',\'VALUE=BY_COURSE\');

htp.formSelectClose;

htp.formHidden(\'i_pid\',i_pid);

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.formSubmit(\'\', \'Get
Report\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

end if;

/\*if isLeader then

htp.tableRowOpen(\'\',\'\',\'\',\'\',\'BGCOLOR=\"#808080\"\');

htp.tableData(htf.formSubmit(\'\', \'Get
Profile\'),\'RIGHT\',\'\',\'\',\'\',\'2\');

htp.p(\'\<TD\>\');

htp.formOpen(\'webtms2000.view_expired_courses_page\');

htp.p(\'\<TD ROWSPAN=\"2\"\>\' \|\| htf.formSubmit(\'\',\'View Only
Expired Courses\') \|\| \'\</TD\>\');

htp.tableData(htf.formRadio(\'i_report_type\',\'By Name\',\'True\') \|\|
\'By Name\');

htp.tableData(htf.formRadio(\'i_report_type\',\'By Course\') \|\| \'By
Course\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

end if;\*/

htp.tableRowOpen;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

htp.p(\'\</CENTER\>\');

lib02.DisplayEpilog;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end selection_criteria;

\--

procedure confirm_print(i_pid IN VARCHAR2,

i_search IN VARCHAR2 DEFAULT NULL,

i_options IN VARCHAR2,

ibadge_noS IN VARCHAR2 DEFAULT NULL,

ibadge_no IN VARCHAR2 DEFAULT NULL,

i_printer IN VARCHAR2 DEFAULT NULL,

i_operation IN VARCHAR2 DEFAULT NULL) IS

vBadgeNo VARCHAR2(20) := NULL;

begin

if is_valid_pid(i_pid) then

IF (ibadge_no IS NOT NULL)

THEN

vBadgeNo := GetBadge(ibadge_no);

ELSE

vBadgeNo := GetBadge(ibadge_noS);

END IF;

if (i_operation != \'View Profile\') AND ((i_printer is null) OR
(i_printer = \'\')) then

lib02.DisplayProlog(\'Missing Printer Name\',\'D0D0D0\');

htp.print(\'\<CENTER\>\');

htp.print(\'Please enter a printer name.\');

htp.NL;

htp.anchor(\'../owa/webtms2000.selection_criteria?i_pid=\' \|\|
i_pid,\'Return to Selection Page\');

htp.print(\'\</CENTER\>\');

lib02.DisplayEpilog;

else

if i_operation = \'Print All Profiles\' then

lib02.DisplayProlog(\'Print All Profiles Confirmation\',\'D0D0D0\');

htp.print(\'\<CENTER\>\');

htp.formOpen( \'webtms2000.print_all\');

htp.print(\'\<h4\>Warning: This option will print profiles for all \'
\|\| i_options \|\| \' people on the previous page.\</h4\>\');

htp.print(\'\<h5\>This may take some time. Please click \'\'Print\'\' if
you wish to proceed.\</h5\>\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_printer\',i_printer);

htp.NL;

htp.formSubmit(\'i_operation\',\'Print\');

htp.formSubmit(\'i_operation\',\'Previous Screen\');

\--htp.formSubmit(\'i_operation\',\'Back\',\'onClick=history.go(-1)\');

htp.formClose;

htp.tableClose;

htp.print(\'\</CENTER\>\');

lib02.DisplayEpilog;

elsif i_operation = \'Print Profile\' then

lib02.DisplayProlog(\'Profile Print Confirmation\',\'D0D0D0\');

htp.print(\'\<CENTER\>\');

if (run_print_it(i_printer,NULL,vBadgeNo,i_pid)) then

htp.print(\'Profile for \' \|\| vBadgeNo \|\| \' successfully sent to
printer \' \|\| i_printer);

else

htp.print(\'Unable to send profile for \' \|\| vBadgeNo \|\| \' to
printer \' \|\| i_printer);

end if;

htp.formOpen(\'webtms2000.selection_criteria\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_printer\',i_printer);

htp.formSubmit(\'i_operation\',\'Return To Selection Screen\');

htp.formClose;

htp.print(\'\</CENTER\>\');

lib02.DisplayEpilog;

else generate_profile(vBadgeNo,i_pid,i_printer);

end if;

end if;

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end confirm_print;

\--

procedure print_all(i_pid in varchar2,i_operation in varchar2,i_printer
in varchar2) is

cursor c_names(p_badge in varchar2) is

select distinct person_id,name

from new_aps_a2z_people,ows_tms_priv

where new_aps_a2z_people.person_id =\'00000\' \|\|
ows_tms_priv.can_see_badge

and login_badge_no = p_badge

order by name;

temp_person_id varchar2(10);

begin

open c_badge(i_pid);

fetch c_badge into tms_badge;

close c_badge;

if is_valid_pid(i_pid) then

if i_operation = \'Print\' then

lib02.DisplayProlog(\'Batch Print Log\',\'D0D0D0\');

htp.print(\'\<CENTER\>\');

for r_name in c_names(tms_badge) loop

if (run_print_it(i_printer,NULL,r_name.person_id,i_pid)) then

htp.print(\'Profile for \' \|\| r_name.person_id \|\| \' successfully
sent to printer \' \|\| i_printer);

else

htp.print(\'Unable to send profile for \' \|\| r_name.person_id \|\| \'
to printer \' \|\| i_printer);

end if;

htp.NL;

end loop;

htp.formOpen(\'webtms2000.selection_criteria\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_printer\',i_printer);

htp.formSubmit(\'i_operation\',\'Return To Selection Screen\');

htp.formClose;

htp.print(\'\</CENTER\>\');

lib02.DisplayEpilog;

else

selection_criteria(i_pid,\'\',i_printer);

end if;

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end print_all;

\--

procedure login(i_pid in varchar2 default \'NEW\') is

begin

log0002.login(\'WEBTMS2\',\'\',i_pid);

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end login;

\--

function get_badge(i_pid in varchar2) return varchar2 is

cursor c_get_badge (p_pid in varchar2) is

select badge_no

from ows_app_login

where pid = p_pid;

result varchar2(10);

begin

open c_get_badge(i_pid);

fetch c_get_badge into result;

if c_get_badge%NOTFOUND then

result := \'NONE\';

end if;

close c_get_badge;

return (result);

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end get_badge;

\--

procedure login_accepted(i_pid in varchar2) is

cursor c_list_exists (p_badge in varchar2) is

select \'1\'

from ows_tms_priv

where login_badge_no = p_badge;

temp_badge varchar2(10);

temp varchar2(1);

begin

\--htp.p(\'LOGIN HAS BEEN ACCEPTED\');

if is_valid_pid(i_pid) then

temp_badge := get_badge(i_pid);

\--htp.p(temp_badge);

\--build list for selection criteria IF NOT ALREADY BUILT FOR THIS USER

open c_list_exists(temp_badge);

fetch c_list_exists into temp;

if c_list_exists%NOTFOUND then

\--make new list

gen0003.request_list(\'\',\'TMS\',temp_badge);

end if;

close c_list_exists;

selection_criteria(i_pid);

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end login_accepted;

\--

procedure course_list_index(i_pid in varchar2) is

begin

htp.print(\'\<h1\>Course Lists\</h1\>\');

\--lib.prolog(\'Course Lists\');

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=A&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>A\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=B&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>B\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=C&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>C\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=D&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>D\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=E&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>E\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=F&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>F\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=G&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>G\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=H&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>H\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=I&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>I\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=J&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>J\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=K&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>K\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=L&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>L\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=M&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>M\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=N&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>N\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=O&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>O\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=P&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>P\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=Q&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>Q\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=R&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>R\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=S&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>S\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=T&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>T\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=U&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>U\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=V&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>V\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=W&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>W\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=X&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>X\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=Y&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>Y\</a\>&nbsp;\|&nbsp\');

\--HTP.NL;

htp.prn(\'\<a href=\"../owa/webtms2000.course_names?i_letter=Z&i_pid=\'
\|\| i_pid \|\| \'\" target=\"course_name\"\>Z\</a\>\');

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end course_list_index;

\--

procedure course_names(i_letter in varchar2, i_pid in varchar2) is

cursor c_course_names (p_letter in varchar2) is

select \*

from aps_a2z_course course

where course_name like upper(p_letter) \|\| \'%\'

and EXISTS

(select \'X\'

from aps_a2z_per_cours_stat stat

where stat.course_no=course.course_no);

/\*where course_no in

(select distinct course_no from aps_a2z_per_cours_stat)

and upper(course_name) like upper(p_letter) \|\| \'%\';\*/

r_course aps_a2z_course%TYPE;

begin

open c_course_names(i_letter);

fetch c_course_names into r_course;

if c_course_names%NOTFOUND then

htp.print(\'.\');

end if;

while not c_course_names%NOTFOUND loop

\--htp.ANCHOR(\'../owa/webtms2000.list_students?i_pid=\' \|\| i_pid \|\|
\'&i_course=\' \|\| r_course.dprod_id \|\|,r_course.a2e_course_name \|\|
\' (\'\|\| r_course.dprod_id \|\| \')\');

htp.prn(\'\<a href=\"../owa/webtms2000.list_students?i_pid=\' \|\| i_pid
\|\| \'&i_course=\' \|\| r_course.course_no \|\| \'\"
target=\"course_detail\"\>\' \|\| r_course.course_name \|\| \' (\'\|\|
r_course.course_no \|\| \')\');

htp.NL;

fetch c_course_names into r_course;

end loop;

close c_course_names;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end course_names;

\--

procedure list_students(i_pid in varchar2,i_course in varchar2) is

begin

declare

cursor c_students(p_badge in varchar2) is

select
per_name,people.person_id,aps_level,next_reqd_dt,current_stat,last_compl_dt

FROM new_aps_a2z_people people,

aps_a2z_per_cours_stat cours_stat,

aps_a2z_course course

WHERE cours_stat.course_no = course.course_no and

cours_stat.person_id = people.person_id

AND (COURS_STAT.RQMNT_LVL = \'L\' OR

COURS_STAT.ENROLL_TYPE = \'E\' OR

(COURSE.STATUS_CD = \'A\' AND

( COURS_STAT.RQMNT_LVL = \'S\' OR

( COURS_STAT.RQMNT_LVL = \'R\' AND

COURS_STAT.CURRENT_STAT in (\'X\',\'C\',\'O\',\'T\',\'V\' )))))

and cours_stat.course_no=i_course

and EXISTS

(select \'X\'

FROM OWS_TMS_PRIV

where \'00000\' \|\| can_see_badge = people.person_id

and login_badge_no = p_badge)

order by aps_level,per_name;

type r_student is RECORD (

per_name new_aps_a2z_people.PER_NAME%TYPE,

person_id new_aps_a2z_people.PERSON_ID%TYPE,

aps_level new_aps_a2z_people.APS_LEVEL%TYPE,

next_reqd_dt aps_a2z_per_cours_stat.NEXT_REQD_DT%TYPE,

current_stat aps_a2z_per_cours_stat.CURRENT_STAT%TYPE,

last_compl_dt aps_a2z_per_cours_stat.LAST_COMPL_DT%TYPE

);

cursor c_name is

select course_name

from aps_a2z_course

where course_no = i_course;

taken_date date;

rec_student r_student;

trans_display varchar2(20);

status varchar2(20);

temp varchar2(255);

ret_date varchar2(20);

begin

open c_badge(i_pid);

fetch c_badge into tms_badge;

close c_badge;

if i_course != \'NONE\' then

if is_valid_pid(i_pid) then

open c_students(tms_badge);

fetch c_students into rec_student;

htp.print(\'\<CENTER\>\');

htp.print(\'\<h4\>Last updated: \' \|\| to_char(sysdate,\'DD-MON-YYYY\')
\|\| \'\</h4\>\');

htp.NL;

open c_name;

fetch c_name into temp;

close c_name;

htp.p(\'\<h1\>\<strong\>\' \|\| i_course \|\| \' - \' \|\| temp);

htp.NL;

htp.p(\'All Requirement Levels, All Status\</strong\>\</h1\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Name\');

htp.tableHeader(\'Division\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Retraining Required Date\');

htp.tableHeader(\'Completed Date\');

while not c_students%NOTFOUND loop

htp.tableRowOpen;

htp.tableData(nvl(rec_student.per_name,\'.\'));

htp.tableData(nvl(rec_student.aps_level,\'.\'));

status := \'Not Scheduled\';

if rec_student.current_stat=\'C\' then

status := \'Current\';

elsif rec_student.current_stat in (\'X\',\'O\',\'E\') then

if rec_student.current_stat = \'X\' then

status := \'Expired\';

elsif rec_student.current_stat = \'O\' then

status := \'Open\';

else

status := \'Enrolled\';

end if;

else

status := \'Not Taken\';

end if;

if status=\'Current\' or status = \'Open\' or status=\'Expired\' then

ret_date :=
nvl(to_char(rec_student.next_reqd_dt,\'DD-MON-YYYY\'),\'&nbsp\');

\--ret_date := to_char(rec_student.next_reqd_dt);

\--ret_date := rec_student.next_reqd_dt;

else

ret_date := \'.\';

end if;

trans_display:=nvl(to_char(rec_student.last_compl_dt,\'DD-MON-YYYY\'),\'Not
Taken\');

htp.tableData(status);

htp.tableData(ret_date);

htp.tableData(trans_display);

htp.tableRowClose;

fetch c_students into rec_student;

end loop;

close c_students;

htp.tableClose;

htp.print(\'\</CENTER\>\');

end if;

else

htp.print(\'.\');

end if;

EXCEPTION

when others then

htp.p(sqlerrm);

htp.NL;

htp.p(rec_student.next_reqd_dt);

end;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end list_students;

\--

procedure course_list_frames(i_pid in varchar2) is

begin

htp.print(\'\<FRAMESET ROWS=\"120,\*\"\>\');

htp.print(\'\<FRAME SRC=\"../owa/webtms2000.course_list_index?i_pid=\'
\|\| i_pid \|\| \'\" SCROLLING=NO\>\');

htp.print(\'\<FRAMESET ROWS=\"150,\*\"\>\');

htp.print(\'\<FRAME SRC=\"../owa/webtms2000.course_names?i_pid=\' \|\|
i_pid \|\| \'&i_letter=A\" NAME=\"course_name\"\>\');

htp.print(\'\<FRAME SRC=\"../owa/webtms2000.list_students?i_pid=\' \|\|
i_pid \|\|\'&i_course=NONE\" NAME=\"course_detail\"\>\');

htp.print(\'\</FRAMESET\>\');

htp.print(\'\</FRAMESET\>\');

htp.print(\'\<NOFRAMES\>\');

lib02.DisplayProlog(\'Course List - Requires Frames\',\'D0D0D0\');

htp.print(\'A \"frame\" capable browser (i.e. Navigator 3.0) is required
for course list information.\');

lib02.DisplayEpilog;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end course_list_frames;

\--

/\* 24-MAR-99 kem - new report added\*/

procedure view_expired_courses_page(i_pid in varchar2,i_report_type in
varchar2) is

cursor c_expired_by_course (p_badge in varchar2) is

select distinct
per_name,people.person_id,aps_level,next_reqd_dt,current_stat,last_compl_dt,course_no

from new_aps_a2z_people people, aps_a2z_per_cours_stat cours

where people.person_id=cours.person_id

and rqmnt_lvl in (\'D\',\'X\',\'R\')

and current_stat=\'X\'

and EXISTS

(select \'X\'

FROM OWS_TMS_PRIV

where \'00000\' \|\| can_see_badge = people.person_id

and login_badge_no = p_badge)

order by aps_level,course_no;

cursor c_expired_by_student (p_badge in varchar2) is

select distinct per_name,people.person_id as
person_id,aps_level,next_reqd_dt as
next_reqd_dt,current_stat,last_compl_dt,course_no

from new_aps_a2z_people people, aps_a2z_per_cours_stat cours

where people.person_id=cours.person_id

and rqmnt_lvl in (\'D\',\'X\',\'R\')

and current_stat=\'X\'

and EXISTS

(select \'X\'

FROM OWS_TMS_PRIV

where \'00000\' \|\| can_see_badge = people.person_id

and login_badge_no = p_badge) order by aps_level,per_name,course_no;

type r_student is RECORD (

per_name new_aps_a2z_people.PER_NAME%TYPE,

person_id new_aps_a2z_people.PERSON_ID%TYPE,

aps_level new_aps_a2z_people.APS_LEVEL%TYPE,

next_reqd_dt aps_a2z_per_cours_stat.NEXT_REQD_DT%TYPE,

current_stat aps_a2z_per_cours_stat.CURRENT_STAT%TYPE,

last_compl_dt aps_a2z_per_cours_stat.LAST_COMPL_DT%TYPE

);

tms_badge varchar2(10);

current_item varchar2(255);

begin

open c_badge(i_pid);

fetch c_badge into tms_badge;

close c_badge;

if is_valid_pid(i_pid) then

lib02.DisplayProlog(\'View Required Status Expired Courses \' \|\|
i_report_type,\'D0D0D0\');

htp.centerOpen;

current_item := \'X\';

if i_report_type=\'By Name\' then

\--open c_expired_by_student

\--htp.p(\'By Name \' \|\| tms_badge);

htp.tableOpen(\'BORDER\');

htp.tableRowOpen;

htp.tableData(\'\<B\>Name\</B\>\');

htp.tableData(\'\<B\>Badge\</B\>\');

htp.tableData(\'\<B\>Division\</B\>\');

htp.tableData(\'\<B\>Required By\</B\>\');

htp.tableData(\'\<B\>Last Completed\</B\>\');

htp.tableData(\'\<B\>Course\</B\>\');

htp.tableRowClose;

for r_expired in c_expired_by_student(tms_badge) loop

htp.tableRowOpen;

if current_item != r_expired.per_name then

htp.tableData(r_expired.per_name);

else

htp.tableData(\'&nbsp\');

end if;

htp.tableData(r_expired.person_id);

htp.tableData(r_expired.aps_level);

htp.tableData(nvl(to_char(r_expired.next_reqd_dt,\'DD-MON-YYYY\'),\'&nbsp\'));

\--htp.tableData(r_expired.current_stat);

htp.tableData(nvl(to_char(r_expired.last_compl_dt,\'DD-MON-YYYY\'),\'&nbsp\'));

htp.tableData(r_expired.course_no);

htp.tableRowClose;

current_item := r_expired.per_name;

end loop;

htp.tableClose;

elsif i_report_type=\'By Course\' then

\--open c_expired_by_course

\--htp.p(\'By Course\');

htp.tableOpen(\'BORDER\');

htp.tableRowOpen;

htp.tableData(\'\<B\>Course\</B\>\');

htp.tableData(\'\<B\>Name\</B\>\');

htp.tableData(\'\<B\>Badge\</B\>\');

htp.tableData(\'\<B\>Division\</B\>\');

htp.tableData(\'\<B\>Required By\</B\>\');

htp.tableData(\'\<B\>Last Completed\</B\>\');

htp.tableRowClose;

for r_expired in c_expired_by_course(tms_badge) loop

htp.tableRowOpen;

if current_item != r_expired.course_no then

htp.tableData(r_expired.course_no);

else

htp.tableData(\'&nbsp\');

end if;

htp.tableData(r_expired.per_name);

htp.tableData(r_expired.person_id);

htp.tableData(r_expired.aps_level);

htp.tableData(nvl(to_char(r_expired.next_reqd_dt,\'DD-MON-YYYY\'),\'&nbsp\'));

htp.tableData(nvl(to_char(r_expired.last_compl_dt,\'DD-MON-YYYY\'),\'&nbsp\'));

htp.tableRowClose;

current_item := r_expired.course_no;

end loop;

htp.tableClose;

else

htp.p(\'No report specified.\');

end if;

htp.centerClose;

lib02.DisplayEpilog;

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end view_expired_courses_page;

\--

procedure process_reports(i_pid in varchar2,i_report in varchar2) is

begin

if is_valid_pid(i_pid) then

if i_report=\'ALL_COURSES\' then

course_list_frames(i_pid);

elsif i_report=\'BY_NAME\' then

view_expired_courses_page(i_pid,\'By Name\');

elsif i_report=\'BY_COURSE\' then

view_expired_courses_page(i_pid,\'By Course\');

end if;

end if;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end process_reports;

\--

procedure generate_profile(ibadge_no in varchar2,i_pid in
varchar2,i_printer in varchar2,i_operation in varchar2 default NULL) is

class_desc varchar2(255);

certification_date varchar2(10);

expiration_date varchar2(10);

name esh.new_aps_a2z_people.per_name%TYPE;

badge_no badge_info.badge_no%TYPE;

cursor c_name (p_badge in varchar2) is

select initcap(name)

from new_aps_a2z_people

where person_id = p_badge;

\--new TMS required

cursor c_profile(p_badge in varchar2) is

SELECT new_aps_a2z_people.person_id,

new_aps_a2z_people.per_name,

new_aps_a2z_people.per_cstctr_cd,

new_aps_a2z_people.per_div_cd,

new_aps_a2z_people.per_supr_name,

new_aps_a2z_people.per_supr_phone,

aps_a2z_course.status_cd,

aps_a2z_course.course_no,

aps_a2z_course.course_name,

aps_a2z_per_cours_stat.compl_cd,

aps_a2z_per_cours_stat.current_stat,

aps_a2z_per_cours_stat.last_compl_dt,

aps_a2z_per_cours_stat.next_reqd_dt,

aps_a2z_per_cours_stat.rqmnt_lvl,

aps_a1z_argonne_values.a1e_num_val1 ,

sysdate ,

decode( aps_a2z_per_cours_stat.rqmnt_lvl,

\'R\',decode(

aps_a2z_per_cours_stat.current_stat,

\'C\',\'2\',\'1\'),

\'S\',\'3\',

\'L\',\'4\',

\'5\') calc_break

FROM new_aps_a2z_people,

aps_a2z_per_cours_stat,

aps_a2z_course,

aps_a1z_argonne_values

WHERE ( aps_a2z_per_cours_stat.course_no = aps_a2z_course.course_no )
and

( aps_a2z_per_cours_stat.person_id = new_aps_a2z_people.person_id ) and

( aps_a2z_per_cours_stat.rqmnt_lvl = aps_a1z_argonne_values.a1e_key1

) and

(\"APS_A2Z_PER_COURS_STAT\".\"RQMNT_LVL\" = \'L\' OR

APS_A2Z_PER_COURS_STAT.ENROLL_TYPE = \'E\' OR

(\"APS_A2Z_COURSE\".\"STATUS_CD\" = \'A\' AND

( \"APS_A2Z_PER_COURS_STAT\".\"RQMNT_LVL\" = \'S\' OR

( \"APS_A2Z_PER_COURS_STAT\".\"RQMNT_LVL\" = \'R\' AND

APS_A2Z_PER_COURS_STAT.CURRENT_STAT in (\'X\',\'C\',\'O\',\'T\',\'V\' )
) )

) ) AND

APS_A1Z_ARGONNE_VALUES.A1E_RECORD_TYPE = \'TMS_REQUIREMENT\'

and new_aps_a2z_people.PERSON_ID=p_badge

ORDER BY calc_break,

aps_a2z_per_cours_stat.course_no;

cursor c_web_class_link (p_prod_id in varchar2) is

select link

from wbt_class_links

where dprod_id=p_prod_id;

class_link varchar2(255);

l_rqmnt_lvl varchar2(3);

l_stat varchar2(3);

stat_print varchar2(255);

\--www_doc_base varchar2(100):=
\'http://www.aps.anl.gov/mis/tms/97TMSPRIM.html\';

www_doc_base varchar2(100):=
\'http://www.aps.anl.gov/esh/asd/eshpages/97TMSPRIM.html\';

\--new code for conversion

type profile_rec is RECORD

(person_id new_aps_a2z_people.person_id%TYPE,

per_name new_aps_a2z_people.per_name%TYPE,

per_cstctr_cd new_aps_a2z_people.per_cstctr_cd%TYPE,

per_div_cd new_aps_a2z_people.per_div_cd%TYPE,

per_supr_name new_aps_a2z_people.per_supr_name%TYPE,

per_supr_phone new_aps_a2z_people.per_supr_phone%TYPE,

status_cd aps_a2z_course.status_cd%TYPE,

course_no aps_a2z_course.course_no%TYPE,

course_name aps_a2z_course.course_name%TYPE,

compl_cd aps_a2z_per_cours_stat.compl_cd%TYPE,

current_stat aps_a2z_per_cours_stat.current_stat%TYPE,

last_compl_dt aps_a2z_per_cours_stat.last_compl_dt%TYPE,

next_reqd_dt aps_a2z_per_cours_stat.next_reqd_dt%TYPE,

rqmnt_lvl aps_a2z_per_cours_stat.rqmnt_lvl%TYPE,

a1e_num_val1 aps_a1z_argonne_values.a1e_num_val1%TYPE,

current_date date,

calc_break VARCHAR2(3));

r_req profile_rec;

due_by varchar2(11);

last varchar2(11);

l_val aps_a1z_argonne_values.a1e_num_val1%TYPE;

l_calc varchar2(3);

begin

open c_name(ibadge_no);

fetch c_name into name;

close c_name;

lib02.DisplayProlog (\'APS WebTMS 2000\',\'D0D0D0\');

htp.p(\'\<FONT SIZE=\"+1\" FACE=\"ARIAL\"\>\<BOLD\>\' \|\|
to_char(sysdate,\'DD-MON-YYYY\') \|\| \'&nbsp&nbsp&nbsp&nbsp Personal
Training Profile for \' \|\| name \|\| \'\</BOLD\<\</FONT\>\');

\--lib.prolog (\'Personal Training Profile for \' \|\| name);

htp.centerOpen;

l_rqmnt_lvl := \'\';

l_stat := \'\';

l_calc := \'0\';

if is_valid_pid(i_pid) and view_ok(i_pid,ibadge_no) then

htp.p(\'\<TABLE BORDER=\"1\" WIDTH=\"100%\" BGCOLOR=\"#F0F0F0\"\>\');

open c_profile(ibadge_no);

fetch c_profile into r_req;

while not c_profile%NOTFOUND loop

\--htp.p(\'Req lvl= \' \|\| r_req.rqmnt_lvl \|\| \' current stat=\' \|\|
r_req.current_stat \|\| \' calc break= \' \|\| r_req.calc_break);

\--htp.p(\'Course=\' \|\| r_req.course_no \|\| \' \<BR\> \');

if r_req.calc_break != l_calc then

if r_req.calc_break = 1 then

\--htp.p(\'Req lvl= \' \|\| r_req.rqmnt_lvl \|\| \' current stat=\' \|\|
r_req.current_stat \|\| \' calc break= \' \|\| r_req.calc_break);

htp.print(\'\<strong\>\<h3\>Required Courses\</h3\>\</strong\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Course\');

htp.tableHeader(\'Course Name\',\'WIDTH=120\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Last Completed\');

htp.tableHeader(\'Due By\');

elsif r_req.calc_break = 2 then

htp.tableClose;

\--htp.p(\'Req lvl= \' \|\| r_req.rqmnt_lvl \|\| \' current stat=\' \|\|
r_req.current_stat \|\| \' calc break= \' \|\| r_req.calc_break);

htp.print(\'\<strong\>\<h3\>Required Courses
Completed\</h3\>\</strong\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Course\');

htp.tableHeader(\'Course Name\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Last Completed\');

htp.tableHeader(\'Due By\');

elsif r_req.calc_break=\'3\' then

htp.tableClose;

\--htp.p(\'Req lvl= \' \|\| r_req.rqmnt_lvl \|\| \' current stat=\' \|\|
r_req.current_stat \|\| \' calc break= \' \|\| r_req.calc_break);

htp.print(\'\<strong\>\<h3\>Suggested Courses\</h3\>\</strong\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Course\');

htp.tableHeader(\'Course Name\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Last Completed\');

htp.tableHeader(\'Due By\');

elsif r_req.calc_break = \'4\' then

htp.tableClose;

\--htp.p(\'Req lvl= \' \|\| r_req.rqmnt_lvl \|\| \' current stat=\' \|\|
r_req.current_stat \|\| \' calc break= \' \|\| r_req.calc_break);

htp.print(\'\<strong\>\<h3\>Elective Courses\</h3\>\</strong\>\');

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Course\');

htp.tableHeader(\'Course Name\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Last Completed\');

htp.tableHeader(\'Due By\');

end if;

end if;

l_rqmnt_lvl := r_req.rqmnt_lvl;

l_stat := r_req.current_stat;

l_calc := r_req.calc_break;

htp.tableRowOpen;

\--if web based course, display link

open c_web_class_link(r_req.course_no);

fetch c_web_class_link into class_link;

if not c_web_class_link%NOTFOUND then

htp.tableData(htf.anchor(class_link ,r_req.course_no));

else

htp.tableData(r_req.course_no);

end if;

close c_web_class_link;

htp.tableData(nvl(r_req.course_name,\'.\'));

if r_req.current_stat = \'O\'

then

stat_print := htf.anchor(www_doc_base \|\| \'#OPEN\',\'Open\');

elsif r_req.current_stat = \'E\'

then

stat_print := \'Enrolled\';

elsif r_req.current_stat = \'L\'

then

stat_print := htf.anchor(www_doc_base \|\| \'#ELECTIVE\',\'Elective\');

elsif r_req.current_stat = \'S\'

then

stat_print := htf.anchor(www_doc_base \|\|
\'#SUGGESTED\',\'Suggested\');

elsif r_req.current_stat = \'V\'

then

stat_print := htf.anchor(www_doc_base \|\|
\'#RESTRICTIVE\',\'Restrictive\');

elsif r_req.current_stat = \'C\'

then

stat_print := htf.anchor(www_doc_base \|\|
\'#COMPLETED\',\'Completed\');

elsif r_req.current_stat = \'X\'

then

stat_print := htf.anchor(www_doc_base \|\| \'#EXPIRED\',\'Expired\');

else

stat_print := r_req.current_stat \|\| \' - error please report\';

end if;

htp.tableData(stat_print);

last:=to_char(r_req.last_compl_dt,\'DD-MON-YYYY\');

htp.tableData(nvl(last,\'&nbsp\'));

due_by := to_char(r_req.next_reqd_dt,\'DD-MON-YYYY\');

if due_by != \'31-DEC-2222\' then

htp.tableData(due_by);

else

htp.tableData(\'&nbsp\');

end if;

htp.tableRowClose;

fetch c_profile into r_req;

end loop;

close c_profile;

htp.tableClose;

htp.NL;

htp.NL;

header_on := FALSE;

htp.formOpen(\'webtms2000.confirm_print\');

htp.formHidden(\'ibadge_no\',ibadge_no);

htp.print(htf.Bold(\'Printer name: \' ) \|\|
htf.formText(\'i_printer\',\'15\',\'15\',i_printer));

htp.formHidden(\'i_pid\',i_pid);

htp.NL;

htp.NL;

htp.formHidden(\'i_options\',\'1\');

htp.formSubmit(\'i_operation\',\'Print Profile\');

htp.formClose;

end if;

htp.centerClose;

lib02.DisplayEpilog;

\--lib.epilog;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end generate_profile;

\--

procedure no_bookmark is

begin

lib02.DisplayProlog(\'Login Required\',\'D0D0D0\');

htp.print(\'\<CENTER\>\');

htp.print(\'Please start this TMS session at the login screen.
Cheers.\');

htp.NL;

htp.anchor(\'../owa/webtms2000.login\',\'Log on to TMS\');

htp.print(\'\</CENTER\>\');

lib02.DisplayEpilog;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end no_bookmark;

\--

procedure selection_criteria is

begin

no_bookmark;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end selection_criteria;

\--

procedure validate_user is

begin

no_bookmark;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end validate_user;

\--

procedure confirm_print is

begin

no_bookmark;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end confirm_print;

\--

procedure course_list_frames is

begin

no_bookmark;

\-- added error handling mtm083199

EXCEPTION

WHEN OTHERS THEN

LIB02.Show_Error(owa_util.get_procedure, \-- package.procedure name

NULL, \-- error location

SQLERRM, \-- error code and message

NULL, \-- additional user-provided error information

FALSE); \-- commit true/false default false

end course_list_frames;

END webtms2000;

/

CREATE OR REPLACE PACKAGE xsr0005

is

G_MENU_START_PAGE constant varchar2(50) := \'wam0002.DCN_MAIN_MENU\';

G_QUERY_START_PAGE_APP constant varchar2(50) := \'XSR_USER\';

G_QUERY_START_PAGE constant varchar2(50) := \'QUERY_START_PAGE\';

G_QUERY_OP constant varchar2(50) := \'Query\';

G_NEW_START_PAGE_APP constant varchar2(50) := \'DCN_NEW\';

G_NEW_START_PAGE constant varchar2(50) := \'NEW_START_PAGE\';

G_NEW_OP constant varchar2(50) := \'New\';

G_ADD_OP constant varchar2(50) := \'Add Another\';

G_REVISE_START_PAGE_APP constant varchar2(50) := \'DCN_REVISE\';

G_REVISE_START_PAGE constant varchar2(50) := \'REVISE_START_PAGE\';

G_REVISE_OP constant varchar2(50) := \'Revise\';

G_UPDATE_START_PAGE_APP constant varchar2(50) := \'DCN_UPDATE\';

G_UPDATE_START_PAGE constant varchar2(50) := \'UPDATE_START_PAGE\';

G_UPDATE_OP constant varchar2(50) := \'Update\';

G_RETURN_TO_QUERY constant varchar2(50) := \' Return to Query Page \';

G_RETURN_TO_NEW constant varchar2(50) := \' Request DCN-New Drawing \';

G_RETURN_TO_REVISE constant varchar2(50) := \' Request DCN-Revise
Drawing \';

G_RETURN_TO_UPDATE constant varchar2(50) := \' Update Drawing Title \';

G_BACK_TO_MENU constant varchar2(50) := \' Back to Main Menu \';

G_ONLINE_HELP constant varchar2(50) := \'Online Help\';

G_ONLINE_HELP_FILE constant varchar2(50) := \'/dcc-doc/dcn_help.html\';

\--

function is_valid_experiment_pid (i_experiment_id in varchar2,i_pid in
varchar2) return boolean;

\--

procedure view_guidance_page (i_pid in varchar2, i_experiment_id in
varchar2);

\--

procedure start_page (i_pid in varchar2 default \'NEW\');

\--

procedure experiment_approval_page(i_pid in varchar2 default \'NEW\',

i_operation in varchar2 default \'NEW\',

i_experiment_id in number default NULL,

i_access_level in varchar2 default \'USER\');

\--

procedure process_experiment_approval(i_pid in varchar2,

i_experiment_id in varchar2,

i_quantity in xsr0001.val_arr,

i_uom in xsr0001.val_arr,

i_cas_num in xsr0001.val_arr,

i_subject in xsr0001.val_arr,

i_funding in xsr0001.val_arr,

i_spokesperson in xsr0001.val_arr,

i_institution in xsr0001.val_arr,

i_email in xsr0001.val_arr,

i_phone in xsr0001.val_arr,

i_exp_name in xsr0001.val_arr,

i_exp_institution in xsr0001.val_arr,

i_material in xsr0001.val_arr,

i_hazard in xsr0001.val_arr,

i_toxic in xsr0001.val_arr,

i_biohazard in xsr0001.val_arr,

i_flammable in xsr0001.val_arr,

i_radioactive in xsr0001.val_arr,

i_other in xsr0001.val_arr,

i_anldispose in xsr0001.val_arr,

\-- These paramters can be re-named when the gudiance changes

\-- See \$safe/source/utilities/xsr5_guidance_parm.sql for a list

VAR_15_22 in xsr0001.val_arr, \-- Equipment

VAR_64_117 in xsr0001.val_arr, \-- Materials Hazards

VAR_89_154 in xsr0001.val_arr, \-- Special Requirements

\--

i_cat_id in varchar2 default NULL,

i_operation in varchar2 default \'INSERT\',

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_stationa in varchar2 default NULL,

i_stationb in varchar2 default NULL,

i_stationc in varchar2 default NULL,

i_stationd in varchar2 default NULL,

i_statione in varchar2 default NULL,

i_title in varchar2 default NULL,

i_other_equipment in varchar2 default NULL,

i_comments in varchar2 default NULL,

i_access_level in varchar2 default \'USER\',

p_level in varchar2 default NULL,

i_la_flag in varchar2 default NULL,

i_ht_flag in varchar2 default NULL,

i_classified in varchar2 default NULL,

i_other_funding in varchar2 default NULL,

i_report in varchar2 default NULL

);

\--

procedure add_xfd_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2 default null,

i_xfd_name in varchar2 default null,

i_xfd_date in varchar2 default null);

\--

procedure add_user_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2

);

\--

procedure add_cat_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2,

i_cat_id in varchar2,

i_approval in varchar2 default null,

i_pen in varchar2 default null,

i_pen_seq in varchar2 default null,

i_cat_approver in varchar2 default null,

i_cat_approval_date in varchar2 default null,

i_cat_verifier in varchar2 default null,

i_se1 in varchar2 default null,

i_se2 in varchar2 default null,

i_se3 in varchar2 default null,

i_se4 in varchar2 default null,

i_se5 in varchar2 default null,

i_se6 in varchar2 default null,

i_se7 in varchar2 default null,

i_se8 in varchar2 default null,

i_se9 in varchar2 default null

); \--

END;

/

CREATE OR REPLACE PACKAGE BODY xsr0005 IS

/\*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

DATE: INITIALS: REMARKS:

\-\-\-\-- \-\-\-\-\-\-\-\-- \-\-\-\-\-\-\--

10-MAR-98 kem Initial coding

19-MAY-98 kem Modify to accomodate new guidance system

28-OCT-98 kem Add Safety Envelopes (9)

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\*/

\--

\-- GLOBAL NEXT N settings

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \' \> \';

PREV_BUT_CAPTION constant varchar2(100) := \' \< \';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\>\>\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\<\<\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'!\<\<\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\>\>!\';

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 5;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'Maximimum number
of records (\'\|\|to_char(MAX_ROWS)\|\| \') returned\');

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

function badge_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(5);

cursor c_badge(p_pid in varchar2) is

select badge_no

from ows_app_login

where pid=p_pid;

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'?????\';

end if;

close c_badge;

return result;

end;

end;

\--

function username_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(50);

cursor c_username(p_pid in varchar2) is

select username

from ows_app_login

where pid=p_pid;

begin

open c_username(i_pid);

fetch c_username into result;

if c_username%NOTFOUND then

result := \'?????\';

end if;

close c_username;

return result;

end;

end;

\--

function cat_for_this_user(i_pid in varchar2) return number is

begin

declare

result number;

cursor c_cat_id(p_pid in varchar2) is

select cat_id from

xsr5_cat_admin_priv cat, ows_app_login log

where (upper(cat.username)=upper(log.username) OR

upper(cat.username)=upper(log.badge_no))

and cat.inactive is NULL

and log.pid=i_pid;

begin

result := 0;

open c_cat_id(i_pid);

fetch c_cat_id into result;

close c_cat_id;

return(result);

end;

end;

\--

function is_XFD_admin(i_pid in varchar2) return boolean is

begin

declare

cursor c_xfd_role (p_pid in varchar2,p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_ADMIN\'

and log.pid=p_pid;

temp varchar2(1);

result boolean;

l_temp varchar2(2000);

begin

l_temp := owa_fix.get_cgi_env(\'REMOTE_ADDR\');

open c_xfd_role(i_pid,l_temp);

fetch c_xfd_role into temp;

if not c_xfd_role%NOTFOUND then

\--htp.p(\'IS XFD ADMIN\');

result := TRUE;

else

\--htp.p(\'NOT XFD ADMNIN\');

result := FALSE;

end if;

close c_xfd_role;

return(result);

end;

end;

\--

function is_CAT_admin(i_pid in varchar2, i_cat_id in varchar2) return
boolean is

begin

declare

cursor c_cat_admin_role (p_username in varchar2,p_cat in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV

where upper(username)=upper(p_username)

and cat_id=p_cat

and role=\'ADMIN\';

temp varchar2(1);

temp_user GEN_USER_TABLE.USERNAME%TYPE;

result boolean;

begin

temp_user := badge_for_this_pid(i_pid);

open c_cat_admin_role(lower(badge_for_this_pid(i_pid)),i_cat_id);

fetch c_cat_admin_role into temp;

if not c_cat_admin_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_cat_admin_role;

return(result);

end;

end;

\--

function is_CAT_user(i_pid in varchar2,i_experiment_id in varchar2)
return boolean

is

begin

declare

l_cat number;

cursor c_this_cat_user(p_cat_id in number, p_user in varchar2,
p_experiment_id in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV priv, XSR5_EXPERIMENT_HEADER exp

where exp.cat_id=priv.cat_id

and priv.cat_id=p_cat_id

and priv.username=p_user

and exp.experiment_id=p_experiment_id;

temp_user varchar2(50);

temp varchar2(1);

result boolean;

begin

l_cat := cat_for_this_user(i_pid);

temp_user := badge_for_this_pid(i_pid);

\--htp.p(\'TEMP USER IS \' \|\| temp_user);

result := FALSE;

open c_this_cat_user(l_cat,temp_user,i_experiment_id);

fetch c_this_cat_user into temp;

if not c_this_cat_user%NOTFOUND then

result := TRUE;

end if;

close c_this_cat_user;

return(result);

end;

end;

\--

\-- To retrieve information from the gudiance system

function get_haz_values (i_label in varchar2) return VARCHAR2 is

begin

declare

cursor c_material(p_label in varchar2) is

select r_response

from xsr5_rules_header

where upper(label) like \'%\' \|\| upper(p_label) \|\| \'%\'

and r_variable =

(select distinct a_variable

from xsr5_rules_action_detail

where rule_id =

(select distinct rule_id

from xsr5_rules_header

where upper(label) like \'%MATERIAL%HAZARD%\')

);

result varchar2(255);

begin

result := \'\';

open c_material(i_label);

fetch c_material into result;

close c_material;

return(result);

end;

end;

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

PROCEDURE run_print_it (i_experiment_id in varchar2,i_report in
varchar2) IS

return_status varchar2(255);

str varchar2(255);

begin

str := \'safety/safety\';

\--
mis_util.utl_print_it(\'\$mis_reports/\',\'test_coats_email\',\'B\',\'mis3\',\'P\',\'SQR\',STR,\'NONE\',

\--
p_tracking_no,p_resp_group,p_badge_no,\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

mis_util.utl_print_it(\'\$mis_reports/\',
i_report,\'B\',\'mis3\',\'P\',\'SQR\',STR,\'NONE\',

i_experiment_id,\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'XSR0005\';

result := log0002.is_valid_pid(i_pid, p_app_name);

If result then

INSERT INTO WEB_ERROR_LOG VALUES (\'IS VALID PID in XSR0005 is TRUE\');

else

INSERT INTO WEB_ERROR_LOG VALUES (\'IS VALID PID in XSR0005 is FALSE\');

end if;

return result;

end;

end;

\--

function get_approval_status(i_status in varchar2) return varchar2 is

begin

declare

cursor c_approval(p_status in number) is

select STATUS_TEXT

from XSR5_STATUS_TABLE

where approval_status=p_status;

temp XSR5_STATUS_TABLE.STATUS_TEXT%TYPE;

begin

open c_approval(to_number(i_status));

fetch c_approval into temp;

close c_approval;

return(temp);

end;

end;

\--

\--Only allow update mode if request UPDATE and experiment

\--approval is pending

function UPDATE_MODE (i_operation in varchar2,i_experiment_id in
varchar2) return BOOLEAN

is

begin

declare

result boolean;

temp varchar2(1);

cursor c_exp_update(p_exp_id in varchar2) is

select \'1\'

from XSR5_EXPERIMENT_HEADER

where experiment_id=to_number(nvl(p_exp_id,\'0\'))

and approval_status != 1;

begin

result := FALSE;

if i_operation=\'UPDATE\' then

\-- htp.p(\'Experiment id is \' \|\| i_experiment_id);

open c_exp_update(i_experiment_id);

fetch c_exp_update into temp;

if NOT c_exp_update%NOTFOUND then

\-- htp.p(\'update mode is set\');

result := TRUE;

end if;

close c_exp_update;

end if;

return result;

end;

end;

\--

function SE_TITLE (i_envelope_id in number) return VARCHAR2 IS

begin

declare

cursor c_env (p_env in number) is

select TITLE from XSR5_SAFETY_ENVELOPE_TABLE

where envelope_id=p_env;

result varchar2(255);

begin

open c_env(i_envelope_id);

fetch c_env into result;

close c_env;

return (result);

end;

end;

\--

\-- change to display only mode only if status = 1 (0=Pending,
2=Rejected\...same form behaviour)

function DISPLAY_MODE (i_operation in varchar2,i_experiment_id in
varchar2) return BOOLEAN

is

begin

declare

result boolean;

temp varchar2(1);

cursor c_exp_update(p_exp_id in varchar2) is

select \'1\'

from XSR5_EXPERIMENT_HEADER

where experiment_id=to_number(nvl(p_exp_id,\'0\'))

and approval_status = 1;

begin

result := FALSE;

if i_operation=\'UPDATE\' then

\-- htp.p(\'Experiment id is \' \|\| i_experiment_id);

open c_exp_update(i_experiment_id);

fetch c_exp_update into temp;

if NOT c_exp_update%NOTFOUND then

\-- htp.p(\'display mode is set\');

result := TRUE;

end if;

close c_exp_update;

end if;

return result;

end;

end;

\--

function eq_is_checked(i_exp_id in varchar2,i_name in varchar2) return
BOOLEAN is

begin

declare

cursor c_eq_selected (p_exp_id in varchar2,p_name in varchar2) is

select \'1\'

from XSR5_EXTRA_EQUIPMENT

where experiment_id=p_exp_id

and guidance_name=p_name;

temp varchar2(1);

result BOOLEAN;

begin

result := FALSE;

open c_eq_selected(i_exp_id,i_name);

fetch c_eq_selected into temp;

if not c_eq_selected%NOTFOUND then

result := TRUE;

end if;

close c_eq_selected;

return result;

end;

end;

\--

function is_CAT_admin(i_pid in varchar2,i_experiment_id in
varchar2,i_cat_id in number) return boolean

is

begin

declare

cursor c_this_cat_admin(p_cat_id in number,p_badge in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV

where cat_id=p_cat_id

and lower(username)=lower(p_badge);

cursor c_cat_role (p_pid in varchar2, p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_CAT_ADMIN\'

and log.pid=p_pid;

temp_username varchar2(50);

temp varchar2(1);

l_temp varchar2(2000);

result boolean;

begin

temp_username := badge_for_this_pid(i_pid);

result := FALSE;

open c_this_cat_admin(i_cat_id,temp_username);

fetch c_this_cat_admin into temp;

if not c_this_cat_admin%NOTFOUND then

result := TRUE;

\--else

\--htp.p(\'\<FONT size=4 color=#FF0000\>This CAT has not granted you
administrator privileges\</FONT\>\');

end if;

close c_this_cat_admin;

l_temp :=owa_fix.get_cgi_env(\'REMOTE_ADDR\');

if result then

open c_cat_role(i_pid,l_temp);

fetch c_cat_role into temp;

if not c_cat_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

\-- htp.p(\'\<FONT size=4 color=#FF0000\>CAT Admin access is not
available for this session\</FONT\>\');

end if;

close c_cat_role;

end if;

return(result);

end;

end;

\--

\--

function is_valid_experiment_pid (i_experiment_id in varchar2,i_pid in
varchar2) return boolean is

begin

declare

result boolean;

cursor c_cat_id(p_exp_id in varchar2) is

select cat_id

from XSR5_EXPERIMENT_HEADER

where experiment_id=to_number(p_exp_id);

l_cat_id number;

begin

open c_cat_id(i_experiment_id);

fetch c_cat_id into l_cat_id;

close c_cat_id;

result := is_XFD_admin(i_pid) or
is_CAT_admin(i_pid,i_experiment_id,l_cat_id);

return(result);

end;

end;

\--

\-- Checks to see if its a valid PID

\--

procedure start_page (i_pid in varchar2 default \'NEW\') is

\--

begin

INSERT INTO WEB_ERROR_LOG values (\'Entering XSR0005.start_page PID=\'
\|\| i_pid);

if i_pid is NULL or

i_pid = \'NEW\' or

NOT log0002.is_valid_pid (i_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',i_pid,NULL,\'N\');

INSERT INTO WEB_ERROR_LOG VALUES(\'would be returning from xsr0005
start_page\');

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\-- REDIRECT TO INTERMEDIATE PAGE

INSERT INTO WEB_ERROR_LOG values (\'Calling experiment approval page\');

experiment_approval_page(i_pid);

\--

end;

\--

\-- Checks to see if its a valid PID

\--

procedure new_experiment_page (i_pid in varchar2 default \'NEW\') is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid);

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\-- REDIRECT TO INTERMEDIATE PAGE

experiment_approval_page(m_pid);

\--

end;

\--

function subject_name(i_subject_id in number) return varchar2 is

begin

declare

cursor c_subject_name (p_subj_id in number) is

select subject

from XSR5_SUBJECT_TABLE

where subject_id=p_subj_id;

result varchar2(50);

begin

open c_subject_name(i_subject_id);

fetch c_subject_name into result;

close c_subject_name;

return result;

end;

end;

\--

function funding_source(i_funding_id in number) return varchar2 is

begin

declare

cursor c_funding_source (p_fund_id in number) is

select funding_source

from XSR5_FUNDING_TABLE

where funding_id=p_fund_id;

result varchar2(255);

begin

open c_funding_source(i_funding_id);

fetch c_funding_source into result;

close c_funding_source;

return result;

htp.p(\'FUNCTION OK\');

end;

end;

\--

procedure experiment_approval_page(i_pid in varchar2 default \'NEW\',

i_operation in varchar2 default \'NEW\',

i_experiment_id in number default NULL,

i_access_level in varchar2 default \'USER\')

is

\--

i number;

xfd_comment_count number;

\--

\--the following cursor is used to retrieve information from the
guidance system

\-- to initialize VAR_START array

cursor c_init_VAR_START is

select a.r_response

from xsr5_rules_header a,

xsr5_rules_action_detail b

where a.rule_id = b.rule_id

and a.r_variable = \'VAR_START\';

cursor c_existing_experiment(p_experiment_id number) is

select \*

from xsr5_experiment_header

where experiment_id = p_experiment_id;

\--

cursor c_subject_lookup is

select \*

from xsr5_subject_table;

\--

cursor c_spokespersons(p_experiment_id in number) is

select \*

from xsr5_spokespersons

where experiment_id=p_experiment_id

and priority \> 1;

\--

cursor c_primary_spokesperson(p_experiment_id in number) is

select \*

from xsr5_spokespersons

where experiment_id=p_experiment_id

and priority=1;

\--

cursor c_experimenters(p_experiment_id in number) is

select \*

from xsr5_experimenters

where experiment_id=p_experiment_id;

\--

cursor c_materials(p_experiment_id in number) is

select \*

from xsr5_materials

where experiment_id=p_experiment_id;

\--

cursor c_subject_areas(p_experiment_id in varchar2,p_subject_id in
number) is

select \'1\'

from XSR5_SUBJECT_AREAS

where experiment_id=to_number(p_experiment_id)

and subject_id=p_subject_id;

\--

cursor c_exp_funding_sources (p_experiment_id in varchar2) is

select \*

from XSR5_FUNDING_SOURCES

where experiment_id=to_number(p_experiment_id);

\--

cursor c_exp_subject_areas(p_experiment_id in varchar2) is

select \*

from XSR5_SUBJECT_AREAS

where experiment_id=to_number(p_experiment_id);

\--

cursor c_funding_sources(p_experiment_id in varchar2,p_funding_id in
number) is

select \'1\'

from XSR5_FUNDING_SOURCES

where experiment_id=to_number(p_experiment_id)

and funding_id=p_funding_id;

\--

cursor c_funding_lookup is

select \*

from XSR5_FUNDING_TABLE;

\--

cursor c_extra_eq_type is

select \*

from XSR5_EXTRA_EQUIPMENT_TABLE;

\--

cursor c_extra_equipment(p_exp_id in varchar2,p_value in varchar2) is

select rep.\*

from XSR5_RESPONSE_DETAIL rep, XSR5_TRANSACTION_DETAIL trans

where rep.R_VALUE=trans.TX_RESPONSE

and TX_LEVEL=2

and trans.PID=p_exp_id

and nvl(trans.inactive,\'N\')=\'N\'

and r_value = p_value;

\--

cursor c_user_comments (p_experiment_id in varchar2) is

select \*

from XSR5_USER_COMMENTS

where experiment_id=to_number(p_experiment_id)

order by comment_seq_id;

\--

cursor c_xfd_comments (p_experiment_id in varchar2) is

select \*

from XSR5_XFD_COMMENTS

where experiment_id=to_number(p_experiment_id);

\--

cursor c_cat_comments (p_experiment_id in varchar2) is

select \*

from XSR5_CAT_COMMENTS

where experiment_id=to_number(p_experiment_id);

\--

cursor c_cat_id (p_experiment_id in varchar2) is

select cat_id

from XSR5_EXPERIMENT_HEADER

where experiment_id=p_experiment_id;

\--

cursor c_approval is

select \*

from XSR5_STATUS_TABLE;

\--

cursor c_xfd_comment_count(p_experiment_id in varchar2) is

select count(experiment_id)

from xsr5_xfd_comments

where experiment_id=p_experiment_id;

\--

cursor c_cat_for_sector(p_sector_no in varchar2) is

select cat_name

from XSR5_CAT_TABLE c, XSR5_CAT_SECTOR_XREF x

where c.cat_id=x.cat_id

and x.sector_no=lpad(p_sector_no,2,\'0\');

\--

r_primary XSR5_SPOKESPERSONS%ROWTYPE;

r_experiment XSR5_EXPERIMENT_HEADER%ROWTYPE;

l_update_mode boolean;

l_selected boolean;

l_display_only boolean;

l_cat_id number;

\--

p_level number;

p_block_id varchar2(100);

p_value varchar2(100);

\--

l_sector_cat xsr5_cat_table.CAT_NAME%TYPE;

l_no_cat_in_sector BOOLEAN;

\--

temp varchar2(255);

counter number;

xfd_admin boolean;

cat_admin boolean;

read_only boolean;

no_changes boolean;

l_pen varchar2(128);

l_experiment_id number;

VAR_START xsr0001.val_arr;

temp2 varchar2(255);

i_prompt_count number := 0;

i_guidance_count number := 0;

browser_type varchar2(255);

ctr number(2);

\--

begin

if is_valid_pid(i_pid) then

\--initialize flags

cat_admin := FALSE;

xfd_admin := FALSE;

read_only := FALSE;

l_display_only := FALSE;

\--set defaults for UPDATE_MODE

l_update_mode := UPDATE_MODE(i_operation,i_experiment_id);

if l_update_mode then

open c_existing_experiment(i_experiment_id);

fetch c_existing_experiment into r_experiment;

close c_existing_experiment;

else

l_display_only := DISPLAY_MODE(i_operation,i_experiment_id);

open c_existing_experiment(i_experiment_id);

fetch c_existing_experiment into r_experiment;

close c_existing_experiment;

l_update_mode := l_display_only;

end if;

\--if i_pid is not null then

\-- if (is_valid_pid(i_pid) then

xfd_admin := is_XFD_admin(i_pid);

open c_cat_id(i_experiment_id);

fetch c_cat_id into l_cat_id;

close c_cat_id;

\--if there is data, ensure only the proper cat user can see it

\--htp.p(\'i_acces_level=\' \|\| i_access_level);

if not xfd_admin and i_experiment_id IS NOT NULL and i_access_level
!=\'USER ENTERING NEW DATA\' then

if NOT is_cat_user(i_pid,i_experiment_id)then

htp.p(\'Sorry. This experiment is not visible to this account.\');

return;

end if;

end if;

\--

\-- change to positive check for approved status

if nvl(r_experiment.approval_status,0) = 1 then

no_changes := TRUE;

else

no_changes := FALSE;

end if;

\--

cat_admin := is_CAT_admin(i_pid,i_experiment_id,l_cat_id);

read_only := l_display_only OR xfd_admin or (cat_admin AND no_changes);

\--Javascript begin

htp.p(\'\<SCRIPT LANGUAGE=Javascript\>\');

htp.p(\'// BOI, followed by one or more digits, followed by EOI.

var reInteger = /\^\\d+\$/;

var reSignedInteger = /\^\\d+\$/;

//var reSignedInteger = /\^(+\|-)\\d+\$/;

//var reSignedInteger = /\^?\\d+\$/;

var daysInMonth = makeArray(12);

daysInMonth\[1\] = 31;

daysInMonth\[2\] = 29; // must programmatically check this

daysInMonth\[3\] = 31;

daysInMonth\[4\] = 30;

daysInMonth\[5\] = 31;

daysInMonth\[6\] = 30;

daysInMonth\[7\] = 31;

daysInMonth\[8\] = 31;

daysInMonth\[9\] = 30;

daysInMonth\[10\] = 31;

daysInMonth\[11\] = 30;

daysInMonth\[12\] = 31;

var monthDelimiter = \"\|\";

var
monthArray=\"JAN\|FEB\|MAR\|APR\|MAY\|JUN\|JUL\|AUG\|SEP\|OCT\|NOV\|DEC\";

\');

htp.p(\' function checkdate(item){

//allow empty dates if both empty

if (isEmpty(item.value)) return true;

//

if (!isOracleDate(item.value)){

alert (\"Not a valid date. Please use format: DD-MON-YYYY (e.g.
02-APR-2000)\");

return false;}

return true;}

// Check whether string s is empty.

function isEmpty(s)

{ return ((s == null) \|\| (s.length == 0))

}

function checkform(form) {

//check title

if (isEmpty(form.i_title.value)) {

alert(\"Please provide a TITLE for the experiment\");

return false;

}

if (isEmpty(form.i_spokesperson\[1\].value) \|\|

isEmpty(form.i_institution\[1\].value) \|\|

isEmpty(form.i_phone\[1\].value) \|\|

isEmpty(form.i_email\[1\].value)) {

alert(\"Please include complete information (Name, Institution, Phone
number, Email) for at least one spokesperson\");

return false;

}

return true;

//check spokespseron, institute, email phone

}

//

// Date validation code\...portions adapted from netscape site

// isOracleDate - original code

function isOracleDate(oracle_date) {

day=oracle_date.substring(0,2);

month=oracle_date.substring(3,6);

monthUpper=month.toUpperCase();

monthVal=monthArray.indexOf(monthUpper);

month_number=parseInt(monthVal,10) / 4 + 1;

year=oracle_date.substring(7,11);

dash1=oracle_date.substring(2,3);

dash2=oracle_date.substring(6,7);

day1=oracle_date.substring(0,1);

day2=oracle_date.substring(1,2);

//alert (\"Day1 is \");

//alert (day1);

//alert (\"day2 is \");

//alert (day2);

//check for dashes

if (dash1!=\"-\") return false;

if (dash2!=\"-\") return false;

if (!isYear(year)){

alert(\"Not a valid year.\");

return false;}

if (!isDay(day) \|\| !isDigit(day1) \|\| !isDigit(day2)) {

alert(\"Not a valid day\");

return false;}

if (!isMonth(month_number)){

alert(\"Not a valid month\");

return false;}

var intYear = parseInt(year,10);

var intMonth = month_number;

var intDay = parseInt(day,10);

// catch invalid days, except for February

if (intDay \> daysInMonth\[intMonth\]) return false;

if ((intMonth == 2) && (intDay \> daysInFebruary(intYear))) return
false;

return true;

}

//

function daysInFebruary (year)

{// February has 29 days in any year evenly divisible by four,

// EXCEPT for centurial years which are not also divisible by 400.

return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) \|\| (year % 400 ==
0) ) ) ? 29 : 28 );

}

//

function isInteger(s) {

return reSignedInteger.test(s);

};

//

function isDigit(s){

return ( s\>=0 && s\<=9 );

}

//

function isIntegerInRange(s,a,b){

var num = parseInt (s,10);

return ((num \>= a) && (num \<= b));}

//

function isYear(year){

if (!isInteger(year)) return false;

return (year.length == 4);}

//

function isMonth(month){

return isIntegerInRange (month, 1, 12);}

//

function isDay(day){

return isIntegerInRange(day,1,31);}

//

function makeArray(n) {

for (var i = 1; i \<= n; i++) {

this\[i\] = 0 }

return this

}

\');

htp.p(\'\</SCRIPT\>\');

\--End Javascript

if i_experiment_id is null then

select XSR5_EXPERIMENT_SEQ.NextVal into l_experiment_id from dual;

else

l_experiment_id := i_experiment_id;

end if;

\--get xfd comment count

open c_xfd_comment_count(l_experiment_id);

fetch c_xfd_comment_count into xfd_comment_count;

close c_xfd_comment_count;

\--get PEN number if available

l_pen := nvl(r_experiment.PEN,\'\');

if l_pen is not null then

l_pen := \' - PEN# \' \|\| l_pen;

end if;

lib.prolog(\'APS User Experiment Safety Approval Form \' \|\|
l_pen,NULL,\'#FFFFFF\');

\--determine instruction line for multi-select

browser_type := upper(owa_fix.get_cgi_env(\'HTTP_USER_AGENT\'));

if instr(browser_type,\'WIN\') \> 0 then

browser_type:=\'To select multiple items, hold the control key and click
on selection.\';

elsif instr(browser_type,\'MAC\') \> 0 then

browser_type:=\'To select multiple items, hold the command key and click
on selection.\';

\-- assume non windows, non-mac = UNIX flavor. Many diff
HTTP_USER_AGENTs kem 6/3/99

else \--elsif instr(browser_type,\'SUN\') \> 0 then

browser_type :=\'To select multiple items, click on each selection.\';

\-- else

\-- browser_type :=\'\';

end if;

/\*if l_display_only then

htp.p(\'\<FONT FACE=ARIAL,HELVETICA COLOR=#FF0000 SIZE=4\>This
experiment has been approved, therefore the information may not be
changed.\</FONT\>\');

end if;\*/

if xfd_admin then

htp.p(\'\<FONT FACE=ARIAL,HELVETICA COLOR=#FF0000 SIZE=4\>This page is
READ ONLY, however comments may be added in the XFD Oversight

Comments section.\</FONT\>\');

end if;

/\*If cat_admin then

htp.p(\'CAT ADMIN = TRUE\');

else

htp.p(\'CAT ADMIN = FALSE\');

end if;\*/

if cat_admin then

if not no_changes then

htp.p(\'\<FONT FACE=ARIAL,HELVETICA COLOR=#FF0000 SIZE=4\>Changes may be
made until the status is approved.\</FONT\>\');

else

htp.p(\'\<FONT FACE=ARIAL,HELVETICA COLOR=#FF0000 SIZE=4\>This page is
READ ONLY, no changes may be made as it has already been
approved.\</FONT\>\');

end if;

end if;

htp.p(\'\<HR\>\');

htp.p(\'\<ALIGN=CENTER\>\');

htp.p(\'\<FONT size=\"3\"\>\');

htp.p(\'\<B\>NOTES: No experiment will be allowed to run until a
properly completed \'\|\|

\' and approved experiment safety form has been posted by an APS Floor
\'\|\|

\' Coordinator. Approval is valid for a maximum of six months from the
\'\|\|

\' CAT approval date.\</B\>\');

htp.p(\'\</FONT\>\');

htp.p(\'\<HR\>\');

\--Actually validate role based on pid \... not anything else

if not read_only then

\--htp.formOpen(\'xsr0005.process_experiment_approval\');

htp.p(\'\<FORM ACTION=\"xsr0005.process_experiment_approval\"
METHOD=\"POST\" onSubmit=\"return checkform(this)\"\>\');

end if;

htp.p(\'\<TABLE WIDTH=700\>\');

\--

htp.p(\'\<TR\>\');

htp.p(\'\<TD ALIGN=\"center\"\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Sector\</B\>\</FONT\>\</TD\>\');

htp.p(\'\<TD ALIGN=\"center\"\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Beamline\</B\>\</FONT\>\</TD\>\');

htp.p(\'\<TD ALIGN=\"center\"\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Station\</B\>\</FONT\>\</TD\>\');

htp.p(\'\<TD ALIGN=\"center\"\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Date Submitted\</B\>\</FONT\>\</TD\>\');

htp.p(\'\<TD\>\</TD\>\');

htp.p(\'\<TD ALIGN=\"center\" colspan=4\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Classified work will be
performed\</B\>\</FONT\>\</TD\>\');

htp.p(\'\</TR\>\');

\--

htp.p(\'\<TR\>\');

htp.p(\'\<TD ALIGN=Center\>\');

\--

if not read_only then

htp.formSelectOpen(\'i_sector\');

\--

i:=1;

while (i \<= 35) loop

if (i != 10 and i != 33 and i != 34) then

open c_cat_for_sector(i);

fetch c_cat_for_sector into l_sector_cat;

if c_cat_for_sector%NOTFOUND then

l_sector_cat:=\'NO CAT\';

end if;

close c_cat_for_sector;

\-- BLANK CATS don\'t show

if l_sector_cat !=\'NO CAT\' then

if (to_char(i,\'09\')=to_char(nvl(r_experiment.sector_no,0),\'09\'))
then

htp.formSelectOption(to_char(i,\'09\') \|\| \' - \' \|\|
l_sector_cat,\'SELECTED\',\'VALUE=\' \|\| to_char(i,\'09\'));

else

htp.formSelectOption(to_char(i,\'09\') \|\| \' - \' \|\|
l_sector_cat,\'\',\'VALUE=\' \|\| to_char(i,\'09\'));

end if;

end if;

end if; \--if i != 10

i := i + 1;

end loop;

htp.formSelectClose;

else

open c_cat_for_sector(r_experiment.sector_no);

fetch c_cat_for_sector into l_sector_cat;

close c_cat_for_sector;

htp.p(r_experiment.sector_no \|\| \' - \' \|\| l_sector_cat);

end if;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD ALIGN=Center\>\');

\--end if;

if not read_only then

htp.formSelectOpen(\'i_beamline\');

if r_experiment.beamline=\'BM\' then

htp.formSelectOption(\'BM\',\'SELECTED\');

htp.formSelectOption(\'ID\');

elsif r_experiment.beamline=\'ID\' then

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\',\'SELECTED\');

else

htp.formSelectOption(\'\');

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\');

end if;

htp.formSelectClose;

else

htp.p(r_experiment.beamline);

end if;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD ALIGN=CENTER WIDTH=200\>\');

\--

if not read_only then

if r_experiment.station_A=\'Y\' then

htp.formCheckBox(\'i_stationa\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_stationa\',\'Y\');

end if;

\--

htp.p(\'\<B\>A &nbsp\');

\--

if r_experiment.station_b=\'Y\' then

htp.formCheckBox(\'i_stationb\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_stationb\',\'Y\');

end if;

\--

htp.p(\'B &nbsp\');

\--

if r_experiment.station_c=\'Y\' then

htp.formCheckBox(\'i_stationc\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_stationc\',\'Y\');

end if;

\--

htp.p(\'C &nbsp\');

\--force a break so next letter and box are not split between two lines

htp.NL;

\--

if r_experiment.station_d=\'Y\' then

htp.formCheckBox(\'i_stationd\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_stationd\',\'Y\');

end if;

\--

\--

htp.p(\'D &nbsp\');

\--

if r_experiment.station_e=\'Y\' then

htp.formCheckBox(\'i_statione\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_statione\',\'Y\');

end if;

\--

htp.p(\'E\</B\>\');

else

\-- read only

if r_experiment.station_a=\'Y\' then

htp.bold(\'A \');

end if;

if r_experiment.station_b=\'Y\' then

htp.bold(\'B \');

end if;

if r_experiment.station_c=\'Y\' then

htp.bold(\'C \');

end if;

if r_experiment.station_d=\'Y\' then

htp.bold(\'D \');

end if;

if r_experiment.station_e=\'Y\' then

htp.bold(\'E \');

end if;

\--end if read only paragraph

end if;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD ALIGN=CENTER\>\');

if l_update_mode then

htp.p(to_char(r_experiment.timestamp,\'DD-MON-YYYY\'));

else

htp.p(to_char(sysdate,\'DD-MON-YYYY\'));

end if;

htp.p(\'\</TD\>\<TD\>\</TD\>\');

\--

\--htp.p(\'\<TD\>\</TD\>\<TD\>\</TD\>\<TD\>\</TD\>\<TD colspan=2\>\');

\--

htp.p(\'\<TD ALIGN=center\>\');

if not read_only then

htp.formSelectOpen(\'i_classified\');

if r_experiment.classified=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

else

if r_experiment.classified=\'Y\' then

htp.p(\'Yes\');

else

htp.p(\'No\');

end if;

end if;

htp.p(\'\</TD\>\</TR\>\');

\--

htp.tableClose;

\--

htp.p(\'\<TABLE\>\<TR\>\<TD WIDTH=35%\>\');

if not read_only then

htp.p(\'\<FONT size=\"3\" color=#008000\>\<B\>Experiment
title:\<SUP\>\*\</SUP\>\</B\>\</FONT\>\</TD\>\');

else

htp.p(\'\<FONT size=\"3\" color=#008000\>\<B\>Experiment
title:\</B\>\</FONT\>\</TD\>\');

end if;

htp.p(\'\<TD\>\<font size=3 color=#008000\>\<B\>Subject area(s) of
experiment:\</B\>\</font\>\</TD\>\');

htp.p(\'\<TD\>\<font size=3 color=#008000\>\<B\>Funding
source(s):\</B\>\</font\>\</TD\>\');

htp.p(\'\</TR\>\<TR\>\<TD\>\');

if not read_only then

\--htp.p(\'\<P\>\<FONTsize=\"3\"\>\<TEXTAREA NAME=\"i_title\" ROWS=3
COLS=35\>\');

htp.formTextareaOpen( cname =\> \'i_title\', nrows =\> \'3\', ncolumns
=\> \'35\', cattributes =\> \' WRAP=\"VIRTUAL\"\');

if l_update_mode then

htp.p(r_experiment.experiment_title);

end if;

htp.p(\'\</TEXTAREA\>\</FONT\>\');

null;

else

htp.p(r_experiment.experiment_title);

end if;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD\>\');

if not read_only then

htp.formHidden(\'i_subject\',\'N/A\');

htp.formSelectOpen(\'i_subject\',\'\',\'5\',\'MULTIPLE\');

for r_subject in c_subject_lookup loop

l_selected := FALSE;

if l_update_mode then

\--

open c_subject_areas(i_experiment_id,r_subject.subject_id);

fetch c_subject_areas into temp;

if not c_subject_areas%NOTFOUND then

htp.formSelectOption(r_subject.subject,\'SELECTED\',\'VALUE=\' \|\|
to_char(r_subject.subject_id));

l_selected := TRUE;

end if;

close c_subject_areas;

end if;

\--

if not l_selected then

htp.formSelectOption(r_subject.subject,\'\',\'VALUE=\' \|\|
to_char(r_subject.subject_id));

end if;

\--

end loop;

htp.formSelectClose;

else

\--read only

htp.p(\'\<TABLE\>\');

for r_subject_name in c_exp_subject_areas(i_experiment_id) loop

htp.p(\'\<TR\>\<TD\>\');

htp.p(subject_name(r_subject_name.subject_id));

htp.p(\'\</TD\>\</TR\>\');

end loop;

htp.p(\'\</TABLE\>\');

end if;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD\>\');

if not read_only then

htp.formHidden(\'i_funding\',\'N/A\');

htp.formSelectOpen(\'i_funding\',\'\',\'5\',\'MULTIPLE\');

for r_funding in c_funding_lookup loop

l_selected := FALSE;

if l_update_mode then

\--

open c_funding_sources(i_experiment_id,r_funding.funding_id);

fetch c_funding_sources into temp;

if not c_funding_sources%NOTFOUND then

htp.formSelectOption(r_funding.funding_source,\'SELECTED\',\'VALUE=\'
\|\| to_char(r_funding.funding_id));

l_selected := TRUE;

end if;

close c_funding_sources;

end if;

\--

if not l_selected then

htp.formSelectOption(r_funding.funding_source,\'\',\'VALUE=\' \|\|
to_char(r_funding.funding_id));

end if;

\--

end loop;

htp.formSelectClose;

else

\--read only

htp.p(\'\<TABLE\>\');

for r_funding_source in c_exp_funding_sources(i_experiment_id) loop

htp.p(\'\<TR\>\<TD\>\');

htp.p(funding_source(r_funding_source.funding_id));

htp.p(\'\</TD\>\</TR\>\');

end loop;

htp.p(\'\</TABLE\>\');

end if;

htp.p(\'\</TD\>\</TR\>\<TR\>\');

\--instructions for multi-select

if not read_only then

htp.p(\'\<TD\>\</TD\>\<TD COLSPAN=2\>\');

htp.p(browser_type);

htp.p(\'\</TD\>\</TR\>\<TR\>\');

end if;

\--other funding sources

htp.p(\'\<TD\>\</TD\>\');

htp.tableData(\'\<FONT color=\"#008000\" size=\"3\"\>\<B\>Specify
funding sources (if necessary):\</B\>\</FONT\>\');

if not read_only then

htp.tableData(htf.formText(\'i_other_funding\',25,255,r_experiment.other_funding));

else

htp.tableData(r_experiment.other_funding);

end if;

htp.p(\'\</TR\>\</TABLE\>\');

\--

htp.tableOpen(\'WIDTH=600\');

htp.tableRowOpen;

htp.tableData(\'\<FONT color=\"#008000\" size=\"3\"\>\<B\>Experiment
spokesperson:\</B\>\<SUP\> \*\*\</SUP\>\</FONT\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>Name\</I\>\</B\>\</FONT\>\');

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>Institution\</I\>\</B\>\</FONT\>\');

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>E-mail\</I\>\</B\>\</FONT\>\</TD\>\');

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>Phone\</I\>\</B\>\</FONT\>\</TD\>\');

htp.tableRowClose;

\--

open c_primary_spokesperson(i_experiment_id);

fetch c_primary_spokesperson into r_primary;

close c_primary_spokesperson;

\--

if not read_only then

\--

htp.formHidden(\'i_spokesperson\',\'N/A\');

htp.formHidden(\'i_institution\',\'N/A\');

htp.formHidden(\'i_email\',\'N/A\');

htp.formHidden(\'i_phone\',\'N/A\');

\--

if l_update_mode then

\--

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_spokesperson\',20,30,r_primary.name) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_institution\',25,40,r_primary.institution) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_email\',25,40,r_primary.email) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_phone\',20,30,r_primary.phone) \|\| \'\</FONT\>\');

htp.tableRowClose;

else

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_spokesperson\',20,30) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_institution\',25,40) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_email\',25,40) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_phone\',20,30) \|\| \'\</FONT\>\');

htp.tableRowClose;

\--

end if;

else

\--read only primary spokesperson

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_primary.name \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_primary.institution \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_primary.email \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_primary.phone \|\|
\'\</FONT\>\');

htp.tableRowClose;

\--

end if;

/\* \-- disable addtional spokesperson per B Glagola 5/21/99

\-- still allows multiple views if already entered, but new experiments
get only one spokesperson.

htp.tableRowOpen;

htp.tableData(\'\<FONT color=\"#008000\" size=\"3\"\>\<B\>Alternate
spokespersons:\</B\>\</FONT\>\');

htp.tableRowClose;

\--

if not read_only then

for r_spokespersons in c_spokespersons(i_experiment_id) loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_spokesperson\',20,30,r_spokespersons.name) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_institution\',25,40,r_spokespersons.institution) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_email\',25,40,r_spokespersons.email) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_phone\',20,30,r_spokespersons.phone) \|\|
\'\</FONT\>\');

htp.tableRowClose;

end loop;

\--

i := 1;

while i \<=2 loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_spokesperson\',20,30) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_institution\',25,40) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_email\',25,40) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_phone\',20,30) \|\| \'\</FONT\>\');

htp.tableRowClose;

i:=i+1;

end loop;

\--

htp.tableClose;

if not xfd_admin and not cat_admin then

htp.formSubmit(\'i_operation\',\'List Additional Spokespersons\');

end if;

else

\*/

if read_only then

\--read only for Additional spokespersons

for r_spokespersons in c_spokespersons(i_experiment_id) loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_spokespersons.name \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_spokespersons.institution
\|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_spokespersons.email \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_spokespersons.phone \|\|
\'\</FONT\>\');

htp.tableRowClose;

end loop;

end if;

htp.tableClose;

\--

if not read_only then

htp.NL;

htp.p(\'\<P\>\<FONT SIZE=3 COLOR=#008000\>\<SUP\>\*\</SUP\> Required
field\');

\--htp.NL;

\--htp.p(\'\<SUP\>\*\*\</SUP\> Complete information required for at
least one spokesperson\</FONT\>\</P\>\');

end if;

htp.p(\'\<HR\>\');

htp.p(\'\<BR\>\');

\--

htp.p(\'\<FONT color=\"#008000\" size=\"3\"\>\<B\>List all other
experimenters (names and institutions) working at the
APS:\</B\>\</FONT\>\');

htp.tableOpen(\'WIDTH=400\');

\--htp.tableRowOpen;

\--htp.tableData(htf.NL);

\--htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>Name\</I\>\</B\>\</FONT\>\');

htp.tableData(\'\<FONT
size=\"3\"\>\<B\>\<I\>Institution\</I\>\</B\>\</FONT\>\');

htp.tableRowClose;

\--

if not read_only then

htp.formHidden(\'i_exp_name\',\'N/A\');

htp.formHidden(\'i_exp_institution\',\'N/A\');

\--

for r_experimenters in c_experimenters(i_experiment_id) loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_exp_name\',20,30,r_experimenters.name) \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_exp_institution\',25,40,r_experimenters.institution)
\|\| \'\</FONT\>\');

htp.tableRowClose;

end loop;

\--

i := 1;

while i \<=4 loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_exp_name\',20,30) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_exp_institution\',25,40) \|\| \'\</FONT\>\');

htp.tableRowClose;

i:=i+1;

end loop;

\--

htp.tableClose;

if not xfd_admin and not cat_admin then

htp.formSubmit(\'i_operation\',\'List Additional Experimenters\');

end if;

else

\--read only for experimenters

for r_experimenters in c_experimenters(i_experiment_id) loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_experimenters.name \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| r_experimenters.institution
\|\| \'\</FONT\>\');

htp.tableRowClose;

end loop;

htp.tableClose;

end if;

\--

htp.p(\'\<HR\>\');

htp.p(\'\<BR\>\');

\--

htp.p(\'\<H2\>\<FONT color=\"#008000\" size=\"3\"\>List samples and
chemicals to be used. Check appropriate boxes regarding known hazards
(Click hazard type for definition):\</FONT\>\</H2\>\');

htp.p(\'\<TABLE border=\"1\"\>\');

htp.p(\'\<TR\>\');

htp.p(\'\<TH ROWSPAN=\"2\" width=\"180\" cellpadding=\"5\"\>\<FONT
size=\"3\"\>Name of material\</FONT\>\</TH\>\');

htp.p(\'\<TH ROWSPAN=\"2\" width=\"80\" cellpadding=\"5\"\>\<FONT
size=\"3\"\>Quantity\</FONT\>\</TH\>\');

htp.p(\'\<TH ROWSPAN=\"2\" width=\"50\" cellpadding=\"5\"\>\<FONT
size=\"3\"\>CAS #\</FONT\>\</TH\>\');

htp.p(\'\<TH COLSPAN=\"5\"\>\<FONT size=\"3\"\>Known
Hazards\</FONT\>\</TH\>\');

htp.p(\'\<TH ROWSPAN=\"2\" width=\"92\" cellpadding=\"2\"\>\<FONT
size=\"3\"\>Dispose at ANL\<SUP\>2\</SUP\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\</TR\>\');

htp.p(\'\<TR\>\');

htp.p(\'\<TH width=\"32\"\>\<FONT size=\"3\"\>\<A
HREF=\"../../gen-doc/xfd_hazard.html\"\>toxic\</A\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\<TH width=\"68\"\>\<FONT size=\"3\"\>\<A
HREF=\"../../gen-doc/xfd_hazard.html\"\>bio-hazard\</A\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\<TH width=\"68\"\>\<FONT size=\"3\"\>\<A
HREF=\"../../gen-doc/xfd_hazard.html\"\>flammable\</A\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\<TH width=\"68\"\>\<FONT size=\"3\"\>\<A
HREF=\"../../gen-doc/xfd_hazard.html\"\>radioactive\</A\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\<TH width=\"38\"\>\<FONT size=\"3\"\>\<A
HREF=\"../../gen-doc/xfd_hazard.html\"\>other\<SUP\>1\</SUP\>\</A\>\<BR\>Y/N\</FONT\>\</TH\>\');

htp.p(\'\</TR\>\');

\--

if not read_only then

htp.formHidden(\'i_material\',\'N/A\');

htp.formHidden(\'i_hazard\',\'N/A\');

htp.formHidden(\'i_toxic\',\'N/A\');

htp.formHidden(\'i_biohazard\',\'N/A\');

htp.formHidden(\'i_flammable\',\'N/A\');

htp.formHidden(\'i_radioactive\',\'N/A\');

htp.formHidden(\'i_other\',\'N/A\');

htp.formHidden(\'i_anldispose\',\'N/A\');

htp.formHidden(\'i_quantity\',\'N/A\');

htp.formHidden(\'i_uom\',\'N/A\');

htp.formHidden(\'i_cas_num\',\'N/A\');

\--

for r_materials in c_materials(i_experiment_id) loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_material\',20,35,r_materials.material) \|\|
\'\</FONT\>\');

\--uom is concatenated qty + uom .. table header=quantity

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_uom\',12,25,r_materials.uom) \|\| \'\</FONT\>\');

\--htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_uom\',7,25,r_materials.uom) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_cas_num\',8,10,r_materials.ref_id) \|\| \'\</FONT\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_toxic\');

if r_materials.toxic=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_biohazard\');

if r_materials.biohazard=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_flammable\');

if r_materials.flammable=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_radioactive\');

if r_materials.radioactive=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_other\');

if r_materials.other=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_anldispose\');

if r_materials.anl_dispose=\'Y\' then

htp.formSelectOption(\'Y\',\'\',\'SELECTED\');

htp.formSelectOption(\'N\');

else

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.tableRowClose;

\--

end loop;

\--

i := 1;

while i \<=4 loop

htp.tableRowOpen;

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_material\',20,35) \|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\| htf.formText(\'i_uom\',12,25)
\|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=\"3\"\>\' \|\|
htf.formText(\'i_cas_num\',8,10) \|\| \'\</FONT\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_toxic\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_biohazard\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_flammable\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_radioactive\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_other\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.p(\'\<TD align=center\>\');

htp.formSelectOpen(\'i_anldispose\');

htp.formSelectOption(\'Y\');

htp.formSelectOption(\'N\',\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

\--

htp.tableRowClose;

i:=i+1;

\--

end loop;

\--

htp.tableClose;

\--

htp.NL;

if not xfd_admin and not cat_admin then

htp.formSubmit(\'i_operation\',\'List Additional Materials\');

end if;

htp.NL;

else

\--read only section for materials list

for r_materials in c_materials(i_experiment_id) loop

\--

htp.tableRowOpen;

htp.tableData(\'\<FONT size=3\>\' \|\| r_materials.material \|\|
\'\</FONT\>\');

\--htp.tableData(\'\<FONT size=3\>\' \|\| to_char(r_materials.quantity)
\|\| \'\</FONT\>\');

htp.tableData(\'\<FONT size=3\>\' \|\| r_materials.uom \|\|
\'\</FONT\>\');

htp.tableData(\'\<FONT size=3\>\' \|\| r_materials.ref_id \|\|
\'\</FONT\>\');

\--htp.p(\'\<TD align=center\>\' \|\| r_materials.hazardous \|\|
\'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.toxic \|\| \'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.biohazard \|\|
\'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.flammable \|\|
\'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.radioactive \|\|
\'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.other \|\| \'\</TD\>\');

htp.p(\'\<TD align=center\>\' \|\| r_materials.anl_dispose \|\|
\'\</TD\>\');

htp.tableRowClose;

\--

end loop;

\--

htp.tableClose;

end if;

\--

htp.p(\'\<H3\>\<FONT size=\"3\"\>Notes:\</FONT\>\</H3\>\');

htp.p(\'\<P\>\<FONT size=\"3\"\>\<B\>\');

htp.p(\'\<SUP\>1\</SUP\> Describe other known hazards in User comment
section.\<BR\>\');

htp.p(\'\<SUP\>2\</SUP\> Check if you plan to dispose of the material at
ANL, either as waste or as effluent, at the end of the experiment.\');

htp.p(\'\</B\>\</FONT\>\<BR\>\');

\--

htp.p(\'\<P\>\');

if not read_only then

\-- the linkgs to the dynamically gnerated guidance section

ctr := 1;

p_level := 1;

for r_init_VAR_START in c_init_VAR_START loop

VAR_START(ctr) := r_init_VAR_START.r_response;

ctr := ctr + 1;

end loop;

xsr0002.exp_sub_display(l_experiment_id,p_level,VAR_START);

end if;

\--

if ((cat_admin AND no_changes) or xfd_admin) then

htp.formOpen(\'xsr0005.view_guidance_page\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_experiment_id\',i_experiment_id);

htp.formSubmit(\'\',\'View Guidance\');

htp.formClose;

end if;

htp.p(\'\<P\>\');

htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"3\"\>User
comments:\</FONT\>\<FONT size=\"3\"\>(include special hazards/controls,
describe effluents, previous Safety Approval Form Serial Number,
etc.):\</FONT\>\</H3\>\');

\--display Current user comments 7/22/98

for r_user_comments in c_user_comments(i_experiment_id) loop

\--if read_only then

htp.p(\'\<LI\>\'\|\|to_char(r_user_comments.timestamp,\'DD-MON-YYYY\')
\|\| \' - \' \|\| r_user_comments.comments);

\-- nd if;

end loop;

htp.p(\'\<BR\>\');

htp.p(\'\<BR\>\');

\-- show the guidance outline 14-JAN-99 kem

xsr0001.guidance_list(i_experiment_id,i_pid,\'N\');

if not read_only then

htp.p(\'\<P\>\<FONT size=\"3\"\>\<TEXTAREA NAME=\"i_comments\" ROWS=5
COLS=70 wrap=\"physical\"\>\');

\--if l_update_mode and r_experiment.COMMENTS is not null then\'

\-- htp.p(r_experiment.COMMENTS);

\--end if;

htp.p(\'\</TEXTAREA\>\</FONT\>\');

\--else

\--htp.p(\'\<P\>\<FONT size=3\>\' \|\| r_experiment.COMMENTS \|\|
\'\</FONT\>\</P\>\');

end if;

\--

htp.NL;

if not no_changes then

\--

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_experiment_id\',to_char(l_experiment_id));

htp.formHidden(\'i_cat_id\',to_char(r_experiment.cat_id));

if not xfd_admin and not (cat_admin AND no_changes) then

if cat_admin then

htp.formSubmit(\'\',\'Save Experiment Info\');

else

htp.formSubmit(\'\',\'Submit Form\');

end if;

htp.formHidden(\'i_operation\',\'Submit Entry\');

htp.formReset;

if cat_admin then

htp.nl;

htp.p(\'\<FONT SIZE=\"4\" color=\"#FF0000\"\>Save Experiment Info only
saves items listed above\</FONT\>\');

htp.Hr;

end if;

end if;

\--

htp.formClose;

\--

end if;

\--only visisble to CAT/XFD admin privileged users

if cat_admin or xfd_admin then

htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"5\"\>CAT Administration
Section\</FONT\>\</H3\>\');

htp.p(\'\<HR\>\');

htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT Oversight
Comments (include Safety Envelope(s) that will cover this
experiment):\</FONT\>\</H3\>\');

\--display safety envelopers

htp.p(\'\<UL\>\<LI\>\');

if r_experiment.SE1=\'Y\' then

htp.p(\' \' \|\| se_title(1));

end if;

if r_experiment.SE2=\'Y\' then

htp.p(\' \' \|\| se_title(2));

end if;

if r_experiment.SE3=\'Y\' then

htp.p(\' \' \|\| se_title(3));

end if;

if r_experiment.SE4=\'Y\' then

htp.p(\' \' \|\| se_title(4));

end if;

if r_experiment.SE5=\'Y\' then

htp.p(\' \' \|\| se_title(5));

end if;

if r_experiment.SE6=\'Y\' then

htp.p(\' \' \|\| se_title(6));

end if;

if r_experiment.SE7=\'Y\' then

htp.p(\' \' \|\| se_title(7));

end if;

if r_experiment.SE8=\'Y\' then

htp.p(\' \' \|\| se_title(8));

end if;

if r_experiment.SE9=\'Y\' then

htp.p(\' \' \|\| se_title(9));

end if;

\--htp.p(\'\<UL\>\');

for r_cat_comments in c_cat_comments(i_experiment_id) loop

htp.p(\'\<LI\>\'\|\|to_char(r_cat_comments.timestamp,\'DD-MON-YYYY\')
\|\| \' - \' \|\| r_cat_comments.comments);

end loop;

htp.p(\'\</UL\>\');

\--CAT admin section (data entry by cat admin, display only XFD admin)

if cat_admin then

if not no_changes then

htp.p(\'Information in this section is entered by the CAT
Admninistrator\');

htp.NL;

htp.p(\'\<P\>\');

htp.p(\'\<FORM ACTION=\"xsr0005.add_cat_comments\" METHOD=\"POST\"
onSubmit=\"return checkdate(this.i_cat_approval_date)\"\>\');

\--htp.formOpen(\'xsr0005.add_cat_comments\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(1)));

htp.p(\'\<TD\>\');

if r_experiment.se1=\'Y\' then

htp.formCheckBox(\'i_se1\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se1\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(2)));

htp.p(\'\<TD\>\');

if r_experiment.se2=\'Y\' then

htp.formCheckBox(\'i_se2\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se2\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(3)));

htp.p(\'\<TD\>\');

if r_experiment.se3=\'Y\' then

htp.formCheckBox(\'i_se3\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se3\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(4)));

htp.p(\'\<TD\>\');

if r_experiment.se4=\'Y\' then

htp.formCheckBox(\'i_se4\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se4\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(5)));

htp.p(\'\<TD\>\');

if r_experiment.se5=\'Y\' then

htp.formCheckBox(\'i_se5\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se5\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(6)));

htp.p(\'\<TD\>\');

if r_experiment.se6=\'Y\' then

htp.formCheckBox(\'i_se6\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se6\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(7)));

htp.p(\'\<TD\>\');

if r_experiment.se7=\'Y\' then

htp.formCheckBox(\'i_se7\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se7\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(8)));

htp.p(\'\<TD\>\');

if r_experiment.se8=\'Y\' then

htp.formCheckBox(\'i_se8\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se8\',\'Y\');

end if;

htp.p(\'\</TD\>\');

\--htp.tableRowClose;

\--htp,tableRowOpen;

htp.tableData(htf.anchor(\'http://www.aps.anl.gov/xfd/tech/safetyenvelopes/envelopesummary.html\',se_title(9)));

htp.p(\'\<TD\>\');

if r_experiment.se9=\'Y\' then

htp.formCheckBox(\'i_se9\',\'Y\',\'CHECKED\');

else

htp.formCheckBox(\'i_se9\',\'Y\');

end if;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

\--htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT Oversight
Comments (include Safety Envelope(s) that will cover this
experiment):\</FONT\>\</H3\>\');

htp.p(\'\<P\>\<FONT size=\"3\"\>\<TEXTAREA NAME=\"i_comments\" ROWS=5
COLS=70 wrap=\"physical\"\>\');

htp.p(\'\</TEXTAREA\>\</FONT\>\');

\--PEN

htp.p(\'\<P\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Safety Approval
Form Serial Number (PEN#):\</FONT\>\</H3\>\');

select decode(r_experiment.station_a,\'Y\',\'A\',\'\') \|\|
decode(r_experiment.station_b,\'Y\',\'B\',\'\') \|\|
decode(r_experiment.station_c,\'Y\',

\'C\',\'\') \|\| decode(r_experiment.station_d,\'Y\',\'D\',\'\') \|\|
decode(r_experiment.station_e,\'Y\',\'E\',\'\') \|\| \'-\'\|\|
to_char(sysdate,

\'YYYY\') \|\| \'-\' into temp2 from dual;

temp2 := r_experiment.sector_no \|\|\'-\' \|\| r_experiment.beamline
\|\| temp2;

htp.p(\'\<P\>\'\|\|temp2);

htp.formText(\'i_pen_seq\',8,8,r_experiment.pen_seq_no);

htp.NL;

htp.formHidden(\'i_pen\',temp2);

\-- Approver name / date

htp.p(\'\<H3\>\<FONT color=\"#000000\" size=\"3\"\>Plans are adequate to
mitigate hazards and activities are within the beamline operation safety
envelope:\</FONT\>\</H3\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Cat Approver
Name:\</FONT\>\</H3\>\');

htp.p(\'\<TD WIDTH=200\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Cat
Approval Date:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD\>\');

htp.formText(\'i_cat_approver\',25,30,r_experiment.cat_approver_name);

htp.p(\'\</TD\>\');

htp.p(\'\<TD valign=\"Top\"\>\<P ALIGN=\"left\"\>\<INPUT TYPE=\"text\"
\'\|\|

\'NAME=\"i_cat_approval_date\" SIZE=\"11\" MAXLENGTH=\"11\"
value=\"\'\|\|

to_char(r_experiment.cat_approval_date,\'DD-MON-YYYY\')\|\|\'\"
onChange=\"checkdate(this)\"\>\</TD\>\');

htp.tableRowClose;

\--date hint

htp.tableRowOpen;

htp.tableData;

htp.tableData(\'\<FONT Color=\"#008000\" Size=\"3\"\>(i.e.
07-AUG-1999)\</FONT\>\');

htp.tableRowClose;

htp.tableClose;

htp.p(\'\<P\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Person
authorized to verify experiment safeguards:\</FONT\>\</H3\>\');

htp.formText(\'i_cat_verifier\',25,30,r_experiment.cat_safety_rep);

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_experiment_id\',i_experiment_id);

htp.formHidden(\'i_cat_id\',to_char(r_experiment.cat_id));

htp.NL;

htp.p(\'\<TABLE\>\');

htp.p(\'\<TR\>\');

htp.p(\'\<TD ALIGN=\"center\"\>\<FONT color=\"#008000\"
size=\"3\"\>\<B\>Approval Status\</B\>\</FONT\>\</TD\>\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_approval\',\'\',\'1\');

for r_approval in c_approval loop

if r_approval.approval_status=r_experiment.approval_status then

htp.formSelectOption(get_approval_status(r_approval.approval_status),\'SELECTED\',\'VALUE=\'
\|\| to_char(r_experiment.approval_status)

);

else

htp.formSelectOption(get_approval_status(r_approval.approval_status),\'\',\'VALUE=\'
\|\| to_char(r_approval.approval_status));

end if;

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\</TR\>\</TABLE\>\');

htp.formSubmit(\'\',\'Save Cat Administration Information\');

htp.Nl;

htp.p(\'\<FONT SIZE=\"4\" color=\"#FF0000\"\>This button only saves
changes in the CAT adminstration section\</FONT\>\');

htp.formClose;

\--end not read only

else

\-- this is redundant, clean up later

\--display only cat admin information

htp.p(\'\<H3\>\<FONT color=\"#000000\" size=\"3\"\>Plans are adequate to
mitigate hazards and activities are within the beamline operation safety
envelope:\</FONT\>\</H3\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT Approver
Name:\</FONT\>\</H3\>\</TD\>\');

htp.p(\'\<TD width=200\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT
Approval Date:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(nvl(r_experiment.cat_approver_name,\'N/A\'));

htp.tableData(nvl(to_char(r_experiment.cat_approval_date,\'DD-MON-YYYY\'),\'N/A\'));

htp.tableRowClose;

\--date hint

htp.tableRowOpen;

htp.tableData;

htp.tableData(\'\<FONT Color=\"#008000\" Size=\"3\"\>(i.e.
17-JAN-1999)\</FONT\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\"
size=\"3\"\>Status:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

if r_experiment.approval_status=2 then

htp.tableData(\'Rejected\');

elsif r_experiment.approval_status=1 then

htp.tableData(\'Approved\');

else

htp.tableData(\'Pending\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.p(\'\<P\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Person
authorized to verify experiment safeguards:\</FONT\>\</H3\>\</TD\>\');

htp.p(nvl(r_experiment.cat_safety_rep,\'N/A\') \|\| \'\</P\>\');

\-- end cat display only

end if;

\-- XFD display only

htp.p(\'\<HR\>\');

htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD Oversight
Comments:\</FONT\>\</H3\>\');

htp.p(\'\<UL\>\');

if (xfd_comment_count \> 0) then

for r_xfd_comments in c_xfd_comments(i_experiment_id) loop

htp.p(\'\<LI\>\'\|\|to_char(r_xfd_comments.timestamp,\'DD-MON-YYYY\')
\|\| \' - \' \|\| r_xfd_comments.comments);

end loop;

else

htp.p(\'\<LI\>\<FONT COLOR=#FF0000\>Copy submitted to XFD. No comments
received at this time.\</FONT\>\');

end if;

htp.p(\'\</UL\>\');

\--htp.p(\'\<H3\>\<FONT color=\"#000000\" size=\"3\"\>\'\|\|

\--\'All required controls, training & safeguards \'\|\|

\--\'are in place to start the experiment (Authorization
signature):\</FONT\>\</H3\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD Verifier
Name:\</FONT\>\</H3\>\</TD\>\');

htp.p(\'\<TD WIDTH=200\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD
Verification Date:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(nvl(r_experiment.xfd_safety_name,\'N/A\'));

htp.tableData(nvl(to_char(r_experiment.xfd_safety_date,\'DD-MON-YYYY\'),\'N/A\'));

htp.tableRowClose;

htp.tableClose;

\-- end XFD display only

\--otherwise user is xfd admin

else

\--display only cat admin information

htp.p(\'\<H3\>\<FONT color=\"#000000\" size=\"3\"\>Plans are adequate to
mitigate hazards and activities are within the beamline operation s

afety envelope:\</FONT\>\</H3\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT Approver
Name:\</FONT\>\</H3\>\</TD\>\');

htp.p(\'\<TD width=200\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>CAT
Approval Date:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(nvl(r_experiment.cat_approver_name,\'N/A\'));

htp.tableData(nvl(to_char(r_experiment.cat_approval_date,\'DD-MON-YYYY\'),\'N/A\'));

htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\"
size=\"3\"\>Status:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

if r_experiment.approval_status=2 then

htp.tableData(\'Rejected\');

elsif r_experiment.approval_status=1 then

htp.tableData(\'Approved\');

else

htp.tableData(\'Pending\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.p(\'\<P\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>Person
authorized to verify experiment safeguards:\</FONT\>\</H3\>\</TD\>\');

htp.p(nvl(r_experiment.cat_safety_rep,\'N/A\') \|\| \'\</P\>\');

\-- end cat display only

htp.p(\'\<HR\>\<P\>\');

\--htp.formOpen(\'xsr0005.add_xfd_comments\');

htp.p(\'\<FORM ACTION=\"xsr0005.add_xfd_comments\" METHOD=\"POST\"
onSubmit=\"return checkdate(this.i_xfd_date)\"\>\');

htp.p(\'\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD Oversight
Comments:\</FONT\>\</H3\>\');

\--

htp.tableOpen;

htp.p(\'\<UL\>\');

\--htp.p(\'\<LI\>Comment count = \' \|\| to_char(xfd_comment_count));

if (xfd_comment_count \> 0) then

for r_xfd_comments in c_xfd_comments(i_experiment_id) loop

htp.p(\'\<LI\>\'\|\|to_char(r_xfd_comments.timestamp,\'DD-MON-YYYY\')
\|\| \' - \' \|\| r_xfd_comments.comments);

end loop;

else

htp.p(\'\<LI\>\<FONT COLOR=#FF0000\>Copy submitted to XFD. No comments
received at this time.\</FONT\>\');

end if;

htp.tableClose;

htp.p(\'\</UL\>\');

htp.p(\'\<P\>\<FONT size=\"3\"\>\<TEXTAREA NAME=\"i_comments\" ROWS=5
COLS=70 wrap=\"physical\"\>\');

htp.p(\'\</TEXTAREA\>\</FONT\>\');

\-- Approver name / date

\--htp.p(\'\<H3\>\<FONT color=\"#000000\" size=\"3\"\>\'\|\|

\--\'All required controls, training & safeguards \'\|\|

\--\'are in place to start the experiment (Authorization
signature):\</FONT\>\</H3\>\');

htp.tableOpen;

htp.tableRowOpen;

htp.p(\'\<TD\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD Verifier
Name:\</FONT\>\</H3\>\</TD\>\');

htp.p(\'\<TD WIDTH=100\>\<H3\>\<FONT color=\"#008000\" size=\"3\"\>XFD
Verification Date:\</FONT\>\</H3\>\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.p(\'\<TD\>\');

htp.formText(\'i_xfd_name\',25,30,r_experiment.xfd_safety_name);

htp.p(\'\</TD\>\');

htp.p(\'\<TD valign=\"Top\"\>\<P ALIGN=\"left\"\>\'\|\|

\'\<INPUT TYPE=\"text\" NAME=\"i_xfd_date\" SIZE=\"11\" MAXLENGTH=\"11\"
value=\"\'\|\|

to_char(nvl(r_experiment.xfd_safety_date,sysdate),\'DD-MON-YYYY\')\|\|\'\"
onChange=\"checkdate(this)\"\>\</TD\>\');

htp.tableRowClose;

\--date hint

htp.tableRowOpen;

htp.tableData;

htp.tableData(\'\<FONT Color=\"#008000\" Size=\"3\"\>(i.e.
07-AUG-1998)\</FONT\>\');

htp.tableRowClose;

htp.tableClose;

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_experiment_id\',i_experiment_id);

htp.NL;

htp.formSubmit(\'\',\'Save\');

htp.formClose;

end if; \-- if cat_admin..else

end if; \--xfd or cat admin

\--

/\*else

htp.p(get_approval_status(r_experiment.approval_status)\|\|\'\</TD\>\');

htp.p(\'\</TR\>\');

htp.p(\'\</TABLE\>\');

end if;\*/

lib.epilog(null,null,null,FALSE);

end if; \--is valid pid

end;

\--

procedure view_guidance_page (i_pid in varchar2, i_experiment_id in
varchar2) is

begin

if is_valid_experiment_pid (i_experiment_id,i_pid) then

xsr0001.guidance_list(i_experiment_id,i_pid);

else

htp.p(\'\<h3\>Sorry, viewing privilege is not available for this
experiment.\</h3\>\');

end if;

end;

\--

procedure process_experiment_approval(i_pid in varchar2,

i_experiment_id in varchar2,

i_quantity in xsr0001.val_arr,

i_uom in xsr0001.val_arr,

i_cas_num in xsr0001.val_arr,

i_subject in xsr0001.val_arr,

i_funding in xsr0001.val_arr,

i_spokesperson in xsr0001.val_arr,

i_institution in xsr0001.val_arr,

i_email in xsr0001.val_arr,

i_phone in xsr0001.val_arr,

i_exp_name in xsr0001.val_arr,

i_exp_institution in xsr0001.val_arr,

i_material in xsr0001.val_arr,

i_hazard in xsr0001.val_arr,

i_toxic in xsr0001.val_arr,

i_biohazard in xsr0001.val_arr,

i_flammable in xsr0001.val_arr,

i_radioactive in xsr0001.val_arr,

i_other in xsr0001.val_arr,

i_anldispose in xsr0001.val_arr,

\-- These paramters can be re-named when the gudiance changes

\-- See \$safe/source/utilities/xsr5_guidance_parm.sql for a list

VAR_15_22 in xsr0001.val_arr, \-- Equipment

VAR_64_117 in xsr0001.val_arr, \-- Materials Hazards

VAR_89_154 in xsr0001.val_arr, \-- Special Requirements

\--

i_cat_id in varchar2 default NULL,

i_operation in varchar2 default \'INSERT\',

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_stationa in varchar2 default NULL,

i_stationb in varchar2 default NULL,

i_stationc in varchar2 default NULL,

i_stationd in varchar2 default NULL,

i_statione in varchar2 default NULL,

i_title in varchar2 default NULL,

i_other_equipment in varchar2 default NULL,

i_comments in varchar2 default NULL,

i_access_level in varchar2 default \'USER\',

p_level in varchar2 default NULL,

i_la_flag in varchar2 default NULL,

i_ht_flag in varchar2 default NULL,

i_classified in varchar2 default NULL,

i_other_funding in varchar2 default NULL,

i_report in varchar2 default NULL) is

begin

declare

cursor c_exp_id(p_exp_id in varchar2) is

select \'1\'

from XSR5_EXPERIMENT_HEADER

where experiment_id=to_number(p_exp_id);

cursor c_cat_id (p_sector in varchar2) is

select cat_id

from XSR5_CAT_SECTOR_XREF

where sector_no = p_sector;

\--

cursor c_approval(p_experiment_id in number) is

select APPROVAL_STATUS

from XSR5_EXPERIMENT_HEADER

where experiment_id= p_experiment_id;

\--

cursor c_chk_master (p_exp_id in varchar2) is

select \'1\'

from xsr5_transaction_header

where pid = p_exp_id;

\--

l_experiment_id number;

counter number;

l_operation varchar2(20);

l_approval number(1);

generate_guidance boolean;

tissue_guidance boolean;

l_mode varchar2(6);

l_cat_id number(3);

temp varchar2(1);

new_record boolean;

material_array xsr0001.val_arr;

err_point varchar2(25);

required_data EXCEPTION;

required_array number;

resp_val varchar2(255);

begin

\--htp.p(\'EXPERIMENT ID is \' \|\| i_experiment_id \|\| \'xxxx\');

l_experiment_id := to_number(i_experiment_id);

open c_cat_id (i_sector);

fetch c_cat_id into l_cat_id;

close c_cat_id;

\--

l_operation := substr(i_operation,1,4);

\-- if i_experiment_id is null then

open c_exp_id (i_experiment_id);

fetch c_exp_id into temp;

if c_exp_id%NOTFOUND then

l_mode := \'INSERT\';

else

\--If an UPDATE is requested, determine if allowed

l_experiment_id :=to_number(i_experiment_id);

open c_approval(l_experiment_id);

fetch c_approval into l_approval;

if c_approval%NOTFOUND then

l_approval := 0;

end if;

close c_approval;

if l_approval = 0 then

l_mode := \'UPDATE\';

else

l_mode := \'NO CHANGE\';

end if;

end if;

\--check for required fields\...raise exception if problem

\--if this is the final save

if i_operation=\'Submit Entry\' then

if i_title is NULL then

raise required_data;

end if;

if i_spokesperson(2) is null then

raise required_data;

end if;

if i_institution(2) is null then

raise required_data;

end if;

if i_email(2) is null then

raise required_data;

end if;

if i_phone(2) is null then

raise required_data;

end if;

end if;

\-- end required field validation

\-- Process (ins/upd) information for up to 6 tables

\-- XSR5_EXPERIMENT_HEADER

\-- XSR5_SUBJECT_AREAS

\-- XSR5_SPOKESPERSONS

\-- XSR5_EXPERIMENTERS

\-- XSR5_MATERIALS

\-- XSR5_EXTRA_EQUIPMENT_TABLE

err_point := \'1\';

if l_mode = \'INSERT\' then

insert into XSR5_EXPERIMENT_HEADER

(EXPERIMENT_ID,

CLASSIFIED,

OTHER_FUNDING,

SECTOR_NO,

BEAMLINE,

STATION_A,

STATION_B,

STATION_C,

STATION_D,

STATION_E,

CAT_ID,

EXPERIMENT_TITLE,

HT_FLAG,

LA_FLAG,

TIMESTAMP,

PEN,

REMOTE_ADDR,

PATH_TRANSLATED,

PATH_INFO,

HTTP_USER_AGENT,

SCRIPT_NAME,

APPROVAL_STATUS,

PID)

values

(l_experiment_id,

i_classified,

i_other_funding,

i_sector,

i_beamline,

i_stationa,

i_stationb,

i_stationc,

i_stationd,

i_statione,

l_cat_id,

i_title,

i_ht_flag,

i_la_flag,

sysdate,

NULL,

owa_fix.get_cgi_env(\'REMOTE_ADDR\'),

owa_fix.get_cgi_env(\'PATH_TRANSLATED\'),

owa_fix.get_cgi_env(\'PATH_INFO\'),

owa_fix.get_cgi_env(\'HTTP_USER_AGENT\'),

owa_fix.get_cgi_env(\'SCRIPT_NAME\'),

0,

i_pid);

\--add first user comment (others added by guidance system)

add_user_comments (i_pid,i_experiment_id,i_comments);

elsif l_mode=\'UPDATE\' then

err_point := \'2\';

\--Only executes for approval=0, type=USER

\--if already approved. XFD Admin / CAT Admin

\--can add comments only.

update XSR5_EXPERIMENT_HEADER

set SECTOR_NO=i_sector,

BEAMLINE=i_beamline,

STATION_A=i_stationa,

STATION_B=i_stationb,

STATION_C=i_stationc,

STATION_D=i_stationd,

STATION_E=i_statione,

CAT_ID=l_cat_id,

EXPERIMENT_TITLE=i_title,

\--COMMENTS=i_comments,

HT_FLAG=i_ht_flag,

LA_FLAG=i_la_flag,

TIMESTAMP=sysdate,

REMOTE_ADDR=owa_fix.get_cgi_env(\'REMOTE_ADDR\'),

PATH_TRANSLATED=owa_fix.get_cgi_env(\'PATH_TRANSLATED\'),

PATH_INFO=owa_fix.get_cgi_env(\'PATH_INFO\'),

HTTP_USER_AGENT=owa_fix.get_cgi_env(\'HTTP_USER_AGENT\'),

SCRIPT_NAME=owa_fix.get_cgi_env(\'SCRIPT_NAME\'),

PID=i_pid,

CLASSIFIED=i_classified,

OTHER_FUNDING=i_other_funding

where EXPERIMENT_ID=i_experiment_id

and APPROVAL_STATUS=0;

add_user_comments (i_pid,i_experiment_id,i_comments);

end if;

\--

if l_mode = \'UPDATE\' then

delete from XSR5_SUBJECT_AREAS

where experiment_id=i_experiment_id;

end if;

if l_mode = \'UPDATE\' or l_mode = \'INSERT\' then

\--add subject areas

for counter in 1..i_subject.count loop

if (nvl(i_subject(counter),\'0\') != \'0\' )

and (i_subject(counter) != \'N/A\') then

INSERT INTO XSR5_SUBJECT_AREAS

(EXPERIMENT_ID,

SUBJECT_ID)

values

(l_experiment_id,

i_subject(counter));

end if;

end loop;

end if;

\--

err_point := \'3\';

if l_mode = \'UPDATE\' then

delete from XSR5_FUNDING_SOURCES

where experiment_id=i_experiment_id;

end if;

if l_mode = \'UPDATE\' or l_mode = \'INSERT\' then

\--add funding sources

for counter in 1..i_funding.count loop

if (nvl(i_funding(counter),\'0\') != \'0\' )

and (i_funding(counter) != \'N/A\') then

INSERT INTO XSR5_FUNDING_SOURCES

(EXPERIMENT_ID,

FUNDING_ID)

values

(l_experiment_id,

i_funding(counter));

end if;

end loop;

end if;

\--

if l_mode=\'UPDATE\' then

delete from XSR5_SPOKESPERSONS

where experiment_id=i_experiment_id;

end if;

if l_mode=\'UPDATE\' or l_mode=\'INSERT\' then

\--add spokespersons

for counter in 1..i_spokesperson.count loop

if (nvl(i_spokesperson(counter),\'\') != \'N/A\') then

null;

INSERT INTO XSR5_SPOKESPERSONS

(EXPERIMENT_ID,

SEQUENCE_ID,

NAME,

INSTITUTION,

PHONE,

EMAIL,

PRIORITY)

values

(l_experiment_id,

counter - 1,

i_spokesperson(counter),

i_institution(counter),

i_phone(counter),

i_email(counter),

counter - 1);

end if;

end loop;

end if;

err_point := \'4\';

if l_mode=\'UPDATE\' then

delete from XSR5_EXPERIMENTERS

where experiment_id=i_experiment_id;

end if;

if l_mode=\'UPDATE\' or l_mode=\'INSERT\' then

\--add experimenters

for counter in 1..i_exp_name.count loop

if (nvl(i_exp_name(counter),\'\') != \'N/A\') then

null;

INSERT INTO XSR5_EXPERIMENTERS

(EXPERIMENT_ID,

SEQUENCE_ID,

NAME,

INSTITUTION

)

values

(l_experiment_id,

counter-1,

i_exp_name(counter),

i_exp_institution(counter)

);

end if;

end loop;

end if;

err_point := \'4a\';

if l_mode=\'UPDATE\' then

delete from XSR5_MATERIALS

where experiment_id=i_experiment_id;

end if;

err_point := \'4b\';

if l_mode=\'UPDATE\' or l_mode=\'INSERT\' then

\--add materials

for counter in 1..i_material.count loop

if (nvl(i_material(counter),\'\') != \'N/A\') then

null;

INSERT INTO XSR5_MATERIALS

(EXPERIMENT_ID,

SEQUENCE_ID,

MATERIAL,

\--HAZARDOUS,

TOXIC,

BIOHAZARD,

FLAMMABLE,

RADIOACTIVE,

ANL_DISPOSE,

OTHER,

\--QUANTITY,

REF_ID,

UOM

)

values

(l_experiment_id,

counter-1,

i_material(counter),

\--i_hazard(counter),

i_toxic(counter),

i_biohazard(counter),

i_flammable(counter),

i_radioactive(counter),

i_anldispose(counter),

i_other(counter),

\--i_quantity(counter,

i_cas_num(counter),

i_uom(counter)

);

end if;

end loop;

end if;

err_point :=\'5\';

generate_guidance := FALSE;

if l_mode=\'UPDATE\' then

delete from XSR5_EXTRA_EQUIPMENT

where experiment_id=i_experiment_id;

end if;

if l_mode=\'UPDATE\' or l_mode=\'INSERT\' then

\-- This section may need to be modified when gudiance is

\-- regenerated

\-- START of GUDIANCE dependent code

\--add extra equipment

for counter in 2..VAR_15_22.count loop

if (nvl(VAR_15_22(counter),\'\') != \'no value\') then

generate_guidance := TRUE;

\--htp.p(\'SM0001 value = \' \|\| SM01_01_0001(counter));

INSERT INTO XSR5_EXTRA_EQUIPMENT

(EXPERIMENT_ID,

GUIDANCE_NAME,

EQUIP_ID

)

values

(i_experiment_id,

VAR_15_22(counter),

counter);

end if;

end loop;

\--human tissue, animals, chemistry

for counter in 2..VAR_89_154.count loop

if (nvl(VAR_89_154(counter),\'\') != \'no value\') then

generate_guidance := TRUE;

end if;

end loop;

\--build materials array

for counter in 2..i_toxic.count loop

if i_toxic(counter) = \'Y\' then

resp_val := get_haz_values(\'toxic\');

material_array(1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

for counter in 2..i_biohazard.count loop

if i_biohazard(counter) = \'Y\' then

resp_val := get_haz_values(\'biohazard\');

material_array(material_array.count + 1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

for counter in 2..i_flammable.count loop

if i_flammable(counter) = \'Y\' then

resp_val := get_haz_values(\'flammable\');

material_array(material_array.count + 1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

for counter in 2..i_radioactive.count loop

if i_radioactive(counter) = \'Y\' then

resp_val := get_haz_values(\'radioactive\');

material_array(material_array.count + 1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

for counter in 2..i_other.count loop

if i_other(counter) = \'Y\' then

resp_val := get_haz_values(\'other hazard\');

material_array(material_array.count + 1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

\-- Added 12-JUN-1998 fml

for counter in 2..i_anldispose.count loop

if i_anldispose(counter) = \'Y\' then

resp_val := get_haz_values(\'disposal at anl\');

material_array(material_array.count + 1) := resp_val;

generate_guidance := TRUE;

end if;

end loop;

end if;

err_point :=\'6\';

\-- END Of GUIDANCE dependent code

\--

if i_operation = \'Submit Entry\' then

run_print_it(i_experiment_id,\'xsr_new_exp_email.sqt\');

\--

open c_chk_master(i_experiment_id);

fetch c_chk_master into temp;

if c_chk_master%NOTFOUND then

INSERT INTO XSR5_TRANSACTION_HEADER

(PID,TIMESTAMP,MEMO)

VALUES(i_experiment_id,sysdate,\'From XSR0005\');

end if;

close c_chk_master;

\--

if generate_guidance then

\--Display material array

/\*for counter in 1..material_array.count loop

htp.p(\'Material array: \' \|\| to_char(counter) \|\| \' = \' \|\|
material_array(counter));

htp.nl;

end loop; \*/

\--xsr0001.reset_tx_detail(i_experiment_id, 1);

\--xsr0002.process_level2_page(i_experiment_id,p_level,

\--material_array, VAR_63_118,VAR_62_119,VAR_15_22,VAR_87_152

\--);

xsr0002.process_level2_page(i_experiment_id,p_level,

VAR_15_22, material_array, VAR_89_154

);

return;

end if;

end if;

\--re-draw last page

experiment_approval_page(i_pid,

\'UPDATE\',

i_experiment_id,\'USER ENTERING NEW DATA\');

exception

when value_error then

htp.p(\'Please check for a valid date.\');

when required_data then

lib.prolog(\'Required Data Missing\') ;

htp.p(\'Please be certain to include a TITLE and at least one
SPOKESPERSON (INSTITUTION, EMAIL and PHONE).\<BR\>Click BACK\');

lib.epilog (null,null,null,FALSE);

when others then

htp.p(\'Unable to store data. Please report problem to mis_mgrs:\');

htp.nl;

htp.p(\'Note:\' \|\| err_point);

htp.nl;

htp.p(sqlerrm);

end;

end;

\--

procedure add_xfd_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2 default null,

i_xfd_name in varchar2 default null,

i_xfd_date in varchar2 default null) is

begin

declare

temp_badge varchar2(5);

begin

\-- validate this is an XFD ADMIN pid

if is_XFD_admin(i_pid) then

temp_badge := badge_for_this_pid(i_pid);

INSERT INTO XSR5_XFD_COMMENTS

(COMMENT_SEQ_ID,

EXPERIMENT_ID,

COMMENTS,

BADGE_NO,

TIMESTAMP)

values

(XSR5_XFD_SEQ.NextVal,

i_experiment_id,

i_comments,

temp_badge,

sysdate);

\--update

UPDATE XSR5_EXPERIMENT_HEADER

SET XFD_SAFETY_NAME=i_xfd_name,

XFD_SAFETY_DATE=to_date(i_xfd_date,\'DD-MON-YYYY\')

WHERE EXPERIMENT_ID=i_experiment_id;

if i_xfd_date is not null then

run_print_it(i_experiment_id,\'xsr_xfd2cat_mailer.sqt\');

end if;

experiment_approval_page(i_pid,

\'X1\',

i_experiment_id);

end if;

exception

when value_error then

htp.p(\'Please check for a valid date.\');

when others then

htp.p(\'Unable to store data. Please report problem to mis_mgrs:\');

htp.nl;

htp.p(sqlerrm);

end;

end;

\--

procedure add_user_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2

) is

begin

\--

if i_comments is not null then

INSERT INTO XSR5_USER_COMMENTS

(COMMENT_SEQ_ID,

EXPERIMENT_ID,

COMMENTS,

BADGE_NO,

TIMESTAMP)

values

(XSR5_XFD_SEQ.NextVal,

i_experiment_id,

i_comments,

null,

sysdate);

end if;

exception

when value_error then

htp.p(\'Please check for a valid date.\');

when others then

htp.p(\'Unable to store data. Please report problem to mis_mgrs:\');

htp.nl;

htp.p(sqlerrm);

end;

\--

procedure add_cat_comments (i_pid in varchar2,

i_experiment_id in varchar2,

i_comments in varchar2,

i_cat_id in varchar2,

i_approval in varchar2 default null,

i_pen in varchar2 default null,

i_pen_seq in varchar2 default null,

i_cat_approver in varchar2 default null,

i_cat_approval_date in varchar2 default null,

i_cat_verifier in varchar2 default null,

i_se1 in varchar2 default null,

i_se2 in varchar2 default null,

i_se3 in varchar2 default null,

i_se4 in varchar2 default null,

i_se5 in varchar2 default null,

i_se6 in varchar2 default null,

i_se7 in varchar2 default null,

i_se8 in varchar2 default null,

i_se9 in varchar2 default null

) is

begin

declare

temp_badge varchar2(5);

l_comments XSR5_CAT_COMMENTS.COMMENTS%TYPE;

begin

\-- validate this is a CAT ADMIN pid

\-- validate the experiment belongs to this CAT

\-- store comment

l_comments := replace(i_comments,chr(13),\'\');

l_comments := replace(l_comments,chr(10),\' \');

if is_CAT_admin(i_pid,i_experiment_id,i_cat_id) then

temp_badge := badge_for_this_pid(i_pid);

\--

if i_comments is not null then

INSERT INTO XSR5_CAT_COMMENTS

(COMMENT_SEQ_ID,

EXPERIMENT_ID,

COMMENTS,

BADGE_NO,

TIMESTAMP)

values

(XSR5_XFD_SEQ.NextVal,

i_experiment_id,

l_comments,

temp_badge,

sysdate);

end if;

\--Mark status

UPDATE XSR5_EXPERIMENT_HEADER

SET APPROVAL_STATUS=i_approval,

PEN=i_pen \|\| nvl(i_pen_seq,\'\'),

PEN_SEQ_NO=i_pen_seq,

CAT_APPROVER_NAME=i_cat_approver,

CAT_APPROVAL_DATE=to_date(i_cat_approval_date,\'DD-MON-YYYY\'),

CAT_SAFETY_REP=i_cat_verifier,

SE1=nvl(i_se1,\'N\'),

SE2=nvl(i_se2,\'N\'),

SE3=nvl(i_se3,\'N\'),

SE4=nvl(i_se4,\'N\'),

SE5=nvl(i_se5,\'N\'),

SE6=nvl(i_se6,\'N\'),

SE7=nvl(i_se7,\'N\'),

SE8=nvl(i_se8,\'N\'),

SE9=nvl(i_se9,\'N\')

WHERE EXPERIMENT_ID=i_experiment_id;

\--if newly approved (make generic)

if i_approval != 0 then

run_print_it(i_experiment_id,\'xsr_cat2xfd_mailer.sqt\');

end if;

experiment_approval_page(i_pid,\'UPDATE\',i_experiment_id);

end if;

exception

when value_error then

htp.p(\'Please check for a valid date.\');

when others then

htp.p(\'Unable to store data. Please report problem to mis_mgrs:\');

htp.nl;

htp.p(sqlerrm);

end;

end;

\--

procedure thank_you_page (i_pid in varchar2,

i_experiment_id in varchar2) is

begin

null;

end;

begin

owa_fix.init_global_cgi_env;

end;

/

CREATE OR REPLACE PACKAGE xsr0006 IS

G_MENU_START_PAGE constant varchar2(50) := \'wam0002.DCN_MAIN_MENU\';

G_QUERY_START_PAGE_APP constant varchar2(50) := \'XSR_ADMIN\';

G_QUERY_START_PAGE constant varchar2(50) := \'QUERY_START_PAGE\';

G_QUERY_OP constant varchar2(50) := \'Query\';

G_NEW_START_PAGE_APP constant varchar2(50) := \'DCN_NEW\';

G_NEW_START_PAGE constant varchar2(50) := \'NEW_START_PAGE\';

G_NEW_OP constant varchar2(50) := \'New\';

G_ADD_OP constant varchar2(50) := \'Add Another\';

G_REVISE_START_PAGE_APP constant varchar2(50) := \'DCN_REVISE\';

G_REVISE_START_PAGE constant varchar2(50) := \'REVISE_START_PAGE\';

G_REVISE_OP constant varchar2(50) := \'Revise\';

G_UPDATE_START_PAGE_APP constant varchar2(50) := \'DCN_UPDATE\';

G_UPDATE_START_PAGE constant varchar2(50) := \'UPDATE_START_PAGE\';

G_UPDATE_OP constant varchar2(50) := \'Update\';

G_RETURN_TO_QUERY constant varchar2(50) := \' Return to Query Page \';

G_RETURN_TO_NEW constant varchar2(50) := \' Request DCN-New Drawing \';

G_RETURN_TO_REVISE constant varchar2(50) := \' Request DCN-Revise
Drawing \';

G_RETURN_TO_UPDATE constant varchar2(50) := \' Update Drawing Title \';

G_BACK_TO_MENU constant varchar2(50) := \' Back to Main Menu \';

G_ONLINE_HELP constant varchar2(50) := \'Online Help\';

G_ONLINE_HELP_FILE constant varchar2(50) := \'/dcc-doc/dcn_help.html\';

\--

procedure xfd_start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL);

\--

\--procedure cat_start_page (i_pid in varchar2 default \'NEW\',i_attrib
in varchar2 default NULL);

\--

procedure query_result_page (i_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

procedure cat_review_page (i_pid in varchar2,

i_operation in varchar2 default NULL,

i_cat_id in varchar2 default NULL,

i_cat_name in varchar2 default NULL);

procedure process_cat_admin(i_pid in varchar2,

i_operation in varchar2,

i_cat_name in varchar2 default NULL,

i_cat_id in varchar2 default \'999\');

procedure process_cat_sector(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_sector in varchar2 default NULL);

procedure fc_management_page(i_pid in varchar2,

i_operation in varchar2);

procedure process_floor_coordinator(i_pid in varchar2,

i_role_id in varchar2,

i_operation in varchar2 default NULL,

i_badge in varchar2 default NULL);

procedure process_cat_safety(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_username in varchar2,

i_last in varchar2 default NULL,

i_first in varchar2 default NULL,

i_email in varchar2 default NULL,

x in varchar2 default NULL,

y in varchar2 default NULL);

END;

/

CREATE OR REPLACE PACKAGE BODY XSR0006 IS

/\*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

DATE: INITIALS: REMARKS:

\-\-\-\-- \-\-\-\-\-\-\-\-- \-\-\-\-\-\-\--

\*/

\--

\-- GLOBAL NEXT N settings

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \' \> \';

PREV_BUT_CAPTION constant varchar2(100) := \' \< \';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\>\>\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\<\<\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'!\<\<\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\>\>!\';

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 5;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'Maximimum number
of records (\'\|\|to_char(MAX_ROWS)\|\| \') returned\');

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

function username_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(5);

cursor c_badge(p_pid in varchar2) is

select username

from ows_app_login

where pid=p_pid;

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'?????\';

end if;

close c_badge;

return result;

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'XSR_ADMIN\';

result := log0002.is_valid_pid(i_pid, p_app_name);

return result;

end;

end;

\--

function cat_for_this_user(i_pid in varchar2) return number is

begin

declare

result number;

cursor c_cat_id(p_pid in varchar2) is

select cat_id from

xsr5_cat_admin_priv cat, ows_app_login log

where cat.username=log.username

and log.pid=i_pid;

begin

result := 0;

open c_cat_id(i_pid);

fetch c_cat_id into result;

close c_cat_id;

return(result);

end;

end;

\--

function is_XFD_admin(i_pid in varchar2) return boolean is

begin

declare

cursor c_xfd_role (p_pid in varchar2,p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_ADMIN\'

and log.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_xfd_role(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_xfd_role into temp;

if not c_xfd_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_xfd_role;

return(result);

end;

end;

\--

function is_CAT_user(i_pid in varchar2,i_experiment_id in varchar2)
return boolean

is

begin

declare

l_cat number;

cursor c_this_cat_user(p_cat_id in number,p_user in varchar2,
p_experiment_id in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV priv, XSR5_EXPERIMENT_HEADER exp

where exp.cat_id=priv.cat_id

and priv.cat_id=p_cat_id

and priv.username=p_user

and exp.experiment_id=p_experiment_id;

/\*cursor c_cat_role (p_pid in varchar2, p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_CAT_ADMIN\'

and log.pid=p_pid;\*/

temp_user varchar2(5);

temp varchar2(1);

result boolean;

begin

l_cat := cat_for_this_user(i_pid);

temp_user := username_for_this_pid(i_pid);

result := FALSE;

open c_this_cat_user(l_cat,temp_user,i_experiment_id);

fetch c_this_cat_user into temp;

if not c_this_cat_user%NOTFOUND then

result := TRUE;

end if;

close c_this_cat_user;

/\*if result then

open c_cat_role(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_cat_role into temp;

if not c_cat_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

\-- htp.p(\'\<FONT size=4 color=#FF0000\>CAT Admin access is not
available for this session\</FONT\>\');

end if;

close c_cat_role;

end if;\*/

return(result);

end;

end;

\--

function is_experiment_visible(i_experiment_id in varchar2, i_pid in
varchar2) return boolean is

begin

declare

result boolean;

begin

result := FALSE;

\--result := is_XFD_admin(i_pid) or is_CAT_user(i_experiment_id, i_pid);

result := is_XFD_admin(i_pid);

return (result);

end;

end;

\--

\-- CAT experiment selection criteria

procedure experiment_selection (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL) is

\--

l_range_from varchar2(20);

l_range_to varchar2(20);

cursor c_cat(p_cat_id in number) is

select \* from XSR5_CAT_TABLE

where cat_id = p_cat_id;

cursor c_cat_sectors(p_cat_id in number) is

select \*

from XSR5_CAT_SECTOR_XREF

where cat_id=p_cat_id;

r_cat XSR5_CAT_TABLE%ROWTYPE;

l_cat number(3);

\--

begin

\-- FIND CAT associated with this user

l_cat := cat_for_this_user(m_pid);

if l_cat != 0 then

open c_cat(l_cat);

fetch c_cat into r_cat;

close c_cat;

else

htp.p(\'You are not authorized to view experiments. Sorry\');

end if;

\--

lib.prolog(\'Enter Search Criteria: \');

\--

\--

htp.centerOpen;

if p_msg is not null then

htp.p(\'\<font type=arial size=4 color=#0000FF\>\' \|\| p_msg \|\|
\'\</font\>\');

end if;

htp.p(\'\<FORM ACTION=\"xsr0006.query_result_page\"
METHOD=\"POST\"\>\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableHeader(\'Sector No.:\',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_sector\');

htp.formSelectOption(\'All\');

for r_cat_sector in c_cat_sectors(l_cat) LOOP

htp.formSelectOption(r_cat_sector.sector_no,r_cat_sector.sector_no);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Beamline: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_beamline\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

\--default to specific cat if cat user!

htp.tableRowOpen;

htp.tableHeader(\'CAT: \',\'Right\');

htp.tableData(r_cat.cat_name);

htp.formHidden(\'i_cat\',r_cat.cat_id);

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Approval Status: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_approval_status\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'Pending\');

htp.formSelectOption(\'Approved\');

htp.formSelectOption(\'Rejected\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Experiments listed per page: \',\'Right\');

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',2,2,\'15\'));

htp.tableRowClose;

\--

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

\--

htp.centerClose;

lib.epilog;

end;

\--

\--

\-- This procedure allows the user to enter in parameters to query off
of.

\--

procedure enter_criteria (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL) is

\--

l_range_from varchar2(20);

l_range_to varchar2(20);

err_pnt varchar2(20);

cursor c_cat is

select \* from XSR5_CAT_TABLE

order by cat_name;

\--

begin

\--l_range_from :=
to_char(to_date(i_from_year\|\|i_from_month\|\|i_from_day,\'YYYYMMDD\'));

\--l_range_to :=
to_char(to_date(i_to_year\|\|i_to_month\|\|i_to_day,\'YYYYMMDD\'));

\--

lib.prolog(\'Enter Search Criteria: \');

\--

\--

htp.centerOpen;

if p_msg is not null then

htp.p(\'\<font type=arial size=4 color=#0000FF\>\' \|\| p_msg \|\|
\'\</font\>\');

end if;

\-- htp.FormOpen(\'rfm0001.query_result_page\');

htp.p(\'\<FORM ACTION=\"xsr0006.query_result_page\"
METHOD=\"POST\"\>\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableHeader(\'Sector No.:\',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_sector\');

htp.formSelectOption(\'All\');

for i in 1..40 LOOP

htp.formSelectOption(to_char(i,\'09\'),null);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Beamline: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_beamline\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

\--default to specific cat if cat user!

htp.tableRowOpen;

htp.tableHeader(\'CAT: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_cat\');

htp.formSelectOption(\'All\');

for r_cat in c_cat LOOP

htp.formSelectOption(r_cat.cat_name,\'\',\'VALUE=\' \|\|
to_char(r_cat.cat_id));

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Approval Status: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_approval_status\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'Pending\');

htp.formSelectOption(\'Approved\');

htp.formSelectOption(\'Rejected\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Experiments listed per page: \',\'Right\');

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',2,2,\'15\'));

htp.tableRowClose;

\--

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

htp.formOpen(\'xsr0006.cat_review_page\');

htp.formSubmit(\'i_operation\',\'CAT Administration\');

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

htp.formOpen(\'xsr0006.fc_management_page\');

htp.formSubmit(\'i_operation\',\'XFD Floor Coordinators\');

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

\-- htp.para;

\-- htp.para;

\-- htp.p(\'\[\');

\-- htp.anchor(dcc0005.G_ONLINE_HELP_FILE,G_ONLINE_HELP);

\-- htp.p(\'\|\');

\-- htp.anchor(\'wam0002.rfm_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

\-- htp.p(\'\]\');

htp.centerClose;

lib.epilog;

end;

\--

\-- Checks to see if its a valid PID

\--

procedure xfd_start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid,i_attrib);

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\-- if iattrib is empty, go to selection screen

\-- otherwise go drectly to detail screen

if i_attrib is not null then

htp.p(\'\<meta http-equiv=\"refresh\"
content=\"2;URL=xsr0005.experiment_approval_page?i_pid=\'\|\| i_pid

\|\|\'&i_operation=X1\'\|\|\'&\' \|\| \'i_experiment_id=\' \|\|
i_attrib\|\|\'\"\>\');

else

enter_criteria(m_pid,G_QUERY_OP);

end if;

\--

end;

\--

\--

\-- This procedure populates the second page of the application.

\--

procedure query_result_page (i_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL) is

\--

\-- Set up the cursors for your detail page (Page 2).

\--

cursor cur_signoff_view(p_rf_proc_detail_id in number) is

select \*

from eq_rf_last_signoff_view

where RF_PROC_DETAIL_ID = p_rf_proc_detail_id;

\--

cursor c_primary_spokesperson(p_exp_id in number) is

select name

from XSR5_SPOKESPERSONS

where experiment_id=p_exp_id

and priority=1;

l_name XSR5_SPOKESPERSONS.NAME%TYPE;

\-- Local variables for the second page (the query_result_page
procedure).

\--

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

I_NEXT_SET_BUT boolean;

I_PREV_SET_BUT boolean;

I_FIRST_SET_BUT boolean;

I_LAST_SET_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number := 10;

total_pages number;

cur_cnt number;

rec_counter number := 0;

temp_anchor varchar2(512);

dcc_print varchar2(512);

l_range_from varchar2(20);

l_range_to varchar2(20);

\--

l_title varchar2(2000);

l_pre_cri varchar2(50);

l_dwg_no varchar2(100);

l_page_no number;

l_hold_page number;

x_temp number;

y_temp number;

\--

j_query varchar2(2000) := \'\';

j_where varchar2(2000) := \'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned number := 0;

instructions varchar2(255);

r_experiment XSR5_EXPERIMENT_HEADER%rowtype;

\--

err_pnt varchar2(20);

begin

\--

\-- Checks to see if there is a valid PID

\--

if is_valid_pid(i_pid) then

\-- if i_operation = G_QUERY_OP then

\-- if NOT log0002.is_valid_pid(m_pid,G_QUERY_START_PAGE_APP) then

\-- return;

\-- end if;

\-- end if;

\--

\--

\--the dynamic select statement to retrieve the complete_document_no
which is a

\-- unique field that can retrieve any other fields needed via cursors.

\--

i_query := \'select
experiment_id,sector_no,beamline,experiment_title,approval_status,pen
from XSR5_EXPERIMENT_HEADER\';

\--

\-- Begins to build the dynamic where clause

\-- This initial part is static while the following if\'s add onto the
where clause

\-- when the conditions are met.

\--

i_where := \'\';

\--

\-- The following series of if\'s dynamicly add to the where clause when
the conditions

\-- are met.

\--

if i_sector is NOT NULL and i_sector != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' sector_no=\'\'\' \|\|
i_sector \|\| \'\'\'\';

end if;

if i_cat is NOT NULL and i_cat != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' cat_id=\' \|\| i_cat;

end if;

if i_beamline is NOT NULL and i_beamline != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' beamline=\'\'\' \|\|
i_beamline \|\| \'\'\'\';

end if;

if i_approval_status is NOT NULL and i_approval_status != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

if i_approval_status = \'Pending\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=0\';

elsif i_approval_status = \'Approved\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=1\';

elsif i_approval_status = \'Rejected\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=2\';

end if;

end if;

/\*kem 3/19/98 Process CAT Selection \.... not so straight
forward\...needs join\*/

\--

\-- This counts the number of records returned in order to place the

\-- correct number of buttons on the bottom of the page.

\--

\--

\-- \*\*\*\* This is where the invalid column field is coming from. Once
the dynamic

\-- where clause is uncommented the invalid column comes up.

\--

err_pnt := \'1\';

if Z_TOTAL_ROWS is NULL then

j_query := \' select count(experiment_id) \'

\|\|\' from \'\|\|\' XSR5_EXPERIMENT_HEADER \' ;

j_where := i_where;

j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

\-- htp.p(\'J WHERE = \' \|\| j_query);

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

\-- htp.p(\'Y TOTAL ROWS = \' \|\| Y_TOTAL_ROWS);

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\--

I_CURSOR := dbms_sql.open_cursor;

i_query := i_query \|\|\' \'\|\| i_where\|\|\' order by
sector_no,beamline\';

\--

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1, r_experiment.experiment_id);

dbms_sql.define_column(I_CURSOR, 2, r_experiment.sector_no,2);

dbms_sql.define_column(I_CURSOR, 3, r_experiment.beamline,2);

dbms_sql.define_column(I_CURSOR, 4, r_experiment.experiment_title,2000);

dbms_sql.define_column(I_CURSOR, 5, r_experiment.approval_status);

dbms_sql.define_column(I_CURSOR, 6, r_experiment.pen,25);

\--

I_VOID := dbms_sql.execute (I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

\--

err_pnt:=\'2\';

\-- Checks to see if there were any rows retrieved from the parameters
entered. If none

\-- then it will display the message with the values entered.

\--

if I_ROWS_FETCHED = 0 then

\-- dbms_sql.close_cursor(I_CURSOR);

/\* enter_criteria(i_pid,

i_operation,

\'No records matching that criteria found. \');

\--i_master_system,

\--i_system,

\--i_components,

\--i_sub_components,

\--i_task_grouping,

\--i_range_from,

\--i_range_to);

return; \*/

null;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -
1)/SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

I_START := ((l_hold_page -1) \* record_set_size) + 1;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

I_START := 1;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\-- Puts the viewable \"Header\" portion on page two.

\--

lib.prolog(\'Experiments \');

\--

\-- Places the header fields on the begining of the report. Note:
tableHeader

\-- automaticly bolds the text for you.

\--

htp.centerOpen;

if I_TOTAL_ROWS \<\> 0 then

htp.tableOpen(\'border\');

\-- htp.tableHeader(\'Sector\');

htp.tableHeader(\'PEN\');

htp.tableHeader(\'Beamline\');

htp.tableHeader(\'Approval Status\');

htp.tableHeader(\'Title\');

htp.tableHeader(\'Primary Spokesperson\');

htp.tableHeader(\'ESA Form\');

\--

\--err_pnt := \'1\';

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1, r_experiment.experiment_id);

dbms_sql.column_value(I_CURSOR, 2, r_experiment.sector_no);

dbms_sql.column_value(I_CURSOR, 3, r_experiment.beamline);

dbms_sql.column_value(I_CURSOR, 4, r_experiment.experiment_title);

dbms_sql.column_value(I_CURSOR, 5, r_experiment.approval_status);

dbms_sql.column_value(I_CURSOR, 6, r_experiment.pen);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or

I_TOTAL_ROWS \>= 1)) then

\--

\-- Starts to retrieve the data requested for the page.

\--

if is_experiment_visible(r_experiment.experiment_id,i_pid) then

htp.tableRowOpen;

temp_anchor := \'xsr0005.experiment_approval_page?i_pid=\' \|\| i_pid
\|\| \'&\' \|\| \'i_operation=UPDATE\' \|\| \'&\' \|\|
\'i_experiment_id=\' \|\| r_experiment.experiment_id;

\-- htp.tableData(htf.anchor(temp_anchor,r_experiment.pen));

htp.tableData(nvl(r_experiment.pen,\'&nbsp\'));

htp.tableData(htf.anchor(temp_anchor,r_experiment.sector_no \|\| \'-\'
\|\| r_experiment.beamline));

if r_experiment.approval_status=0 then

htp.tableData(\'Pending\',\'Center\');

elsif r_experiment.approval_status=1 then

htp.tableData(\'Approved\',\'Center\');

elsif r_experiment.approval_status=2 then

htp.tableData(\'Rejected\',\'Center\');

else

htp.tableData(\'N/A\',\'Center\');

end if;

htp.tableData(nvl(r_experiment.experiment_title,\'&nbsp\'),\'Center\');

\--get spokesperson

open c_primary_spokesperson(r_experiment.experiment_id);

fetch c_primary_spokesperson into l_name;

close c_primary_spokesperson;

htp.tableData(nvl(l_name,\'&nbsp\'));

htp.p(\'\<TD\>\');

htp.formOpen(\'/gen-bin/uncgi/xsr_web_reports.pdf\');

htp.formHidden(\'p_exp_id\',r_experiment.experiment_id);

htp.formHidden(\'i_report\',\'DOOR_REPORT\');

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit(\'\',\'Generate\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\--close if for \"is_experiment_visible\"

end if;

else

htp.p(\' \*\*\*\*\* \');

htp.br;

end if;

\--

\-- F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

\--

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

\-- htp.tableRowClose;

\-- end if;

end loop;

\--

htp.tableClose;

\--dbms_sql.close_cursor(I_CURSOR);

else

htp.p(\'\<FONT FACE=ARIAL,HELVETICA SIZE=6 COLOR=#006010\>No experiments
were found for those criteria.\</FONT\>\');

htp.NL;

htp.p(\'\<FONT face=ARIAL,Helvetica Size=4 color=#006010\>Click \[Back\]
to try again.\</FONT\>\');

end if;

dbms_sql.close_cursor(I_CURSOR);

\--

htp.formOpen(\'xsr0006.query_result_page\');

\--

if I_PREV_BUT or I_NEXT_BUT then

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_sector\',i_sector);

htp.formHidden(\'i_beamline\',i_beamline);

htp.formHidden(\'i_cat\',i_cat);

htp.formHidden(\'i_approval_status\',i_approval_status);

htp.formHidden(\'Z_START\', to_char(I_START));\--

htp.formHidden(\'i_operation\',i_operation);\--

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

\--

htp.para;

\--

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

\--

err_pnt:=\'3\';

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

\--

\-- For toggle buttons \*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\--

\-- This is where the buttons are built for the application.

\--

if Z_ACTION = NEXT_BUT_CAPTION then

l_hold_page := TO_NUMBER(NVL(Z_PAGE_NO,\'0\')) +1;

elsif Z_ACTION = PREV_BUT_CAPTION then

l_hold_page := TO_NUMBER(Z_PAGE_NO) -1;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -1) /
SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

else

l_hold_page := to_number(nvl(Z_ACTION,\'1\'));

end if;

\--

err_pnt := 4;

htp.tableOpen;

\--

I_NEXT_SET_BUT := FALSE;

I_PREV_SET_BUT := FALSE;

I_FIRST_SET_BUT := FALSE;

I_LAST_SET_BUT := FALSE;

\--

if l_hold_page \> SLIDER_WIDTH then

I_PREV_SET_BUT := TRUE;

I_FIRST_SET_BUT := TRUE;

end if;

\--

\-- Displaying the NEXT SET BUTTON

\--

if trunc((nvl(l_hold_page,1) - 1) / SLIDER_WIDTH) \< trunc((Y_TOTAL_ROWS
/ (Z_RECORD_SET_SIZE \* SLIDER_WIDTH)))

then

I_NEXT_SET_BUT := TRUE;

I_LAST_SET_BUT := TRUE;

end if;

\--

\-- ADDING THE PREVIOUS SET BUTTON FUNC.

\--

htp.tableRowOpen;

\--

y_temp := mod(l_hold_page,SLIDER_WIDTH);

\--

if y_temp = 0 then

x_temp := SLIDER_WIDTH;

else

x_temp := y_temp;

end if;

\--

htp.formHidden(\'Z_PAGE_NO\',l_hold_page);

cur_cnt := 1 + (l_hold_page - x_temp);

\--

\-- Creates the numeric toggle buttons on the bottom of the page.

\--

while cur_cnt \<= total_pages loop

if cur_cnt = l_hold_page then

htp.tableData(htf.bold(to_char(l_hold_page)));

else

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(\'
\'\|\|to_char(cur_cnt)\|\|\' \')));

end if;

\--

if mod(cur_cnt,SLIDER_WIDTH) = 0 then

exit;

end if;

cur_cnt := cur_cnt + 1;

end loop;

htp.tableRowClose;

htp.tableClose;

\--

\-- Creates the buttons on the bottom of the page to toggle from one
page, one set, or

\-- last set of buttons.

htp.tableOpen(\'border\');

htp.tableRowOpen;

\-- Creates the !\<\< button. The else condition on all of the following
buttons \"disables\"

\-- the button when the condition cannot be done.

\--

if I_FIRST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(FIRST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(FIRST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \<\< button.

\--

if I_PREV_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_SET_BUT_CAPTION\|\|\'&\'\|\|\'nbsp\'));

end if;

\--

\-- Creates the \< button.

\--

if I_PREV_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \> button.

\--

if I_NEXT_BUT then

htp.tableData(htf.bold(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_BUT_CAPTION))));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\> button.

\--

if I_NEXT_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\>! button.

\--

if I_LAST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(LAST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(LAST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p(MAX_ROWS_MESSAGE);

end if;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

end if;

exception

when others then

htp.p(\'ERR POINT \' \|\| err_pnt);

htp.p (SQLERRM);

htp.NL;

htp.p(i_query);

end;

\--

procedure cat_review_page (i_pid in varchar2,

i_operation in varchar2 default NULL,

i_cat_id in varchar2 default NULL,

i_cat_name in varchar2 default NULL) is

begin

declare

cursor c_cats is

select \*

from XSR5_CAT_TABLE

where inactive is NULL

order by cat_name;

begin

if is_valid_pid(i_pid) then

lib.prolog(\'XFD Experimental Safety Review CAT Administration\');

htp.centerOpen;

htp.formOpen(\'xsr0006.process_cat_admin\');

htp.formSelectOpen(\'i_cat_id\');

for r_cat in c_cats loop

htp.formSelectOption(r_cat.cat_name,\'\',\'VALUE=\'\|\|r_cat.cat_id);

end loop;

htp.formSelectClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\',\'Remove\'));

htp.tableData(htf.formSubmit(\'i_operation\',\'Review Safety
Administrators\'));

htp.tableData(htf.formSubmit(\'i_operation\',\'Assign Sectors\'));

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'To add a new CAT, enter new CAT name: \' \|\|
htf.formText(\'i_cat_name\',10,25));

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Add\');

htp.formHidden(\'i_pid\',i_pid);

htp.centerClose;

htp.formClose;

lib.epilog;

end if;

end;

end;

\--

\--

procedure review_safety_users (i_pid in varchar2, i_cat_id in varchar2)
is

begin

declare

cursor c_cat(p_cat_id in number) is

select \*

from xsr5_cat_table

where cat_id=p_cat_id;

cursor c_safety_users(p_cat_id in number) is

select \*

from xsr5_cat_admin_priv

where cat_id=p_cat_id;

r_cat XSR5_CAT_TABLE%ROWTYPE;

begin

if is_valid_pid(i_pid) then

htp.centerOpen;

open c_cat(i_cat_id);

fetch c_cat into r_cat;

close c_cat;

lib.prolog(\'CAT Safety Users for \' \|\| r_cat.cat_name);

htp.p(\'\<TABLE BGCOLOR=\"#AAC7E6\" BORDER=1\>\');

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Last Name\'));

htp.tableData(htf.bold(\'First Name\'));

htp.tableData(htf.bold(\'Badge No.\'));

htp.tableData(htf.bold(\'Email\'));

htp.tableData(htf.bold(\'Email Active\'));

htp.tableData(htf.Bold(\'User Active\'));

htp.tableData(htf.Bold(\'Delete User\'));

htp.tableRowClose;

\--

\--

for r_cat_safety_user in c_safety_users(i_cat_id) loop

htp.tableRowOpen;

htp.tableData(nvl(r_cat_safety_user.LAST_NAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_safety_user.FIRST_NAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_safety_user.USERNAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_safety_user.EMAIL,\'&nbsp\'));

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_cat_safety\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_safety_user.username);

if r_cat_safety_user.email_flag=\'Y\' then

htp.formHidden(\'i_operation\',\'Email Off\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/chkbox.gif\"
BORDER=\"0\"\>\');

else

htp.formHidden(\'i_operation\',\'Email On\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/nochkbox.gif\"
BORDER=\"0\"\>\');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_cat_safety\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_safety_user.username);

if r_cat_safety_user.inactive is null then

htp.formHidden(\'i_operation\',\'Inactivate\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/chkbox.gif\"
BORDER=\"0\"\>\');

else

htp.formHidden(\'i_operation\',\' Activate \');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/nochkbox.gif\"
BORDER=\"0\"\>\');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_cat_safety\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_safety_user.username);

htp.formHidden(\'i_operation\',\'Delete\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/erase.gif\"
BORDER=\"0\"\>\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

end loop;

htp.tableRowOpen;

htp.formOpen(\'xsr0006.process_cat_safety\');

htp.tableData(htf.formText(\'i_last\',12,25));

htp.tableData(htf.formText(\'i_first\',12,25));

htp.tableData(htf.formText(\'i_username\',12,20));

htp.tableData(htf.formText(\'i_email\',20,50));

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.tableData(htf.formSubmit(\'i_operation\',\'Add\'));

htp.p(\'\<TD COLSPAN=2\>&nbsp\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.NL;

htp.formClose;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--

procedure assign_sectors (i_pid in varchar2, i_cat_id in varchar2) is

begin

declare

cursor c_cat(p_cat_id in number) is

select \*

from xsr5_cat_table

where cat_id=p_cat_id;

cursor c_cat_sector(p_cat_id in number) is

select \*

from xsr5_cat_sector_xref

where cat_id=p_cat_id

order by sector_no;

r_cat XSR5_CAT_TABLE%ROWTYPE;

begin

if is_valid_pid(i_pid) then

htp.centerOpen;

open c_cat(i_cat_id);

fetch c_cat into r_cat;

close c_cat;

lib.prolog(\'CAT Sector Assignments for \' \|\| r_cat.cat_name);

htp.p(\'\<TABLE BGCOLOR=\"#AAC7E6\" BORDER=1\');

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Sector\'));

htp.tableData(htf.bold(\'Operation\'));

htp.tableRowClose;

\--

for r_cat_sector in c_cat_sector(i_cat_id) loop

htp.tableRowOpen;

htp.tableData(nvl(r_cat_sector.SECTOR_NO,\'&nbsp\'));

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_cat_sector\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_sector\',r_cat_sector.SECTOR_NO);

htp.formSubmit(\'i_operation\',\'Delete\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

end loop;

htp.tableRowOpen;

htp.formOpen(\'xsr0006.process_cat_sector\');

htp.tableData(htf.formText(\'i_sector\',10,10));

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.p(\'\<TD ALIGN=CENTER\>\');

htp.formSubmit(\'i_operation\',\'Add\');

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.NL;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--

procedure process_cat_safety(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_username in varchar2,

i_last in varchar2 default NULL,

i_first in varchar2 default NULL,

i_email in varchar2 default NULL,

x in varchar2 default NULL,

y in varchar2 default NULL) is

begin

declare

cursor c_user_exists(p_username in varchar2) is

select \'1\'

from GEN_USER_TABLE

where username=p_username

or badge_no=p_username;

temp varchar2(1);

begin

if i_operation=\'Add\' then

\--Create user if necessary

open c_user_exists(i_username);

fetch c_user_exists into temp;

if c_user_exists%NOTFOUND then

\--Add user

INSERT INTO GEN_USER_TABLE

(BADGE_NO,USERNAME,BREAKER,CREATE_DATE,CREATE_USER,MUST_CHANGE_PWD)

values

(i_username,i_username,i_last,sysdate,\'XFD_ADMIN\',\'Y\');

end if;

close c_user_exists;

INSERT INTO XSR5_CAT_ADMIN_PRIV

(CAT_ID,USERNAME,PK_ID,EMAIL,LAST_NAME,FIRST_NAME,EMAIL_FLAG)

VALUES
(i_cat_id,i_username,safety.xsr5_cat_admin_seq.nextval,i_email,i_last,i_first,\'Y\');

elsif i_operation=\'Email Off\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET EMAIL_FLAG=\'N\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Email On\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET EMAIL_FLAG=\'Y\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Inactivate\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET INACTIVE=\'Y\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\' Activate \' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET INACTIVE=NULL

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Delete\' then

DELETE FROM XSR5_CAT_ADMIN_PRIV

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

end if;

review_safety_users(i_pid,i_cat_id);

EXCEPTION

when others then

htp.p (SQLERRM);

htp.NL;

htp.p(\'Please press BACK to address the problem.\');

end;

end;

\--

procedure process_cat_sector(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_sector in varchar2 default NULL) is

begin

declare

begin

if i_operation=\'Add\' then

\--Create user if necessary

INSERT INTO XSR5_CAT_SECTOR_XREF

(CAT_ID,SECTOR_NO)

VALUES (i_cat_id,i_sector);

elsif i_operation=\'Delete\' then

DELETE FROM XSR5_CAT_SECTOR_XREF

WHERE CAT_ID=i_cat_id

AND SECTOR_NO=i_sector;

end if;

assign_sectors(i_pid,i_cat_id);

EXCEPTION

when others then

htp.p (SQLERRM);

htp.NL;

htp.p(\'Please press BACK to address the problem.\');

end;

end;

\--

procedure process_cat_admin(i_pid in varchar2,

i_operation in varchar2,

i_cat_name in varchar2 default NULL,

i_cat_id in varchar2 default \'999\') is

begin

declare

next_cat_id number(3);

cursor c_next_id is

select max(CAT_ID)+1

from XSR5_CAT_TABLE;

begin

if i_operation=\'Add\' then

\--INSERT NEW CAT

\--Get highest CAT ID

open c_next_id;

fetch c_next_id into next_cat_id;

if c_next_id%NOTFOUND then

next_cat_id := 1;

end if;

close c_next_id;

INSERT INTO XSR5_CAT_TABLE

(CAT_ID,CAT_NAME)

VALUES (next_cat_id,i_cat_name);

cat_review_page(i_pid);

elsif i_operation=\'Remove\' then

UPDATE XSR5_CAT_TABLE

SET INACTIVE=\'Y\'

where CAT_ID=i_cat_id;

cat_review_page(i_pid);

elsif i_operation=\'Review Safety Administrators\' then

\--JUMP TO CAT SAFETY COORD MOD

review_safety_users(i_pid,i_cat_id);

elsif i_operation=\'Assign Sectors\' then

assign_sectors(i_pid,i_cat_id);

end if;

EXCEPTION

when others then

htp.p (SQLERRM);

htp.NL;

end;

end;

\--

procedure fc_management_page(i_pid in varchar2,i_operation in varchar2)
is

begin

declare

cursor c_email_groups is

select distinct(role_id)

from XSR5_EMAIL_ROLES;

cursor c_sectors(p_role_id in number) is

select sector_no

from XSR5_EMAIL_ROLES

where role_id=p_role_id;

cursor c_email_grantees(p_role_id in number) is

select \*

from XSR5_EMAIL_ROLE_GRANTEES

where role_id=p_role_id;

l_role_id number(2);

sector_list varchar2(100);

temp varchar2(5);

begin

if is_valid_pid(i_pid) then

lib.prolog(\'XFD Floor Coordinator List\');

htp.centerOpen;

open c_email_groups;

fetch c_email_groups into l_role_id;

while not c_email_groups%NOTFOUND loop

sector_list:=\'\';

\--get related sectors

open c_sectors(l_role_id);

fetch c_sectors into temp;

while not c_sectors%NOTFOUND loop

sector_list := sector_list \|\| temp \|\| \', \';

fetch c_sectors into temp;

end loop;

close c_sectors;

sector_list := rtrim(sector_list,\', \');

htp.p(\'\<TABLE BGCOLOR=\"#AAC7E6\" BORDER=1\');

\--

htp.tableRowOpen;

htp.p(\'\<TD COLSPAN=3\>\');

htp.p(\'\<FONT COLOR=\"#CC3299\" SIZE=5 FACE=ARIAL\>Sectors:\' \|\|
sector_list \|\| \'\</FONT\>\');

htp.p(\'\</TD\>\');

htp.p(\'\<TD COLSPAN=3 ALIGN=CENTER VALIGN=MIDDLE\>\');

htp.formOpen(\'xsr0006.process_floor_coordinator\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_role_id\',l_role_id);

htp.p(\'Badge No: \');

htp.formText(\'i_badge\',5,5);

htp.formSubmit(\'i_operation\',\'Add\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableData(htf.bold(\'Badge No.\'));

htp.tableData(htf.bold(\'Name\'));

htp.tableData(htf.bold(\'Email\'));

htp.tableData(htf.bold(\'Phone\'));

htp.tableData(htf.bold(\'Choose Status\'));

htp.tableData(htf.bold(\'Delete\'));

htp.tableRowClose;

\--

for r_grantee in c_email_grantees(l_role_id) loop

htp.tableRowOpen;

htp.tableData(nvl(r_grantee.badge_no,\'&nbsp\'));

htp.tableData(nvl(r_grantee.name,\'&nbsp\'));

htp.tableData(nvl(r_grantee.email,\'&nbsp\'));

htp.tableData(nvl(r_grantee.phone,\'&nbsp\'));

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_floor_coordinator\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_role_id\',l_role_id);

htp.formHidden(\'i_badge\',r_grantee.badge_no);

if r_grantee.inactive is null then

htp.formSubmit(\'i_operation\',\'Inactivate\');

else

htp.formSubmit(\'i_operation\',\' Activate \');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0006.process_floor_coordinator\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_role_id\',l_role_id);

htp.formHidden(\'i_badge\',r_grantee.badge_no);

htp.formSubmit(\'i_operation\',\'Delete\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

end loop;

htp.tableClose;

htp.NL;

fetch c_email_groups into l_role_id;

end loop;

close c_email_groups;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--

procedure process_floor_coordinator(i_pid in varchar2,

i_role_id in varchar2,

i_operation in varchar2 default NULL,

i_badge in varchar2 default NULL) is

begin

declare

cursor c_badge_info(p_badge_no in varchar2) is

select \*

from badge_info

where badge_no=p_badge_no;

r_badge BADGE_INFO%ROWTYPE;

begin

if is_valid_pid(i_pid) then

if i_operation=\'Add\' then

open c_badge_info(i_badge);

fetch c_badge_info into r_badge;

if not c_badge_info%NOTFOUND then

INSERT INTO XSR5_EMAIL_ROLE_GRANTEES

(ROLE_ID,NAME,PHONE,EMAIL,BADGE_NO)

VALUES(i_role_id,initcap(r_badge.name),r_badge.extension,lower(r_badge.username),r_badge.badge_no);

end if;

close c_badge_info;

elsif i_operation = \' Activate \' then

UPDATE XSR5_EMAIL_ROLE_GRANTEES

SET INACTIVE=NULL

WHERE BADGE_NO=i_badge

AND ROLE_ID=i_role_id;

elsif i_operation = \'Inactivate\' then

UPDATE XSR5_EMAIL_ROLE_GRANTEES

SET INACTIVE=\'Y\'

WHERE BADGE_NO=i_badge

AND ROLE_ID=i_role_id;

elsif i_operation = \'Delete\' then

DELETE from XSR5_EMAIL_ROLE_GRANTEES

WHERE BADGE_NO=i_badge

AND ROLE_ID=i_role_id;

end if;

end if;

fc_management_page(i_pid,\'RETURN\');

EXCEPTION

When Others Then

htp.p(\'\<FONT COLOR=#FF0000\>Error occurred processing the
data\...nothing done.\</FONT\>\');

htp.NL;

htp.p(\'\<FONT COLOR=#0000FF\> \' \|\| sqlerrm \|\| \' \' \|\| sqlcode
\|\| \'\</FONT\>\');

fc_management_page(i_pid,\'RETURN\');

end;

end;

\--

END;

\-- THIS IS THE END OF THE CODE

/

CREATE OR REPLACE PACKAGE xsr0007 IS

G_MENU_START_PAGE constant varchar2(50) := \'wam0002.DCN_MAIN_MENU\';

G_QUERY_START_PAGE_APP constant varchar2(50) := \'XSR_ADMIN\';

G_QUERY_START_PAGE constant varchar2(50) := \'QUERY_START_PAGE\';

G_QUERY_OP constant varchar2(50) := \'Query\';

G_NEW_START_PAGE_APP constant varchar2(50) := \'DCN_NEW\';

G_NEW_START_PAGE constant varchar2(50) := \'NEW_START_PAGE\';

G_NEW_OP constant varchar2(50) := \'New\';

G_ADD_OP constant varchar2(50) := \'Add Another\';

G_REVISE_START_PAGE_APP constant varchar2(50) := \'DCN_REVISE\';

G_REVISE_START_PAGE constant varchar2(50) := \'REVISE_START_PAGE\';

G_REVISE_OP constant varchar2(50) := \'Revise\';

G_UPDATE_START_PAGE_APP constant varchar2(50) := \'DCN_UPDATE\';

G_UPDATE_START_PAGE constant varchar2(50) := \'UPDATE_START_PAGE\';

G_UPDATE_OP constant varchar2(50) := \'Update\';

G_RETURN_TO_QUERY constant varchar2(50) := \' Return to Query Page \';

G_RETURN_TO_NEW constant varchar2(50) := \' Request DCN-New Drawing \';

G_RETURN_TO_REVISE constant varchar2(50) := \' Request DCN-Revise
Drawing \';

G_RETURN_TO_UPDATE constant varchar2(50) := \' Update Drawing Title \';

G_BACK_TO_MENU constant varchar2(50) := \' Back to Main Menu \';

G_ONLINE_HELP constant varchar2(50) := \'Online Help\';

G_ONLINE_HELP_FILE constant varchar2(50) := \'/dcc-doc/dcn_help.html\';

\--

procedure cat_start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL);

\--

procedure query_result_page (i_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL);

\--

procedure review_cat_users (i_pid in varchar2,

i_cat_id in varchar2);

\--

procedure process_cat_user(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_username in varchar2,

i_last in varchar2 default NULL,

i_first in varchar2 default NULL,

i_email in varchar2 default NULL,

X in varchar2 default NULL,

Y in varchar2 default NULL);

END;

/

CREATE OR REPLACE PACKAGE BODY XSR0007 IS

/\*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

DATE: INITIALS: REMARKS:

\-\-\-\-- \-\-\-\-\-\-\-\-- \-\-\-\-\-\-\--

\*/

\--

\-- GLOBAL NEXT N settings

\--

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \' \> \';

PREV_BUT_CAPTION constant varchar2(100) := \' \< \';

NEXT_SET_BUT_CAPTION constant varchar2(100) := \'\>\>\';

PREV_SET_BUT_CAPTION constant varchar2(100) := \'\<\<\';

FIRST_SET_BUT_CAPTION constant varchar2(100) := \'!\<\<\';

LAST_SET_BUT_CAPTION constant varchar2(100) := \'\>\>!\';

MAX_ROWS constant number(4) := 1000;

RECORD_SET_SIZE constant number(4) := 5;

MAX_ROWS_MESSAGE constant varchar2(100) := htf.italic(\'Maximimum number
of records (\'\|\|to_char(MAX_ROWS)\|\| \') returned\');

image_dir varchar2(255) := \'/gen-img/\';

main_menu varchar2(255) := \'/gen-doc/index2.html\';

\--

function username_for_this_pid (i_pid in varchar2) return varchar2 is

begin

declare

result varchar2(50);

cursor c_badge(p_pid in varchar2) is

select BADGE_NO

from ows_app_login

where pid=p_pid;

begin

open c_badge(i_pid);

fetch c_badge into result;

if c_badge%NOTFOUND then

result := \'?????\';

end if;

close c_badge;

return result;

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'XSR_CAT_ADMIN\';

htp.NL;

result := log0002.is_valid_pid(i_pid, p_app_name);

return result;

end;

end;

\--

function cat_for_this_user(i_pid in varchar2) return number is

begin

declare

result number;

cursor c_cat_id(p_pid in varchar2) is

select cat_id from

xsr5_cat_admin_priv cat, ows_app_login log

where (upper(cat.username)=upper(log.username) OR

upper(cat.username)=upper(log.badge_no))

and cat.inactive is NULL

and log.pid=i_pid;

begin

result := 0;

open c_cat_id(i_pid);

fetch c_cat_id into result;

close c_cat_id;

return(result);

end;

end;

\--

function is_XFD_admin(i_pid in varchar2) return boolean is

begin

declare

cursor c_xfd_role (p_pid in varchar2,p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_ADMIN\'

and log.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_xfd_role(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_xfd_role into temp;

if not c_xfd_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_xfd_role;

return(result);

end;

end;

\--

function is_CAT_admin(i_pid in varchar2, i_cat_id in varchar2) return
boolean is

begin

declare

cursor c_cat_admin_role (p_username in varchar2,p_cat in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV

where upper(username)=upper(p_username)

and cat_id=p_cat

and role=\'ADMIN\';

temp varchar2(1);

temp_user GEN_USER_TABLE.USERNAME%TYPE;

result boolean;

begin

temp_user := username_for_this_pid(i_pid);

open c_cat_admin_role(lower(username_for_this_pid(i_pid)),i_cat_id);

fetch c_cat_admin_role into temp;

if not c_cat_admin_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_cat_admin_role;

return(result);

end;

end;

\--

function is_CAT_user(i_pid in varchar2,i_experiment_id in varchar2)
return boolean

is

begin

declare

l_cat number;

cursor c_this_cat_user(p_cat_id in number, p_user in varchar2,
p_experiment_id in varchar2) is

select \'1\'

from XSR5_CAT_ADMIN_PRIV priv, XSR5_EXPERIMENT_HEADER exp

where exp.cat_id=priv.cat_id

and priv.cat_id=p_cat_id

and priv.username=p_user

and exp.experiment_id=p_experiment_id;

/\*cursor c_cat_role (p_pid in varchar2, p_ip in varchar2) is

select \'1\'

from OWS_APP_PID_XREF xref, OWS_APP_LOGIN log

where xref.pid=log.pid

and log.ip=p_ip

and (sysdate - timestamp) \< (4/24)

and xref.app_name=\'XSR_CAT_ADMIN\'

and log.pid=p_pid;\*/

temp_user varchar2(50);

temp varchar2(1);

result boolean;

begin

l_cat := cat_for_this_user(i_pid);

temp_user := username_for_this_pid(i_pid);

\--htp.p(\'TEMP USER IS \' \|\| temp_user \|\| \' cat id is \' \|\|
to_char(l_cat));

result := FALSE;

open c_this_cat_user(l_cat,temp_user,i_experiment_id);

fetch c_this_cat_user into temp;

if not c_this_cat_user%NOTFOUND then

result := TRUE;

end if;

close c_this_cat_user;

/\*if result then

open c_cat_role(i_pid,owa_util.get_cgi_env(\'REMOTE_ADDR\'));

fetch c_cat_role into temp;

if not c_cat_role%NOTFOUND then

result := TRUE;

else

result := FALSE;

\-- htp.p(\'\<FONT size=4 color=#FF0000\>CAT Admin access is not
available for this session\</FONT\>\');

end if;

close c_cat_role;

end if;\*/

return(result);

end;

end;

\--

function is_experiment_visible(i_experiment_id in varchar2, i_pid in
varchar2) return boolean is

begin

declare

result boolean;

begin

result := FALSE;

result := is_CAT_user(i_experiment_id, i_pid);

return (result);

end;

end;

\--

\-- CAT experiment selection criteria

procedure experiment_selection (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL) is

\--

l_range_from varchar2(20);

l_range_to varchar2(20);

cursor c_cat(p_cat_id in number) is

select \* from XSR5_CAT_TABLE

where cat_id = p_cat_id;

cursor c_cat_sectors(p_cat_id in number) is

select \*

from XSR5_CAT_SECTOR_XREF

where cat_id=p_cat_id;

r_cat XSR5_CAT_TABLE%ROWTYPE;

l_cat number(3);

err_pnt varchar2(20);

\--

begin

err_pnt := \'1\';

\-- FIND CAT associated with this user

l_cat := cat_for_this_user(m_pid);

if l_cat != 0 then

open c_cat(l_cat);

fetch c_cat into r_cat;

close c_cat;

else

htp.p(\'You are not authorized to view experiments. Sorry\');

return;

end if;

err_pnt := 3;

\--

lib.prolog(\'Enter Search Criteria: \');

\--

\--

htp.centerOpen;

if p_msg is not null then

htp.p(\'\<font type=arial size=4 color=#0000FF\>\' \|\| p_msg \|\|
\'\</font\>\');

end if;

htp.p(\'\<FORM ACTION=\"xsr0007.query_result_page\"
METHOD=\"POST\"\>\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableHeader(\'Sector No.:\',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_sector\');

htp.formSelectOption(\'All\');

for r_cat_sector in c_cat_sectors(l_cat) LOOP

htp.formSelectOption(r_cat_sector.sector_no,r_cat_sector.sector_no);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Beamline: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_beamline\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

\--default to specific cat if cat user!

htp.tableRowOpen;

htp.tableHeader(\'CAT: \',\'Right\');

htp.tableData(r_cat.cat_name);

htp.formHidden(\'i_cat\',r_cat.cat_id);

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Approval Status: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_approval_status\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'Pending\');

htp.formSelectOption(\'Approved\');

htp.formSelectOption(\'Rejected\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Experiments listed per page: \',\'Right\');

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',2,2,\'15\'));

htp.tableRowClose;

\--

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

\--

err_pnt :=4;

if is_CAT_admin(m_pid,r_cat.cat_id) then

htp.formOpen(\'xsr0007.review_cat_users\');

htp.formHidden(\'i_pid\',m_pid);

htp.formHidden(\'i_cat_id\',r_cat.cat_id);

htp.formSubmit(\'\',\'Update \' \|\| r_cat.cat_name \|\| \'
Administrator List\');

htp.formClose;

end if;

\--

err_pnt := 5;

htp.centerClose;

lib.epilog(null,null,null,FALSE);

exception

when others then

htp.p(\'Err point \' \|\| err_pnt);

htp.p(sqlerrm);

end;

\--

\-- This procedure allows the user to enter in parameters to query off
of.

\--

procedure enter_criteria (m_pid in varchar2,

i_operation in varchar2,

p_msg in varchar2 default NULL,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_RECORD_SET_SIZE in varchar2 default NULL) is

\--

l_range_from varchar2(20);

l_range_to varchar2(20);

err_pnt varchar2(20);

cursor c_cat is

select \* from XSR5_CAT_TABLE

order by cat_name;

\--

begin

\--l_range_from :=
to_char(to_date(i_from_year\|\|i_from_month\|\|i_from_day,\'YYYYMMDD\'));

\--l_range_to :=
to_char(to_date(i_to_year\|\|i_to_month\|\|i_to_day,\'YYYYMMDD\'));

\--

lib.prolog(\'Enter Search Criteria: \');

\--

\--

htp.centerOpen;

if p_msg is not null then

htp.p(\'\<font type=arial size=4 color=#0000FF\>\' \|\| p_msg \|\|
\'\</font\>\');

end if;

\-- htp.FormOpen(\'rfm0001.query_result_page\');

htp.p(\'\<FORM ACTION=\"xsr0007.query_result_page\"
METHOD=\"POST\"\>\');

htp.tableOpen;

\--

htp.tableRowOpen;

htp.tableHeader(\'Sector No.:\',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_sector\');

htp.formSelectOption(\'All\');

for i in 1..40 LOOP

htp.formSelectOption(to_char(i,\'09\'),null);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Beamline: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_beamline\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'BM\');

htp.formSelectOption(\'ID\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

\--default to specific cat if cat user!

htp.tableRowOpen;

htp.tableHeader(\'CAT: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_cat\');

htp.formSelectOption(\'All\');

for r_cat in c_cat LOOP

htp.formSelectOption(r_cat.cat_name,r_cat.cat_id);

end loop;

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Approval Status: \',\'Right\');

htp.p(\'\<td\>\');

htp.formSelectOpen(\'i_approval_status\');

htp.formSelectOption(\'All\');

htp.formSelectOption(\'Pending\');

htp.formSelectOption(\'Approved\');

htp.formSelectOption(\'Rejected\');

htp.formSelectClose;

htp.p(\'\</td\>\');

htp.tableRowClose;

\--

htp.tableRowOpen;

htp.tableHeader(\'Experiments listed per page: \',\'Right\');

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',2,2,\'15\'));

htp.tableRowClose;

\--

htp.tableClose;

\--

\-- The htp.nl adds a blank line before the submit button on the first
page.

\--

htp.nl;

\--

\-- The submit button the on first page.

\--

htp.formSubmit(NULL,\'Submit\');

\--

\-- Assigns values to the appropriate fields.

\--

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'i_operation\',i_operation);

htp.formHidden(\'i_pid\',m_pid);

htp.formClose;

htp.formOpen(\'xsr0007.review_cat_users\');

htp.formClose;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

\-- htp.para;

\-- htp.para;

\-- htp.p(\'\[\');

\-- htp.anchor(dcc0005.G_ONLINE_HELP_FILE,G_ONLINE_HELP);

\-- htp.p(\'\|\');

\-- htp.anchor(\'wam0002.rfm_main_menu?i_pid=\'\|\|m_pid,\'Main Menu\');

\-- htp.p(\'\]\');

htp.centerClose;

lib.epilog(null,null,null,FALSE);

end;

\--

\-- Checks to see if its a valid PID

\--

procedure xfd_start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(100);

\--

begin

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, G_QUERY_START_PAGE_APP) then

log0002.login(G_QUERY_START_PAGE_APP,\'\',m_pid,i_attrib);

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\-- if iattrib is empty, go to selection screen

\-- otherwise go drectly to detail screen

if i_attrib is not null then

htp.p(\'\<meta http-equiv=\"refresh\"
content=\"2;URL=xsr0005.experiment_approval_page?i_pid=\'\|\| i_pid

\|\|\'&i_operation=UPDATE\'\|\|\'&\' \|\| \'i_experiment_id=\' \|\|
i_attrib\|\|\'\"\>\');

else

enter_criteria(m_pid,G_QUERY_OP);

end if;

\--

end;

\--

procedure cat_start_page (i_pid in varchar2 default \'NEW\',i_attrib in
varchar2 default NULL) is

\--

m_pid varchar2(512);

err_pnt varchar2(10);

\--

begin

err_pnt := \'1\';

m_pid := i_pid;

if m_pid is NULL or

m_pid = \'NEW\' or

NOT log0002.is_valid_pid (m_pid, \'XSR_CAT_ADMIN\') then

log0002.login(\'XSR_CAT_ADMIN\',\'\',m_pid,i_attrib,\'N\');

htp.p(\'\<CENTER\>\');

htp.p(\'\<i\>\<Strong\>If you have any concerns about this information
or its presentation please contact Bruce Glagola\</i\>\</strong\>\');

htp.nl;

htp.anchor(\'mailto:glagola@aps.anl.gov,mis_mgrs@aps.anl.gov\',\'Send
mail to Bruce Glagola\');

lib.epilog;

htp.p(\'\</CENTER\>\');

return;

end if;

\--

\-- Goes to the enter_criteria procedure.

\-- if iattrib is empty, go to selection screen

\-- otherwise go drectly to detail screen

err_pnt := \'2\';

if i_attrib is null then

\--same as enter criteria but for specific CAT..not XFD admin

experiment_selection(m_pid,G_QUERY_OP);

else

err_pnt := \'3\';

if is_experiment_visible(i_pid,i_attrib) then

htp.p(\'\<meta http-equiv=\"refresh\"
content=\"2;URL=xsr0005.experiment_approval_page?i_pid=\'\|\| i_pid

\|\|\'&i_operation=UPDATE\'\|\|\'&\' \|\| \'i_experiment_id=\' \|\|
i_attrib\|\|\'\"\>\');

else

htp.p(\'Sorry, that experiment is not visible to this account.\');

end if;

end if;

exception

when others then

htp.p(\'Err pnt \' \|\| err_pnt);

\--

end;

\--

\--

\-- This procedure populates the second page of the application.

\--

procedure query_result_page (i_pid in varchar2 default \'NEW\',

i_operation in varchar2,

i_sector in varchar2 default NULL,

i_beamline in varchar2 default NULL,

i_cat in varchar2 default NULL,

i_approval_status in varchar2 default NULL,

Z_START in varchar2,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in varchar2 default \'25\',

Z_TOTAL_ROWS in varchar2 default NULL,

Z_PAGE_NO in varchar2 default NULL) is

\--

\-- Set up the cursors for your detail page (Page 2).

\--

cursor cur_signoff_view(p_rf_proc_detail_id in number) is

select \*

from eq_rf_last_signoff_view

where RF_PROC_DETAIL_ID = p_rf_proc_detail_id;

\--

cursor c_primary_spokesperson(p_exp_id in number) is

select name

from XSR5_SPOKESPERSONS

where experiment_id=p_exp_id

and priority=1;

l_name XSR5_SPOKESPERSONS.NAME%TYPE;

\-- Local variables for the second page (the query_result_page
procedure).

\--

I_QUERY varchar2(2000) := \'\';

i_where varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

I_NEXT_SET_BUT boolean;

I_PREV_SET_BUT boolean;

I_FIRST_SET_BUT boolean;

I_LAST_SET_BUT boolean;

RECORD_SET_SIZE number;

Y_TOTAL_ROWS number;

SLIDER_WIDTH number := 10;

total_pages number;

cur_cnt number;

rec_counter number := 0;

temp_anchor varchar2(512);

dcc_print varchar2(512);

l_range_from varchar2(20);

l_range_to varchar2(20);

\--

l_title varchar2(2000);

l_pre_cri varchar2(50);

l_dwg_no varchar2(100);

l_page_no number;

l_hold_page number;

x_temp number;

y_temp number;

\--

j_query varchar2(2000) := \'\';

j_where varchar2(2000) := \'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned number := 0;

instructions varchar2(255);

r_experiment XSR5_EXPERIMENT_HEADER%rowtype;

\--

err_pnt varchar2(20);

begin

\--

\-- Checks to see if there is a valid PID

\--

if is_valid_pid(i_pid) then

\-- if i_operation = G_QUERY_OP then

\-- if NOT log0002.is_valid_pid(m_pid,G_QUERY_START_PAGE_APP) then

\-- return;

\-- end if;

\-- end if;

\--

\--

\--the dynamic select statement to retrieve the complete_document_no
which is a

\-- unique field that can retrieve any other fields needed via cursors.

\--

i_query := \'select
experiment_id,sector_no,beamline,experiment_title,approval_status,pen
from XSR5_EXPERIMENT_HEADER exp, XSR5_CAT_ADMIN_PRIV cat, OWS_APP_LOGIN
log\';

\--

\-- Begins to build the dynamic where clause

\-- This initial part is static while the following if\'s add onto the
where clause

\-- when the conditions are met.

\--

i_where := \'where cat.cat_id=exp.cat_id and
lower(cat.username)=lower(log.badge_no) and log.pid=\' \|\| i_pid;

\--

\-- The following series of if\'s dynamicly add to the where clause when
the conditions

\-- are met.

\--

if i_sector is NOT NULL and i_sector != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' sector_no=\'\'\' \|\|
i_sector \|\| \'\'\'\';

end if;

if i_cat is NOT NULL and i_cat != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' exp.cat_id=\' \|\| i_cat;

end if;

if i_beamline is NOT NULL and i_beamline != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' beamline=\'\'\' \|\|
i_beamline \|\| \'\'\'\';

end if;

if i_approval_status is NOT NULL and i_approval_status != \'All\' then

if i_where is NULL then

l_pre_cri := \' WHERE \';

else

l_pre_cri := \' AND \';

end if;

if i_approval_status = \'Pending\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=0\';

elsif i_approval_status = \'Approved\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=1\';

elsif i_approval_status = \'Rejected\' then

i_where := i_where\|\|\' \'\|\|l_pre_cri\|\|\' approval_status=2\';

end if;

end if;

/\*kem 3/19/98 Process CAT Selection \.... not so straight
forward\...needs join\*/

\--

\-- This counts the number of records returned in order to place the

\-- correct number of buttons on the bottom of the page.

\--

\--

\-- \*\*\*\* This is where the invalid column field is coming from. Once
the dynamic

\-- where clause is uncommented the invalid column comes up.

\--

if Z_TOTAL_ROWS is NULL then

j_query := \' select count(experiment_id) \'

\|\|\' from \'\|\|\' XSR5_EXPERIMENT_HEADER exp, XSR5_CAT_ADMIN_PRIV
cat, OWS_APP_LOGIN log \' ;

j_where := i_where;

j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

\--htp.p(\'J WHERE = \' \|\| j_query);

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

\-- htp.p(\'Y TOTAL ROWS = \' \|\| Y_TOTAL_ROWS);

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\--

I_CURSOR := dbms_sql.open_cursor;

i_query := i_query \|\|\' \'\|\| i_where\|\|\' order by
sector_no,beamline\';

\--

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1, r_experiment.experiment_id);

dbms_sql.define_column(I_CURSOR, 2, r_experiment.sector_no,2);

dbms_sql.define_column(I_CURSOR, 3, r_experiment.beamline,2);

dbms_sql.define_column(I_CURSOR, 4, r_experiment.experiment_title,2000);

dbms_sql.define_column(I_CURSOR, 5, r_experiment.approval_status);

dbms_sql.define_column(I_CURSOR, 6, r_experiment.pen,25);

\--

I_VOID := dbms_sql.execute (I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

\--

\-- Checks to see if there were any rows retrieved from the parameters
entered. If none

\-- then it will display the message with the values entered.

\--

if I_ROWS_FETCHED = 0 then

\-- dbms_sql.close_cursor(I_CURSOR);

/\* enter_criteria(i_pid,

i_operation,

\'No records matching that criteria found. \');

\--i_master_system,

\--i_system,

\--i_components,

\--i_sub_components,

\--i_task_grouping,

\--i_range_from,

\--i_range_to);

return; \*/

null;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

end if;

RECORD_SET_SIZE := to_number(Z_RECORD_SET_SIZE);

if Z_START IS NULL then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -
1)/SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

I_START := ((l_hold_page -1) \* record_set_size) + 1;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

I_START := ((l_hold_page -1) \* record_set_size) +1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

I_START := 1;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

I_PREV_BUT := TRUE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

\-- Puts the viewable \"Header\" portion on page two.

\--

lib.prolog(\'Query Results \');

\--

\-- Places the header fields on the begining of the report. Note:
tableHeader

\-- automaticly bolds the text for you.

\--

htp.centerOpen;

if I_TOTAL_ROWS \<\> 0 then

htp.tableOpen(\'border\');

\-- htp.tableHeader(\'Sector\');

htp.tableHeader(\'PEN\');

htp.tableHeader(\'Beamline\');

htp.tableHeader(\'Approval Status\');

htp.tableHeader(\'Title\');

htp.tableHeader(\'Primary Spokesperson\');

htp.tableHeader(\'ESA Form\');

\--

\--err_pnt := \'1\';

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1, r_experiment.experiment_id);

dbms_sql.column_value(I_CURSOR, 2, r_experiment.sector_no);

dbms_sql.column_value(I_CURSOR, 3, r_experiment.beamline);

dbms_sql.column_value(I_CURSOR, 4, r_experiment.experiment_title);

dbms_sql.column_value(I_CURSOR, 5, r_experiment.approval_status);

dbms_sql.column_value(I_CURSOR, 6, r_experiment.pen);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if ((RECORD_SET_SIZE \>= 1) and

(I_ROWS_FETCHED \> 0 or

I_TOTAL_ROWS \>= 1)) then

\--

\-- Starts to retrieve the data requested for the page.

\--

\--if is_experiment_visible(r_experiment.experiment_id,i_pid) then

htp.tableRowOpen;

temp_anchor := \'xsr0005.experiment_approval_page?i_pid=\' \|\| i_pid
\|\| \'&\' \|\| \'i_operation=UPDATE\' \|\| \'&\' \|\|
\'i_experiment_id=\' \|\| r_experiment.experiment_id;

\-- htp.tableData(htf.anchor(temp_anchor,r_experiment.pen));

htp.tableData(nvl(r_experiment.pen,\'&nbsp\'));

htp.tableData(htf.anchor(temp_anchor,r_experiment.sector_no \|\| \'-\'
\|\| r_experiment.beamline));

if r_experiment.approval_status=0 then

htp.tableData(\'Pending\',\'Center\');

elsif r_experiment.approval_status=1 then

htp.tableData(\'Approved\',\'Center\');

elsif r_experiment.approval_status=2 then

htp.tableData(\'Rejected\',\'Center\');

else

htp.tableData(\'N/A\',\'Center\');

end if;

htp.tableData(nvl(r_experiment.experiment_title,\'&nbsp\'),\'Center\');

\--get spokesperson

open c_primary_spokesperson(r_experiment.experiment_id);

fetch c_primary_spokesperson into l_name;

close c_primary_spokesperson;

htp.tableData(nvl(l_name,\'&nbsp\'));

htp.p(\'\<TD\>\');

htp.formOpen(\'/gen-bin/uncgi/xsr_web_reports.pdf\');

htp.formHidden(\'p_exp_id\',r_experiment.experiment_id);

htp.formHidden(\'i_report\',\'DOOR_REPORT\');

htp.formHidden(\'i_pid\',i_pid);

htp.formSubmit(\'\',\'Generate\');

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

\--close if for \"is_experiment_visible\"

\--end if;

else

htp.p(\' \*\*\*\*\* \');

htp.br;

end if;

\--

\-- F5 DBMS SQL CURSOR DETERMINE BUTTONS TO DISPLAY

\--

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

\-- htp.tableRowClose;

\-- end if;

end loop;

\--

htp.tableClose;

\--dbms_sql.close_cursor(I_CURSOR);

else

htp.p(\'\<FONT FACE=ARIAL,HELVETICA SIZE=6 COLOR=#006010\>No experiments
were found for those criteria.\</FONT\>\');

htp.NL;

htp.p(\'\<FONT face=ARIAL,Helvetica Size=4 color=#006010\>Click \[Back\]
to try again.\</FONT\>\');

end if;

dbms_sql.close_cursor(I_CURSOR);

\--

htp.formOpen(\'xsr0007.query_result_page\');

\--

if I_PREV_BUT or I_NEXT_BUT then

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_sector\',i_sector);

htp.formHidden(\'i_beamline\',i_beamline);

htp.formHidden(\'i_cat\',i_cat);

htp.formHidden(\'i_approval_status\',i_approval_status);

htp.formHidden(\'Z_START\', to_char(I_START));\--

htp.formHidden(\'i_operation\',i_operation);\--

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\|

\' to \'\|\|to_char(I_TOTAL_ROWS));

end if;

\--

htp.para;

\--

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

\--

err_pnt:=\'3\';

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

\--

\-- For toggle buttons \*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\--

\-- This is where the buttons are built for the application.

\--

if Z_ACTION = NEXT_BUT_CAPTION then

l_hold_page := TO_NUMBER(NVL(Z_PAGE_NO,\'0\')) +1;

elsif Z_ACTION = PREV_BUT_CAPTION then

l_hold_page := TO_NUMBER(Z_PAGE_NO) -1;

elsif Z_ACTION = PREV_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) -1) /
SLIDER_WIDTH) + 1) - 1) \* SLIDER_WIDTH;

elsif Z_ACTION = NEXT_SET_BUT_CAPTION then

l_hold_page := (trunc(((to_number(Z_PAGE_NO) - 1)/SLIDER_WIDTH) + 1) \*
SLIDER_WIDTH) +1;

elsif Z_ACTION = LAST_SET_BUT_CAPTION then

l_hold_page := trunc((Y_TOTAL_ROWS / to_number(Z_RECORD_SET_SIZE))) + 1;

elsif Z_ACTION = FIRST_SET_BUT_CAPTION then

l_hold_page := 1;

else

l_hold_page := to_number(nvl(Z_ACTION,\'1\'));

end if;

\--

err_pnt := 4;

htp.tableOpen;

\--

I_NEXT_SET_BUT := FALSE;

I_PREV_SET_BUT := FALSE;

I_FIRST_SET_BUT := FALSE;

I_LAST_SET_BUT := FALSE;

\--

if l_hold_page \> SLIDER_WIDTH then

I_PREV_SET_BUT := TRUE;

I_FIRST_SET_BUT := TRUE;

end if;

\--

\-- Displaying the NEXT SET BUTTON

\--

if trunc((nvl(l_hold_page,1) - 1) / SLIDER_WIDTH) \< trunc((Y_TOTAL_ROWS
/ (Z_RECORD_SET_SIZE \* SLIDER_WIDTH)))

then

I_NEXT_SET_BUT := TRUE;

I_LAST_SET_BUT := TRUE;

end if;

\--

\-- ADDING THE PREVIOUS SET BUTTON FUNC.

\--

htp.tableRowOpen;

\--

y_temp := mod(l_hold_page,SLIDER_WIDTH);

\--

if y_temp = 0 then

x_temp := SLIDER_WIDTH;

else

x_temp := y_temp;

end if;

\--

htp.formHidden(\'Z_PAGE_NO\',l_hold_page);

cur_cnt := 1 + (l_hold_page - x_temp);

\--

\-- Creates the numeric toggle buttons on the bottom of the page.

\--

while cur_cnt \<= total_pages loop

if cur_cnt = l_hold_page then

htp.tableData(htf.bold(to_char(l_hold_page)));

else

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(\'
\'\|\|to_char(cur_cnt)\|\|\' \')));

end if;

\--

if mod(cur_cnt,SLIDER_WIDTH) = 0 then

exit;

end if;

cur_cnt := cur_cnt + 1;

end loop;

htp.tableRowClose;

htp.tableClose;

\--

\-- Creates the buttons on the bottom of the page to toggle from one
page, one set, or

\-- last set of buttons.

htp.tableOpen(\'border\');

htp.tableRowOpen;

\-- Creates the !\<\< button. The else condition on all of the following
buttons \"disables\"

\-- the button when the condition cannot be done.

\--

if I_FIRST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(FIRST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(FIRST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \<\< button.

\--

if I_PREV_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_SET_BUT_CAPTION\|\|\'&\'\|\|\'nbsp\'));

end if;

\--

\-- Creates the \< button.

\--

if I_PREV_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(PREV_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(PREV_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \> button.

\--

if I_NEXT_BUT then

htp.tableData(htf.bold(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_BUT_CAPTION))));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\> button.

\--

if I_NEXT_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(NEXT_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(NEXT_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

\--

\-- Creates the \>\>! button.

\--

if I_LAST_SET_BUT then

htp.tableData(htf.formSubmit(\'Z_ACTION\',htf.escape_sc(LAST_SET_BUT_CAPTION)));

else

htp.tableData(\'&\'\|\|\'nbsp\'\|\|htf.bold(LAST_SET_BUT_CAPTION)\|\|\'&\'\|\|\'nbsp\');

end if;

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

\--

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p(MAX_ROWS_MESSAGE);

end if;

\--

\-- This is for the online help and link to the main menu. It also has
the epilog

\-- in it which is the send comments and/or suggestions to MIS_MGRS
link.

\--

end if;

exception

when others then

htp.p(\'ERR POINT \' \|\| err_pnt);

htp.p (SQLERRM);

end;

\--

procedure review_cat_users (i_pid in varchar2, i_cat_id in varchar2) is

begin

declare

cursor c_cat(p_cat_id in number) is

select \*

from xsr5_cat_table

where cat_id=p_cat_id;

cursor c_cat_users(p_cat_id in number) is

select \*

from xsr5_cat_admin_priv

where cat_id=p_cat_id;

r_cat XSR5_CAT_TABLE%ROWTYPE;

begin

if is_valid_pid(i_pid) then

htp.centerOpen;

open c_cat(i_cat_id);

fetch c_cat into r_cat;

close c_cat;

lib.prolog(\'CAT Users for \' \|\| r_cat.cat_name);

htp.p(\'\<TABLE BGCOLOR=\"#AAC7E6\" BORDER=1\>\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'Last Name\'));

htp.tableData(htf.bold(\'First Name\'));

htp.tableData(htf.bold(\'Badge No.\'));

htp.tableData(htf.bold(\'Email\'));

htp.tableData(htf.bold(\'Email Active\'));

htp.tableData(htf.Bold(\'User Active\'));

htp.tableData(htf.Bold(\'Admin Privs\'));

htp.tableRowClose;

\--

\--

for r_cat_user in c_cat_users(i_cat_id) loop

htp.tableRowOpen;

htp.tableData(nvl(r_cat_user.LAST_NAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_user.FIRST_NAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_user.USERNAME,\'&nbsp\'));

htp.tableData(nvl(r_cat_user.EMAIL,\'&nbsp\'));

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0007.process_cat_user\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_user.username);

if r_cat_user.email_flag=\'Y\' then

htp.formHidden(\'i_operation\',\'Email Off\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/chkbox.gif\" BORDER=\"0\"
ALT=\"Turn Off Email\"\>\');

else

htp.formHidden(\'i_operation\',\'Email On\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/nochkbox.gif\"
BORDER=\"0\" ALT=\"Turn On Email\"\>\');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0007.process_cat_user\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_user.username);

if r_cat_user.inactive is null then

htp.formHidden(\'i_operation\',\'Inactivate\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/chkbox.gif\" BORDER=\"0\"
ALT=\"Set User Active\"\>\');

else

htp.formHidden(\'i_operation\',\' Activate \');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/nochkbox.gif\"
BORDER=\"0\" ALT=\"Set User Inactive\"\>\');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER VALIGN=MIDDLE HEIGHT=15\>\');

htp.formOpen(\'xsr0007.process_cat_user\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.formHidden(\'i_username\',r_cat_user.username);

if r_cat_user.role=\'ADMIN\' then

htp.formHidden(\'i_operation\',\'Remove Admin\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/chkbox.gif\" BORDER=\"0\"
ALT=\"Grant Admin Priv\"\>\');

else

htp.formHidden(\'i_operation\',\'Add Admin\');

htp.p(\'\<INPUT TYPE=\"image\" SRC=\"/gen-img/nochkbox.gif\"
BORDER=\"0\" ALT=\"Revoke Admin Priv\"\>\');

end if;

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

end loop;

htp.tableRowOpen;

htp.formOpen(\'xsr0007.process_cat_user\');

htp.tableData(htf.formText(\'i_last\',12,25));

htp.tableData(htf.formText(\'i_first\',12,25));

htp.tableData(htf.formText(\'i_username\',12,20));

htp.tableData(htf.formText(\'i_email\',20,50));

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_cat_id\',i_cat_id);

htp.tableData(htf.formSubmit(\'i_operation\',\'Add\'));

htp.p(\'\<TD COLSPAN=2\>&nbsp\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.NL;

htp.formClose;

htp.centerClose;

lib.epilog(null,null,null,FALSE);

end if;

end;

end;

\--

procedure process_cat_user(i_pid in varchar2,

i_operation in varchar2,

i_cat_id in varchar2,

i_username in varchar2,

i_last in varchar2 default NULL,

i_first in varchar2 default NULL,

i_email in varchar2 default NULL,

X in varchar2 default NULL,

Y in varchar2 default NULL) is

begin

declare

cursor c_user_exists(p_username in varchar2) is

select \'1\'

from GEN_USER_TABLE

where username=p_username

or badge_no=p_username;

temp varchar2(1);

begin

if i_operation=\'Add\' then

\--Create user if necessary

open c_user_exists(i_username);

fetch c_user_exists into temp;

if c_user_exists%NOTFOUND then

\--Add user

INSERT INTO GEN_USER_TABLE

(BADGE_NO,USERNAME,BREAKER,CREATE_DATE,CREATE_USER,MUST_CHANGE_PWD)

values

(i_username,i_username,i_last,sysdate,\'XFD_ADMIN\',\'Y\');

end if;

close c_user_exists;

INSERT INTO XSR5_CAT_ADMIN_PRIV

(CAT_ID,USERNAME,PK_ID,EMAIL,LAST_NAME,FIRST_NAME,EMAIL_FLAG,ROLE)

VALUES
(i_cat_id,i_username,safety.xsr5_cat_admin_seq.nextval,i_email,i_last,i_first,\'Y\',\'ADMIN\');

elsif i_operation=\'Email Off\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET EMAIL_FLAG=\'N\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Email On\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET EMAIL_FLAG=\'Y\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Inactivate\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET INACTIVE=\'Y\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\' Activate \' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET INACTIVE=NULL

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Delete\' then

DELETE FROM XSR5_CAT_ADMIN_PRIV

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Add Admin\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET ROLE=\'ADMIN\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

elsif i_operation=\'Remove Admin\' then

UPDATE XSR5_CAT_ADMIN_PRIV

SET ROLE=\'USER\'

WHERE CAT_ID=i_cat_id

AND USERNAME=i_username;

end if;

review_cat_users(i_pid,i_cat_id);

EXCEPTION

when others then

htp.p (SQLERRM);

htp.NL;

htp.p(\'Please press BACK to address the problem.\');

end;

end;

\--

\--

\--

END;

\-- THIS IS THE END OF THE CODE

/

CREATE OR REPLACE PACKAGE isi0001 IS

pkg_name varchar2(255) := \'isi0001\';

prod_user varchar2(255) := \':APSWEB:WEBPROD:\';

dev_user varchar2(255) := \':MISWEB:WEBDEV:\';

prod_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'/owa/\';

\--dev_service varchar2(255) := \'/\'\|\|pkg_name\|\|\'w/owa/\';

dev_service varchar2(255) := \'/ps0001w/owa/\';

pkg_syn varchar2(255) := pkg_name;

ping varchar2(255) := pkg_name\|\|\' is alive\';

app_title varchar2(255) := \'APS Training Profiles\';

\--

cursor c_badge(p_pid in varchar2) is

select username

from ows_app_login

where pid=p_pid;

tms_badge varchar2(10);

header_on boolean;

cursor c_badge2 (p_badge_no in varchar2) is

select initcap(name)

from badge_info

where badge_no = p_badge_no;

procedure start_doc(i_pid in varchar2 default \'NEW\');

FUNCTION run_print_it (i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,i_pid in varchar2,i_report in
varchar2) return boolean;

procedure display_list (i_pid in varchar2);

procedure display_list_next_n (i_pid in varchar2,

i_doc_no in varchar2 default null,

i_cabinet in varchar2 default null,

i_drawer in varchar2 default null,

i_operation in varchar2 default null,

Z_START in varchar2,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in number);

procedure submit_problem(i_pid in varchar2);

procedure verify_submit(i_pid in varchar2,i_item_id in
varchar2,i_description in varchar2,i_machine in varchar2);

procedure select_documents_page (i_pid in varchar2);

procedure problem_list_request(i_pid in varchar2);

procedure problem_list (i_pid in varchar2,i_item_id in varchar2 default
\'ALL\');

procedure print_report (i_pid in varchar2,i_printer in varchar2 default
null,

i_operation in varchar2 default null,i_report in varchar2 default null);

procedure display_menu (i_pid in varchar2);

procedure doc_detail (i_pid in varchar2,i_doc_id in varchar2 default
null,i_operation in varchar2 default \'Default\',

i_doc_no in varchar2 default null, i_print_flag in varchar2 default
null, i_title_1 in varchar2 default null,

i_title_2 in varchar2 default null, i_title_3 in varchar2 default null,
i_doc_date in varchar2 default null,

i_location in varchar2 default null, i_author in varchar2 default null,
i_entry in varchar2 default null,

i_entry_date in varchar2 default null,i_collection_flag in varchar2
default null,i_collection_id in varchar2 default null);

procedure check_in_out (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default
null,i_check_out_badge in varchar2 default null,

i_reason_code in varchar2 default null,i_check_out_date in varchar2
default null,

i_check_in_date in varchar2 default null,i_chk_id in varchar2 default
null);

procedure err_msg (err_code in varchar2, err_str in varchar2);

procedure doc_approval (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default null,i_approval_id
in varchar2 default null,

i_approval_type in varchar2 default null,i_approval_date in varchar2
default null,

i_approval_badge in varchar2 default null);

procedure copy_request_page (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default null,i_copy_badge in
varchar2 default null,

i_copy_date in varchar2 default null,i_copy_id in varchar2 default
null);

procedure security_list_page (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_badge in varchar2 default null,i_priv_id in varchar2 default
null,i_app_id in varchar2

default null,i_qry_priv in varchar2 default null,i_ins_priv in varchar2
default null,

i_upd in varchar2 default null,i_del in varchar2 default null);

END;

/

CREATE OR REPLACE PACKAGE BODY isi0001 IS

no_insert constant varchar2(128) := \'\<font face=arial size=3
color=#FF0000\>You do not have insert privileges on this
screen.\</font\>\';

no_query constant varchar2(128) := \'\<font face=arial size=3
color=#FF0000\>You do not have query privileges on this
screen.\</font\>\';

no_update constant varchar2(128) := \'\<font face=arial size=3
color=#FF0000\>You do not have update privileges on this
screen.\</font\>\';

no_delete constant varchar2(128) := \'\<font face=arial size=3
color=#FF0000\>You do not have delete privileges on this
screen.\</font\>\';

QUERY_BUT_CAPTION constant varchar2(100) := \'Query\';

CLEAR_BUT_CAPTION constant varchar2(100) := \'Clear\';

NEXT_BUT_CAPTION constant varchar2(100) := \'Next\';

PREV_BUT_CAPTION constant varchar2(100) := \'Previous\';

MAX_ROWS constant number(4) := 5000;

MAX_ROWS_MESSAGE constant varchar2(100):=

htf.italic(\'Maximimum number of records (\'\|\|to_char(MAX_ROWS)\|\|

\') returned\');

function get_service return varchar2 is

begin

\-- Initialize Service Path

if instr(prod_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(prod_service);

elsif instr(dev_user,\':\'\|\|UPPER(USER)\|\|\':\') \> 0 then

return(dev_service);

end if;

end;

\--

function get_name (i_badge in varchar2) return varchar2 is

begin

declare

result varchar2(100);

begin

open c_badge2(i_badge);

fetch c_badge2 into result;

if c_badge2%NOTFOUND then

result := \'N/A\';

end if;

close c_badge2;

return(result);

end;

end;

\--

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'ISI_DOC\';

result := log0002.is_valid_pid(i_pid,p_app_name);

\--htp.p (wam0001.get_application_name(\'ISIMENU\'));

return result;

end;

end;

\--

function query_ok (i_pid in varchar2,i_app_id in varchar2) return
boolean is

begin

declare

cursor c_query (p_pid in varchar2,p_app_id in varchar2) is

select \'1\'

from ows_app_login l,doc_app_privs p

where l.badge_no = p.badge_no

and p.app_id=p_app_id

and query_priv = \'Y\'

and l.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_query(i_pid,i_app_id);

fetch c_query into temp;

if not c_query%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_query;

return result;

end;

end;

\--

function insert_ok (i_pid in varchar2,i_app_id in varchar2) return
boolean is

begin

declare

cursor c_insert (p_pid in varchar2,p_app_id in varchar2) is

select \'1\'

from ows_app_login l,doc_app_privs p

where l.badge_no = p.badge_no

and p.app_id=p_app_id

and insert_priv = \'Y\'

and l.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_insert(i_pid,i_app_id);

fetch c_insert into temp;

if not c_insert%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_insert;

return result;

end;

end;

\--

function delete_ok (i_pid in varchar2,i_app_id in varchar2) return
boolean is

begin

declare

cursor c_delete (p_pid in varchar2,p_app_id in varchar2) is

select \'1\'

from ows_app_login l,doc_app_privs p

where l.badge_no = p.badge_no

and p.app_id=p_app_id

and delete_priv = \'Y\' and l.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_delete(i_pid,i_app_id);

fetch c_delete into temp;

if not c_delete%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_delete;

return result;

end;

end;

\--

function update_ok (i_pid in varchar2,i_app_id in varchar2) return
boolean is

begin

declare

cursor c_update (p_pid in varchar2,p_app_id in varchar2) is

select \'1\'

from ows_app_login l,doc_app_privs p

where l.badge_no = p.badge_no

and p.app_id=p_app_id

and update_priv = \'Y\'

and l.pid=p_pid;

temp varchar2(1);

result boolean;

begin

open c_update(i_pid,i_app_id);

fetch c_update into temp;

if not c_update%NOTFOUND then

result := TRUE;

else

result := FALSE;

end if;

close c_update;

return result;

end;

end;

\--

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \* Modification history Description

\-- \* 05-MAR-97 kem Initial coding

\-- \*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

FUNCTION run_print_it (i_printer in varchar2 default \'werther\',

i_operation in varchar2 default NULL,i_pid in varchar2,i_report in
varchar2) return BOOLEAN IS

begin

declare

STR varchar2(255);

return_status varchar2(255);

tmp_cs varchar2(2000);

begin

if not header_on then

\--lib.prolog (\'Print Modification Definition\');

header_on := TRUE;

end if;

if is_valid_pid(i_pid) then

\-- STR := \'ESH/ESH@aps1\';

STR := \'ets/ets\';

mis_util.utl_print_it(\'\$mis_reports/\',i_report,\'B\',i_printer,\'P\',\'SQR\',STR,\'NONE\',

\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',\'NONE\',return_status);

\--message(\'return_status:\'\|\|return_status);

\-- log all print requests to tracking table \"ows_tms_login\"

if return_status = \'status:0\' then

\--htp.print (\'Modification Definitions successfully sent to printer
\"\' \|\| i_printer \|\| \'\"\');

return TRUE;

else

\--htp.print (\'Print request was unsuccessful. Printing \'\'daemon\'\'
may be down.\');

\--result := \'FAILED\';

return FALSE;

\--htp.print (return_status);

end if;

end if;

htp.NL;

\-- lib.epilog;

end;

END;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure start_doc(i_pid in varchar2 default \'NEW\') is

begin

if i_pid is NULL or

i_pid = \'NEW\' or

NOT is_valid_pid (i_pid) then

log0002.login(\'ISI_DOC\',\'\',i_pid);

return;

end if;

\-- display_list (i_pid);

select_documents_page(i_pid);

/\* if is_valid_pid(i_pid) then

display_list(i_pid);

end if;\*/

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure select_documents_page (i_pid in varchar2) is

begin

declare

cursor c_badge is

select \*

from badge_info

where inactive is null

order by name;

begin

if is_valid_pid (i_pid) then

lib.prolog(\'ISI Document Management System\');

htp.centerOpen;

htp.formOpen(\'isi0001.display_list_next_n\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Document No. (full or partial):\'));

htp.tableData(htf.formText(\'i_doc_no\',20,20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Cabinet:\'));

htp.tableData(htf.formText(\'i_cabinet\',20,20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Drawer:\'));

htp.tableData(htf.formText(\'i_drawer\',20,20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Number of records to view at a time:\'));

htp.tableData(htf.formText(\'Z_RECORD_SET_SIZE\',5,5,10));

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Find Documents\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'Z_START\', NULL);

htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formClose;

if query_ok(i_pid,4) then

htp.nl;

htp.formOpen(\'isi0001.security_list_page\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'Security for User:\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_badge\',null,5);

for r_badge in c_badge loop

htp.formSelectOption(initcap(r_badge.name),\'\',\'VALUE=\' \|\|
r_badge.badge_no);

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'View Security\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

end if;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*

procedure doc_detail (i_pid in varchar2,i_doc_id in varchar2 default
null,i_operation in varchar2 default \'Default\',

i_doc_no in varchar2 default null, i_print_flag in varchar2 default
null, i_title_1 in varchar2 default null,

i_title_2 in varchar2 default null, i_title_3 in varchar2 default null,
i_doc_date in varchar2 default null,

i_location in varchar2 default null, i_author in varchar2 default null,
i_entry in varchar2 default null,

i_entry_date in varchar2 default null,i_collection_flag in varchar2
default null,

i_collection_id in varchar2 default null) is

begin

declare

cursor c_doc_detail (p_doc_id in varchar2) is

select \*

from doc_master

where doc_id = p_doc_id;

cursor c_doc_title is

select \*

from doc_title_lines_table;

cursor c_approvers (p_doc_id in varchar2) is

select \*

from isi.doc_approval

where doc_id = p_doc_id;

cursor c_approval_type (p_type_id in varchar2) is

select approver_type

from doc_approver_types

where type_id=p_type_id;

cursor c_collection is

select \*

from doc_master

where collection=\'Y\'

order by doc_no;

r_doc_detail doc_master%ROWTYPE;

temp_title varchar2(10);

temp varchar2(255);

new_id number(8);

begin

if is_valid_pid(i_pid) then

if query_ok(i_pid,1) then

\--process operation Save Changes, Create New, New List or Delete
Document

if i_operation = \'Save Changes\' then

if update_ok(i_pid,1) then

\--save changes

update doc_master

set doc_no=i_doc_no,

doc_title_line1 = i_title_1,

doc_title_line2 = i_title_2,

doc_title_line3 = i_title_3,

doc_date = to_date(i_doc_date,\'DD-MON-YYYY\'),

location = i_location,

creator_badge = i_author,

data_entry_badge = i_entry,

data_entry_date = to_date(i_entry_date,\'DD-MON-YYYY\'),

print_flag=substr(i_print_flag,1,1),

collection=substr(i_collection_flag,1,1),

collection_doc_id=to_number(i_collection_id)

where doc_id = i_doc_id;

doc_detail(i_pid,i_doc_id,\'Saved\');

else

\--htp.p(\'\<font face=arial size=3 color=#FF0000\>You do not have
update privileges for this screen.\');

htp.p(no_update);

end if;

elsif i_operation=\'Create New\' then

if insert_ok(i_pid,1) then

\--create new. seq used for pk, gaps are ok. pk is internal

select isi_doc_id_seq.nextval into new_id from dual;

insert into doc_master

(doc_id)

values(new_id);

doc_detail(i_pid,to_char(new_id),\'Default\');

else

htp.p(no_insert);

end if;

elsif i_operation = \'New List\' then

select_documents_page (i_pid);

elsif i_operation = \'Delete Document\' then

\--delete document

htp.p(\'This function is not yet enabled.\');

end if;

if i_operation=\'Default\' or i_operation=\'Saved\' or
i_operation=\'Detail\' then

lib.prolog(\'ISI Document Detail\');

if i_operation = \'Saved\' then

htp.p (\'\<font color=#006010 face=arial size=4\>Record saved
successfully\</font\>\');

end if;

open c_doc_detail(i_doc_id);

fetch c_doc_detail into r_doc_detail;

if not c_doc_detail%NOTFOUND then

htp.formOpen(\'isi0001.doc_detail\');

htp.centerOpen;

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_doc_id\',i_doc_id);

\--htp.formSubmit(\'i_operation\',\'Delete Document\');

htp.centerClose;

htp.tableOpen;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Document No.\'));

htp.tableData(htf.formText(\'i_doc_no\',30,30,r_doc_detail.doc_no));

htp.tableData(htf.bold(\'Print\'),\'RIGHT\');

htp.p(\'\<TD\>\');

if r_doc_detail.print_flag = \'Y\' then

htp.formRadio(\'i_print_flag\',\'Yes\',\'CHECKED\');

htp.p(\'Yes\');

htp.formRadio(\'i_print_flag\',\'No\');

htp.p(\'No\');

else

htp.formRadio(\'i_print_flag\',\'Yes\');

htp.p(\'Yes\');

htp.formRadio(\'i_print_flag\',\'No\',\'CHECKED\');

htp.p(\'No\');

end if;

htp.p(\'\</TD\>\');

htp.tableData(htf.bold(\'Collection\'),\'RIGHT\');

htp.p(\'\<TD\>\');

if r_doc_detail.collection = \'Y\' then

htp.formRadio(\'i_collection_flag\',\'Yes\',\'CHECKED\');

htp.p(\'Yes\');

htp.formRadio(\'i_collection_flag\',\'No\');

htp.p(\'No\');

else

htp.formRadio(\'i_collection_flag\',\'Yes\');

htp.p(\'Yes\');

htp.formRadio(\'i_collection_flag\',\'No\',\'CHECKED\');

htp.p(\'No\');

end if;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Title Line 1\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_title_1\');

for r_title in c_doc_title loop

if r_title.title_line_id = r_doc_detail.doc_title_line1 then

htp.formSelectOption(r_title.title_line_text,\'SELECTED\',\'VALUE=\"\'
\|\| r_title.title_line_id \|\| \'\"\');

else

htp.formSelectOption(r_title.title_line_text,\'\',\'VALUE=\"\' \|\|
r_title.title_line_id \|\| \'\"\');

end if;

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD COLSPAN=2\>\</TD\>\');

htp.tableData(htf.bold(\'Part of Collection Named:\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_collection_id\');

for r_collection in c_collection loop

if r_collection.doc_id = r_doc_detail.collection_doc_id then

htp.formSelectOption(r_collection.doc_no,\'SELECTED\',\'VALUE=\"\' \|\|
r_collection.doc_id \|\| \'\"\');

else

htp.formSelectOption(r_collection.doc_no,\'\',\'VALUE=\"\' \|\|
r_collection.doc_id \|\| \'\"\');

end if;

end loop;

htp.formSelectOption(\'None\',\'\',\'VALUE=\"0\"\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Title Line 2\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_title_2\');

for r_title in c_doc_title loop

if r_title.title_line_id = r_doc_detail.doc_title_line2 then

htp.formSelectOption(r_title.title_line_text,\'SELECTED\',\'VALUE=\"\'
\|\| r_title.title_line_id \|\| \'\"\');

else

htp.formSelectOption(r_title.title_line_text,\'\',\'VALUE=\"\' \|\|
r_title.title_line_id \|\| \'\"\');

end if;

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Title Line 3\'));

htp.print(\'\<TD COLSPAN=4\>\');

htp.formTextAreaOpen(\'i_title_3\',\'5\',\'50\',\'LEFT\',\'WRAP\');

htp.Print(r_doc_detail.doc_title_line3);

htp.formTextAreaClose;

htp.print(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Document Date:\'));

htp.tableData(htf.formText(\'i_doc_date\',11,11,to_char(r_doc_detail.doc_date,\'DD-MON-YYYY\')));

htp.tableData(\'\');

htp.tableData(\'\');

htp.tableData(\'\');

htp.tableData(htf.Bold(\'Drawer Location:\'));

htp.tableData(htf.formText(\'i_location\',25,25,r_doc_detail.location),\'\',\'\',\'\',\'\',2);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Author Badge No:\'));

htp.tableData(htf.formText(\'i_author\',10,10,r_doc_detail.creator_badge));

htp.tableData(get_name(r_doc_detail.creator_badge),\'\',\'\',\'\',\'\',2);

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Document Input By:\'));

htp.tableData(htf.formText(\'i_entry\',10,10,r_doc_detail.data_entry_badge));

htp.tableData(get_name(r_doc_detail.data_entry_badge),\'\',\'\',\'\',\'\',2);

htp.tableData(\'\');

htp.tableData(htf.Bold(\'Date Input:\'));

htp.tableData(htf.formText(\'i_entry_date\',11,11,to_char(r_doc_detail.data_entry_date,\'DD-MON-YYYY\')));

htp.tableRowClose;

htp.tableClose;

htp.centerOpen;

if update_ok(i_pid,1) then

htp.formSubmit(\'i_operation\',\'Save Changes\');

end if;

if insert_ok(i_pid,1) then

htp.formSubmit(\'i_operation\',\'Create New\');

end if;

htp.formSubmit(\'i_operation\',\'New List\');

htp.formReset(\'Undo Changes\');

htp.formClose;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Approver Type\');

htp.tableHeader(\'Approval Date\');

htp.tableHeader(\'Approver\');

for r_approval in c_approvers(r_doc_detail.doc_id) loop

htp.tableRowOpen;

open c_approval_type(r_approval.type_id);

fetch c_approval_type into temp;

close c_approval_type;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(r_approval.approval_date);

htp.tableData(get_name(r_approval.badge_no));

htp.tableRowClose;

end loop;

htp.tableClose;

htp.formOpen(\'isi0001.doc_approval\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_doc_id\',i_doc_id);

if update_ok(i_pid,1) or insert_ok(i_pid,1) or query_ok(i_pid,1) or
delete_ok(i_pid,1) then

htp.formSubmit(\'i_operation\',\'Approvals\');

end if;

htp.formClose;

htp.centerClose;

htp.tableClose;

close c_doc_detail;

htp.formClose;

end if;

lib.epilog;

end if;

else

htp.p(no_query);

end if;

end if;

exception when others then

err_msg(to_char(SQLCODE),SQLERRM);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure document_header (i_pid in varchar2,i_doc_id in varchar2) is

begin

declare

cursor c_doc_header (p_doc_id in varchar2) is

select \*

from doc_master

where doc_id = p_doc_id;

cursor c_title_line (p_title_id in varchar2) is

select title_line_text

from doc_title_lines_table

where title_line_id=p_title_id;

r_doc_header doc_master%ROWTYPE;

title doc_title_lines_table.title_line_text%TYPE;

begin

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Document No.:\'));

open c_doc_header(i_doc_id);

fetch c_doc_header into r_doc_header;

if not c_doc_header%NOTFOUND then

htp.tableData(r_doc_header.doc_no);

\--decode title line 1

open c_title_line(r_doc_header.doc_title_line1);

fetch c_title_line into title;

if not c_title_line%NOTFOUND then

htp.tableData(title);

else

htp.tableData(\'\');

end if;

close c_title_line;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\');

htp.tableData(\'\');

open c_title_line(r_doc_header.doc_title_line2);

fetch c_title_line into title;

if not c_title_line%NOTFOUND then

htp.tableData(title);

else

htp.tableData(\'\');

end if;

close c_title_line;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Document Date:\'));

htp.tableData(to_char(r_doc_header.doc_date));

htp.tableData(r_doc_header.doc_title_line3);

htp.tableRowClose;

else

htp.tableData(\'Document not found \');

htp.tableRowClose;

end if;

close c_doc_header;

htp.tableClose;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure doc_approval (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default null,i_approval_id
in varchar2 default null,

i_approval_type in varchar2 default null,i_approval_date in varchar2
default null,

i_approval_badge in varchar2 default null) is

begin

declare

cursor c_approval (p_doc_id in varchar2) is

select \*

from isi.doc_approval

where doc_id=p_doc_id

order by approval_date;

cursor c_approval_type (p_type in varchar2) is

select approver_type

from doc_approver_types

where type_id=p_type;

cursor c_approval_type_list is

select \*

from doc_approver_types;

cursor c_trans (p_trans in varchar2)is

select \'1\'

from isi_trans_id

where trans_id = p_trans;

temp_title varchar2(10);

temp varchar2(255);

new_id number(8);

new_trans_id varchar2(20);

begin

if is_valid_pid(i_pid) then

if query_ok (i_pid,1) then

if i_operation = \'Saved\' or i_operation=\'Default\' or
i_operation=\'Approvals\' or i_operation=\'Duplicate\' then

lib.prolog(\'ISI Document Approvals\');

if i_operation = \'Saved\' then

htp.p (\'\<font color=#006010 face=arial size=4\>Record saved
successfully\</font\>\');

end if;

if i_operation = \'Duplicate\' then

htp.p (\'\<font color=#FF0000 face=arial size=5\>This record has already
been saved. No changes applied\</font\>\');

end if;

htp.NL;

htp.p(\'\<i\>\<font color=#0000FF\>To change information, click on the
badge number on the desired line\</font\>\</i\>\');

document_header(i_pid,i_doc_id);

htp.centerOpen;

\--assign a new transaction id

select to_char(isi_trid_seq.nextval) into new_trans_id from dual;

\--new_trans_id := to_char(isi_trid_seq.nextval);

\--process operation Check Out, Check In, New List

elsif i_operation = \'New List\' then

select_documents_page (i_pid);

else

\--check transaction id before

open c_trans(i_trans_id);

fetch c_trans into temp;

close c_trans;

\--save changes

if temp is null then

if i_approval_id = \'Insert\' then

\--do insert

if insert_ok (i_pid,1) then

insert into isi.doc_approval

values(isi_app_id_seq.nextval,i_approval_type,i_doc_id,i_approval_badge,to_date(i_approval_date,\'DD-MON-YYYY\'),0);

\--htp.p(\'REFRESH SCREEN\');

else

htp.p(no_insert);

end if;

else

\--do update

if update_ok (i_pid,1) then

update isi.doc_approval

set type_id = i_approval_type,

doc_id = i_doc_id,

badge_no = i_approval_badge,

approval_date = to_date(i_approval_date,\'DD-MON-YYYY\')

where approval_id=i_approval_id;

else

htp.p(no_update);

end if;

end if;

\--store transaction info

insert into isi_trans_id

values (i_pid,i_trans_id,\'APPROV - \' \|\| i_approval_id);

doc_approval (i_pid,\'Saved\',i_doc_id);

else

doc_approval (i_pid,\'Duplicate\',i_doc_id);

end if;

end if;

if i_operation=\'Saved\' or i_operation=\'Default\' or i_operation =
\'Approvals\' or i_operation=\'Duplicate\' then

\--input boxes

htp.formOpen(\'isi0001.doc_approval\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_doc_id\',i_doc_id);

htp.formHidden(\'i_trans_id\',new_trans_id);

htp.tableOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Approver\');

htp.tableHeader(\'Name\');

htp.tableHeader(\'Type\',\'\',\'\',\'\',\'\',2);

htp.tableHeader(\'Approval Date\');

for r_approval in c_approval(i_doc_id) loop

htp.tableRowOpen;

if r_approval.approval_id = i_approval_id then

htp.tableRowOpen;

htp.tableData(htf.formText(\'i_approval_badge\',10,10,r_approval.badge_no));

open c_badge2(r_approval.badge_no);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.p(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_approval_type\');

for r_type in c_approval_type_list loop

if r_type.type_id = r_approval.type_id then

htp.formSelectOption(r_type.approver_type,\'SELECTED\',\'VALUE=\"\' \|\|
r_type.type_id \|\| \'\"\');

else

htp.formSelectOption(r_type.approver_type,\'\',\'VALUE=\"\' \|\|
r_type.type_id \|\| \'\"\');

end if;

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableData(htf.formText(\'i_approval_date\',11,11,to_char(r_approval.approval_date,\'DD-MON-YYYY\')));

htp.formHidden(\'i_approval_id\',i_approval_id);

htp.tableRowClose;

else

if update_ok (i_pid,1) then

htp.tableData(htf.anchor(\'isi0001.doc_approval?i_pid=\' \|\| i_pid \|\|

\'&i_approval_id=\' \|\| r_approval.approval_id \|\| \'&i_doc_id=\' \|\|
i_doc_id

,r_approval.badge_no));

else

htp.tableData(r_approval.badge_no);

end if;

open c_badge2(r_approval.badge_no);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(r_approval.type_id);

open c_approval_type(r_approval.type_id);

fetch c_approval_type into temp;

close c_approval_type;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(nvl(to_char(r_approval.approval_date),\'.\'));

end if;

htp.tableRowClose;

end loop;

if insert_ok (i_pid,1) then

if i_approval_id is null then

\--add mode

htp.tableRowOpen;

\--input boxes

htp.tableData(htf.formText(\'i_approval_badge\'));

htp.tableData(\'.\');

htp.p(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_approval_type\');

for r_type in c_approval_type_list loop

htp.formSelectOption(r_type.approver_type,\'\',\'VALUE=\"\' \|\|
r_type.type_id \|\| \'\"\');

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableData(htf.formText(\'i_approval_date\',\'11\',\'11\',to_char(sysdate,\'DD-MON-YYYY\')));

htp.formHidden(\'i_approval_id\',\'Insert\');

htp.tableRowClose;

end if;

htp.tableClose;

end if;

if update_ok (i_pid,1) or insert_ok (i_pid,1) then

htp.formSubmit(\'i_operation\',\'Save\');

end if;

htp.formSubmit(\'i_operation\',\'New List\');

htp.formClose;

htp.centerClose;

lib.epilog; end if;

else

htp.p(no_query);

end if;

end if;

exception when others then

err_msg(to_char(SQLCODE),SQLERRM);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure err_msg (err_code in varchar2, err_str in varchar2) is

begin

htp.p(\'\<center\>\');

htp.tableOpen(\'border=2\');

htp.tableHeader(\'ERROR NO:\');

htp.tableHeader(\'ERROR MESSAGE:\');

htp.tableRowOpen;

htp.tableData(err_code);

htp.tableData(err_str);

htp.tableRowOpen;

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.p(\'Click on BACK to try again\');

htp.p(\'\</center\>\');

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

/\*

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Notes:\'));

htp.print(\'\<TD\>\');

htp.formTextAreaOpen(\'i_notes\',\'5\',\'50\',\'LEFT\',\'WRAP\');

htp.Print(r_job.notes);

htp.formTextAreaClose;

htp.print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowClose;

\*/

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure display_list_next_n (i_pid in varchar2,

i_doc_no in varchar2 default null,

i_cabinet in varchar2 default null,

i_drawer in varchar2 default null,

i_operation in varchar2 default null,

Z_START in varchar2,

Z_TOTAL_ROWS in varchar2 default NULL,

Z_ACTION in varchar2,

Z_RECORD_SET_SIZE in number) is

begin

declare

I_QUERY varchar2(2000) := \'\';

I_WHERE varchar2(2000) := \'\';

I_URL varchar2(2000) := \'\';

I_CURSOR integer;

I_VOID integer;

I_ROWS_FETCHED integer := 0;

I_TOTAL_ROWS integer := 0;

I_START number(6) := to_number(Z_START);

I_NEXT_BUT boolean;

I_PREV_BUT boolean;

SLIDER_WIDTH number;

tmp_str varchar2(255);

curr_line1 varchar2(2000);

\--

j_query varchar2(2000) := \'\';

j_where varchar2(2000) := \'\';

j_cursor integer;

j_rows_fetched integer := 0;

total_rows_returned integer := 0;

y_total_rows varchar2(20);

total_pages number;

cur_cnt number;

l_pre_cri varchar2(2000);

r_doc doc_master%ROWTYPE;

RECORD_SET_SIZE number(4);

local_doc varchar2(25);

local_cab varchar2(25);

local_drawer varchar2(25);

begin

\--htp.Print(\'Starting record is \' \|\| to_char(I_START));

if is_valid_pid(i_pid) then

lib.prolog(\'ISI Documents\');

\-- Build up the Where clause

RECORD_SET_SIZE := Z_RECORD_SET_SIZE;

I_QUERY := \'select doc_no,cabinet,drawer,doc_id from doc_master\';

i_where := NULL;

local_doc := i_doc_no \|\| \'%\';

local_cab := i_cabinet \|\| \'%\';

local_drawer := i_drawer \|\| \'%\';

i_where :=\'where doc_no like \'\'\' \|\| local_doc \|\| \'\'\' and
cabinet like \'\'\' \|\| local_cab

\|\| \'\'\' and drawer like \'\'\' \|\| local_drawer \|\| \'\'\'\';

I_QUERY := I_QUERY\|\|\' \'\|\|I_WHERE\|\|\' ORDER BY DOC_NO\';

\--htp.Print(I_QUERY);

\--

if Z_TOTAL_ROWS is NULL then

j_query := \'select count(doc_id) from doc_master\';

j_where := i_where;

j_query := j_query \|\|\' \'\|\| j_where;

j_cursor := dbms_sql.open_cursor;

dbms_sql.parse(j_cursor,j_query,dbms_sql.v7);

dbms_sql.define_column(j_cursor,1,total_rows_returned);

i_void := dbms_sql.execute(j_cursor);

i_rows_fetched := dbms_sql.fetch_rows(j_cursor);

dbms_sql.column_value(j_cursor,1,total_rows_returned);

dbms_sql.close_cursor(j_cursor);

Y_TOTAL_ROWS := to_char(total_rows_returned);

\--htp.print(\'Recalculated total rows\...\');

else

Y_TOTAL_ROWS := Z_TOTAL_ROWS;

end if;

\-- htp.bold(Y_TOTAL_ROWS);

\--

\-- htp.nl;

I_CURSOR := dbms_sql.open_cursor;

dbms_sql.parse(I_CURSOR, I_QUERY, dbms_sql.v7);

dbms_sql.define_column(I_CURSOR, 1,r_doc.doc_no,25);

dbms_sql.define_column(I_CURSOR, 2,r_doc.cabinet,25);

dbms_sql.define_column(I_CURSOR, 3,r_doc.drawer,25);

dbms_sql.define_column(I_CURSOR, 4,r_doc.doc_id);

I_VOID := dbms_sql.execute(I_CURSOR);

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

\-- htp.nl;

if I_ROWS_FETCHED = 0 then

htp.nl;

htp.bold(\'No records returned\');

dbms_sql.close_cursor(I_CURSOR);

lib.epilog;

return;

else

I_TOTAL_ROWS := I_ROWS_FETCHED;

end if;

if (Z_START IS NULL) then

I_START := 1;

elsif Z_ACTION = NEXT_BUT_CAPTION or Z_ACTION IS NULL then

I_START := I_START + RECORD_SET_SIZE;

elsif Z_ACTION = PREV_BUT_CAPTION then

I_START := I_START - RECORD_SET_SIZE;

else

I_START := RECORD_SET_SIZE \* (to_number(Z_ACTION) - 1) + 1;

end if;

I_PREV_BUT := TRUE;

\-- I_PREV_BUT := FALSE;

I_NEXT_BUT := FALSE;

if I_START = 1 or Z_ACTION IS NULL then

I_PREV_BUT := FALSE;

end if;

htp.centerOpen;

\-- htp.nl;

\-- htp.nl;

\--htp.dlistOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Document #\');

htp.tableHeader(\'Cabinet\');

htp.tableHeader(\'Drawer\');

htp.tableHeader(\'Click Button or Document No.\',\'\',\'\',\'\',\'\',2);

while I_ROWS_FETCHED \<\> 0 loop

if I_TOTAL_ROWS \>= I_START then

dbms_sql.column_value(I_CURSOR, 1,r_doc.doc_no);

dbms_sql.column_value(I_CURSOR, 2,r_doc.cabinet);

dbms_sql.column_value(I_CURSOR, 3,r_doc.drawer);

dbms_sql.column_value(I_CURSOR, 4,r_doc.doc_id);

htp.tableRowOpen;

curr_line1 := htf.anchor(\'isi0001.doc_detail?i_pid=\' \|\| i_pid \|\|
\'&\' \|\| \'i_doc_id=\' \|\| r_doc.doc_id,r_doc.doc_no);

htp.tableData(curr_line1);

htp.tableData(r_doc.cabinet);

htp.tableData(r_doc.drawer);

htp.p(\'\<TD\>\');

htp.formOpen(\'isi0001.check_in_out\');

htp.formSubmit(\'i_operation\',\'Check In/Out\');

htp.formHidden(\'i_doc_id\',r_doc.doc_id);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD\>\');

htp.formOpen(\'isi0001.copy_request_page\');

htp.formSubmit(\'i_operation\',\'Copy Requests\');

htp.formHidden(\'i_doc_id\',r_doc.doc_id);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

htp.NL;

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

if I_TOTAL_ROWS = I_START + RECORD_SET_SIZE - 1 then

if I_ROWS_FETCHED \<\> 0 then

I_NEXT_BUT := TRUE;

end if;

exit;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

exit;

end if;

else

I_ROWS_FETCHED := dbms_sql.fetch_rows(I_CURSOR);

end if;

I_TOTAL_ROWS := I_TOTAL_ROWS + I_ROWS_FETCHED;

htp.tableRowClose;

end loop;

htp.tableClose;

dbms_sql.close_cursor(I_CURSOR);

if I_PREV_BUT or I_NEXT_BUT then

htp.formOpen(\'isi0001.display_list_next_n\');

htp.formHidden(\'Z_START\', to_char(I_START));

htp.formHidden(\'Z_TOTAL_ROWS\',Y_TOTAL_ROWS);

if I_START = I_TOTAL_ROWS then

htp.p(\'Record \'\|\|to_char(I_TOTAL_ROWS));

else

htp.p(\'Records \'\|\|to_char(I_START) \|\| \' to
\'\|\|to_char(I_TOTAL_ROWS));

end if;

htp.para;

if I_PREV_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(PREV_BUT_CAPTION));

end if;

if I_NEXT_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(NEXT_BUT_CAPTION));

end if;

total_pages := to_number(Y_TOTAL_ROWS)/RECORD_SET_SIZE;

if total_pages != trunc(total_pages) then

total_pages := trunc( total_pages) + 1;

end if;

\-- htp.print(to_char(total_pages));

cur_cnt := 0;

while cur_cnt \< total_pages loop

cur_cnt := cur_cnt + 1;

htp.formSubmit(\'Z_ACTION\',htf.escape_sc(\'
\'\|\|to_char(cur_cnt)\|\|\' \'));

if SLIDER_WIDTH = cur_cnt then

exit;

end if;

end loop;

\-- Just in case reload button was pressed

\-- htp.formHidden(\'Z_ACTION\',NEXT_BUT_CAPTION);

htp.formHidden(\'Z_RECORD_SET_SIZE\',Z_RECORD_SET_SIZE);

htp.formHidden(\'i_pid\',i_pid);

/\* if I_PREV_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(PREV_BUT_CAPTION));

end if;

if I_NEXT_BUT then

htp.formSubmit(\'Z_ACTION\', htf.escape_sc(NEXT_BUT_CAPTION));

end if;\*/

htp.formClose;

end if;

if I_TOTAL_ROWS = I_START + MAX_ROWS - 1 then

htp.p( MAX_ROWS_MESSAGE);

end if;

\--

\--

\--htp.anchor(get_service\|\|pkg_syn\|\|\'.job_selection\',\'Return to
Query Page\');

htp.centerClose;

lib.epilog;

end if;

exception

when NO_DATA_FOUND then

htp.nl;

htp.bold(\'No records match the criteria.\');

htp.nl;

when others then

htp.nl;

htp.print(to_char(SQLCODE)\|\|\' \'\|\| SQLERRM);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure display_list (i_pid in varchar2) is

begin

declare

cursor c_doc is

select \* from doc_master

order by doc_no;

cursor c_badge is

select \*

from badge_info

where inactive is null

order by name;

begin

if is_valid_pid(i_pid) then

lib.prolog(\'ISI Document Selection\');

htp.centerOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Document No.\');

htp.tableHeader(\'Title\');

htp.tableHeader(\'Screens\',\'\',\'\',\'\',\'\',\'3\');

for r_doc in c_doc loop

htp.tableRowOpen;

htp.tableData(r_doc.doc_no);

htp.tableData(r_doc.doc_title_line3);

htp.p(\'\<TD\>\');

htp.formOpen(\'isi0001.doc_detail\');

htp.formSubmit(\'i_operation\',\'Detail\');

htp.formHidden(\'i_doc_id\',r_doc.doc_id);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD\>\');

htp.formOpen(\'isi0001.check_in_out\');

htp.formSubmit(\'i_operation\',\'Check In/Out\');

htp.formHidden(\'i_doc_id\',r_doc.doc_id);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

htp.p(\'\<TD\>\');

htp.formOpen(\'isi0001.copy_request_page\');

htp.formSubmit(\'i_operation\',\'Copy Requests\');

htp.formHidden(\'i_doc_id\',r_doc.doc_id);

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

end loop;

htp.tableClose;

htp.NL;

htp.formOpen(\'isi0001.security_list_page\');

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(\'Security for User:\');

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_badge\',null,5);

for r_badge in c_badge loop

htp.formSelectOption(initcap(r_badge.name),\'\',\'VALUE=\' \|\|
r_badge.badge_no);

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'View Security\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure display_menu(i_pid in varchar2) is

begin

lib.prolog(\'ISI Document Management System\');

if is_valid_pid(i_pid) then

\--htp.print(\'\<IMG SRC=\"/gen-img/atomanim.gif\"\>\');

htp.print(\'\<CENTER\>\');

htp.print(\'\<table border=0 cellpadding=5 cellspacing=10\>\');

htp.print(\'\<tr bgcolor=CCCCFF\>\');

htp.print(\'\<td align=center width = 25%\>\<b\> Inventory
\</b\>\</td\>\');

htp.print(\'\<td align=center width = 25%\>\<b\> Modifications
\</b\>\</td\>\');

htp.print(\'\<td bgcolor=CCCCFF align=center width = 25%\>\<b\>
Maintenance \</b\>\</td\>\');

htp.print(\'\<td bgcolor=CCCCFF align=center width = 25%\>\<b\> Faults
\</b\>\</td\>\');

htp.tableRowClose;

htp.tableRowopen;

htp.print(\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.selection_criteria?i_pid=\' \|\| i_pid \|\|
\'&i_part_no=inv\',\'View Inventory\');

htp.print(\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.selection_criteria?i_pid=\' \|\| i_pid \|\|
\'&i_part_no=mod\',\'View Modifications\');

htp.print(\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.maint_selection?i_pid=\' \|\| i_pid,\'View
Maintenance Log\');

htp.print(\'\<td align=center\>\');

htp.print(\'Not available\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\');

htp.print (\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.print_report?i_pid=\' \|\| i_pid,\'Print
Modification Definitions\');

htp.print (\'\</td\>\');

htp.print(\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.shutdown_schedule?i_pid=\' \|\|
i_pid,\'Shutdown Schedule\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\');

htp.print (\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.pending_modifications?i_pid=\' \|\|
i_pid,\'View Pending Modifications\');

htp.print (\'\</td\>\');

htp.print(\'\<td align=center\>\');

htp.anchor(\'../owa/ps0001.select_planning_dates?i_pid=\' \|\|
i_pid,\'Planning Schedule\');

htp.tableRowClose;

htp.tableClose;

htp.anchor(\'../owa/ps0001.submit_problem?i_pid=\' \|\| i_pid,\'TESTING:
SUBMIT NEW PROBLEM\');

htp.nl;

htp.anchor(\'../owa/ps0001.problem_list?i_pid=\' \|\| i_pid,\'TESTING:
VIEW KNOWN PROBLEMS\');

htp.print(\'\</CENTER\>\');

end if;

lib.epilog;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure print_report (i_pid in varchar2,i_printer in varchar2 default
null,

i_operation in varchar2 default null,i_report in varchar2 default null)
is

begin

declare

temp boolean;

begin

if is_valid_pid(i_pid) then

lib.prolog(\'Print Report\');

htp.centerOpen;

if i_operation = \'Print\' then

temp := run_print_it(i_printer,\'\',i_pid,i_report);

if temp then

htp.print(i_report \|\| \' successfully sent to \' \|\| i_printer);

else

htp.print (\'Unable to send report. Please report problem to
mis_mgrs\');

end if;

else

htp.formOpen(get_service\|\|pkg_syn\|\|\'.print_report\');

htp.formHidden(\'i_report\',\'mod_list\');

htp.formHidden(\'i_pid\',i_pid);

htp.bold(\'Printer Name:\');

htp.formText(\'i_printer\',\'20\',\'20\');

htp.NL;

htp.NL;

htp.formSubmit(\'i_operation\',\'Print\');

end if;

htp.NL;

htp.NL;

htp.anchor(\'../owa/ps0001.display_menu?i_pid=\' \|\| i_pid,\'Return to
Main Menu\');

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure no_bookmark is

begin

lib.prolog(\'Login Required\');

htp.print(\'\<CENTER\>\');

htp.print(\'Please start this session at the login screen. Cheers.\');

htp.NL;

htp.anchor(\'../owa/ps0001.login\',\'Log on to Power Supplies ETS\');

htp.print(\'\</CENTER\>\');

lib.epilog;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure submit_problem(i_pid in varchar2) is

begin

declare

cursor c_forms is

select \*

from eq_ps_forms_id_table

order by description;

begin

if is_valid_pid(i_pid) then

lib.prolog(\'Power Supplies ETS Forms/Web Problem Report\');

htp.formOpen(get_service\|\|pkg_syn\|\|\'.verify_submit\');

htp.formHidden(\'i_pid\',i_pid);

htp.centerOpen;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Form or Web Page:\'));

htp.print(\'\<TD\>\');

htp.formSelectOpen(\'i_item_id\');

for r_item in c_forms loop

htp.formSelectOption(r_item.description,\'\',\'VALUE=\"\' \|\|
r_item.item_id \|\| \'\"\');

end loop;

htp.formSelectClose;

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Machine Type:\'));

htp.print(\'\<TD\>\');

htp.formRadio(\'i_machine\',\'X-Term\',\'SELECTED\');

htp.print(\'X-Terminal/Workstation\');

htp.print(\'\</TD\>\');

htp.tableRowOpen;

htp.print(\'\<TD\>\</TD\>\<TD\>\');

htp.formRadio(\'i_machine\',\'PC\');

htp.print(\'PC\');

htp.print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.print(\'\<TD\>\</TD\>\<TD\>\');

htp.formRadio(\'i_machine\',\'Mac\');

htp.print(\'Macintosh\');

htp.print(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Description:\'));

htp.print(\'\<TD\>\');

htp.formTextAreaOpen(\'i_description\',\'20\',\'50\',\'LEFT\',\'WRAP\');

htp.formTextAreaClose;

htp.print(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.NL;

htp.formSubmit;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure verify_submit(i_pid in varchar2,i_item_id in
varchar2,i_description in varchar2,i_machine in varchar2) is

begin

declare

temp_badge varchar2(10);

next_prob_number number(5);

begin

if is_valid_pid(i_pid) then

open c_badge(i_pid);

fetch c_badge into temp_badge;

close c_badge;

select ets.ets_ps_test_seq.nextval into next_prob_number from dual;

insert into eq_ps_forms_problems

values(next_prob_number,temp_badge,sysdate,\'\',i_item_id,i_description,\'NEW\',i_machine);

lib.prolog(\'Problem Report Submitted\');

htp.centerOpen;

htp.print(\'\<h3\>Assigned problem number: \' \|\|
to_char(next_prob_number));

htp.NL;

htp.anchor(\'../owa/ps0001.login_accepted?i_pid=\' \|\| i_pid,\'Return
to main menu\');

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure problem_list_request(i_pid in varchar2) is

begin

null;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure problem_list (i_pid in varchar2,i_item_id in varchar2 default
\'ALL\') is

begin

declare

cursor c_problems is

select \* from eq_ps_forms_problems

order by problem_id;

cursor c_form_name (p_item in varchar2) is

select description

from eq_ps_forms_id_table

where item_id = p_item;

cursor c_reported_by (p_username in varchar2) is

select initcap(name)

from badge_info

where username = p_username;

temp varchar2(50);

begin

if is_valid_pid(i_pid) then

lib.prolog(\'Power Supplies ETS Forms/Web Page Problems\');

htp.centerOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Problem #\');

htp.tableHeader(\'Form/Web Page\');

htp.tableHeader(\'Description\');

htp.tableHeader(\'Status\');

htp.tableHeader(\'Reported By\');

htp.tableHeader(\'Reported Date\');

htp.tableHeader(\'Corrected Date\');

for r_prob in c_problems loop

htp.tableRowOpen;

htp.tableData(r_prob.problem_id);

\--htp.tableData(r_prob.item_id);

open c_form_name(r_prob.item_id);

fetch c_form_name into temp;

close c_form_name;

htp.tableData(temp);

htp.tableData(r_prob.description);

htp.tableData(r_prob.status);

open c_reported_by(r_prob.badge_no);

fetch c_reported_by into temp;

close c_reported_by;

htp.tableData(temp);

htp.tableData(r_prob.report_date);

htp.tableData(r_prob.corrected_date);

htp.tableRowClose;

end loop;

htp.tableClose;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure check_in_out (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default
null,i_check_out_badge in varchar2 default null,

i_reason_code in varchar2 default null,i_check_out_date in varchar2
default null,

i_check_in_date in varchar2 default null,i_chk_id in varchar2 default
null) is

begin

declare

cursor c_doc_detail (p_doc_id in varchar2) is

select \*

from doc_master

where doc_id = p_doc_id;

cursor c_doc_title is

select \*

from doc_title_lines_table;

cursor c_check_out (p_doc_id in varchar2) is

select \*

from doc_check_out

where doc_id=p_doc_id

order by check_out_date;

cursor c_reason (p_reason in varchar2) is

select reason

from doc_check_out_reason_table

where reason_code=p_reason;

cursor c_reason_list is

select \* from

doc_check_out_reason_table;

cursor c_trans (p_trans in varchar2)is

select \'1\'

from isi_trans_id

where trans_id = p_trans;

r_doc_detail doc_master%ROWTYPE;

temp_title varchar2(10);

temp varchar2(255);

new_id number(8);

new_trans_id varchar2(20);

begin

if is_valid_pid(i_pid) then

if query_ok (i_pid,2) then

if i_operation = \'Saved\' or i_operation=\'Default\' or
i_operation=\'Check In/Out\' or i_operation=\'Duplicate\' then

lib.prolog(\'ISI Document Check In / Check Out\');

if i_operation = \'Saved\' then

htp.p (\'\<font color=#006010 face=arial size=4\>Record saved
successfully\</font\>\');

end if;

if i_operation = \'Duplicate\' then

htp.p (\'\<font color=#FF0000 face=arial size=5\>This record has already
been saved. No changes applied\</font\>\');

end if;

htp.NL;

htp.p(\'\<i\>\<font color=#0000FF\>To Check In or change other
information, click on the badge number on the desired
line\</font\>\</i\>\');

document_header(i_pid,i_doc_id);

htp.centerOpen;

\--assign a new transaction id

select to_char(isi_trid_seq.nextval) into new_trans_id from dual;

\--new_trans_id := to_char(isi_trid_seq.nextval);

\--process operation Check Out, Check In, New List

elsif i_operation = \'New List\' then

select_documents_page (i_pid);

else

\--check transaction id before

open c_trans(i_trans_id);

fetch c_trans into temp;

close c_trans;

\--save changes

if temp is null then

if i_chk_id = \'Insert\' then

\--do insert

if insert_ok (i_pid,2) then

insert into doc_check_out

values(isi_chk_id_seq.nextval,i_doc_id,i_check_out_badge,i_reason_code,to_date(i_check_out_date,\'DD-MON-YYYY\'),to_date(i_check_in_date,\'DD-MON-YYYY\'));

\--htp.p(\'REFRESH SCREEN\');

else

htp.p(no_insert);

end if;

else

\--do update

if update_ok (i_pid,2) then

update doc_check_out

set check_in_date = to_date(i_check_in_date,\'DD-MON-YYYY\'),

check_out_date=to_date(i_check_out_date,\'DD-MON-YYYY\'),

check_out_badge=i_check_out_badge,

reason_code=i_reason_code

where check_out_id=i_chk_id;

else

htp.p(no_update);

end if;

end if;

\--store transaction info

insert into isi_trans_id

values (i_pid,i_trans_id,\'DOC - \' \|\| i_chk_id);

check_in_out (i_pid,\'Saved\',i_doc_id);

else

check_in_out (i_pid,\'Duplicate\',i_doc_id);

end if;

end if;

if i_operation=\'Saved\' or i_operation=\'Default\' or i_operation =
\'Check In/Out\' or i_operation=\'Duplicate\' then

\--input boxes

htp.formOpen(\'isi0001.check_in_out\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_doc_id\',i_doc_id);

htp.formHidden(\'i_trans_id\',new_trans_id);

htp.tableOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Checked Out By\');

htp.tableHeader(\'Name\');

htp.tableHeader(\'Reason\',\'\',\'\',\'\',\'\',2);

htp.tableHeader(\'Check Out Date\');

htp.tableHeader(\'Check In Date\');

for r_check in c_check_out(i_doc_id) loop

htp.tableRowOpen;

if r_check.check_out_id = i_chk_id then

htp.tableRowOpen;

htp.tableData(htf.formText(\'i_check_out_badge\',10,10,r_check.check_out_badge));

open c_badge2(r_check.check_out_badge);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.p(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_reason_code\');

for r_reason in c_reason_list loop

if r_reason.reason_code = r_check.reason_code then

htp.formSelectOption(r_reason.reason,\'SELECTED\',\'VALUE=\"\' \|\|
r_reason.reason_code \|\| \'\"\');

else

htp.formSelectOption(r_reason.reason,\'\',\'VALUE=\"\' \|\|
r_reason.reason_code \|\| \'\"\');

end if;

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableData(htf.formText(\'i_check_out_date\',11,11,to_char(r_check.check_out_date,\'DD-MON-YYYY\')));

htp.tableData(htf.formText(\'i_check_in_date\',11,11,to_char(r_check.check_in_date,\'DD-MON-YYYY\')));

htp.formHidden(\'i_chk_id\',i_chk_id);

htp.tableRowClose;

else

if update_ok (i_pid,2) then

htp.tableData(htf.anchor(\'isi0001.check_in_out?i_pid=\' \|\| i_pid \|\|

\'&i_chk_id=\' \|\| r_check.check_out_id \|\| \'&i_doc_id=\' \|\|
i_doc_id

,r_check.check_out_badge));

else

htp.tableData(r_check.check_out_badge);

end if;

open c_badge2(r_check.check_out_badge);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(r_check.reason_code);

open c_reason(r_check.reason_code);

fetch c_reason into temp;

close c_reason;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(nvl(to_char(r_check.check_out_date),\'.\'));

htp.tableData(nvl(to_char(r_check.check_in_date),\'.\'));

end if;

htp.tableRowClose;

end loop;

if insert_ok (i_pid,2) then

if i_chk_id is null then

\--add mode

htp.tableRowOpen;

\--input boxes

htp.tableData(htf.formText(\'i_check_out_badge\'));

htp.tableData(\'.\');

htp.p(\'\<TD COLSPAN=2\>\');

htp.formSelectOpen(\'i_reason_code\');

for r_reason in c_reason_list loop

htp.formSelectOption(r_reason.reason,\'\',\'VALUE=\"\' \|\|
r_reason.reason_code \|\| \'\"\');

end loop;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableData(htf.formText(\'i_check_out_date\',\'11\',\'11\',to_char(sysdate,\'DD-MON-YYYY\')));

htp.tableData(htf.formText(\'i_check_in_date\',\'11\',\'11\'));

htp.formHidden(\'i_chk_id\',\'Insert\');

htp.tableRowClose;

end if;

htp.tableClose;

end if;

if update_ok (i_pid,2) or insert_ok (i_pid,2) then

htp.formSubmit(\'i_operation\',\'Save\');

end if;

htp.formSubmit(\'i_operation\',\'New List\');

htp.formClose;

htp.centerClose;

lib.epilog;

end if;

else

htp.p(no_query);

end if;

end if;

exception when others then

err_msg(to_char(SQLCODE),SQLERRM);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure copy_request_page (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_doc_id in varchar2,i_trans_id in varchar2 default null,i_copy_badge in
varchar2 default null,

i_copy_date in varchar2 default null,i_copy_id in varchar2 default null)
is

begin

declare

cursor c_copy (p_doc_id in varchar2) is

select \*

from doc_copy_requests

where doc_id=p_doc_id

order by request_date;

cursor c_trans (p_trans in varchar2)is

select \'1\'

from isi_trans_id

where trans_id = p_trans;

r_doc_detail doc_master%ROWTYPE;

temp_title varchar2(10);

temp varchar2(255);

new_id number(8);

new_trans_id varchar2(20);

begin

if is_valid_pid(i_pid) then

if query_ok(i_pid,3) then

if i_operation = \'Saved\' or i_operation=\'Default\' or
i_operation=\'Copy Requests\' or i_operation=\'Duplicate\' then

lib.prolog(\'ISI Copy Requests\');

if i_operation = \'Saved\' then

htp.p (\'\<font color=#006010 face=arial size=4\>Record saved
successfully\</font\>\');

end if;

if i_operation = \'Duplicate\' then

htp.p (\'\<font color=#FF0000 face=arial size=5\>This record has already
been saved. No changes applied\</font\>\');

end if;

htp.NL;

htp.p(\'\<i\>\<font color=#0000FF\>To change or correct information,
click on the badge number on the desired line\</font\>\</i\>\');

document_header(i_pid,i_doc_id);

htp.centerOpen;

\--assign a new transaction id

select to_char(isi_trid_seq.nextval) into new_trans_id from dual;

\--new_trans_id := to_char(isi_trid_seq.nextval);

\--process operation Copy Request, New List

elsif i_operation = \'New List\' then

select_documents_page (i_pid);

else

\--check transaction id before

open c_trans(i_trans_id);

fetch c_trans into temp;

close c_trans;

\--save changes

if temp is null then

if i_copy_id = \'Insert\' then

if insert_ok(i_pid,3) then

\--do insert

insert into doc_copy_requests

values(isi_chk_id_seq.nextval,i_doc_id,i_copy_badge,to_date(i_copy_date,\'DD-MON-YYYY\'));

\--htp.p(\'REFRESH SCREEN\');

else

htp.p(no_insert);

end if;

else

if update_ok (i_pid,3) then

\--do update

update doc_copy_requests

set request_date = to_date(i_copy_date,\'DD-MON-YYYY\'),

request_badge=i_copy_badge

where copy_req_id=i_copy_id;

else

htp.p(no_update);

end if;

end if;

\--store transaction info

insert into isi_trans_id

values (i_pid,i_trans_id,\'CPY - \' \|\| i_copy_id);

copy_request_page (i_pid,\'Saved\',i_doc_id);

else

copy_request_page (i_pid,\'Duplicate\',i_doc_id);

end if;

end if;

if i_operation=\'Saved\' or i_operation=\'Default\' or i_operation =
\'Copy Requests\' or i_operation=\'Duplicate\' then

\--input boxes

htp.formOpen(\'isi0001.copy_request_page\');

htp.formHidden(\'i_pid\',i_pid);

htp.formHidden(\'i_doc_id\',i_doc_id);

htp.formHidden(\'i_trans_id\',new_trans_id);

htp.tableOpen;

htp.tableOpen(\'BORDER\');

htp.tableHeader(\'Copy Requested By\');

htp.tableHeader(\'Name\');

htp.tableHeader(\'Copy Request Date\');

for r_copy in c_copy(i_doc_id) loop

htp.tableRowOpen;

if r_copy.copy_req_id = i_copy_id then

htp.tableRowOpen;

htp.tableData(htf.formText(\'i_copy_badge\',10,10,r_copy.request_badge));

open c_badge2(r_copy.request_badge);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(htf.formText(\'i_copy_date\',11,11,to_date(r_copy.request_date,\'DD-MON-YYYY\')));

htp.formHidden(\'i_copy_id\',i_copy_id);

htp.tableRowClose;

else

htp.tableData(htf.anchor(\'isi0001.copy_request_page?i_pid=\' \|\| i_pid
\|\|

\'&i_copy_id=\' \|\| r_copy.copy_req_id \|\| \'&i_doc_id=\' \|\|
i_doc_id

,r_copy.request_badge));

open c_badge2(r_copy.request_badge);

fetch c_badge2 into temp;

close c_badge2;

htp.tableData(nvl(temp,\'.\'));

htp.tableData(nvl(to_char(r_copy.request_date),\'.\'));

end if;

htp.tableRowClose;

end loop;

if i_copy_id is null then

\--add mode

htp.tableRowOpen;

\--input boxes

htp.tableData(htf.formText(\'i_copy_badge\'));

htp.tableData(\'.\');

htp.tableData(htf.formText(\'i_copy_date\',\'11\',\'11\',to_char(sysdate,\'DD-MON-YYYY\')));

htp.formHidden(\'i_copy_id\',\'Insert\');

htp.tableRowClose;

end if;

htp.tableClose;

if update_ok(i_pid,3) or insert_ok(i_pid,3) then

htp.formHidden(\'i_doc_id\',i_doc_id);

htp.formSubmit(\'i_operation\',\'Save\');

end if;

htp.formSubmit(\'i_operation\',\'New List\');

htp.formClose;

htp.centerClose;

lib.epilog;

end if;

else

htp.p(no_query);

end if;

end if;

exception when others then

err_msg(to_char(SQLCODE),SQLERRM);

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure security_list_page (i_pid in varchar2,i_operation in varchar2
default \'Default\',

i_badge in varchar2 default null,i_priv_id in varchar2 default
null,i_app_id in varchar2

default null,i_qry_priv in varchar2 default null,i_ins_priv in varchar2
default null,

i_upd in varchar2 default null,i_del in varchar2 default null) is

begin

declare

cursor c_app_priv (p_badge in varchar2) is

select \*

from doc_app_privs

where badge_no = p_badge;

cursor c_app_priv_check (p_badge in varchar2,p_app_id in varchar2) is

select \*

from doc_app_privs

where badge_no = p_badge

and app_id=to_number(p_app_id);

cursor c_name (p_app_id in varchar2) is

select app_name

from doc_app_table

where app_id = p_app_id;

cursor c_usernames is

select \*

from badge_info

where inactive is null

order by name;

cursor c_all_apps is

select \* from doc_app_table;

r_priv_check doc_app_privs%ROWTYPE;

new_trans_id varchar2(8);

temp varchar2(255);

common_ref varchar2(255);

full_ref varchar2(512);

begin

if is_valid_pid(i_pid) then

if query_ok(i_pid,4) then

lib.prolog(\'ISI Security Maintenance\');

if i_operation = \'Update\' then

\--process update

if i_qry_priv is not null then

update doc_app_privs

set query_priv=i_qry_priv

where app_priv_id=i_priv_id;

end if;

if i_ins_priv is not null then

update doc_app_privs

set insert_priv=i_ins_priv

where app_priv_id=i_priv_id;

end if;

if i_upd is not null then

update doc_app_privs

set update_priv=i_upd

where app_priv_id=i_priv_id;

end if;

if i_del is not null then

update doc_app_privs

set delete_priv=i_del

where app_priv_id=i_priv_id;

end if;

else

\--check if first time, if so insert rows necessary in DOC_APP_PRIV
first

if i_badge is not null then

for r_all_apps in c_all_apps loop

open c_app_priv_check(i_badge,r_all_apps.app_id);

fetch c_app_priv_check into r_priv_check;

if c_app_priv_check%NOTFOUND then

select to_char(isi_trid_seq.nextval) into new_trans_id from dual;

insert into doc_app_privs

values
(new_trans_id,i_badge,r_all_apps.app_id,\'N\',\'N\',\'N\',\'N\',\'\');

end if;

close c_app_priv_check;

end loop;

end if;

end if;

htp.centerOpen;

htp.tableOpen;

htp.formOpen(\'isi0001.security_list_page\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'Username:\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_badge\');

for r_user in c_usernames loop

if r_user.badge_no = i_badge then

htp.formSelectOption(initcap(r_user.name),\'SELECTED\',\'VALUE=\' \|\|
r_user.badge_no);

else

htp.formSelectOption(initcap(r_user.name),\'\',\'VALUE=\' \|\|
r_user.badge_no);

end if;

end loop;

htp.formSelectClose;

htp.tableRowClose;

htp.tableClose;

htp.formSubmit(\'i_operation\',\'Get Privs\');

htp.formHidden(\'i_pid\',i_pid);

htp.formClose;

if update_ok(i_pid,4) or insert_ok(i_pid,4) then

htp.p(\'\<FONT COLOR=#0000FF face=arial size=3\>Click on \<IMG
SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\" HEIGHT=\"26\"\> or \<IMG
SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\" HEIGHT=\"23\"\> to assign
or deny privilege\</font\>\');

htp.NL;

htp.NL;

end if;

htp.tableOpen(\'Border\');

htp.tableHeader(\'Application\');

htp.p(\'\<TH Width=150\>Query\');

htp.p(\'\<TH Width=150\>Insert\');

htp.p(\'\<TH Width=150\>Update\');

htp.p(\'\<TH Width=150\>Delete\');

/\*htp.tableHeader(\'Insert\');

htp.tableHeader(\'Update\');

htp.tableHeader(\'Delete\');\*/

for r_app_priv in c_app_priv(i_badge) loop

htp.tableRowOpen;

open c_name (r_app_priv.app_id);

fetch c_name into temp;

close c_name;

if update_ok(i_pid,4) or insert_ok(i_pid,4) then

htp.tableData(htf.bold(temp));

common_ref := \'\<A HREF=\"isi0001.security_list_page?i_pid=\' \|\|
i_pid \|\| \'&i_priv_id=\' \|\|

r_app_priv.app_priv_id \|\| \'&i_operation=Update&i_app_id=\' \|\|
r_app_priv.app_id \|\|

\'&i_badge=\' \|\| i_badge;

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.query_priv = \'N\' then

htp.p(common_ref \|\| \'&i_qry_priv=Y\"\>\<IMG
SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\" HEIGHT=\"26\"\>\</A\>\');

else

htp.p(common_ref \|\| \'&i_qry_priv=N\"\>\<IMG
SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\" HEIGHT=\"23\"\>\</A\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.insert_priv = \'N\' then

htp.p(common_ref \|\| \'&i_ins_priv=Y\"\>\<IMG
SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\" HEIGHT=\"26\"\>\</A\>\');

else

htp.p(common_ref \|\| \'&i_ins_priv=N\"\>\<IMG
SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\" HEIGHT=\"23\"\>\</A\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.update_priv = \'N\' then

htp.p(common_ref \|\| \'&i_upd=Y\"\>\<IMG SRC=\"/gen-img/red_x.gif\"
WIDTH=\"25\" HEIGHT=\"26\"\>\</A\>\');

else

htp.p(common_ref \|\| \'&i_upd=N\"\>\<IMG
SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\" HEIGHT=\"23\"\>\</A\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.delete_priv = \'N\' then

htp.p(common_ref \|\| \'&i_del=Y\"\>\<IMG SRC=\"/gen-img/red_x.gif\"
WIDTH=\"25\" HEIGHT=\"26\"\>\</A\>\');

else

htp.p(common_ref \|\| \'&i_del=N\"\>\<IMG
SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\" HEIGHT=\"23\"\>\</A\>\');

end if;

htp.p(\'\</TD\>\');

else

htp.tableData(htf.bold(temp));

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.query_priv = \'N\' then

htp.p(\'\<IMG SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\"
HEIGHT=\"26\"\>\');

else

htp.p(\'\<IMG SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.insert_priv = \'N\' then

htp.p(\'\<IMG SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\"
HEIGHT=\"26\"\>\');

else

htp.p(\'\<IMG SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.update_priv = \'N\' then

htp.p(\'\<IMG SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\"
HEIGHT=\"26\"\>\');

else

htp.p(\'\<IMG SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

end if;

htp.p(\'\</TD\>\');

htp.p(\'\<TD ALIGN=CENTER\>\');

if r_app_priv.delete_priv = \'N\' then

htp.p(\'\<IMG SRC=\"/gen-img/red_x.gif\" WIDTH=\"25\"
HEIGHT=\"26\"\>\');

else

htp.p(\'\<IMG SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

end if;

htp.p(\'\</TD\>\');

end if;

htp.tableRowClose;

end loop;

htp.tableClose;

htp.tableOpen;

htp.tableHeader(\'Legend\',\'\',\'\',\'\',\'\',2);

htp.tableRowOpen;

htp.tableData(\'\<IMG SRC=\"/gen-img/green_check.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

htp.tableData(\'Privilege enabled\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(\'\<IMG SRC=\"/gen-img/red_x.gif\" WIDTH=\"19\"
HEIGHT=\"23\"\>\');

htp.tableData(\'Not allowed\');

htp.tableRowClose;

htp.tableClose;

htp.anchor( \'isi0001.select_documents_page?i_pid=\' \|\| i_pid,\'Get
New Document List\');

htp.centerClose;

lib.epilog;

else

htp.p(no_query);

end if;

end if;

end;

end;

\--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

END;

/

CREATE OR REPLACE PACKAGE ISI0002 IS

procedure start_vld(i_pid in varchar2 default \'NEW\');

procedure display_beamlines(

i_pid in varchar2,

i_validationID in number default null,

i_doc_id in varchar2 default null,

i_beamline in varchar2 default null,

i_stations in varchar2 default null,

i_shutters in varchar2 default null,

i_modes in varchar2 default null,

i_complete in varchar2 default null,

i_new_doc_id in number default null,

i_new_beamline in varchar2 default null,

i_operation in varchar2 default null);

procedure display_beamline_details(

i_pid in varchar2,

i_validationID in number,

i_validation_detail_id in number default null,

i_operation in varchar2 default null,

i_validation_date in varchar2 default null,

i_configuration in varchar2 default null,

i_a_battery in varchar2 default null,

i_b_battery in varchar2 default null,

i_relays in varchar2 default null,

i_next_validation_date in varchar2 default null);

procedure select_documents_page (i_pid in varchar2);

procedure validation_detail(

i_pid in varchar2,

i_validationID in number,

i_validation_detail_id in number);

procedure list_signoffs(

i_pid in varchar2,

i_validationID in number,

i_validation_detail_id in number,

i_operation in varchar2 default null,

i_badge in varchar2 default null,

i_init in varchar2 default null,

i_signoff_id in number default null);

procedure chains(

i_pid in varchar2,

i_validationID in number,

i_validation_detail_id in number,

i_chain_type in varchar2,

i_programmer in varchar2 default null,

i_screen in varchar2 default null,

i_screen_date in date default null,

i_io_rev in varchar2 default null,

i_io_rev_date in date default null,

i_fault_rev in number default null,

i_fault_date in date default null,

i_disk_date in date default null,

i_operation in varchar2 default null);

procedure err_msg(

err_code in varchar2,

err_str in varchar2);

END;

/

CREATE OR REPLACE PACKAGE BODY isi0002 IS

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This function checks for a valid PID

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

function is_valid_pid (i_pid in varchar2) return boolean is

begin

declare

result boolean;

p_app_name varchar2(30);

begin

p_app_name := \'ISI_VLD\';

result := log0002.is_valid_pid(i_pid, p_app_name);

return result;

end;

end;

\-- \*\*\* END FUNCTION is_valid_pid \*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This function substitutes the full word for

\-- \*\*\* the values of \'Y\' or \'N\'

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

function YesNoNull (WhatIsIt in varchar2) return varchar2 is

begin

if WhatIsIt = \'Y\' then

return \'Yes\';

elsif WhatIsIt = \'N\' then

return \'No\';

else

return \'&nbsp\';

end if;

end;

\-- \*\*\* END FUNCTION YesNoNull
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure checks for a valid PID before

\-- \*\*\* allowing the user to continue

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure start_vld(i_pid in varchar2 default \'NEW\') is

begin

if i_pid is NULL or i_pid = \'NEW\' or NOT is_valid_pid (i_pid) then

log0002.login(\'ISI_VLD\', \'\', i_pid);

return;

end if;

select_documents_page(i_pid);

end;

\--\*\*\* END PROCEDURE start_vld
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure allows the user to select the

\-- \*\*\* initital beamline validations to be returned

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure select_documents_page (i_pid in varchar2) is

begin

declare

cursor c_badge is

select \* from badge_info

where inactive is NULL

order by name;

begin

if is_valid_pid (i_pid) then

lib.prolog(\'ISI Validation System\');

htp.centerOpen;

htp.formOpen(\'isi0002.display_beamlines\');

htp.tableOpen;

htp.tableRowOpen;

\--htp.tableData(htf.bold(\'Document No. (full or partial):\'));

\--htp.tableData(htf.formText(\'i_doc_id\', 20, 8));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'Beam Line (full or partial):\'));

htp.tableData(htf.formText(\'i_beamline\', 20, 20));

htp.tableRowClose;

htp.tableClose;

htp.br;

htp.formSubmit(\'\', \'Find Documents\');

htp.formHidden(\'i_pid\', i_pid);

htp.formClose;

htp.centerClose;

lib.epilog;

end if;

end;

end;

\-- \*\*\* END PROCEDURE select_documents_page \*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure displays the initial list of

\-- \*\*\* available beamline validation entries

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure display_beamlines (i_pid in varchar2, i_validationID in number
default null, i_doc_id in varchar2 default null, i_beamline in varchar2
default null, i_stations in varchar2 default null, i_shutters in
varchar2 default null, i_modes in varchar2 de

fault null, i_complete in varchar2 default null, i_new_doc_id in number
default null, i_new_beamline in varchar2 default null, i_operation in
varchar2 default null) is

begin

declare

rBeamlines doc_validation_header%ROWTYPE;

cursor cBeamlines(TheValidationID in varchar2) is

select \* from doc_validation_header

where beamline like i_beamline \|\| \'%\' and

validation_id like TheValidationID

order by beamline;

rUpdateHeader doc_validation_header%ROWTYPE;

cursor cUpdateHeader is

select \* from doc_validation_header

where validation_id = i_validationID

for update;

TempSeq number(10);

begin

lib.prolog(\'Beamlines\');

if is_valid_pid(i_pid) then

\-- \*\*\* Update the record if necessary

if i_operation = \'Update Information\' then

open cUpdateHeader;

fetch cUpdateHeader into rUpdateHeader;

update doc_validation_header

set doc_id = i_new_doc_id,

beamline = upper(i_new_beamline),

bm_stations = upper(i_stations),

bm_shutters = upper(i_shutters),

modes = i_modes,

complete = i_complete,

last_updated = SYSDATE

where validation_id = i_validationID;

close cUpdateHeader;

\-- \*\*\* Update the record if necessary

elsif i_operation = \'Add Information\' then

select ISI_VAL_ID_SEQ.nextval into TempSeq from dual;

insert into doc_validation_header(

validation_id, doc_id, beamline, bm_stations, bm_shutters,

modes, complete, last_updated)

values(TempSeq, i_new_doc_id, upper(i_new_beamline),

upper(i_stations), upper(i_shutters), i_modes, i_complete,

SYSDATE);

end if;

\-- \*\*\* Display usage message

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Add Information\' or i_operation = \'Update Information\' then

htp.p(\'Select a beamline to view it\'\'s validations. Click the
\"Edit\" button to change information for the selected beamline. Click
the \"Add New Beamline\" button to create a new beamline entry.\');

elsif i_operation = \'Add New Beamline\' then

htp.p(\'Enter the necessary information and click the \"Add
Information\" button. Click \"Cancel\" to cancel adding a new entry.\');

elsif i_operation = \'Edit\' then

htp.p(\'Change the information and click the \"Update Information\"
button. Click \"Cancel\" to cancel updating the entry.\');

end if;

htp.para;

\-- \*\*\* Display existing beamlines

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Update Information\' or i_operation = \'Add Information\' then

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

\-- htp.tableData(htf.Bold(\'Doc #\'));

htp.tableData(htf.Bold(\'Beamline\'));

htp.tableData(htf.Bold(\'Stations\'));

htp.tableData(htf.Bold(\'Shutters\'));

htp.tableData(htf.Bold(\'Modes\'));

htp.tableData(htf.Bold(\'Complete\'));

htp.tableData(\'&nbsp\');

htp.tableRowClose;

for Loop1 in cBeamlines(\'%\') loop

htp.tableRowOpen;

\-- htp.tableData(Loop1.doc_id);

htp.tableData(htf.anchor(\'isi0002.display_beamline_details?i_pid=\'
\|\| i_pid \|\| \'&\' \|\| \'i_validationID=\' \|\| Loop1.validation_id,
Loop1.beamline));

htp.tableData(nvl(Loop1.bm_stations,\'&nbsp\'));

htp.tableData(nvl(Loop1.bm_shutters,\'&nbsp\'));

htp.tableData(nvl(YesNoNull(Loop1.modes),\'&nbsp\'));

htp.tableData(nvl(YesNoNull(Loop1.complete),\'&nbsp\'));

htp.formOpen(\'../owa/isi0002.display_beamlines\');

htp.tableData(htf.formSubmit(\'\', \' Edit \'));

htp.formHidden(\'i_operation\', \'Edit\');

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', Loop1.validation_id);

htp.formHidden(\'i_doc_id\', i_doc_id);

htp.formHidden(\'i_beamline\', i_beamline);

htp.formClose;

htp.tableRowClose;

end loop;

htp.tableClose;

htp.centerClose;

\-- \*\*\* Setup table to edit an exiting beamline

elsif i_operation = \'Edit\' then

open cBeamlines(i_validationID);

fetch cBeamlines into rBeamlines;

htp.formOpen(\'../owa/isi0002.display_beamlines\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Document ID:\</P\>\'));

htp.tableData(htf.formText(\'i_new_doc_id\', 8, 8, rBeamlines.doc_id));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Beamline:\</P\>\'));

htp.tableData(htf.formText(\'i_new_beamline\', 20, 20,
rBeamlines.beamline));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Stations:\</P\>\'));

htp.tableData(htf.formText(\'i_stations\', 20, 20,
rBeamlines.bm_stations));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Shutters:\</P\>\'));

htp.tableData(htf.formText(\'i_shutters\', 20, 20,
rBeamlines.bm_shutters));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Modes:\</P\>\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_modes\');

if rBeamlines.modes = \'Y\' then

htp.formSelectOption(\'Yes\',\'SELECTED\',\'VALUE=\"Y\"\');

else

htp.formSelectOption(\'Yes\',\'\',\'VALUE=\"Y\"\');

end if;

if rBeamlines.modes = \'N\' then

htp.formSelectOption(\'No\',\'SELECTED\',\'VALUE=\"N\"\');

else

htp.formSelectOption(\'No\',\'\',\'VALUE=\"N\"\');

end if;

if rBeamlines.modes is NULL then

htp.formSelectOption(\'\',\'SELECTED\');

else

htp.formSelectOption(\'\',\'\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Complete:\</P\>\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_complete\');

if rBeamlines.complete = \'Y\' then

htp.formSelectOption(\'Yes\',\'SELECTED\',\'VALUE=\"Y\"\');

else

htp.formSelectOption(\'Yes\',\'\',\'VALUE=\"Y\"\');

end if;

if rBeamlines.complete = \'N\' then

htp.formSelectOption(\'No\',\'SELECTED\',\'VALUE=\"N\"\');

else

htp.formSelectOption(\'No\',\'\',\'VALUE=\"N\"\');

end if;

if rBeamlines.complete is NULL then

htp.formSelectOption(\'\',\'SELECTED\');

else

htp.formSelectOption(\'\',\'\');

end if;

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

close cBeamlines;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\', \'Update Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_doc_id\', i_doc_id);

htp.formHidden(\'i_beamline\', i_beamline);

htp.formClose;

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

\-- \*\*\* Display table columns to add a new beamline

elsif i_operation = \'Add New Beamline\' then

htp.formOpen(\'../owa/isi0002.display_beamlines\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Document ID:\</P\>\'));

htp.tableData(htf.formText(\'i_new_doc_id\', 8, 8));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Beamline:\</P\>\'));

htp.tableData(htf.formText(\'i_new_beamline\', 20, 20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Stations:\</P\>\'));

htp.tableData(htf.formText(\'i_stations\', 20, 20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Shutters:\</P\>\'));

htp.tableData(htf.formText(\'i_shutters\', 20, 20));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Modes:\</P\>\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_modes\');

htp.formSelectOption(\'Yes\',\'\',\'VALUE=\"Y\"\');

htp.formSelectOption(\'No\',\'\',\'VALUE=\"N\"\');

htp.formSelectOption(\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.Bold(\'\<P ALIGN=\"RIGHT\"\>Complete:\</P\>\'));

htp.p(\'\<TD\>\');

htp.formSelectOpen(\'i_complete\');

htp.formSelectOption(\'Yes\',\'\',\'VALUE=\"Y\"\');

htp.formSelectOption(\'No\',\'\',\'VALUE=\"N\"\');

htp.formSelectOption(\'\',\'SELECTED\');

htp.formSelectClose;

htp.p(\'\</TD\>\');

htp.tableRowClose;

htp.tableClose;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\', \'Add Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_doc_id\', i_doc_id);

htp.formHidden(\'i_beamline\', i_beamline);

htp.formClose;

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

end if;

\-- \*\*\* Display buttons

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Update Information\' or i_operation = \'Add Information\' then

htp.centerOpen;

htp.tableOpen;

htp.tableRowOpen;

htp.formOpen(\'../owa/isi0002.display_beamlines\');

htp.tableData(htf.formSubmit(\'i_operation\', \'Add New Beamline\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_doc_id\', i_doc_id);

htp.formHidden(\'i_beamline\', i_beamline);

htp.formClose;

htp.formOpen(\'../owa/isi0002.select_documents_page\');

htp.tableData(htf.formSubmit(\'\', \'New Beamline List\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formClose;

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

end if;

end if;

lib.epilog;

exception when others then

err_msg(to_char(SQLCODE), SQLERRM);

end;

end;

\-- \*\*\* END PROCEDURE display_beamlines \*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure displays the initial list of

\-- \*\*\* available beamline validation entries

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure display_beamline_details (i_pid in varchar2, i_validationID in
number, i_validation_detail_id in number default null,

i_operation in varchar2 default null, i_validation_date in varchar2
default null,

i_configuration in varchar2 default null, i_a_battery in varchar2
default null,

i_b_battery in varchar2 default null, i_relays in varchar2 default null,

i_next_validation_date in varchar2 default null) is

begin

declare

cursor cBeamlines is

select \* from doc_validation_detail

where validation_id = i_validationID

order by validation_date desc;

rUpdateDetails doc_validation_detail%ROWTYPE;

cursor cUpdateDetails is

select \* from doc_validation_detail

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id

for update;

TempSeq number(8);

begin

lib.prolog(\'Beamline Validations\');

if is_valid_pid(i_pid) then

\-- \*\*\* Update the record if necessary

if i_operation = \'Update Information\' then

open cUpdateDetails;

fetch cUpdateDetails into rUpdateDetails;

update doc_validation_detail

set validation_date = to_date(i_validation_date),

config = upper(i_configuration),

a_battery = upper(i_a_battery),

b_battery = upper(i_b_battery),

relays = upper(i_relays),

next_validation = to_date(i_next_validation_date)

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id;

close cUpdateDetails;

\-- \*\*\* Insert a record if necessary

elsif i_operation = \'Add Information\' then

select ISI_VAL_DETAIL_ID_SEQ.nextval into TempSeq from dual;

insert into doc_validation_detail(

validation_id, config, next_validation, a_battery, b_battery,

relays, validation_detail_id, last_updated, validation_date)

values(i_validationID, upper(i_configuration),
to_date(i_next_validation_date),

upper(i_a_battery), upper(i_b_battery), upper(i_relays), TempSeq,

SYSDATE, to_date(i_validation_date));

end if;

\-- \*\*\* Display usage message

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Add Information\' or i_operation = \'Update Information\' then

htp.p(\'Select a validation date to view it\'\'s information. Click
\"Edit\" to change the information for the selected validation. Click
\"Signoff\" the add/change signoff information. Click \"A\" or \"B\" to
change Chain A or B information.\');

elsif i_operation = \'Add New Validation\' then

htp.p(\'Enter the necessary information and click the \"Add
Information\" button. Click \"Cancel\" to cancel adding a new entry.\');

elsif i_operation = \'Edit\' then

htp.p(\'Change the information and click the \"Update Information\"
button. Click \"Cancel\" to cancel updating the entry.\');

end if;

htp.para;

\-- \*\*\* List existing validations

htp.centerOpen;

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Update Information\' or i_operation = \'Add Information\' then

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.Bold(\'Validated\'));

htp.tableData(htf.Bold(\'Configuration\'));

htp.tableData(htf.Bold(\'Next Validation\'));

htp.tableData(\'&nbsp\',\'\',\'\',\'\',\'\',\'4\');

htp.tableRowClose;

for Loop1 in cBeamlines loop

htp.tableRowOpen;

htp.tableData(htf.anchor(\'isi0002.validation_detail?i_pid=\' \|\| i_pid
\|\| \'&i_validationID=\' \|\| Loop1.validation_id \|\|
\'&i_validation_detail_id=\' \|\| Loop1.validation_detail_id,
Loop1.validation_date));

htp.tableData(Loop1.config);

htp.tableData(Loop1.next_validation);

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableData(htf.formSubmit(\'\', \' Edit \'));

htp.formHidden(\'i_operation\', \'Edit\');

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', Loop1.validation_id);

htp.formHidden(\'i_validation_detail_id\', Loop1.validation_detail_id);

htp.formHidden(\'i_validation_date\', Loop1.validation_date);

htp.formHidden(\'i_configuration\', Loop1.config);

htp.formHidden(\'i_a_battery\', Loop1.a_battery);

htp.formHidden(\'i_b_battery\', Loop1.b_battery);

htp.formHidden(\'i_relays\', Loop1.relays);

htp.formHidden(\'i_next_validation_date\', Loop1.next_validation);

htp.formClose;

htp.formOpen(\'../owa/isi0002.list_signoffs\');

htp.tableData(htf.formSubmit(\'\', \'Signoffs\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', Loop1.validation_id);

htp.formHidden(\'i_validation_detail_id\', Loop1.validation_detail_id);

htp.formClose;

htp.formOpen(\'../owa/isi0002.chains\');

htp.tableData(htf.formSubmit(\'\', \' A \'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_chain_type\', \'A\');

htp.formHidden(\'i_validationID\', Loop1.validation_id);

htp.formHidden(\'i_validation_detail_id\', Loop1.validation_detail_id);

htp.formClose;

htp.formOpen(\'../owa/isi0002.chains\');

htp.tableData(htf.formSubmit(\'\', \' B \'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_chain_type\', \'B\');

htp.formHidden(\'i_validationID\', Loop1.validation_id);

htp.formHidden(\'i_validation_detail_id\', Loop1.validation_detail_id);

htp.formClose;

htp.tableRowClose;

end loop;

htp.tableClose;

\-- \*\*\* Create fields for new validation info

elsif i_operation = \'Add New Validation\' then

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Validation
Date:\</P\>\'));

htp.tableData(htf.formText(\'i_validation_date\', 10, 10));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Configuration:\</P\>\'));

htp.tableData(htf.formText(\'i_configuration\', 30, 30));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>A Battery:\</P\>\'));

htp.tableData(htf.formText(\'i_a_battery\', 10, 10));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>B Battery:\</P\>\'));

htp.tableData(htf.formText(\'i_b_battery\', 10, 10));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Relays:\</P\>\'));

htp.tableData(htf.formText(\'i_relays\', 10, 10));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Next Validation
Date:\</P\>\'));

htp.tableData(htf.formText(\'i_next_validation_date\', 10, 10));

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\', \'Add Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.tableRowClose;

htp.tableClose;

htp.formClose;

\-- \*\*\* Edit an existing record

elsif i_operation = \'Edit\' then

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Validation
Date:\</P\>\'));

htp.tableData(htf.formText(\'i_validation_date\', 10, 10,
i_validation_date));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Configuration:\</P\>\'));

htp.tableData(htf.formText(\'i_configuration\', 30, 30,
i_configuration));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>A Battery:\</P\>\'));

htp.tableData(htf.formText(\'i_a_battery\', 10, 10, i_a_battery));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>B Battery:\</P\>\'));

htp.tableData(htf.formText(\'i_b_battery\', 10, 10, i_b_battery));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Relays:\</P\>\'));

htp.tableData(htf.formText(\'i_relays\', 10, 10, i_relays));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Next Validation
Date:\</P\>\'));

htp.tableData(htf.formText(\'i_next_validation_date\', 10, 10,
i_next_validation_date));

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.tableOpen;

htp.tableRowOpen;

htp.tableData(htf.formSubmit(\'i_operation\', \'Update Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.tableRowClose;

htp.tableClose;

htp.formClose;

end if;

htp.centerClose;

\-- \*\*\* Create buttons

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Update Information\' or i_operation = \'Add Information\' then

htp.centerOpen;

htp.tableOpen;

htp.tableRowOpen;

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableData(htf.formSubmit(\'i_operation\', \'Add New Validation\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', -1);

htp.formClose;

htp.formOpen(\'../owa/isi0002.select_documents_page\');

htp.tableData(htf.formSubmit(\'\', \'New Beamline List\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formClose;

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

end if;

end if;

lib.epilog;

end;

end;

\-- \*\*\* END PROCEDURE display_beamline_details \*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure displays detail information

\-- \*\*\* for the selected beamline

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure validation_detail (i_pid in varchar2, i_validationID in
number, i_validation_detail_id in number) is

begin

declare

rBeamlineDetail doc_validation_detail%ROWTYPE;

cursor cBeamlineDetail(detail_id in number) is

select \* from doc_validation_detail

where validation_id = i_validationID and

validation_detail_id = detail_id;

rGetInitials doc_validation_signoff%ROWTYPE;

cursor cGetInitials is

select init from doc_validation_signoff

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id;

Initials varchar(200);

begin

\-- \*\*\* Display the prolog and make sure PID is valid

lib.prolog(\'Beamline Validation Information\');

if is_valid_pid(i_pid) then

\-- \*\*\* Get signoff initials

for Loop1 in cGetInitials loop

Initials := Initials \|\| Loop1.init \|\| \'/\';

end loop;

Initials := substr(Initials, 1, length(Initials)-1);

\-- \*\*\* Display validation information

open cBeamlineDetail(i_validation_detail_id);

fetch cBeamlineDetail into rBeamlineDetail;

htp.centerOpen;

\--htp.formOpen(\'../owa/isi0002.validation_detail\');

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Initials:\</P\>\'));

htp.tableData(Initials \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Validation
Date:\</P\>\'));

htp.tableData(rBeamlineDetail.validation_date \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Configuration:\</P\>\'));

htp.tableData(rBeamlineDetail.config \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>A Battery:\</P\>\'));

htp.tableData(rBeamlineDetail.a_battery \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>B Battery:\</P\>\'));

htp.tableData(rBeamlineDetail.b_battery \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Relays:\</P\>\'));

htp.tableData(rBeamlineDetail.relays \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Next Validation
Date:\</P\>\'));

htp.tableData(rBeamlineDetail.next_validation \|\| \'&nbsp\');

htp.tableRowClose;

htp.tableClose;

\-- \*\*\* Create buttons

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.formSubmit(\'\', \'Back to Beamline Validations\');

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formClose;

htp.centerClose;

end if;

lib.epilog;

exception when others then

err_msg(to_char(SQLCODE), SQLERRM);

end;

end;

\-- \*\*\* END PROCEDURE doc_detail \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure displays a list of signoff

\-- \*\*\* initials

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure list_signoffs (i_pid in varchar2, i_validationID in number,
i_validation_detail_id in number, i_operation in varchar2 default null,
i_badge in varchar2 default null, i_init in varchar2 default null,
i_signoff_id in number default null) is

begin

declare

cursor cListSignoffs is

select \* from doc_validation_signoff

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id;

rUpdateSignoffs doc_validation_signoff%ROWTYPE;

cursor cUpdateSignoffs is

select \* from doc_validation_signoff

where validation_signoff_id = i_signoff_id

for update;

TempSeq number(8);

begin

\-- \*\*\* Display the prolog and make sure PID is valid

lib.prolog(\'Validation Signoffs\');

if is_valid_pid(i_pid) then

\-- \*\*\* Insert a new row if necessary

if i_operation = \'Add Information\' then

select ISI_SIGNOFF_ID_SEQ.nextval into TempSeq from dual;

insert into doc_validation_signoff(

validation_id, validation_detail_id, validation_signoff_id,

badge_no, init, last_updated)

values(i_validationID, i_validation_detail_id, TempSeq,

upper(i_badge), upper(i_init), SYSDATE);

\-- \*\*\* Update a selected record if necessary

elsif i_operation = \'Update Information\' then

open cUpdateSignoffs;

fetch cUpdateSignoffs into rUpdateSignoffs;

update doc_validation_signoff

set badge_no = upper(i_badge),

init = upper(i_init),

last_updated = SYSDATE

where validation_signoff_id = i_signoff_id;

close cUpdateSignoffs;

end if;

\-- \*\*\* Display usage message

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Add Information\' or i_operation = \'Update Information\' then

htp.p(\'Select a signoff to edit or click the \"New Signoff\" button to
create a new entry.\');

elsif i_operation = \'New Signoff\' then

htp.p(\'Enter the necessary information and click the \"Add
Information\" button. Click \"Cancel\" to cancel adding a new entry.\');

elsif i_operation = \'Edit\' then

htp.p(\'Change the information and click the \"Update Information\"
button. Click \"Cancel\" to cancel updating the entry.\');

end if;

htp.para;

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'Badge Number\'));

htp.tableData(htf.bold(\'Initials\'));

htp.tableData(\'&nbsp\',\'\',\'\',\'\',\'\',\'2\');

htp.tableRowClose;

\-- \*\*\* Display existing signoffs

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Add Information\' or i_operation = \'Update Information\' then

for Loop1 in cListSignoffs loop

htp.tableRowOpen;

htp.formOpen(\'../owa/isi0002.list_signoffs\');

\--htp.tableData(htf.anchor(\'isi0002.list_signoffs?i_pid=\' \|\| i_pid
\|\| \'&i_validationID=\' \|\| Loop1.validation_id \|\|
\'&i_validation_detail_id=\' \|\| Loop1.validation_detail_id \|\|
\'&i_operation=Update&i_badge=\' \|\| Loop1.badge_no \|\| \'&i_init=\'
\|\| Loop1.init

\|\| \'&i_signoff_id=\' \|\| Loop1.validation_signoff_id,
Loop1.badge_no));

htp.tableData(Loop1.badge_no);

htp.tableData(Loop1.init);

htp.tableData(htf.formSubmit(\'\', \' Edit \'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formHidden(\'i_operation\', \'Edit\');

htp.formHidden(\'i_signoff_id\', Loop1.validation_signoff_id);

htp.formClose;

htp.tableRowClose;

end loop;

\-- \*\*\* Display for update signoff

elsif i_operation = \'Edit\' then

for Loop1 in cListSignoffs loop

htp.tableRowOpen;

if Loop1.validation_signoff_id = i_signoff_id then

htp.formOpen(\'../owa/isi0002.list_signoffs\');

htp.tableData(htf.formText(\'i_badge\', 15, 5, Loop1.badge_no));

htp.tableData(htf.formText(\'i_init\', 15, 10, Loop1.init));

htp.tableData(htf.formSubmit(\'i_operation\', \'Update Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formHidden(\'i_signoff_id\', Loop1.validation_signoff_id);

htp.formClose;

else

htp.tableData(htf.anchor(\'isi0002.list_signoffs?i_pid=\' \|\| i_pid
\|\| \'&i_validationID=\' \|\| Loop1.validation_id \|\|
\'&i_validation_detail_id=\' \|\| Loop1.validation_detail_id \|\|
\'&i_operation=Edit&i_badge=\' \|\| Loop1.badge_no \|\| \'&i_init=\'
\|\| Loop1.init \|\|

\'&i_signoff_id=\' \|\| Loop1.validation_signoff_id, Loop1.badge_no));

htp.tableData(Loop1.init);

htp.tableData(\'&nbsp\',\'\',\'\',\'\',\'\',\'2\');

end if;

htp.tableRowClose;

end loop;

\-- \*\*\* Create empty fields for new signoff

elsif i_operation = \'New Signoff\' then

htp.formOpen(\'../owa/isi0002.list_signoffs\');

htp.tableData(htf.formText(\'i_badge\', 15, 5));

htp.tableData(htf.formText(\'i_init\', 15, 10));

htp.tableData(htf.formSubmit(\'i_operation\', \'Add Information\'));

htp.tableData(htf.formSubmit(\'i_operation\', \'Cancel\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formClose;

end if;

\-- \*\*\* Close the signoff table list

htp.tableClose;

\-- \*\*\* Open the button table

htp.tableOpen;

htp.tableRowOpen;

\-- \*\*\* Display buttons

if i_operation is NULL or i_operation = \'Cancel\' or i_operation =
\'Add Information\' or i_operation = \'Update Information\' then

htp.formOpen(\'../owa/isi0002.list_signoffs\');

htp.tableData(htf.formSubmit(\'i_operation\', \'New Signoff\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formClose;

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableData(htf.formSubmit(\'\', \'Back to Beamline Validations\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formClose;

end if;

\-- \*\*\* Close the button table

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

end if;

lib.epilog;

\-- \*\*\* Error trap

exception when others then

err_msg(to_char(SQLCODE), SQLERRM);

end;

end;

\-- \*\*\* END PROCEDURE list_signoffs \*\*\*\*\*\*\*\*\*\*\*\*\*

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\-- \*\*\* This procedure allows the user to edit

\-- \*\*\* chain information for the validations

\--
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure chains (i_pid in varchar2, i_validationID in number,
i_validation_detail_id in number,

i_chain_type in varchar2, i_programmer in varchar2 default null,
i_screen in varchar2 default null,

i_screen_date in date default null, i_io_rev in varchar2 default null,
i_io_rev_date in date default null,

i_fault_rev in number default null, i_fault_date in date default null,
i_disk_date in date default null,

i_operation in varchar2 default null) is

begin

declare

rGetChainInfo doc_validation_chains%ROWTYPE;

cursor cGetChainInfo is

select \* from doc_validation_chains

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id and

type = i_chain_type;

rUpdateChains doc_validation_chains%ROWTYPE;

cursor cUpdateChains is

select \* from doc_validation_chains

where validation_id = i_validationID and

validation_detail_id = i_validation_detail_id and

type = i_chain_type

for update;

begin

\-- \*\*\* Display the prolog and make sure PID is valid

lib.prolog(\'Chain \' \|\| i_chain_type);

if is_valid_pid(i_pid) then

\-- \*\*\* Update the record if necessary

if i_operation = \'Update Information\' then

open cUpdateChains;

fetch cUpdateChains into rUpdateChains;

update doc_validation_chains

set programmer = upper(i_programmer),

scr = upper(i_screen),

scr_date = i_screen_date,

io_rev = upper(i_io_rev),

io_rev_date = i_io_rev_date,

fault_rev = i_fault_rev,

fault_date = i_fault_date,

disk_date = i_disk_date

where validation_id = i_validationID and

type = i_chain_type;

close cUpdateChains;

elsif i_operation = \'Add Information\' then

insert into doc_validation_chains(

programmer, scr, scr_date, io_rev, io_rev_date,

fault_rev, fault_date, disk_date, last_updated,

validation_id, validation_detail_id, type)

values(upper(i_programmer), upper(i_screen), i_screen_date,

upper(i_io_rev), i_io_rev_date, i_fault_rev, i_fault_date,

i_disk_date, SYSDATE, i_validationID, i_validation_detail_id,

i_chain_type);

end if;

open cGetChainInfo;

fetch cGetChainInfo into rGetChainInfo;

\-- \*\*\* Display usage message

if cGetChainInfo%NOTFOUND then

htp.p(\'Enter the chain information and click \"Add Information\" to
store it in the database.\');

else

htp.p(\'Change the chain information and click \"Update Information\" to
store it in the database.\');

end if;

htp.para;

htp.formOpen(\'../owa/isi0002.chains\');

htp.centerOpen;

htp.tableOpen(\'BORDER=\"1\" CELLPADDING=\"2\" BGCOLOR=\"#F0F0F0\"\');

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Programmer:\</P\>\'));

htp.tableData(htf.formText(\'i_programmer\', 30, 30,
rGetChainInfo.programmer));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>SCR:\</P\>\'));

htp.tableData(htf.formText(\'i_screen\', 25, 25, rGetChainInfo.scr));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>SCR Date:\</P\>\'));

htp.tableData(htf.formText(\'i_screen_date\', 10, 10,
rGetChainInfo.scr_date));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>I/O Rev:\</P\>\'));

htp.tableData(htf.formText(\'i_io_rev\', 10, 10, rGetChainInfo.io_rev));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>I/O Rev Date:\</P\>\'));

htp.tableData(htf.formText(\'i_io_rev_date\', 10, 10,
rGetChainInfo.io_rev_date));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Fault Rev:\</P\>\'));

htp.tableData(htf.formText(\'i_fault_rev\', 3, 3,
rGetChainInfo.fault_rev));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>FaultDate:\</P\>\'));

htp.tableData(htf.formText(\'i_fault_date\', 10, 10,
rGetChainInfo.fault_date));

htp.tableRowClose;

htp.tableRowOpen;

htp.tableData(htf.bold(\'\<P ALIGN=\"RIGHT\"\>Disk Date:\</P\>\'));

htp.tableData(htf.formText(\'i_disk_date\', 10, 10,
rGetChainInfo.disk_date));

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.tableOpen;

htp.tableRowOpen;

if cGetChainInfo%NOTFOUND then

htp.tableData(htf.formSubmit(\'i_operation\', \'Add Information\'));

else

htp.tableData(htf.formSubmit(\'i_operation\', \'Update Information\'));

end if;

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.formHidden(\'i_chain_type\', i_chain_type);

htp.formClose;

htp.formOpen(\'../owa/isi0002.display_beamline_details\');

htp.tableData(htf.formSubmit(\'\', \'Back to Beamline Validations\'));

htp.formHidden(\'i_pid\', i_pid);

htp.formHidden(\'i_validationID\', i_validationID);

htp.formHidden(\'i_validation_detail_id\', i_validation_detail_id);

htp.tableRowClose;

htp.tableClose;

htp.centerClose;

htp.formClose;

close cGetChainInfo;

end if;

lib.epilog;

\-- \*\*\* Error trap

exception when others then

err_msg(to_char(SQLCODE), SQLERRM);

end;

end;

\-- \*\*\* END PROCEDURE chains \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

procedure err_msg(err_code in varchar2, err_str in varchar2) is

begin

htp.centerOpen;

htp.tableOpen(\'BORDER=2\');

htp.tableHeader(\'ERROR NO:\');

htp.tableHeader(\'ERROR MESSAGE:\');

htp.tableRowOpen;

htp.tableData(err_code);

htp.tableData(err_str);

htp.tableRowOpen;

htp.tableRowClose;

htp.tableClose;

htp.para;

htp.p(\'Use the \'\|\|\'\'\'BACK\'\'\'\|\|\' button and correct the
error if necessary.\');

htp.centerClose;

return;

end;

END;

/