drop package carrier; / create or replace package carrier is /* procedure AddVisitor(host in char,address in char,user in char,name char); procedure showvisitors; procedure clearvisitors; procedure clear_action(userid in char,passwd in char,clear in number);*/ --procedure bom_admin(userid in varchar2,passwd in varchar2); procedure bom_admin_home(uid varchar2); procedure bom_admin_index; procedure bom_admin(uid in varchar2,passwd in varchar2); function validation(uid in varchar2,passwd in varchar2,grp integer) return boolean; function validation(uid in varchar2,grp integer) return boolean; procedure insert_user_index(userid in varchar2); procedure insert_user(userid in varchar2); procedure insert_u(uid varchar2,email varchar2, passwd varchar2,name varchar2,grp integer,host varchar2,url varchar2,me varchar2); procedure all_user(uid in varchar2); procedure password_typein(url varchar2); procedure passwd_action(me varchar2,passwd varchar2,uid varchar2); procedure passwd(me varchar2,uid varchar2); procedure passwd_action1(old varchar2,p1 varchar2,p2 varchar2,uid varchar2); procedure passwd1(uid varchar2); procedure demo_user; procedure delete_user(me varchar2) ; procedure delete_user_action(me varchar2,uid varchar2); procedure insert_bom(me varchar2); procedure insert_bom_action(me varchar2,p_no in varchar2,pca in varchar2,opca in varchar2,type in varchar2,family in varchar2, pitem in char,cost in number,rlevel in char,mm in char,dd in char,yy in char,d in varchar2) ; procedure all_bom(uid in varchar2,op integer); procedure move_pending(uid in varchar2,p varchar2); procedure move_pending(uid in varchar2); procedure change(uid in varchar2,p varchar2,mm in char,dd in char,yy in char); procedure move(uid in varchar2,p varchar2); procedure notyet(uid varchar2); procedure notyet; procedure move_prod(uid varchar2) ; procedure bom_search_index; procedure bom_search; procedure bom_search(op integer,fid varchar2); procedure search(typein varchar2,op integer,fid varchar2); procedure all_bom_prod; procedure bom_list(p varchar2,pca varchar2,time varchar2,f varchar2,c number,t varchar2,i varchar2,r varchar2, d varchar2,ctime date); procedure by_pca(fid varchar2); procedure search_button(op integer,fid varchar2); procedure by_pca(fid varchar2,p varchar2) ; procedure keyword(p varchar2,fid varchar2); procedure day(str varchar2,result out date,tag in out char) ; procedure date_search; procedure parse_date(typein varchar2) ; function tr(name varchar2) return varchar2; function th(name varchar2) return varchar2; function td(name varchar2) return varchar2; cgi_bin constant varchar2(60) := '/cgi-bin/demo/wow/'; username constant varchar2(10) := 'carrier'; password constant varchar2(10) := 'demo'; client varchar2(30) := owa.remote_addr; time_out number(8,5) := 5./1440.; help_page constant varchar2(100) := htf.url('http://naos.npac.syr.edu:1963/demo/help.html','Help'); end; / create or replace package body carrier is total_visitors number(7); total number(8); hh_time date; h_host users.host%TYPE; h_grp users.group_id%TYPE; one users%ROWTYPE; two bom%ROWTYPE; h_time varchar2(50) := '
'; h_family bom.p_family%TYPE := '
'; h_cost bom.s_cost%TYPE; h_desc varchar2(2000); h_status varchar2(30):= 'Production (most recent)'; h_caption varchar2(600); -- for date TYPE wordstype IS TABLE OF varchar2(50) INDEX BY BINARY_INTEGER; word_tab wordstype; w_count BINARY_INTEGER; date_tag char(1); function td(name varchar2) return varchar2 is begin return (''||name||''); end; function th(name varchar2) return varchar2 is begin return (''||name||''); end; function tr(name varchar2) return varchar2 is begin return (''||name||''); end; procedure bom_admin_home(uid varchar2) is begin select group_id into h_grp from users where userid=uid; htp.p('
'); if (h_grp = 5) then htp.p(tr(td(htf.url(cgi_bin||'carrier.insert_user_index?userid='||uid, 'Insert a BoM user'))||td('Insert a new BoM user into the system')|| td(htf.url('/carrier/users.html','BoM DB Administrator')))); htp.p(tr(td(htf.url(cgi_bin||'carrier.delete_user?me='||uid, 'Delete a BoM user'))||td('Remove an existingBoM user from the system')|| td(htf.url('/carrier/users.html','BoM DB Administrator')))); htp.p(''||td(htf.url(cgi_bin||'carrier.all_user?uid='||uid, 'List Users/Change Passwords'))); htp.p(td('Show all BoM users or change their passwords in the system')|| td(htf.url('/carrier/users.html','BoM DB Administrator'))||''); end if; if (h_grp >= 1) then htp.p(''||td(htf.url(cgi_bin||'carrier.all_bom?uid='||uid||'&op=1', 'List All BoM document in production'))); htp.p(td('Display all BoM production document, including most recent and all the previous revisions')|| td(htf.url('carrier/users.html','Produciton BoM User II and III'))||''); end if; if (h_grp <= 2 or h_grp >= 5 ) then htp.p(''||td(htf.url(cgi_bin||'carrier.move_prod?uid='||uid, 'Move Production BoM''s between Divisions'))); htp.p(td('Move BoM ducument owned by one division to another')|| td(htf.url('carrier/users.html','Produciton BoM User III'))||''); end if; if (h_grp >= 3) then htp.p(''||td(htf.url(cgi_bin||'carrier.all_bom?uid='||uid||'&op=0', 'List all pending BoM document'))); htp.p(td('Display all pending BoM''s and check their effective dates')|| td(htf.url('carrier/users.html','Pending BoM User II and III'))||''); htp.p(''||td(htf.url(cgi_bin||'carrier.insert_bom?me='||uid, 'Insert a BoM document'))); htp.p(td('Insert a new BoM document into the pending document database')|| td(htf.url('/carrier/users.html','Pending BoM User II and III'))||''); htp.p(''||td(htf.url(cgi_bin||'carrier.notyet?uid='||uid, 'Delete a pending BoM document'))); htp.p(td('Delete an existing BoM document from the pending database')|| td(htf.url('carrier/users.html','Pending BoM User II and III'))||''); htp.p(''||td(htf.url(cgi_bin||'carrier.notyet?uid='||uid, 'Move a pending BoM document to production status'))); htp.p(td('change a pending BoM status to production after the effective date is reached')|| td(htf.url('carrier/users.html','Pending BoM User II and III'))||''); end if; if (h_grp >= 4) then htp.p(''||td(htf.url(cgi_bin||'carrier.assign_pending?uid='||uid, 'change/assign an effective date to a pending BoM document'))); htp.p(td('assign or change the effective date for a pending BoM to be moved to production')|| td(htf.url('carrier/users.html','Pending BoM User III'))||''); end if; htp.p(''||td(htf.url(cgi_bin||'carrier.passwd1?uid='||uid, 'Change your password'))||td('Create a new password for yourself')); htp.p(td(htf.url('carrier/users.html','Any registered BoM user'))||''); htp.p('
BoM Document and User Management and Control'); htp.p('
OperationDescriptionAuthorized User
'); wow.sig; end; procedure bom_admin_index is begin htp.p(''); htp.p('This page is for authorized user only.
'); htp.p('
'); htp.p('
'); htp.p(''); htp.p(''); htp.p('
User Id :
Password :
'); htp.p(htf.formDo('Submit')); htp.p('
'); demo_user; end; procedure demo_user is begin htp.p('
'); htp.p(tr(th('Userid/Password')||th('Privilege'))); htp.p(tr(td(' root/demo')||td(' BoM DB Admin.'))); htp.p(tr(td(' user2/user2')||td(' BoM Production User II'))); htp.p(tr(td(' user3/user3')||td(' BoM Production User III'))); htp.p(tr(td(' user4/user4 ')||td(' BoM Pending User II'))); htp.p(tr(td(' user5/user5')||td(' BoM Pending User III'))); htp.p('
Demo Users
'); end; procedure bom_admin(uid in varchar2,passwd in varchar2) is begin htp.p(''); if (validation(uid,passwd,1)) then bom_admin_home(uid); else bom_admin_index; end if; end; procedure password_typein(url varchar2) is begin htp.p('This operation is for authorized BoM DB admin. only.
'); htp.p('
'); htp.p('
'); htp.p(''); htp.p(''); htp.p('
User Id :
Password :
'); htp.p(htf.formDo('Submit')); htp.p('
'); demo_user; end; procedure insert_user_index(userid in varchar2) is begin --htp.p(''); if (validation(userid,5)) then insert_user(userid); end if; end; function validation(uid in varchar2,passwd in varchar2,grp integer) return boolean is cursor cuser(uid varchar2,pwd varchar2) is select group_id from users where userid=uid and password=pwd; h_grp integer; begin open cuser(uid,passwd); fetch cuser into h_grp; if (cuser%NOTFOUND) then close cuser; htp.p(''); htp.p('
You have the wrong userid/password !
'); htp.p('Try again.'); return false; elsif ((h_grp=4) and (h_host!=client))) then close cuser; htp.p(''); htp.p('
You do not have the privilegeto perform this operation.
'); return false; end if; close cuser; update users set time=sysdate where userid=uid; update users set host=client where userid=uid and group_id >=4; commit; return true; end; function validation(uid in varchar2,grp integer) return boolean is cursor cuser(u varchar2,g integer) is select time,host from users where userid=u and group_id>=g; begin open cuser(uid,grp); fetch cuser into hh_time,h_host; if ((cuser%NOTFOUND) or (h_host != client)) then close cuser; htp.p(''); htp.p('
You do not have the privilegeto perform this operation.

'); htp.p('Go back.

'); return false; elsif ((sysdate - hh_time) > time_out) then -- 10 minutes close cuser; htp.p(''); htp.p('Your login time is out. Last login: '||to_char(hh_time,'mm/dd/yy hh24:mi')||' EST.'); htp.p('Re-login again.
'); bom_admin_index; return false; end if; close cuser; update users set time=sysdate where userid=uid; commit; return true; end; procedure insert_user(userid in varchar2) is begin htp.p(''); htp.p('

Insert a new BoM user

'); htp.p('
'); htp.p('
'); htp.p(''); htp.p(''); htp.p(''); htp.p(''); htp.p(''); htp.p(''); htp.p(''); htp.p(''); htp.p('
User Id :
Initial Password :
Name :
Email Address :
Privilege :
Client Host (for User III only) :
URL (optional):
'); htp.p(htf.formDo('Submit')); htp.p(''); htp.p('

'); all_user(userid); wow.sig; end; procedure all_user(uid varchar2) is cursor cuser is select * from users order by userid; h_time varchar2(20) := '
'; h_host users.host%TYPE := '
'; h_url users.url%TYPE; h_grp varchar2(20) := 'Production User II'; begin if (not validation(uid,5)) then return; end if; htp.p(''); htp.p('
'); select count(*) into total from users; if (total > 0 ) then htp.p('There are total '||htf.bold(total)||' users.'); htp.p('
'); htp.p(''); htp.p(tr(th('User Id')||th('Name')||th('User Group')||th('Hostname')||th('URL')||th('Last login'))); open cuser; loop fetch cuser into one; exit when cuser%NOTFOUND; if (one.group_id = 2) then h_grp := 'Production User III'; elsif (one.group_id = 3) then h_grp := 'Pending User II'; elsif (one.group_id = 4) then h_grp := 'Pending User III'; elsif (one.group_id = 5) then h_grp := 'BoM DB Administrator'; end if; if (one.url IS NULL or one.url like '%N/A%') then h_url := '
'; else h_url := htf.url(one.url,one.url); end if; if (one.time IS NOT NULL) then h_time := to_char(one.time,'mm/dd/yy, hh24:mi')||' EST'; else h_time := '
'; end if; if (one.group_id >= 3 and one.host IS NOT NULL) then h_host := one.host; else h_host := '
'; end if; htp.p(tr(td(htf.url(cgi_bin||'carrier.passwd?me='||uid||'&uid='||one.userid,one.userid))|| td(one.name)||td(h_grp)||td(h_host)||td(h_url)||td(h_time))); end loop; close cuser; htp.p('
Current BoM users in the system
'); else htp.p('No user for BoM system yet.'); end if; end; procedure passwd(me varchar2,uid varchar2) is begin if (validation(me,5)) then htp.p('
'); select * into one from users where userid = uid; htp.p('
'); htp.p(''); htp.p(tr(td('User Id: ')||td(one.userid))); htp.p(tr(td('Name: ')||td(one.name))); htp.p(tr(td('New Password: ')||td(''))); htp.p('
Change a user''s password
'); htp.p(''); htp.p(''); htp.p(htf.formDo('Submit')); htp.p('
'); wow.sig; end if; end; procedure passwd1(uid varchar2) is begin if (validation(uid,1)) then htp.p('
'); select * into one from users where userid = uid; htp.p('
'); htp.p(''); htp.p(tr(td('User Id: ')||td(one.userid))); htp.p(tr(td('Name: ')||td(one.name))); htp.p(tr(td('Old Password: ')||td(''))); htp.p(tr(td('New Password: ')||td(''))); htp.p(tr(td('New Password Again: ')||td(''))); htp.p('
Change your password
'); htp.p(''); --htp.p(''); htp.p(htf.formDo('Submit')); htp.p('
'); wow.sig; end if; end; procedure passwd_action1(old varchar2,p1 varchar2,p2 varchar2,uid varchar2) is begin if (validation(uid,1)) then select * into one from users where userid = uid; if (one.password != old or (p1!=p2)) then htp.p('Wrong password. Try again.
'); passwd1(uid); return; end if; htp.p('
'); update users set password=p1 where userid=uid; commit; htp.p('Your password has been changed.
'); bom_admin_home(uid); end if; end; procedure passwd_action(me varchar2,passwd varchar2,uid varchar2) is begin if (validation(me,5)) then htp.p('
'); update users set password=passwd where userid=uid; commit; htp.p(htf.bold(uid)||' password has been changed.
'); bom_admin_home(uid); end if; end; procedure insert_u(uid varchar2,email varchar2, passwd varchar2,name varchar2,grp integer,host varchar2,url varchar2,me varchar2) is cursor cuser(u varchar2) is select * from users where userid=u; uu users%ROWTYPE; begin if ((uid||passwd||name) IS NULL) then htp.p('The field '||htf.bold('User Id/Name/Password')||' must not be blank.'); htp.p('

Go back and correct it. Try again.'); return; end if; if (grp >= 4 and host IS NULL) then htp.p('The field '||htf.bold('Host')||' must not be blank.'); htp.p('

Go back and correct it. Try again.'); return; end if; open cuser(uid); fetch cuser into uu; if (cuser%FOUND) then htp.p('There is already a user with the userid = '||htf.bold(uid)||' in the system.'); htp.p('

Go back and correct it. Try again.'); return; else insert into users values(uid,passwd,email,name,grp,host,sysdate,url,null,null); COMMIT; end if; htp.p('


The new user '||htf.bold(uid)||' ('||name||') has been sucessfully added into the BoM user list.'); htp.p('

You may send an email to inform '||email||' of this new account.'); all_user(me); wow.sig; end; procedure delete_user(me varchar2) is cursor cuser is select * from users where group_id <= 5 order by userid; begin if (validation(me,5)) then htp.p('


'); select count(*) into total from users; htp.p('
Total '||total||' BoM users. Which one to remove ?:
'); open cuser; htp.p('
'); htp.p(''); close cuser; htp.p(htf.formDo('Delete')); htp.p(''); htp.p('
'); htp.p('
'); htp.p(''); end if; end; procedure delete_user_action(me varchar2,uid varchar2) is begin if (validation(me,5)) then htp.p('
'); delete from users where userid=uid; commit; htp.p('User '||htf.bold(uid)||' has been removed.
'); all_user(me); wow.sig; end if; end; procedure insert_bom(me varchar2) is cursor cbom is select distinct pca from bom order by pca; h_pca bom.pca%TYPE; begin if (validation(me,3)) then htp.p('
'); htp.bp(' This page allows a user to insert a new BoM document with required attributes and indexes into the database so that other users can search and access. Upon the entering of a new document into the DB, the infomation will be validated to make sure data consisency and other criteria required by a relational database management system. If invalid data entry is found, the user will be requested to re-enter the entry. If all data are correct, the new information will be inserted and are immediately available to other users to share. The data items used here are fake data for demo only. In actual situation, more complex data structure and data entry requirement are expected.
'); htp.p(''); htp.bp('
Insert a new BoM document
Data ItemNew Value to be inserted
Part No.
New PCA'); open cbom; loop fetch cbom into h_pca; exit when cbom%NOTFOUND; if cbom%ROWCOUNT = 1 then htp.p('Or choose from: '); else htp.p(''); end if; close cbom; htp.bp('
Item StatusPending
BoM Item Type
Product Family
Purchased Item
STD Unit Cost
Revise Level
Effective Date// (mm/dd/yy)
Description
'); htp.p(''); htp.p('
'); end if; wow.sig; end; procedure insert_bom_action(me varchar2,p_no in varchar2,pca in varchar2,opca in varchar2,type in varchar2,family in varchar2, pitem in char,cost in number,rlevel in char,mm in char,dd in char,yy in char,d in varchar2) is edate date; cursor cbom(p varchar2) is select part_no from bom where part_no = p; h_part_no bom.part_no%TYPE; h_pca bom.pca%TYPE; begin if (not validation(me,3)) then return; end if; htp.p('
'); h_pca:=pca; if (pca IS NULL) then h_pca := opca; end if; if (p_no IS NULL or h_pca IS NULL) then htp.p('The Part No. and PCA must be provided. Try again.
'); insert_bom(me); return; end if; if ((mm||dd) IS NOT NULL) then edate := to_date(lpad(mm,2,'0')||lpad(dd,2,'0')||lpad(yy,2,'0'),'mmddyy'); if (to_char(edate,'mmddyy') < to_char(sysdate,'mmddyy')) then htp.p('**Invalid Date**: The effective date you enterered ('||edate||') is less than'); htp.p('today ('||sysdate||'). Try again.
'); insert_bom(me); return; end if; end if; open cbom(p_no); fetch cbom into h_part_no; if (cbom%FOUND) then close cbom; htp.p('There is already a BoM document with the part no. = '||htf.bold(p_no)||' in the system.'); htp.p('

Correct it. Try again.');insert_bom(me); return; else insert into bom values(p_no,rlevel,pitem,h_pca,'Pending',sysdate,family,cost,edate,d,type); COMMIT; end if; close cbom; htp.p('

The BoM document (Part No.='||htf.bold(p_no)||') has been sucessfully added into the BoM pending document DB.'); all_bom(me,0); wow.sig; end; procedure move_prod(uid varchar2) is begin if (not validation(uid,2)) then return; end if; notyet(uid); end; procedure notyet(uid varchar2) is begin if (not validation(uid,1)) then return; end if; htp.p('

Sorry, this function has not implemented yet in the demo. Stay tuned!'); bom_admin_home(uid); end; procedure move_pending(uid in varchar2) is begin if (not validation(uid,3)) then return; end if; htp.p('Choose a document for the list below'); all_bom(uid,0); end; procedure move_pending(uid in varchar2,p varchar2) is h_date date; h_grp integer; h_status bom.status%TYPE; begin if (not validation(uid,3)) then return; end if; htp.p(''); htp.p('
'); select group_id into h_grp from users where userid=uid; select effective_date,status into h_date,h_status from bom where part_no=p; if (h_grp >=3 and lower(h_status) like '%pending%') then if (to_char(h_date,'mmddyy') <= to_char(sysdate,'mmddyy')) then htp.p(htf.url(cgi_bin||'carrier.move?uid='||uid||'&p='||p,'Move this document to production')); htp.p('
'); else htp.p('This document ('||htf.bold(p)||') has not reached its effective day yet. Effective='||h_date); htp.p('.
You can not move it to the production area. Wait until its effective date.'); end if; end if; if (h_grp >=4 ) then htp.p('
'); htp.p('Change the effective date from '||htf.bold(h_date)); htp.p('

to // (mm/dd/yy)'); htp.p(''); htp.p(''); htp.p(''); htp.p('

'); end if; end ; procedure change(uid in varchar2,p varchar2,mm in char,dd in char,yy in char) is edate date; begin if (not validation(uid,3)) then return; end if; if ((mm||dd) IS NOT NULL) then edate := to_date(lpad(mm,2,'0')||lpad(dd,2,'0')||lpad(yy,2,'0'),'mmddyy'); if (to_char(edate,'mmddyy')< to_char(sysdate,'mmddyy')) then htp.p('**Invalid Date**: The effective date you enterered ('||edate||') is less than'); htp.p('today ('||sysdate||'). Try again.
'); move_pending(uid,p); return; end if; else htp.p('Wrong Date. Try again.'); move_pending(uid,p); return; end if; htp.p(''); htp.p('
'); update bom set effective_date=edate where part_no=p; commit; htp.p('The effective date of the pending document ('||htf.bold(p)||') has been assigned/changed to '||edate); all_bom(uid,0); end; procedure move(uid in varchar2,p varchar2) is begin if (not validation(uid,3)) then return; end if; htp.p(''); htp.p('
'); update bom set status='production' where part_no=p; commit; htp.p('The pending document ('||htf.bold(p)||') has been sucessfully moved to the produciton area.'); all_bom(uid,0); end; procedure all_bom(uid in varchar2,op integer) is cursor cuser(s varchar2) is select * from bom where lower(status) like '%'||s||'%' order by part_no; h_time varchar2(50) := '
'; h_family bom.p_family%TYPE := '
'; h_cost bom.s_cost%TYPE; h_desc varchar2(2000); h_status bom.status%TYPE := 'pending'; begin if (not validation(uid,3)) then return; end if; if (op = 1) then h_status := 'production'; end if; htp.p(''); htp.p('
'); select count(*) into total from bom where lower(status) like '%'||h_status||'%'; if (total > 0 ) then htp.p('There are total '||htf.bold(total)||' BoM '||h_status||' documents.
'); htp.p('
'); htp.p(''); htp.p(tr(th('Part No.')||th('PCA')||th('Effective Date(EST)')||th('Part Family')||th('Unit Cost')|| th('Item Type')||th('Purchased Item')||th('Revise Level')||th('Description')||th('Creation Date(EST)'))); open cuser(h_status); loop fetch cuser into two; exit when cuser%NOTFOUND; if (two.effective_date IS NOT NULL) then if (to_char(two.effective_date,'mmddyy')<=to_char(sysdate,'mmddyy') and op=0) then h_time := ''||to_char(two.effective_date,'mm/dd/yy, hh24:mi')||''; else h_time := to_char(two.effective_date,'mm/dd/yy, hh24:mi'); end if; else h_time := 'not set yet'; end if; if (two.p_family IS NULL) then h_family := '
'; else h_family := two.p_family; end if; if (two.s_cost IS NULL) then h_cost := 0.; else h_cost := two.s_cost; end if; if (two.description IS NULL) then h_desc := '
'; else h_desc := two.description; end if; if (op=0) then htp.p(''||td(htf.url(cgi_bin||'carrier.move_pending?uid='||uid||'&p='||two.part_no,two.part_no))); else htp.p(''||td(two.part_no)); end if; htp.p(td(two.pca)||td(h_time)||td(h_family)||td(h_cost)); htp.p(td(two.b_type)||td(two.p_item)||td(two.r_level)||td(h_desc)|| td(to_char(two.revise_date,'mm/dd/yy, hh24:mi'))||''); end loop; close cuser; htp.p('
Current BoM '||h_status||' documents in the system
'); if (op=0) then htp.p('If you noticed any document with blink effective date, that document needs to be moved immediately to the production area.'); end if; htp.p('
'); else if (op=0) then htp.p('No BoM Pending document yet.'); else htp.p('No BoM Production document yet.'); end if; end if; wow.sig; end; procedure bom_search_index is begin htp.p('

Carrier RTS BoM Document Search Page

'); htp.p(''); htp.p('