root/modules/branches/2.7/callforward/functions.inc.php

Revision 10433, 22.3 kB (checked in by p_lindheimer, 3 years ago)

Merged revisions 10432 via svnmerge from
http://svn.freepbx.org/modules/branches/2.8

........

r10432 | p_lindheimer | 2010-10-22 14:54:49 -0700 (Fri, 22 Oct 2010) | 1 line


fixes #4578 use NOT_INUSE in place of UNKNOWN

........

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 // Copyright (C) 2005 qldrob
18 function callforward_get_config($engine) {
19   $modulename = 'callforward';
20  
21   // This generates the dialplan
22   global $ext; 
23   global $amp_conf; 
24   global $version;
25   global $DEVSTATE;
26   switch($engine) {
27     case "asterisk":
28       // If Using CF then set this so AGI scripts can determine
29       //
30       if ($amp_conf['USEDEVSTATE']) {
31         $ext->addGlobal('CFDEVSTATE','TRUE');
32       }
33       $DEVSTATE = version_compare($version, "1.6", "ge") ? "DEVICE_STATE" : "DEVSTATE";
34
35       if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
36         foreach($featurelist as $item) {
37           $featurename = $item['featurename'];
38           $fname = $modulename.'_'.$featurename;
39           if (function_exists($fname)) {
40             $fcc = new featurecode($modulename, $featurename);
41             $fc = $fcc->getCodeActive();
42             unset($fcc);
43             
44             if ($fc != '')
45               $fname($fc);
46           } else {
47             $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
48             var_dump($item);
49           }
50         }
51       }
52
53       // Create hints context for CF codes so a device can subscribe to the DND state
54       //
55       $fcc = new featurecode($modulename, 'cf_toggle');
56       $cf_code = $fcc->getCodeActive();
57       unset($fcc);
58
59       if ($amp_conf['USEDEVSTATE'] && $cf_code != '') {
60         $ext->addInclude('from-internal-additional','ext-cf-hints');
61         $contextname = 'ext-cf-hints';
62         $device_list = core_devices_list("all", false, true);
63         $base_offset = strlen($cf_code);
64         foreach ($device_list as $device) {
65           $offset = $base_offset + strlen($device['id']);
66           $ext->add($contextname, $cf_code.$device['id'], '', new ext_goto("1",$cf_code,"app-cf-toggle"));
67           $ext->add($contextname, '_'.$cf_code.$device['id'].'.', '', new ext_set("toext",'${EXTEN:'.$offset.'}'));
68           $ext->add($contextname, '_'.$cf_code.$device['id'].'.', '', new ext_goto("setdirect",$cf_code,"app-cf-toggle"));
69           $ext->addHint($contextname, $cf_code.$device['id'], "Custom:DEVCF".$device['id']);
70         }
71       }
72
73     break;
74   }
75 }
76
77 // Unconditional Call Forwarding Toggle
78 function callforward_cf_toggle($c) {
79   global $ext;
80   global $amp_conf;
81   global $DEVSTATE;
82
83   $id = "app-cf-toggle"; // The context to be included
84
85   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
86
87   $ext->add($id, $c, '', new ext_answer(''));
88   $ext->add($id, $c, '', new ext_wait('1'));
89   $ext->add($id, $c, '', new ext_macro('user-callerid'));
90   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
91
92   $ext->add($id, $c, '', new ext_gotoif('$["${DB(CF/${fromext})}" = ""]', 'activate', 'deactivate'));
93
94   $ext->add($id, $c, 'activate', new ext_playback('ent-target-attendant'));
95   $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
96   $ext->add($id, $c, '', new ext_gotoif('$["${toext}"=""]', 'activate'));
97   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
98   $ext->add($id, $c, 'toext', new ext_setvar('DB(CF/${fromext})', '${toext}'));
99   if ($amp_conf['USEDEVSTATE']) {
100     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
101     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
102   }
103   if ($amp_conf['FCBEEPONLY']) {
104     $ext->add($id, $c, 'hook_on', new ext_playback('beep')); // $cmd,n,Playback(...)
105   } else {
106     $ext->add($id, $c, 'hook_on', new ext_playback('call-fwd-unconditional&for&extension'));
107     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
108     $ext->add($id, $c, '', new ext_playback('is-set-to'));
109     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
110   }
111   $ext->add($id, $c, '', new ext_macro('hangupcall'));
112   $ext->add($id, $c, 'setdirect', new ext_answer(''));
113   $ext->add($id, $c, '', new ext_wait('1'));
114   $ext->add($id, $c, '', new ext_macro('user-callerid'));
115   $ext->add($id, $c, '', new ext_goto('toext'));
116
117   $ext->add($id, $c, 'deactivate', new ext_dbdel('CF/${fromext}'));
118   if ($amp_conf['USEDEVSTATE']) {
119     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
120     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
121   }
122   if ($amp_conf['FCBEEPONLY']) {
123     $ext->add($id, $c, 'hook_off', new ext_playback('beep')); // $cmd,n,Playback(...)
124   } else {
125     $ext->add($id, $c, 'hook_off', new ext_playback('call-fwd-unconditional&de-activated')); // $cmd,n,Playback(...)
126   }
127   $ext->add($id, $c, '', new ext_macro('hangupcall'));
128
129   if ($amp_conf['USEDEVSTATE']) {
130     $c = 'sstate';
131     $ext->add($id, $c, '', new ext_setvar($DEVSTATE.'(Custom:CF${fromext})', '${STATE}'));
132     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
133     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
134     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
135     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
136     $ext->add($id, $c, 'begin', new ext_setvar($DEVSTATE.'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
137     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
138     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
139     $ext->add($id, $c, 'return', new ext_return());
140   }
141 }
142
143 // Unconditional Call Forwarding
144 function callforward_cfon($c) {
145   global $ext;
146   global $amp_conf;
147   global $DEVSTATE;
148
149   $id = "app-cf-on"; // The context to be included
150
151   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
152
153   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
154   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
155   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
156   $ext->add($id, $c, '', new ext_playback('call-fwd-unconditional'));
157   $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
158   $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
159   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
160   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
161   $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
162   $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
163   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
164   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
165   $ext->add($id, $c, '', new ext_setvar('DB(CF/${fromext})', '${toext}'));
166   if ($amp_conf['USEDEVSTATE']) {
167     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
168     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
169   }
170   if ($amp_conf['FCBEEPONLY']) {
171     $ext->add($id, $c, 'hook_1', new ext_playback('beep')); // $cmd,n,Playback(...)
172   } else {
173     $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&for&extension'));
174     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
175     $ext->add($id, $c, '', new ext_playback('is-set-to'));
176     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
177   }
178   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
179
180   $clen = strlen($c);
181   $c = "_$c.";
182   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
183   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
184   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
185   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
186   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
187   $ext->add($id, $c, '', new ext_setvar('DB(CF/${fromext})', '${toext}'));
188   if ($amp_conf['USEDEVSTATE']) {
189     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
190     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
191   }
192   if ($amp_conf['FCBEEPONLY']) {
193     $ext->add($id, $c, 'hook_2', new ext_playback('beep')); // $cmd,n,Playback(...)
194   } else {
195     $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-unconditional&for&extension'));
196     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
197     $ext->add($id, $c, '', new ext_playback('is-set-to'));
198     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
199   }
200   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
201
202   if ($amp_conf['USEDEVSTATE']) {
203     $c = 'sstate';
204     $ext->add($id, $c, '', new ext_setvar($DEVSTATE.'(Custom:CF${fromext})', '${STATE}'));
205     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
206     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
207     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
208     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
209     $ext->add($id, $c, 'begin', new ext_setvar($DEVSTATE.'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
210     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
211     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
212     $ext->add($id, $c, 'return', new ext_return());
213   }
214 }
215
216 function callforward_cfoff_any($c) {
217   global $ext;
218   global $amp_conf;
219   global $DEVSTATE;
220
221   $id = "app-cf-off-any"; // The context to be included
222
223   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
224
225   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
226   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
227   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
228   $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
229   $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
230   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
231   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
232   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
233   if ($amp_conf['USEDEVSTATE']) {
234     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
235     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
236   }
237   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&for&extension'));
238   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
239   $ext->add($id, $c, '', new ext_playback('cancelled'));
240   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
241
242   if ($amp_conf['USEDEVSTATE']) {
243     $c = 'sstate';
244     $ext->add($id, $c, '', new ext_setvar($DEVSTATE.'(Custom:CF${fromext})', '${STATE}'));
245     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
246     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
247     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
248     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
249     $ext->add($id, $c, 'begin', new ext_setvar($DEVSTATE.'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
250     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
251     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
252     $ext->add($id, $c, 'return', new ext_return());
253   }
254 }
255
256 function callforward_cfoff($c) {
257   global $ext;
258   global $amp_conf;
259   global $DEVSTATE;
260
261   $id = "app-cf-off"; // The context to be included
262
263   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
264
265   // for this extension
266   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
267   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
268   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
269   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
270   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
271   if ($amp_conf['USEDEVSTATE']) {
272     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
273     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
274   }
275   if ($amp_conf['FCBEEPONLY']) {
276     $ext->add($id, $c, 'hook_1', new ext_playback('beep')); // $cmd,n,Playback(...)
277   } else {
278     $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&de-activated')); // $cmd,n,Playback(...)
279   }
280   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
281
282   // for any extension, dial *XX<exten>
283   $clen = strlen($c);
284   $c = "_$c.";
285   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
286   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
287   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
288   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
289   if ($amp_conf['USEDEVSTATE']) {
290     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
291     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
292   }
293   if ($amp_conf['FCBEEPONLY']) {
294     $ext->add($id, $c, 'hook_2', new ext_playback('beep')); // $cmd,n,Playback(...)
295   } else {
296     $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-unconditional&for&extension'));
297     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
298     $ext->add($id, $c, '', new ext_playback('cancelled'));
299   }
300   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
301
302   if ($amp_conf['USEDEVSTATE']) {
303     $c = 'sstate';
304     $ext->add($id, $c, '', new ext_setvar($DEVSTATE.'(Custom:CF${fromext})', '${STATE}'));
305     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
306     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
307     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
308     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
309     $ext->add($id, $c, 'begin', new ext_setvar($DEVSTATE.'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
310     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
311     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
312     $ext->add($id, $c, 'return', new ext_return());
313   }
314 }
315
316 // Call Forward on Busy
317 function callforward_cfbon($c) {
318   global $ext;
319
320   $id = "app-cf-busy-on"; // The context to be included
321
322   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
323
324   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
325   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
326   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
327   $ext->add($id, $c, '', new ext_playback('call-fwd-on-busy'));
328   $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
329   $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
330   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
331   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
332   $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
333   $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
334   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
335   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
336   $ext->add($id, $c, '', new ext_setvar('DB(CFB/${fromext})', '${toext}'));
337   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&for&extension'));
338   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
339   $ext->add($id, $c, '', new ext_playback('is-set-to'));
340   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
341   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
342
343   $clen = strlen($c);
344   $c = "_$c.";
345   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
346   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
347   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
348   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
349   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
350   $ext->add($id, $c, '', new ext_setvar('DB(CFB/${fromext})', '${toext}'));
351   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-on-busy&for&extension'));
352   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
353   $ext->add($id, $c, '', new ext_playback('is-set-to'));
354   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
355   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
356 }
357
358 function callforward_cfboff_any($c) {
359   global $ext;
360
361   $id = "app-cf-busy-off-any"; // The context to be included
362
363   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
364
365   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
366   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
367   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
368   $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
369   $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
370   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
371   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
372   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
373   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&for&extension'));
374   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
375   $ext->add($id, $c, '', new ext_playback('cancelled'));
376   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
377 }
378
379 function callforward_cfboff($c) {
380   global $ext;
381
382   $id = "app-cf-busy-off"; // The context to be included
383
384   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
385
386   // for this extension
387   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
388   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
389   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
390   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
391   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
392   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&de-activated')); // $cmd,n,Playback(...)
393   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
394
395   // for any extension, dial *XX<exten>
396   $clen = strlen($c);
397   $c = "_$c.";
398   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
399   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
400   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
401   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
402   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-on-busy&for&extension'));
403   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
404   $ext->add($id, $c, '', new ext_playback('cancelled'));
405   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
406  
407 }
408
409 // Call Forward on No Answer/Unavailable (i.e. phone not registered)
410 function callforward_cfuon($c) {
411   global $ext;
412
413   $id = "app-cf-unavailable-on"; // The context to be included
414
415   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
416
417   // prompt for extension
418   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
419   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
420   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
421   $ext->add($id, $c, '', new ext_playback('call-fwd-no-ans'));
422   $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
423   $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
424   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
425   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
426   $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
427   $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
428   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
429   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
430   $ext->add($id, $c, '', new ext_setvar('DB(CFU/${fromext})', '${toext}'));
431   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-no-ans&for&extension'));
432   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
433   $ext->add($id, $c, '', new ext_playback('is-set-to'));
434   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
435   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
436
437   // assume this extension and forward to number after the feature code
438   $clen = strlen($c);
439   $c = "_$c.";
440   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
441   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
442   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
443   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
444   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
445   $ext->add($id, $c, '', new ext_setvar('DB(CFU/${fromext})', '${toext}'));
446   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-no-ans&for&extension'));
447   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
448   $ext->add($id, $c, '', new ext_playback('is-set-to'));
449   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
450   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
451 }
452
453 function callforward_cfuoff($c) {
454   global $ext;
455
456   $id = "app-cf-unavailable-off"; // The context to be included
457
458   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
459
460   // for this extension
461   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
462   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
463   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
464   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
465   $ext->add($id, $c, '', new ext_dbdel('CFU/${fromext}'));
466   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-no-ans&de-activated')); // $cmd,n,Playback(...)
467   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
468
469   // for any extension, dial *XX<exten>
470   $clen = strlen($c);
471   $c = "_$c.";
472   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
473   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
474   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
475   $ext->add($id, $c, '', new ext_dbdel('CFU/${fromext}'));
476   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-no-ans&for&extension'));
477   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
478   $ext->add($id, $c, '', new ext_playback('cancelled'));
479   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
480 }
481
482 ?>
Note: See TracBrowser for help on using the browser.