#! /bin/ksh

html-header Courses

echo "
This report contains details of all the courses in the survey,
sorted by the program code.  The report begins with a table
of contents containing:
<ul>
 <li>the <b><i>shortname</i></b> for the institution and academic unit
</ul>
Entries in the main part of the report contain:
<table border=0>
<tr valign=top>
 <td>Course:        <td>the course title (and course number)
<tr valign=top>
 <td>Instructor:    <td>all faculty who teach the course
<tr valign=top>
 <td>Frequency:     <td>how often the course is taught
<tr valign=top>
 <td>Times_Taught:  <td>how many times the course has been taught
<tr valign=top>
 <td>Enrollment:    <td>the approximate enrollment for recent offerings
<tr valign=top>
 <td>Text:          <td>the text(s) used in the course
<tr valign=top>
 <td>Tools:         <td>software and hardware tools used in the course
<tr valign=top>
 <td>Description:   <td>a short description of the course
</table>
"

# Table of Contents
echo "<ol>"
for i in ${*-*}
do
	sssearch section=unit $i |
		ssadd -f codename -t "${i##*/}"
done | ssformat -t "<li><a href=\"#%codename\">%shortname</a>"
echo "</ol>"

template="<hr>
<table border=0>
<tr valign=top>
	<td>Course:<td> %+title (%number)
<tr valign=top>
	<td>Instructor:<td> %instructor
<tr valign=top>
	<td>Frequency:<td> %frequency
<tr valign=top>
	<td>Times_Taught:<td> %times_taught
<tr valign=top>
	<td>Enrollment:<td> %enrollment
<tr valign=top>
	<td>Text:<td> <ul>%text</ul>
<tr valign=top>
	<td>Tools:<td> <ul>%tools</ul>
<tr valign=top>
	<td>Description:<td> %description
</table>
"

function clean
	{
	sed '
		s/ +$//
		s/<ul>+/<ul>/
		s/<ol>+/<ol>/
		s/^ \* /<li>/
		s/^ - /<li>/
		s/^ + /<li>/
		' $*
	}

for i in ${*-*}
do
	sssearch section=unit $i |
		ssformat -t "<hr><a name=\"${i##*/}\"><h3>%Shortname</h3></a>"
	sssearch section=course $i |
		ssformat -t "$template" |
			clean
done 

