Page 311 - Asterisk™: The Future of Telephony
P. 311

read=SELECT extension FROM ast_hotdesk WHERE status = '1'
                   AND location = '${ARG1}' ORDER BY id LIMIT '1' OFFSET '${ARG2}'
               Now that we know what extension we want to update, we write to the HOTDESK_STATUS
               () function, and assign a 0 to the status column where the extension number matches
               the value in the ${WHO} variable (i.e., 1101). We then end the loop with EndWhile() and
               return back to the valid_login extension at the set_login_status priority label (as dis-
               cussed previously):
                   exten => logout_login,n,Set(HOTDESK_STATUS(${WHO})=0)           ; logout phone
                   exten => logout_login,n,Set(ROW_COUNTER=$[${ROW_COUNTER} + 1])
                   exten => logout_login,n,EndWhile()
                   exten => logout_login,n,Goto(valid_login,set_login_status)      ; return to logging in
               The rest of the context should be fairly straightforward (if some of this doesn’t make
               sense, we suggest you go back and refresh your memory with Chapter 5 and Chap-
               ter 6). The one trick you may be unfamiliar with could be the usage of the  ${ODB
               CROWS} channel variable, which is set by the HOTDESK_STATUS() function. This tells us
               how many rows were affected in the SQL UPDATE, which we assume to be 1. If the value
               of ${ODBCROWS} is less than 1, then we assume an error and handle appropriately:
                   exten => logout,1,NoOp()
                   exten => logout,n,Set(HOTDESK_STATUS(${E})=0)
                   exten => logout,n,GotoIf($[${ODBCROWS} < 1]?error,1)
                   exten => logout,n,Playback(silence/1&agent-loggedoff)
                   exten => logout,n,Hangup()
                   exten => login_fail,1,NoOp()
                   exten => login_fail,n,Playback(silence/1&login-fail)
                   exten => login_fail,n,Hangup()

                   exten => error,1,NoOp()
                   exten => error,n,Playback(silence/1&connection-failed)
                   exten => error,n,Hangup()

                   exten => invalid_user,1,NoOp()
                   exten => invalid_user,n,Verbose(1|Hot Desk extension ${E} does not exist)
                   exten => invalid_user,n,Playback(silence/2&invalid)
                   exten => invalid_user,n,Hangup()
               We also include the hotdesk_outbound context which will handle our outgoing calls
               after we have logged the agent in to the system:
                   include => hotdesk_outbound
               The hotdesk_outbound context utilizes many of the same principles and usage as pre-
               viously discussed, so we won’t approach it quite so thoroughly, but essentially the
               [hotdesk_outbound] context will catch all dialed numbers from the desk phones. We first
               set our LOCATION variable using the CHANNEL variable, then determine which extension
               (agent) is logged in to the system and assign it to the WHO variable. If this variable is
               NULL, then we reject the outgoing call. If not NULL, then we get the agent information
               using  the  HOTDESK_INFO()  function  and  assign  it  to  several  CHANNEL  variables.  This



                                                        Getting Funky with func_odbc: Hot-Desking | 283
   306   307   308   309   310   311   312   313   314   315   316