-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfunctions.inc.php
557 lines (496 loc) · 22.6 KB
/
functions.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2013 Schmooze Com Inc.
//
/* $Id$ */
// The destinations this module provides
// returns a associative arrays with keys 'destination' and 'description'
function ivr_destinations() {
global $module_page;
//get the list of IVR's
$results = ivr_get_details();
// return an associative array with destination and description
if (isset($results)) {
foreach($results as $result){
$name = $result['name'] ? $result['name'] : 'IVR ' . $result['id'];
$extens[] = array('destination' => 'ivr-'.$result['id'].',s,1', 'description' => $name);
}
}
if (isset($extens)) {
return $extens;
} else {
return null;
}
}
//dialplan generator
function ivr_get_config($engine) {
global $ext;
switch($engine) {
case "asterisk":
//FREEPBX-17112 Return to IVR after VM broken
$ext->splice('macro-vm','exit-RETURN', 1, new ext_gotoif('$["${RETVM}" = "RETURN"]','ext-local,vmret,1'));
$ddial_contexts = array();
$ivrlist = ivr_get_details();
if(!is_array($ivrlist)) {
break;
}
//FREEPBX-14431
$ext->splice('macro-dial-one','s', 'dial', new ext_execif('$["${ivrreturn}" = "1"]', 'Set', 'D_OPTIONS=${D_OPTIONS}g'));
// splice into macro-dial-one
$ext->splice('macro-dial-one','s-ANSWER','bye', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
$ext->splice('macro-dial-one','s-CHANUNAVAIL','return', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
$ext->splice('macro-dial-one','s-NOANSWER','return', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
$ext->splice('macro-dial-one','s-BUSY','return', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
//splice into macro dial
$ext->splice('macro-dial','s','nddialapp', new ext_execif('$["${ivrreturn}" = "1"]', 'Set', 'ds=${ds}g'));
$ext->splice('macro-dial','s','hsdialapp', new ext_execif('$["${ivrreturn}" = "1"]', 'Set', 'ds=${ds}g'));
$ext->splice('macro-dial','ANSWER','bye', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
$ext->splice('macro-dial','NOANSWER','bye', new ext_gotoif('$["${ivrreturn}" = "1"]','${IVR_CONTEXT},return,1'));
// splice into from-did-direct-ivr to strip off trailing # as needed
$ext->splice('from-did-direct-ivr', '_.', 0, new ext_gotoif('$["${IVR_ACCEPT_POUND}" = "1" & "${EXTEN:-1:1}" = "#"]', 'from-did-direct-ivr,${EXTEN:0:-1},1'));
if (function_exists('queues_list')) {
//draw a list of ivrs included by any queues
$queues = queues_list(true);
$qivr = array();
foreach ($queues as $q) {
$thisq = queues_get($q[0]);
if ($thisq['context'] && strpos($thisq['context'], 'ivr-') === 0) {
$qivr[] = str_replace('ivr-', '', $thisq['context']);
}
}
}
foreach($ivrlist as $ivr) {
$c = 'ivr-' . $ivr['id'];
$ivr = ivr_get_details($ivr['id']);
$ext->addSectionComment($c, $ivr['name'] ? $ivr['name'] : 'IVR ' . $ivr['id']);
if ($ivr['directdial']) {
if ($ivr['directdial'] != 'ext-local') {
//generated by directory
$ext->addInclude($c, 'from-ivr-directory-' . $ivr['directdial']);
$directdial_contexts[$ivr['directdial']] = $ivr['directdial'];
}
}
//set variables for loops when used
if ($ivr['timeout_loops'] != 'disabled' && $ivr['timeout_loops'] > 0) {
$ext->add($c, 's', '', new ext_setvar('TIMEOUT_LOOPCOUNT', 0));
}
if ($ivr['invalid_loops'] != 'disabled' && $ivr['invalid_loops'] > 0) {
$ext->add($c, 's', '', new ext_setvar('INVALID_LOOPCOUNT', 0));
}
$ext->add($c, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}'));
$ext->add($c, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
if ($ivr['retvm']) {
$ext->add($c, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN'));
} else {
//TODO: do we need to set anything at all?
$ext->add($c, 's', '', new ext_setvar('__IVR_RETVM', ''));
}
if ($ivr['alertinfo'] != '') {
$ext->add($c, 's', '', new ext_setvar('__ALERT_INFO', str_replace(';', '\;', $ivr['alertinfo'])));
}
if (!empty($ivr['rvolume'])) {
$ext->add($c, 's', '', new ext_setvar("__RVOL", $ivr['rvolume']));
}
$ext->add($c, 's', '', new ext_setvar("__IVR_ACCEPT_POUND", (isset($ivr['accept_pound_key']) && $ivr['accept_pound_key']) ? 1 : 0));
$ext->add($c, 's', '', new ext_gotoif('$["${CHANNEL(state)}" = "Up"]','skip'));
$ext->add($c, 's', '', new ext_answer(''));
$ivr_announcement = recordings_get_file($ivr['announcement']);
$ext->add($c, 's', 'skip', new ext_set('IVR_MSG', $ivr_announcement));
switch($ivr['strict_dial_timeout']) {
case "0": //force strict dial timeout :: no
$ext->add($c, 's', 'start', new ext_setvar("DIGITS",""));
$ext->add($c, 's', '', new ext_setvar("IVREXT",""));
$ext->add($c, 's', '', new ext_setvar("NODEFOUND","0"));
$ext->add($c, 's', '', new ext_setvar("LOCALEXT","0"));
$ext->add($c, 's', '', new ext_setvar("DIREXT","0"));
$ext->add($c, 's', 'beforewhile', new ext_execif('$["${IVREXT}" != ""]', 'Set', 'DIGITS=${DIGITS}${IVREXT}'));
$ext->add($c, 's', '', new ext_while('$["${NODEFOUND}" = "0"] '));
$ext->add($c, 's', '', new ext_read('IVREXT', '${IVR_MSG}', '1', '', '0', $ivr['timeout_time']));
$ext->add($c, 's', '', new ext_set('IVR_MSG', ''));
$ext->add($c, 's', '', new ext_gotoif('$["${READSTATUS}" = "OK" & "${IVREXT}" = ""]','#,1'));
$ext->add($c, 's', '', new ext_gotoif('$["${READSTATUS}" = "TIMEOUT" & "${DIGITS}" != ""]','i,1'));
$ext->add($c, 's', '', new ext_gotoif('$["${READSTATUS}" = "TIMEOUT" & "${IVREXT}" = ""]','t,1'));
$ext->add($c, 's', '', new ext_noop('${DB(DEVICE/${DIGITS}${IVREXT}/user)}'));
if ($ivr['directdial']!= "" && $ivr['directdial'] !="Disabled" ) {
if ($ivr['directdial'] == 'ext-local') {
$ext->add($c, 's', '', new ext_execif('$["${DB(DEVICE/${DIGITS}${IVREXT}/user)}" != ""]', 'Set', 'LOCALEXT=1'));
$ext->add($c, 's', '', new ext_gotoif('$["${LOCALEXT}" = "1"]','from-did-direct-ivr,${DIGITS}${IVREXT},1'));
$ext->add($c, 's', '', new ext_noop('${CONTEXT}${DIGITS},${IVREXT},1'));
$ext->add($c, 's', '', new ext_execif('$["${DIALPLAN_EXISTS(${CONTEXT},${DIGITS}${IVREXT},1)}" != "0"]', 'Set', 'NODEFOUND=1'));
$ext->add($c, 's', '', new ext_gotoif('$["${NODEFOUND}" = "0"]','beforewhile:nodedial'));
} else {// this should be a ivr node or directory exten
$ext->add($c, 's', '', new ext_execif('"${DIALPLAN_EXISTS(from-ivr-directory-' . $ivr['directdial'].',${DIGITS}${IVREXT},1)}" != "0"]', 'Set', 'DIREXT=1'));
$ext->add($c, 's', '', new ext_execif('$["${DIALPLAN_EXISTS(${CONTEXT},${DIGITS}${IVREXT},1)}" != "0"]', 'Set', 'NODEFOUND=1'));
$ext->add($c, 's', '', new ext_gotoif('$["${NODEFOUND}" = "0"]','beforewhile:nodedial'));
}
}else {
$ext->add($c, 's', '', new ext_gotoif('$["${DIALPLAN_EXISTS(${CONTEXT},${DIGITS}${IVREXT},1)}" = "0"]','beforewhile:nodedial'));
}
$ext->add($c, 's', '', new ext_endwhile(''));
$ext->add($c, 's', '', new ext_gotoif('$["${DIALPLAN_EXISTS(${CONTEXT},${DIGITS},1)}" = "0"]','i,1'));
$ext->add($c, 's', 'nodedial', new ext_goto('${DIGITS}${IVREXT},1'));
break;
case "1": //force strict dial timeout :: yes
$ext->add($c, 's', 'start', new ext_digittimeout($ivr['timeout_time']));
$ext->add($c, 's', '', new ext_read('IVREXT', '${IVR_MSG}', '', '', '0', $ivr['timeout_time']));
$ext->add($c, 's', '', new ext_gotoif('$["${READSTATUS}" = "OK" & "${IVREXT}" = ""]','#,1'));
$ext->add($c, 's', '', new ext_gotoif('$["${READSTATUS}" = "TIMEOUT" & "${IVREXT}" = ""]','t,1'));
if ($ivr['directdial']) {
if ($ivr['directdial'] == 'ext-local') {
$ext->add($c, 's', '', new ext_execif('$["${DB(DEVICE/${IVREXT}/user)}" != ""]', 'Set', 'LOCALEXT=1'));
$ext->add($c, 's', '', new ext_gotoif('$["${DIALPLAN_EXISTS(${CONTEXT},${IVREXT},1)}" = "0" & "${DIALPLAN_EXISTS(from-did-direct-ivr,${IVREXT},1)}" = "0"]','i,1'));
} else {
//generated by directory
$ext->add($c, 's', '', new ext_gotoif('$["${DIALPLAN_EXISTS(${CONTEXT},${IVREXT},1)}" = "0" & "${DIALPLAN_EXISTS(from-ivr-directory-' . $ivr['directdial'].',${IVREXT},1)}" = "0"]','i,1'));
}
} else {
$ext->add($c, 's', '', new ext_gotoif('$["${DIALPLAN_EXISTS(${CONTEXT},${IVREXT},1)}" = "0"]','i,1'));
}
$ext->add($c, 's', '', new ext_gotoif('$["${LOCALEXT}" = "1"]','from-did-direct-ivr,${IVREXT},1'));
$ext->add($c, 's', '', new ext_goto('${IVREXT},1'));
break;
case "2": //force strict dial timeout :: instant
if ($ivr['directdial'] != "" && $ivr['directdial'] == "ext-local" ) {
$ext->addInclude($c, 'from-did-direct-ivr'); //generated in core module
}
$ext->add($c, 's', 'start', new ext_digittimeout(3));
$ext->add($c, 's', '', new ext_execif('$["${IVR_MSG}" != ""]','Background','${IVR_MSG}'));
$ext->add($c, 's', '', new ext_waitexten($ivr['timeout_time']));
break;
}
// Actually add the IVR entires now
$entries = ivr_get_entries($ivr['id']);
if ($entries) {
foreach($entries as $e) {
//dont set a t or i if there already defined above
if ($e['selection'] == 't' && $ivr['timeout_loops'] != 'disabled') {
continue;
}
if ($e['selection'] == 'i' && $ivr['invalid_loops'] != 'disabled') {
continue;
}
// for entries ending with a # just trim it off
if (isset($ivr['accept_pound_key']) && $ivr['accept_pound_key']) {
$ext->add($c, $e['selection'] . '#', '', new ext_goto(1, $e['selection']));
}
//only display these two lines if the ivr is included in any queues
if (function_exists('queues_list') && in_array($ivr['id'], $qivr)) {
$ext->add($c, $e['selection'],'', new ext_macro('blkvm-clr'));
$ext->add($c, $e['selection'], '', new ext_setvar('__NODEST', ''));
}
if ($e['ivr_ret']) {
//FREEPBX-14431 ivr return option not working : should work for extension only.//from-did-direct,111,1
$desarray = explode(',',$e['dest']);
if ($desarray[0] == 'from-did-direct') {
$ext->add($c, $e['selection'], '', new ext_setvar('__ivrreturn', '1'));
$ext->add($c, $e['selection'], '',
new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]',
$e['dest'] . ':${IVR_CONTEXT_${CONTEXT}},return,1'));
} else {
$ext->add($c, $e['selection'], '', new ext_setvar('__ivrreturn', '0'));
$ext->add($c, $e['selection'],'ivrsel-' . $e['selection'], new ext_goto($e['dest']));
}
} else {
$ext->add($c, $e['selection'], '', new ext_setvar('__ivrreturn', '0'));
$ext->add($c, $e['selection'],'ivrsel-' . $e['selection'], new ext_goto($e['dest']));
}
}
}
// add invalid destination if required
if ($ivr['invalid_loops'] != 'disabled') {
if ($ivr['invalid_loops'] > 0) {
$ext->add($c, 'i', '', new ext_set('INVALID_LOOPCOUNT', '$[${INVALID_LOOPCOUNT}+1]'));
$ext->add($c, 'i', '', new ext_gotoif('$[${INVALID_LOOPCOUNT} > ' . $ivr['invalid_loops'] . ']','final'));
switch ($ivr['invalid_retry_recording']) {
case 'default':
$invalid_annoucement = 'no-valid-responce-pls-try-again';
break;
case '':
$invalid_annoucement = '';
break;
default:
$invalid_annoucement = recordings_get_file($ivr['invalid_retry_recording']);
break;
}
if ($ivr['invalid_append_announce'] || $invalid_annoucement == '') {
$invalid_annoucement .= '&' . $ivr_announcement;
}
$ext->add($c, 'i', '', new ext_set('IVR_MSG', trim($invalid_annoucement, '&')));
$ext->add($c, 'i', '', new ext_goto('s,start'));
}
$label = 'final';
switch ($ivr['invalid_recording']) {
case 'default':
$ext->add($c, 'i', $label, new ext_playback('no-valid-responce-transfering'));
$label ='';
break;
case '':
break;
default:
$ext->add($c, 'i', $label,
new ext_playback(recordings_get_file($ivr['invalid_recording'])));
$label = '';
break;
}
if (!empty($ivr['invalid_ivr_ret'])) {
$ext->add($c, 'i', $label,
new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]',
$ivr['invalid_destination'] . ':${IVR_CONTEXT_${CONTEXT}},return,1'));
} else {
$ext->add($c, 'i', $label, new ext_goto($ivr['invalid_destination']));
}
} else {
// If no invalid destination provided we need to do something
$ext->add($c, 'i', '', new ext_playback('sorry-youre-having-problems'));
$ext->add($c, 'i', '', new ext_goto('1','hang'));
}
// Apply timeout destination if required
if ($ivr['timeout_loops'] != 'disabled') {
if ($ivr['timeout_loops'] > 0) {
$ext->add($c, 't', '', new ext_set('TIMEOUT_LOOPCOUNT', '$[${TIMEOUT_LOOPCOUNT}+1]'));
$ext->add($c, 't', '', new ext_gotoif('$[${TIMEOUT_LOOPCOUNT} > ' . $ivr['timeout_loops'] . ']','final'));
switch ($ivr['timeout_retry_recording']) {
case 'default':
$timeout_annoucement = 'no-valid-responce-pls-try-again';
break;
case '':
$timeout_annoucement = '';
break;
default:
$timeout_annoucement = recordings_get_file($ivr['timeout_retry_recording']);
break;
}
if ($ivr['timeout_append_announce'] || $timeout_annoucement == '') {
$timeout_annoucement .= '&' . $ivr_announcement;
}
$ext->add($c, 't', '', new ext_set('IVR_MSG', trim($timeout_annoucement, '&')));
$ext->add($c, 't', '', new ext_goto('s,start'));
}
$label = 'final';
switch ($ivr['timeout_recording']) {
case 'default':
$ext->add($c, 't', $label, new ext_playback('no-valid-responce-transfering'));
$label = '';
break;
case '':
break;
default:
$ext->add($c, 't', $label,
new ext_playback(recordings_get_file($ivr['timeout_recording'])));
$label = '';
break;
}
if (!empty($ivr['timeout_ivr_ret'])) {
$ext->add($c, 't', $label,
new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]',
$ivr['timeout_destination'] . ':${IVR_CONTEXT_${CONTEXT}},return,1'));
} else {
$ext->add($c, 't', $label, new ext_goto($ivr['timeout_destination']));
}
} else {
// If no invalid destination provided we need to do something
$ext->add($c, 't', '', new ext_playback('sorry-youre-having-problems'));
$ext->add($c, 't', '', new ext_goto('1','hang'));
}
// these need to be reset or inheritance problems makes them go away in some conditions
//and infinite inheritance creates other problems
$ext->add($c, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
$ext->add($c, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}'));
$ext->add($c, 'return', '', new ext_set('IVR_MSG', $ivr_announcement));
$ext->add($c, 'return', '', new ext_goto('s,start'));
//h extension
$ext->add($c, 'h', '', new ext_hangup(''));
$ext->add($c, 'hang', '', new ext_playback('vm-goodbye'));
$ext->add($c, 'hang', '', new ext_hangup(''));
}
//generate from-ivr-directory contexts for direct dialing a directory entire
if (!empty($directdial_contexts)) {
foreach($directdial_contexts as $dir_id) {
$c = 'from-ivr-directory-' . $dir_id;
$entries = function_exists('directory_get_dir_entries') ? directory_get_dir_entries($dir_id) : array();
foreach ($entries as $dstring) {
$exten = $dstring['dial'] == '' ? $dstring['foreign_id'] : $dstring['dial'];
if ($exten == '' || $exten == 'custom') {
continue;
}
$ext->add($c, $exten, '', new ext_macro('blkvm-clr'));
$ext->add($c, $exten, '', new ext_setvar('__NODEST', ''));
$ext->add($c, $exten, '', new ext_goto('1', '${EXTEN}', 'from-internal'));
// this only gets reached with force strict dial timeout set to "no-legacy" which uses Background() instead of Read()
$ext->add($c, $exten . '#', '', new ext_gotoif('$["${IVR_ACCEPT_POUND}" = "1"]', $exten . ',1', '${IVR_CONTEXT},i,1'));
}
}
}
break;
}
}
//replaces ivr_list(), returns all details of any ivr
function ivr_get_details($id = '') {
FreePBX::Modules()->deprecatedFunction();
return FreePBX::Ivr()->getDetails($id);
}
//get all ivr entires
function ivr_get_entries($id) {
global $db;
//+0 to convert string to an integer
$sql = "SELECT * FROM ivr_entries WHERE ivr_id = ? ORDER BY selection + 0";
$res = $db->getAll($sql, array($id), DB_FETCHMODE_ASSOC);
if ($db->IsError($res)) {
die_freepbx($res->getDebugInfo());
}
return $res;
}
//save ivr settings
function ivr_save_details($vals){
FreePBX::Modules()->deprecatedFunction();
return FreePBX::Ivr()->saveDetails($vals);
}
//save ivr entires
function ivr_save_entries($id, $entries){
FreePBX::Modules()->deprecatedFunction();
return FreePBX::Ivr()->saveEntries($id,$entries);
}
//draw uvr entires table header
function ivr_draw_entries_table_header_ivr() {
return array(fpbx_label(_('Digits'),_("Digits the caller needs to dial to access said destination. Digits are limited to 10 digits.")), fpbx_label(_('Destination'),_("Choose a destination to route the call to")), fpbx_label(_('Return'), _('Return to this IVR when finished')), _('Delete'));
}
//draw actualy entires
function ivr_draw_entries($id,$restrict_mods=false){
$headers = mod_func_iterator('draw_entries_table_header_ivr');
$ivr_entries = ivr_get_entries($id);
if ($ivr_entries) {
foreach ($ivr_entries as $k => $e) {
$entries[$k]= $e;
$array = array('id' => $id, 'ext' => $e['selection']);
$entries[$k]['hooks'] = mod_func_iterator('draw_entries_ivr', $array);
}
}
$entries['blank'] = array('selection' => '', 'dest' => '', 'ivr_ret' => '0');
//assign to a vatriable first so that it can be passed by reference
$array = array('id' => '', 'ext' => '');
$entries['blank']['hooks'] = mod_func_iterator('draw_entries_ivr', $array);
return load_view(dirname(__FILE__) . '/views/entries.php',
array(
'headers' => $headers,
'entries' => $entries,
'restrict_mods' => $restrict_mods
)
);
}
//delete an ivr + entires
function ivr_delete($id) {
FreePBX::Modules()->deprecatedFunction();
return FreePBX::Ivr()->delete($id);
}
//----------------------------------------------------------------------------
// Dynamic Destination Registry and Recordings Registry Functions
function ivr_check_destinations($dest=true) {
global $active_modules;
global $db;
$destlist = array();
$destlist_option = array();
$destlist_invalid = array();
$destlist_timeout = array();
if (is_array($dest) && empty($dest)) {
return $destlist;
}
$sql = "SELECT dest, name, selection, a.id id FROM ivr_details a INNER JOIN ivr_entries d ON a.id = d.ivr_id ";
if ($dest !== true && is_array($dest)) {
$sql .= "WHERE dest in (".implode(",",array_fill(0, count($dest), "?")).")";
}
$sql .= "ORDER BY name";
$results = $db->getAll($sql, $dest, DB_FETCHMODE_ASSOC);
foreach ($results as $result) {
$thisdest = $result['dest'];
$thisid = $result['id'];
$name = $result['name'] ? $result['name'] : 'IVR ' . $thisid;
$destlist_option[] = array(
'dest' => $thisdest,
'description' => sprintf(_("IVR: %s / Option: %s"),$name,$result['selection']),
'edit_url' => 'config.php?display=ivr&action=edit&id='.urlencode($thisid),
);
}
$sql = "SELECT invalid_destination, name, id FROM ivr_details ";
if ($dest !== true && is_array($dest)) {
$sql .= "WHERE invalid_destination in (".implode(",",array_fill(0, count($dest), "?")).")";
}
$sql .= "ORDER BY name";
$results = $db->getAll($sql, $dest, DB_FETCHMODE_ASSOC);
foreach ($results as $result) {
$thisdest = $result['invalid_destination'];
$thisid = $result['id'];
$name = $result['name'] ? $result['name'] : 'IVR ' . $thisid;
$destlist_invalid[] = array(
'dest' => $thisdest,
'description' => sprintf(_("IVR: %s (%s)"),$name,"Invalid Destination"),
'edit_url' => 'config.php?display=ivr&action=edit&id='.urlencode($thisid),
'allow_empty' => true,
);
}
$sql = "SELECT timeout_destination, name, id FROM ivr_details ";
if ($dest !== true && is_array($dest)) {
$sql .= "WHERE timeout_destination in (".implode(",",array_fill(0, count($dest), "?")).")";
}
$sql .= "ORDER BY name";
$results = $db->getAll($sql, $dest, DB_FETCHMODE_ASSOC);
foreach ($results as $result) {
$thisdest = $result['timeout_destination'];
$thisid = $result['id'];
$name = $result['name'] ? $result['name'] : 'IVR ' . $thisid;
$destlist_timeout[] = array(
'dest' => $thisdest,
'description' => sprintf(_("IVR: %s (%s)"),$name,"Timeout Destination"),
'edit_url' => 'config.php?display=ivr&action=edit&id='.urlencode($thisid),
'allow_empty' => true,
);
}
$destlist = array_merge($destlist_option, $destlist_invalid, $destlist_timeout);
return $destlist;
}
function ivr_change_destination($old_dest, $new_dest) {
global $db;
$sql = "UPDATE ivr_entires SET dest = ? WHERE dest = ?";
$params = array($new_dest, $old_dest);
$db->query($sql, $params);
}
function ivr_getdest($exten) {
return array('ivr-'.$exten.',s,1');
}
function ivr_getdestinfo($dest) {
global $active_modules;
if (substr(trim($dest),0,4) == 'ivr-') {
$exten = explode(',',$dest);
$exten = substr($exten[0],4);
$thisexten = ivr_get_details($exten);
if (empty($thisexten)) {
return array();
} else {
//$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup';
return array('description' => sprintf(_("IVR: %s"), ($thisexten['name'] ? $thisexten['name'] : $thisexten['id'])),
'edit_url' => 'config.php?display=ivr&action=edit&id='.urlencode($exten),
);
}
} else {
return false;
}
}
function ivr_recordings_usage($recording_id) {
global $active_modules;
global $db;
$sql = "SELECT `id`, `name` FROM `ivr_details` WHERE `announcement` = :recording_id OR `invalid_retry_recording` = :recording_id OR `invalid_recording` = :recording_id OR `timeout_recording` = :recording_id OR `timeout_retry_recording` = :recording_id";
$params = array(":recording_id"=>$recording_id);
$results = $db->getAll($sql, $params, DB_FETCHMODE_ASSOC);
if (empty($results)) {
return array();
} else {
foreach ($results as $result) {
$usage_arr[] = array(
'url_query' => 'config.php?display=ivr&action=edit&id='.urlencode($result['id']),
'description' => sprintf(_("IVR: %s"), ($result['name'] ? $result['name'] : $result['id'])),
);
}
return $usage_arr;
}
}
?>