forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.2 KiB
162 lines
5.2 KiB
#!/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ã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(); |
|
} |
|
}
|
|
|