#! /bin/ksh

report-header Courses

line2="================================================================="
line1="-----------------------------------------------------------------"

echo "$line1
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:
 * the 'code' for the program, based on the institution and unit,
   which is repeated in the main part of the report at the start
   of the courses in a program
 * the 'shortname' for the institution and academic unit
Entries in the main part of the report contain:
 COURSE:        the course title (and course number)
 INSTRUCTOR:    all faculty who teach the course
 FREQUENCY:     how often the course is taught
 TIMES_TAUGHT:  how many times the course has been taught
 ENROLLMENT:    the approximate enrollment for recent offerings
 TEXT:          the text(s) used in the course
 TOOLS:         software and hardware tools used in the course
 DESCRIPTION:   a short description of the course
$line2"

# Table of Contents
for i in ${*-*}
do
	sssearch section=unit $i |
		ssadd -f codename -t "${i##*/}"
done | ssformat -t "%-14codename %shortname"

template="$line1
COURSE: %+title (%number)
INSTRUCTOR: %instructor
FREQUENCY: %frequency
TIMES_TAUGHT: %times_taught  ENROLLMENT: %enrollment
TEXT: %text
TOOLS: %tools
DESCRIPTION: %description"

function clean
	{
	sed 's/ +$//' $*
	}

for i in ${*-*}
do
	echo "$line2 ${i##*/}"
	sssearch section=unit $i |
		ssformat -t "%Shortname"
	sssearch section=course $i |
		ssfill -f freq,course,instruct,text,tool,desc -w 65 |
			ssformat -t "$template" |
				clean
done 

