functions.inc.php
来自「最近在做软交换时研究的一个软交换的东东」· PHP 代码 · 共 1,043 行 · 第 1/3 页
PHP
1,043 行
} else { // option line $output[] = $key."=".$vmconf[$section][ $key ]; // remove this one from $vmconf unset($vmconf[$section][$key ]); } } } //DEBUG echo "</i></blockquote>"; } fclose($fd); //DEBUG echo "\n\nwriting ".$filename; //DEBUG echo "\n-----------\n"; //DEBUG echo implode("\n",$output); //DEBUG echo "\n-----------\n"; // write this file back out if ($fd = fopen($filename, "w")) { fwrite($fd, implode("\n",$output)."\n"); fclose($fd); } }}function saveVoicemail($vmconf) { // yes, this is hardcoded.. is this a bad thing? write_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section);}// $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)// esnure that any form that includes this calls the setDestinations() javascript function on submit.// ie: if the form name is "edit", and drawselects has been called with $i=2 then use onsubmit="setDestinations(edit,2)"function drawselects($goto,$i) { /* --- MODULES BEGIN --- */ global $active_modules; // This is purely to remove a warning. if (!isset($selectHtml)) { $selectHtml=''; } $selectHtml .= '<tr><td colspan=2>'; //check for module-specific destination functions foreach ($active_modules as $mod => $displayname) { $funct = strtolower($mod.'_destinations'); //if the modulename_destinations() function exits, run it and display selections for it if (function_exists($funct)) { $options = ""; $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' : '').' /> '._($displayname['displayName']).': '; if ($checked) { $goto = $mod; } $selectHtml .= '<select name="'.$mod.$i.'"/>'; $selectHtml .= $options; $selectHtml .= "</select><br>\n"; } } } /* --- MODULES END --- */ //display a custom goto field $selectHtml .= '<input type="radio" name="goto_indicate'.$i.'" value="custom" onclick="javascript:this.form.goto'.$i.'.value=\'custom\';" onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) this.form.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'.$i.'" value="'.(strpos($goto,'custom') === false ? '' : $goto).'" />'; $selectHtml .= "\n<input type='hidden' name='goto$i' value='$goto'>"; //close off our row $selectHtml .= '</td></tr>'; return $selectHtml;}/* below are legacy functions required to allow pre 2.0 modules to function (ie: interact with 'extensions' table) */ //add to extensions table - used in callgroups.php function legacy_extensions_add($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 function legacy_extensions_del($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 args for specified exten and priority - primarily used to grab goto destination function legacy_args_get($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; }/* end legacy functions *//* UsageGrab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;$objXML = new xml2Array();$arrOutput = $objXML->parse($strYourXML);print_r($arrOutput); //print it out, or do whatever!*/class xml2Array { var $arrOutput = array(); var $resParser; var $strXmlData; function parse($strInputXML) { $this->resParser = xml_parser_create (); xml_set_object($this->resParser,$this); xml_set_element_handler($this->resParser, "tagOpen", "tagClosed"); xml_set_character_data_handler($this->resParser, "tagData"); $this->strXmlData = xml_parse($this->resParser,$strInputXML ); if(!$this->strXmlData) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->resParser)), xml_get_current_line_number($this->resParser))); } xml_parser_free($this->resParser); return $this->arrOutput; } function tagOpen($parser, $name, $attrs) { $tag=array("name"=>$name,"attrs"=>$attrs); array_push($this->arrOutput,$tag); } function tagData($parser, $tagData) { if(trim($tagData)) { if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) { $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $tagData; } else { $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $tagData; } } } function tagClosed($parser, $name) { $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1]; array_pop($this->arrOutput); }}/* Return a much more manageable assoc array with module data.*/class xml2ModuleArray extends xml2Array { function parseModulesXML($strInputXML) { $arrOutput = $this->parse($strInputXML); // if you are confused about what's happening below, uncomment this why we do it // echo "<pre>"; print_r($arrOutput); echo "</pre>"; // ignore the regular xml garbage ([0]['children']) & loop through each module if(!is_array($arrOutput[0]['children'])) return false; foreach($arrOutput[0]['children'] as $module) { if(!is_array($module['children'])) return false; // loop through each modules's tags foreach($module['children'] as $modTags) { if(isset($modTags['children']) && is_array($modTags['children'])) { $$modTags['name'] = $modTags['children']; // loop if there are children (menuitems and requirements) foreach($modTags['children'] as $subTag) { $subTags[strtolower($subTag['name'])] = $subTag['tagData']; } $$modTags['name'] = $subTags; unset($subTags); } else { // create a variable for each tag we find $$modTags['name'] = $modTags['tagData']; } } // now build our return array $arrModules[$RAWNAME]['rawname'] = $RAWNAME; // This has to be set $arrModules[$RAWNAME]['displayName'] = $NAME; // This has to be set $arrModules[$RAWNAME]['version'] = $VERSION; // This has to be set $arrModules[$RAWNAME]['type'] = isset($TYPE)?$TYPE:'setup'; $arrModules[$RAWNAME]['category'] = isset($CATEGORY)?$CATEGORY:'Unknown'; $arrModules[$RAWNAME]['info'] = isset($INFO)?$INFO:'http://www.freepbx.org/wiki/'.$RAWNAME; $arrModules[$RAWNAME]['location'] = isset($LOCATION)?$LOCATION:'local'; $arrModules[$RAWNAME]['items'] = isset($MENUITEMS)?$MENUITEMS:null; $arrModules[$RAWNAME]['requirements'] = isset($REQUIREMENTS)?$REQUIREMENTS:null; $arrModules[$RAWNAME]['md5sum'] = isset($MD5SUM)?$MD5SUM:null; //print_r($arrModules); //unset our variables unset($NAME); unset($VERSION); unset($TYPE); unset($CATEGORY); unset($AUTHOR); unset($EMAIL); unset($LOCATION); unset($MENUITEMS); unset($REQUIREMENTS); unset($MD5SUM); } //echo "<pre>"; print_r($arrModules); echo "</pre>"; return $arrModules; }}class moduleHook { var $hookHtml = ''; var $arrHooks = array(); function install_hooks($viewing_itemid,$target_module,$target_menuid = '') { global $active_modules; // loop through all active modules foreach($active_modules as $this_module) { // look for requested hooks for $module // ie: findme_hook_extensions() $funct = $this_module['rawname'] . '_hook_' . $target_module; if( function_exists( $funct ) ) { // execute the function, appending the // html output to that of other hooking modules if ($hookReturn = $funct($viewing_itemid,$target_menuid)) $this->hookHtml .= $hookReturn; // remember who installed hooks // we need to know this for processing form vars $this->arrHooks[] = $this_module['rawname']; } } } // process the request from the module we hooked function process_hooks($viewing_itemid, $target_module, $target_menuid, $request) { if(is_array($this->arrHooks)) { foreach($this->arrHooks as $hookingMod) { // check if there is a processing function $funct = $hookingMod . '_hookProcess_' . $target_module; if( function_exists( $funct ) ) { $funct($viewing_itemid, $request); } } } }}// Dragged this in from page.modules.php, so it can be used by install_amp. function runModuleSQL($moddir,$type){ global $db; global $amp_conf; $data=''; // if there is an sql file, run it if (is_file($amp_conf["AMPWEBROOT"]."/admin/modules/{$moddir}/{$type}.sql")) { // run sql script $fd = fopen($amp_conf["AMPWEBROOT"]."/admin/modules/{$moddir}/{$type}.sql","r"); while (!feof($fd)) { $data .= fread($fd, 1024); } fclose($fd); preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches); foreach ($matches[1] as $sql) { $result = $db->query($sql); if(DB::IsError($result)) { return false; } } } // if there is a php file, run it if (is_file($amp_conf["AMPWEBROOT"]."/admin/modules/{$moddir}/{$type}.php")) { include($amp_conf["AMPWEBROOT"]."/admin/modules/{$moddir}/{$type}.php"); } return true;}/*// just for testing hooks, i'll delete it laterfunction queues_hook_core($viewing_itemid, $target_menuid) { switch ($target_menuid) { case 'did': //get the current setting for this display (if any) $alertinfo = $viewing_itemid; return ' <tr> <td><a href="#" class="info">'._("Alert Info").'<span>'._('ALERT_INFO can be used for distinctive ring with SIP devices.').'</span></a>:</td> <td><input type="text" name="alertinfo" size="10" value="'.(($alertinfo) ? $alertinfo : "") .'"></td> </tr> '; break; default: return false; break; }}function queues_hookProcess_core($viewing_itemid, $request) { switch ($request['action']) { case 'edtIncoming': echo "<h1>HI</h1>"; return ' <tr> <td><a href="#" class="info">'._("Alert Info").'<span>'._('ALERT_INFO can be used for distinctive ring with SIP devices.').'</span></a>:</td> <td><input type="text" name="alertinfo" size="10" value="'.(($alertinfo) ? $alertinfo : "") .'"></td> </tr> '; break; default: return false; break; }}*/?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?