/**
  * Executa a ação. É chamado dentro de uma instancia usando AGI.
  *
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     $tronco = PBX_Trunks::get($this->config['tronco']);
     // Montando as Flags para limite na ligação
     $flags = $this->config['dial_flags'];
     if (isset($this->config['dial_limit']) && $this->config['dial_limit'] > 0) {
         $flags .= "L(" . $this->config['dial_limit'];
         // play_warning_value
         if (isset($this->defaultConfig['play_warning']) && $this->defaultConfig['play_warning'] > 0) {
             $flags .= ":" . $this->defaultConfig['play_warning'];
             // warning_freq
             if (isset($this->defaultConfig['warning_freq']) && $this->defaultConfig['warning_freq'] > 0) {
                 $flags .= ":" . $this->defaultConfig['warning_freq'];
             }
         }
         $flags .= ")";
         if (isset($this->defaultConfig['warning_sound'])) {
             $warning_sound = $this->defaultConfig['warning_sound'] != "" ? $this->defaultConfig['warning_sound'] : "beep";
             $asterisk->set_variable("LIMIT_WARNING_FILE", $warning_sound);
         }
     }
     if ($tronco->getDtmfDialMode()) {
         $dst_number = $tronco->getDtmfDialNumber();
         $flags .= "D({$request->destino})";
     } else {
         $dst_number = $request->destino;
     }
     if ($tronco->getInterface() instanceof PBX_Asterisk_Interface_SIP_NoAuth || $tronco->getInterface() instanceof PBX_Asterisk_Interface_IAX2_NoAuth) {
         $destiny = $tronco->getInterface()->getTech() . "/" . $dst_number . "@" . $tronco->getInterface()->getHost();
     } else {
         $postfix = isset($this->config['omit_kgsm']) && $this->config['omit_kgsm'] == "true" ? "/orig=restricted" : "";
         $destiny = $tronco->getInterface()->getCanal() . "/" . $dst_number . $postfix;
     }
     $flags .= "A({$this->config['announce']})";
     $log->info("Discando para {$request->destino} atraves do tronco {$tronco->getName()}({$destiny})");
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $lastdialstatus = $dialstatus['data'];
     if (Zend_Registry::get('outgoingNumber') !== "") {
         $asterisk->set_variable("CALLERID(num)", Zend_Registry::get('outgoingNumber'));
     }
     $log->debug("Dial({$destiny}, {$this->config['dial_timeout']}, {$flags}");
     // ==== DIAL ====
     $asterisk->exec_dial($destiny, $this->config['dial_timeout'], $flags);
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $log->debug("DIALSTATUS: " . $dialstatus['data']);
     // Enviar email de alerta.
     if (isset($this->config['alertEmail']) && $this->config['alertEmail'] != "") {
         $informations = array('Regra' => $this->getRule(), 'Hora da chamada' => date('H:i'), 'Data da chamada' => date('d/m/Y'), 'Origem Original' => $request->getOriginalCallerid(), 'Destino original' => $request->getOriginalExtension(), 'Origem' => $request->origem, 'Destino' => $request->destino, 'Status da Ligação' => $dialstatus['data']);
         if ($lastdialstatus != "") {
             $lastdialaction = null;
             foreach ($this->getRule()->getAcoes() as $action) {
                 if ($action == $this) {
                     break;
                 }
                 $cfg = $action->getConfigArray();
                 if ($action instanceof FaxOutAction) {
                     $lastdialaction = PBX_Trunks::get($cfg['tronco']);
                 } else {
                     if ($action instanceof PBX_Rule_Action_DiscarRamal) {
                         $lastdialaction = $cfg['ramal'];
                     }
                 }
             }
             $informations["\nHouve uma tentativa de ligação anterior"] = "";
             $informations["Ultima ligação para"] = $lastdialaction;
             $informations["Estado da ultima ligação"] = $lastdialstatus;
         }
         $this->sendMailAlert(explode(",", $this->config['alertEmail']), $informations);
     }
     switch ($dialstatus['data']) {
         case 'ANSWER':
         case 'CANCEL':
         case 'NOANSWER':
         case 'BUSY':
             throw new PBX_Rule_Action_Exception_StopExecution("Fim da ligacao");
             break;
         default:
             $log->err($dialstatus['data'] . " ao discar para {$request->destino} pelo tronco {$tronco}");
     }
 }
Ejemplo n.º 2
0
 /**
  * Executa a ação. É chamado dentro de uma instancia usando AGI.
  *
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     $trs = $this->i18n;
     $tronco = PBX_Trunks::get($this->config['tronco']);
     // Montando as Flags para limite na ligação
     $flags = $this->config['dial_flags'];
     if (isset($this->config['dial_limit']) && $this->config['dial_limit'] > 0) {
         $flags .= "L(" . $this->config['dial_limit'];
         // play_warning_value
         if (isset($this->defaultConfig['play_warning']) && $this->defaultConfig['play_warning'] > 0) {
             $flags .= ":" . $this->defaultConfig['play_warning'];
             // warning_freq
             if (isset($this->defaultConfig['warning_freq']) && $this->defaultConfig['warning_freq'] > 0) {
                 $flags .= ":" . $this->defaultConfig['warning_freq'];
             }
         }
         $flags .= ")";
         if (isset($this->defaultConfig['warning_sound'])) {
             $warning_sound = $this->defaultConfig['warning_sound'] != "" ? $this->defaultConfig['warning_sound'] : "beep";
             $asterisk->set_variable("LIMIT_WARNING_FILE", $warning_sound);
         }
     }
     if ($tronco->getDtmfDialMode()) {
         $dst_number = $tronco->getDtmfDialNumber();
         $flags .= "D({$request->destino})";
     } else {
         $dst_number = $request->destino;
     }
     if ($tronco->getInterface() instanceof PBX_Asterisk_Interface_SIP_NoAuth || $tronco->getInterface() instanceof PBX_Asterisk_Interface_IAX2_NoAuth) {
         $destiny = $tronco->getInterface()->getTech() . "/" . $dst_number . "@" . $tronco->getInterface()->getHost();
     } else {
         $postfix = isset($this->config['omit_kgsm']) && $this->config['omit_kgsm'] == "true" ? "/orig=restricted" : "";
         $destiny = $tronco->getInterface()->getCanal() . "/" . $dst_number . $postfix;
     }
     $log->info("Dialing to {$request->destino} through trunk {$tronco->getName()}({$destiny})");
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $lastdialstatus = $dialstatus['data'];
     if (Zend_Registry::get('outgoingNumber') !== "") {
         $asterisk->set_variable("CALLERID(num)", Zend_Registry::get('outgoingNumber'));
     }
     $log->debug("Dial({$destiny}, {$this->config['dial_timeout']}, {$flags})");
     // ==== DIAL ====
     $asterisk->exec_dial($destiny, $this->config['dial_timeout'], $flags);
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $log->debug("DIALSTATUS: " . $dialstatus['data']);
     // Enviar email de alerta.
     if (isset($this->config['alertEmail']) && $this->config['alertEmail'] != "") {
         $informations = array($trs->translate('Rule') => $this->getRule(), $trs->translate('Call Time') => date('H:i'), $trs->translate('Call Date') => date('d/m/Y'), $trs->translate('Original Source') => $request->getOriginalCallerid(), $trs->translate('Original Destination') => $request->getOriginalExtension(), $trs->translate('Source') => $request->origem, $trs->translate('Destination') => $request->destino, $trs->translate('Call status') => $dialstatus['data']);
         if ($lastdialstatus != "") {
             $lastdialaction = null;
             foreach ($this->getRule()->getAcoes() as $action) {
                 if ($action == $this) {
                     break;
                 }
                 $cfg = $action->getConfigArray();
                 if ($action instanceof DiscarTronco) {
                     $lastdialaction = PBX_Trunks::get($cfg['tronco']);
                 } else {
                     if ($action instanceof DiscarRamal) {
                         $lastdialaction = $cfg['ramal'];
                     }
                 }
             }
             $informations[$trs->translate("\nThere were a previous call attempt")] = "";
             $informations[$trs->translate("Last call to")] = $lastdialaction;
             $informations[$trs->translate("Status of last call")] = $lastdialstatus;
         }
         $this->sendMailAlert(explode(",", $this->config['alertEmail']), $informations);
     }
     switch ($dialstatus['data']) {
         case 'ANSWER':
         case 'CANCEL':
         case 'NOANSWER':
         case 'BUSY':
             throw new PBX_Rule_Action_Exception_StopExecution("Call end");
             break;
         default:
             $log->err($dialstatus['data'] . " dialing to {$request->destino} through trunk {$tronco}");
     }
 }