Last active
January 4, 2016 13:09
-
-
Save lgaetz/8626154 to your computer and use it in GitHub Desktop.
PHP function for use with FreePBX that accepts a DAHDI group as an argument, and returns an array of DAHDI channels (if any) for that goup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This function works within FreePBX or with FreePBX 2.9+ bootstrap loader | |
// $astman (phpagi class) already declared | |
function group2chan($groupid) { | |
global $astman; | |
// strip non-digits and assume the remaining number is the group number | |
$groupid = preg_replace("/[^0-9]*/", "", $groupid); | |
// use phpagi class to query channels in dahdi group | |
$data = $astman->command("dahdi show channels group $groupid"); | |
foreach(explode("\n", $data['data']) as $line) { | |
// catch the leading digits of each line and ignore the rest of the line | |
preg_match("~^.*?(\d+?) .*~",$line,$foo); | |
if (trim($foo[1]) != "") { | |
$channels[] = trim($foo[1]); | |
} | |
} | |
if (isset($channels)) { | |
return $channels; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment