| 3221 | | global $amp_conf; |
|---|
| 3222 | | |
|---|
| 3223 | | if ($amp_conf["AMPDBENGINE"] == "sqlite3") |
|---|
| 3224 | | $sql_code = "SELECT DISTINCT context, priority FROM extensions WHERE context LIKE 'outrt-%' AND (args LIKE 'dialout-trunk,".$trunknum.",%' OR args LIKE 'dialout-enum,".$trunknum.",%' OR args LIKE 'dialout-dundi,".$trunknum.",%') ORDER BY context"; |
|---|
| 3225 | | else |
|---|
| 3226 | | $sql_code = "SELECT DISTINCT SUBSTRING(context,7), priority FROM extensions WHERE context LIKE 'outrt-%' AND (args LIKE 'dialout-trunk,".$trunknum.",%' OR args LIKE 'dialout-enum,".$trunknum.",%' OR args LIKE 'dialout-dundi,".$trunknum.",%') ORDER BY context"; |
|---|
| 3227 | | |
|---|
| 3228 | | $results = sql( $sql_code, "getAll" ); |
|---|
| 3229 | | |
|---|
| 3230 | | foreach ($results as $row) { |
|---|
| 3231 | | // original code was: |
|---|
| 3232 | | // $routes[$row[0]] = $row[1]; |
|---|
| 3233 | | // but substring is not supported in sqlite3. |
|---|
| 3234 | | // how about we remove the 2nd part of the "if"? and use the same code on all DB's? |
|---|
| 3235 | | |
|---|
| 3236 | | $t = ($amp_conf["AMPDBENGINE"] == "sqlite3") ? substr( $row[0], 7 ) : $row[0]; |
|---|
| 3237 | | $r = $row[1]; |
|---|
| 3238 | | $routes[ $t ] = $r; |
|---|
| 3239 | | |
|---|
| 3240 | | } |
|---|
| 3241 | | // array(routename=>priority) |
|---|
| 3242 | | return isset($routes)?$routes:null; |
|---|
| | 3221 | $sql_code = "SELECT DISTINCT SUBSTRING(context,7) route ,args trunk FROM extensions WHERE context LIKE 'outrt-%' AND |
|---|
| | 3222 | (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY context,priority"; |
|---|
| | 3223 | $results = sql( $sql_code, "getAll" ,DB_FETCHMODE_ASSOC); |
|---|
| | 3224 | $routeseq = array(); |
|---|
| | 3225 | foreach ($results as $entry) { |
|---|
| | 3226 | $pos1 = strpos($entry['trunk'],',')+1; |
|---|
| | 3227 | $routeseq[$entry['route']][] = substr($entry['trunk'],$pos1,strpos($entry['trunk'],',',$pos1)-$pos1); |
|---|
| | 3228 | } |
|---|
| | 3229 | $routes = array(); |
|---|
| | 3230 | foreach ($routeseq as $key => $value) { |
|---|
| | 3231 | $pos = array_search($trunknum, array_values(array_unique($value))); |
|---|
| | 3232 | if ($pos !== false) { |
|---|
| | 3233 | $routes[$key] = $pos+1; // start at 1, not 0 |
|---|
| | 3234 | } |
|---|
| | 3235 | } |
|---|
| | 3236 | return $routes; |
|---|