# System Accounting Menu
#
# Created:	 13-Oct-87
# Modified Date: 07-Nov-87
#
# Created By:	 Sandy Marshall
# Modified By:	 Sandy Marshall

# Edit DEFAULT as needed:
DEFAULT="q"

# Edit TITLE as needed:
TITLE="			  System Accounting Menu"

if [ "`echo -n`" = "-n" ]
then
	NLF1=""
	NLF2="\c"
else
	NLF1="-n"
	NLF2=""
fi

while true
do

t=`pwd`
s=`date '+%a %h %d, 19%y'`
clear=`tput clear`

echo $clear

# SHOW ==================================================

cat << TBLOCK
$TITLE

TBLOCK
echo "Present Directory: $t		Date: $s \n"
cat << SHOWEND
			a. UNIX Daily Report
			b. UNIX Monthly Report

			q. Return to previous menu		? Help

SHOWEND
#
# Add additional lines before 'SHOWEND' and
# add corresponding entries in 'SELECT' below:
# <tab><letter(s)><tab><description"	# format for additional lines
#
# Use blank lines for visual grouping.
#

# ENTER ==================================================

echo $NLF1 "

			       Select [$DEFAULT] :  $NLF2"
read SELECT

if [ -z "$SELECT" ]
then
	SELECT=$DEFAULT
fi

DEFAULT=$SELECT
RT="0"

echo $clear

# SELECT ==================================================

case $SELECT in
	a)	echo "			UNIX Daily Report\n\n"
		echo "			Printers Available\n"
		lpstat -t
		echo "\nEnter printer name report is to be printed on"
		echo "(default is system default printer): \c"
		read PTR
		echo "\nEnter date, mmdd, (default is previous day): \c"
		read DATE
		if [ -n "$DATE" ]
		then	if [ -n "$PTR" ]
			then	/usr/lib/acct/prdaily $DATE | lp -d$PTR
				EXERR=$?
			else	/usr/lib/acct/prdaily $DATE | lp
				EXERR=$?
			fi
		else	if [ -n "$PTR" ]
			then	/usr/lib/acct/prdaily | lp -d$PTR
				EXERR=$?
			else	/usr/lib/acct/prdaily | lp
				EXERR=$?
			fi
		fi						;;

	b)	echo "			UNIX Monthly Report\n\n"
		echo "			Printers Available\n"
		lpstat -t
		echo "\nEnter printer name report is to be printed on"
		echo "(default is system default printer): \c"
		read PTR
		echo "\nEnter month (default is previous month): \c"
		read DATE
		if [ -z "$DATE" ]
		then	DATE=`date '+%m'`
		fi
		if [ -n "$PTR" ]
		then	lp -d$PTR /usr/adm/acct/fiscal/fiscrpt$DATE
			EXERR=$?
		else	lp /usr/adm/acct/fiscal/fiscrpt$DATE
			EXERR=$?
		fi						;;

	\?)	sh /usr/bin/sysacct.help
		EXERR=0
		RT=1						;;
	
	q)	exit $EXERR					;;


esac

if [ "$EXERR" != "0" ]
then
	echo $NLF1 " Exit error: $EXERR	$NLF2	"
	echo $NLF1 "  Press <RETURN> to continue:  $NLF2"
	read OK
else
	if [ "$RT" = "1" ]
	then
		echo $NLF1 " \n Press <RETURN> to continue:  $NLF2"
		read OK
	fi
fi

done
