Changeset 123

Show
Ignore:
Timestamp:
03/02/05 15:26:23 (4 years ago)
Author:
gregmac
Message:

Remove debug lines
Add support for multiple contexts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/AMP2-UseAmportal/amp_conf/var/lib/asterisk/agi-bin/directory

    r119 r123  
    2828 
    2929/******************************************************************************/ 
     30 
     31define("DEBUG", 0); 
    3032 
    3133define("DIR_LAST", 0); 
     
    5355 
    5456function output(&$var) { 
    55         global $logfile; 
    56          
    57         if (!isset($logfile)) return false; 
    58          
    59         ob_start(); 
    60         var_dump($var); 
    61         $output = ob_get_contents(); 
    62         ob_end_clean(); 
    63         fwrite($logfile, $output); 
     57        if (DEBUG) { 
     58                global $logfile; 
     59                 
     60                if (!isset($logfile)) return false; 
     61                 
     62                ob_start(); 
     63                var_dump($var); 
     64                $output = ob_get_contents(); 
     65                ob_end_clean(); 
     66                fwrite($logfile, $output); 
     67        } 
    6468} 
    6569 
     
    263267} 
    264268 
    265 function do_directory($type, &$directory, $vm_context, $dial_context, $say_exten, $operator) { 
     269function do_directory($type, &$directory, $dial_context, $say_exten, $operator) { 
    266270        global $agi; 
    267271         
     
    274278                case DIR_LAST: default: $intro = ($operator ? "dir-intro-oper" : "dir-intro"); break; 
    275279        } 
    276          
    277         $intro = "digits/1"; 
    278280         
    279281        $loop = 0; 
     
    300302                 
    301303                $i = 0; 
     304                $digit = false; 
    302305                if (isset($directory[$digits]) && isset($directory[$digits][$i])) { 
    303306                        $loop = 0; // reset loop counter 
     
    305308                                $match = & $directory[$digits][$i]; 
    306309                                 
    307                                 $maindirname = sprintf(VOICEMAIL_DIR, $vm_context, $match["ext"]); 
     310                                $maindirname = sprintf(VOICEMAIL_DIR, $match["context"], $match["ext"]); 
    308311 
    309312                                if (sound_file_exists($maindirname."/greet")) { 
     
    381384$agi = new AGI; 
    382385 
    383 $logfile = fopen("/tmp/directory.log","w"); 
    384  
     386if (DEBUG) $logfile = fopen("/tmp/directory.log","w"); 
    385387 
    386388$vmconf = array(); 
     
    395397$vm_context = trim($argv[1]); 
    396398 
    397 if (!isset($vmconf[$vm_context])) { 
     399if (!isset($vmconf[$vm_context]) && ($vm_context != "general")) { 
     400        // we make an exception for "general" context,as it just includes other contexts 
    398401        $agi->verbose("Cannot find context ".$vm_context." in ".DIRECTORY_FILE); 
    399402        exit(1); 
     
    432435} 
    433436 
    434  
     437if ($vm_context == "general") { 
     438        $boxes = array(); 
     439        foreach ($vmconf as $context=>$arr) { 
     440                // skip if it's general context -- this doesn't contain mailboxes 
     441                if ($context == "general") continue; 
     442                 
     443                foreach ($arr as $key=>$box) { 
     444                        // we could do if !isset($boxes[$key]) to NOT override mailboxes 
     445                         
     446                        // add in the context, otherwise we don't know what it is 
     447                        $box["context"] = $context; 
     448                         
     449                        $boxes[$key] = $box; 
     450                } 
     451        } 
     452} else { 
     453        $boxes = &$vmconf[$vm_context]; 
     454
    435455 
    436456$directory = array(); 
    437 foreach ($vmconf[$vm_context] as $box) { 
     457foreach ($boxes as $box) { 
    438458        if (!empty($box["name"])) { 
    439459                $name = explode(" ",$box["name"]); 
     460                 
     461                if (isset($box["context"])) { 
     462                        $context = $box["context"]; 
     463                } else { 
     464                        $context = $vm_context; 
     465                } 
     466                 
    440467                switch ($dir_type) { 
    441468                        case DIR_FIRST: // first name only 
    442469                                $digits = string_to_digits($name[0]); 
    443                                 $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"]); 
     470                                $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"], "context"=>$context); 
    444471                        break; 
    445472                        case DIR_BOTH: // all names 
    446473                                foreach ($name as $temp) { 
    447474                                        $digits = string_to_digits($temp); 
    448                                         $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"]); 
     475                                        $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"], "context"=>$context); 
    449476                                } 
    450477                        break; 
    451478                        case DIR_LAST: default: // last name only 
    452479                                $digits = string_to_digits(end($name)); 
    453                                 $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"]); 
    454                         break; 
    455                 } 
    456         } 
    457 
    458  
    459 output($argv); 
    460 output($dir_type); 
    461 output($directory); 
    462  
    463 do_directory($dir_type, $directory, $vm_context, $dial_context, $say_exten, $operator); 
     480                                $directory[$digits][] = array("ext"=>$box["mailbox"], "name"=>$box["name"], "context"=>$context); 
     481                        break; 
     482                } 
     483        } 
     484
     485 
     486if (DEBUG) { 
     487        output($argv); 
     488        output($dir_type); 
     489        output($directory); 
     490
     491 
     492do_directory($dir_type, $directory, $dial_context, $say_exten, $operator); 
    464493         
    465494?> 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads