📄 functions.php
字号:
addextensions($addarray); $addarray = array('ext-queues',$account,'3','SetVar','MONITOR_FILENAME=/var/spool/asterisk/monitor/q${EXTEN}-${TIMESTAMP}-${UNIQUEID}','','0'); addextensions($addarray); $addarray = array('ext-queues',$account,'4','Playback','custom/'.$joinannounce,'','0'); addextensions($addarray); $addarray = array('ext-queues',$account,'5','Queue',$account.'|t||'.$agentannounce.'|'.$_REQUEST['maxwait'],$name,'0'); addextensions($addarray); $addarray = array('ext-queues',$account.'*','1','Macro','agent-add,'.$account.','.$password,'','0'); addextensions($addarray); $addarray = array('ext-queues',$account.'**','1','Macro','agent-del,'.$account,'','0'); addextensions($addarray); //failover goto setGoto($account,'ext-queues','6',$goto,0); // now add to queues table $fields = array( array($account,'account',$account), array($account,'maxlen',($_REQUEST['maxlen'])?$_REQUEST['maxlen']:'0'), array($account,'joinempty',($_REQUEST['joinempty'])?$_REQUEST['joinempty']:'yes'), array($account,'leavewhenempty',($_REQUEST['leavewhenempty'])?$_REQUEST['leavewhenempty']:'no'), array($account,'strategy',($_REQUEST['strategy'])?$_REQUEST['strategy']:'ringall'), array($account,'timeout',($_REQUEST['timeout'])?$_REQUEST['timeout']:'15'), array($account,'retry',($_REQUEST['retry'])?$_REQUEST['retry']:'5'), array($account,'wrapuptime',($_REQUEST['wrapuptime'])?$_REQUEST['wrapuptime']:'0'), //array($account,'agentannounce',($_REQUEST['agentannounce'])?$_REQUEST['agentannounce']:'None'), array($account,'announce-frequency',($_REQUEST['announcefreq'])?$_REQUEST['announcefreq']:'0'), array($account,'announce-holdtime',($_REQUEST['announceholdtime'])?$_REQUEST['announceholdtime']:'no'), array($account,'queue-youarenext',($_REQUEST['announceposition']=='no')?'':'queue-youarenext'), //if no, play no sound array($account,'queue-thereare',($_REQUEST['announceposition']=='no')?'':'queue-thereare'), //if no, play no sound array($account,'queue-callswaiting',($_REQUEST['announceposition']=='no')?'':'queue-callswaiting'), //if no, play no sound array($account,'queue-thankyou',($_REQUEST['announcemenu']=='none')?'queue-thankyou':'custom/'.$_REQUEST['announcemenu']), //if none, play default thankyou, else custom/aa array($account,'context',($_REQUEST['announcemenu']=='none')?'':$_REQUEST['announcemenu']), //if not none, set context=aa array($account,'monitor-format',($_REQUEST['monitor-format'])?$_REQUEST['monitor-format']:''), array($account,'monitor-join','yes'), array($account,'music',($_REQUEST['music'])?$_REQUEST['music']:'default')); //there can be multiple members if (isset($members)) { foreach ($members as $member) { $fields[] = array($account,'member',$member); } } $compiled = $db->prepare('INSERT INTO queues (id, keyword, data) values (?,?,?)'); $result = $db->executeMultiple($compiled,$fields); if(DB::IsError($result)) { die($result->getMessage()."<br><br>error adding to queues table"); }}//obsoletefunction delqueue($account) { global $db; //delete from extensions table delextensions('ext-queues',$account); delextensions('ext-queues',$account.'*'); delextensions('ext-queues',$account.'**'); $sql = "DELETE FROM queues WHERE id = '$account'"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); }}//obsoletefunction getqueueinfo($account) { global $db; if ($account == "") { return array(); } //get all the variables for the queue $sql = "SELECT keyword,data FROM queues WHERE id = '$account'"; $results = $db->getAssoc($sql); //okay, but there can be multiple member variables ... do another select for them $sql = "SELECT data FROM queues WHERE id = '$account' AND keyword = 'member'"; $results['member'] = $db->getCol($sql); //queues.php looks for 'announcemenu', which is the same a context $results['announcemenu'] = $results['context']; //if 'queue-youarenext=queue-youarenext', then assume we want to announce position if($results['queue-youarenext'] == 'queue-youarenext') $results['announce-position'] = 'yes'; else $results['announce-position'] = 'no'; //get CID Prefix $sql = "SELECT args FROM extensions WHERE extension = '$account' AND context = 'ext-queues' AND application = 'SetCIDName'"; list($args) = $db->getRow($sql); $prefix = explode('$',$args); //in table like prefix${CALLERIDNAME} $results['prefix'] = $prefix[0]; //get max wait time from Queue command $sql = "SELECT args,descr FROM extensions WHERE extension = '$account' AND context = 'ext-queues' AND application = 'Queue'"; list($args, $descr) = $db->getRow($sql); $maxwait = explode('|',$args); //in table like queuenum|t|||maxwait $results['agentannounce'] = $maxwait[3]; $results['maxwait'] = $maxwait[4]; $results['name'] = $descr; $sql = "SELECT args FROM extensions WHERE extension = '$account' AND context = 'ext-queues' and application = 'Playback'"; list($args) = $db->getRow($sql); $results['joinannounce'] = $args; //get password from AddQueueMember command $sql = "SELECT args FROM extensions WHERE extension = '$account*' AND context = 'ext-queues'"; list($args) = $db->getRow($sql); $password = explode(',',$args); //in table like agent-add,account,password $results['password'] = $password[2]; //get the failover destination (desc=jump) $sql = "SELECT args FROM extensions WHERE extension = '".$account."' AND descr = 'jump'"; list($args) = $db->getRow($sql); $results['goto'] = $args; return $results;}/* moved to functions.inc.php// $formName is the name of the form we are drawing in// $goto is the current goto destination setting// $i is the destination set number (used when drawing multiple destination sets in a single form ie: digital receptionist)function drawselects($goto,$i) { //query for exisiting aa_N contexts $unique_aas = getaas(); //get unique extensions $extens = getextens(); //get unique ring groups $gresults = getgroups(); //get unique queues $queues = getqueues(); if (isset($extens)) { //get voicemail $uservm = getVoicemail(); $vmcontexts = array_keys($uservm); foreach ($extens 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[] = array($extnum, '"' . $vmname . '" <' . $extnum . '>'); } } } } $selectHtml = ' <tr><td colspan=2><input type="hidden" name="goto'.$i.'" value="">'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="ivr" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'ivr\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'ivr\';" '.(strpos($goto,'aa_') === false ? '' : 'CHECKED=CHECKED').' /> '._("Digital Receptionist").': '; $selectHtml .= '<select name="ivr'.$i.'">'; if (isset($unique_aas)) { foreach ($unique_aas as $unique_aa) { $menu_id = $unique_aa[0]; $menu_name = $unique_aa[1]; $selectHtml .= '<option value="'.$menu_id.'" '.(strpos($goto,$menu_id) === false ? '' : 'SELECTED').'>'.($menu_name ? $menu_name : 'Menu ID'.$menu_id) . '</option>'; } } $selectHtml .= '</select><br>'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="extension" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'extension\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'extension\';" '.(strpos($goto,'ext-local') === false ? '' : 'CHECKED=CHECKED').'/> '._("Extension").': '; $selectHtml .= '<select name="extension'.$i.'">'; if (isset($extens)) { foreach ($extens as $exten) { $selectHtml .= '<option value="'.$exten[0].'" '.(strpos($goto,$exten[0]) === false ? '' : 'SELECTED').'>'.$exten[1] . ' <'.$exten[0].'></option>'; } } $selectHtml .= '</select><br>'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="voicemail" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'voicemail\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'voicemail\';" '.(strpos($goto,'vm') === false ? '' : 'CHECKED=CHECKED').(strpos($goto,'ext-local,${VM_PREFIX}') === false ? '' : 'CHECKED=CHECKED').' /> '._("Voicemail").': '; $selectHtml .= '<select name="voicemail'.$i.'">'; if (isset($vmboxes)) { foreach ($vmboxes as $exten) { $selectHtml .= '<option value="'.$exten[0].'" '.(strpos($goto,$exten[0]) === false ? '' : 'SELECTED').'>'.$exten[1] . '</option>'; } } $selectHtml .= '</select><br>'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="group" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'group\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'group\';" '.(strpos($goto,'ext-group') === false ? '' : 'CHECKED=CHECKED').' /> '._("Ring Group").': '; $selectHtml .= '<select name="group'.$i.'">'; if (isset($gresults)) { foreach ($gresults as $gresult) { $selectHtml .= '<option value="'.$gresult[0].'" '.(strpos( ','.$goto.',' , ','.$gresult[0].',' ) === false ? '' : 'SELECTED').'>#'.$gresult[0] . '</option>'; } } $selectHtml .= '</select><br>'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="queue" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'queue\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'queue\';" '.(strpos($goto,'ext-queues') === false ? '' : 'CHECKED=CHECKED').' /> '._("Queue").': '; $selectHtml .= '<select name="queue'.$i.'">'; if (isset($queues)) { foreach ($queues as $queue) { $selectHtml .= '<option value="'.$queue[0].'" '.(strpos($goto,$queue[0]) === false ? '' : 'SELECTED').'>'.$queue[0].':'.$queue[1] . '</option>'; } } $selectHtml .= '</select><br>'; $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="custom" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'custom\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'custom\';" '.(strpos($goto,'custom') === false ? '' : 'CHECKED=CHECKED').' />'; $selectHtml .= '<a href="#" class="info"> '._("Custom App<span><br>ADVANCED USERS ONLY<br><br>Uses Goto() to send caller to a custom context.<br><br>The context name <b>MUST</b> contain the word 'custom' and should be in the format custom-context , extension , priority. Example entry:<br><br><b>custom-myapp,s,1</b><br><br>The <b>[custom-myapp]</b> context would need to be created and included in extensions_custom.conf</span>").'</a>:'; $selectHtml .= '<input type="text" size="15" name="custom_args'.$i.'" value="'.(strpos($goto,'custom') === false ? '' : $goto).'" />'; global $active_modules; $selectHtml .= '<tr><td colspan=2><input type="hidden" name="goto'.$i.'" value="">'; //check for module-specific destination functions foreach ($active_modules as $mod) { $funct = strtolower($mod.'_destinations'); //if the modulename_destinations() function exits, run it and display selections for it if (function_exists($funct)) { $destArray = $funct(); //returns an array with 'destination' and 'description'. $checked = false; if (isset($destArray)) { //loop through each option returned by the module foreach ($destArray as $dest) { // check to see if the currently selected goto matches one these destinations if ($dest['destination'] == $goto) $checked = true; //there is a match, so we select the radio for this group // create an select option for each destination $options .= '<option value="'.$dest['destination'].'" '.(strpos($goto,$dest['destination']) === false ? '' : 'SELECTED').'>'.($dest['description'] ? $dest['description'] : $dest['destination']); } } $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="'.$mod.'" onclick="javascript:this.form.goto'.$i.'.value=\''.$mod.'\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) this.form.goto'.$i.'.value=\''.$mod.'\';" '.($checked? 'CHECKED=CHECKED' : '').' /> '._($mod).': '; $selectHtml .= '<select name="'.$mod.$i.'"/>'; $selectHtml .= $options; $selectHtml .= '</select><br>'; } } //display a custom goto field $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="custom" onclick="javascript:document.'.$formName.'.goto'.$i.'.value=\'custom\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) document.'.$formName.'.goto'.$i.'.value=\'custom\';" '.(strpos($goto,'custom') === false ? '' : 'CHECKED=CHECKED').' />'; $selectHtml .= '<a href="#" class="info"> '._("Custom App<span><br>ADVANCED USERS ONLY<br><br>Uses Goto() to send caller to a custom context.<br><br>The context name <b>MUST</b> contain the word 'custom' and should be in the format custom-context , extension , priority. Example entry:<br><br><b>custom-myapp,s,1</b><br><br>The <b>[custom-myapp]</b> context would need to be created and included in extensions_custom.conf</span>").'</a>:'; $selectHtml .= '<input type="text" size="15" name="custom_args'.$i.'" value="'.(strpos($goto,'custom') === false ? '' : $goto).'" />'; //close off our row $selectHtml .= '</td></tr>'; return $selectHtml;}*///obsoletefunction setGoto($account,$context,$priority,$goto,$i) { //preforms logic for setting goto destinations if ($goto == 'extension') { $args = 'ext-local,'.$_REQUEST['extension'.$i].',1'; $addarray = array($context,$account,$priority,'Goto',$args,'jump','0'); addextensions($addarray); } elseif ($goto == 'voicemail') { $args = 'vm,'.$_REQUEST['voicemail'.$i]; $addarray = array($context,$account,$priority,'Macro',$args,'jump','0'); addextensions($addarray); } elseif ($goto == 'ivr') { $args = $_REQUEST['ivr'.$i].',s,1'; $addarray = array($context,$account,$priority,'Goto',$args,'jump','0'); addextensions($addarray); } elseif ($goto == 'group') { $args = 'ext-group,'.$_REQUEST['group'.$i].',1'; $addarray = array($context,$account,$priority,'Goto',$args,'jump','0'); addextensions($addarray); } elseif ($goto == 'custom') { $args = $_REQUEST['custom_args'.$i]; $addarray = array($context,$account,$priority,'Goto',$args,'jump','0'); addextensions($addarray); } elseif ($goto == 'queue') { $args = 'ext-queues,'.$_REQUEST['queue'.$i ].',1'; $addarray = array($context,$account,$priority,'Goto',$args,'jump','0'); addextensions($addarray); }}/*// the old drawselects stuff above builds the select forms using abbreviated goto names.. // setGoto then translates these into a full goto string, which is used in the dialplan.// terrible, I know. New functionality, like Inbound Routing, stores the "full goto" string in it's table// This function just returns what the full goto is supposed to be. (will bo obsolete in AMP2).function buildActualGoto($requestarray,$i) { switch($requestarray['goto'.$i]) { case 'extension': return 'ext-local,'.$requestarray['extension'.$i].',1'; break; case 'voicemail': return 'ext-local,${VM_PREFIX}'.$requestarray['voicemail'.$i].',1'; break; case 'ivr': return $requestarray['ivr'.$i].',s,1'; break; case 'group': return 'ext-group,'.$requestarray['group'.$i].',1'; break; case 'custom': return $requestarray['custom_args'.$i]; break; case 'queue': return 'ext-queues,'.$requestarray['queue'.$i ].',1'; break; default: return $requestarray['goto'.$i]; break; }}*///get args for specified exten and priority - primarily used to grab goto destination//obsoletefunction getargs($exten,$priority,$context) { global $db; $sql = "SELECT args FROM extensions WHERE extension = '".$exten."' AND priority = '".$priority."' AND context = '".$context."'"; list($args) = $db->getRow($sql); return $args;}//obsoletefunction addgroup($account,$grplist,$grpstrategy,$grptime,$grppre,$goto) { global $db; $addarray = array('ext-group',$account,'1','Macro','rg-group,'.$grpstrategy.','.$grptime.','.$grppre.','.$grplist,'','0'); addextensions($addarray); setGoto($account,'ext-group','2',$goto,0);}//obsoletefunction getsystemrecordings($path) { $i = 0; $arraycount = 0; if (is_dir($path)){ if ($handle = opendir($path)){ while (false !== ($file = readdir($handle))){ if (($file != ".") && ($file != "..") && ($file != "CVS") && (strpos($file, "aa_") === FALSE) ) { $file_parts=explode(".",$file); $filearray[($i++)] = $file_parts[0]; } } closedir($handle); } } if (isset($filearray)) sort($filearray); return ($filearray);}//obsoletefunction getmusiccategory($path) { $i = 0; $arraycount = 0; if (is_dir($path)){ if ($handle = opendir($path)){ while (false !== ($file = readdir($handle))){ if ( ($file != ".") && ($file != "..") && ($file != "CVS") ) { if (is_dir("$path/$file")) $filearray[($i++)] = "$file"; } } cl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -