Carlos, 

Hoje eu utilizo AGI em php para fazer isso, segue minha em anexo o código da 
minha URA.

Na linha 339 esta o codigo onde eu toco a gravação , consigo digitar e recupero 
o valor digitado


[]s

  ----- Original Message ----- 
  From: Carlos César Alves Silva 
  To: asteriskbrasil@listas.asteriskbrasil.org 
  Sent: Monday, May 18, 2009 3:40 PM
  Subject: [AsteriskBrasil] Configuração de URA


  Pessoal, 

   

  Boa Tarde.

   

  Estou tentando configurar uma URA, mas me deparei com as seguintes situações:

   

  1)      Como fazer para que o usuário não precise esperar o termino da 
gravação para escolher a opção desejada?

  Atualmente só permite que eu digite a opção após a gravação terminar.

   

  2)      Como eu recupero o que for digitado pela pessoa que está sendo 
atendida pela URA?

  A pessoa que ligar para ura deverá discar o código dela na empresa e a data 
de nascimento, e eu preciso destas duas informações para chegar no BD se ela 
tem autorização ou não para abrir o chamado.

   

  Agradeço a atenção.

   

  Carlos César



   



  __________ Informação do NOD32 IMON 4062 (20090508) __________

  Esta mensagem foi verificada pelo NOD32 sistema antivírus
  http://www.eset.com.br



------------------------------------------------------------------------------


  _______________________________________________
  Openmoko Freerunner, primeiro telefone open source, disponível no Brasil 
rodando o Android da Google.
  http://www.neodroid.com

  Compre uma camiseta da AsteriskBrasil.org!
  http://www.voipmania.com.br

  Acesse o canal IRC de discussão sobre Asterisk em Português Brasileiro na 
rede Freenode.net: #asterisk-br
  _______________________________________________
  Lista de discussões AsteriskBrasil.org
  AsteriskBrasil@listas.asteriskbrasil.org
  http://listas.asteriskbrasil.org/mailman/listinfo/asteriskbrasil

  __________ Informação do NOD32 IMON 4062 (20090508) __________

  Esta mensagem foi verificada pelo NOD32 sistema antivírus
  http://www.eset.com.br

#!/usr/bin/php -q 
<?php 
 
        ob_implicit_flush(true);  
        set_time_limit(5);  
        error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); 
        declare(ticks = 1); 
        if (function_exists('pcntl_signal')) { 
                pcntl_signal(SIGHUP,  SIG_IGN); 
        } 
 
        include('dbconnection_postgres.php'); 
        include('phpagi.php'); 
 
        $agi = new AGI(); 
 
        $lstrOrigem       = $argv[1]; 
        $lstrDestino      = $argv[2]; 
        $linttempo        = $argv[3]; 
        $lstrTecnologia   = $argv[4]; 
        $lstrStatusRegra  = $argv[5]; 
        $lstrStatus1Regra = $argv[6]; 
        $lstrDestinoCdr   = $lstrOrigem; 
        $agi->verbose("x Status 1 Regra:  $lstrStatus1Regra"); 
        $agi->verbose("x Regra executa quando status nulo ou igual a:  
$lstrStatusRegra"); 
        
        if ($lstrStatus1Regra != "" && $lstrStatus1Regra != null && 
$lstrStatusRegra != "" && $lstrStatusRegra != null){
                if($lstrStatus1Regra != $lstrStatusRegra){
                        exit;
                }
        }
 
        $lstrDevLigTransf =""; 
        $lstrTransferO =""; 
        $lstrParkO =""; 
        $lstrGravacaoO =""; 
 
        if (strtoupper($lstrDestino) == 'DND' || strtoupper($lstrDestino) == 
'HANGUP'){ 
                $agi->hangup(); 
                 exit; 
        } 
 
        if (strtoupper($lstrDestino) == 'VOICEMAIL'){ 
                $agi->exec('Voicemail',$lstrOrigem."@ramais"); 
                $agi->hangup(); 
                 exit; 
        } 
 
        if (strtoupper($lstrDestino) == 'URA'){ 
                ura_default($argv[1],$agi); 
                $agi->hangup(); 
                exit; 
        } 
 
        $lstrEndereco   =''; 
        $lstrTipoLigacao=''; 
        $lstrBlindTransfer  = $agi->get_variable('BLINDTRANSFER',TRUE); 
        $lstrRedirLigServ   = $agi->get_variable('REDIR_LIG_SERV',TRUE);  
        $lstrChannel        = $agi->get_variable('CHANNEL',TRUE); 
 
        if ($lstrBlindTransfer == '' ){ 
                $lstrOriginador  =  $agi->get_variable('CALLERID(num)',TRUE); 
                $agi->set_variable('ENV(TEMP_BLINDCALLERID)',$lstrOrigem); 
                
$agi->set_variable('ENV(TEMP_BLINDCALLEDNUMBER)',$lstrOriginador); 
        } else { 
                $lstrOriginador = 
$agi->get_variable('ENV(TEMP_BLINDCALLERID)',TRUE);  
        } 
 
        $conn= 
db_connect_param('127.0.0.1','sa','rtw56gt','comprod_asterisk',5432); 
 
        $rs = db_query('select now() as data',$conn);  
        $datars=db_fetch_array($rs); 
        $lstrInicio=$datars['data']; 
 
        $rs = db_query("select x_acc_conta from ast_ramais where x_acc_conta = 
'$lstrOriginador'",$conn); 
        $datars=db_fetch_array($rs); 
        $lstrOriginadorAux=$datars['x_acc_conta']; 
 
        if ($lstrOriginadorAux ==  '' ){ 
                $lstrTipo    = 'IN'; 
                $lstrgateway = $agi->get_variable('SIPCHANINFO(peerip)',TRUE); 
        } else { 
                $lstrTipo    ='RM'; 
                $lstrgateway = ''; 
                $lstrSql = " select"; 
                $lstrSql.= " CASE WHEN x_fl_permite_transferencia = 'yes' THEN 
'T' ELSE '' END AS flag_trans,"; 
                $lstrSql.= " CASE WHEN x_fl_permite_park = 'yes' THEN 'K' ELSE 
'' END AS flag_park,"; 
                $lstrSql.= " CASE WHEN x_fl_permite_gravar_lig = 'yes' THEN 
'MonitorCaller#' ELSE '' END AS flag_grav ,"; 
                $lstrSql.= " x_devolver_lig_transf"; 
                $lstrSql.= " from ast_ramais  "; 
                $lstrSql.= " where x_acc_conta = '$lstrOriginador'"; 
                $rs = db_query($lstrSql,$conn);  
                $datars=db_fetch_array($rs);  
                $lstrTransferO =$datars['flag_trans']; 
                $lstrParkO     =$datars['flag_park']; 
                $lstrGravacaoO =$datars['flag_grav']; 
                $lstrDevLigTransf =$datars['x_devolver_lig_transf']; 
        } 
        if ($agi->get_variable('NUMERO_CALLBACK',TRUE) == $lstrOrigem && 
$lstrTipo == 'IN' ) {
                $lstrSql = " select 
x_acc_conta,x_callback_solicita_senha,x_callback_senha";
                $lstrSql.= " from ast_ramais  ";
                $lstrSql.= " where x_fl_permite_callback = 'yes'"; 
                $lstrSql.= " and   x_callback_numeros like  
'%$lstrOriginador%'";
                $rs = db_query($lstrSql,$conn);
                $datars=db_fetch_array($rs);
                if ($datars["x_acc_conta"] != "") {
                  
$agi->Gera_Call($datars["x_acc_conta"],$lstrOriginador,$datars["x_callback_solicita_senha"],$datars["x_callback_senha"]);
                        $agi->verbose("Executando Callback");
                }
                $agi->hangup();
                exit;
        }
 
        $lstrSql = " select"; 
        $lstrSql.= " CASE WHEN a.x_fl_permite_transferencia = 'yes' THEN 't' 
ELSE '' END AS flag_trans,"; 
        $lstrSql.= " CASE WHEN a.x_fl_permite_park = 'yes' THEN 'k' ELSE '' END 
AS flag_park,"; 
        $lstrSql.= " CASE WHEN a.x_fl_permite_gravar_lig = 'yes' THEN 
'MonitorCallee#' ELSE '' END AS flag_grav, "; 
        $lstrSql.= " CASE WHEN b.dmn_fl_grava_cdr_lig_in_out = '1' THEN 'yes' 
ELSE 'no' END AS grava_cdr_in_out ,"; 
        $lstrSql.= " a.x_blacklist_in, x_fl_permite_gravar_lig_aut"; 
        $lstrSql.= " from ast_ramais a, ast_dominios b "; 
        $lstrSql.= " where a.x_dmn_codigo = b.dmn_codigo"; 
        $lstrSql.= " and x_acc_conta = '$lstrOrigem'"; 
        $rs = db_query($lstrSql,$conn);  
        $datars=db_fetch_array($rs);  
        $lstrTransferD   =$datars['flag_trans']; 
        $lstrParkD       =$datars['flag_park']; 
        $lstrGravacaoD   =$datars['flag_grav']; 
        $lstrBlackListIn =$datars['x_blacklist_in']; 
        $lstrGravaCDR    =$datars['grava_cdr_in_out']; 
        $lstrGravacaoAut =$datars['x_fl_permite_gravar_lig_aut']; 
 
        $lstrFeatures =$lstrTransferO.$lstrTransferD.$lstrParkO.$lstrParkD; 
        if ($lstrTecnologia != 'LOCAL'  ) { 
                if ((($lstrGravacaoAut == 'ALL' || $lstrGravacaoAut == 'IN') && 
$lstrTipo  == 'IN') || (($lstrGravacaoAut == 'ALL' || $lstrGravacaoAut == 'RM' 
)&&  $lstrTipo  == 'RM')) { 
                        
$lstrFeatures=$lstrFeatures."M(monitor_ativo^$lstrOriginador^$lstrOrigem^$lstrTipo)";
 
                } 
        } 
        $lstrFeaturesD=$lstrGravacaoO.$lstrGravacaoD; 
        if(strlen($lstrFeaturesD) >0){ 
                
$lstrFeaturesD=substr($lstrFeaturesD,0,strlen($lstrFeaturesD)-1); 
        } 
 
        $agi->set_variable('__DYNAMIC_FEATURES',$lstrFeaturesD);  
 
        if ($lstrTecnologia == 'LOCAL'  ) { 
                
$agi->set_variable('CALLERID(all))',"$lstrOriginador<$lstrOrigem>"); 
        } 
 
        if ($lstrBlindTransfer != '' ){ 
                $lstrOriginadorTemp = 
$agi->get_variable('ENV(TEMP_BLINDCALLEDNUMBER)',TRUE); 
                $agi->verbose("x originador Temp:    $lstrOriginadorTemp"); 
                
$agi->set_variable('CALLERID(all))',"$lstrOriginadorTemp<$lstrOriginador>"); 
        } 
 
        if ((SUBSTR($lstrChannel,0,5) == 'Khomp' || SUBSTR($lstrChannel,0,3) == 
'Zap' || SUBSTR($lstrChannel,0,5) == 'DAHDI') && $lstrTipo == 'IN') { 
                $lstrSql = " select CASE WHEN x_fl_bloq_cob_hab = 'yes'and 
x_fl_bloq_cob_efe = 'yes' THEN 'yes' ELSE 'no' END AS bloqcob from ast_ramais 
where x_acc_conta = '$lstrOrigem'"; 
                $rs = db_query($lstrSql,$conn);  
                $datars=db_fetch_array($rs);  
                $lstrBloqCobrar=$datars['bloqcob']; 
 
                if ($lstrBloqCobrar == 'yes' && SUBSTR($lstrChannel,0,5) == 
'Khomp'  ) { 
                        $agi->verbose("x Bloqueando chamada a cobrar"); 
                        $agi->set_variable('KDropCollectCall','yes'); 
                } 
                if ($lstrBloqCobrar == 'yes' && SUBSTR($lstrChannel,0,3) == 
'Zap'  ) { 
                        $agi->verbose("x Bloqueando chamada a cobrar"); 
                        $agi->exec('Flash'); 
                } 
                if ($lstrBloqCobrar == 'yes' &&  SUBSTR($lstrChannel,0,5) == 
'DAHDI' ) { 
                        $agi->verbose("x Bloqueando chamada a cobrar"); 
                        $agi->exec('SendDTMF','w'); 
                } 
        } 
 
        db_close($conn);  
 
 
        if ($lstrTipo == 'IN' && $lstrRedirLigServ != 'null'){  
                if (strpos($lstrRedirLigServ,'@') !== false){  
                        $lstrDestino='SIP/'.$lstrRedirLigServ;   
                } else {  
                        $lstrDestino='SIP/'.$lstrDestino.'@'.$lstrRedirLigServ; 
  
                }  
        } 
 
        $lstrCallerIDAll     = $agi->get_variable('CALLERID(all)',TRUE); 
        $agi->verbose("x Origem:        $lstrOrigem"); 
        $agi->verbose("x Destino:       $lstrDestino"); 
        $agi->verbose("x originador:    $lstrOriginador"); 
        $agi->verbose("x Tipo:          $lstrTipo"); 
        $agi->verbose("x BlindTransfer: $lstrBlindTransfer"); 
        $agi->verbose("x RedirLigServ:  $lstrRedirLigServ"); 
        $agi->verbose("x GravaCDR:      $lstrGravaCDR"); 
        $agi->verbose("x Channel:       $lstrChannel"); 
        $agi->verbose("x Tecnologia:    $lstrTecnologia"); 
        $agi->verbose("x tempo:         $linttempo"); 
        $agi->verbose("x Features:      $lstrFeatures"); 
        $agi->verbose("x FeaturesD:     $lstrFeaturesD"); 
        $agi->verbose("x BlackList:     $lstrBlackListIn"); 
        $agi->verbose("x Dev Lig.Transf:$lstrDevLigTransf"); 
        $agi->verbose("x CallerId All  :$lstrCallerIDAll"); 
 
        if (trim($lstrBlackListIn) != '') {
                $agi->verbose("verificando blacklist"); 
                $lstrBlackListIn =','.$lstrBlackListIn.','; 
                if (strpos($lstrBlackListIn,','.$lstrOriginador.',') !== 
false){ 
                        $agi->verbose("Originador esta na black list"); 
                        $agi->hangup(); 
                        exit;
                };
        };
 
        if($lstrTipo == 'RM' && $lstrBlindTransfer != '' && $lstrDevLigTransf 
!= 'no'){
                $linttempo = $lstrDevLigTransf; 
        };
 
        $agi->exec('DIAL', "$lstrDestino|$linttempo|of$lstrFeatures");  
 
        $lstrDialStatus       = $agi->get_variable('DIALSTATUS',TRUE);  
 
        if (($lstrGravaCDR == 'yes' && $lstrTipo == 'IN')   || $lstrTipo == 
'RM') {  
                $lstrDialTime         = $agi->get_variable('DIALEDTIME',TRUE);  
                $lstrAnswerTime       = 
$agi->get_variable('ANSWEREDTIME',TRUE);  
                $lstrcdr_id           = 
$agi->get_variable('SIP_HEADER(CALL-ID)',TRUE); 
                if (trim($lstrDialTime) == '' || $lstrDialTime == null || 
is_null($lstrDialTime)){  
                        $lstrDialTime = 0; 
                } 
 
                if (trim($lstrAnswerTime) == '' || $lstrAnswerTime == null || 
is_null($lstrAnswerTime)){  
                        $lstrAnswerTime = 0;  
                } 
 
                $conn= 
db_connect_param('127.0.0.1','sa','rtw56gt','comprod_asterisk',5432); 
                if ($lstrTipo == 'IN'){  
                        $lstrSql = "select x_acc_conta from ast_ramais_regras 
where exten ='$lstrOrigem' limit 1";  
                        $rsDst=db_query($lstrSql,$conn);  
                        If (db_numrows($rsDst) > 0) {  
                                $dataDst = db_fetch_array($rsDst);  
                                $lstrDestinoCdr = $dataDst['x_acc_conta'];  
                        } 
                } 
 
                $rs = db_query("select x_dmn_codigo from ast_ramais where 
x_acc_conta='$lstrDestinoCdr'",$conn);  
                $datars=db_fetch_array($rs); 
                $lstrDmnCodigo=$datars['x_dmn_codigo']; 
 
                $lstrSql = "insert into ast_cdr_custom(dmn_codigo,cdr_tipo    , 
cdr_tipo_ligacao, cdr_origem       , cdr_destino       , cdr_inicio_ligacao, 
cdr_fim_ligacao, cdr_duracao_dial   ,cdr_duracao_answer , gtw_codigo    
,cdr_ip_gateway  , cdr_id          , cdr_status       ,cdr_debug)";  
                $lstrSql.= "                   values 
($lstrDmnCodigo,'$lstrTipo', ''               , '$lstrOriginador', 
'$lstrDestinoCdr' , '$lstrInicio'     ,  now()         , $lstrDialTime      ,  
$lstrAnswerTime  ,0              , ''             ,'$lstrcdr_id'   , 
'$lstrDialStatus','')";  
                db_exec($lstrSql,$conn);  
                db_close($conn);  
        }  
        if($lstrTipo == 'RM' && $lstrBlindTransfer != '' && $lstrDevLigTransf 
!= 'no' && $lstrDialStatus != 'ANSWER'){
                $conn= 
db_connect_param('127.0.0.1','sa','rtw56gt','comprod_asterisk',5432); 
                $rs = db_query("select exten from ast_ramais_regras where 
x_acc_conta = '$lstrOriginador' limit 1",$conn); 
                $datars=db_fetch_array($rs); 
                $lstrOriginadorTemp=$datars['exten']; 
                $agi->exec('DIAL', "LOCAL/$lstroriginadort...@ramais");  
                db_close($conn);  
        };

        if($lstrDialStatus == 'ANSWER'){
                $agi->verbose("x Ligação atendida, hangup"); 
                $agi->hangup(); 
        };

 function ura_default( $lstrConta, $agi) {
 
        $conn= 
db_connect_param('127.0.0.1','sa','rtw56gt','comprod_asterisk',5432); 
        $lstrSql = ""; 
        $lstrSql.= " select musiconhold,"; 
        $lstrSql.= " 
x_ura_numeros,x_ura_comandos,x_ura_comando_timeout,x_ura_arquivo_saudacao, 
x_ura_arquivo_feriado,"; 
        $lstrSql.= " 
x_ura_moh_ring,x_ura_arquivo_ocupado,x_ura_tipo,x_ura_escolha_aleatoria, 
x_ura_feriado_1, 
x_ura_feriado_2,x_ura_sabado,x_ura_domingo,x_ura_segunda_sexta"; 
        $lstrSql.= " from ast_ramais"; 
        $lstrSql.= " where x_acc_conta = '$lstrConta'"; 
        $rs = db_query($lstrSql,$conn);   
        $datars=db_fetch_array($rs);   
        $lstrRamais =$datars['x_ura_numeros'];  
        $lstrComandos =$datars['x_ura_comandos'];  
        $lstComandoTo =$datars['x_ura_comando_timeout'];  
        $lstrArqSaudacao =$datars['x_ura_arquivo_saudacao'];  
        $lstrArqFeriado =$datars['x_ura_arquivo_feriado'];  
        $lstrMohRing =$datars['x_ura_moh_ring'];  
        $lstrClasseMoh =$datars['musiconhold'];  
        $lstrArqOcupado =$datars['x_ura_arquivo_ocupado'];  
        $lstrTipo =$datars['x_ura_tipo'];  
        $lstrAleatorio =$datars['x_ura_escolha_aleatoria'];  
        $lstrUraFeriado1 =$datars['x_ura_feriado_1'];  
        $lstrUraFeriado2 =$datars['x_ura_feriado_2'];  
        $lstrUraSabado =$datars['x_ura_sabado'];  
        $lstrUraDomingo =$datars['x_ura_domingo'];  
        $lstrUraSegundaSexta =$datars['x_ura_segunda_sexta'];  
        $larrComandos = split(',',$lstrComandos); 
        $larrRamais = split(',',$lstrRamais); 
        $lstrRamaisCount=count($larrRamais); 
        $lbolcallPending = true; 
 
        db_close($conn); 
 
        $agi->verbose("ura Query:            $lstrSql");  
        $agi->verbose("ura Ramais:           $lstrRamais");  
        $agi->verbose("ura Comando:          $lstrComandos");  
        $agi->verbose("ura Comando TimeOut:  $lstComandoTo");  
        $agi->verbose("ura Arquivo Saudacao: $lstrArqSaudacao");  
        $agi->verbose("ura Arquivo Feriado:  $lstrArqFeriado");  
        $agi->verbose("ura Usa Moh como Ring:$lstrMohRing");  
        $agi->verbose("ura Classe Moh       :$lstrClasseMoh");  
        $agi->verbose("ura Arquivo Ocupado:  $lstrArqOcupado");  
        $agi->verbose("ura Tipo:             $lstrTipo");  
        $agi->verbose("ura Aleatorio:        $lstrAleatorio");  
        $agi->verbose("ura Origem:           $lstrRamaisCount");  
 
        if ($lstrArqSaudacao != '' ||  $lstrArqFeriado != '' || $lstrArqOcupado 
!= '' ){ 
                $agi->Answer(); 
                $lbolcallPending =false; 
        } 
 
        if 
(valida_feriado($lstrUraFeriado1,$lstrUraFeriado2,$lstrUraSabado,$lstrUraDomingo,$lstrUraSegundaSexta,$agi)
 !== false) { 
                if ( $lstrArqFeriado != '') { 
                        
$agi->exec('Playback',"ura/$lstrConta/$lstrArqFeriado"); 
                } 
                $agi->verbose("saindo da ura");  
                return false; 
        }
 
        $agi->verbose("passo 2");  
 
        if ($lstrAleatorio == 'yes') { 
                $lintCount=RAND(0,$lstrRamaisCount-1); 
        } else { 
                $lintCount = 0; 
        } 
 
        $lbolTrava = true; 
        $input=''; 
        $lboltimeOut=true; 
        While($lbolTrava && $lstrTipo != ''){ 
                if ($lstrTipo == '1' || $lstrTipo == '2') { 
                        if($input == '') { 
                                $input = 
$agi->get_data("ura/$lstrConta/$lstrArqSaudacao",0,1,'#'); 
                                $agi->verbose("ura input:".$input['result']);  
                                if ($input['result'] == '-' || $input['result'] 
== '-1') {
                                        exit;
                                } 
                                $input = $input['result']; 
                        } 
 
                        if (($input == '') && $lboltimeOut === true) { 
                                $input=$lstComandoTo;  
                                $lboltimeOut=false; 
                        } 
 
                        $lstrchannel = $agi->channel_status();
                        $agi->verbose("ura channel:".$lstrchannel['data']);  
                        if  ($lstrchannel['data'] != 'Line is up') {
                                $agi->hangup();
                                exit;
                        }
 
                        $lstrRamal = 'error'; 
 
                        $i=0; 
 
                        while ($i <= count($larrComandos) -1 ) { 
                                $lstrComandoA=$larrComandos[$i]; 
                                if(trim($input) == trim($lstrComandoA)) { 
                                        $lstrComando=$i; 
                                        $i=count($larrComandos) + 1; 
                                } 
 
                                $i=$i + 1; 
                        };  
 
                        if( is_numeric($lstrComando)) { 
                                $lstrRamal=$larrRamais[$lstrComando]; 
                        }else { 
                                $lstrRamal=''; 
                        } 
 
                        if ($lstrRamal != 'error' || $lstrRamal != '') { 
                                $lboltimeOut = true; 
                        } 
                } 
 
                if ($lstrTipo == '7') { 
                        $lstrRamal=$larrRamais[$lintCount]; 
                        $lintCount=$lintCount + 1; 
 
                        $agi->verbose("ura Count array: ".count($larrRamais));  
                        $agi->verbose("ura Count:            $lintCount");  
                        if( $lintCount > count($larrRamais)-1  ){ 
                                $lintCount = 0; 
                        } 
                } 
                if ($lstrTipo == '6') { 
                        $lstrRamal=$larrRamais[$lintCount]; 
                        if( $lstrRamal == '' ){ 
                                $lbolTrava = false; 
                        } 
                } 
 
                if ($lstrTipo != '1' && $lstrTipo != '2') { 
                        $input=''; 
                } 
 
                if ($lbolTrava == false) { 
                        Exit; 
                } 
 
                if ( $lstrRamal != '' ) { 
                        if (trim($lstrMohRing) == 'yes') { 
                                $agi->exec('SetMusicOnHold',$lstrClasseMoh); 
                                
$agi->exec('Dial','Local/'.$lstrRamal.'@ramais|60|m('.$lstrClasseMoh.')'); 
                        } else {
                                
$agi->exec('Dial','Local/'.$lstrRamal.'@ramais|60'); 
                        } 
                } 
        
                $lstrDialStatus = $agi->get_variable('DIALSTATUS',TRUE);   
                $agi->verbose("ura status ramal : $lstrRamal=$lstrDialStatus"); 
 
                if ($lstrTipo == '2' || strpos('ANSWER',$lstrDialStatus) !== 
false || strpos('CANCEL',$lstrDialStatus) !== false || trim($lstrDialStatus) == 
'') { 
                        if ($lstrArqOcupado != '') { 
                                
$agi->exec('Playback',"ura/$lstrConta/$lstrArqOcupado"); 
                        } 
                        $agi->hangup(); 
                        Exit; 
                } 
                if ( ($lstrTipo == '1' || $lstrTipo == '6' || ($lstrTipo == '7' 
&& $lintCount == 0) ) && strpos('ANSWER',$lstrDialStatus) === false) { 
                        if ($lstrArqOcupado != '') { 
                                
$agi->exec('Playback',"ura/$lstrConta/$lstrArqOcupado"); 
                        } 
                        $agi->verbose("Aguarda 3 segundos e tenta novamente");  
                        sleep(3); 
                } 
        } 
                $agi->hangup; 
                exit; 
        } 
        
function valida_feriado($lstrFeriados1,$lstrFeriados2, $lstrSabados, 
$lstrDomingos, $lstrSegSexs,$agi) { 

        $larrFeriados1 = array();
        $larrFeriados2 = array();
        $larrSabados = array();
        $larrDomingos = array();
        $larrSegSexs = array();
        IF (trim($lstrFeriados1) <> "") {
                $larrFeriados1 = split(',',$lstrFeriados1);
        }

        IF (trim($lstrFeriados2) <> "") {
                $larrFeriados2 = split(',',$lstrFeriados2);
        }

        IF (trim($lstrSabados) <> "") {
                $larrSabados   = split(',',$lstrSabados);
        }

        IF (trim($lstrDomingos) <> "") {
                $larrDomingos  = split(',',$lstrDomingos);
        }

        IF (trim($lstrSegSexs) <> "") {
                $larrSegSexs   = split(',',$lstrSegSexs);
        }

        $ldtaHoje=getdate();
        $dias_semana = array('SUN', 'MON', 'TUE','WED', 'THU', 'FRI', 'SAT');

        $lintHora      = date('G',$ldtaHoje[0]) ;
        $lstrDiaSemana = $dias_semana[date('w',$ldtaHoje[0])];
        $lstrData      = date('d/m/Y',$ldtaHoje[0]) ;

        $lbolNotFeriado = false;


        $agi->verbose("entrando da validação de feriado");  
        $agi->verbose("Data Atual:           $lstrData");  
        $agi->verbose("Dia Semana:           $lstrDiaSemana");  
        $agi->verbose("Hora:                 $lintHora");  
        $agi->verbose("Feriados1:            ".count($larrFeriados1));  
        $agi->verbose("Feriados2:            ".count($larrFeriados2));  
        $agi->verbose("Sabados:              ".count($larrSabados));  
        $agi->verbose("Domingos:             ".count($larrDomingos));  
        $agi->verbose("SegSexs:              ".count($larrSegSexs));  
        IF (count($larrFeriados1) > 0) {
                $i = 0;
                while ($i <= count($larrFeriados1) -1) {
                        $agi->verbose("validando feriado 1");  

                        $lstrDataFeriado1 = $larrFeriados1[$i];

                        $lintHoraInicial = Substr($lstrDataFeriado1,11,2);
                        $lintHoraFinal   = Substr($lstrDataFeriado1,14,2);
                        IF (Substr($lstrDataFeriado1,0,10) == $lstrData) {
                                if ($lintHora >= $lintHoraInicial && $lintHora 
< $lintHoraFinal) {
                                        $lbolNotFeriado = true; 
                                }
                        }

                        $i = $i + 1;
                }

                if ($lbolNotFeriado) {
                        return false;
                }
        }

        $lbolNotFeriado = false;
        IF (count($larrFeriados2) > 0) {
                $i = 0;
                while ($i <= count($larrFeriados2) - 1) {
                        $lstrDataFeriado2 = $larrFeriados2[$i];
                        $lintHoraInicial = Substr($lstrDataFeriado2,11,2);
                        $lintHoraFinal   = Substr($lstrDataFeriado2,14,2);

                        IF (Substr($lstrDataFeriado2,0,10) == $lstrData) {
                                if ($lintHora >= $lintHoraInicial && $lintHora 
< $lintHoraFinal) {
                                        $lbolNotFeriado = true; 
                                }
                        }

                        $i = $i + 1;
                }
                if ($lbolNotFeriado) {
                        return false;
                }
        }
        $lbolNotFeriado = false;
        IF (count($larrSabados) > 0) {
                if ($lstrDiaSemana == 'SAT')  {
                        $i = 0;
                        while ($i <= count($larrSabados) -1) {
                                $lstrDataSabado = $larrSabados[$i];
                                if ($lstrDataSabado != '' && $lstrDataSabado != 
null) {
                                        $lintHoraInicial = 
Substr($lstrDataSabado,0,2);
                                        $lintHoraFinal   = 
Substr($lstrDataSabado,3,2);

                                        if ($lintHora >= $lintHoraInicial && 
$lintHora < $lintHoraFinal) {
                                                $lbolNotFeriado = true;
                                        }
                                }
                                $i = $i + 1;
                        }
                        if ($lbolNotFeriado) {
                                return false;
                        } else {
                                return true;
                        }
                }
        }

        $lbolNotFeriado = false;
        IF (count($larrDomingos) > 0) {
                if ($lstrDiaSemana == 'SUN')  {

                        $i = 0;
                        while ($i <= count(larrDomingos) -1) {
                                $lstrDataDomingo = $larrDomingos[$i];
                                if ($lstrDataDomingo != '' && $lstrDataDomingo 
!= null) {
                                        $lintHoraInicial = 
Substr($lstrDataDomingo,0,2);
                                        $lintHoraFinal   = 
Substr($lstrDataDomingo,3,2);
                                        if ($lintHora >= $lintHoraInicial && 
$lintHora < $lintHoraFinal) {
                                                $lbolNotFeriado = true;
                                        }
                                }
                                $i = $i + 1;
                        }
                        if ($lbolNotFeriado) {
                                return false;
                        } else {
                                return true;
                        }
                }
        }
        $lbolNotFeriado = false;
        IF (count($larrSegSexs) > 0) {
                if (strpos('|MON|TUE|WED|THU|FRI|',$lstrDiaSemana) !== false)  {

                        $i = 0;
                        while ($i <= count($larrSegSexs) -1) {
                                $lstrDataSegSex = $larrSegSexs[$i];     
                                if ($lstrDataSegSex != '' && $lstrDataSegSex != 
null) {
                                        $lintHoraInicial = 
Substr($lstrDataSegSex,0,2);
                                        $lintHoraFinal   = 
Substr($lstrDataSegSex,3,2);
                                        if ($lintHora >= $lintHoraInicial && 
$lintHora < $lintHoraFinal) {
                                                $lbolNotFeriado = true;
                                        }
                                }
                                $i = $i + 1;
                        }
                        if ($lbolNotFeriado) {
                                return false;
                        } else {
                                return true;
                        }
                }
        }
        $agi->verbose("saindo da validação de feriado");  
        return false;
}
?> 
_______________________________________________
Openmoko Freerunner, primeiro telefone open source, disponível no Brasil 
rodando o Android da Google.
http://www.neodroid.com

Compre uma camiseta da AsteriskBrasil.org!
http://www.voipmania.com.br

Acesse o canal IRC de discussão sobre Asterisk em Português Brasileiro na rede 
Freenode.net: #asterisk-br
_______________________________________________
Lista de discussões AsteriskBrasil.org
AsteriskBrasil@listas.asteriskbrasil.org
http://listas.asteriskbrasil.org/mailman/listinfo/asteriskbrasil

Responder a