;Call Forward/Selective Call Forward Application
;By: Aaron Wickware (daw@xpance.net)
;Date: 07/28/05
;
;Desc: Call forward application allows CLASS type call forward features with Selective Call Forward capabilities. Users can enable and disable
;convention call forwarding and additionally specify up to five callers who will be the only callers forwarded (Selective call forwarding).
;This is based upon the callers 10 digit caller id number information. Given that, SCFE entries should be specified in the 10 digit caller
;id format to provide the best reliability. Any format other than 10 digit us CID nubmer format will be considered invalid.
;
;Commands are relative to the station they are issued from:
;
;*72 - Enable call forwarding and specify call forward number
;*73 - Disable call forwarding and clear any selective call forward entries
;*83 - Disable selective call forward and lear all selective call forward entries
;*63 - Set selective call forward entries (allowed up to 5)
;
;Incoming detection will largely depend on your incoming dial plan, but you should be able to use the following statements with minor changes
;
;If CALLERIDNUM/CFWD is Null (disabled) then continue to dial extension, if CALLERIDNUM/CFWD has a value then continue to check SCFE
;exten => 100,1,GotoIf($["${DB(${CALLERIDNUM}/CFWD)}" = ""]?100:2)
;
;If MAINCOUNT is set then check SCFE variables, if not the continue to dial extension
;exten => 100,2,GotoIf($["${DB(${CALLERIDNUM}/MAINCOUNT)}" = ""]?100:3)
;
;Check SCFE 1-5 against Callers caller ID num, if there is a match then continue to dial extension.
;exten => 100,3,GotoIf($["${DB($SCFE{CALLERIDNUM}/1)}" = "${CALLERIDNUM}"]?100:4)
;exten => 100,4,GotoIf($["${DB($SCFE{CALLERIDNUM}/2)}" = "${CALLERIDNUM}"]?100:5)
;exten => 100,5,GotoIf($["${DB($SCFE{CALLERIDNUM}/3)}" = "${CALLERIDNUM}"]?100:6)
;exten => 100,6,GotoIf($["${DB($SCFE{CALLERIDNUM}/4)}" = "${CALLERIDNUM}"]?100:7)
;exten => 100,7,GotoIf($["${DB($SCFE{CALLERIDNUM}/5)}" = "${CALLERIDNUM}"]?100:8)
;exten => 100,8,Voicemail(u100@context) ; If no SCFE entries match then goto voicemail
;
;Dial the extension
;exten => 100,100,Dial.......
;
;-----------------------------------------------------------------------------
; Call Forwarding Activation/Deactivation
;-----------------------------------------------------------------------------
;
[cfwd-act] ; Activate call forwarding and specify the CFWD number
exten => *72,1,Background(call-forward)
exten => *72,2,Set(TIMEOUT(response)=10)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup()
exten => _X.,1,Set(DB(${CALLERIDNUM}/CFWD)=${EXTEN})
exten => _X.,2,Playback(call-forward)
exten => _X.,3,Playback(activated)
exten => _X.,4,Hangup()
;
;
[cfwd-deact] ; Deactivate call forwarding and clear any existing selective call forward (SCFE) entries
exten => *73,1,DBdel(${CALLERIDNUM}/CFWD)
exten => *73,2,DBdel(${CALLERIDNUM}/MAINCOUNT)
exten => *73,3,DBdel(SCFE${CALLERIDNUM}/1)
exten => *73,4,DBdel(SCFE${CALLERIDNUM}/2)
exten => *73,5,DBdel(SCFE${CALLERIDNUM}/3)
exten => *73,6,DBdel(SCFE${CALLERIDNUM}/4)
exten => *73,7,DBdel(SCFE${CALLERIDNUM}/5)
exten => *73,8,Playback(call-forward)
exten => *73,9,Playback(de-activated)
exten => *73,10,Hangup()
;
;-----------------------------------------------------------------------------
; Selective Call Forward Activation/Entry and Deactivation/Clear
;-----------------------------------------------------------------------------
;
[enter-scfe] ; SCFE entry. Checks that cfwd is enabled and SCFE count and proceeds accordingly
exten => *63,1,GotoIf($["${DB(${CALLERIDNUM}/CFWD)}" = ""]?97:2) ; Check if CFWD is activated
exten => *63,2,GotoIf($["${DB(${CALLERIDNUM}/MAINCOUNT)}" = "0"]?100:3) ; If MAINCOUNT=0 all 5 SCFE are used
exten => *63,3,GotoIf($["${DB(${CALLERIDNUM}/MAINCOUNT)}" = ""]?101:4) ; If MAINCOUNT=NULL 5 SCFE entries are available
exten => *63,4,Goto(add-scfe,*63,2) ; Continue with current SCFE count
exten => *63,3,GotoIf($["${DB(${CALLERIDNUM}/MAINCOUNT)}" = ""]?101:4) ; If MAINCOUNT=NULL 5 SCFE entries are available
exten => *63,4,Goto(add-scfe,*63,2) ; Continue with current SCFE count
exten => *63,97,Playback(call-forward)
exten => *63,98,Playback(de-activated)
exten => *63,99,Hangup()
exten => *63,100,Goto(scfe-count,1,100)
exten => *63,101,Goto(add-scfe,*63,1)
;
;
[add-scfe]
exten => *63,1,Set(DB(${CALLERIDNUM}/MAINCOUNT)=123450) ;Set Total allowed SCFE's in the Database
exten => *63,2,Set(COUNT=${DB(${CALLERIDNUM}/MAINCOUNT)}) ;Set a channel variable to match
exten => *63,3,Background(scfe-add) ;Playback menu like "Please enter selective call forward number now."
exten => *63,4,Set(TIMEOUT(response)=10)
exten => t,1,Playback(vm-gooodbye)
exten => t,2,Hangup()
exten => i,1,Goto(add-scfe,*63,3)
exten => _NXXXXXXXXX,1,Set(DB(SCFE${CALLERIDNUM}/${COUNT:0:1})=${EXTEN}) ; Add unique SCFE to database
exten => _NXXXXXXXXX,2,Set(DB(${CALLERIDNUM}/MAINCOUNT)=${COUNT:1}) ; Increment (rather decrease) the SCFE total avail count
exten => _NXXXXXXXXX,3,Goto(scfe-count,s,1) ; Jump to the counter
;
;
[scfe-count] ; Determines the current count of SCFE numbers based on MAINCOUNT
exten => s,1,Background(scfe-another) ; Another menu prompt asking us if we want to add another number 1=Y 2=N
exten => s,2,Set(TIMEOUT(response)=10)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup()
exten => i,1,Goto(scfe-count,s,1)
exten => 1,1,GotoIf($["${DB(${CALLERIDNUM}/MAINCOUNT)}" = "0"]?100:2)
exten => 1,2,Goto(add-scfe,*63,2) ; If COUNT is not 0 jump back to add-scfe context at priority *63,2
exten => 2,1,Playback(vm-goodbye) ; If 2 (NO) is entered playback goodbye
exten => 2,2,Hangup()
exten => 1,100,Playback(scfe-count-exceeded) ; playback message indicating you have 5 scf numbers entered
exten => 1,101,Hangup() ; Hangup
;
;
[scfe-clear] ; Clear all SCFE database entries but does not change overall cfwd status
exten => *83,1,DBdel(${CALLERIDNUM}/MAINCOUNT)
exten => *83,2,DBdel(SCFE${CALLERIDNUM}/1)
exten => *83,3,DBdel(SCFE${CALLERIDNUM}/2)
exten => *83,4,DBdel(SCFE${CALLERIDNUM}/3)
exten => *83,5,DBdel(SCFE${CALLERIDNUM}/4)
exten => *83,6,DBdel(SCFE${CALLERIDNUM}/5)
exten => *83,7,Playback(call-forward)
exten => *83,8,Playback(de-activated)
exten => *83,9,Hangup()