#ident	"@(#)nlp.admin:menu/packagemgmt/lpmgmt/printers/disable_p	1.5"
## IDOC:   SCREEN 2.31: DISABLE PRINTER
#menu# Disable printer from printing

##+++ (help _H78)
#help#        You use the "disable" command to keep  print  requests  from
#help#        printing  on  a  printer.  This does not discard or move any
#help#        requests currently in the queue, nor does it refuse  further
#help#        requests.   All  requests  will  remain  in  queue until the
#help#        printer is enabled again.
#help#
#help#        Use the "reject" command in the "printers"  menu  to  reject
#help#        further requests for a printer.
##--- (help _H78)

##+++ (general)
echo "
Whenever you want to quit, type \"q\".
If you are not sure how to answer any prompt, type \"?\" for help,
or see the System Administrator's Guide.

If a default appears in the question, press the return key to use it.
"
##--- (general)

trap 'exit 0' 1 2 15
flags="-qq -k$$"

##+++ (functions)
chk_printer_list () {
# listof: printer-name
    while true; do
	RESP=`checkre ${flags} -fe \
		-H "$3" \
		"$1${SyStSt:+!printer-list!}" \
		$4 \
		'.*' ''`
	RESP=`echo "${RESP}" | tr ',' ' '`
	if [ -z "${RESP}" ]; then : ${RESP:="$2"}; fi
	if [ -z "${RESP}" ]; then :; else if ( set -- ${RESP}
		while [ $# -gt 0 ]; do
			echo "$1" \
			| ( flags="-m1"; chk_name >/dev/null 2>&1 ) || exit 1
			shift
		done; exit 0
	); then return 0; fi
	fi
	echo '	You did not give a valid printer name.
	Separate multiple items with a comma or blank.'
    done
}
chk_name () {
	RESP=`checkre ${flags} -fe $4 \
		${2:+"-D$2"} -H "$3" \
		"$1${SyStSt:+!name!}" \
		'^[a-zA-Z0-9_]\{1,14\}$' \
			'A name can contain only 1 to 14 letters, digits, and underscores.' \
	`
}
chk_one_line_comment () {
	RESP=`checkre ${flags} -fe $4 \
		${2:+"-D$2"} -H "$3" \
		"$1${SyStSt:+!one-line-comment!}" \
		'.*' '' \
	`
}
##--- (functions)

DEF=`cat ${TMPDIR:-/tmp}/PRT.\`basename \\\`tty\\\`\` 2>/dev/null`
while true
do

##+++ (line 1)
echo \
"Enter the names of the printers that should stop printing requests.
Separate multiple names with a space or comma."
##--- (line 2)

##+++ (2.31.3)
chk_printer_list \
	"${DEF:+(default: ${DEF})}" \
	"${DEF}" \
	"\
        You are expected to enter the name of the printer  you  want
        to  disable.   If  you  don't  know  the name, enter \"q\" and
        select the \"status\" command from the \"printers\" menu, to get
        a list of known printers.  You can give several names if you
        separate them with spaces or commas.

        A  disabled  printer  is  prevented  from  printing  further
        requests  but  requests  can  continue  to  queue up for the
        printer.  You will be able to specify  whether  any  request
        currently  printing be stopped and put back in the queue, be
        canceled and discarded, or be  allowed  to  finish  printing
        before the printer is disabled.

        If you also want to stop further requests from being queued,
        when  you are done with the \"disable\" command go back to the
        \"printers\" menu and select the \"reject\" command.  This is  a
        good  idea  if the printer will be disabled for a long time.
        \
"
OPT=${RESP}
##--- (2.31.3)

DEF_c=no
##+++ (2.31.4)
if checkyn ${flags} -f \
	${DEF_c:+"-D${DEF_c}"} -H \
	"\
        Enter \"y\" (for yes) if any requests  currently  printing  on
        the printer(s) you identified should be CANCELED.  This will
        destroy those print requests.  Enter \"n\" (for  no)  if  they
        should be left in queue or allowed to finish printing.  \
" \
	"Cancel any requests currently printing?${DEF_c:+ (default: ${DEF_c})}"
then
	OPT="-c ${OPT}"
else

##--- (2.31.4)

DEF_W=no
##+++ (2.31.5)
if checkyn ${flags} -f \
	${DEF_W:+"-D${DEF_W}"} -H \
	"\
        Enter \"y\" (for yes) if any requests  currently  printing  on
        the  printer(s)  you  identified should be allowed to finish
        printing.  You will not have to wait,  since  the  LP  Print
        Service  will  mark  the printers as being disabled and will
        prevent any other request from  printing,  too.   Enter  \"n\"
        (for  no)  if they should be stopped but left in queue to be
        printed later.  When later printed, these requests  will  be
        restarted  from  the  BEGINNING,  unless someone changes the
        request and gives a subset of pages to print.   You  can  do
        this  by  selecting the \"change\" command from the \"requests\"
        menu later.  \
" \
	"Wait for any requests currently printing?${DEF_W:+ (default: ${DEF_W})}"
then
	OPT="-W ${OPT}"
else
	:
fi
##--- (2.31.5)
fi

##+++ (line 6)
echo \
"Reason for disabling:"
##--- (line 6)

DEF_r=none
##+++ (2.31.7)
chk_one_line_comment \
	"${DEF_r:+(default: ${DEF_r})}" \
	"${DEF_r}" \
	"\
        You are  expected  to  enter  a  reason  for  disabling  the
        printer(s).   The  only  purpose of the reason is to give an
        explanation to  the  users  who  inquire  about  a  disabled
        printer.   Just  press  return  if you don't care to explain
        what you're doing.  \
"
OPT_r=${RESP}
##--- (2.31.7)

	if [ "none" != "${OPT_r}" ]
	then
		disable -r "${OPT_r}" ${OPT} && break
	else
		disable ${OPT} && break
	fi
done
