#!/bin/ksh

# Create PitStop Fax Menus (fax.menu.html and all.faxes.html)
#   This version creates menus with slightly different file names
#   than create.pitstop.fax.menus and it uses the new URL method
#   that will be put into effect for pitstop on Feb. 1, 1996.

# Author:  Cynthia Roush
# Date:    09/19/95 - 09/27/95

# Changes:
#   10/09/95  CR   Substitute "plusplus" for "+" in file names.  psc_fax_show.sh
#                  will translate back.  "+" is misinterpreted as space.
#   01/16/96  CR   New URL method for new pitstop version

# ------------------------------------------------------------

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

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

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

echo "<html>" > $TMP
echo "<title>AIX Technical Fax Documents</title>" >> $TMP
echo "<h1>AIX Technical Fax Documents......." >> $TMP
echo "<hr>" >> $TMP
echo "<a href=file:/PitStop/packages/selfsrv/selfsrv.html><img src=file:/PitStop/packages/gifs/returnw.gif></a>" >> $TMP
echo "<a href=file:/PitStop/pitstop.html><img src=file:/PitStop/packages/gifs/pitbox.gif></a>" >> $TMP
echo "<hr></h1>" >> $TMP
echo "<form method=post action=http://localhost:21169/psc-scripts/psc_faxmenu_get.sh>">> $TMP
echo "<p><em>This page last updated on</em>" >> $TMP
echo ".<input type=submit value=\"Request latest update\">" >> $TMP
echo "</form>" >> $TMP

echo "<p>" >> $TMP
echo "<h2>Top Ten Faxes</h2>" >> $TMP
echo "<h3>" >> $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/"`
   TITLE2=`echo $TITLE | sed "s/ /!/g"`
   NUM=`cut -c$NUM_COLS tmp$$ | sed "s/ \(....\) /\1/"`

   # Repace "+" with "plusplus" to avoid misinterpretation on http server.
   # PitStop's psc_fax_show.sh will translate back to "+".
   FAXNAME=`echo $FAXNAME | sed "s/+/plusplus/g"`
 
   echo "<li> <a href=http://localhost:21169/psc-scripts/psc_fax_show.sh?$FAXNAME+$TITLE2+$NUM>$TITLE</a>" >> $TMP

done < $SRC

echo "</ul>" >> $TMP
echo "</em>" >> $TMP
echo "<h2>Ten Newest Faxes</h2>" >> $TMP
echo "<h3>" >> $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/"`
   TITLE2=`echo $TITLE | sed "s/ /!/g"`
   NUM=`cut -c$NUM_COLS tmp$$ | sed "s/ \(....\) /\1/"`
 
   # Repace "+" with "plusplus" to avoid misinterpretation on http server.
   # PitStop's psc_fax_show.sh will translate back to "+".
   FAXNAME=`echo $FAXNAME | sed "s/+/plusplus/g"`
 
   echo "<li> <a href=http://localhost:21169/psc-scripts/psc_fax_show.sh?$FAXNAME+$TITLE2+$NUM>$TITLE</a>" >> $TMP

done < $SRC

echo "</ul>" >> $TMP
echo "</em>" >> $TMP
#echo "<h3><a href=/pitstop/selfsrv/all.faxes.html>Public Faxes By Category</a> " >> $TMP
echo "<h3><a href=file:/PitStop/packages/selfsrv/all.faxes.html>Public Faxes By Category</a> " >> $TMP
echo "<br><a href=http://service.boulder.ibm.com/rbin-usa/getrobj.pl?/rdocs-usa/tips_hints.html>Registered Faxes By Category (SupportLine customers only)</a> <img src=file:/PitStop/packages/gifs/bolt.gif><img src=file:/PitStop/packages/gifs/key.gif>" >> $TMP
echo "<hr></h3><strong>" >> $TMP
echo "<a href=http://localhost:21169/psc-scripts/psc_fax_build_del_form.sh>Delete Selected Faxes from Local System</a>" >> $TMP
echo "</em>" >> $TMP
echo "<h4>" >> $TMP
echo "<hr>" >> $TMP
echo "<strong>PitStop Pages :</strong>" >> $TMP
echo "[ <a href=file:/PitStop/pitstop.html>PitStop</a> |
      <a href=file:/PitStop/packages/tools/tools.html>ToolBox</a> |
      <a href=file:/PitStop/packages/suptinfo/suptinfo.html> RoadMap</a> |
      <a href=file:/PitStop/html/search_form.html>Search</a> |
      <a href=file:/PitStop/html/feedback_form.html>Feedback</a>]
      <br> " >> $TMP
echo "<strong>Internet Pages:</strong>
      [<a href="http://service.boulder.ibm.com/aixsupport/">Support Family</a> |
      <a href="http://www.austin.ibm.com"> RISC Home Page</a> |
      <a href="http://www.ibm.com/">IBM Home Page</a> |
      <img src=file:/PitStop/packages/gifs/labelintr.gif>
      <p> " >> $TMP
echo "<hr>" >> $TMP
echo "</html>" >> $TMP
echo "<local=0>" >> $TMP

mv $TMP $TGT
chmod a+r $TGT

# 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$$
# remove fee faxes
sed "/! fee  !/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$TTL_COLS group$$ > ttl$$
  cut -c$NUM_COLS group$$ > num$$

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

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

  # add html syntax
  sed "s/^/<li> <a href=http:\/\/localhost:21169\/psc-scripts\/psc_fax_show.sh\?/" fn$$ > tmp$$
  # Replace "+" with "plusplus".  Will be translated back by psc_fax_show.sh.
  sed "s/+/plusplus/g" tmp$$ > fn$$

  mv ttl$$ tmp$$
  sed "s/ *$/+/" tmp$$ | sed "s/^ */+/" | sed "s/ /!/g" > ttl$$

  # remove blanks around 4fax number and add "+all"
  sed "s/ *$/+all>/" num$$ > tmp$$
  sed "s/^ *//" tmp$$ > num$$

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

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

  # add rest of link syntax

  echo "<h2> <a name=\"$TITLE\">$TITLE</a></h3>" >> 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 "<title>Public Faxes By Category</title>" > $HTMLDIR/pitstop.allfaxes.html
echo "<h1>Public Faxes By Category</h1>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<hr>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<a href=http://localhost:21169/psc-scripts/psc_faxmenu_show.sh><img src=file:/PitStop/packages/gifs/returnw.gif></a>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<a href=file:/PitStop/pitstop.html><img src=file:/PitStop/packages/gifs/pitbox.gif></a>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<hr>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<form method=post action=http://localhost:21169/psc-scripts/psc_faxmenu_get.sh>">> $HTMLDIR/pitstop.allfaxes.html
echo "<p><em>This page last updated on</em>" >> $HTMLDIR/pitstop.allfaxes.html
echo ".<input type=submit value=\"Request latest update\">" >> $HTMLDIR/pitstop.allfaxes.html
echo "</form>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<h2>Contents</h2>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<h3>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<ul>" >> $HTMLDIR/pitstop.allfaxes.html
cat contents$$ >> $HTMLDIR/pitstop.allfaxes.html
echo "</ul>" >> $HTMLDIR/pitstop.allfaxes.html
echo "<hr>" >> $HTMLDIR/pitstop.allfaxes.html
cat final.dt.$$ >> $HTMLDIR/pitstop.allfaxes.html
echo "<hr>" >> $HTMLDIR/pitstop.allfaxes.html
echo "</html>" >> $HTMLDIR/pitstop.allfaxes.html

###############

rm -f *$$
