Sorry, got distracted and then our admin building had a "soup"er bowl activity, lots of soup going into the weekend.
Here’s what I found. I haven’t tested it in a while like I said, I’m hoping we get a trunk going again for our FreePBX set up. I know Macro is deprecated coming up soon. I had about four variations of this I think. I first made it back when I was in the experimental first few months of FreePBX, so if I sat down and looked at it further, a better way could probably be found. But hopefully it helps as a stepping stone!
The logic I have here is that each of our schools has a location code. Really just used internally for mainly our student SIS to identify each school in the databases. I found it convenient to use for this purpose, but I add a 0 or 1 to the end. So School A’s location code might be 235 and I’ll add a 1 or 0 at the end per extension at that school, dictating whether external calls to that number will be sent straight to voicemail, or be allowed to ring through. I made a Python GUI so I could toggle that last digit per extension on the fly, if a teacher deals with the public a lot and wants calls from the outside to ring into the classroom phone.
[from-pstn-custom]
exten => _509222XXXX,1,NoOp(Checking school hours...)
same => n,Answer()
same => n,Set(finalexten=${EXTEN:-4})
same => n,Set(CALLER_ACCOUNTCODE=${DB(AMPUSER/${finalexten}/accountcode)})
same => n,GoToIf($[ ${CALLER_ACCOUNTCODE:-1} = 1 ]?allowcall)
same => n,GoSub(loc${CALLER_ACCOUNTCODE})
;set hours for school days
same => n(sethours),Noop(in sethours)
same => n,Set(hours_elem_nonwed=8:40-15:17)
same => n,Set(hours_elem_wed=8:40-14:00)
same => n,Set(hours_midl_nonwed=7:50-14:35)
same => n,Set(hours_midl_wed=7:50-13:00)
same => n,Set(hours_high_nonwed=7:45-14:20)
same => n,Set(hours_high_wed=7:45-13:10)
same => n,Gosub(loc${loccode})
;elementary schools
same => n(loc2020),Goto(elemhours)
(the rest of elementary removed because it's basically the same)
;middle schools
same => n(loc2190),Goto(middlehours)
(the rest of middle removed because it's basically the same)
;high schools
same => n(loc2300),Goto(highhours)
(the rest of high removed because it's basically the same)
same => n(elemhours),Noop(in elemhours) ;elementary forwarding check
same => n,GotoIfTime(${hours_elem_nonwed},mon&tue&thu&fri,*,*?schoolhours)
same => n,GotoIfTime(${hours_elem_wed},wed,*,*?schoolhours)
same => n,Goto(allowcall)
same => n(middlehours),Noop(in middlehours) ;middle school forwarding check
same => n,GotoIfTime(${hours_midl_nonwed},mon&tue&thu&fri,*,*?schoolhours)
same => n,GotoIfTime(${hours_midl_wed},wed,*,*?schoolhours)
same => n,Goto(allowcall)
same => n(middlespecial),Noop(in middlespecial) ;middle schools with no Wednesday early release
same => n,GotoIfTime(${hours_midl_nonwed},mon-fri,*,*?schoolhours)
same => n,Goto(allowcall)
same => n(highhours),Noop(in highhours) ;high school forwarding check
same => n,GotoIfTime(${hours_high_nonwed},mon&tue&thu&fri,*,*?schoolhours)
same => n,GotoIfTime(${hours_high_wed},wed,*,*?schoolhours)
same => n,Goto(allowcall)
same => n(loc2020),GoTo(elemhours) ; elementary
(the rest of elementary removed because it's basically the same)
same => n(loc2190),GoTo(middlehours) ; middle
(the rest of middle removed because it's basically the same)
same => n(loc2300),GoTo(highhours) ; high
(the rest of high removed because it's basically the same)
same => n(elemhours),Set(hourscheck=${EXTENSION_STATE(*272@from-internal)})
same => n,GoTo(vmorthrough)
same => n(middlehours),Set(hourscheck=${EXTENSION_STATE(*274@from-internal)})
same => n,GoTo(vmorthrough)
same => n(highhours),Set(hourscheck=${EXTENSION_STATE(*275@from-internal)})
same => n,GoTo(vmorthrough)
same => n(vmorthrough),NoOp(Voicemail or let caller in?)
same => n,GoToIf($[ "${hourscheck}" != "NOT_INUSE" ]?allowcall:gotovm)
same => n(gotovm),Noop(School is in session, send caller to voicemail)
same => n,Voicemail(${finalexten},u)
same => n,Macro(hangupcall,)
same => n(allowcall),Noop(Outside classroom hours, allowing call to ring to classroom)
same => n,GoTo(from-internal,${finalexten},1)
same => n,Hangup()