#!/bin/csh -f
# dir.tmp - source script for the ../htmlbin/dir script
# dir     - created from dir.tmp by Makefile
# purpose - to display the dictionary-type directory structure
#           for the jgofs data management system based on the data
#           contained in the dictionary files, .remoteobjects
#
#    9/30/94, clh -- narration added 
#   10/12/94, clh -- output log file entry if .log present 
#    1/04/95, clh -- modified to accept a command line parameter replacing
#        if ( "$QUERY_STRING" == "" ) setenv QUERY_STRING objectdir/ 
#        with an if block based on $1
#    1/05/95, clh -- changed log file to be handled like .remoteobjects, but
#        want event log to stand out, so need a separate section
#
# set currentdir = the subdir that is requested - may be empty if at top level
# if we are at the top level, don't show that link
# if we are at first level down, add a link to get to top
# to list the objects of a directory, send name of this subdir (if any),
#      send .remoteobjects to readdct2 which creates the 'obj, pi, descript' 
#      type of directory listing
#
# Customizing this script:  the makefile in htmlsrc will use the values from
#  build to customize (lower)JGOFSDIR and (lower)OBJECTDIR and (lower)MYADDR, 
#  and $OFFICE from dmoname.  
#  However, the value of $HELPFILE must be set manually.
#
########################
set OFFICE="dmoname"
setenv HELPFILE "http://www1.whoi.edu/dir-help.html"
########################

echo "Content-type: text/html"
echo ""

if ( "$1" == "" ) then 
   setenv QUERY_STRING objectdir/
else
   setenv QUERY_STRING $1
endif

set topdir=jgofsdir/objects
set currentdir=$QUERY_STRING
#set currentdir=$currentdir:h
set subdir=$currentdir:t

cd $topdir$QUERY_STRING
if ( "$currentdir" == "objectdir/" ) then
   if ( -f dirhead ) then
     cat dirhead
   endif
   if ( -f direxplain ) then
     cat direxplain
   endif
endif
#
# Below are 2 links (standard): Help, linked to an HTML document providing
#    help in navigating and Home, pointed to the current machine's HTTP
#    daemon top level.  If your home page is different from 
#    http://your.machine.domain/, change the link below.
#
echo "<h2>| <a href="\""$HELPFILE"\"">Help</a> |\
<a href="\""http://myaddr/"\"">Home Page</a> |</h2>"

echo "<pre>"

if ( -f .log || -e .remoteobjects ) then
  echo ""
  echo "<h2>Data in directory $QUERY_STRING</h2>"
  if ( -f .log) then
    jgofsdir/htmlbinx/readdct $QUERY_STRING < .log  
    echo ""
  endif
  echo ""

  if ( -e .remoteobjects) then
    echo "<em>Data           Investigator    Description</em>"
    echo "<hr>"
   jgofsdir/htmlbinx/readdct $QUERY_STRING < .remoteobjects
  endif
endif

echo "<hr>"
echo "<h2>$OFFICE Data Categories</h2>"
echo "Go to the indicated category of data by clicking on its name"

if ( "$currentdir" == "objectdir/" ) then
 find ${topdir}objectdir/ -type d -print | grep objectsobjectdir | sort | NAWK '\
$1 != "." {  n=split($1,arr,"/");\
  for(i=1;i<n;i++)printf "   "\
  printf "<a href=\"http:/jg/dir?%s/\">%s</a>\n",substr($1,dirlength+1,length($1)-2),arr[n]}\
'
else
 find ${topdir}/ -type d -print | grep objectsobjectdir | sort | NAWK '\
$1 != "." {  n=split($1,arr,"/");\
  for(i=1;i<n;i++)printf "   "\
  printf "<a href=\"http:/jg/dir?%s/\">%s</a>\n",substr($1,dirlength+1,length($1)-2),arr[n]}\
'
endif
echo "</pre>"
