#!/usr/bin/php -q getMessage(), $ex->getFile(), $ex->getLine(), $sql, date('Y-m-d H:i:s')); WriteLog($log, $pathLog); } function ibRaiseExcept($msg, $dbError = true) { if ($dbError) { $msg .= " DB: " . pg_last_error(); } GeraExcept($msg); } function discGetConnection() { /* * Se precisar de uma conexão diferente da padrão, espcifique sua propria connection string. * $connStr = sprintf("host='%s' port='%s' dbname='%s' user='%s' password='%s'", '127.0.0.1', '5432', 'pbx', 'contacte', 'ctepgSQL'); */ $connStr = ''; $connStr = !$connStr ? GetDefStrDb() : $connStr; $conn = pg_connect($connStr); if (!$conn) { GeraExcept("Não foi possível estabelecer uma conexão com o banco de dados!"); } return $conn; } function LiberaDiscador($db) { global $dac; $liberar = $_REQUEST['liberar']; $msg = $_REQUEST['msg']; $status = $_REQUEST['status']; $confId = $_REQUEST['conf_id']; $contId = $_REQUEST['cont_id']; $inTran = 0; $matricula = GetMatricula(); $uid = trim($_REQUEST['uniqueid']); $uid = $uid ? QuotedStr($uid) : 'null'; try { if ((GetDadosDiscador($dac, 0) === false)) { GeraExcept("ERRO;Não há atendimento pendente!"); } /* * se a classificação ogrigatória estiver configurada, * garante que o discador não será liberado até que a * chamada seja classificada. if(GetExigeClas()) { $liberar = 0; } */ if ($_SESSION[SS_STATUS_AGENTE] == 'OCUPADO') { GeraExcept("ERRO; Não é possível encerrar o atendimento quando \"Ocupado\"!"); }; if (GetExigeClas() && !ChamdaClassificadaAgente($db, $matricula)) { GeraExcept("ERRO;Para gravar o atendimento a chamda deve estar classificada!"); } $result = pg_query($db, 'begin'); if (!$result) { GeraExcept("ERRO;Não foi iniciar uma transação!"); } $inTran = 1; $query = "update pbx_supervisor_agentes set status_discador = '1' where matricula = '$matricula'"; $result = pg_query($db, $query); if (!$result) { GeraExcept("ERRO;Erro ao liberar o agente!"); }; /* * Marca o telefone com o ultimo staus */ // "update pbx_campanha_contato_fone set conf_status = %s, conf_agente_matricula = %s, conf_uid = %s where conf_id = %s"; $query = "update pbx_campanha_contato_fone set conf_discado = %s, conf_status = %s, conf_agente_matricula = %s, conf_uid = %s where conf_id = %s"; $query = sprintf($query, QuotedStr($liberar), QuotedStr($status), QuotedStr($matricula), $uid, QuotedStr($confId)); $result = pg_query($db, $query); if (!$result || !pg_affected_rows($result)) { GeraExcept("ERRO;Não foi possível atualizar o número informado!"); } /* * Marca o contato da lista com discado. */ $query = sprintf("update pbx_campanha_contato set cont_discado = 1, cont_status = %s, cont_fechamento = now(), cont_msg = %s where cont_id = %s", QuotedStr($status), QuotedStr($msg), QuotedStr($contId)); $result = pg_query($db, $query); if (!$result) { GeraExcept("ERRO;Erro ao alterar o contato do número discado!"); }; /* * Libera o registro para nova discagem. */ $query = sprintf("update pbx_campanha_operacao set cmpo_status = %s, cmpo_fim = now() where cont_id = %s and cmpo_status in(0,2) and matricula = %s", QuotedStr($liberar ? '1' : '2'), QuotedStr($contId), QuotedStr($matricula)); $result = pg_query($db, $query); if (!$result) { GeraExcept("ERRO;Erro ao alterar o status da operação!"); }; // if (!$liberar) { // if (GetDispoDiscador()) { // DisponivelAtendimento(); // SetDispoDiscador(false); // } // } $result = pg_query($db, 'commit'); if (!$result) { GeraExcept("ERRO;Não foi finalizar a transação!"); } echo sprintf("OK;Liberação executada com sucesso!;%s", QuotedStr($liberar ? 'S' : 'N')); } catch (Exception $ex) { RegistraLogAgente("LiberaDiscador", $ex->getMessage(), $ex); if ($inTran) { pg_query($db, 'rollback'); } echo $ex->getMessage(); } }