# Printer Control Menu
#
# Created:	 05-Sep-87
# Revision Date: 09-Nov-87
#
# Created By:	 Sandy Marshall
# Modified By:	 Sandy Marshall

# Edit DEFAULT as needed:
DEFAULT="q"

# Edit TITLE as needed:
TITLE="			  Printer Control 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
$TITL2

TBLOCK
echo "Present Directory: $t		Date: $s \n"
cat << SHOWEND
			a. Print a File
			b. Display Printer Status
			c. Cancel a Print Job
			d. Change Directory

			q. Return to Main 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 "			Printers Available\n"
		lpstat -t
		echo "\n\nPrint file to this printer (RETURN for default): \c"
		read PTR
		echo "\nName of file to be printed, enter full pathname"
		echo "if not in this directory: \c"
		read FNAME
		if [ -n "$FNAME" ]
		then	if [ -f "$FNAME" ]
			then	if [ -n "$PTR" ]
				then	lp -d$PTR $FNAME
					EXERR=$?
				else	lp $FNAME
					EXERR=$?
				fi
			else	echo "\nFile $FNAME does not exist"
				EXERR=0
				RT=1
			fi
		else	EXERR=0
		fi							;;

	b)	echo "			Current Printer Status\n"
		lpstat -t
		EXERR=0
		RT=1							;;

	c)	echo "			Current Print Jobs\n"
		lpstat
		echo "\n\nEnter the \"Request ID\" to be cancelled: \c"
		read ID
		if [ -n "$ID" ]
		then	cancel $ID
			EXERR=$?
		else	EXERR=0
		fi							;;

	d)	echo "Current Directory: \c"
		pwd
		echo "Enter new directory name: \c"
		read x
		if [ -n "$x" ]
		then	if [ -d "$x" ]
			then	cd $x
				EXERR=$?
			else	echo "\nDirectory $x does not exist"
				EXERR=0
				RT=1
			fi
		else	EXERR=0
		fi							;;

	\?)	sh /usr/bin/ptr.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
