| 1 |
<?php /* $Id: functions.inc.php 201 2006-10-13 21:40:20Z plindheimer $ */ |
|---|
| 2 |
|
|---|
| 3 |
//require('common/php-asmanager.php'); |
|---|
| 4 |
include_once('common/php-asmanager.php'); |
|---|
| 5 |
|
|---|
| 6 |
// The destinations this module provides |
|---|
| 7 |
// returns a associative arrays with keys 'destination' and 'description' |
|---|
| 8 |
function findmefollow_destinations() { |
|---|
| 9 |
//get the list of findmefollow |
|---|
| 10 |
$results = findmefollow_full_list(); |
|---|
| 11 |
|
|---|
| 12 |
// return an associative array with destination and description |
|---|
| 13 |
if (isset($results)) { |
|---|
| 14 |
foreach($results as $result){ |
|---|
| 15 |
$thisgrp = findmefollow_get(ltrim($result['0'])); |
|---|
| 16 |
$extens[] = array('destination' => 'ext-findmefollow,'.ltrim($result['0']).',1', 'description' => $thisgrp['grppre'].' <'.ltrim($result['0']).'>'); |
|---|
| 17 |
} |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
return isset($extens)?$extens:null; |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
/* Generates dialplan for findmefollow |
|---|
| 24 |
We call this with retrieve_conf |
|---|
| 25 |
*/ |
|---|
| 26 |
function findmefollow_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-findmefollow'); |
|---|
| 31 |
$contextname = 'ext-findmefollow'; |
|---|
| 32 |
$ringlist = findmefollow_full_list(); |
|---|
| 33 |
if (is_array($ringlist)) { |
|---|
| 34 |
foreach($ringlist as $item) { |
|---|
| 35 |
$grpnum = ltrim($item['0']); |
|---|
| 36 |
$grp = findmefollow_get($grpnum); |
|---|
| 37 |
|
|---|
| 38 |
$strategy = $grp['strategy']; |
|---|
| 39 |
$grptime = $grp['grptime']; |
|---|
| 40 |
$grplist = $grp['grplist']; |
|---|
| 41 |
$postdest = $grp['postdest']; |
|---|
| 42 |
$grppre = (isset($grp['grppre'])?$grp['grppre']:''); |
|---|
| 43 |
$annmsg = $grp['annmsg']; |
|---|
| 44 |
$dring = $grp['dring']; |
|---|
| 45 |
|
|---|
| 46 |
$needsconf = $grp['needsconf']; |
|---|
| 47 |
$remotealert = $grp['remotealert']; |
|---|
| 48 |
$toolate = $grp['toolate']; |
|---|
| 49 |
$ringing = $grp['ringing']; |
|---|
| 50 |
$pre_ring = $grp['pre_ring']; |
|---|
| 51 |
|
|---|
| 52 |
if($ringing == 'Ring' || empty($ringing) ) { |
|---|
| 53 |
$dialopts = '${DIAL_OPTIONS}'; |
|---|
| 54 |
} else { |
|---|
| 55 |
// We need the DIAL_OPTIONS variable |
|---|
| 56 |
$sops = sql("SELECT value from globals where variable='DIAL_OPTIONS'", "getRow"); |
|---|
| 57 |
$dialopts = "m(${ringing})".str_replace('r', '', $sops[0]); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
$ext->add($contextname, $grpnum, '', new ext_macro('user-callerid')); |
|---|
| 62 |
|
|---|
| 63 |
// deal with group CID prefix |
|---|
| 64 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RGPREFIX}" = "foo"]', 'REPCID')); |
|---|
| 65 |
$ext->add($contextname, $grpnum, '', new ext_noop('Current RGPREFIX is ${RGPREFIX}....stripping from Caller ID')); |
|---|
| 66 |
$ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):${LEN(${RGPREFIX})}}')); |
|---|
| 67 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RGPREFIX', '')); |
|---|
| 68 |
$ext->add($contextname, $grpnum, 'REPCID', new ext_noop('CALLERID(name) is ${CALLERID(name)}')); |
|---|
| 69 |
if ($grppre != '') { |
|---|
| 70 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RGPREFIX', $grppre)); |
|---|
| 71 |
$ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}')); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
// MODIFIED (PL) |
|---|
| 75 |
// Add Alert Info if set |
|---|
| 76 |
// |
|---|
| 77 |
if ((isset($dring) ? $dring : '') != '') { |
|---|
| 78 |
$ext->add($contextname, $grpnum, '', new ext_setvar("_ALERT_INFO", str_replace(';', '\;', $dring))); |
|---|
| 79 |
} |
|---|
| 80 |
// If pre_ring is set, then ring this number of seconds prior to moving on |
|---|
| 81 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$[ ${DB(AMPUSER/'.$grpnum.'/followme/prering)} = 0 ]', 'skipsimple')); |
|---|
| 82 |
$ext->add($contextname, $grpnum, '', new ext_macro('simple-dial',$grpnum.',${DB(AMPUSER/'."$grpnum/followme/prering)}")); |
|---|
| 83 |
|
|---|
| 84 |
// recording stuff |
|---|
| 85 |
$ext->add($contextname, $grpnum, 'skipsimple', new ext_setvar('RecordMethod','Group')); |
|---|
| 86 |
$ext->add($contextname, $grpnum, '', new ext_macro('record-enable','${DB(AMPUSER/'."$grpnum/followme/grplist)}".',${RecordMethod}')); |
|---|
| 87 |
|
|---|
| 88 |
// group dial |
|---|
| 89 |
$ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',$strategy)); |
|---|
| 90 |
if ((isset($annmsg) ? $annmsg : '') != '') { |
|---|
| 91 |
// should always answer before playing anything, shouldn't we ? |
|---|
| 92 |
$ext->add($contextname, $grpnum, '', new ext_gotoif('$["${DIALSTATUS}" = "ANSWER"]','DIALGRP')); |
|---|
| 93 |
$ext->add($contextname, $grpnum, '', new ext_answer('')); |
|---|
| 94 |
$ext->add($contextname, $grpnum, '', new ext_wait(1)); |
|---|
| 95 |
$ext->add($contextname, $grpnum, '', new ext_playback($annmsg)); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
// Create the confirm target |
|---|
| 99 |
$len=strlen($grpnum)+4; |
|---|
| 100 |
$ext->add("grps", "_RG-${grpnum}-.", '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},". |
|---|
| 101 |
"M(confirm^${remotealert}^${toolate}^${grpnum})$dialopts".',${EXTEN:'.$len.'}')); |
|---|
| 102 |
|
|---|
| 103 |
// If grpconf == ENABLED call with confirmation ELSE call normal |
|---|
| 104 |
$ext->add($contextname, $grpnum, 'DIALGRP', new |
|---|
| 105 |
ext_gotoif('$[ "${DB(AMPUSER/'.$grpnum.'/followme/grpconf)}" = "ENABLED" ]', 'doconfirm')); |
|---|
| 106 |
|
|---|
| 107 |
// Normal call |
|---|
| 108 |
$ext->add($contextname, $grpnum, '', new |
|---|
| 109 |
ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)}")); |
|---|
| 110 |
$ext->add($contextname, $grpnum, '', new ext_goto('nextstep')); |
|---|
| 111 |
|
|---|
| 112 |
// Call Confirm call |
|---|
| 113 |
$ext->add($contextname, $grpnum, 'doconfirm', new |
|---|
| 114 |
ext_macro('dial-confirm','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)},".$grpnum)); |
|---|
| 115 |
|
|---|
| 116 |
$ext->add($contextname, $grpnum, 'nextstep', new ext_setvar('RingGroupMethod','')); |
|---|
| 117 |
|
|---|
| 118 |
// where next? |
|---|
| 119 |
if ((isset($postdest) ? $postdest : '') != '') { |
|---|
| 120 |
$ext->add($contextname, $grpnum, '', new ext_goto($postdest)); |
|---|
| 121 |
} else { |
|---|
| 122 |
$ext->add($contextname, $grpnum, '', new ext_hangup('')); |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
break; |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
function findmefollow_add($grpnum,$strategy,$grptime,$grplist,$postdest,$grppre='',$annmsg='',$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring) { |
|---|
| 131 |
global $amp_conf; |
|---|
| 132 |
|
|---|
| 133 |
$sql = "INSERT INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, dring, needsconf, remotealert, toolate, ringing, pre_ring) VALUES (".$grpnum.", '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $dring)."', '$needsconf', '$remotealert', '$toolate', '$ringing', '$pre_ring')"; |
|---|
| 134 |
|
|---|
| 135 |
$results = sql($sql); |
|---|
| 136 |
|
|---|
| 137 |
$astman = new AGI_AsteriskManager(); |
|---|
| 138 |
if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { |
|---|
| 139 |
$astman->database_put("AMPUSER",$grpnum."/followme/prering",isset($pre_ring)?$pre_ring:''); |
|---|
| 140 |
$astman->database_put("AMPUSER",$grpnum."/followme/grptime",isset($grptime)?$grptime:''); |
|---|
| 141 |
$astman->database_put("AMPUSER",$grpnum."/followme/grplist",isset($grplist)?$grplist:''); |
|---|
| 142 |
$confvalue = ($needsconf == 'CHECKED')?'ENABLED':'DISABLED'; |
|---|
| 143 |
$astman->database_put("AMPUSER",$grpnum."/followme/grpconf",isset($needsconf)?$confvalue:''); |
|---|
| 144 |
$astman->disconnect(); |
|---|
| 145 |
} else { |
|---|
| 146 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 147 |
} |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
function findmefollow_del($grpnum) { |
|---|
| 151 |
global $amp_conf; |
|---|
| 152 |
|
|---|
| 153 |
$results = sql("DELETE FROM findmefollow WHERE grpnum = $grpnum","query"); |
|---|
| 154 |
|
|---|
| 155 |
$astman = new AGI_AsteriskManager(); |
|---|
| 156 |
if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { |
|---|
| 157 |
$astman->database_del("AMPUSER",$grpnum."/followme/prering"); |
|---|
| 158 |
$astman->database_del("AMPUSER",$grpnum."/followme/grptime"); |
|---|
| 159 |
$astman->database_del("AMPUSER",$grpnum."/followme/grplist"); |
|---|
| 160 |
$astman->database_del("AMPUSER",$grpnum."/followme/grpconf"); |
|---|
| 161 |
$astman->disconnect(); |
|---|
| 162 |
} else { |
|---|
| 163 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
function findmefollow_full_list() { |
|---|
| 169 |
$results = sql("SELECT grpnum FROM findmefollow ORDER BY grpnum","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 170 |
foreach ($results as $result) { |
|---|
| 171 |
if (isset($result['grpnum']) && checkRange($result['grpnum'])) { |
|---|
| 172 |
$grps[] = array($result['grpnum']); |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
if (isset($grps)) |
|---|
| 176 |
return $grps; |
|---|
| 177 |
else |
|---|
| 178 |
return null; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
function findmefollow_list() { |
|---|
| 182 |
|
|---|
| 183 |
global $db; |
|---|
| 184 |
$sql = "SELECT grpnum FROM findmefollow ORDER BY grpnum"; |
|---|
| 185 |
$results = $db->getCol($sql); |
|---|
| 186 |
if(DB::IsError($results)) { |
|---|
| 187 |
$results = null; |
|---|
| 188 |
} |
|---|
| 189 |
if (isset($results)) { |
|---|
| 190 |
foreach($results as $result) { |
|---|
| 191 |
if (checkRange($result)){ |
|---|
| 192 |
$grps[] = $result; |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
} |
|---|
| 196 |
if (isset($grps)) { |
|---|
| 197 |
sort($grps); // hmm, should be sorted already |
|---|
| 198 |
return $grps; |
|---|
| 199 |
} |
|---|
| 200 |
else { |
|---|
| 201 |
return null; |
|---|
| 202 |
} |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
// This gets the list of all active users so that the Find Me Follow display can limit the options to only created users. |
|---|
| 206 |
// the returned arrays contain [0]:extension [1]:name |
|---|
| 207 |
// |
|---|
| 208 |
// This was pulled straight out of previous 1.x version, might need cleanup laster |
|---|
| 209 |
// |
|---|
| 210 |
function findmefollow_allusers() { |
|---|
| 211 |
global $db; |
|---|
| 212 |
$sql = "SELECT extension,name FROM users ORDER BY extension"; |
|---|
| 213 |
$results = $db->getAll($sql); |
|---|
| 214 |
if(DB::IsError($results)) { |
|---|
| 215 |
$results = null; |
|---|
| 216 |
} |
|---|
| 217 |
foreach($results as $result){ |
|---|
| 218 |
if (checkRange($result[0])){ |
|---|
| 219 |
$users[] = array($result[0],$result[1]); |
|---|
| 220 |
} |
|---|
| 221 |
} |
|---|
| 222 |
if (isset($users)) sort($users); |
|---|
| 223 |
return $users; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
// Only check astdb if check_astdb is not 0. For some reason, this fails if the asterisk manager code |
|---|
| 227 |
// is included (executed) by all calls to this function. This results in silently not generating the |
|---|
| 228 |
// extensions_additional.conf file. page.findmefollow.php does set it to 1 which means that when running |
|---|
| 229 |
// the GUI, any changes not reflected in SQL will be detected and written back to SQL so that they are |
|---|
| 230 |
// in sync. Ideally, anything that changes the astdb should change SQL. (in some ways, these should both |
|---|
| 231 |
// not be here but ... |
|---|
| 232 |
// |
|---|
| 233 |
function findmefollow_get($grpnum, $check_astdb=0) { |
|---|
| 234 |
global $amp_conf; |
|---|
| 235 |
|
|---|
| 236 |
$results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, dring, needsconf, remotealert, toolate, ringing, pre_ring FROM findmefollow WHERE grpnum = $grpnum","getRow",DB_FETCHMODE_ASSOC); |
|---|
| 237 |
|
|---|
| 238 |
if ($check_astdb) { |
|---|
| 239 |
$astman = new AGI_AsteriskManager(); |
|---|
| 240 |
if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { |
|---|
| 241 |
$astdb_prering = $astman->database_get("AMPUSER",$grpnum."/followme/prering"); |
|---|
| 242 |
$astdb_grptime = $astman->database_get("AMPUSER",$grpnum."/followme/grptime"); |
|---|
| 243 |
$astdb_grplist = $astman->database_get("AMPUSER",$grpnum."/followme/grplist"); |
|---|
| 244 |
$astdb_grpconf = $astman->database_get("AMPUSER",$grpnum."/followme/grpconf"); |
|---|
| 245 |
$astman->disconnect(); |
|---|
| 246 |
} else { |
|---|
| 247 |
fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 248 |
} |
|---|
| 249 |
// If the values are different then use what is in astdb as it may have been changed. |
|---|
| 250 |
// |
|---|
| 251 |
$changed=0; |
|---|
| 252 |
if (($astdb_prering != $results['pre_ring']) && ($astdb_prering >= 0)) { |
|---|
| 253 |
$results['pre_ring'] = $astdb_prering; |
|---|
| 254 |
$changed=1; |
|---|
| 255 |
} |
|---|
| 256 |
if (($astdb_grptime != $results['grptime']) && ($astdb_grptime > 0)) { |
|---|
| 257 |
$results['grptime'] = $astdb_grptime; |
|---|
| 258 |
$changed=1; |
|---|
| 259 |
} |
|---|
| 260 |
if ((trim($astdb_grplist) != trim($results['grplist'])) && (trim($astdb_grplist) != '')) { |
|---|
| 261 |
$results['grplist'] = $astdb_grplist; |
|---|
| 262 |
$changed=1; |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
if (trim($astdb_grpconf) == 'ENABLED') { |
|---|
| 266 |
$confvalue = 'CHECKED'; |
|---|
| 267 |
} elseif (trim($astdb_grpconf) == 'DISABLED') { |
|---|
| 268 |
$confvalue = ''; |
|---|
| 269 |
} else { |
|---|
| 270 |
//Bogus value, should not get here but treat as disabled |
|---|
| 271 |
$confvalue = ''; |
|---|
| 272 |
} |
|---|
| 273 |
if ($confvalue != trim($results['needsconf'])) { |
|---|
| 274 |
$results['needsconf'] = $confvalue; |
|---|
| 275 |
$changed=1; |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
if ($changed) { |
|---|
| 279 |
$sql = "UPDATE findmefollow SET grptime = '".$results['grptime']."', grplist = '". |
|---|
| 280 |
str_replace("'", "''", trim($results['grplist']))."', pre_ring = '".$results['pre_ring']. |
|---|
| 281 |
"', needsconf = '".$results['needsconf']."' WHERE grpnum = $grpnum LIMIT 1"; |
|---|
| 282 |
$sql_results = sql($sql); |
|---|
| 283 |
} |
|---|
| 284 |
} // if check_astdb |
|---|
| 285 |
|
|---|
| 286 |
return $results; |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
function findmefollow_configpageinit($dispnum) { |
|---|
| 290 |
global $currentcomponent; |
|---|
| 291 |
|
|---|
| 292 |
if ( ($dispnum == 'users' || $dispnum == 'extensions') ) { |
|---|
| 293 |
$currentcomponent->addguifunc('findmefollow_configpageload'); |
|---|
| 294 |
} |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
function findmefollow_configpageload() { |
|---|
| 298 |
global $currentcomponent; |
|---|
| 299 |
|
|---|
| 300 |
$viewing_itemid = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 301 |
if ( $viewing_itemid != '' ) { |
|---|
| 302 |
$set_findmefollow = findmefollow_list(); |
|---|
| 303 |
$grpURL = $_SERVER['PHP_SELF'].'?'.'display=findmefollow&extdisplay=GRP-'.$viewing_itemid; |
|---|
| 304 |
if (is_array($set_findmefollow)) { |
|---|
| 305 |
$grpTEXT = (in_array($viewing_itemid,$set_findmefollow) ? "Edit" : "Add")." Follow Me Settings"; |
|---|
| 306 |
} else { |
|---|
| 307 |
$grpTEXT = "Add Follow Me Settings"; |
|---|
| 308 |
} |
|---|
| 309 |
$currentcomponent->addguielem('_top', new gui_link('findmefollowlink', $grpTEXT, $grpURL)); |
|---|
| 310 |
} |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
// this function builds the AMPUSE/<grpnum>/followme tree for each user who has a group number |
|---|
| 315 |
// it's purpose is to convert after an upgrade |
|---|
| 316 |
// |
|---|
| 317 |
function findmefollow_users2astdb(){ |
|---|
| 318 |
checkAstMan(); |
|---|
| 319 |
global $amp_conf; |
|---|
| 320 |
$sql = "SELECT * FROM findmefollow"; |
|---|
| 321 |
$userresults = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 322 |
|
|---|
| 323 |
//add details to astdb |
|---|
| 324 |
$astman = new AGI_AsteriskManager(); |
|---|
| 325 |
if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { |
|---|
| 326 |
foreach($userresults as $usr) { |
|---|
| 327 |
|
|---|
| 328 |
extract($usr); |
|---|
| 329 |
|
|---|
| 330 |
$astman->database_put("AMPUSER",$grpnum."/followme/prering",isset($pre_ring)?$pre_ring:''); |
|---|
| 331 |
$astman->database_put("AMPUSER",$grpnum."/followme/grptime",isset($grptime)?$grptime:''); |
|---|
| 332 |
$astman->database_put("AMPUSER",$grpnum."/followme/grplist",isset($grplist)?$grplist:''); |
|---|
| 333 |
$confvalue = ($needsconf == 'CHECKED')?'ENABLED':'DISABLED'; |
|---|
| 334 |
$astman->database_put("AMPUSER",$grpnum."/followme/grpconf",isset($needsconf)?$confvalue:''); |
|---|
| 335 |
} |
|---|
| 336 |
} else { |
|---|
| 337 |
echo _("Cannot connect to Asterisk Manager with ").$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]; |
|---|
| 338 |
} |
|---|
| 339 |
return $astman->disconnect(); |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
?> |
|---|