CSuite Workshop Notes - September 18, 1996

Next September 25, 1996

Previous September 11, 1996

Return to CSuite Workshop Index

Agenda:


Opportunity NS

Plans were finalized on the presentation for the Opportunity NS Trade Show, and a roster was assigned to staff the booth.

Return to Topic List


Quota Project

Today we undertook an experiment, by running a longer than usual session. We undertook to design and implement a system to make expanded disk quota available to CSuite users.

As a project it will also demonstrate the methodology of implementing a new feature for CSuite.

1. Design phase

2. Script development:

A script to handle the office processing part of the function was developed as a group excercise.

location: /ccn/etc/cgi-officebin/
name: money

Please note: this version is incomplete as of September 24, 1996. Follow the above link to view the current version.

First, a new file called money was created in the appropriate cgi directory: /ccn/etc/cgi-officebin/ using the editor

The template file /t/cgi was read in to provide this header:

#! /bin/sh

# Copyright (C) 1995, 1996 Chebucto Community Net Society
# This file is part of Chebucto Suite.  Use is governed by the terms
# laid out in the file COPYRIGHT.

# template version 1.0

The line beginning with ## provides a content line for the source-browser - Edit it!


## money - process incoming monetary transactions

. $DOCUMENT_ROOT/.cgi-funclib

cs_html_head -t office Title

Edit this line for proper recipient for comments (in this case Office) and put in the title for the generated document.
cs_html_head -t office Transaction Processing

Trap sets what to do in case of exit from this script.
Note: this is an important security precaution.
On trap 0 we execute the routine cs_html_foot, which is included in the .cgi-funclib

trap cs_html_foot 0

exec 2... sends (>> appends) all error messages to the test.money file

exec 2>>$CS_LOG/test.`basename $0`
set -x

Use system path, rather than the default. We are using sh, not bash, so export and path are separate commands.
PATH=$SYSPATH ; export PATH

How many blank lines to display in form.
nlines=5 	# number of possible categories to break payment into

if [ "$cgi_TOTAL" = "" ]; then
# no input, so put up the form

We skipped by this and came back to it later when we needed to know more. Initially, our goal was just to get the framework up, then fill in the details.
	echo "
	<FORM METHOD=POST ACTION=http://$SERVER_NAME$SCRIPT_NAME>
	Total <INPUT TYPE=TEXT SIZE=8 NAME=TOTAL>
	Account Name <INPUT TYPE=TEXT SIZE=20 NAME=NAME> <p>
	"

	for line in `count $nlines`
	do
		echo "<INPUT TYPE=TEXT NAME=AMT$line SIZE=8>"
		echo "<SELECT NAME=TYPE$line>
		<OPTION>quota
		<OPTION>invoice
		<OPTION>ip
		<OPTION>membership
		<OPTION>donation
		<OPTION>other
		</SELECT> <BR>
		"


	done
	echo '
		<P>
		<INPUT TYPE=SUBMIT VALUE=Process>
		<INPUT TYPE=RESET VALUE=CLEAR>
		</FORM>'

At this point we have displayed the form. The user now enters data into the form and will eventually process it, as clicking the Process button will execute this script again. (Next time the arguments will not be empty, so the next part will be executed.) So for now we are finished, just go away and wait for the browser to call.

	exit 0

fi

# process each input line
echo Total: $cgi_TOTAL
echo Name: $cgi_NAME
for line in `count $nlines`

Use of eval here forces 2 evaluations: first pass, \$ becomes $, second pass we actually retrieve $cgi_AMT$line

do
	eval amt=\$cgi_AMT$line
	eval type=\$cgi_TYPE$line

Now we need some data to work with, so we had better go back and build the form.

	if [ "$amt" = "" ]; then
		continue
	fi	case "$type" in
	"quota")
		# check that they are member
		;;
	invoice) ;;
	ip) ;;
	membership) ;;
	donation) ;;
	other) ;;
	esac

	echo $amt

This tricky bit of code takes the output of the do loop and pipes it to gawk, where the "Checque amount" (cgi_TOTAL) is compared to the sum of the items, and if they should not be equal, executes the error statement. In an error one exits with non-zero status. (exit 1)


done | 
gawk -v total="$cgi_TOTAL" '
	{ sum += $1 }
	END { exit sum - total }' || {
echo "Individual amounts do not add up to Total; go back and make 
corrections."
exit 1
}

First pass we do some checking, and complain if problems are seen. Otherwise we proceed to do more processing:

for line in `count $nlines`
do
	eval amt=\$cgi_AMT$line
	eval type=\$cgi_TYPE$line

	if [ "$amt" = "" ]; then
		continue
	fi
	
	case "$type" in
	"quota")
		echo "
		<FORM METHOD=POST ACTION=http://$SERVER_NAME$SCRIPT_NAME>
		<P>
		<INPUT TYPE=SUBMIT VALUE=Process>
		<INPUT TYPE=RESET VALUE=CLEAR>
		</FORM>
		"
		;;
	invoice) ;;
	ip) ;;
	membership) ;;
	donation) ;;
	other) ;;
	esac

done
At this stage we have not implemented any processing for the other types of transactions, or output the required database records.

More to come in the September 25 meeting.

Return to Topic List


Next Workshop September 25, 1996

Previous Workshop September 11, 1996

Return to CSuite Workshop Index

Submitted by Ed Dyer aa146
Workshop Coordinator David J Murdoch djm


[Up] [Search] [Comments] [CCN Homepage]