| 1 |
<?php /* $Id: functions.inc.php 175 2006-10-03 19:12:39Z plindheimer $ */ |
|---|
| 2 |
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); } |
|---|
| 3 |
|
|---|
| 4 |
/* Generates dialplan for findmefollow |
|---|
| 5 |
We call this with retrieve_conf |
|---|
| 6 |
*/ |
|---|
| 7 |
|
|---|
| 8 |
function findmefollow_destinations() { |
|---|
| 9 |
global $display; |
|---|
| 10 |
global $extdisplay; |
|---|
| 11 |
global $followme_exten; |
|---|
| 12 |
global $db; |
|---|
| 13 |
|
|---|
| 14 |
if ($display == 'findmefollow' && $followme_exten != '') { |
|---|
| 15 |
$extens[] = array('destination' => 'ext-local,'.$followme_exten.',dest', 'description' => _("Normal Extension Behavior")); |
|---|
| 16 |
return $extens; |
|---|
| 17 |
} |
|---|
| 18 |
if (($display != 'extensions' && $display != 'users') || !isset($extdisplay) || $extdisplay == '') { |
|---|
| 19 |
return null; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
//TODO: need to do a join with user to get the displayname also |
|---|
| 23 |
|
|---|
| 24 |
//TODO: if extdisplay is set, sort such that this extension's follow-me is at the top of the list if they have one |
|---|
| 25 |
// alternatively, only put this extension's follow-me since you should not be able to force to others and you can use their extension |
|---|
| 26 |
//$results = findmefollow_list(); |
|---|
| 27 |
$grpnum = sql("SELECT grpnum FROM findmefollow WHERE grpnum = '".$db->escapeSimple($extdisplay)."'","getOne"); |
|---|
| 28 |
|
|---|
| 29 |
// return an associative array with destination and description |
|---|
| 30 |
if ($grpnum != '') { |
|---|
| 31 |
$extens[] = array('destination' => 'ext-findmefollow,FM'.$grpnum.',1', 'description' => _("Force Follow Me")); |
|---|
| 32 |
return $extens; |
|---|
| 33 |
} else { |
|---|
| 34 |
return null; |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
function findmefollow_get_config($engine) { |
|---|
| 39 |
global $ext; // is this the best way to pass this? |
|---|
| 40 |
global $amp_conf; |
|---|
| 41 |
switch($engine) { |
|---|
| 42 |
case "asterisk": |
|---|
| 43 |
if ($amp_conf['USEDEVSTATE']) { |
|---|
| 44 |
$ext->addGlobal('FMDEVSTATE','TRUE'); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
$fcc = new featurecode('findmefollow', 'fmf_toggle'); |
|---|
| 48 |
$fmf_code = $fcc->getCodeActive(); |
|---|
| 49 |
unset($fcc); |
|---|
| 50 |
|
|---|
| 51 |
if ($fmf_code != '') { |
|---|
| 52 |
findmefollow_fmf_toggle($fmf_code); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
$ext->addInclude('from-internal-additional','ext-findmefollow'); |
|---|
| 56 |
$ext->addInclude('from-internal-additional','fmgrps'); |
|---|
| 57 |
$contextname = 'ext-findmefollow'; |
|---|
| 58 |
|
|---|
| 59 |
// Before creating all the contexts, let's make a list of hints if needed |
|---|
| 60 |
// |
|---|
| 61 |
if ($amp_conf['USEDEVSTATE'] && $fmf_code != '') { |
|---|
| 62 |
$device_list = core_devices_list("all", 'full', true); |
|---|
| 63 |
foreach ($device_list as $device) { |
|---|
| 64 |
if ($device['tech'] == 'sip' || $device['tech'] == 'iax2') { |
|---|
| 65 |
$ext->add($contextname, $fmf_code.$device['id'], '', new ext_goto("1",$fmf_code,"app-fmf-toggle")); |
|---|
| 66 |
$ext->addHint($contextname, $fmf_code.$device['id'], "Custom:FOLLOWME".$device['id']); |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
$ringlist = findmefollow_full_list(); |
|---|
| 72 |
if (is_array($ringlist)) { |
|---|
| 73 |
foreach($ringlist as $item) { |
|---|
| 74 |
$grpnum = ltrim($item['0']); |
|---|
| 75 |
if ($grpnum == "") { |
|---|
| 76 |
continue; |
|---|
| 77 |
} |
|---|
| 78 |
$grp = findmefollow_get($grpnum); |
|---|
| 79 |
|
|---|
| 80 |
$strategy = $grp['strategy']; |
|---|
| 81 |
$grptime = $grp['grptime']; |
|---|
| 82 |
$grplist = $grp['grplist']; |
|---|
| 83 |
$postdest = $grp['postdest']; |
|---|
| 84 |
$grppre = (isset($grp['grppre'])?$grp['grppre']:''); |
|---|
| 85 |
$annmsg_id = $grp['annmsg_id']; |
|---|
| 86 |
$dring = $grp['dring']; |
|---|
| 87 |
|
|---|
| 88 |
$needsconf = $grp['needsconf']; |
|---|
| 89 |
$remotealert_id = $grp['remotealert_id']; |
|---|
| 90 |
$toolate_id = $grp['toolate_id']; |
|---|
| 91 |
$ringing = $grp['ringing']; |
|---|
| 92 |
$pre_ring = $grp['pre_ring']; |
|---|
| 93 |
|
|---|
| 94 |
if($ringing == 'Ring' || empty($ringing) ) { |
|---|
| 95 |
$dialopts = '${DIAL_OPTIONS}'; |
|---|
| 96 |
} else { |
|---|
| 97 |
// We need the DIAL_OPTIONS variable |
|---|
| 98 |
if (!isset($sops)) { |
|---|
| 99 |
$sops = sql("SELECT value from globals where variable='DIAL_OPTIONS'", "getRow"); |
|---|
| 100 |
} |
|---|
| 101 |
$dialopts = "m(${ringing})".str_replace('r', '', $sops[0]); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
// Direct target to Follow-Me come here bypassing the followme/ddial conditional check |
|---|
| 105 |
// |
|---|
| 106 |
$ext->add($contextname, 'FM'.$grpnum, '', new ext_goto("FM$grpnum","$grpnum")); |
|---|
| 107 |
|
|---|
| 108 |
// |
|---|
| 109 |
// If the followme is configured for extension dialing to go to the the extension and not followme then |
|---|
| 110 |
// go there. This is often used in VmX Locater functionality when the user does not want the followme |
|---|
| 111 |
// to automatically be called but only if chosen by the caller as an alternative to going to voicemail |
|---|
| 112 |
// |
|---|
| 113 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$[ "${DB(AMPUSER/'.$grpnum.'/followme/ddial)}" = "EXTENSION" ]', 'ext-local,'.$grpnum.',1')); |
|---|
| 114 |
$ext->add($contextname, $grpnum, 'FM'.$grpnum, new ext_macro('user-callerid')); |
|---|
| 115 |
|
|---|
| 116 |
$ext->add($contextname, $grpnum, '', new ext_set('DIAL_OPTIONS','${DIAL_OPTIONS}I')); |
|---|
| 117 |
$ext->add($contextname, $grpnum, '', new ext_set('CONNECTEDLINE(num)', $grpnum)); |
|---|
| 118 |
$ext->add($contextname, $grpnum, '', new ext_set('CONNECTEDLINE(name,i)','${DB(AMPUSER/' . $grpnum . '/cidname)}')); |
|---|
| 119 |
$ext->add($contextname, $grpnum, '', new ext_set('FM_DIALSTATUS','${EXTENSION_STATE(' .$grpnum. '@ext-local)}')); |
|---|
| 120 |
$ext->add($contextname, $grpnum, '', new ext_set('__EXTTOCALL','${EXTEN}')); |
|---|
| 121 |
$ext->add($contextname, $grpnum, '', new ext_set('__PICKUPMARK','${EXTEN}')); |
|---|
| 122 |
|
|---|
| 123 |
// block voicemail until phone is answered at which point a macro should be called on the answering |
|---|
| 124 |
// line to clear this flag so that subsequent transfers can occur, if already set by a the caller |
|---|
| 125 |
// then don't change. |
|---|
| 126 |
// |
|---|
| 127 |
$ext->add($contextname, $grpnum, '', new ext_macro('blkvm-setifempty')); |
|---|
| 128 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["${GOSUB_RETVAL}" = "TRUE"]', 'skipov')); |
|---|
| 129 |
$ext->add($contextname, $grpnum, '', new ext_macro('blkvm-set','reset')); |
|---|
| 130 |
$ext->add($contextname, $grpnum, '', new ext_setvar('__NODEST', '')); |
|---|
| 131 |
|
|---|
| 132 |
// Remember if NODEST was set later, but clear it in case the call is answered so that subsequent |
|---|
| 133 |
// transfers work. |
|---|
| 134 |
// |
|---|
| 135 |
$ext->add($contextname, $grpnum, 'skipov', new ext_setvar('RRNODEST', '${NODEST}')); |
|---|
| 136 |
$ext->add($contextname, $grpnum, 'skipvmblk', new ext_setvar('__NODEST', '${EXTEN}')); |
|---|
| 137 |
|
|---|
| 138 |
$ext->add($contextname, $grpnum, '', new ext_gosubif('$[${DB_EXISTS(AMPUSER/'.$grpnum.'/followme/changecid)} = 1 & "${DB(AMPUSER/'.$grpnum.'/followme/changecid)}" != "default" & "${DB(AMPUSER/'.$grpnum.'/followme/changecid)}" != ""]', 'sub-fmsetcid,s,1')); |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
// deal with group CID prefix |
|---|
| 142 |
if ($grppre != '') { |
|---|
| 143 |
$ext->add($contextname, $grpnum, '', new ext_macro('prepend-cid', $grppre)); |
|---|
| 144 |
} |
|---|
| 145 |
// recording stuff |
|---|
| 146 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RecordMethod','Group')); |
|---|
| 147 |
|
|---|
| 148 |
// Note there is no cancel later as the special case of follow-me, if they say record, it should stick |
|---|
| 149 |
$ext->add($contextname, $grpnum, 'checkrecord', new ext_gosub('1','s','sub-record-check',"exten,$grpnum,")); |
|---|
| 150 |
|
|---|
| 151 |
// MODIFIED (PL) |
|---|
| 152 |
// Add Alert Info if set but don't override and already set value (could be from ringgroup, directdid, etc.) |
|---|
| 153 |
// |
|---|
| 154 |
if ((isset($dring) ? $dring : '') != '') { |
|---|
| 155 |
// If ALERTINFO is set, then skip to the next set command. This was modified to two lines because the previous |
|---|
| 156 |
// IF() couldn't handle ':' as part of the string. The jump to PRIORITY+2 allows for now destination label |
|---|
| 157 |
// which is needed in the 2.3 version. |
|---|
| 158 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["x${ALERT_INFO}"!="x"]','$[${PRIORITY}+2])}')); |
|---|
| 159 |
$ext->add($contextname, $grpnum, '', new ext_setvar("__ALERT_INFO", str_replace(';', '\;', $dring) )); |
|---|
| 160 |
} |
|---|
| 161 |
// If pre_ring is set, then ring this number of seconds prior to moving on |
|---|
| 162 |
if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') { |
|---|
| 163 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$[$[ "${DB(AMPUSER/'.$grpnum.'/followme/prering)}" = "0" ] | $[ "${DB(AMPUSER/'.$grpnum.'/followme/prering)}" = "" ]] ', 'skipsimple')); |
|---|
| 164 |
$ext->add($contextname, $grpnum, '', new ext_macro('simple-dial',$grpnum.',${DB(AMPUSER/'."$grpnum/followme/prering)}")); |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
// group dial |
|---|
| 168 |
$ext->add($contextname, $grpnum, 'skipsimple', new ext_setvar('RingGroupMethod',$strategy)); |
|---|
| 169 |
$ext->add($contextname, $grpnum, '', new ext_setvar('_FMGRP',$grpnum)); |
|---|
| 170 |
|
|---|
| 171 |
if ((isset($annmsg_id) ? $annmsg_id : '')) { |
|---|
| 172 |
$annmsg = recordings_get_file($annmsg_id); |
|---|
| 173 |
// should always answer before playing anything, shouldn't we ? |
|---|
| 174 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$[$["${DIALSTATUS}" = "ANSWER"] | $["foo${RRNODEST}" != "foo"]]','DIALGRP')); |
|---|
| 175 |
$ext->add($contextname, $grpnum, '', new ext_answer('')); |
|---|
| 176 |
$ext->add($contextname, $grpnum, '', new ext_wait(1)); |
|---|
| 177 |
$ext->add($contextname, $grpnum, '', new ext_playback($annmsg)); |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
// Create the confirm target |
|---|
| 181 |
$len=strlen($grpnum)+4; |
|---|
| 182 |
$remotealert = recordings_get_file($remotealert_id); |
|---|
| 183 |
$toolate = recordings_get_file($toolate_id); |
|---|
| 184 |
$ext->add("fmgrps", "_RG-${grpnum}.", '', new ext_nocdr('')); |
|---|
| 185 |
$ext->add("fmgrps", "_RG-${grpnum}.", '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts" . "M(confirm^${remotealert}^${toolate}^${grpnum})".',${EXTEN:'.$len.'}')); |
|---|
| 186 |
|
|---|
| 187 |
// If grpconf == ENABLED call with confirmation ELSE call normal |
|---|
| 188 |
$ext->add($contextname, $grpnum, 'DIALGRP', new |
|---|
| 189 |
ext_gotoif('$[("${DB(AMPUSER/'.$grpnum.'/followme/grpconf)}"="ENABLED") | ("${FORCE_CONFIRM}"!="") ]', 'doconfirm')); |
|---|
| 190 |
|
|---|
| 191 |
// Normal call |
|---|
| 192 |
if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') { |
|---|
| 193 |
$ext->add($contextname, $grpnum, '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)}")); |
|---|
| 194 |
} else { |
|---|
| 195 |
$ext->add($contextname, $grpnum, '', new ext_macro('dial','$[ ${DB(AMPUSER/'.$grpnum.'/followme/grptime)} + ${DB(AMPUSER/'.$grpnum.'/followme/prering)} ],'.$dialopts.',${DB(AMPUSER/'.$grpnum.'/followme/grplist)}')); |
|---|
| 196 |
} |
|---|
| 197 |
$ext->add($contextname, $grpnum, '', new ext_goto('nextstep')); |
|---|
| 198 |
|
|---|
| 199 |
// Call Confirm call |
|---|
| 200 |
if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') { |
|---|
| 201 |
$ext->add($contextname, $grpnum, 'doconfirm', new ext_macro('dial-confirm','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)},".$grpnum)); |
|---|
| 202 |
} else { |
|---|
| 203 |
$ext->add($contextname, $grpnum, 'doconfirm', new ext_macro('dial-confirm','$[ ${DB(AMPUSER/'.$grpnum.'/followme/grptime)} + ${DB(AMPUSER/'.$grpnum.'/followme/prering)} ],'.$dialopts.',${DB(AMPUSER/'.$grpnum.'/followme/grplist)},'.$grpnum)); |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
$ext->add($contextname, $grpnum, 'nextstep', new ext_setvar('RingGroupMethod','')); |
|---|
| 207 |
|
|---|
| 208 |
// Did the call come from a queue or ringgroup, if so, don't go to the destination, just end and let |
|---|
| 209 |
// the queue or ringgroup decide what to do next |
|---|
| 210 |
// |
|---|
| 211 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RRNODEST}" != "foo"]', 'nodest')); |
|---|
| 212 |
$ext->add($contextname, $grpnum, '', new ext_setvar('__NODEST', '')); |
|---|
| 213 |
$ext->add($contextname, $grpnum, '', new ext_set('__PICKUPMARK','')); |
|---|
| 214 |
$ext->add($contextname, $grpnum, '', new ext_macro('blkvm-clr')); |
|---|
| 215 |
|
|---|
| 216 |
/* NOANSWER: NOT_INUSE |
|---|
| 217 |
* CHANUNAVAIL: UNAVAILABLE, UNKNOWN, INVALID (or DIALSTATUS=CHANUNAVAIL) |
|---|
| 218 |
* BUSY: BUSY, INUSE, RINGING, RINGINUSE, HOLDINUSE, ONHOLD |
|---|
| 219 |
*/ |
|---|
| 220 |
$ext->add($contextname, $grpnum, '', new ext_noop_trace('FM_DIALSTATUS: ${FM_DIALSTATUS} DIALSTATUS: ${DIALSTATUS}')); |
|---|
| 221 |
$ext->add($contextname, $grpnum, '', new ext_set('DIALSTATUS', |
|---|
| 222 |
'${IF($["${FM_DIALSTATUS}"="NOT_INUSE"&"${DIALSTATUS}"!="CHANUNAVAIL"]?NOANSWER:' |
|---|
| 223 |
. '${IF($["${DIALSTATUS}"="CHANUNAVAIL"|"${FM_DIALSTATUS}"="UNAVAILABLE"|"${FM_DIALSTATUS}"="UNKNOWN"|"${FM_DIALSTATUS}"="INVALID"]?' |
|---|
| 224 |
. 'CHANUNAVAIL:BUSY)})}')); |
|---|
| 225 |
|
|---|
| 226 |
// where next? |
|---|
| 227 |
if ((isset($postdest) ? $postdest : '') != '') { |
|---|
| 228 |
$ext->add($contextname, $grpnum, '', new ext_goto($postdest)); |
|---|
| 229 |
} else { |
|---|
| 230 |
$ext->add($contextname, $grpnum, '', new ext_hangup('')); |
|---|
| 231 |
} |
|---|
| 232 |
$ext->add($contextname, $grpnum, 'nodest', new ext_noop('SKIPPING DEST, CALL CAME FROM Q/RG: ${RRNODEST}')); |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
/* |
|---|
| 236 |
ASTDB Settings: |
|---|
| 237 |
AMPUSER/nnn/followme/changecid default | did | fixed | extern |
|---|
| 238 |
AMPUSER/nnn/followme/fixedcid XXXXXXXX |
|---|
| 239 |
|
|---|
| 240 |
changecid: |
|---|
| 241 |
default - works as always, same as if not present |
|---|
| 242 |
fixed - set to the fixedcid |
|---|
| 243 |
extern - set to the fixedcid if the call is from the outside only |
|---|
| 244 |
did - set to the DID that the call came in on or leave alone, treated as foreign |
|---|
| 245 |
forcedid - set to the DID that the call came in on or leave alone, not treated as foreign |
|---|
| 246 |
|
|---|
| 247 |
EXTTOCALL - has the exten num called, hoaky if that goes away but for now use it |
|---|
| 248 |
*/ |
|---|
| 249 |
if (count($ringlist)) { |
|---|
| 250 |
$contextname = 'sub-fmsetcid'; |
|---|
| 251 |
$exten = 's'; |
|---|
| 252 |
$ext->add($contextname, $exten, '', new ext_goto('1','s-${DB(AMPUSER/${EXTTOCALL}/followme/changecid)}')); |
|---|
| 253 |
|
|---|
| 254 |
$exten = 's-fixed'; |
|---|
| 255 |
$ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${DB(AMPUSER/${EXTTOCALL}/followme/fixedcid)})}" = "1"]', 'Set', '__TRUNKCIDOVERRIDE=${DB(AMPUSER/${EXTTOCALL}/followme/fixedcid)}')); |
|---|
| 256 |
$ext->add($contextname, $exten, '', new ext_return('')); |
|---|
| 257 |
|
|---|
| 258 |
$exten = 's-extern'; |
|---|
| 259 |
$ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${DB(AMPUSER/${EXTTOCALL}/followme/fixedcid)})}" == "1" & "${FROM_DID}" != ""]', 'Set', '__TRUNKCIDOVERRIDE=${DB(AMPUSER/${EXTTOCALL}/followme/fixedcid)}')); |
|---|
| 260 |
$ext->add($contextname, $exten, '', new ext_return('')); |
|---|
| 261 |
|
|---|
| 262 |
$exten = 's-did'; |
|---|
| 263 |
$ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${FROM_DID})}" = "1"]', 'Set', '__REALCALLERIDNUM=${FROM_DID}')); |
|---|
| 264 |
$ext->add($contextname, $exten, '', new ext_return('')); |
|---|
| 265 |
|
|---|
| 266 |
$exten = 's-forcedid'; |
|---|
| 267 |
$ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${FROM_DID})}" = "1"]', 'Set', '__TRUNKCIDOVERRIDE=${FROM_DID}')); |
|---|
| 268 |
$ext->add($contextname, $exten, '', new ext_return('')); |
|---|
| 269 |
|
|---|
| 270 |
$exten = '_s-.'; |
|---|
| 271 |
$ext->add($contextname, $exten, '', new ext_noop('Unknown value for AMPUSER/${EXTTOCALL}/followme/changecid of ${DB(AMPUSER/${EXTTOCALL}/followme/changecid)} set to "default"')); |
|---|
| 272 |
$ext->add($contextname, $exten, '', new ext_setvar('DB(AMPUSER/${EXTTOCALL}/followme/changecid)', 'default')); |
|---|
| 273 |
$ext->add($contextname, $exten, '', new ext_return('')); |
|---|
| 274 |
} |
|---|
| 275 |
} |
|---|
| 276 |
break; |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
function findmefollow_add($grpnum,$strategy,$grptime,$grplist,$postdest,$grppre='',$annmsg_id='',$dring,$needsconf,$remotealert_id,$toolate_id,$ringing,$pre_ring,$ddial,$changecid='default',$fixedcid='') { |
|---|
| 281 |
global $amp_conf; |
|---|
| 282 |
global $astman; |
|---|
| 283 |
global $db; |
|---|
| 284 |
|
|---|
| 285 |
if (empty($postdest)) { |
|---|
| 286 |
$postdest = "ext-local,$grpnum,dest"; |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
$sql = "INSERT INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring) VALUES ('".$db->escapeSimple($grpnum)."', '".$db->escapeSimple($strategy)."', ".$db->escapeSimple($grptime).", '".$db->escapeSimple($grppre)."', '".$db->escapeSimple($grplist)."', '".$db->escapeSimple($annmsg_id)."', '".$db->escapeSimple($postdest)."', '".$db->escapeSimple($dring)."', '$needsconf', '$remotealert_id', '$toolate_id', '$ringing', '$pre_ring')"; |
|---|
| 290 |
$results = sql($sql); |
|---|
| 291 |
|
|---|
| 292 |
if ($astman) { |
|---|
| 293 |
$astman->database_put("AMPUSER",$grpnum."/followme/prering",isset($pre_ring)?$pre_ring:''); |
|---|
| 294 |
$astman->database_put("AMPUSER",$grpnum."/followme/grptime",isset($grptime)?$grptime:''); |
|---|
| 295 |
$astman->database_put("AMPUSER",$grpnum."/followme/grplist",isset($grplist)?$grplist:''); |
|---|
| 296 |
|
|---|
| 297 |
$needsconf = isset($needsconf)?$needsconf:''; |
|---|
| 298 |
$confvalue = ($needsconf == 'CHECKED')?'ENABLED':'DISABLED'; |
|---|
| 299 |
$astman->database_put("AMPUSER",$grpnum."/followme/grpconf",$confvalue); |
|---|
| 300 |
|
|---|
| 301 |
$ddial = isset($ddial)?$ddial:''; |
|---|
| 302 |
$ddialvalue = ($ddial == 'CHECKED')?'EXTENSION':'DIRECT'; |
|---|
| 303 |
$astman->database_put("AMPUSER",$grpnum."/followme/ddial",$ddialvalue); |
|---|
| 304 |
|
|---|
| 305 |
$astman->database_put("AMPUSER",$grpnum."/followme/changecid",$changecid); |
|---|
| 306 |
$fixedcid = preg_replace("/[^0-9\+]/" ,"", trim($fixedcid)); |
|---|
| 307 |
$astman->database_put("AMPUSER",$grpnum."/followme/fixedcid",$fixedcid); |
|---|
| 308 |
} else { |
|---|
| 309 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 310 |
} |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
function findmefollow_del($grpnum) { |
|---|
| 314 |
global $amp_conf; |
|---|
| 315 |
global $astman; |
|---|
| 316 |
global $db; |
|---|
| 317 |
|
|---|
| 318 |
$results = sql("DELETE FROM findmefollow WHERE grpnum = '".$db->escapeSimple($grpnum)."'","query"); |
|---|
| 319 |
|
|---|
| 320 |
if ($astman) { |
|---|
| 321 |
$astman->database_deltree("AMPUSER/".$grpnum."/followme"); |
|---|
| 322 |
} else { |
|---|
| 323 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 324 |
} |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
function findmefollow_full_list() { |
|---|
| 328 |
$results = sql("SELECT grpnum FROM findmefollow ORDER BY CAST(grpnum as UNSIGNED)","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 329 |
foreach ($results as $result) { |
|---|
| 330 |
if (isset($result['grpnum']) && checkRange($result['grpnum'])) { |
|---|
| 331 |
$grps[] = array($result['grpnum']); |
|---|
| 332 |
} |
|---|
| 333 |
} |
|---|
| 334 |
if (isset($grps)) |
|---|
| 335 |
return $grps; |
|---|
| 336 |
else |
|---|
| 337 |
return null; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
function findmefollow_list($get_all=false) { |
|---|
| 341 |
|
|---|
| 342 |
global $db; |
|---|
| 343 |
$sql = "SELECT grpnum FROM findmefollow ORDER BY CAST(grpnum as UNSIGNED)"; |
|---|
| 344 |
$results = $db->getCol($sql); |
|---|
| 345 |
if(DB::IsError($results)) { |
|---|
| 346 |
$results = null; |
|---|
| 347 |
} |
|---|
| 348 |
if (isset($results)) { |
|---|
| 349 |
foreach($results as $result) { |
|---|
| 350 |
if ($get_all || checkRange($result)){ |
|---|
| 351 |
$grps[] = $result; |
|---|
| 352 |
} |
|---|
| 353 |
} |
|---|
| 354 |
} |
|---|
| 355 |
if (isset($grps)) { |
|---|
| 356 |
return $grps; |
|---|
| 357 |
} |
|---|
| 358 |
else { |
|---|
| 359 |
return null; |
|---|
| 360 |
} |
|---|
| 361 |
} |
|---|
| 362 |
|
|---|
| 363 |
// This gets the list of all active users so that the Find Me Follow display can limit the options to only created users. |
|---|
| 364 |
// the returned arrays contain [0]:extension [1]:name |
|---|
| 365 |
// |
|---|
| 366 |
// This was pulled straight out of previous 1.x version, might need cleanup laster |
|---|
| 367 |
// |
|---|
| 368 |
function findmefollow_allusers() { |
|---|
| 369 |
global $db; |
|---|
| 370 |
$sql = "SELECT extension,name FROM users ORDER BY extension"; |
|---|
| 371 |
$results = $db->getAll($sql); |
|---|
| 372 |
if(DB::IsError($results)) { |
|---|
| 373 |
$results = null; |
|---|
| 374 |
} |
|---|
| 375 |
foreach($results as $result){ |
|---|
| 376 |
if (checkRange($result[0])){ |
|---|
| 377 |
$users[] = array($result[0],$result[1]); |
|---|
| 378 |
} |
|---|
| 379 |
} |
|---|
| 380 |
if (isset($users)) sort($users); |
|---|
| 381 |
return $users; |
|---|
| 382 |
} |
|---|
| 383 |
|
|---|
| 384 |
// Only check astdb if check_astdb is not 0. For some reason, this fails if the asterisk manager code |
|---|
| 385 |
// is included (executed) by all calls to this function. This results in silently not generating the |
|---|
| 386 |
// extensions_additional.conf file. page.findmefollow.php does set it to 1 which means that when running |
|---|
| 387 |
// the GUI, any changes not reflected in SQL will be detected and written back to SQL so that they are |
|---|
| 388 |
// in sync. Ideally, anything that changes the astdb should change SQL. (in some ways, these should both |
|---|
| 389 |
// not be here but ... |
|---|
| 390 |
// |
|---|
| 391 |
// Need to go back and confirm at some point that the $check_astdb error is still there and deal with it. |
|---|
| 392 |
// as variables like $ddial get introduced to only be in astdb, the result array will not include them |
|---|
| 393 |
// if not able to get to astdb. (I suspect in 2.2 and beyond this may all be fixed). |
|---|
| 394 |
// |
|---|
| 395 |
function findmefollow_get($grpnum, $check_astdb=0) { |
|---|
| 396 |
global $amp_conf; |
|---|
| 397 |
global $astman; |
|---|
| 398 |
global $db; |
|---|
| 399 |
|
|---|
| 400 |
$results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring, voicemail FROM findmefollow INNER JOIN `users` ON `extension` = `grpnum` WHERE grpnum = '".$db->escapeSimple($grpnum)."'","getRow",DB_FETCHMODE_ASSOC); |
|---|
| 401 |
if (empty($results)) { |
|---|
| 402 |
return array(); |
|---|
| 403 |
} |
|---|
| 404 |
if (!isset($results['voicemail'])) { |
|---|
| 405 |
$results['voicemail'] = sql("SELECT `voicemail` FROM `users` WHERE `extension` = '".$db->escapeSimple($grpnum)."'","getOne"); |
|---|
| 406 |
} |
|---|
| 407 |
if (!isset($results['strategy'])) { |
|---|
| 408 |
$results['strategy'] = $amp_conf['FOLLOWME_RG_STRATEGY']; |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
if ($check_astdb) { |
|---|
| 412 |
if ($astman) { |
|---|
| 413 |
$astdb_prering = $astman->database_get("AMPUSER",$grpnum."/followme/prering"); |
|---|
| 414 |
$astdb_grptime = $astman->database_get("AMPUSER",$grpnum."/followme/grptime"); |
|---|
| 415 |
$astdb_grplist = $astman->database_get("AMPUSER",$grpnum."/followme/grplist"); |
|---|
| 416 |
$astdb_grpconf = $astman->database_get("AMPUSER",$grpnum."/followme/grpconf"); |
|---|
| 417 |
|
|---|
| 418 |
$astdb_changecid = strtolower($astman->database_get("AMPUSER",$grpnum."/followme/changecid")); |
|---|
| 419 |
switch($astdb_changecid) { |
|---|
| 420 |
case 'default': |
|---|
| 421 |
case 'did': |
|---|
| 422 |
case 'forcedid': |
|---|
| 423 |
case 'fixed': |
|---|
| 424 |
case 'extern': |
|---|
| 425 |
break; |
|---|
| 426 |
default: |
|---|
| 427 |
$astdb_changecid = 'default'; |
|---|
| 428 |
} |
|---|
| 429 |
$results['changecid'] = $astdb_changecid; |
|---|
| 430 |
$fixedcid = $astman->database_get("AMPUSER",$grpnum."/followme/fixedcid"); |
|---|
| 431 |
$results['fixedcid'] = preg_replace("/[^0-9\+]/" ,"", trim($fixedcid)); |
|---|
| 432 |
} else { |
|---|
| 433 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 434 |
} |
|---|
| 435 |
$astdb_ddial = $astman->database_get("AMPUSER",$grpnum."/followme/ddial"); |
|---|
| 436 |
// If the values are different then use what is in astdb as it may have been changed. |
|---|
| 437 |
// If sql returned no results for pre_ring/grptime then it's not configued so we reset |
|---|
| 438 |
// the astdb defaults as well |
|---|
| 439 |
// |
|---|
| 440 |
$changed=0; |
|---|
| 441 |
if (!isset($results['pre_ring'])) { |
|---|
| 442 |
$results['pre_ring'] = $astdb_prering = $amp_conf['FOLLOWME_PRERING']; |
|---|
| 443 |
} |
|---|
| 444 |
if (!isset($results['grptime'])) { |
|---|
| 445 |
$results['grptime'] = $astdb_grptime = $amp_conf['FOLLOWME_TIME']; |
|---|
| 446 |
} |
|---|
| 447 |
if (!isset($results['grplist'])) { |
|---|
| 448 |
$results['grplist'] = ''; |
|---|
| 449 |
} |
|---|
| 450 |
if (!isset($results['needsconf'])) { |
|---|
| 451 |
$results['needsconf'] = ''; |
|---|
| 452 |
} |
|---|
| 453 |
if (($astdb_prering != $results['pre_ring']) && ($astdb_prering >= 0)) { |
|---|
| 454 |
$results['pre_ring'] = $astdb_prering; |
|---|
| 455 |
$changed=1; |
|---|
| 456 |
} |
|---|
| 457 |
if (($astdb_grptime != $results['grptime']) && ($astdb_grptime > 0)) { |
|---|
| 458 |
$results['grptime'] = $astdb_grptime; |
|---|
| 459 |
$changed=1; |
|---|
| 460 |
} |
|---|
| 461 |
if ((trim($astdb_grplist) != trim($results['grplist'])) && (trim($astdb_grplist) != '')) { |
|---|
| 462 |
$results['grplist'] = $astdb_grplist; |
|---|
| 463 |
$changed=1; |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
if (trim($astdb_grpconf) == 'ENABLED') { |
|---|
| 467 |
$confvalue = 'CHECKED'; |
|---|
| 468 |
} elseif (trim($astdb_grpconf) == 'DISABLED') { |
|---|
| 469 |
$confvalue = ''; |
|---|
| 470 |
} else { |
|---|
| 471 |
//Bogus value, should not get here but treat as disabled |
|---|
| 472 |
$confvalue = ''; |
|---|
| 473 |
} |
|---|
| 474 |
if ($confvalue != trim($results['needsconf'])) { |
|---|
| 475 |
$results['needsconf'] = $confvalue; |
|---|
| 476 |
$changed=1; |
|---|
| 477 |
} |
|---|
| 478 |
|
|---|
| 479 |
// Not in sql so no sanity check needed |
|---|
| 480 |
// |
|---|
| 481 |
if (trim($astdb_ddial) == 'EXTENSION') { |
|---|
| 482 |
$ddial = 'CHECKED'; |
|---|
| 483 |
} elseif (trim($astdb_ddial) == 'DIRECT') { |
|---|
| 484 |
$ddial = ''; |
|---|
| 485 |
} else { |
|---|
| 486 |
// If here then followme must not be set so use default |
|---|
| 487 |
$ddial = $amp_conf['FOLLOWME_DISABLED'] ? 'CHECKED' : ''; |
|---|
| 488 |
} |
|---|
| 489 |
$results['ddial'] = $ddial; |
|---|
| 490 |
|
|---|
| 491 |
if ($changed) { |
|---|
| 492 |
$sql = "UPDATE findmefollow SET grptime = '".$results['grptime']."', grplist = '". |
|---|
| 493 |
$db->escapeSimple(trim($results['grplist']))."', pre_ring = '".$results['pre_ring']. |
|---|
| 494 |
"', needsconf = '".$results['needsconf']."' WHERE grpnum = '".$db->escapeSimple($grpnum)."' LIMIT 1"; |
|---|
| 495 |
$sql_results = sql($sql); |
|---|
| 496 |
} |
|---|
| 497 |
} // if check_astdb |
|---|
| 498 |
|
|---|
| 499 |
return $results; |
|---|
| 500 |
} |
|---|
| 501 |
|
|---|
| 502 |
function findmefollow_configpageinit($dispnum) { |
|---|
| 503 |
global $currentcomponent; |
|---|
| 504 |
global $amp_conf; |
|---|
| 505 |
|
|---|
| 506 |
if ( ($dispnum == 'users' || $dispnum == 'extensions') ) { |
|---|
| 507 |
$currentcomponent->addguifunc('findmefollow_configpageload'); |
|---|
| 508 |
|
|---|
| 509 |
if ($amp_conf['FOLLOWME_AUTO_CREATE']) { |
|---|
| 510 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 511 |
if ($action=="add") { |
|---|
| 512 |
$currentcomponent->addprocessfunc('findmefollow_configprocess', 8); |
|---|
| 513 |
} |
|---|
| 514 |
} |
|---|
| 515 |
} |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
function findmefollow_configpageload() { |
|---|
| 519 |
global $currentcomponent; |
|---|
| 520 |
|
|---|
| 521 |
$viewing_itemid = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 522 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 523 |
if ( $viewing_itemid != '' && $action != 'del') { |
|---|
| 524 |
$set_findmefollow = findmefollow_list(); |
|---|
| 525 |
$grpURL = $_SERVER['PHP_SELF'].'?'.'display=findmefollow&extdisplay=GRP-'.$viewing_itemid; |
|---|
| 526 |
if (is_array($set_findmefollow)) { |
|---|
| 527 |
if (in_array($viewing_itemid,$set_findmefollow)) { |
|---|
| 528 |
$grpTEXT = _("Edit Follow Me Settings"); |
|---|
| 529 |
$icon = "images/user_go.png"; |
|---|
| 530 |
} else { |
|---|
| 531 |
$grpTEXT = _("Add Follow Me Settings"); |
|---|
| 532 |
$icon = "images/user_add.png"; |
|---|
| 533 |
} |
|---|
| 534 |
} else { |
|---|
| 535 |
$grpTEXT = _("Add Follow Me Settings"); |
|---|
| 536 |
$icon = "images/user_add.png"; |
|---|
| 537 |
} |
|---|
| 538 |
$label = '<span><img width="16" height="16" border="0" title="'.$grpTEXT.'" alt="" src="'.$icon.'"/> '.$grpTEXT.'</span>'; |
|---|
| 539 |
$currentcomponent->addguielem('_top', new gui_link('findmefollowlink', $label, $grpURL)); |
|---|
| 540 |
} |
|---|
| 541 |
} |
|---|
| 542 |
|
|---|
| 543 |
// If we are auto-creating a followme for each extension then add the hook funcitons for |
|---|
| 544 |
// extensions and users. |
|---|
| 545 |
// |
|---|
| 546 |
if ($amp_conf['FOLLOWME_AUTO_CREATE']) { |
|---|
| 547 |
function findmefollow_configprocess() { |
|---|
| 548 |
global $amp_conf; |
|---|
| 549 |
|
|---|
| 550 |
//create vars from the request |
|---|
| 551 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 552 |
$ext = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 553 |
$extn = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; |
|---|
| 554 |
|
|---|
| 555 |
if ($ext=='') { |
|---|
| 556 |
$extdisplay = $extn; |
|---|
| 557 |
} else { |
|---|
| 558 |
$extdisplay = $ext; |
|---|
| 559 |
} |
|---|
| 560 |
if ($action == "add") { |
|---|
| 561 |
if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) { |
|---|
| 562 |
|
|---|
| 563 |
$ddial = $amp_conf['FOLLOWME_DISABLED'] ? 'CHECKED' : ''; |
|---|
| 564 |
findmefollow_add($extdisplay, $amp_conf['FOLLOWME_RG_STRATEGY'], $amp_conf['FOLLOWME_TIME'], |
|---|
| 565 |
$extdisplay, "", "", "", "", "", "", "","", $amp_conf['FOLLOWME_PRERING'], $ddial,'default',''); |
|---|
| 566 |
} |
|---|
| 567 |
} |
|---|
| 568 |
} |
|---|
| 569 |
} |
|---|
| 570 |
|
|---|
| 571 |
// we only return the destination that other modules might use, e.g. extenions/users |
|---|
| 572 |
function findmefollow_getdest($exten) { |
|---|
| 573 |
return array('ext-findmefollow,FM' . $exten . ',1'); |
|---|
| 574 |
} |
|---|
| 575 |
|
|---|
| 576 |
function findmefollow_getdestinfo($dest) { |
|---|
| 577 |
if (substr(trim($dest),0,17) == 'ext-findmefollow,' || substr(trim($dest),0,10) == 'ext-local,' && substr(trim($dest),-4) == 'dest') { |
|---|
| 578 |
$grp = explode(',',$dest); |
|---|
| 579 |
$grp = ltrim($grp[1],'FM'); |
|---|
| 580 |
$thisgrp = findmefollow_get($grp); |
|---|
| 581 |
if (empty($thisgrp)) { |
|---|
| 582 |
return array(); |
|---|
| 583 |
} else { |
|---|
| 584 |
return array('description' => sprintf(_("Follow Me: %s"),urlencode($grp)), |
|---|
| 585 |
'edit_url' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($grp), |
|---|
| 586 |
); |
|---|
| 587 |
} |
|---|
| 588 |
} else { |
|---|
| 589 |
return false; |
|---|
| 590 |
} |
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
function findmefollow_check_destinations($dest=true) { |
|---|
| 594 |
global $active_modules; |
|---|
| 595 |
|
|---|
| 596 |
$destlist = array(); |
|---|
| 597 |
if (is_array($dest) && empty($dest)) { |
|---|
| 598 |
return $destlist; |
|---|
| 599 |
} |
|---|
| 600 |
$sql = "SELECT grpnum, postdest, name FROM findmefollow INNER JOIN users ON grpnum = extension "; |
|---|
| 601 |
if ($dest !== true) { |
|---|
| 602 |
$sql .= "WHERE postdest in ('".implode("','",$dest)."')"; |
|---|
| 603 |
} |
|---|
| 604 |
$results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 605 |
|
|---|
| 606 |
//$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup'; |
|---|
| 607 |
|
|---|
| 608 |
foreach ($results as $result) { |
|---|
| 609 |
$thisdest = $result['postdest']; |
|---|
| 610 |
$thisid = $result['grpnum']; |
|---|
| 611 |
$destlist[] = array( |
|---|
| 612 |
'dest' => $thisdest, |
|---|
| 613 |
'description' => sprintf(_("Follow-Me: %s (%s)"),$thisid,$result['name']), |
|---|
| 614 |
'edit_url' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($thisid), |
|---|
| 615 |
); |
|---|
| 616 |
} |
|---|
| 617 |
return $destlist; |
|---|
| 618 |
} |
|---|
| 619 |
|
|---|
| 620 |
function findmefollow_change_destination($old_dest, $new_dest) { |
|---|
| 621 |
$sql = 'UPDATE findmefollow SET postdest = "' . $new_dest . '" WHERE postdest = "' . $old_dest . '"'; |
|---|
| 622 |
sql($sql, "query"); |
|---|
| 623 |
} |
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
function findmefollow_recordings_usage($recording_id) { |
|---|
| 627 |
global $active_modules; |
|---|
| 628 |
|
|---|
| 629 |
$results = sql("SELECT `grpnum` FROM `findmefollow` WHERE `annmsg_id` = '$recording_id' OR `remotealert_id` = '$recording_id' OR `toolate_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 630 |
if (empty($results)) { |
|---|
| 631 |
return array(); |
|---|
| 632 |
} else { |
|---|
| 633 |
//$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup'; |
|---|
| 634 |
foreach ($results as $result) { |
|---|
| 635 |
$usage_arr[] = array( |
|---|
| 636 |
'url_query' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($result['grpnum']), |
|---|
| 637 |
'description' => sprintf(_("Follow-Me User: %s"),$result['grpnum']), |
|---|
| 638 |
); |
|---|
| 639 |
} |
|---|
| 640 |
return $usage_arr; |
|---|
| 641 |
} |
|---|
| 642 |
} |
|---|
| 643 |
|
|---|
| 644 |
function findmefollow_fmf_toggle($c) { |
|---|
| 645 |
global $ext; |
|---|
| 646 |
global $amp_conf; |
|---|
| 647 |
global $version; |
|---|
| 648 |
|
|---|
| 649 |
$id = "app-fmf-toggle"; // The context to be included |
|---|
| 650 |
$ext->addInclude('from-internal-additional', $id); // Add the include from from-internal |
|---|
| 651 |
|
|---|
| 652 |
$ext->add($id, $c, '', new ext_goto('start','s',$id)); |
|---|
| 653 |
$c = 's'; |
|---|
| 654 |
|
|---|
| 655 |
$ext->add($id, $c, 'start', new ext_answer('')); |
|---|
| 656 |
$ext->add($id, $c, '', new ext_wait('1')); |
|---|
| 657 |
$ext->add($id, $c, '', new ext_macro('user-callerid')); |
|---|
| 658 |
|
|---|
| 659 |
$ext->add($id, $c, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/followme/ddial)}" = "EXTENSION"]', 'activate')); |
|---|
| 660 |
$ext->add($id, $c, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/followme/ddial)}" = "DIRECT"]', 'deactivate','end')); |
|---|
| 661 |
|
|---|
| 662 |
$ext->add($id, $c, 'deactivate', new ext_setvar('DB(AMPUSER/${AMPUSER}/followme/ddial)', 'EXTENSION')); |
|---|
| 663 |
if ($amp_conf['USEDEVSTATE']) { |
|---|
| 664 |
$ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE')); |
|---|
| 665 |
$ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id)); |
|---|
| 666 |
} |
|---|
| 667 |
if ($amp_conf['FCBEEPONLY']) { |
|---|
| 668 |
$ext->add($id, $c, 'hook_off', new ext_playback('beep')); // $cmd,n,Playback(...) |
|---|
| 669 |
} else { |
|---|
| 670 |
$ext->add($id, $c, 'hook_off', new ext_playback('followme&de-activated')); |
|---|
| 671 |
} |
|---|
| 672 |
$ext->add($id, $c, 'end', new ext_macro('hangupcall')); |
|---|
| 673 |
|
|---|
| 674 |
$ext->add($id, $c, 'activate', new ext_setvar('DB(AMPUSER/${AMPUSER}/followme/ddial)', 'DIRECT')); |
|---|
| 675 |
if ($amp_conf['USEDEVSTATE']) { |
|---|
| 676 |
$ext->add($id, $c, '', new ext_setvar('STATE', 'INUSE')); |
|---|
| 677 |
$ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id)); |
|---|
| 678 |
} |
|---|
| 679 |
if ($amp_conf['FCBEEPONLY']) { |
|---|
| 680 |
$ext->add($id, $c, 'hook_on', new ext_playback('beep')); // $cmd,n,Playback(...) |
|---|
| 681 |
} else { |
|---|
| 682 |
$ext->add($id, $c, 'hook_on', new ext_playback('followme&activated')); |
|---|
| 683 |
} |
|---|
| 684 |
$ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 685 |
|
|---|
| 686 |
if ($amp_conf['USEDEVSTATE']) { |
|---|
| 687 |
$c = 'sstate'; |
|---|
| 688 |
$ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${AMPUSER}/device')); |
|---|
| 689 |
$ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return')); |
|---|
| 690 |
$ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}')); |
|---|
| 691 |
$ext->add($id, $c, '', new ext_setvar('ITER', '1')); |
|---|
| 692 |
$ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:FOLLOWME${CUT(DEVICES,&,${ITER})})','${STATE}')); |
|---|
| 693 |
$ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]')); |
|---|
| 694 |
$ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin')); |
|---|
| 695 |
$ext->add($id, $c, 'return', new ext_return()); |
|---|
| 696 |
} |
|---|
| 697 |
} |
|---|
| 698 |
?> |
|---|