📄 functions.php
字号:
<?php /* $id$ *///Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)////This program is free software; you can redistribute it and/or//modify it under the terms of the GNU General Public License//as published by the Free Software Foundation; either version 2//of the License, or (at your option) any later version.////This program is distributed in the hope that it will be useful,//but WITHOUT ANY WARRANTY; without even the implied warranty of//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the//GNU General Public License for more details./* everything in this file is obsolete!!= *///get unique voice menu numbers - returns 2 dimensional array//obsoletefunction getaas() { global $db; $dept = str_replace(' ','_',$_SESSION["AMP_user"]->_deptname); if (empty($dept)) $dept='%'; //if we are not restricted to dept (ie: admin), then display all AA menus $sql = "SELECT context,descr FROM extensions WHERE extension = 's' AND application LIKE 'DigitTimeout' AND context LIKE '".$dept."aa_%' ORDER BY context"; $unique_aas = $db->getAll($sql); if(DB::IsError($unique_aas)) { die('unique: '.$unique_aas->getMessage().'<hr>'.$sql); } return $unique_aas;}// get the existing extensions// the returned arrays contain [0]:extension [1]:name//obsoletefunction getextens() { global $db; $sql = "SELECT extension,name FROM users ORDER BY extension"; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = null; } foreach($results as $result){ if (checkRange($result[0])){ $extens[] = array($result[0],$result[1]); } } if (isset($extens)) sort($extens); return $extens;}//get the existing devices//obsoletefunction getdevices() { global $db; $sql = "SELECT id,description FROM devices"; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = null; } foreach($results as $result){ if (checkRange($result[0])){ $extens[] = array($result[0],$result[1]); } } if (isset($extens)) sort($extens); return $extens;}//get the existing group extensions//obsoletefunction getgroups() { global $db; $sql = "SELECT DISTINCT extension FROM extensions WHERE context = 'ext-group' ORDER BY extension"; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = null; } foreach($results as $result){ if (checkRange($result[0])){ $extens[] = array($result[0]); } } return $extens;}//get the existing queue extensions//obsoletefunction getqueues() { global $db; $sql = "SELECT extension,descr FROM extensions WHERE application = 'Queue' ORDER BY extension"; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = null; } foreach($results as $result){ if (checkRange($result[0])){ $extens[] = array($result[0],$result[1]); } } return $extens;}//get the existing did extensionsfunction getdids() { global $db; $sql = "SELECT extension FROM extensions WHERE context = 'ext-did' and priority ='1' ORDER BY extension"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } return $results;}//get goto in specified groupfunction getgroupgoto($grpexten) { global $db; $sql = "SELECT args FROM extensions WHERE extension = '".$grpexten."' AND (args LIKE 'ext-local,%,%' OR args LIKE 'vm,%' OR args LIKE 'aa_%,%,%' OR args LIKE 'ext-group,%,%' OR args LIKE 'from-pstn,s,1' OR args LIKE '%custom%')"; $thisGRPgoto = $db->getAll($sql); if(DB::IsError($thisGRPgoto)) { die($thisGRPgoto->getMessage()); } return $thisGRPgoto;}//obsoletefunction getgroupinfo($grpexten, &$strategy, &$time, &$prefix, &$group) { global $db; $sql = "SELECT args FROM extensions WHERE context = 'ext-group' AND extension = '".$grpexten."' AND priority = '1'"; $res = $db->getAll($sql); if(DB::IsError($res)) { die($res->getMessage()); } if (preg_match("/^rg-group,(.*),(.*),(.*),(.*)$/", $res[0][0], $matches)) { $strategy = $matches[1]; $time = $matches[2]; $prefix = $matches[3]; $group = $matches[4]; return true; } return false;}//add to extensions table - used in callgroups.php//obsoletefunction addextensions($addarray) { global $db; $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ('".$addarray[0]."', '".$addarray[1]."', '".$addarray[2]."', '".$addarray[3]."', '".$addarray[4]."', '".$addarray[5]."' , '".$addarray[6]."')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } return $result;}//delete extension from extensions table//obsoletefunction delextensions($context,$exten) { global $db; $sql = "DELETE FROM extensions WHERE context = '".$context."' AND `extension` = '".$exten."'"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } return $result;}//get info about auto-attendant//obsoletefunction aainfo($menu_id) { global $db; //do another select for all parts in this aa_// $sql = "SELECT * FROM extensions WHERE context = '".$dept."aa_".$menu_num."' ORDER BY extension"; $sql = "SELECT * FROM extensions WHERE context = '".$menu_id."' ORDER BY extension"; $aalines = $db->getAll($sql); if(DB::IsError($aalines)) { die('aalines: '.$aalines->getMessage()); } return $aalines;}function zapexists() { global $db; $sql = "CREATE TABLE IF NOT EXISTS `zap` (`id` bigint(11) NOT NULL default '-1',`keyword`varchar(20) NOT NULL default '',`data`varchar(150) NOT NULL default '',`flags` int(1) NOT NULL default '0',PRIMARY KEY (`id`,`keyword`))"; $results = $db->query($sql);}/*function addzap($account,$callerid) { zapexists(); global $db; $zapfields = array( array($account,'account',$account), array($account,'context',($_REQUEST['context'])?$_REQUEST['context']:''), array($account,'mailbox',($_REQUEST['mailbox'])?$_REQUEST['mailbox']:''), array($account,'callerid',$callerid), array($account,'signalling',($_REQUEST['signalling'])?$_REQUEST['signalling']:'fxo_ks'), array($account,'echocancel',($_REQUEST['echocancel'])?$_REQUEST['echocancel']:'yes'), array($account,'echocancelwhenbridged',($_REQUEST['echocancelwhenbridged'])?$_REQUEST['echocancelwhenbridged']:'no'), array($account,'echotraining',($_REQUEST['echotraining'])?$_REQUEST['echotraining']:'800'), //array($account,'group',($_REQUEST['group'])?$_REQUEST['group']:'31'), //Default<>0 which is the default zap trunk array($account,'busydetect',($_REQUEST['busydetect'])?$_REQUEST['busydetect']:'no'), array($account,'busycount',($_REQUEST['busycount'])?$_REQUEST['busycount']:'7'), array($account,'callprogress',($_REQUEST['callprogress'])?$_REQUEST['callprogress']:'no'), array($account,'record_in',($_REQUEST['record_in'])?$_REQUEST['record_in']:'On-Demand'), array($account,'record_out',($_REQUEST['record_out'])?$_REQUEST['record_out']:'On-Demand'), array($account,'channel',($_REQUEST['channel'])?$_REQUEST['channel']:'')); $compiled = $db->prepare('INSERT INTO zap (id, keyword, data) values (?,?,?)'); $result = $db->executeMultiple($compiled,$zapfields); if(DB::IsError($result)) { die($result->getMessage()."<br><br>error adding to ZAP table"); } //add E<enten>=ZAP to global vars (appears in extensions_additional.conf) $sql = "INSERT INTO globals VALUES ('E$account', 'ZAP')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } //add ZAPCHAN_<exten>=<zapchannel> to global vars. Needed in dialparties.agi to decide channel number without hitting the database. $zapchannel=$_REQUEST['channel']; $sql = "INSERT INTO globals VALUES ('ZAPCHAN_$account', '$zapchannel')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } //add ECID<enten> to global vars if using outbound CID if ($_REQUEST['outcid'] != '') { $outcid = $_REQUEST['outcid']; $sql = "INSERT INTO globals VALUES ('ECID$account', '$outcid')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } }}*///create iax if it doesn't existfunction iaxexists() { global $db; $sql = "CREATE TABLE IF NOT EXISTS `iax` (`id` bigint(11) NOT NULL default '-1',`keyword` varchar(20) NOT NULL default '',`data` varchar(150) NOT NULL default '',`flags` int(1) NOT NULL default '0',PRIMARY KEY (`id`,`keyword`))"; $results = $db->query($sql);}//add to iax table/*function addiax($account,$callerid) { iaxexists(); global $db; $iaxfields = array(array($account,'account',$account), array($account,'secret',($_REQUEST['secret'])?$_REQUEST['secret']:''), array($account,'notransfer',($_REQUEST['notransfer'])?$_REQUEST['notransfer']:''), array($account,'context',($_REQUEST['context'])?$_REQUEST['context']:''), array($account,'host',($_REQUEST['host'])?$_REQUEST['host']:''), array($account,'type',($_REQUEST['type'])?$_REQUEST['type']:''), array($account,'mailbox',($_REQUEST['mailbox'])?$_REQUEST['mailbox']:''), array($account,'username',($_REQUEST['username'])?$_REQUEST['username']:''), array($account,'port',($_REQUEST['iaxport'])?$_REQUEST['iaxport']:''), array($account,'qualify',($_REQUEST['qualify'])?$_REQUEST['qualify']:''), array($account,'disallow',($_REQUEST['disallow'])?$_REQUEST['disallow']:''), array($account,'allow',($_REQUEST['allow'])?$_REQUEST['allow']:''), array($account,'record_in',($_REQUEST['record_in'])?$_REQUEST['record_in']:'On-Demand'), array($account,'record_out',($_REQUEST['record_out'])?$_REQUEST['record_out']:'On-Demand'), array($account,'callerid',$callerid)); $compiled = $db->prepare('INSERT INTO iax (id, keyword, data) values (?,?,?)'); $result = $db->executeMultiple($compiled,$iaxfields); if(DB::IsError($result)) { die($result->getMessage()."<br><br>error adding to IAX table"); } //add E<enten>=IAX2 to global vars (appears in extensions_additional.conf) $sql = "INSERT INTO globals VALUES ('E$account', 'IAX2')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } //add ECID<enten> to global vars if using outbound CID if ($_REQUEST['outcid'] != '') { $outcid = $_REQUEST['outcid']; $sql = "INSERT INTO globals VALUES ('ECID$account', '$outcid')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } }}*///create sip if it doesn't existfunction sipexists() { global $db; $sql = "CREATE TABLE IF NOT EXISTS `sip` (`id` bigint(11) NOT NULL default '-1',`keyword` varchar(20) NOT NULL default '',`data` varchar(150) NOT NULL default '',`flags` int(1) NOT NULL default '0',PRIMARY KEY (`id`,`keyword`))"; $results = $db->query($sql);}//add to sip table/*function addsip($account,$callerid) { sipexists(); global $db; $sipfields = array(array($account,'account',$account), array($account,'accountcode',($_REQUEST['accountcode'])?$_REQUEST['accountcode']:''), array($account,'secret',($_REQUEST['secret'])?$_REQUEST['secret']:''), array($account,'canreinvite',($_REQUEST['canreinvite'])?$_REQUEST['canreinvite']:'no'), array($account,'context',($_REQUEST['context'])?$_REQUEST['context']:'from-internal'), array($account,'dtmfmode',($_REQUEST['dtmfmode'])?$_REQUEST['dtmfmode']:''), array($account,'host',($_REQUEST['host'])?$_REQUEST['host']:'dynamic'), array($account,'type',($_REQUEST['type'])?$_REQUEST['type']:'friend'), array($account,'mailbox',($_REQUEST['mailbox'])?$_REQUEST['mailbox']:$account.'@device'), array($account,'username',($_REQUEST['username'])?$_REQUEST['username']:$account), array($account,'nat',($_REQUEST['nat'])?$_REQUEST['nat']:'never'), array($account,'port',($_REQUEST['port'])?$_REQUEST['port']:'5060'), array($account,'qualify',($_REQUEST['qualify'])?$_REQUEST['qualify']:'no'), array($account,'callgroup',($_REQUEST['callgroup'])?$_REQUEST['callgroup']:''), array($account,'pickupgroup',($_REQUEST['pickupgroup'])?$_REQUEST['pickupgroup']:''), array($account,'disallow',($_REQUEST['disallow'])?$_REQUEST['disallow']:''), array($account,'allow',($_REQUEST['allow'])?$_REQUEST['allow']:''), array($account,'record_in',($_REQUEST['record_in'])?$_REQUEST['record_in']:'On-Demand'), array($account,'record_out',($_REQUEST['record_out'])?$_REQUEST['record_out']:'On-Demand'), array($account,'callerid',$callerid)); $compiled = $db->prepare('INSERT INTO sip (id, keyword, data) values (?,?,?)'); $result = $db->executeMultiple($compiled,$sipfields); if(DB::IsError($result)) { die($result->getMessage()."<br><br>".'error adding to SIP table'); } //add E<enten>=SIP to global vars (appears in extensions_additional.conf) $sql = "INSERT INTO globals VALUES ('E$account', 'SIP')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } //add ECID<enten> to global vars if using outbound CID if ($_REQUEST['outcid'] != '') { $outcid = $_REQUEST['outcid']; $sql = "INSERT INTO globals VALUES ('ECID$account', '$outcid')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage().$sql); } }}*/function addaccount($account,$mailb) { extensionsexists(); global $db; $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ('ext-local', '".$account."', '1', 'Macro', 'exten-vm,".$mailb.",".$account."', NULL , '0')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } return $result;}//create extensions if it doesn't existfunction extensionsexists() { global $db; $sql = "CREATE TABLE IF NOT EXISTS `extensions` (`context` varchar(20) NOT NULL default 'default',`extension` varchar(20) NOT NULL default '',`priority` int(2) NOT NULL default '1',`application` varchar(20) NOT NULL default '',`args` varchar(50) default NULL,`descr` text,`flags` int(1) NOT NULL default '0',PRIMARY KEY (`context`,`extension`,`priority`))"; $results = $db->query($sql);}/* was obsolete in 009?? //get all rows relating to selected accountfunction exteninfo($extdisplay) { global $db; $sql = "SELECT * FROM sip WHERE id = '$extdisplay'"; $thisExten = $db->getAll($sql); if(DB::IsError($thisExten)) { die($thisExten->getMessage()); } if (count($thisExten) > 0) { $thisExten[] = array('$extdisplay','tech','sip','info'); //add this to the array - as it doesn't exist in the table } else { //if (count($thisExten) == 0) { //if nothing was pulled from sip, then it must be iax $sql = "SELECT * FROM iax WHERE id = '$extdisplay'"; $thisExten = $db->getAll($sql); if(DB::IsError($thisExten)) { die($thisExten->getMessage());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -