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

Because the Set() dialplan application can also take arguments (you can
                           set multiple variables and values by separating them with commas or
                           pipes), you need to escape the comma with the backslash ( \ ) so it is
                           not processed by the expression parser for the Set() application, but
                           rather parses it for the HOTDESK_STATUS() function.

               Notice the syntax is slightly different from that of the read style function. This signals
               to Asterisk that you want to perform a write (this is the same syntax as other dialplan
               functions).
               We are passing the value of the ${E} variable to the HOTDESK_STATUS() function, whose
               value is then accessible in the SQL statement within func_odbc.conf with the ${ARG1}
               variable. We then pass two values: 1 and ${LOCATION}. These are available to the SQL
               statement in the ${VAL1} and ${VAL2} variables, respectively.
               As mentioned previously, if we had to log out one or more agents before logging in, we
               would check this with the logout_login extension. This dialplan logic will utilize the
               While() application to loop through the database and perform any database correction
               that may need to occur. More than likely this will execute only one loop, but it’s a good
               example of how you might update or parse multiple rows in the database:
                   exten => logout_login,1,NoOp()
                   ; set all logged in users on this device to logged out status
                   exten => logout_login,n,Set(ROW_COUNTER=0)
                   exten => logout_login,n,While($[${ROW_COUNTER} < ${USERS_LOGGED_IN}])

               The ${USERS_LOGGED_IN} variable was set previously with the HOTDESK_CHECK_PHONE_LOG
               INS() function, which assigned a value of 1 or greater. We did this by counting the
               number of rows that were affected:
                   ; func_odbc.conf
                   [CHECK_PHONE_LOGINS]
                   prefix=HOTDESK
                   dsn=asterisk
                   read=SELECT COUNT(status) FROM ast_hotdesk WHERE status = '1' AND location = '${ARG1}'
               We then get the extension number of the user that is logged in with the HOTDESK_LOG
               GED_IN_USER() function. The LOCATION variable is populated with desk_1, which tells us
               which device we want to check on, and the ${ROW_COUNTER} contains which iteration of
               the loop we’re on. These are both passed as arguments to the dialplan function. The
               result is then assigned to the WHO variable:
                   exten => logout_login,n,Set(WHO=${HOTDESK_LOGGED_IN_USER(${LOCATION},${ROW_COUNTER})})
               The HOTDESK_LOGGED_IN_USER() function then pulls a specific row out of the database
               that corresponds with the iteration of the loops we are trying to process:

                   [LOGGED_IN_USER]
                   prefix=HOTDESK
                   dsn=asterisk



               282 | Chapter 12: Relational Database Integration
   305   306   307   308   309   310   311   312   313   314   315