-- param takes a string and a number and creates a 1-column table
-- of that string repeated that number of times.
-- this version uses dynamic parameters
-- drop-down menu for advisor

create or replace procedure new_student2
as
i number;
cursor c1 is select s.studentid,s.last,s.first, s.startterm, s.facultyid,
	m.majordesc || ' (' || m.majorid || ')' AS MAJOR
	from student s, major m
	where s.majorid = m.majorid
	order by s.studentid;
rec c1%rowtype;

cursor c2 is select facultyid from faculty;
c2_rec c2%rowtype;

cursor c3 is select m.majordesc || ' (' || m.majorid || ')' AS MAJOR from major m;
c3_rec c3%rowtype;

begin
    htp.htmlOpen;
    htp.headOpen;
    htp.title('New Student');
    htp.headClose;
    htp.bodyOpen;


    htp.formOpen('/indo/make_new_student', 'GET');	-- note leading /
    htp.header(2, 'Create a new student record');
    
    htp.tableOpen;
    
    htp.tableRowOpen;
    htp.tableData('Student ID');
    htp.tableData(htf.formText('studid', 30, 50));
    htp.tableRowClose;
    htp.br;
    
    htp.tableRowOpen;
    htp.tableData('Last Name');
    htp.tableData(htf.formText('lname', 30, 50));
    htp.tableRowClose;
    htp.br;
    
    htp.tableRowOpen;
    htp.tableData('First Name');
    htp.tableData(htf.formText('fname', 30, 50));
    htp.tableRowClose;
    htp.br;
    
    htp.tableRowOpen;
    htp.tableData('start term');
    htp.tableData(htf.formText('startterm', 30, 50, 'SP03'));
    htp.tableRowClose;
    htp.br;
    
    
    htp.tableRowOpen;
    htp.tableData('Major ID');
    htp.tableData(htf.formText('major', 30, 50));
    htp.tableRowClose;
    htp.br;
    
    htp.tableClose;

    --htp.tableRowOpen;
    htp.tableData('Advisor ID');
    htp.print('<td>');
    htp.formSelectOpen('advisor');   --, 'Advisor:');
    for c2_rec in c2 loop
    	htp.formSelectOption(c2_rec.facultyid);
    end loop;
    htp.formSelectClose;
    htp.print('</td>');
    --htp.tableData(htf.formText('advisor', 30, 50, 555));
    --htp.tableRowClose;

    htp.br;

     
    htp.formSubmit('theButton', 'do it');
    htp.formSubmit('theButton', 'cancel');

    htp.formClose;
        

    htp.print('Here are the existing students');

    htp.tableOpen(cattributes => 'border=2 width=60%' );
    htp.tableRowOpen;
    htp.tableHeader('StudentID');
    htp.tableHeader('Last name');
    htp.tableHeader('First name');
    htp.tableHeader('start term');
    htp.tableHeader('advisor');
    htp.tableHeader('major');		-- notice how I gave this a name above

    for rec in c1 loop
    	htp.tableRowOpen;
    	htp.tableData(rec.studentid);
    	htp.tableData(rec.last);
    	htp.tableData(rec.first);
    	htp.tableData(rec.startterm);
    	htp.tableData(rec.facultyid);
    	htp.tableData(rec.major);
    	htp.tableRowClose;
    end loop;
    htp.tableClose;

    htp.bodyClose;
    htp.htmlClose;
end;
/
show errors

