Changeset 6122

Show
Ignore:
Timestamp:
07/21/08 17:19:51 (3 months ago)
Author:
p_lindheimer
Message:

allow splice to splice before a tag so you don't always need to know the exact priority

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/extensions.class.php

    r6043 r6122  
    106106        /* This function allows new priorities to be injected into already generated dialplan 
    107107        *  usage: $ext->splice($context, $exten, $priority_number, new ext_goto('1','s','ext-did')); 
     108        *         if $priority is not numeric, it will interpret it as a tag and try to inject  
     109        *         the command just prior to  the first instruction it finds with the specified tag 
     110        *         if it can't find the tag, it will inject it after the last instruction 
    108111        */ 
    109112        function splice($section, $extension, $priority, $command) { 
     113 
     114                // if the priority is a tag, then we look for the real priority to insert it before that 
     115                // tag. If the tag does not exists, then we put it at the very end which may not be 
     116                // desired but it puts it somewhere 
     117                // 
     118                if (!ctype_digit($priority)) { 
     119                        $new_priority = false; 
     120                        $count = 0; 
     121                        if (isset($this->_exts[$section][$extension])) { 
     122                                foreach($this->_exts[$section][$extension] as $pri => $curr_command) { 
     123                                        if ($curr_command['tag'] == $priority) { 
     124                                                $new_priority = $count; 
     125                                                break; 
     126                                        } 
     127                                        $count++; 
     128                                } 
     129                        } 
     130                        $priority = ($new_priority === false) ? $count : $new_priority; 
     131                } 
    110132                if($priority == 0) { 
    111133                        $basetag = '1'; 
     
    125147                *  problems that array_splice has with multidmentional arrays 
    126148                */ 
    127                         $array = isset($this->_exts[$section][$extension]) ? $this->_exts[$section][$extension] : array(); 
    128                         $ky = $priority; 
    129                         $val = $newcommand; 
    130                         $n = $ky;  
    131                          foreach($array as $key => $value)  
    132                            {  
    133                                 $backup_array[$key] = $array[$key];  
    134                            }  
    135                          $upper_limit = count($array);  
    136                          while($n <= $upper_limit)  
    137                            {  
    138                                 if($n == $ky)  
    139                                   {  
    140                          $array[$n] = $val;  
    141                         // echo $n;  
    142                                   }  
    143                                 else  
    144                                   {  
    145                          $i = $n - "1";  
    146                          $array[$n] = $backup_array[$i];  
    147                                   }  
    148                                 $n++;  
    149                            }  
    150                  
     149                $array = isset($this->_exts[$section][$extension]) ? $this->_exts[$section][$extension] : array(); 
     150                $ky = $priority; 
     151                $val = $newcommand; 
     152                $n = $ky;  
     153                foreach($array as $key => $value) {  
     154                        $backup_array[$key] = $array[$key];  
     155                }  
     156                $upper_limit = count($array);  
     157                while($n <= $upper_limit) {  
     158                        if($n == $ky) {  
     159                                $array[$n] = $val;  
     160                                // echo $n;  
     161                        } else {  
     162                                $i = $n - "1";  
     163                                $array[$n] = $backup_array[$i];  
     164                        }  
     165                        $n++;  
     166                }  
     167 
    151168                // apply our newly modified array 
    152169                //echo "Splicing [$section] $extension\n"; 
    153170                $this->_exts[$section][$extension] = $array;             
    154                  
     171 
    155172                //print_r($this->_exts[$section][$extension]); 
    156173        } 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads