| 17 | | // Get a list of all the phones used for paging |
|---|
| 18 | | $sql = "SELECT DISTINCT ext FROM paging_groups"; |
|---|
| 19 | | $results = $db->getAll($sql); |
|---|
| 20 | | if (!isset($results[0][0])) { |
|---|
| 21 | | // There are no phones here, no paging support, lets give up now. |
|---|
| 22 | | return 0; |
|---|
| 23 | | } |
|---|
| 24 | | // We have paging support. |
|---|
| 25 | | $ext->addInclude('from-internal-additional','ext-paging'); |
|---|
| 26 | | // Lets give all the phones their PAGExxx lines. |
|---|
| 27 | | // TODO: Support for specific phones configurations |
|---|
| 28 | | foreach ($results as $grouparr) { |
|---|
| 29 | | $skipheaders = false; |
|---|
| 30 | | $xtn=trim($grouparr[0]); |
|---|
| 31 | | if (strtoupper(substr($xtn,-1)) == "X") { |
|---|
| 32 | | // hack for allowing no SIP headers |
|---|
| 33 | | //TODO : replace this with DevicesTakeTwo stuff |
|---|
| 34 | | $xtn = rtrim($xtn,"xX"); |
|---|
| 35 | | $skipheaders = true; |
|---|
| 36 | | } |
|---|
| 37 | | |
|---|
| 38 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${AMPUSER} = '.$xtn.' ]','skipself')); |
|---|
| 39 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${FORCE_PAGE} != 1 ]','AVAIL')); |
|---|
| 40 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('AVAILSTATUS', 'not checked')); |
|---|
| 41 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_goto('SKIPCHECK')); |
|---|
| 42 | | $ext->add('ext-paging', "PAGE${xtn}", 'AVAIL', new ext_chanisavail('${DB(DEVICE/'.$xtn.'/dial)}', 'js')); |
|---|
| 43 | | $ext->add('ext-paging', "PAGE${xtn}", 'SKIPCHECK', new ext_noop('Seems to be available (state = ${AVAILSTATUS}')); |
|---|
| 44 | | |
|---|
| 45 | | if (!$skipheaders) { |
|---|
| 46 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_sipaddheader('Call-Info','\;answer-after=0')); |
|---|
| 47 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_alertinfo('Ring Answer')); |
|---|
| 48 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true')); |
|---|
| 49 | | } |
|---|
| 50 | | |
|---|
| 51 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_dial("\${DB(DEVICE/${xtn}/dial)}", '5, A(beep)')); |
|---|
| 52 | | $ext->add('ext-paging', "PAGE${xtn}", 'skipself', new ext_noop('Not paging originator')); |
|---|
| 53 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_hangup()); |
|---|
| 54 | | |
|---|
| 55 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_noop('Channel ${AVAILCHAN} is not available (state = ${AVAILSTATUS})'), 'AVAIL',101); |
|---|
| 56 | | } |
|---|
| 57 | | // Now get a list of all the paging groups... |
|---|
| 58 | | $sql = "SELECT page_group, force_page FROM paging_config"; |
|---|
| 59 | | $paging_groups = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| 60 | | foreach ($paging_groups as $thisgroup) { |
|---|
| 61 | | $grp=trim($thisgroup['page_group']); |
|---|
| 62 | | $sql = "SELECT ext FROM paging_groups WHERE page_number='$grp'"; |
|---|
| 63 | | $all_exts = $db->getAll($sql); |
|---|
| 64 | | $dialstr=''; |
|---|
| 65 | | foreach($all_exts as $local_dial) { |
|---|
| 66 | | if (strtoupper(substr($local_dial[0],-1)) == "X") { |
|---|
| 67 | | $local_dial[0] = rtrim($local_dial[0],"xX"); |
|---|
| 68 | | } |
|---|
| 69 | | |
|---|
| 70 | | $dialstr .= "LOCAL/PAGE".trim($local_dial[0])."@ext-paging&"; |
|---|
| 71 | | } |
|---|
| 72 | | // It will always end with an &, so lets take that off. |
|---|
| 73 | | $dialstr = rtrim($dialstr, "&"); |
|---|
| 74 | | $ext->add('ext-paging', "Debug", '', new ext_noop("dialstr is $dialstr")); |
|---|
| 75 | | $ext->add('ext-paging', $grp, '', new ext_setvar("_FORCE_PAGE", ($thisgroup['force_page']?1:0))); |
|---|
| 76 | | $ext->add('ext-paging', $grp, '', new ext_macro('user-callerid')); |
|---|
| 77 | | // make AMPUSER inherited here, so we can skip the proper 'self' if using cidnum masquerading |
|---|
| 78 | | $ext->add('ext-paging', $grp, '', new ext_setvar('_AMPUSER', '${AMPUSER}')); |
|---|
| 79 | | $ext->add('ext-paging', $grp, '', new ext_page($dialstr)); |
|---|
| 80 | | } |
|---|
| 81 | | |
|---|
| 82 | | |
|---|
| 83 | | |
|---|
| 118 | | $ext->add('ext-intercom', $oncode, '', new ext_answer('')); // $cmd,1,Answer |
|---|
| 119 | | $ext->add('ext-intercom', $oncode, '', new ext_wait('1')); // $cmd,n,Wait(1) |
|---|
| 120 | | $ext->add('ext-intercom', $oncode, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid) |
|---|
| 121 | | $ext->add('ext-intercom', $oncode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'enabled')); // $cmd,n,Set(...=enabled) |
|---|
| 122 | | $ext->add('ext-intercom', $oncode, '', new ext_playback('intercom&enabled')); // $cmd,n,Playback(...) |
|---|
| 123 | | $ext->add('ext-intercom', $oncode, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid) |
|---|
| 124 | | } |
|---|
| | 48 | $ext->add('ext-intercom', $oncode, '', new ext_answer('')); |
|---|
| | 49 | $ext->add('ext-intercom', $oncode, '', new ext_wait('1')); |
|---|
| | 50 | $ext->add('ext-intercom', $oncode, '', new ext_macro('user-callerid')); |
|---|
| | 51 | $ext->add('ext-intercom', $oncode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'enabled')); |
|---|
| | 52 | $ext->add('ext-intercom', $oncode, '', new ext_playback('intercom&enabled')); |
|---|
| | 53 | $ext->add('ext-intercom', $oncode, '', new ext_macro('hangupcall')); |
|---|
| | 54 | } |
|---|
| 131 | | $ext->add('ext-intercom', $offcode, '', new ext_answer('')); // $cmd,1,Answer |
|---|
| 132 | | $ext->add('ext-intercom', $offcode, '', new ext_wait('1')); // $cmd,n,Wait(1) |
|---|
| 133 | | $ext->add('ext-intercom', $offcode, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid) |
|---|
| 134 | | $ext->add('ext-intercom', $offcode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'disabled')); // $cmd,n,Set(...=disabled) |
|---|
| 135 | | $ext->add('ext-intercom', $offcode, '', new ext_playback('intercom&disabled')); // $cmd,n,Playback(...) |
|---|
| 136 | | $ext->add('ext-intercom', $offcode, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid) |
|---|
| 137 | | } |
|---|
| 138 | | } |
|---|
| 139 | | |
|---|
| | 61 | $ext->add('ext-intercom', $offcode, '', new ext_answer('')); |
|---|
| | 62 | $ext->add('ext-intercom', $offcode, '', new ext_wait('1')); |
|---|
| | 63 | $ext->add('ext-intercom', $offcode, '', new ext_macro('user-callerid')); |
|---|
| | 64 | $ext->add('ext-intercom', $offcode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'disabled')); |
|---|
| | 65 | $ext->add('ext-intercom', $offcode, '', new ext_playback('intercom&disabled')); |
|---|
| | 66 | $ext->add('ext-intercom', $offcode, '', new ext_macro('hangupcall')); |
|---|
| | 67 | } |
|---|
| | 68 | } |
|---|
| | 69 | |
|---|
| | 70 | // Get a list of all the phones used for paging |
|---|
| | 71 | $sql = "SELECT DISTINCT ext FROM paging_groups"; |
|---|
| | 72 | $results = $db->getAll($sql); |
|---|
| | 73 | if (!isset($results[0][0])) { |
|---|
| | 74 | // There are no phones here, no paging support, lets give up now. |
|---|
| | 75 | return 0; |
|---|
| | 76 | } |
|---|
| | 77 | // We have paging support. |
|---|
| | 78 | $ext->addInclude('from-internal-additional','ext-paging'); |
|---|
| | 79 | // Lets give all the phones their PAGExxx lines. |
|---|
| | 80 | // TODO: Support for specific phones configurations |
|---|
| | 81 | foreach ($results as $grouparr) { |
|---|
| | 82 | $skipheaders = false; |
|---|
| | 83 | $xtn=trim($grouparr[0]); |
|---|
| | 84 | if (strtoupper(substr($xtn,-1)) == "X") { |
|---|
| | 85 | // hack for allowing no SIP headers |
|---|
| | 86 | //TODO : replace this with DevicesTakeTwo stuff |
|---|
| | 87 | $xtn = rtrim($xtn,"xX"); |
|---|
| | 88 | $skipheaders = true; |
|---|
| | 89 | } |
|---|
| | 90 | |
|---|
| | 91 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${AMPUSER} = '.$xtn.' ]','skipself')); |
|---|
| | 92 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${FORCE_PAGE} != 1 ]','AVAIL')); |
|---|
| | 93 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('AVAILSTATUS', 'not checked')); |
|---|
| | 94 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_goto('SKIPCHECK')); |
|---|
| | 95 | $ext->add('ext-paging', "PAGE${xtn}", 'AVAIL', new ext_chanisavail('${DB(DEVICE/'.$xtn.'/dial)}', 'js')); |
|---|
| | 96 | $ext->add('ext-paging', "PAGE${xtn}", 'SKIPCHECK', new ext_noop('Seems to be available (state = ${AVAILSTATUS}')); |
|---|
| | 97 | |
|---|
| | 98 | if (!$skipheaders) { |
|---|
| | 99 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_sipaddheader('Call-Info','\;answer-after=0')); |
|---|
| | 100 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_alertinfo('Ring Answer')); |
|---|
| | 101 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true')); |
|---|
| | 102 | } |
|---|
| | 103 | |
|---|
| | 104 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_dial("\${DB(DEVICE/${xtn}/dial)}", '5, A(beep)')); |
|---|
| | 105 | $ext->add('ext-paging', "PAGE${xtn}", 'skipself', new ext_noop('Not paging originator')); |
|---|
| | 106 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_hangup()); |
|---|
| | 107 | |
|---|
| | 108 | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_noop('Channel ${AVAILCHAN} is not available (state = ${AVAILSTATUS})'), 'AVAIL',101); |
|---|
| | 109 | } |
|---|
| | 110 | // Now get a list of all the paging groups... |
|---|
| | 111 | $sql = "SELECT page_group, force_page FROM paging_config"; |
|---|
| | 112 | $paging_groups = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| | 113 | foreach ($paging_groups as $thisgroup) { |
|---|
| | 114 | $grp=trim($thisgroup['page_group']); |
|---|
| | 115 | $sql = "SELECT ext FROM paging_groups WHERE page_number='$grp'"; |
|---|
| | 116 | $all_exts = $db->getAll($sql); |
|---|
| | 117 | $dialstr=''; |
|---|
| | 118 | foreach($all_exts as $local_dial) { |
|---|
| | 119 | if (strtoupper(substr($local_dial[0],-1)) == "X") { |
|---|
| | 120 | $local_dial[0] = rtrim($local_dial[0],"xX"); |
|---|
| | 121 | } |
|---|
| | 122 | |
|---|
| | 123 | $dialstr .= "LOCAL/PAGE".trim($local_dial[0])."@ext-paging&"; |
|---|
| | 124 | } |
|---|
| | 125 | // It will always end with an &, so lets take that off. |
|---|
| | 126 | $dialstr = rtrim($dialstr, "&"); |
|---|
| | 127 | $ext->add('ext-paging', "Debug", '', new ext_noop("dialstr is $dialstr")); |
|---|
| | 128 | $ext->add('ext-paging', $grp, '', new ext_setvar("_FORCE_PAGE", ($thisgroup['force_page']?1:0))); |
|---|
| | 129 | $ext->add('ext-paging', $grp, '', new ext_macro('user-callerid')); |
|---|
| | 130 | // make AMPUSER inherited here, so we can skip the proper 'self' if using cidnum masquerading |
|---|
| | 131 | $ext->add('ext-paging', $grp, '', new ext_setvar('_AMPUSER', '${AMPUSER}')); |
|---|
| | 132 | $ext->add('ext-paging', $grp, '', new ext_page($dialstr)); |
|---|
| | 133 | } |
|---|
| | 134 | |
|---|