| 29 | | $ivrlist = ivr_list(); |
|---|
| 30 | | if(is_array($ivrlist)) { |
|---|
| 31 | | foreach($ivrlist as $item) { |
|---|
| 32 | | $id = "ivr-".$item['ivr_id']; |
|---|
| 33 | | $details = ivr_get_details($item['ivr_id']); |
|---|
| 34 | | |
|---|
| 35 | | $announcement_id = (isset($details['announcement_id']) ? $details['announcement_id'] : ''); |
|---|
| 36 | | $timeout_id = (isset($details['timeout_id']) ? $details['timeout_id'] : ''); |
|---|
| 37 | | $invalid_id = (isset($details['invalid_id']) ? $details['invalid_id'] : ''); |
|---|
| 38 | | $loops = (isset($details['loops']) ? $details['loops'] : '2'); |
|---|
| 39 | | $retvm = (isset($details['retvm']) ? $details['retvm'] : ''); |
|---|
| 40 | | |
|---|
| 41 | | if (!empty($details['enable_directdial'])) { |
|---|
| 42 | | if ($details['enable_directdial'] == 'CHECKED') { |
|---|
| 43 | | $ext->addInclude($id,'from-did-direct-ivr'); //generated in core module |
|---|
| | 39 | $ivrlist = ivr_get_details(); |
|---|
| | 40 | if(!is_array($ivrlist)) { |
|---|
| | 41 | break; |
|---|
| | 42 | } |
|---|
| | 43 | |
|---|
| | 44 | //draw a list of ivrs included by queues |
|---|
| | 45 | $queues = queues_list(true); |
|---|
| | 46 | |
|---|
| | 47 | foreach ($queues as $q) { |
|---|
| | 48 | $thisq = queues_get($q[0]); |
|---|
| | 49 | if ($thisq['context'] && strpos($thisq['context'], 'ivr-') === 0) { |
|---|
| | 50 | $qivr[] = str_replace('ivr-', '', $thisq['context']); |
|---|
| | 51 | } |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | foreach($ivrlist as $ivr) { |
|---|
| | 55 | $c = 'ivr-' . $ivr['id']; |
|---|
| | 56 | $ivr = ivr_get_details($ivr['id']); |
|---|
| | 57 | |
|---|
| | 58 | if ($ivr['directdial'] != '') { |
|---|
| | 59 | if ($details['enable_directdial'] == 'ext-local') { |
|---|
| | 60 | $ext->addInclude($id,'from-did-direct-ivr'); //generated in core module |
|---|
| | 61 | } else { |
|---|
| | 62 | //TODO: include directory context here! |
|---|
| | 63 | //$ext->addInclude($id,'from-ivr-directory-'.$details['enable_directdial']); |
|---|
| | 64 | //$ddial_contexts[$details['enable_directdial']] = true; |
|---|
| | 65 | } |
|---|
| | 66 | } |
|---|
| | 67 | |
|---|
| | 68 | //TODO: seperate timeout & invalid loops |
|---|
| | 69 | if ($ivr['timeout_loops'] != 'disabled') { |
|---|
| | 70 | $ext->add($c, 's', '', new ext_setvar('TIMEOUT_LOOPCOUNT', 0)); |
|---|
| | 71 | } |
|---|
| | 72 | if ($ivr['invalid_loops'] != 'disabled') { |
|---|
| | 73 | $ext->add($c, 's', '', new ext_setvar('INVALID_LOOPCOUNT', 0)); |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | //TODO: no clue what the next tow lines are for --MB |
|---|
| | 77 | $ext->add($c, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}')); |
|---|
| | 78 | $ext->add($c, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); |
|---|
| | 79 | $ext->add($c, 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]','start')); |
|---|
| | 80 | $ext->add($c, 's', '', new ext_answer('')); |
|---|
| | 81 | $ext->add($c, 's', '', new ext_wait('1')); |
|---|
| | 82 | $ext->add($c, 's', 'start', new ext_digittimeout(3)); |
|---|
| | 83 | //$ext->add($ivr_id, 's', '', new ext_responsetimeout($ivr['timeout_time'])); |
|---|
| | 84 | |
|---|
| | 85 | if ($ivr['retvm']) { |
|---|
| | 86 | $ext->add($c, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN')); |
|---|
| | 87 | } else { |
|---|
| | 88 | //TODO: do we need to set anything at all? |
|---|
| | 89 | $ext->add($c, 's', '', new ext_setvar('__IVR_RETVM', '')); |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | $ext->add($c, 's', '', new ext_background(recordings_get_file($ivr['announcement']))); |
|---|
| | 93 | $ext->add($c, 's', '', new ext_waitexten($ivr['timeout_time'])); |
|---|
| | 94 | |
|---|
| | 95 | |
|---|
| | 96 | // Actually add the IVR commands now. |
|---|
| | 97 | $entries = ivr_get_entries($ivr['id']); |
|---|
| | 98 | |
|---|
| | 99 | if ($entries) { |
|---|
| | 100 | foreach($entries as $e) { |
|---|
| | 101 | //dont set a t or i if there already defined above |
|---|
| | 102 | if ($e['selection'] == 't' && $ivr['timeout_loops'] != 'disabled') { |
|---|
| | 103 | continue; |
|---|
| | 104 | } |
|---|
| | 105 | if ($e['selection'] == 'i' && $ivr['invalid_loops'] != 'disabled') { |
|---|
| | 106 | continue; |
|---|
| | 107 | } |
|---|
| | 108 | |
|---|
| | 109 | //only display these two lines if the ivr can be called from a queue |
|---|
| | 110 | if (in_array($ivr['id'], $qivr)) { |
|---|
| | 111 | $ext->add($c, $e['selection'],'', new ext_macro('blkvm-clr')); |
|---|
| | 112 | $ext->add($c, $e['selection'], '', new ext_setvar('__NODEST', '')); |
|---|
| | 113 | |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 116 | if ($e['ivr_ret']) { |
|---|
| | 117 | $ext->add($c, $e['selection'], '', |
|---|
| | 118 | new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]', |
|---|
| | 119 | $e['dest'] . ':${IVR_CONTEXT_${CONTEXT}},return,1')); |
|---|
| 49 | | // I'm not sure I like the ability of people to send voicemail from the IVR. |
|---|
| 50 | | // Make it a config option, possibly? |
|---|
| 51 | | // $ext->addInclude($item[0],'app-messagecenter'); |
|---|
| 52 | | if (!empty($details['enable_directory'])) { |
|---|
| 53 | | $ext->addInclude($id,'app-directory'); |
|---|
| 54 | | $dir = featurecodes_getFeatureCode('infoservices', 'directory'); |
|---|
| 55 | | $ext->add($id, '#' ,'', new ext_macro('blkvm-clr')); |
|---|
| 56 | | $ext->add($id, '#' ,'', new ext_setvar('__NODEST', '')); |
|---|
| 57 | | $ext->add($id, '#', '', new ext_goto("app-directory,$dir,1")); |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 126 | // add invalid if required |
|---|
| | 127 | dbug('ivr', $ivr); |
|---|
| | 128 | if ($ivr['invalid_loops'] != 'disabled') { |
|---|
| | 129 | switch ($ivr['invalid_retry_recording']) { |
|---|
| | 130 | case 'default': |
|---|
| | 131 | $ext->add($c, 'i', '', new ext_playback('invalid')); |
|---|
| | 132 | break; |
|---|
| | 133 | case '': |
|---|
| | 134 | break; |
|---|
| | 135 | default: |
|---|
| | 136 | $ext->add($c, 'i', '', |
|---|
| | 137 | new ext_playback(recordings_get_file($ivr['invalid_retry_recording']))); |
|---|
| | 138 | break; |
|---|
| 59 | | |
|---|
| 60 | | $ext->add($id, 'h', '', new ext_hangup('')); |
|---|
| 61 | | if ($announcement_id) { |
|---|
| 62 | | $announcement_msg = recordings_get_file($announcement_id); |
|---|
| 63 | | $ext->add($id, 's', '', new ext_setvar('MSG', "$announcement_msg")); |
|---|
| 64 | | } else { |
|---|
| 65 | | $ext->add($id, 's', '', new ext_setvar('MSG', "")); |
|---|
| | 140 | $ext->add($c, 'i', '', new ext_set('INVALID_LOOPCOUNT', '$[${INVALID_LOOPCOUNT}+1]')); |
|---|
| | 141 | $ext->add($c, 'i', '', |
|---|
| | 142 | new ext_gotoif('$[${INVALID_LOOPCOUNT} <= ' . $ivr['invalid_loops'] . ']','s,start')); |
|---|
| | 143 | |
|---|
| | 144 | |
|---|
| | 145 | switch ($ivr['invalid_recording']) { |
|---|
| | 146 | case 'default': |
|---|
| | 147 | $ext->add($c, 'i', '', new ext_playback('invalid')); |
|---|
| | 148 | break; |
|---|
| | 149 | case '': |
|---|
| | 150 | break; |
|---|
| | 151 | default: |
|---|
| | 152 | $ext->add($c, 'i', '', |
|---|
| | 153 | new ext_playback(recordings_get_file($ivr['invalid_recording']))); |
|---|
| | 154 | break; |
|---|
| 67 | | $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0)); |
|---|
| 68 | | $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext'])); |
|---|
| 69 | | $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}')); |
|---|
| 70 | | $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); |
|---|
| 71 | | $ext->add($id, 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]','begin')); |
|---|
| 72 | | $ext->add($id, 's', '', new ext_answer('')); |
|---|
| 73 | | $ext->add($id, 's', '', new ext_wait('1')); |
|---|
| 74 | | $ext->add($id, 's', 'begin', new ext_digittimeout(3)); |
|---|
| 75 | | $ext->add($id, 's', '', new ext_responsetimeout($details['timeout'])); |
|---|
| 76 | | |
|---|
| 77 | | if ($retvm) { |
|---|
| 78 | | $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN')); |
|---|
| 79 | | } else { |
|---|
| 80 | | $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', '')); |
|---|
| | 156 | $ext->add($c, 'i', '', new ext_goto($ivr['invalid_destination'])); |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | // Apply timeout if required |
|---|
| | 160 | if ($ivr['timeout_loops'] != 'disabled') { |
|---|
| | 161 | switch ($ivr['timeout_retry_recording']) { |
|---|
| | 162 | case 'default': |
|---|
| | 163 | $ext->add($c, 't', '', new ext_playback('invalid')); |
|---|
| | 164 | break; |
|---|
| | 165 | case '': |
|---|
| | 166 | break; |
|---|
| | 167 | default: |
|---|
| | 168 | $ext->add($c, 't', '', |
|---|
| | 169 | new ext_playback(recordings_get_file($ivr['timeout_retry_recording']))); |
|---|
| | 170 | break; |
|---|
| 82 | | |
|---|
| 83 | | $ext->add($id, 's', '', new ext_execif('$["${MSG}" != ""]','Background','${MSG}')); |
|---|
| 84 | | $ext->add($id, 's', '', new ext_waitexten($details['timeout'])); |
|---|
| 85 | | $ext->add($id, 'hang', '', new ext_playback('vm-goodbye')); |
|---|
| 86 | | $ext->add($id, 'hang', '', new ext_hangup('')); |
|---|
| 87 | | |
|---|
| 88 | | $default_t=true; |
|---|
| 89 | | |
|---|
| 90 | | // Actually add the IVR commands now. |
|---|
| 91 | | $dests = ivr_get_dests($item['ivr_id']); |
|---|
| 92 | | $timeout=false; |
|---|
| 93 | | $invalid=false; |
|---|
| 94 | | $addloop=false; |
|---|
| 95 | | if (!empty($dests)) { |
|---|
| 96 | | foreach($dests as $dest) { |
|---|
| 97 | | if ($dest['selection'] == 't' && empty($details['alt_timeout'])) { |
|---|
| 98 | | $timeout=true; |
|---|
| 99 | | } elseif ($dest['selection'] == 'i' && empty($details['alt_invalid'])) { |
|---|
| 100 | | $invalid=true; |
|---|
| 101 | | } elseif (($dest['selection'] == 't' && !empty($details['alt_timeout']))) { |
|---|
| 102 | | $timeout=true; |
|---|
| 103 | | if ($timeout_id) { |
|---|
| 104 | | $timeout_msg = recordings_get_file($timeout_id); |
|---|
| 105 | | $ext->add($id, $dest['selection'], '', new ext_setvar('MSG',"$timeout_msg")); |
|---|
| 106 | | } |
|---|
| 107 | | $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT','$[${LOOPCOUNT} + 1]')); |
|---|
| 108 | | $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= '.$loops.']','s,begin')); |
|---|
| 109 | | } elseif (($dest['selection'] == 'i' && !empty($details['alt_invalid']))) { |
|---|
| 110 | | $invalid=true; |
|---|
| 111 | | $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT','$[${LOOPCOUNT} + 1]')); |
|---|
| 112 | | |
|---|
| 113 | | |
|---|
| 114 | | if ($invalid_id) { |
|---|
| 115 | | $invalid_msg = recordings_get_file($invalid_id); |
|---|
| 116 | | $ext->add($id, $dest['selection'], '', new ext_setvar('MSG',"$invalid_msg")); |
|---|
| 117 | | } else { |
|---|
| 118 | | $ext->add($id, $dest['selection'], '', new ext_execif('$[${LOOPCOUNT} <= '.$loops.']','Playback','invalid')); |
|---|
| 119 | | } |
|---|
| 120 | | $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= '.$loops.']','s,begin')); |
|---|
| 121 | | } |
|---|
| 122 | | $ext->add($id, $dest['selection'],'', new ext_macro('blkvm-clr')); |
|---|
| 123 | | $ext->add($id, $dest['selection'],'', new ext_setvar('__NODEST', '')); |
|---|
| 124 | | |
|---|
| 125 | | // if the goto goes loops back to this ivr, then don't go to the begining or it will break the return to previous ivr info |
|---|
| 126 | | // |
|---|
| 127 | | $dest_context = trim(strtok($dest['dest'],",|")); |
|---|
| 128 | | if ($dest_context == $id) { |
|---|
| 129 | | $dest['dest'] = $id.',s,begin'; |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | if ($dest['ivr_ret']) { |
|---|
| 133 | | $ext->add($id, $dest['selection'],'', new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]', $dest['dest'].':${IVR_CONTEXT_${CONTEXT}},return,1')); |
|---|
| 134 | | } else { |
|---|
| 135 | | $ext->add($id, $dest['selection'],'', new ext_goto($dest['dest'])); |
|---|
| 136 | | } |
|---|
| 137 | | } |
|---|
| | 172 | $ext->add($c, 't', '', new ext_set('TIMEOUT_LOOPCOUNT', '$[${TIMEOUT_LOOPCOUNT}+1]')); |
|---|
| | 173 | $ext->add($c, 't', '', |
|---|
| | 174 | new ext_gotoif('$[${TIMEOUT_LOOPCOUNT} <= ' . $ivr['timeout_loops'] . ']','s,start')); |
|---|
| | 175 | |
|---|
| | 176 | |
|---|
| | 177 | switch ($ivr['timeout_recording']) { |
|---|
| | 178 | case 'default': |
|---|
| | 179 | $ext->add($c, 't', '', new ext_playback('invalid')); |
|---|
| | 180 | break; |
|---|
| | 181 | case '': |
|---|
| | 182 | break; |
|---|
| | 183 | default: |
|---|
| | 184 | $ext->add($c, 't', '', |
|---|
| | 185 | new ext_playback(recordings_get_file($ivr['timeout_recording']))); |
|---|
| | 186 | break; |
|---|
| 139 | | // Apply invalid if required |
|---|
| 140 | | if (!$invalid) { |
|---|
| 141 | | if ($invalid_id) { |
|---|
| 142 | | $invalid_msg = recordings_get_file($invalid_id); |
|---|
| 143 | | $ext->add($id, 'i', '', new ext_setvar('MSG',"$invalid_msg")); |
|---|
| 144 | | } else { |
|---|
| 145 | | $ext->add($id, 'i', '', new ext_playback('invalid')); |
|---|
| 146 | | } |
|---|
| 147 | | $ext->add($id, 'i', '', new ext_goto('loop,1')); |
|---|
| 148 | | $addloop=true; |
|---|
| 149 | | } |
|---|
| 150 | | if (!$timeout) { |
|---|
| 151 | | if ($timeout_id) { |
|---|
| 152 | | $timeout_msg = recordings_get_file($timeout_id); |
|---|
| 153 | | $ext->add($id, 't', '', new ext_setvar('MSG',"$timeout_msg")); |
|---|
| 154 | | } |
|---|
| 155 | | $ext->add($id, 't', '', new ext_goto('loop,1')); |
|---|
| 156 | | $addloop=true; |
|---|
| 157 | | } |
|---|
| 158 | | if ($addloop) { |
|---|
| 159 | | $ext->add($id, 'loop', '', new ext_setvar('LOOPCOUNT','$[${LOOPCOUNT} + 1]')); |
|---|
| 160 | | $ext->add($id, 'loop', '', new ext_gotoif('$[${LOOPCOUNT} > '.$loops.']','hang,1')); |
|---|
| 161 | | $ext->add($id, 'loop', '', new ext_goto($id.',s,begin')); |
|---|
| 162 | | |
|---|
| 163 | | // these need to be reset or inheritance problems makes them go away in some conditions and infinite inheritance creates other problems |
|---|
| 164 | | // reset the message including blanking it if set by a sub-ivr |
|---|
| 165 | | $announcement_msg = ($announcement_id) ? $announcement_msg : ''; |
|---|
| 166 | | $ext->add($id, 'return', '', new ext_setvar('MSG', "$announcement_msg")); |
|---|
| 167 | | $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); |
|---|
| 168 | | $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}')); |
|---|
| 169 | | $ext->add($id, 'return', '', new ext_goto($id.',s,begin')); |
|---|
| 170 | | } |
|---|
| 171 | | } |
|---|
| 172 | | |
|---|
| 173 | | if (!empty($ddial_contexts)) { |
|---|
| 174 | | global $version; |
|---|
| 175 | | $ast_lt_14 = version_compare($version, '1.4', 'lt'); |
|---|
| 176 | | |
|---|
| 177 | | foreach(array_keys($ddial_contexts) as $dir_id) { |
|---|
| 178 | | $context = 'from-ivr-directory-'.$dir_id; |
|---|
| 179 | | $entries = function_exists('directory_get_dir_entries') ? directory_get_dir_entries($dir_id) : array(); |
|---|
| 180 | | foreach ($entries as $dstring) { |
|---|
| 181 | | $exten = $dstring['dial'] == '' ? $dstring['foreign_id'] : $dstring['dial']; |
|---|
| 182 | | if ($exten == '' || $exten == 'custom') { |
|---|
| 183 | | continue; |
|---|
| 184 | | } |
|---|
| 185 | | $ext->add($context, $exten,'', new ext_macro('blkvm-clr')); |
|---|
| 186 | | $ext->add($context, $exten,'', new ext_setvar('__NODEST', '')); |
|---|
| 187 | | $ext->add($context, $exten,'', new ext_goto('1',$exten,'from-internal')); |
|---|
| 188 | | } |
|---|
| 189 | | } |
|---|
| | 188 | $ext->add($c, 't', '', new ext_goto($ivr['timeout_destination'])); |
|---|
| | 189 | } |
|---|
| | 190 | if ($ivr['retvm']) { |
|---|
| | 191 | // these need to be reset or inheritance problems makes them go away in some conditions |
|---|
| | 192 | //and infinite inheritance creates other problems |
|---|
| | 193 | $ext->add($c, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); |
|---|
| | 194 | $ext->add($c, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}')); |
|---|
| | 195 | $ext->add($c, 'return', '', new ext_goto($ivr['id'] . ',s,start')); |
|---|