/* TITLE: avm:rexx/processmailbox.avm */
/* This is called as a command with mailbox */

/* we want results! Otherwise, we wouldn't get anything from RESULT */
options results

/* Need to make sure that stdtail.avm is also included */
signal on halt
signal on novalue
signal on syntax
signal on break_c

/* needed for some of the functions we use */
call addlib("rexxsupport.library", 0, -30, 0)

/* a higher than normal priority since calls are important to us :) */
call pragma('priority', 1)


parse arg mailbox .
call loadMailBox(mailbox)
calledSysop = 0
pagedSysop = 0

if mailbox.autoalertb = 1 & mailbox.autoalertscript ~= '' then
  address rexx 'alertsysop' mailbox

'playvoice' voiceFile(mailbox,'Personal')
a_=rc
if 0 then nop
else if a_=1 then signal aakeypressed
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort

aaAnnounce:
if mailbox.autoforwardannounce = 1 & mailbox.autoforward ~= '' then call announceForwardNumber

aanopersonal:
'playvoice' 'avm:voices/MailboxGreeting'
a_=rc
if 0 then nop
else if a_=1 then signal aakeypressed
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror

/* Init log file stuff */

aaskipinstructions:
handle = makeUniqueFile()
call initLogEntry()
call time('r')

userBeep = getclip('AVMUserBeep')
if userBeep = 'YES' then do

'playvoice' 'avm:voices/UserBeep'
a_=rc
if 0 then nop
else if a_=1 then signal aakeypressed
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror

end; else do

'playbeep' '1500' '0' '40'
call stdPlayXX(rc)

end

'recordvoice' '0' '-1' '-1' voiceFile(mailbox,handle)
a_=rc
if 0 then nop
else if a_=1 then do;call aafixlog; signal aakeypressedafterrecord;end
else if a_=2 then do;call aafixlog; signal stdabort;end
else if a_=3 then do;call aafixlog; if upper(getclip('AVMDataAfterSilence')) = 'YES' then signal stddata; else signal stdabort;end
else if a_=4 then do;call aafixlog; signal stdfax;end
else if a_=5 then do;call aafixlog; signal stddata;end
else if a_=8 then do;call aafixlog; signal stdbusy;end
else if a_=10 then do;call aafixlog; signal aakeypressedafterrecord;end
else if a_=12 then do;call aafixlog; signal stdabort;end
else if a_=14 then do;call aafixlog; signal stderror;end
else if a_=16 then do;call aafixlog; signal stderror;end

/* Shouldn't get here */
signal stderror

aafixlog:
/* This writes out the log file */

if mailbox.autoforwardb = 1 & mailbox.autoforwardondemand = "" & calledSysop = 0 then do
  call aaCallSysop
end
if mailbox.autopageb = 1 & mailbox.autopageondemand = "" & pagedSysop = 0 then do
  call aaPageSysop
end

log.filename = handle
log.length = trunc(time('e'))
log.type = 'voice'; log.origMailbox = mailbox
call saveLogEntry(mailbox, handle)
preConv = upper(getclip('AVMPreConvert')); preConvShow = upper(getclip('AVMShowPreConvertGUI'))
if preConv = 'YES' then
  if preConvShow = 'YES' then address command 'run >nil: <nil: avm:voice2iff' ,
    voiceFile(mailbox, handle) voiceFile(mailbox, handle) || 'i' '-preconvert'
  else address command 'run >nil: <nil: avm:voice2iff',
    voiceFile(mailbox, handle) voiceFile(mailbox, handle) || 'i' '-preconvert -nogui'
return

aakeypressedafterrecord:
'flushphonebuffer'

processmailboxmenu:
call aapresentmenu('avm:voices/MailboxCaller', '012345679#*', '3')
a_=result
if 0 then nop
else if a_='=0' then signal processmailboxmenu
else if a_='=1' then signal aaAnnounce
else if a_='=2' then signal stdfaxinstruct
else if a_='=3' then do;call aaleavenumber();end
else if a_='=4' then do;good = getpassword(mailbox.autoalertondemand); if good then address rexx 'alertsysop' mailbox;end
else if a_='=5' then signal stddatainstruct
else if a_='=6' then do;good = getpassword(mailbox.autoforwardondemand); if good & calledSysop = 0 then call aaCallSysop();end
else if a_='=7' then do;good = getpassword(mailbox.autopageondemand); if good & pagedSysop = 0 then call aaPageSysop();end
else if a_='=9' then do;call 'avmrexxalt:maintenancemode'(mailbox);if symbol('RESULT')~='VAR' then exit;end
else if a_='=#' then do;return 1;end
else if a_='=*' then signal answervoiceDone
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=10 then signal answervoiceDone
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror
signal processmailboxmenu

/* Shouldn't get here */
signal stderror

aaleavenumber:
number = getNumber()

log.returnnumber = number
call updateLogEntry(mailbox, handle)
return

aakeypressed:
call aapresentmenu('avm:voices/SkipFaxMaintenance', '012359#*', '3')
a_=result
if 0 then nop
else if a_='=0' then signal aakeypressed
else if a_='=1' then signal aaskipinstructions
else if a_='=2' then signal stdfaxinstruct
else if a_='=3' then signal aaAnnounce
else if a_='=5' then signal stddatainstruct
else if a_='=9' then do;call 'avmrexxalt:maintenancemode'(mailbox);if symbol('RESULT')~='VAR' then exit;end
else if a_='=#' then do;return 1;end
else if a_='=*' then signal stdabort
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=10 then signal answervoiceDone
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror
return

aaCallSysop:
procedure expose mailbox. mailbox calledSysop
if mailbox.autoforwardscript ~= "" & mailbox.autoforward ~= "" then do
     calledSysop = 1
     handle = makeUniqueFile()
     call initLogEntry(); log.origmailbox = mailbox
     log.filename = 'avm:voices/autoforward'; log.type = 'voice'
     log.returnsendfunc = mailbox.autoforwardscript; log.returninterval = 5
     log.returnretry = 3; log.returnnumber = mailbox.autoforward; log.altFileName = voiceFile(mailbox, 'Introduction')
     call saveLogEntry('Outgoing', handle)

'playvoice' 'avm:voices/BeingForwarded'
call stdPlayXX(rc)

    call playNumber(mailbox.autoforward)

'flushphonebuffer'

end
return

announceForwardNumber:
'playvoice' 'avm:voices/AnnounceForward'
call stdPlayXX(rc)

call playNumber(mailbox.autoforward)

'playvoice' 'avm:voices/AnnounceAgain'
call stdPlayXX(rc)
return

aaPageSysop:
procedure expose mailbox. mailbox pagedSysop
if mailbox.autopagescript ~= "" & mailbox.autopage ~= "" then do
     pagedSysop = 1
     handle = makeUniqueFile()
     call initLogEntry(); log.origmailbox = mailbox
     log.filename = 'avm:voices/autoforward'; log.type = 'voice'
     log.returnsendfunc = mailbox.autopagescript; log.returninterval = 5
     log.returnretry = 3; log.returnnumber = mailbox.autopage; log.altFileName = voiceFile(mailbox, 'Introduction')
     call saveLogEntry('Outgoing', handle)
end
return

answerVoiceDone:
'playvoice' 'avm:voices/Goodbye'
call stdPlayXX(rc)
exit

/* TITLE: avm:rexx/simplestdtail.avm */
/* This is the standard tail */
exit

exit

mailboxDir: procedure
	parse arg mailbox

	return 'avmmbox:' || mailbox || '/'

logFile: procedure
	parse arg mailbox, magiccookie

	return 'avmmbox:' || mailbox || '/logs/' || magiccookie

voiceFile: procedure
	parse arg mailbox, magiccookie

        if (verify(magiccookie, '/:', 'M') = 0) then
          return 'avmmbox:' || mailbox || '/voices/' || magiccookie
        else
          return magiccookie

makeUniqueFile: procedure
	if arg() ~= 0 then do
		rc = "makeUniqueFile: bad args"
		signal error
	end
	return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))

convertToDate: procedure
	if arg() ~= 1 then do
		rc = "convertToDate: bad args"
		signal error
	end
	parse arg timeInC

	actualTime = (timeInC - (2922)*86400) // (86400)
	actualDate = (timeInC - actualTime - 2922*86400) % 86400

	return actualDate /* returning it in 'internal' format */

convertToTime: procedure
	if arg() ~= 1 then do
		rc = "convertToTime: bad args"
		signal error
	end
	parse arg timeInC
	
	actualTime = (timeInC - (2922)*86400) // (86400)

	return actualTime

cTime: procedure
	/* 2922 = 8*365 + 2 */
	/* 86400 = 24*60*60 */
	return (date('i')+2922)*86400 + time('s')

/* this returns a handle that you must use after initializing log. */
initLogEntry: procedure expose log.
	if arg() ~= 0 then do
		rc = "initLogEntry: bad args"
		signal error
	end
	
	drop log.
        log. = ''

        acidname = getclip(address() || 'CIDNAME')
        acidnumber = getclip(address() || 'CIDNUMBER')

	/* 2922 = 8*365 + 2 */
	/* 86400 = 24*60*60 */
	log.time = (date('i')+2922)*86400 + time('s')
	log.cidname = acidname
	log.cidnumber = acidnumber

	return

loadLogEntry: procedure expose log.
	if arg() ~= 2 then do
		rc = "loadLogEntry: bad args"
		signal error
	end
	parse arg mailbox, handle

        drop log.
        log. = ''

	if ~exists(mailboxDir(mailbox)) then do
		call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
		return
	end

	opened = open(handle, logFile(mailbox, handle), 'r')
        if opened then do
		call showDebugger('Loading entry' logFile(mailbox, handle))
		do while ~eof(handle)
			line = readln(handle)
			parse upper var line variable '=' value
			log.variable = value
		end
		call close(handle)
	end; else call showDebugger('Could not load' logFile(mailbox, handle))
	return

/* pass a handle here */
saveLogEntry: procedure expose log.
	if arg() ~= 2 then do
		rc = "saveLogEntry: bad args"
		signal error
	end
	parse arg mailbox, handle

	if ~exists(mailboxDir(mailbox)) then do
		call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
		return
	end

	opened = open(handle, logFile(mailbox, handle), 'w')

	if opened then do
		call showDebugger('Saving entry' logFile(mailbox, handle))
		call writeln(handle, 'TYPE=' || log.type)
		call writeln(handle, 'TIME=' || log.time)
		call writeln(handle, 'LENGTH=' || log.length)

		call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)

		call writeln(handle, 'CIDNAME=' || log.cidname)
		call writeln(handle, 'CIDNUMBER=' || log.cidnumber)

		call writeln(handle, 'COMMENT=' || log.comment)

		call writeln(handle, 'FILENAME=' || log.filename)
		call writeln(handle, 'ALTFILENAME=' || log.altfilename)

		call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
		call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
		call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)

		call writeln(handle, 'RETURNRETRY=' || log.returnretry)
		call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)

		call close(handle)
		address rexx 'broadcast' 'addtomailbox' mailbox handle
	end; else call showDebugger('Could not save' logFile(mailbox, handle))

	return

/* pass a handle here */
updateLogEntry: procedure expose log.
	if arg() ~= 2 then do
		rc = "updateLogEntry: bad args"
		signal error
	end
	parse arg mailbox, handle

	if ~exists(mailboxDir(mailbox)) then do
		call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
		return
	end

	if ~exists(logFile(mailbox, handle)) then do
		call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
		return
	end
	opened = open(handle, logFile(mailbox, handle), 'w')

	if opened then do
		call showDebugger('Updating entry' logFile(mailbox, handle))
		call writeln(handle, 'TYPE=' || log.type)
		call writeln(handle, 'TIME=' || log.time)
		call writeln(handle, 'LENGTH=' || log.length)

		call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)

		call writeln(handle, 'CIDNAME=' || log.cidname)
		call writeln(handle, 'CIDNUMBER=' || log.cidnumber)

		call writeln(handle, 'COMMENT=' || log.comment)

		call writeln(handle, 'FILENAME=' || log.filename)
		call writeln(handle, 'ALTFILENAME=' || log.altfilename)

		call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
		call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
		call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)

		call writeln(handle, 'RETURNRETRY=' || log.returnretry)
		call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)

		call close(handle)
		address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
	end; else call showDebugger('Could not update' logFile(mailbox, handle))

	return



showDebugger: procedure
	if arg() ~= 1 then do
		say "showDebugger: ERROR"
		exit 20
	end

	parse arg debuggerInfo
	
	firstLine = sourceline(1)
	parse var firstLine '/*' 'TITLE:' title '*/'
	if showlist('p', 'AVMUSERINTERFACE') then
		address 'AVMUSERINTERFACE' 'addlog' title ':' debuggerInfo
	else
		say title ':' debuggerInfo

	return 

/*-----------------------------------------------------------------------*/
/*                         signal processing                             */

arexxerror:
error:
	call showDebugger("Error" rc "at line" sigl)
	exit 20

break_c:
halt:
	call showDebugger("Halt/Break_C at line" sigl)
	exit 20

novalue:
	call showDebugger("No value at line" sigl)
	exit 20

syntax:
	call showDebugger("Syntax error" rc "at line" sigl)
	exit 20

/* TITLE: avm:rexx/stdplayvoice.avm */
stdPlayXX:
procedure
parse arg ret

rs.normal = 0
rs.keydetected = 1
rs.quietdetected = 2
rs.silencedetected = 3
rs.faxdetected = 4
rs.datadetected = 5
rs.busydetected = 8
rs.timedout = 10
rs.signaldetected = 12
rs.overflow = 14
rs.error = 16
/* CB 0000 */

select
  when ret=rs.faxdetected then signal stdfax
  when ret=rs.datadetected then signal stddata
  when ret=rs.busydetected then signal stdbusy
  when ret=rs.signaldetected then signal stdabort
  when ret=rs.overflow then signal stderror
  when ret=rs.error then signal stderror
  otherwise nop
end
return


aapresentmenu:
/* TITLE: avm:rexx/presentmenu.avm */
procedure expose pmRetries pmTimesAround
parse arg filename, valid, retries
timesaround = retries
pmTimesAround = timesaround
pmRetries = retries

rs.normal = 0
rs.keydetected = 1
rs.quietdetected = 2
rs.silencedetected = 3
rs.faxdetected = 4
rs.datadetected = 5
rs.busydetected = 8
rs.timedout = 10
rs.signaldetected = 12
rs.overflow = 14
rs.error = 16
/* CB 0000 */

aapresentmenuloop:
'playvoice' filename
a_=rc
if 0 then nop
else if a_=4 then do;return rs.faxdetected;end
else if a_=5 then do;return rs.datadetected;end
else if a_=8 then do;return rs.busydetected;end
else if a_=12 then do;return rs.signaldetected;end
else if a_=14 then do;return rs.error;end
else if a_=16 then do;return rs.error;end

'readnkeys' '1' '5'
a_=rc
if a_=0 then value=result
if 0 then nop
else if a_=0 then signal aapresentmenuvalue
else if a_=4 then do;return rs.faxdetected;end
else if a_=5 then do;return rs.datadetected;end
else if a_=8 then do;return rs.busydetected;end
else if a_=10 then signal aapresentmenutimeout
else if a_=12 then do;return rs.signaldetected;end
else if a_=14 then do;return rs.error;end
else if a_=16 then do;return rs.error;end
return rs.error

aapresentmenutimeout:
'flushphonebuffer'

'playvoice' 'avm:voices/TimedOut'
a_=rc
if 0 then nop
else if a_=4 then do;return rs.faxdetected;end
else if a_=5 then do;return rs.datadetected;end
else if a_=8 then do;return rs.busydetected;end
else if a_=12 then do;return rs.signaldetected;end
else if a_=14 then do;return rs.error;end
else if a_=16 then do;return rs.error;end

timesaround = timesaround - 1; pmTimesAround = timesaround
if timesaround <= 0 then return rs.timedout
signal aapresentmenuloop

aapresentmenuvalue:
if pos(value, valid) = 0 then signal aainvalid
return '=' || value

aainvalid:
'flushphonebuffer'

'playvoice' 'avm:voices/BadChoice'
a_=rc
if 0 then nop
else if a_=4 then do;return rs.faxdetected;end
else if a_=5 then do;return rs.datadetected;end
else if a_=8 then do;return rs.busydetected;end
else if a_=12 then do;return rs.signaldetected;end
else if a_=14 then do;return rs.error;end
else if a_=16 then do;return rs.error;end

timesaround = timesaround - 1; pmTimesAround = timesaround
if timesaround <= 0 then return rs.timedout
signal aapresentmenuloop


stdabort:
exit

stdbusy:
exit

stderror:
exit

stdtimedout:
exit

stdfaxinstruct:
'playvoice' 'avm:voices/FaxStarting'
a_=rc
if 0 then nop
else if a_=1 then do;call checkifabort;end
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort

stdfax:
faxscript = getclip(address() || 'FAXSCRIPT')
if faxscript = '' then faxscript = 'handlefax'
if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
else address rexx faxscript address() 'anonymous'
exit

stddatainstruct:
'playvoice' 'avm:voices/DataStarting'
a_=rc
if 0 then nop
else if a_=1 then do;call checkifabort;end
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort

stddata:
datascript = getclip(address() || 'DATASCRIPT')
if datascript = '' then datascript = 'handledata'
if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
else address rexx datascript address()
exit

checkifabort:
'readnkeys' '1' '3'
a_=rc
if a_=0 then value=result
if 0 then nop
else if a_=0 then do;if value = '*' then signal stdabort;end
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror
return


exit

/* this requires logfunctions.avm */

loadMailbox: procedure expose mailbox.
	if arg() ~= 1 then do
		rc = "loadMailbox: bad args"
		signal error
	end

        mailbox. = ''
	parse arg mailbox

	handle = 'mailboxconfig'
	opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
	if opened then do
		do while ~eof(handle)
			line = readln(handle)
			parse upper var line variable '=' value
			mailbox.variable = value
		end
		call close(handle)
	end
	return

/* pass a handle here */
saveMailbox: procedure expose mailbox.
	if arg() ~= 1 then do
		rc = "saveMailbox: bad args"
		signal error
	end
	parse arg mailbox

	handle = 'mailboxconfig'
	opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')

	if opened then do
		call writeln(handle, 'PASSWORD=' || mailbox.password)

		call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
		call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
		call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)

		call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
		call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
		call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
		call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)

		call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
		call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
		call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
		call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)

		call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
		call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
		call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)

		call close(handle)
	end

	return

/* TITLE: avm:rexx/playnumber.avm */
playnumber:
/* Cycle through value and play each symbol */

procedure
parse arg number

do i = 1 to length(number)
  if pos(substr(number, i, 1), '0123456789') > 0 then
    call playAVoice('avm:voices/number0'||substr(number, i, 1))
  else if substr(number, i, 1) = '#' then
    call playAVoice('avm:voices/numberpound')
  else if substr(number, i, 1) = '*' then
    call playAVoice('avm:voices/numberstar')
end
return

playAVoice:
procedure
parse arg filename

'playvoice' filename
call stdPlayXX(rc)
return


/* TITLE: avm:rexx/getnumber.avm */
getnumber:
procedure

aagetnumberagain:
'playvoice' 'avm:voices/GetNumber'
call stdPlayXX(rc)

'readkeysuntil' '#' '15' '7'
a_=rc
if a_=0 then value=result
if 0 then nop
else if a_=0 then do;number = value;end
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=10 then do;number = '';end
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror

'playvoice' 'avm:voices/NumberEntered'
call stdPlayXX(rc)

call playNumber(number)

aagetnumbermenu:
call aapresentmenu('avm:voices/numbercorrect', '02#*', '3')
a_=result
if 0 then nop
else if a_='=0' then signal aagetnumbermenu
else if a_='=2' then signal aagetnumberagain
else if a_='=#' then signal aagetnumberdone
else if a_='=*' then signal answerVoiceDone
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=10 then do;number = ''; signal aagetnumberdone;end
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror

aagetnumberdone:
/* We're done.  Number is in 'number' */

return number


/* TITLE: avm:rexx/getpassword.avm */
/* This is a procedure which accepts 1 argument, a password */

getpassword:
procedure
parse arg password
count = 3 /* max of 3 times */
if password = '' then return 1

getpasswordagain:
count = count - 1
if count = 0 then return 0 /* didn't get a good password */

'playvoice' 'avm:voices/getpassword'
call stdPlayXX(rc)

'readkeysuntil' '#' '10' '7'
a_=rc
if a_=0 then value=result
if 0 then nop
else if a_=0 then signal getpasskeydetected
else if a_=4 then signal stdfax
else if a_=5 then signal stddata
else if a_=8 then signal stdbusy
else if a_=12 then signal stdabort
else if a_=14 then signal stderror
else if a_=16 then signal stderror

'playvoice' 'avm:voices/passwordtimeout'
call stdPlayXX(rc)
signal getpasswordagain

getpasskeydetected:
if value = password then return 1

'playvoice' 'avm:voices/passwordbad'
call stdPlayXX(rc)
signal getpasswordagain


