|
|
|
|
#!/usr/bin/php -q
|
|
|
|
|
<?php
|
|
|
|
|
error_reporting(E_ERROR);
|
|
|
|
|
ini_set('display_errors', 0);
|
|
|
|
|
include("util/util.php");
|
|
|
|
|
include("funcoes/shared.php");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Realiza a conexao com o banco de dados.
|
|
|
|
|
*/
|
|
|
|
|
$dbcon = discGetConnection();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Variavel indica uma transacao em curso.
|
|
|
|
|
*/
|
|
|
|
|
$inTran = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Log do sistema
|
|
|
|
|
*/
|
|
|
|
|
$pathLog = "/var/log/asterisk/importa_bilhetes.log";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
/*
|
|
|
|
|
* verifica se a conexao foi criada com sucesso.
|
|
|
|
|
*/
|
|
|
|
|
if (pg_connection_status($dbcon) === PGSQL_CONNECTION_BAD) {
|
|
|
|
|
ibRaiseExcept("Nao foi possivel conecta com o banco de dados!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$log = sprintf("Importados Dacs: %s Bilhetes: %s Excluidos %s Registros Duplicados %s OK\n", $numDacs, $numBilhetes, $numDuplic, date('Y-m-d H:i:s'));
|
|
|
|
|
WriteLog($log, $pathLog);
|
|
|
|
|
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$log = sprintf("Erro:%s File: %s Line: %s \ncmd: %s\n %s\n", $ex->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<EFBFBD>o diferente da padr<EFBFBD>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<EFBFBD>o foi poss<EFBFBD>vel estabelecer uma conex<EFBFBD>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<EFBFBD>o h<EFBFBD> atendimento pendente!");
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* se a classifica<EFBFBD><EFBFBD>o ogrigat<EFBFBD>ria estiver configurada,
|
|
|
|
|
* garante que o discador n<EFBFBD>o ser<EFBFBD> liberado at<EFBFBD> que a
|
|
|
|
|
* chamada seja classificada.
|
|
|
|
|
|
|
|
|
|
if(GetExigeClas())
|
|
|
|
|
{
|
|
|
|
|
$liberar = 0;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if ($_SESSION[SS_STATUS_AGENTE] == 'OCUPADO') {
|
|
|
|
|
GeraExcept("ERRO; N<EFBFBD>o <EFBFBD> poss<EFBFBD>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<EFBFBD>o foi iniciar uma transa<EFBFBD><EFBFBD>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<EFBFBD>o foi poss<EFBFBD>vel atualizar o n<EFBFBD>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<EFBFBD>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<EFBFBD><EFBFBD>o!");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!$liberar) {
|
|
|
|
|
// if (GetDispoDiscador()) {
|
|
|
|
|
// DisponivelAtendimento();
|
|
|
|
|
// SetDispoDiscador(false);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
$result = pg_query($db, 'commit');
|
|
|
|
|
if (!$result) {
|
|
|
|
|
GeraExcept("ERRO;N<EFBFBD>o foi finalizar a transa<EFBFBD><EFBFBD>o!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo sprintf("OK;Libera<EFBFBD><EFBFBD>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();
|
|
|
|
|
}
|
|
|
|
|
}
|