Show
Ignore:
Timestamp:
12/29/10 16:15:57 (2 years ago)
Author:
p_lindheimer
Message:

put back CLI debug() function as verbose, change several dbug back to verbose, have verbose write to dbug log, put back php4 comp functions until bootstrap is enabled, fix some errors with db debug method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/bootstrap-2.9/directory/agi-bin/directory.agi

    r10680 r10753  
    44set_error_handler("error_handler"); 
    55 
    6 dbug('entered dir!'); 
     6verbose('entered dir!',6); 
    77require_once(dirname(__FILE__).'/directory.lib.php'); 
    88$loopcounter1 = 0; 
     
    5757        if ($matches > 9) { 
    5858          $search = rtrim($search,'#'); 
    59           dbug("Too many found: $matches, remove # if set and try again"); 
     59          verbose("Too many found: $matches, remove # if set and try again",6); 
    6060        } 
    6161      } else { 
     
    7575      $validkeys .= $i; 
    7676    } 
    77       dbug("valid keys for entries are: $validkeys"); 
     77      verbose("valid keys for entries are: $validkeys",6); 
    7878     
    7979    //playback entries 
     
    104104    } 
    105105     
    106     dbug("got result: ".$ret['result']); 
     106    verbose("got result: ".$ret['result'],6); 
    107107    if (trim($ret['result'])) { 
    108108      call($matches[$ret['result']-1]); 
     
    136136} 
    137137 
     138//send debug to asterisk cli 
     139function verbose($string, $level=3){ 
     140  global $dir; 
     141  $dir->agi->verbose($string, $level); 
     142 
     143  // send same message to debug log if enabled 
     144  dbug($string); 
     145} 
    138146 
    139147 /*  
  • modules/branches/bootstrap-2.9/directory/agi-bin/directory.lib.php

    r10680 r10753  
    106106      $res=$this->db->getAll($sql,DB_FETCHMODE_ASSOC); 
    107107        if(DB::IsError($res)) { 
    108             dbug("FATAL: got error from getAll query",1); 
    109             dbug($res->getdbugInfo()); 
     108            verbose("FATAL: got error from getAll query",1); 
     109            dbug($res->getDebugInfo()); 
    110110          } 
    111111          $rec_file = array(); 
     
    168168        $vm_dir = $this->agi->database_get('AMPUSER',$con['dial'].'/voicemail'); 
    169169        $vm_dir = $vm_dir['data']; 
    170         dbug("got directory $vm_dir for user {$con['dial']}",6); 
     170        verbose("got directory $vm_dir for user {$con['dial']}",6); 
    171171        //check to see if we have a greet.* and play it. otherwise, fallback to spelling the name 
    172172            if ($vm_dir && $vm_dir != 'novm') { 
     
    176176          $dir = scandir($this->vmbasedir.$vm_dir.'/'.$con['dial']); 
    177177          foreach ($dir as $file) { 
    178           dbug("looking for vm file $file using: ".basename($file),6); 
     178          verbose("looking for vm file $file using: ".basename($file),6); 
    179179          if (substr($file,0,5) == 'greet' && is_file($this->vmbasedir.$vm_dir.'/'.$con['dial'].'/'.$file)) { 
    180180            $ret = $this->agi->stream_file($this->vmbasedir . $vm_dir . '/' . $con['dial'] . '/greet',$ keys); 
     
    216216          $sql = 'SELECT filename from recordings where id = ?'; 
    217217          $rec = $this->db->getOne($sql, array($con['audio'])); 
    218           dbug("got record id: {$con['audio']} file(s): $rec"); 
     218          verbose("got record id: {$con['audio']} file(s): $rec"); 
    219219          if ($rec) { 
    220220            $rec = explode('&',$rec); 
     
    228228          } else { 
    229229            //TODO: handle error 
    230             dbug("ERROR: unknown/undefined sound file"); 
     230            verbose("ERROR: unknown/undefined sound file"); 
    231231          } 
    232232        } 
     
    242242 
    243243    if (strstr($key,'0') !== false) { 
    244       dbug("user pressed 0 - bailing out"); 
     244      verbose("user pressed 0 - bailing out"); 
    245245      $this->bail(); 
    246246    } 
     
    250250  $alph = array("[ \s@,-\!/+=\.']",'[abcABC]','[defDEF]','[ghiGHI]','[jklJKL]','[mnoMNO]','[pqrsPQRS]','[tuvTUV]','[wxyzWXYZ]','',''); 
    251251    $this->searchstring = $this->db->escapeSimple(str_replace($num,$alph,$key)); 
    252     dbug("search string for regex: {$this->searchstring}",6); 
     252    verbose("search string for regex: {$this->searchstring}",6); 
    253253 
    254254    //TODO: check db results for errors and fail gracefully 
     
    258258    $res=$this->db->getOne($sql); 
    259259      if (DB::IsError($res)) { 
    260       dbug("FATAL: got error from COUNT(*) query"); 
    261       dbug($res->getdbugInfo()); 
    262     } 
    263     dbug("Found $res possible matches from $key"); 
     260      verbose("FATAL: got error from COUNT(*) query"); 
     261      dbug($res->getDebugInfo()); 
     262    } 
     263    verbose("Found $res possible matches from $key"); 
    264264  } else { 
    265265    $sql = "SELECT * FROM $vtable WHERE name REGEXP \"(^| ){$this->searchstring}\""; 
    266266    $res = $this->db->getAll($sql,DB_FETCHMODE_ASSOC); 
    267267    if (DB::IsError($res)) { 
    268       dbug("FATAL: got error from getAll query"); 
    269       dbug($res->getdbugInfo()); 
     268      verbose("FATAL: got error from getAll query"); 
     269      dbug($res->getDebugInfo()); 
    270270    } else { 
    271       dbug("Found the following matches:"); 
     271      verbose("Found the following matches:",6); 
    272272      foreach ($res as $ent) { 
    273         dbug("name: {$ent['name']}, audio: {$ent['audio']}, dial: {$ent['dial']}"); 
     273        verbose("name: {$ent['name']}, audio: {$ent['audio']}, dial: {$ent['dial']}",6); 
    274274      } 
    275275    } 
     
    280280  function bail() { 
    281281  //do something if we are exiting due to to many tries 
    282     dbug("User pressed zero, passing back recording of {$this->dir['invalid_recording']}"); 
     282    verbose("User pressed zero, passing back recording of {$this->dir['invalid_recording']}"); 
    283283  $this->agi->set_variable('DIR_INVALID_RECORDING',$this->dir['invalid_recording']); 
    284284  if ($this->agi_get_var('IVR_CONTEXT')) { 
     
    296296 
    297297} 
    298  
     298// PHP 4 does not have file_put_contents so create an aproximation of what the real function does 
     299// TODO: get rid of extinc php4 stuff as we dont support it anymore 
     300// 
     301if (!function_exists('file_put_contents')) { 
     302  function file_put_contents($filename, $data, $flags='', $context=null) { 
     303    $option = $flags == FILE_APPEND ? 'a' : 'w'; 
     304    if ($context !== null) { 
     305      $fd = @fopen($filename, $option); 
     306    } else { 
     307      $fd = @fopen($filename, $option, false, $context); 
     308    } 
     309    if (!$fd) { 
     310      return false; 
     311    } 
     312    if (is_array($data)) { 
     313      $data = implode('',$data); 
     314    } else if (is_object($data)) { 
     315      $data = print_r($data,true); 
     316    } 
     317    $bytes = fwrite($fd,$data); 
     318    fclose($fd); 
     319 
     320    return $bytes; 
     321  } 
     322
     323if (!function_exists('scandir')) { 
     324  function scandir($path,$sort=0) { 
     325    $fh = opendir($path); 
     326    $list = array(); 
     327    while(false !== ($filename = readdir($fh))) { 
     328      $list[] = $filename; 
     329    } 
     330    closedir($fh); 
     331    /* Not really needed here 
     332    if ($sort) { 
     333      sort($list); 
     334    } else { 
     335      rsort($list); 
     336    } 
     337    */ 
     338    return $list; 
     339  } 
     340
     341 
     342// non-utf8 version for php4 
     343if(!function_exists('str_split')) { 
     344  function str_split($string, $split_length = 1) { 
     345    $array = explode("\r\n", chunk_split($string, $split_length)); 
     346    array_pop($array); 
     347    return $array; 
     348  } 
     349
    299350?>