Changeset 7890

Show
Ignore:
Timestamp:
07/05/09 12:37:32 (3 years ago)
Author:
p_lindheimer
Message:

fixes #3744 found a good way to get proper sequences without multiple ugly queries

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.5/core/functions.inc.php

    r7886 r7890  
    40174017//get outbound routes for a given trunk 
    40184018function core_trunks_gettrunkroutes($trunknum) { 
    4019   global $amp_conf; 
    4020  
    4021   if ($amp_conf["AMPDBENGINE"] == "sqlite3") 
    4022     $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"; 
    4023   else 
    4024     $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"; 
    4025  
    4026   $results = sql( $sql_code, "getAll" ); 
    4027  
    4028   foreach ($results as $row) { 
    4029     // original code was: 
    4030     //  $routes[$row[0]] = $row[1]; 
    4031     // but substring is not supported in sqlite3. 
    4032     // how about we remove the 2nd part of the "if"? and use the same code on all DB's? 
    4033  
    4034     $t = ($amp_conf["AMPDBENGINE"] == "sqlite3") ? substr( $row[0], 7 ) : $row[0]; 
    4035     $r = $row[1]; 
    4036     $routes[ $t ] = $r; 
    4037  
    4038   } 
    4039   // array(routename=>priority) 
    4040   return isset($routes)?$routes:null; 
     4019  $sql_code = "SELECT DISTINCT SUBSTRING(context,7) route ,args trunk FROM extensions WHERE context LIKE 'outrt-%' AND  
     4020    (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY context,priority"; 
     4021  $results = sql( $sql_code, "getAll" ,DB_FETCHMODE_ASSOC); 
     4022  $routeseq = array(); 
     4023  foreach ($results as $entry) { 
     4024    $pos1 = strpos($entry['trunk'],',')+1; 
     4025    $routeseq[$entry['route']][] = substr($entry['trunk'],$pos1,strpos($entry['trunk'],',',$pos1)-$pos1); 
     4026  } 
     4027  $routes = array(); 
     4028  foreach ($routeseq as $key => $value) { 
     4029    $pos = array_search($trunknum, array_values(array_unique($value))); 
     4030    if ($pos !== false) { 
     4031      $routes[$key] = $pos+1; // start at 1, not 0 
     4032    } 
     4033  } 
     4034  return $routes; 
    40414035} 
    40424036