Script started on Wed Jan  9 15:17:14 2002
ws13% cat ncal3.cgi

#!/bin/sh
# cgi wrapper for ncal2

nthElement()
{
    #
    # get nth element in list
    #

    shift $1
    echo $1
}


    echo "Content-type: text/plain"
    echo ""
    
    DATE=`date`
    MONTH=`nthElement 2 $DATE`
    YEAR=`nthElement 6 $DATE`
    if [ `./name2num $MONTH` -gt `./name2num $QUERY_STRING` ] ; then
        YEAR=`expr $YEAR + 1`
    fi

    ./ncal2 $QUERY_STRING $YEAR
ws13% ./ ncal3.cgi [Pnncal3.cgi april

Content-type: text/plain

Bad argument
ws13% cat year.html

<html>
<!--
  -- this is the start of a table   -->
<body bgcolor=white>
<h4>
A clickable calendar
<hr>
</h4>
<table border=1>
<!-- winter months in white -->
<tr>
        <td bgcolor=white align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Jan>Jan
        </td>
        <td bgcolor=white align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Feb>Feb
        </td>
        <td bgcolor=white align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Mar>Mar
        </td>
</tr>
<!-- spring months in green -->
<tr>
        <td bgcolor=green align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Apr>Apr
        </td>
        <td bgcolor=green align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?May>May
        </td>
        <td bgcolor=green align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Jun>Jun
        </td>
</tr>
<!-- summer months in yellow -->
<tr>
        <td bgcolor=yellow align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Jul>Jul
        </td>
        <td bgcolor=yellow align=center width=50 valign=center height=35>
    <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Aug>Aug
        </td>
        <td bgcolor=yellow align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Sep>Sep
        </td>
</tr>
<!-- fall months in orange -->
<tr>
        <td bgcolor=orange align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Oct>Oct
        </td>
        <td bgcolor=orange align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Nov>Nov
        </td>
        <td bgcolor=orange align=center width=50 valign=center height=35>
        <a href=http://www.people.fas.harvard.edu/~lowke/mwp/ncal3.cgi?Dec>Dec
        </td>
</tr>
</table>
ws13% cat mwp.cgi

#!/bin/sh
#  a web page called cities


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

    echo "<html>"
    echo "<!-- a web page called cities -->"
    echo "<head>"
        echo "    <title>cities</title>"
    echo "</head>"

    echo "<body bgcolor=white>"
    echo "<b>A Web Page for cities</b>"
    echo "<hr>"
    echo "Customized Links for cities"
    echo "<p>"
    echo "<center>"
    echo "<table border=1 cellpadding=5>"

    ./fl -d\| cities.fmt < data/$QUERY_STRING.tab
    
    echo "</table>"
ws13% l[Kcat add.edit[K[K[K[K[K[K[K[K[K[K[Kls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% cat add-edit_item.cgi

#!/bin/sh
#
# add_item.cgi
# this script is called from ewp.html for the Add function
# it takes the specified items and creates a new record on the
# end of the named file in the data directory
#

error()
{
        echo $*
    echo "Press the Back button now."
        exit 1
}


        eval `./qryparse`                                       # receive form data
        DATAFILE=$pagename.tab                          # $pagename set by qryparse

        echo "Content-type: text/plain"                 # tell browser type of output
        echo ""                                                     # end of header

    if [ "$pagename" = "" ] ; then                  # ensure pagename
       error "Your pagename is blank."
    fi
    
    if [ "$title" = "" ] ; then                     # ensure title
       error "Your item title is blank."
    fi

    
        if [ ! -d data ] ; then                         # if no data directory
                mkdir data                                          # try to make it
                if [ $? -ne 0 ] ; then                          # and check for errors
                        error "Cannot create data directory."
                fi
        fi

        cd data
    
    #prep newline
    NEWLINE="title=$title|tcolor=$titlecolor|desc=$descrip|url=$url"
    STDAPPND=YES
    
    if [ -e $DATAFILE ] ; then                      # check for datafile
        if grep $title $DATAFILE > /dev/null ; then # check for specific line
            sed "/$title/c\\
$NEWLINE" $DATAFILE > $DATAFILE.tmp
            STDAPPND=NO
            mv -f $DATAFILE.tmp $DATAFILE           # copy .tmp over .tab
        fi
    fi
    
    # use standard replace
    if [ "$STDAPPND" = "YES" ] ; then
        printf "title=%s|tcolor=%s|desc=%s|url=%s\n" \
                    "$title" "$titlecolor" "$descrip" "$url" >> $DATAFILE
    fi
            
        if [ $? -eq 0 ] ; then
                echo "Addition of $title was successful."
                echo "Press the Back button now."
        else
                echo "Unable to update file $DATAFILE ."
                echo "Please report to page admin."
        fi
ws13% ls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% cat delete_item.cgi

#!/bin/sh
#
# delete_item.cgi
# cgi program to delete title item
#

error()
{
        echo $*
    echo "Press the Back button now."
        exit 1
}


        eval `./qryparse`                                       # receive form data
        DATAFILE=$pagename.tab                          # $pagename set by qryparse

        echo "Content-type: text/plain"                 # tell browser type of output
        echo ""                                                     # end of header

    if [ "$pagename" = "" ] ; then                  # ensure pagename
       error "Your pagename is blank."
    fi
    
    if [ "$title" = "" ] ; then                     # ensure title
       error "Your item title is blank."
    fi

        if [ ! -d data ] ; then                         # if no data directory
                mkdir data                                          # try to make it
                if [ $? -ne 0 ] ; then                          # and check for errors
                        error "Cannot create data directory."
                fi
        fi

        cd data
        
    if [ -e $DATAFILE ] ; then                      # check for datafile
        if grep $title $DATAFILE > /dev/null ; then # check for specific line
            sed "/$title/d" $DATAFILE > $DATAFILE.tmp
            mv -f $DATAFILE.tmp $DATAFILE           # copy .tmp over .tab
        else
            error "Could not find title $title in file $DATAFILE"
        fi
    else
        error "Could not find pagename $pagename"
    fi
                
        if [ $? -eq 0 ] ; then
                echo "removal of $title from $DATAFILE was successful."
                echo "Press the Back button now."
        else
                echo "Unable to update file $DATAFILE ."
                echo "Please report to page admin."
        fi
ws13% ls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% cat view_page.cgi

#!/bin/sh
#
# view_page.cgi
# cgi program to display current state of page
# simply takes the page name from form and passes it to mwp.cgi
# as QUERY_STRING and as $1
#

error()
{
    printf "Content-type: text/plain\n\n"
        echo $*
    echo "Press the Back button now."
        exit 1
}

        eval `./qryparse`
        DATAFILE="data/$pagename.tab"              # $pagename path

    # echo "got here"
    if [ -z "$pagename" ] ; then             # ensure pagename
       error "Your pagename is blank."
    fi

    if [ -e $DATAFILE ] ; then                 # check for datafile

        QUERY_STRING=$pagename
        export QUERY_STRING

        ./mwp.cgi $pagename
    else
        error "Could not find pagename $pagename"

    fi
ws13% ls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% caty [K mwp.cgi

#!/bin/sh
#  a web page called cities


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

    echo "<html>"
    echo "<!-- a web page called cities -->"
    echo "<head>"
        echo "    <title>cities</title>"
    echo "</head>"

    echo "<body bgcolor=white>"
    echo "<b>A Web Page for cities</b>"
    echo "<hr>"
    echo "Customized Links for cities"
    echo "<p>"
    echo "<center>"
    echo "<table border=1 cellpadding=5>"

    ./fl -d\| cities.fmt < data/$QUERY_STRING.tab
    
    echo "</table>"
ws13% cat cities.fmt

<tr>
<td bgcolor=%tcolor%><a href="%url%">%title%</a></td>
<td>%desc%</td>
</tr>
ws13% cat cities.html

<html>
<!-- a web page called cities -->
<head>
        <title>cities</title>
</head>

<body bgcolor=white>
<b>A Web Page for cities</b>
<hr>
Customized Links for cities
<p>
<center>
<table border=1 cellpadding=5>
<tr>
  <td bgcolor=cream><a href="http://www.boston.com">Boston</a></td>
  <td>A nice coastal town in New England, lots of history</td>
</tr>

<tr>
  <td bgcolor=gold><a href="http://www.newyork.com">New York</a></td>
  <td>The largest city on the East Coast.  Lots to do and see</td>
</tr>

<tr>
  <td bgcolor=silver><a href="http://www.dallas.com">Dallas</a></td>
  <td>A sprawling, cheery Texas city.  Hot in the summer</td>
</tr>

<tr>
  <td bgcolor=yellow><a href="http://www.chicago.com">Chicago</a></td>
  <td>Said to be windy.  Cold in the winter, but the people are warm</td>
</tr>

<tr>
  <td bgcolor=linen><a href="http://www.kansascity.com">Kansas City</a></td>
  <td>Lewis and Clark set out from here.  Known for jazz and steaks</td>
</tr>

</table>
ws13% ls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% ewp.cgi[K[K[K[K[K[K[Kcat ewp.cgi

cat: cannot open ewp.cgi
ws13% cat ewp.cgi[K[K[Khtml

<html>
<head>
<title>My Web Page Designer</title>
</head>

<body bgcolor=white>
<center>
        <hr>
        <font color=blue size=+1>
        My Web Page<br> Page Creator/Editor Tool<br>
        </font>
        <hr>
</center>
<p>
Use this page to create and edit customized web pages.  You can add
items to pages, edit items on pages, and delete items on pages.  You
can also delete entire pages. 
<hr>

<!-- a def list allows for headers and indented blocks -->

<dl>
<dt><b>Add/Edit an Item</b></dt>
        <dd>
        <p>
        Use this function to add new items to your web page or
        edit existing items.  Include
        the name of the page and all the details about the item.
        When you are done, press the <b>update</b> button, and the
        new item will be added to the named web page.  If the
        page contains an item with the same title, that item
        will be replaced with the data you provide.
        <p>
        <form action='add-edit_item.cgi' method=get>
        <table border=0 cellpadding=2 cellspacing=0>
        <tr>
           <td align=right>Page name:</td>
           <td><input type=text name=pagename size=20></td>
        </tr>
        <tr>
           <td align=right>Item title:</td>
           <td><input type=text name=title size=20></td>
        </tr>
        <tr>
           <td align=right>Title color:</td>
           <td><input type=text name=titlecolor size=20></td>
        </tr>
        <tr>
           <td align=right>Description:</td>
           <td><input type=text name=descrip size=40></td>
        </tr>
        <tr>
           <td align=right>URL:</td>
           <td><input type=text name=url size=40></td>
        </tr>
        <tr>
           <td></td>
           <td><input type=submit value=' update '></td>
        </tr>
        </table>
        </form>
        </dd>
<dt>
<hr>
<b>Delete an Item</b></dt>
        <dd>
        <p>
        Use this function to delete an item from a page.
        Enter the name of the page and the title of the
        item.  Then press the <b>Delete</b> button.
        <p>
        <form action='delete_item.cgi' method=get>
        <table border=0 cellpadding=2 cellspacing=0>
        <tr>
           <td align=right>Page name:</td>
           <td><input type=text name=pagename size=20></td>
        </tr>
        <tr>
           <td align=right>Item title:</td>
           <td><input type=text name=title size=20></td>
        </tr>
           <td></td>
           <td><input type=submit value=' delete '></td>
        </tr>
        </table>
        </form>
        </dd>
<dt>
<hr>
<b>View a Page</b></dt>
        <dd>
        <p>
        Use this function to see what a page looks like.
        Enter the name of the page and press the <b>view</b>
        button.
        <p>
        <form action=view_page.cgi method=get>
        <table border=0 cellpadding=2 cellspacing=0>
        <tr>
           <td align=right>Page name:</td>
           <td><input type=text name=pagename size=20></td>
        </tr>
           <td></td>
           <td><input type=submit value=' view '></td>
        </tr>
        </table>
        </form>
        </dd>
</dl>
ws13% ls

add-edit.b         ewp.html           mwp.cgi            sample.dat
add-edit_item.cgi  fl                 name2num           sample.fmt
args1.cgi          fun.sed            ncal2              t2l
cities.fmt         l2t.sed            ncal2.cgi          typescript
cities.html        l2t.sh             ncal3.cgi          view_page.cgi
cities.lst         list_to_table.txt  ncal4.cgi          year.html
data               makefile           qryparse
delete_item.cgi    mwp.bk             qryparse.c
ws13% exit

exit

script done on Wed Jan  9 15:25:00 2002
