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.
242 lines
10 KiB
242 lines
10 KiB
#!/usr/bin/php -q |
|
<?php |
|
include("bd.php"); |
|
include("util/util.php"); |
|
include("util/Pid.php"); |
|
|
|
$debug = (isset($argv[4]) && ($argv[4] == 'DEBUG')) ? 1 : 0; |
|
$path = "/var/log/asterisk/log_erro_pabx.log"; |
|
$p1 = trim($argv[1]); |
|
$p2 = isset($argv[2]) ? trim($argv[2]) : ''; |
|
$p3 = isset($argv[3]) ? trim($argv[3]) : ''; |
|
$TBL_AGENTES = "pbx_supervisor_agentes"; |
|
$log = ''; |
|
try { |
|
|
|
if (!$p1 || !$p2 || !$dbcon) { |
|
GeraExcept("Parametros de entrada invalidos, Argv1: $p1 Argv2: $p2 "); |
|
} |
|
|
|
if ($p1 == "CANALTRANSFER") { |
|
|
|
list($tipocanal, $ramal) = explode('/', $p2); |
|
|
|
if ($tipocanal != "Local") { |
|
list($ramal) = explode("-", $ramal); |
|
} |
|
|
|
$query = "UPDATE $TBL_AGENTES SET canal_transfer = '' WHERE ramal = '$ramal'"; |
|
if (!pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} else if ($p1 == "AGENTE-LOGOFF") { |
|
|
|
$query = "select count(*) from $TBL_AGENTES where status in ('PAUSA','OCUPADO') and matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$STATUS = GetDbField($result); |
|
if (!$STATUS) { |
|
|
|
$query = "delete from $TBL_AGENTES where matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
|
|
$log = sprintf("Data: %s Agente: %s Status: %s", date("d-m-Y H:i:s"), $p2, $p3); |
|
WriteLog($log, "/var/log/asterisk/atualizar-agente.log"); |
|
} |
|
} else if ($p1 == "ESCUTA-CLASSIFICACAO") { |
|
|
|
$query = "UPDATE $TBL_AGENTES SET canal_agente = '$p3' WHERE ramal = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} else if ($p1 == "PAUSA-AUSENTE") { |
|
|
|
$query = "select matricula from $TBL_AGENTES where ramal = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$MATRICULA = GetDbField($result); |
|
|
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$AUSENTE = GetDbField($result); |
|
|
|
if (!$AUSENTE) { |
|
|
|
$query = "insert into pbx_motivos_pausas (motivo) values ('AUSENTE')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$AUSENTE = GetDbField($result); |
|
} |
|
|
|
$query = "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$AUSENTE',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$MATRICULA') "; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$ID_EVENTOS_AGENTE = GetCurrVal("pbx_eventos_agentes"); |
|
|
|
$query = "UPDATE $TBL_AGENTES SET status = 'PAUSA',protocolo = '', duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '', tipo_discagem = '',motivo_pausa = 'ausente', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$MATRICULA'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
//INICIO: INCLUSAO - ALAN PABLO |
|
} else if ($p1 == "PAUSA-RECUSADA") { |
|
|
|
$query = "select matricula from $TBL_AGENTES where ramal = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$MATRICULA = GetDbField($result); |
|
|
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('recusada')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$RECUSADA = GetDbField($result); |
|
|
|
if (!$RECUSADA) { |
|
|
|
$query = "insert into pbx_motivos_pausas (motivo) values ('RECUSADA')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('recusada')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$RECUSADA = GetDbField($result); |
|
} |
|
|
|
$query = "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$RECUSADA',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$MATRICULA') "; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$ID_EVENTOS_AGENTE = GetCurrVal("pbx_eventos_agentes"); |
|
|
|
$query = "UPDATE $TBL_AGENTES SET status = 'PAUSA',protocolo = '', duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '', tipo_discagem = '',motivo_pausa = 'recusada', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$MATRICULA'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
|
|
//FIM: INCLUSAO - ALAN PABLO |
|
} else if ($p1 == "RAMAL") { |
|
$query = "select count(*) from $TBL_AGENTES where status in ('PAUSA') and ramal = '$p3'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$PAUSA = GetDbField($result); |
|
|
|
|
|
if (!$PAUSA) { |
|
$query = "UPDATE $TBL_AGENTES SET status = '$p2' , duracao = 'now()' , origem_destino = '',canal = '' , sala_1 = '' , sala_2 = '' , facilidade = '' , canal_agente = '' , canal_transfer = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '', protocolo = '' WHERE ramal = '$p3'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} |
|
} else if ($p1 == "GRAVACAO") { |
|
|
|
$query = "UPDATE $TBL_AGENTES SET status_gravacao = 'V' WHERE matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} else if ($p1 == "LOGIN") { |
|
$query = "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '',motivo_pausa = 'login' WHERE matricula = '$p2'"; |
|
if (!($result = pg_query($dbcon, $query))) { |
|
RaiseExcept("Erro Exec: " . $query); |
|
} |
|
if (!pg_affected_rows($result)) { |
|
RaiseExcept("Registro nao encontrado para upd: " . $query); |
|
} |
|
} else { |
|
|
|
$query = "select dac from pbx_supervisor_agentes where matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$FILA = GetDbField($result); |
|
|
|
|
|
$query = "select count(*) from pbx_pausa_automatica where iddac = (select id from pbx_queues_grupos where nome = '$FILA') "; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$AUTOPAUSA = GetDbField($result); |
|
if ($AUTOPAUSA) { |
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$ACW = GetDbField($result); |
|
if (!$ACW) { |
|
$query = "insert into pbx_motivos_pausas (motivo) values ('acw')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
|
|
$query = "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$ACW = GetDbField($result); |
|
} |
|
|
|
$query = "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$ACW',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$p2');"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$ID_EVENTOS_AGENTE = GetCurrVal("pbx_eventos_agentes"); |
|
|
|
$query = "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '',tipo_discagem = '',motivo_pausa = 'acw', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} |
|
|
|
$query = "select count(*) from $TBL_AGENTES where status = 'PAUSA' and matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
$PAUSA = GetDbField($result); |
|
|
|
if ($PAUSA) { |
|
$query = "UPDATE $TBL_AGENTES SET origem_destino = '',tipo_ligacao = '',status_gravacao = 'F', protocolo = '', uniqueid = '',canal = '',canal_agente = '',canal_transfer = '' WHERE matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} else { |
|
$query = "UPDATE $TBL_AGENTES SET status = '$p1',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '',tipo_discagem = '', protocolo = '' WHERE matricula = '$p2'"; |
|
if (!$result = pg_query($dbcon, $query)) { |
|
RaiseExcept($query); |
|
} |
|
} |
|
} |
|
|
|
_LogLocal(); |
|
} catch (Exception $ex) { |
|
$log .= sprintf("Script: %s Data: %s Erro: %s Erro Sys: %s Erro Db: %s\n", $argv[0], date("Y-m-d H:m:i"), $ex->getMessage(), GetLasterror(), pg_last_error()); |
|
WriteLog($log, $path); |
|
} |
|
pg_close($dbcon); |
|
|
|
function _LogLocal() { |
|
global $path, $debug, $p1, $p2, $p3, $TBL_AGENTES, $query; |
|
|
|
if ($debug) { |
|
WriteLog(sprintf("P1: %s P2: %s P3: %s TB: %s Cmd: %s", $p1, $p2, $p3, $TBL_AGENTES, $query), $path); |
|
} |
|
}
|
|
|