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

Revision 14223, 25.8 kB (checked in by GameGamer43, 11 months ago)

adds getters and setters for callforward, not currently used anywhere but should be used in the future for things like ARI, etc

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2 if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
3 //This file is part of FreePBX.
4 //
5 //    FreePBX is free software: you can redistribute it and/or modify
6 //    it under the terms of the GNU General Public License as published by
7 //    the Free Software Foundation, either version 2 of the License, or
8 //    (at your option) any later version.
9 //
10 //    FreePBX is distributed in the hope that it will be useful,
11 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //    GNU General Public License for more details.
14 //
15 //    You should have received a copy of the GNU General Public License
16 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Copyright (C) 2005 qldrob
19 function callforward_get_config($engine) {
20   $modulename = 'callforward';
21  
22   // This generates the dialplan
23   global $ext; 
24   global $amp_conf; 
25   global $version;
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       if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
34         foreach($featurelist as $item) {
35           $featurename = $item['featurename'];
36           $fname = $modulename.'_'.$featurename;
37           if (function_exists($fname)) {
38             $fcc = new featurecode($modulename, $featurename);
39             $fc = $fcc->getCodeActive();
40             unset($fcc);
41             
42             if ($fc != '')
43               $fname($fc);
44           } else {
45             $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
46             var_dump($item);
47           }
48         }
49       }
50
51       // Create hints context for CF codes so a device can subscribe to the DND state
52       //
53       $fcc = new featurecode($modulename, 'cf_toggle');
54       $cf_code = $fcc->getCodeActive();
55       unset($fcc);
56
57       if ($amp_conf['USEDEVSTATE'] && $cf_code != '') {
58         $ext->addInclude('from-internal-additional','ext-cf-hints');
59         $contextname = 'ext-cf-hints';
60         $device_list = core_devices_list("all", 'full', true);
61         $base_offset = strlen($cf_code);
62         foreach ($device_list as $device) {
63           if ($device['tech'] == 'sip' || $device['tech'] == 'iax2') {
64             $offset = $base_offset + strlen($device['id']);
65             $ext->add($contextname, $cf_code.$device['id'], '', new ext_goto("1",$cf_code,"app-cf-toggle"));
66             $ext->add($contextname, '_'.$cf_code.$device['id'].'.', '', new ext_set("toext",'${EXTEN:'.$offset.'}'));
67             $ext->add($contextname, '_'.$cf_code.$device['id'].'.', '', new ext_goto("setdirect",$cf_code,"app-cf-toggle"));
68             $ext->addHint($contextname, $cf_code.$device['id'], "Custom:DEVCF".$device['id']);
69           }
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 $version;
82   $ast_ge_16 = version_compare($version, "1.6", "ge");
83
84   $id = "app-cf-toggle"; // The context to be included
85
86   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
87
88   $ext->add($id, $c, '', new ext_answer(''));
89   $ext->add($id, $c, '', new ext_wait('1'));
90   $ext->add($id, $c, '', new ext_macro('user-callerid'));
91   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
92
93   $ext->add($id, $c, '', new ext_gotoif('$["${DB(CF/${fromext})}" = ""]', 'activate', 'deactivate'));
94
95   if ($ast_ge_16) {
96     $ext->add($id, $c, 'activate', new ext_read('toext', 'ent-target-attendant&then-press-pound'));
97   } else {
98     $ext->add($id, $c, 'activate', new ext_playback('ent-target-attendant'));
99     $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
100   }
101   $ext->add($id, $c, '', new ext_gotoif('$["${toext}"=""]', 'activate'));
102   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
103   $ext->add($id, $c, 'toext', new ext_setvar('DB(CF/${fromext})', '${toext}'));
104   if ($amp_conf['USEDEVSTATE']) {
105     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
106     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
107   }
108   if ($amp_conf['FCBEEPONLY']) {
109     $ext->add($id, $c, 'hook_on', new ext_playback('beep')); // $cmd,n,Playback(...)
110   } else {
111     $ext->add($id, $c, 'hook_on', new ext_playback('call-fwd-unconditional&for&extension'));
112     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
113     $ext->add($id, $c, '', new ext_playback('is-set-to'));
114     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
115   }
116   $ext->add($id, $c, '', new ext_macro('hangupcall'));
117   $ext->add($id, $c, 'setdirect', new ext_answer(''));
118   $ext->add($id, $c, '', new ext_wait('1'));
119   $ext->add($id, $c, '', new ext_macro('user-callerid'));
120   $ext->add($id, $c, '', new ext_goto('toext'));
121
122   $ext->add($id, $c, 'deactivate', new ext_dbdel('CF/${fromext}'));
123   if ($amp_conf['USEDEVSTATE']) {
124     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
125     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
126   }
127   if ($amp_conf['FCBEEPONLY']) {
128     $ext->add($id, $c, 'hook_off', new ext_playback('beep')); // $cmd,n,Playback(...)
129   } else {
130     $ext->add($id, $c, 'hook_off', new ext_playback('call-fwd-unconditional&de-activated')); // $cmd,n,Playback(...)
131   }
132   $ext->add($id, $c, '', new ext_macro('hangupcall'));
133
134   if ($amp_conf['USEDEVSTATE']) {
135     $c = 'sstate';
136     $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:CF${fromext})', '${STATE}'));
137     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
138     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
139     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
140     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
141     $ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
142     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
143     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
144     $ext->add($id, $c, 'return', new ext_return());
145   }
146 }
147
148 // Unconditional Call Forwarding
149 function callforward_cfon($c) {
150   global $ext;
151   global $amp_conf;
152   global $version;
153   $ast_ge_16 = version_compare($version, "1.6", "ge");
154
155   $id = "app-cf-on"; // The context to be included
156
157   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
158
159   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
160   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
161   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
162
163   if ($ast_ge_16) {
164     $ext->add($id, $c, '', new ext_read('fromext', 'call-fwd-unconditional&please-enter-your&extension&then-press-pound'));
165   } else {
166     $ext->add($id, $c, '', new ext_playback('call-fwd-unconditional'));
167     $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
168     $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
169   }
170   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
171   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
172
173   if ($ast_ge_16) {
174     $ext->add($id, $c, 'startread', new ext_read('toext', 'ent-target-attendant&then-press-pound'));
175   } else {
176     $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
177     $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
178   }
179   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
180   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
181   $ext->add($id, $c, '', new ext_setvar('DB(CF/${fromext})', '${toext}'));
182   if ($amp_conf['USEDEVSTATE']) {
183     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
184     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
185   }
186   if ($amp_conf['FCBEEPONLY']) {
187     $ext->add($id, $c, 'hook_1', new ext_playback('beep')); // $cmd,n,Playback(...)
188   } else {
189     $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&for&extension'));
190     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
191     $ext->add($id, $c, '', new ext_playback('is-set-to'));
192     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
193   }
194   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
195
196   $clen = strlen($c);
197   $c = "_$c.";
198   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
199   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
200   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
201   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
202   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
203   $ext->add($id, $c, '', new ext_setvar('DB(CF/${fromext})', '${toext}'));
204   if ($amp_conf['USEDEVSTATE']) {
205     $ext->add($id, $c, '', new ext_setvar('STATE', 'BUSY'));
206     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
207   }
208   if ($amp_conf['FCBEEPONLY']) {
209     $ext->add($id, $c, 'hook_2', new ext_playback('beep')); // $cmd,n,Playback(...)
210   } else {
211     $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-unconditional&for&extension'));
212     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
213     $ext->add($id, $c, '', new ext_playback('is-set-to'));
214     $ext->add($id, $c, '', new ext_saydigits('${toext}'));
215   }
216   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
217
218   if ($amp_conf['USEDEVSTATE']) {
219     $c = 'sstate';
220     $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:CF${fromext})', '${STATE}'));
221     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
222     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
223     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
224     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
225     $ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
226     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
227     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
228     $ext->add($id, $c, 'return', new ext_return());
229   }
230 }
231
232 function callforward_cfoff_any($c) {
233   global $ext;
234   global $amp_conf;
235   global $version;
236   $ast_ge_16 = version_compare($version, "1.6", "ge");
237
238   $id = "app-cf-off-any"; // The context to be included
239
240   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
241
242   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
243   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
244   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
245
246   if ($ast_ge_16) {
247     $ext->add($id, $c, '', new ext_read('fromext', 'please-enter-your&extension&then-press-pound'));
248   } else {
249     $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
250     $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
251   }
252   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
253   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
254   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
255   if ($amp_conf['USEDEVSTATE']) {
256     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
257     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
258   }
259   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&for&extension'));
260   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
261   $ext->add($id, $c, '', new ext_playback('cancelled'));
262   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
263
264   if ($amp_conf['USEDEVSTATE']) {
265     $c = 'sstate';
266     $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:CF${fromext})', '${STATE}'));
267     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
268     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
269     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
270     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
271     $ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
272     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
273     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
274     $ext->add($id, $c, 'return', new ext_return());
275   }
276 }
277
278 function callforward_cfoff($c) {
279   global $ext;
280   global $amp_conf;
281
282   $id = "app-cf-off"; // The context to be included
283
284   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
285
286   // for this extension
287   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
288   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
289   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
290   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
291   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
292   if ($amp_conf['USEDEVSTATE']) {
293     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
294     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
295   }
296   if ($amp_conf['FCBEEPONLY']) {
297     $ext->add($id, $c, 'hook_1', new ext_playback('beep')); // $cmd,n,Playback(...)
298   } else {
299     $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-unconditional&de-activated')); // $cmd,n,Playback(...)
300   }
301   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
302
303   // for any extension, dial *XX<exten>
304   $clen = strlen($c);
305   $c = "_$c.";
306   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
307   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
308   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
309   $ext->add($id, $c, '', new ext_dbdel('CF/${fromext}'));
310   if ($amp_conf['USEDEVSTATE']) {
311     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
312     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
313   }
314   if ($amp_conf['FCBEEPONLY']) {
315     $ext->add($id, $c, 'hook_2', new ext_playback('beep')); // $cmd,n,Playback(...)
316   } else {
317     $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-unconditional&for&extension'));
318     $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
319     $ext->add($id, $c, '', new ext_playback('cancelled'));
320   }
321   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
322
323   if ($amp_conf['USEDEVSTATE']) {
324     $c = 'sstate';
325     $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:CF${fromext})', '${STATE}'));
326     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${fromext}/device'));
327     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
328     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
329     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
330     $ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:DEVCF${CUT(DEVICES,&,${ITER})})','${STATE}'));
331     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
332     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
333     $ext->add($id, $c, 'return', new ext_return());
334   }
335 }
336
337 // Call Forward on Busy
338 function callforward_cfbon($c) {
339   global $ext;
340   global $version;
341   global $amp_conf;
342   $ast_ge_16 = version_compare($version, "1.6", "ge");
343
344   $id = "app-cf-busy-on"; // The context to be included
345
346   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
347
348   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
349   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
350   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
351   if ($ast_ge_16) {
352     $ext->add($id, $c, '', new ext_read('fromext', 'call-fwd-on-busy&please-enter-your&extension&then-press-pound'));
353   } else {
354     $ext->add($id, $c, '', new ext_playback('call-fwd-on-busy'));
355     $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
356     $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
357   }
358   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
359   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
360   if ($ast_ge_16) {
361     $ext->add($id, $c, 'startread', new ext_read('toext', 'ent-target-attendant&then-press-pound'));
362   } else {
363     $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
364     $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
365   }
366   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
367   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
368   $ext->add($id, $c, '', new ext_setvar('DB(CFB/${fromext})', '${toext}'));
369   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&for&extension'));
370   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
371   $ext->add($id, $c, '', new ext_playback('is-set-to'));
372   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
373   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
374
375   $clen = strlen($c);
376   $c = "_$c.";
377   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
378   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
379   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
380   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
381   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
382   $ext->add($id, $c, '', new ext_setvar('DB(CFB/${fromext})', '${toext}'));
383   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-on-busy&for&extension'));
384   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
385   $ext->add($id, $c, '', new ext_playback('is-set-to'));
386   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
387   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
388 }
389
390 function callforward_cfboff_any($c) {
391   global $ext;
392   global $version;
393   global $amp_conf;
394   $ast_ge_16 = version_compare($version, "1.6", "ge");
395
396   $id = "app-cf-busy-off-any"; // The context to be included
397
398   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
399
400   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
401   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
402   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
403   if ($ast_ge_16) {
404     $ext->add($id, $c, '', new ext_read('fromext', 'please-enter-your&extension&then-press-pound'));
405   } else {
406     $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
407     $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
408   }
409   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
410   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
411   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
412   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&for&extension'));
413   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
414   $ext->add($id, $c, '', new ext_playback('cancelled'));
415   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
416 }
417
418 function callforward_cfboff($c) {
419   global $ext;
420   global $amp_conf;
421
422   $id = "app-cf-busy-off"; // The context to be included
423
424   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
425
426   // for this extension
427   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
428   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
429   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
430   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
431   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
432   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-on-busy&de-activated')); // $cmd,n,Playback(...)
433   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
434
435   // for any extension, dial *XX<exten>
436   $clen = strlen($c);
437   $c = "_$c.";
438   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
439   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
440   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
441   $ext->add($id, $c, '', new ext_dbdel('CFB/${fromext}'));
442   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-on-busy&for&extension'));
443   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
444   $ext->add($id, $c, '', new ext_playback('cancelled'));
445   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
446  
447 }
448
449 // Call Forward on No Answer/Unavailable (i.e. phone not registered)
450 function callforward_cfuon($c) {
451   global $ext;
452   global $version;
453   global $amp_conf;
454   $ast_ge_16 = version_compare($version, "1.6", "ge");
455
456   $id = "app-cf-unavailable-on"; // The context to be included
457
458   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
459
460   // prompt for 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   if ($ast_ge_16) {
465     $ext->add($id, $c, '', new ext_read('fromext', 'call-fwd-no-ans&please-enter-your&extension&then-press-pound'));
466   } else {
467     $ext->add($id, $c, '', new ext_playback('call-fwd-no-ans'));
468     $ext->add($id, $c, '', new ext_playback('please-enter-your&extension'));
469     $ext->add($id, $c, '', new ext_read('fromext', 'then-press-pound'));
470   }
471   $ext->add($id, $c, '', new ext_setvar('fromext', '${IF($["foo${fromext}"="foo"]?${AMPUSER}:${fromext})}'));
472   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
473   if ($ast_ge_16) {
474     $ext->add($id, $c, 'startread', new ext_read('toext', 'ent-target-attendant&then-press-pound'));
475   } else {
476     $ext->add($id, $c, 'startread', new ext_playback('ent-target-attendant'));
477     $ext->add($id, $c, '', new ext_read('toext', 'then-press-pound'));
478   }
479   $ext->add($id, $c, '', new ext_gotoif('$["foo${toext}"="foo"]', 'startread'));
480   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
481   $ext->add($id, $c, '', new ext_setvar('DB(CFU/${fromext})', '${toext}'));
482   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-no-ans&for&extension'));
483   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
484   $ext->add($id, $c, '', new ext_playback('is-set-to'));
485   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
486   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
487
488   // assume this extension and forward to number after the feature code
489   $clen = strlen($c);
490   $c = "_$c.";
491   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
492   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
493   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
494   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
495   $ext->add($id, $c, '', new ext_setvar('toext', '${EXTEN:'.$clen.'}'));
496   $ext->add($id, $c, '', new ext_setvar('DB(CFU/${fromext})', '${toext}'));
497   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-no-ans&for&extension'));
498   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
499   $ext->add($id, $c, '', new ext_playback('is-set-to'));
500   $ext->add($id, $c, '', new ext_saydigits('${toext}'));
501   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
502 }
503
504 function callforward_cfuoff($c) {
505   global $ext;
506   global $amp_conf;
507
508   $id = "app-cf-unavailable-off"; // The context to be included
509
510   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
511
512   // for this extension
513   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
514   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
515   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
516   $ext->add($id, $c, '', new ext_setvar('fromext', '${AMPUSER}'));
517   $ext->add($id, $c, '', new ext_dbdel('CFU/${fromext}'));
518   $ext->add($id, $c, 'hook_1', new ext_playback('call-fwd-no-ans&de-activated')); // $cmd,n,Playback(...)
519   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
520
521   // for any extension, dial *XX<exten>
522   $clen = strlen($c);
523   $c = "_$c.";
524   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
525   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
526   $ext->add($id, $c, '', new ext_setvar('fromext', '${EXTEN:'.$clen.'}'));
527   $ext->add($id, $c, '', new ext_dbdel('CFU/${fromext}'));
528   $ext->add($id, $c, 'hook_2', new ext_playback('call-fwd-no-ans&for&extension'));
529   $ext->add($id, $c, '', new ext_saydigits('${fromext}'));
530   $ext->add($id, $c, '', new ext_playback('cancelled'));
531   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
532 }
533
534 function callforward_get_extension($extension = '') {
535   global $astman;
536  
537   $cf_type = array('CF','CFU','CFB');
538   $users = array();
539  
540         foreach ($cf_type as $value) {
541     if ($extension) {
542       $users[$value] = $astman->database_get($value, $extension);
543     } else {
544                         $users[] = $astman->database_show($value);
545     }
546   }
547         
548   return $users;
549 }
550
551 function callforward_get_number($extension = '', $type = 'CF') {
552   global $astman;
553
554    switch ($type) {
555                 case 'CFU':
556                         $cf_type = 'CFU';
557                 break;
558                 case 'CFB':
559                         $cf_type = 'CFB';
560                 break;
561                 case 'CF':
562                 default:
563             $cf_type = 'CF';
564     break;
565         }
566  
567   $number = $astman->database_get($cf_type, $extension);
568   if (is_numeric($number)) {
569     return $number;
570   }
571 }
572
573 function callforward_set_number($extension, $number, $type = "CF") {
574   global $astman;
575
576   switch ($type) {
577     case 'CFU':
578       $cf_type = 'CFU';
579     break;
580     case 'CFB':
581       $cf_type = 'CFB';
582     break;
583     case 'CF':
584     default:
585       $cf_type = 'CF';
586     break;
587   }
588
589   return $astman->database_put($cf_type, $extension, $number);
590 }
591
592 function callforward_set_ringtimer($extension, $ringtimer = 0) {
593   global $astman;
594
595   if ($ringtimer > 120) {
596     $ringtimer = 120;
597   } else if ($ringtimer < -1) {
598     $ringtimer = -1;
599   }
600
601   return $astman->database_put("AMPUSER", $extension . '/cfringtimer', $ringtimer);
602 }
603
604 function callforward_get_ringtimer($extension) {
605   global $astman;
606
607   return $astman->database_get('AMPUSER', $extension . '/cfringtimer');
608 }
609 ?>
Note: See TracBrowser for help on using the browser.