#! /bin/ksh

html-header Faculty


echo "
This report contains details of all the faculty in the survey,
sorted by last name.  The report begins with a table of contents
containing:
<ul>
 <li>the faculty name
 <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>Name:          <td>the the name and title of the faculty
<tr valign=top>
 <td>Degree:        <td>the academic degrees(s) obtained by the faculty
<tr valign=top>
 <td>Email:         <td>the electronic mail address of the faculty
<tr valign=top>
 <td>Phone:         <td>the phone number of the faculty
<tr valign=top>
 <td>Institution:   <td>the institution (e.g., university) of the faculty
<tr valign=top>
 <td>Unit:          <td>the academic unit of the faculty
<tr valign=top>
 <td>Interests:     <td>the subjects of interest to the faculty
<tr valign=top>
 <td>Publications:  <td>three HCI-related publications by the faculty
</table>
"

template="
<hr>
<table border=0>
<tr valign=top>
	<td><a name=\"%name\">Name:</a><td> <b>%+name</b>, %title
<tr valign=top>
	<td>Degree:<td> %degree
<tr valign=top>
	<td>Email:<td> <a href=mailto:%email>%email</a>
<tr valign=top>
	<td>Phone:<td> %phone
<tr valign=top>
	<td>Institution:<td> %institution
<tr valign=top>
	<td>Unit:<td> <a href=Data/%codename>%unit</a>
<tr valign=top>
	<td>Interests:<td> <ul>%interests</ul>
<tr valign=top>
	<td>Publications:<td> <ul>%publications</ul>
</table>
"

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
echo "<ol>"
sssort -f name:P $FACULTY |
	ssformat -t "<li><a href=\"#%name\"><b>%name</b></a> <a href=Data/%codename>%shortname</a>"
echo "</ol>"

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

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

/bin/rm -f $FACULTY
