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