#! /bin/ksh

report-header Faculty

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

echo "$line1
This report contains details of all the faculty in the survey,
sorted by last name.  The report begins with a table of contents
containing:
 * the faculty name
 * the 'code' for the program, based on the institution and unit
 * the 'shortname' for the institution and academic unit,
   possibly truncated to fit inside 80 characters
Entries in the main part of the report contain:
 NAME:          the the name and title of the faculty
 DEGREE:        the academic degrees(s) obtained by the faculty
 EMAIL:         the electronic mail address of the faculty
 PHONE:         the phone number of the faculty
 INSTITUTION:   the institution (e.g., university) of the faculty
 UNIT:          the academic unit of the faculty
 INTERESTS:     the subjects of interest to the faculty
 PUBLICATIONS:  three HCI-related publications by the faculty
$line2"

template="$line1
NAME: %+name, %title
DEGREE: %degree
EMAIL: %email
PHONE: %phone
INSTITUTION: %institution
UNIT: %unit
INTERESTS: %interests
PUBLICATIONS: %publications"

FACULTY=/tmp/fac$$
/bin/rm -f $FACULTY

for i in ${*-*}
do
    #echo "$line2 ${i##*/}"
	# Add unit institution and unit to faculty records
	record=`sssearch section=unit $i`
	unit=`echo "$record" | ssformat -t "%unit"`
	inst=`echo "$record" | ssformat -t "%inst"`
	shortname=`echo "$record" | ssformat -t "%shortname"`
	sssearch section=faculty $i |
		ssadd -f codename -t ${i##*/} |
			ssadd -f shortname -t "$shortname" |
				ssadd -f Unit -t "$unit" |
					ssadd -f Institution -t "$inst" >> $FACULTY
done

# Table of Contents
sssort -f name:P $FACULTY |
	ssformat -t "%-22.22name %-14.14codename %-.42shortname"

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

sssort -f name:P $FACULTY |
	ssfill -f name,degree,inst,unit,interest,public -w 65 |
		ssformat -t "$template" |
			clean

/bin/rm -f $FACULTY
