| 1 |
<?php /* $Id: functions.inc.php 1951 2006-05-23 21:12:17Z mheydon1973 $ */ |
|---|
| 2 |
|
|---|
| 3 |
// The destinations this module provides |
|---|
| 4 |
// returns a associative arrays with keys 'destination' and 'description' |
|---|
| 5 |
function ringgroups_destinations() { |
|---|
| 6 |
//get the list of ringgroups |
|---|
| 7 |
$results = ringgroups_list(); |
|---|
| 8 |
|
|---|
| 9 |
// return an associative array with destination and description |
|---|
| 10 |
if (isset($results)) { |
|---|
| 11 |
foreach($results as $result){ |
|---|
| 12 |
$thisgrp = ringgroups_get(ltrim($result['0'])); |
|---|
| 13 |
$extens[] = array('destination' => 'ext-group,'.ltrim($result['0']).',1', 'description' => $thisgrp['description'].' <'.ltrim($result['0']).'>'); |
|---|
| 14 |
} |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
if (isset($extens)) |
|---|
| 18 |
return $extens; |
|---|
| 19 |
else |
|---|
| 20 |
return null; |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
/* Generates dialplan for ringgroups |
|---|
| 24 |
We call this with retrieve_conf |
|---|
| 25 |
*/ |
|---|
| 26 |
function ringgroups_get_config($engine) { |
|---|
| 27 |
global $ext; // is this the best way to pass this? |
|---|
| 28 |
switch($engine) { |
|---|
| 29 |
case "asterisk": |
|---|
| 30 |
$ext->addInclude('from-internal-additional','ext-group'); |
|---|
| 31 |
$contextname = 'ext-group'; |
|---|
| 32 |
$ringlist = ringgroups_list(); |
|---|
| 33 |
if (is_array($ringlist)) { |
|---|
| 34 |
foreach($ringlist as $item) { |
|---|
| 35 |
$grpnum = ltrim($item['0']); |
|---|
| 36 |
$grp = ringgroups_get($grpnum); |
|---|
| 37 |
|
|---|
| 38 |
$strategy = $grp['strategy']; |
|---|
| 39 |
$grptime = $grp['grptime']; |
|---|
| 40 |
$grplist = $grp['grplist']; |
|---|
| 41 |
$postdest = $grp['postdest']; |
|---|
| 42 |
$grppre = $grp['grppre']; |
|---|
| 43 |
$annmsg = (isset($grp['annmsg'])?$grp['annmsg']:''); |
|---|
| 44 |
$alertinfo = $grp['alertinfo']; |
|---|
| 45 |
|
|---|
| 46 |
$ext->add($contextname, $grpnum, '', new ext_macro('user-callerid')); |
|---|
| 47 |
// check for old prefix |
|---|
| 48 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["${CALLERID(name):0:${LEN(${RGPREFIX})}}" != "${RGPREFIX}"]', 'NEWPREFIX')); |
|---|
| 49 |
// strip off old prefix |
|---|
| 50 |
$ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${CALLERID(name):${LEN(${RGPREFIX})}}')); |
|---|
| 51 |
// set new prefix |
|---|
| 52 |
$ext->add($contextname, $grpnum, 'NEWPREFIX', new ext_setvar('RGPREFIX',$grppre)); |
|---|
| 53 |
// add prefix to callerid name |
|---|
| 54 |
$ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}')); |
|---|
| 55 |
// Set Alert_Info |
|---|
| 56 |
if ($alertinfo != '') { |
|---|
| 57 |
$ext->add($contextname, $grpnum, '', new ext_setvar('_ALERT_INFO',$alertinfo)); |
|---|
| 58 |
} |
|---|
| 59 |
// recording stuff |
|---|
| 60 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RecordMethod','Group')); |
|---|
| 61 |
$ext->add($contextname, $grpnum, '', new ext_macro('record-enable',$grplist.',${RecordMethod}')); |
|---|
| 62 |
// group dial |
|---|
| 63 |
if ($strategy=='hunt-rand') |
|---|
| 64 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod','hunt')); |
|---|
| 65 |
else if ($strategy=='memoryhunt-rand') |
|---|
| 66 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod','memoryhunt')); |
|---|
| 67 |
else |
|---|
| 68 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',$strategy)); |
|---|
| 69 |
if ($annmsg != '') { |
|---|
| 70 |
$ext->add($contextname, $grpnum, '', new ext_answer('')); |
|---|
| 71 |
$ext->add($contextname, $grpnum, '', new ext_wait(1)); |
|---|
| 72 |
$ext->add($contextname, $grpnum, '', new ext_playback($annmsg)); |
|---|
| 73 |
} |
|---|
| 74 |
if ($strategy=='hunt-rand' || $strategy=='memoryhunt-rand') { |
|---|
| 75 |
// the setvar is to avoid that it there is a problem with the AGI, the call will continue |
|---|
| 76 |
$ext->add($contextname, $grpnum, 'DIALGRP', new ext_setvar('RESULT',$grplist)); |
|---|
| 77 |
$ext->add($contextname, $grpnum, '', new ext_agi('resort.agi,'.$grplist)); |
|---|
| 78 |
$ext->add($contextname, $grpnum, '', new ext_macro('dial',$grptime.',${DIAL_OPTIONS},${RESULT}')); |
|---|
| 79 |
} else |
|---|
| 80 |
$ext->add($contextname, $grpnum, 'DIALGRP', new ext_macro('dial',$grptime.',${DIAL_OPTIONS},'.$grplist)); |
|---|
| 81 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod','')); |
|---|
| 82 |
// where next? |
|---|
| 83 |
if ((isset($postdest) ? $postdest : '') != '') |
|---|
| 84 |
$ext->add($contextname, $grpnum, '', new ext_goto($postdest)); |
|---|
| 85 |
else |
|---|
| 86 |
$ext->add($contextname, $grpnum, '', new ext_hangup('')); |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
break; |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
function ringgroups_add($grpnum,$strategy,$grptime,$grplist,$postdest,$desc,$grppre='',$annmsg='',$alertinfo) { |
|---|
| 94 |
$results = sql("INSERT INTO ringgroups (grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo) VALUES (".$grpnum.", '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $desc)."', '".str_replace("'", "''", $alertinfo)."')"); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
function ringgroups_del($grpnum) { |
|---|
| 98 |
$results = sql("DELETE FROM ringgroups WHERE grpnum = $grpnum","query"); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
function ringgroups_list() { |
|---|
| 102 |
$results = sql("SELECT grpnum, description FROM ringgroups ORDER BY grpnum","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 103 |
foreach ($results as $result) { |
|---|
| 104 |
if (isset($result['grpnum']) && checkRange($result['grpnum'])) { |
|---|
| 105 |
$grps[] = array($result['grpnum'], $result['description']); |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
if (isset($grps)) |
|---|
| 109 |
return $grps; |
|---|
| 110 |
else |
|---|
| 111 |
return null; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
function ringgroups_get($grpnum) { |
|---|
| 115 |
$results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo FROM ringgroups WHERE grpnum = $grpnum","getRow",DB_FETCHMODE_ASSOC); |
|---|
| 116 |
return $results; |
|---|
| 117 |
} |
|---|
| 118 |
?> |
|---|