#!/bin/ksh

# creates an os/2 version of the aix fax menus
# Create os2 Fax Menus (fax.menu.html and all.faxes.html)
# for INTERNAL PitStop

# Author:  Cynthia Roush
# Date:    03/19/96

# Changes:
#   04/22/96  CR   Incorporate search and html faxes, and make it
#                  look more like Jim's format.
#   05/06/96  CR   Change from fax_search.sh to gen_search.sh.
#   06/03/96  EHR  Modify for os2 pkg remove search form
#                  links and gifs changed.
# ------------------------------------------------------------

. /u/hsim/other/fax.data/scripts/setvars
cd $TMPDIR

# Build PitStop TOP fax menu ###########

TMP=${TMPDIR}/pitstop.fax.$$
TGT=${HTMLDIR}/index.htm
SRC=${HTMLDIR}/top.ten.for.pitstop

date=`date "+%B %d, %Y"`

echo "<html>" > $TMP
echo "<title>AIX Technical Fax Documents</title>" >> $TMP
echo "<a href="help.htm"> <img src=fax.gif> </a>" >> $TMP
echo "$date" >> $TMP
echo "<p><center>" >> $TMP
echo "<img src="blckln.gif" border="0"></center>" >> $TMP

echo "<p><font size=+3>Top Ten Faxes</font>" >> $TMP
echo "<ul>" >> $TMP

while read FAXNAME
do
   # Get title, etc., from db
   grep "^ $FAXNAME" $FAXDB > tmp$$
   TITLE=`cut -c$TTL_COLS tmp$$ | sed "s/ *\(.*[^ ]\) *$/\1/"`
   cut -c$VM_COLS tmp$$ | read VMNAME

   echo "<li> <a href=$VMNAME.htm>$TITLE</a>" >> $TMP

done < $SRC

echo "</ul>" >> $TMP
echo "<p><font size=+3>Ten Newest Faxes</font>" >> $TMP
echo "<ul>" >> $TMP

SRC=${HTMLDIR}/ten.newest.for.pitstop

while read FAXNAME
do
   # Get title, etc., from db
   grep "^ $FAXNAME" $FAXDB > tmp$$
   TITLE=`cut -c$TTL_COLS tmp$$ | sed "s/ *\(.*[^ ]\) *$/\1/"`
   cut -c$VM_COLS tmp$$ | read VMNAME
 
   echo "<li> <a href=$VMNAME.htm>$TITLE</a>" >> $TMP

done < $SRC

echo "</ul>" >> $TMP
echo "<p><center>" >> $TMP
echo "<img src="blckln.gif" border="0"></center>" >> $TMP
echo "</html>" >> $TMP


# Build PitStop all-fax menu ###########

# remove comments, links, and limited distribution faxes
sed "/^#/d" $FAXDB > tmp$$
sed "/<linked/d" tmp$$ > tmp1$$
sed "/! limited/d" tmp1$$ > tmp$$
sed "/ notVM/d" tmp$$ > tmp1$$
mv tmp1$$ tmp$$

# sort by title
sort -t ! -o tmp1$$ -k $TTL_FIELD tmp$$ 
mv tmp1$$ src.dt.$$

while read LINE
do

  # Get variables from LINE, which was read from group.names
  COMPGRP=`echo $LINE | sed "s/^\(...\).*/\1/"`
  TITLE=`echo $LINE | sed "s/^... *\(.*\)$/\1/"`

  # Write title to contents list
  echo "<li><a href=\"#$TITLE\">$TITLE</a>" >> contents$$

  # Separate component groups
  grep "! $COMPGRP !" src.dt.$$ > group$$

  # Separate file name and doc title, revision date and 4FAX#
  #cut -c$FN_COLS group$$ > fn$$
  cut -c$VM_COLS group$$ > vm$$
  cut -c$TTL_COLS group$$ > ttl$$
  #cut -c$NUM_COLS group$$ > num$$

  # Remove blanks around file names 
  #/u/hsim/execs/endblanks fn$$
  /u/hsim/execs/endblanks vm$$
  #sed "s/^ //" fn$$ > tmp$$
  #mv tmp$$ fn$$
  sed "s/^ //" vm$$ > tmp$$
  mv tmp$$ vm$$

  # copy title column because need it twice
  cp ttl$$ ttl2$$

  # add html syntax
  sed "s/.*/<li> <a href=&.htm>/" vm$$ > tmp$$
  mv tmp$$ vm$$

  sed "s/ *\(.*[^ ]\) *$/\1<\/a>/" ttl2$$ > tmp$$
  mv tmp$$ ttl2$$

  # put file names and doc titles and dates together
  paste -d "\0" vm$$ ttl2$$ > all$$

  # add rest of link syntax

  echo "<p><font size=+3> <a name=\"$TITLE\">$TITLE</a></font>" >> final.dt.$$
  echo "<ul>" >> final.dt.$$
  cat all$$ >> final.dt.$$
  echo "</ul>" >> final.dt.$$
  
done < $DBDIR/group.names


# Add header and footer information
/u/hsim/execs/endblanks final.dt.$$
echo "<center><font size=+3>All Faxes By Category</center></font>" >> $TMP
echo "<p><center>" >> $TMP
echo "<img src="blckln.gif" border="0"></center>" >> $TMP
echo "<p>" >> $TMP
echo "<p><font size=+3>Contents</font>" >> $TMP
echo "<ul>" >> $TMP
cat contents$$ >> $TMP
echo "</ul>" >> $TMP
echo "<hr>" >> $TMP
cat final.dt.$$ >> $TMP
echo "<p><p>" >> $TMP
echo "<center>" >> $TMP
echo "<img src="blckln.gif" border="0"></center>" >> $TMP
echo "</html>" >> $TMP

###############
mv $TMP $TGT
rm -f *$$
chmod a+r $TGT

cd /u/hsim/other/fax.data/html
# --- acquire permission to write out to afs
grep afs.*wwadmin ~/.netrc | read Mach Afs Login User Pass AFS_PASSWORD

klog -principal wwadmin -password $AFS_PASSWORD
echo "copying to os2fax.htm"
cp /u/hsim/other/fax.data/html/index.htm /afs/austin/depts/aixserv/os2fax.htm/
unlog


#mv $TGT /afs/austin/depts/aixserv/faxes.html/

# cd to u/hsim/execs
# change.stuff.sh to copy over afs .html files and rename in proper
# os2fax.htm dir and give .htm extensions plus fix date format.

cd /u/hsim/execs
change.stuff.sh
