📄 functions.inc.php
字号:
<?php// The destinations this module provides// returns a associative arrays with keys 'destination' and 'description'function core_destinations() { //get the list of meetmes $results = core_users_list(); if (isset($results)) { //get voicemail $uservm = getVoicemail(); $vmcontexts = array_keys($uservm); foreach ($results as $thisext) { $extnum = $thisext[0]; // search vm contexts for this extensions mailbox foreach ($vmcontexts as $vmcontext) { if(isset($uservm[$vmcontext][$extnum])){ // $vmname = $uservm[$vmcontext][$extnum]['name']; // $vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>'); $vmboxes[$extnum] = true; } } } } // return an associative array with destination and description // core provides both users and voicemail boxes as destinations if (isset($results)) { foreach($results as $result){ $extens[] = array('destination' => 'ext-local,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); if(isset($vmboxes[$result['0']])) { $extens[] = array('destination' => 'ext-local,${VM_PREFIX}'.$result['0'].',1', 'description' => 'voicemail box '.$result['0']); } } } if (isset($extens)) return $extens; else return null;}/* Generates dialplan for "core" components (extensions & inbound routing) We call this with retrieve_conf*/function core_get_config($engine) { global $ext; // is this the best way to pass this? $modulename = "core"; switch($engine) { case "asterisk": // FeatureCodes $fcc = new featurecode($modulename, 'userlogon'); $fc_userlogon = $fcc->getCodeActive(); unset($fcc); $fcc = new featurecode($modulename, 'userlogoff'); $fc_userlogoff = $fcc->getCodeActive(); unset($fcc); $fcc = new featurecode($modulename, 'zapbarge'); $fc_zapbarge = $fcc->getCodeActive(); unset($fcc); $fcc = new featurecode($modulename, 'simu_pstn'); $fc_simu_pstn = $fcc->getCodeActive(); unset($fcc); $fcc = new featurecode($modulename, 'simu_fax'); $fc_simu_fax = $fcc->getCodeActive(); unset($fcc); // Log on / off -- all in one context if ($fc_userlogoff != '' || $fc_userlogon != '') { $ext->addInclude('from-internal-additional', 'app-userlogonoff'); // Add the include from from-internal if ($fc_userlogoff != '') { $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_macro('user-logoff')); $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_hangup('')); } if ($fc_userlogon != '') { $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon')); $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup('')); $clen = strlen($fc_userlogon); $fc_userlogon = "_$fc_userlogon."; $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon,${EXTEN:'.$clen.'}')); $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup('')); } } // zap barge if ($fc_zapbarge != '') { $ext->addInclude('from-internal-additional', 'app-zapbarge'); // Add the include from from-internal $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_macro('user-callerid')); $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_setvar('GROUP()','${CALLERID(number)}')); $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_answer('')); $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_wait(1)); $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_zapbarge('')); $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_hangup('')); } // Simulate options (ext-test) if ($fc_simu_pstn != '' || $fc_simu_fax != '') { $ext->addInclude('from-internal-additional', 'ext-test'); // Add the include from from-internal if ($fc_simu_pstn != '') { $ext->add('ext-test', $fc_simu_pstn, '', new ext_goto('1', 's', 'from-pstn')); } if ($fc_simu_fax != '') { $ext->add('ext-test', $fc_simu_fax, '', new ext_goto('1', 'in_fax', 'ext-fax')); } $ext->add('ext-test', 'h', '', new ext_macro('hangupcall')); } /* inbound routing extensions */ $didlist = core_did_list(); if(is_array($didlist)){ $catchall = false; foreach($didlist as $item) { $did = core_did_get($item['extension'],$item['cidnum'],$item['channel']); $exten = $did['extension']; $cidnum = $did['cidnum']; $channel = $did['channel']; $exten = (empty($exten)?"s":$exten); $exten = $exten.(empty($cidnum)?"":"/".$cidnum); //if a CID num is defined, add it if (empty($channel)) $context = "ext-did"; else { $context = "macro-from-zaptel-{$channel}"; if (!isset($zapchan[$channel])) { // create the macro-from-zaptel-$chan context and load up the // startup settings $ext->add($context, 's', '', new ext_noop('Entering '.$context.' with DID = ${DID}')); $zapchan[$channel] = "unfinished"; } } //sub a blank extension with 's' $ext->add($context, $exten, '', new ext_setvar('FROM_DID',$exten)); if ($exten == "s" && $context == "ext-did") { //if the exten is s, then also make a catchall for undefined DIDs if it's not a zaptel route $catchaccount = "_X.".(empty($cidnum)?"":"/".$cidnum); if ($catchaccount == "_X.") $catchall = true; $ext->add($context, $catchaccount, '', new ext_NoOp('Catch-All DID Match - Found ${EXTEN} - You probably want a DID for this.')); $ext->add($context, $catchaccount, '', new ext_goto('1','s','ext-did')); } if ($item['faxexten'] != "default") { $ext->add($context, $exten, '', new ext_setvar('FAX_RX',$item['faxexten'])); } if (!empty($item['faxemail'])) { $ext->add($context, $exten, '', new ext_setvar('FAX_RX_EMAIL',$item['faxemail'])); } if ($item['answer'] == "1") { $ext->add($context, $exten, '', new ext_answer('')); $ext->add($context, $exten, '', new ext_wait($item['wait'])); } if ($item['answer'] == "2") { // NVFaxDetect $ext->add($context, $exten, '', new ext_answer('')); $ext->add($context, $exten, '', new ext_playtones('ring')); $ext->add($context, $exten, '', new ext_nvfaxdetect($item['wait'])); } if ($item['privacyman'] == "1") { $ext->add($context, $exten, '', new ext_macro('privacy-mgr')); } if (!empty($item['alertinfo'])) { $ext->add($context, $exten, '', new ext_setvar("__ALERT_INFO", $item['alertinfo'])); } // If we're doing a zaptel route, now we need to do the gotos ONLY IF it's the first time round. // Except for the fact that this doesn't work. Not at all. Dial returns -1 and hangs up the // call. This is fixed in 1.4 with TryExec(), but until then, we can't match on zap // _and_ anything else. When we decide to say 'Only 1.4!' then we can reenable this // and use TryExec(Goto..) and then check ${TRYSTATUS} for FAILED or SUCCESS. I didn't // bother actually writing that, as the syntax may change. //if (isset($zapchan[$channel]) && $zapchan[$channel] == "unfinished") { // $ext->add($context, 's', '', new ext_gotoif('$[ "${DID}" = "s" ]', 'nos', 'sok')); // $ext->add($context, 's', 'nos', new ext_noop('Skipping ${DID} because it is s')); // $ext->add($context, 's', '', new ext_goto("trycid")); // $ext->add($context, 's', 'sok', new ext_noop('Trying ${DID}')); // $ext->add($context, 's', '', new ext_goto("1", '${DID}')); // $ext->add($context, 's', 'trycid', new ext_gotoif('$[ "${CALLERID(num)}" = "" ]', 'nocid', 'cidok')); // $ext->add($context, 's', 'nocid', new ext_noop('Skipping empty CallerID Num')); // $ext->add($context, 's', '', new ext_goto("end")); // $ext->add($context, 's', 'cidok', new ext_noop('Trying ${DID}/${CALLERID(num)}')); // $ext->add($context, 's', '', new ext_goto("1", '${DID}/${CALLERID(num)}')); // $ext->add($context, 's', 'end', new ext_noop('End of macro init')); // Now set $zapchan[$channel] so we don't do this again $zapchan[$channel] = "set"; //} //the goto destination // destination field in 'incoming' database is backwards from what ext_goto expects $goto_context = strtok($did['destination'],','); $goto_exten = strtok(','); $goto_pri = strtok(','); $ext->add($context, $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context)); } // If there's not a catchall, make one with an error message if (!$catchall) { $ext->add('ext-did', 's', '', new ext_noop("No DID or CID Match")); $ext->add('ext-did', 's', '', new ext_answer('')); $ext->add('ext-did', 's', '', new ext_wait('2')); $ext->add('ext-did', 's', '', new ext_playback('ss-noservice')); $ext->add('ext-did', 's', '', new ext_sayalpha('${FROM_DID}')); $ext->add('ext-did', '_[*#X].', '', new ext_setvar('FROM_DID', '${EXTEN}')); $ext->add('ext-did', '_[*#X].', '', new ext_noop('Received an unknown call with DID set to ${EXTEN}')); $ext->add('ext-did', '_[*#X].', '', new ext_goto('1','s','ext-did')); } } /* MODIFIED (PL) * * Add Direct DIDs * * This functions creates a new context, ext-did-direct, used to route an incoming DID directly to the specified user. * The purpose is to use when a user has a personal external DID. This keeps it clean and easy to administer. * Any conflict with those routes will depend on which of the two contexts are included first in the extensions.conf file. * * Calls are sent to context from-did-direct though this feature. You must create that context in extenions.conf or * in extensions_custom.conf and it should look something like: * * [from-did-direct] * include => ext-grouppersonal * include => ext-local * * This is so that personal ring groups are used if they exist for the direct did and if not, then the local extension. * If the module is not implented, it will just go to the users extension. */ $directdidlist = core_directdid_list(); if(is_array($directdidlist)){ foreach($directdidlist as $item) { $exten = $item['directdid']; $ext->add('ext-did-direct', $exten, '', new ext_setvar('FROM_DID',$exten)); if (!empty($item['didalert'])) { $ext->add('ext-did-direct', $exten, '', new ext_setvar("_ALERT_INFO", $item['didalert'])); } $goto_context = 'from-did-direct'; $goto_exten = $item['extension']; $goto_pri = 1; $ext->add('ext-did-direct', $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context)); } } /* user extensions */ $ext->addInclude('from-internal-additional','ext-local'); $userlist = core_users_list(); if (is_array($userlist)) { foreach($userlist as $item) { $exten = core_users_get($item[0]); $vm = ($exten['voicemail'] == "disabled" ? "novm" : $exten['extension']); $ext->add('ext-local', $exten['extension'], '', new ext_macro('exten-vm',$vm.",".$exten['extension'])); $ext->add('ext-local', $exten['extension'], '', new ext_hangup('')); if($vm != "novm") { $ext->add('ext-local', '${VM_PREFIX}'.$exten['extension'], '', new ext_macro('vm',"$vm,DIRECTDIAL")); $ext->add('ext-local', '${VM_PREFIX}'.$exten['extension'], '', new ext_hangup('')); } $hint = core_hint_get($exten['extension']); if (!empty($hint)) $ext->addHint('ext-local', $exten['extension'], $hint); } } /* dialplan globals */ // modules should NOT use the globals table to store anything! // modules should use $ext->addGlobal("testvar","testval"); in their module_get_config() function instead // I'm cheating for core functionality - do as I say, not as I do ;-) $sql = "SELECT * FROM globals"; $globals = sql($sql,"getAll",DB_FETCHMODE_ASSOC); foreach($globals as $global) { $ext->addGlobal($global['variable'],$global['value']); } /* outbound routes */ // modules should use their own table for storage (and module_get_config() to add dialplan) // modules should NOT use the extension table to store anything! $sql = "SELECT application FROM extensions where context = 'outbound-allroutes' ORDER BY application"; $outrts = sql($sql,"getAll",DB_FETCHMODE_ASSOC); $ext->addInclude('from-internal-additional','outbound-allroutes'); $ext->add('outbound-allroutes', 'foo', '', new ext_noop('bar')); foreach($outrts as $outrt) { $ext->addInclude('outbound-allroutes',$outrt['application']); $sql = "SELECT * FROM extensions where context = '".$outrt['application']."' ORDER BY extension, CAST(priority AS UNSIGNED) ASC"; $thisrt = sql($sql,"getAll",DB_FETCHMODE_ASSOC); foreach($thisrt as $exten) { //if emergencyroute, then set channel var if(strpos($exten['args'],"EMERGENCYROUTE") !== false) $ext->add($outrt['application'], $exten['extension'], '', new ext_setvar("EMERGENCYROUTE",substr($exten['args'],15))); if(strpos($exten['args'],"dialout-trunk") !== false) $ext->add($outrt['application'], $exten['extension'], '', new ext_macro($exten['args'])); if(strpos($exten['args'],"dialout-enum") !== false) $ext->add($outrt['application'], $exten['extension'], '', new ext_macro($exten['args'])); if(strpos($exten['args'],"outisbusy") !== false) $ext->add($outrt['application'], $exten['extension'], '', new ext_macro("outisbusy")); } } general_generate_indications(); break; }}/* begin page.ampusers.php functions */function core_ampusers_get_actmodules($status) { $modules = find_allmodules(); //$return_modules = $modules; // add only modules of type=$status foreach(array_keys($modules) as $key) { //remove modules not matching status or type if(isset($modules[$key]['status']) && $modules[$key]['status'] == $status && isset($modules[$key]['type'])) { $return_modules[$key] = $modules[$key]; } } return $return_modules;}function core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections) { $sql = "INSERT INTO ampusers (username, password, extension_low, extension_high, deptname, sections) VALUES ("; $sql .= "'".$username."',"; $sql .= "'".$password."',"; $sql .= "'".$extension_low."',"; $sql .= "'".$extension_high."',"; $sql .= "'".$deptname."',"; $sql .= "'".implode(";",$sections)."');"; sql($sql,"query");}function core_ampusers_del($username) { $sql = "DELETE FROM ampusers WHERE username = '".$username."'"; sql($sql,"query");}function core_ampusers_list() { $sql = "SELECT username FROM ampusers ORDER BY username"; return sql($sql,"getAll");}/* end page.ampusers.php functions *//* begin page.did.php functions */function core_did_list(){ $sql = "SELECT * FROM incoming ORDER BY extension,cidnum";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -