if ((($tipo == 1) or ( $tipo == 2)) && !($getAgt || $getClass || $getItem)) {
if ((($tipo == 1) or ( $tipo == 2)) && !($getAgt || $getClass || $getItem)) {
$query = "DROP TABLE IF EXISTS tmp_restricao_ramal;
$query = "DROP TABLE IF EXISTS tmp_restricao_ramal$org_id;
CREATE TEMPORARY TABLE tmp_restricao_ramal AS
CREATE TEMPORARY TABLE tmp_restricao_ramal AS
SELECT DISTINCT x.nome FROM pbx_grupo_audio_ramal x, pbx_grupo_usuario y WHERE y.gp_id = x.gp_id AND y.user_id = '{$idUser}';
SELECT DISTINCT x.nome FROM pbx_grupo_audio_ramal x, pbx_grupo_usuario y WHERE y.gp_id = x.gp_id AND y.user_id = '{$idUser}' and x.org_id = y.org_id and x.org_id = $org_id;
CREATE INDEX \"tmpRestricaoRamalNome\" on tmp_restricao_ramal(nome);\n\n";
CREATE INDEX \"tmpRestricaoRamalNome\" on tmp_restricao_ramal$org_id(nome);\n\n";
$query .= "DROP TABLE IF EXISTS tmp_restricao_sigame;
$query .= "DROP TABLE IF EXISTS tmp_restricao_sigame$org_id;
CREATE TEMPORARY TABLE tmp_restricao_sigame as
CREATE TEMPORARY TABLE tmp_restricao_sigame$org_id as
SELECT sigame_externo FROM pbx_sip_ramais WHERE nome IN (SELECT nome FROM tmp_restricao_ramal) AND sigame_externo <> ''; ";
SELECT sigame_externo FROM pbx_sip_ramais WHERE nome IN (SELECT nome FROM tmp_restricao_ramal) AND sigame_externo <> '' and org_id = $org_id; ";
}
}
$addPdx = !($getAgt || $getClass || $getItem);
$addPdx = !($getAgt || $getClass || $getItem);
@ -305,20 +305,20 @@
$query .= " SELECT DISTINCT a.data_bilhete, a.uniqueid, CASE WHEN(b.evento <> '') THEN 'Fila' ELSE 'Ramal' END AS tipo,
$query .= " SELECT DISTINCT a.data_bilhete, a.uniqueid, CASE WHEN(b.evento <> '') THEN 'Fila' ELSE 'Ramal' END AS tipo,
CASE WHEN(b.evento in('COMPLETECALLER', 'COMPLETEAGENT','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL'))THEN 'entrada' ELSE 'saida' END AS direcao,
CASE WHEN(b.evento in('COMPLETECALLER', 'COMPLETEAGENT','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL'))THEN 'entrada' ELSE 'saida' END AS direcao,
c.id AS iddac, b.fila, d.apelido, a.calldate, a.src,
c.id AS iddac, b.fila, d.apelido, a.calldate, a.src,
CASE WHEN(b.evento IN('TRANSFERORIG', 'TRANSFER') )THEN strtoint(param4) ELSE strtoint(param2) END AS duration,
CASE WHEN(b.evento IN('TRANSFERORIG', 'TRANSFER') )THEN strtoint(param4) ELSE strtoint(param2) END AS duration,
1 AS acesso_audio \n";
1 AS acesso_audio \n";
}
}
$query .= "FROM pbx_bilhetes a
$query .= "FROM pbx_bilhetes a
LEFT JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento IN('COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG', 'COMPLETECALLER', 'COMPLETEAGENT', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL')
LEFT JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento IN('COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG', 'COMPLETECALLER', 'COMPLETEAGENT', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL') and b.org_id = a.org_id
LEFT JOIN pbx_dacs c ON c.nome = b.fila
LEFT JOIN pbx_dacs c ON c.nome = b.fila and c.org_id = b.org_id
LEFT JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente, 7,4)
LEFT JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente, 7,4)
LEFT JOIN pbx_protocolo_reg e ON e.uniqueid = a.uniqueid
LEFT JOIN pbx_protocolo_reg e ON e.uniqueid = a.uniqueid and e.org_id = a.org_id
LEFT JOIN pbx_classifica_reg f ON f.id_bilhetes = a.uniqueid
LEFT JOIN pbx_classifica_reg f ON f.id_bilhetes = a.uniqueid and f.org_id = a.org_id
LEFT JOIN pbx_classifica_item g ON g.clas_id = f.clas_id and g.clit_id = f.clit_id
LEFT JOIN pbx_classifica_item g ON g.clas_id = f.clas_id and g.clit_id = f.clit_id and g.org_id = f.org_id
LEFT JOIN pbx_classifica_atendimento h ON h.clas_id = f.clas_id
LEFT JOIN pbx_classifica_atendimento h ON h.clas_id = f.clas_id and h.org_id = f.org_id
WHERE a.org_id = {$org_id} AND a.billsec > 3 \n
WHERE a.org_id = {$org_id} AND a.billsec > 3 \n
AND exists(SELECT '' FROM pbx_fila_audios x, pbx_grupo_usuario y WHERE x.org_id = {$org_id} AND y.gp_id = x.gp_id AND y.user_id = '{$idUser}' and x.id = c.id)\n";
AND exists(SELECT '' FROM pbx_fila_audios x, pbx_grupo_usuario y WHERE x.org_id = {$org_id} AND y.gp_id = x.gp_id AND y.user_id = '{$idUser}' and x.id = c.id)\n";
function ___GetAgente($revendaUser, $agente = null, $empId = null) {
function ___GetAgente($revendaUser, $agente = null, $empId = null) {
global $dataIni, $dataFim;
global $dataIni, $dataFim;
$org_id = GetOrganizacao();
if (!$empId) {
if (!$empId) {
$query = "SELECT vdr_apelido AS apelido, vdr_matricula AS matricula, emp_id
$query = "SELECT vdr_apelido AS apelido, vdr_matricula AS matricula, emp_id
FROM vds_vendedores
FROM vds_vendedores
WHERE ";
WHERE ";
$query .= "emp_id IN ($revendaUser) ORDER BY apelido";
$query .= "emp_id IN ($revendaUser) and org_id = $org_id ORDER BY apelido";
} else {
} else {
$query = sprintf("SELECT DISTINCT vdr_apelido AS apelido, vdr_matricula AS matricula, a.emp_id
$query = sprintf("SELECT DISTINCT vdr_apelido AS apelido, vdr_matricula AS matricula, a.emp_id
FROM vds_chamadas a
FROM vds_chamadas a
INNER JOIN vds_vendedores b ON a.emp_id = b.emp_id
INNER JOIN vds_vendedores b ON a.emp_id = b.emp_id and a.org_id = b.org_id
WHERE chm_data_bilhete >= '%s' AND chm_data_bilhete <= '%s' AND b.emp_id = %s", FormatDtMssql($dataIni), FormatDtMssql($dataFim), $empId);
WHERE chm_data_bilhete >= '%s' AND chm_data_bilhete <= '%s' AND b.emp_id = %s and org_id = %d", FormatDtMssql($dataIni), FormatDtMssql($dataFim), $empId, $org_id);
$query = "SELECT id, prm_sk_host, prm_sk_port, prm_sk_login, prm_sk_password, prm_sk_host_externo, prm_sk_api_centrais FROM pbx_parametros WHERE id = {$_SESSION['prm_id']}";
$query = "SELECT id, prm_sk_host, prm_sk_port, prm_sk_login, prm_sk_password, prm_sk_host_externo, prm_sk_api_centrais FROM pbx_parametros WHERE id = {$_SESSION['prm_id']} and org_id = $org_id";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$dados = pg_fetch_array($result);
$dados = pg_fetch_array($result);
foreach ($fields as $value) {
foreach ($fields as $value) {
@ -444,13 +444,13 @@ if ($idSubProg == CONFIG_BASE_DADOS) {
} else {
} else {
if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) {
if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) {
from pbx_usuarios a, pbx_grupo_usuario b, pbx_fila_grupos c, pbx_dacs d
from pbx_usuarios a, pbx_grupo_usuario b, pbx_fila_grupos c, pbx_dacs d
where b.user_id = a.id
where b.user_id = a.id
and c.gp_id = b.gp_id
and c.gp_id = b.gp_id and c.org_id = d.org_id
and d.id = c.id
and d.id = c.id
and a.id = '$idUser' ";
and a.id = '$idUser'
c.org_id = $org_id";
/* $query = "select d.id, d.nome
/* $query = "select d.id, d.nome
from pbx_dac_usuario u, pbx_dacs d
from pbx_dac_usuario u, pbx_dacs d
where d.id = u.id_dac
where d.id = u.id_dac
@ -194,9 +198,10 @@ function GetIdDacPadrao($dbcon, $idUser)
{
{
if (IsAdmin()) {
if (IsAdmin()) {
return ;
return ;
} else {
$query = "select dac_padrao from pbx_usuarios where id = $idUser";
}
}
$query = "select dac_padrao from pbx_usuarios where id = $idUser";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$ret = 0;
$ret = 0;
@ -209,10 +214,12 @@ function GetIdDacPadrao($dbcon, $idUser)
function SetIdDacPadrao($dbcon, $idUser)
function SetIdDacPadrao($dbcon, $idUser)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT DISTINCT id_dac,nome_dac
$query = "SELECT DISTINCT id_dac,nome_dac
FROM pbx_usuarios a
FROM pbx_usuarios a
INNER JOIN pbx_usuarios_dacs b ON a.id = b.id_usuario
INNER JOIN pbx_usuarios_dacs b ON a.id = b.id_usuario
INNER JOIN pbx_dacs c ON id_dac = c.id
INNER JOIN pbx_dacs c ON id_dac = c.id and c.org_id = $org_id
WHERE a.id = $idUser
WHERE a.id = $idUser
AND c.status = 'A'
AND c.status = 'A'
ORDER BY 1
ORDER BY 1
@ -237,15 +244,18 @@ function GetLoginFromId($dbcon, $idUser)
function GetNomeDacPadrao($dbcon, $idUser)
function GetNomeDacPadrao($dbcon, $idUser)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
$isAdm = !$idUser && IsAdmin();
$isAdm = !$idUser && IsAdmin();
if ($isAdm) {
if ($isAdm) {
$query = "select d.id, d.nome
$query = "select d.id, d.nome
from pbx_dacs d
from pbx_dacs d
where d.status = 'A' limit 1";
where d.status = 'A' org_id = $org_id limit 1";
} else {
} else {
$query = "select b.id, b.nome from pbx_usuarios a, pbx_dacs b where b.id = a.dac_padrao and a.id = '$idUser'
$query = "select b.id, b.nome from pbx_usuarios a, pbx_dacs b where b.id = a.dac_padrao and a.id = '$idUser' and b.org_id = $org_id
union
union
select b.cmp_id as id, b.cmp_descricao as nome from pbx_usuarios a, pbx_campanha b where b.cmp_id = a.dac_padrao and a.id = '$idUser' ";
select b.cmp_id as id, b.cmp_descricao as nome from pbx_usuarios a, pbx_campanha b where b.cmp_id = a.dac_padrao and b.org_id = $org_id and a.id = '$idUser' ";
}
}
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
@ -271,29 +281,32 @@ function GetDacDesc($dbcon, $id)
function GetPausa($dbcon, $mat, $verPausa = false)
function GetPausa($dbcon, $mat, $verPausa = false)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
/*
/*
* Quando $verPausa é definido como true indica que apenas queremos
* Quando $verPausa é definido como true indica que apenas queremos
* nos certificar se o agente entrou em pausa. Quando a pausa é ativa-
* nos certificar se o agente entrou em pausa. Quando a pausa é ativa-
* da pelo supervisor precisamos alimentar os parametro da sessao cor-
* da pelo supervisor precisamos alimentar os parametro da sessao cor-
* rente entao $verPausa é definido como false.
* rente entao $verPausa é definido como false.
*/
*/
$query = "SELECT count(*) FROM pbx_supervisor_agentes WHERE matricula = '$mat' AND upper(status) = 'PAUSA'";
$query = "SELECT count(*) FROM pbx_supervisor_agentes WHERE matricula = '$mat' AND upper(status) = 'PAUSA' and org_id = $org_id";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = @pg_fetch_row($result);
$row = @pg_fetch_row($result);
$ret = $row[0];
$ret = $row[0];
if ($verPausa && ($ret == 0)) {
if ($verPausa && ($ret == 0)) {
return false;
return false;
} elseif ($verPausa) {
} elseif ($verPausa) {
return true;
return true;
}
}
if ($ret > 0) {
if ($ret > 0) {
$query = "SELECT id, id_motivo_pausa
$query = "SELECT id, id_motivo_pausa
FROM pbx_eventos_agentes a
FROM pbx_eventos_agentes a
WHERE matricula = '$mat'
WHERE matricula = '$mat'
AND entrada_pausa IS NOT NULL
AND entrada_pausa IS NOT NULL
AND id = (SELECT max(id) FROM pbx_eventos_agentes WHERE matricula = a.matricula)";
AND id = (SELECT max(id) FROM pbx_eventos_agentes WHERE matricula = a.matricula and pbx_eventos_agentes.org_id = $org_id) and a.org_id = $org_id";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = pg_fetch_row($result);
$row = pg_fetch_row($result);
$_SESSION[AGT_ID_PAUSA] = $row[0];
$_SESSION[AGT_ID_PAUSA] = $row[0];
@ -306,7 +319,9 @@ function GetPausa($dbcon, $mat, $verPausa = false)
function GetPausaDescricao($dbcon, $codigo)
function GetPausaDescricao($dbcon, $codigo)
{
{
$query = "SELECT motivo FROM pbx_motivos_pausas WHERE id = '$codigo'";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT motivo FROM pbx_motivos_pausas WHERE id = '$codigo' and org_id IN ($org_id, 0)";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = pg_fetch_row($result);
$row = pg_fetch_row($result);
return $row[0];
return $row[0];
@ -314,7 +329,9 @@ function GetPausaDescricao($dbcon, $codigo)
function GetDacCod($dbcon, $dac)
function GetDacCod($dbcon, $dac)
{
{
$query = "SELECT d.id FROM pbx_dacs d WHERE upper(d.nome) = upper('$dac')";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT d.id FROM pbx_dacs d WHERE upper(d.nome) = upper('$dac') and d.org_id IN ($org_id, 0)";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = pg_fetch_row($result);
$row = pg_fetch_row($result);
$ret = $row[0];
$ret = $row[0];
@ -323,11 +340,13 @@ function GetDacCod($dbcon, $dac)
function GetDacPadraoAgente($dbcon, $getId = true)
function GetDacPadraoAgente($dbcon, $getId = true)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
$idUser = GetIdUser();
$idUser = GetIdUser();
if (IsAdmin())
if (IsAdmin())
return 0;
return 0;
else
$query = "SELECT dac_padrao AS id_dac, b.nome FROM pbx_usuarios a, pbx_dacs b WHERE b.id = a.dac_padrao AND a.id = $idUser ";
$query = "SELECT dac_padrao AS id_dac, b.nome FROM pbx_usuarios a, pbx_dacs b WHERE b.id = a.dac_padrao AND a.id = $idUser b.org_id = $org_id";
//echo $query;
//echo $query;
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = @pg_fetch_row($result);
$row = @pg_fetch_row($result);
@ -337,7 +356,9 @@ function GetDacPadraoAgente($dbcon, $getId = true)
function GetSiteDesc($dbcon, $id)
function GetSiteDesc($dbcon, $id)
{
{
$query = "SELECT d.descricao FROM pbx_sites d WHERE id = $id";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT d.descricao FROM pbx_sites d WHERE id = $id and org_id = $org_id";
// Esta funcao retorna true se o usuario tiver algum menu ativado
// Esta funcao retorna true se o usuario tiver algum menu ativado
// para pbx
// para pbx
$query = "select count(*)
$query = "select count(*)
from pbx_grupo_usuario a, pbx_grupo_funcoes b, pbx_funcoes_menu_pbx c
from pbx_grupo_usuario a, pbx_grupo_funcoes b, pbx_funcoes_menu_pbx c
where b.gp_id = a.gp_id
where b.gp_id = a.gp_id and a.org_id = b.org_id
and c.fun_id = b.fun_id
and c.fun_id = b.fun_id and c.org_id = b.org_id
and a.org_id = $org_id
and a.user_id = $idUser";
and a.user_id = $idUser";
@ -709,8 +733,10 @@ function GetMenuAgente($idSub)
function GetRamalSip($dbcon, $ramalAgente)
function GetRamalSip($dbcon, $ramalAgente)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
//$query = "select dispositivo from pbx_ramais where nome = '$ramalAgente'";
//$query = "select dispositivo from pbx_ramais where nome = '$ramalAgente'";
$query = "select case when( upper(tipo_ramal) = 'KHOMP')then upper(tipo_ramal) || '/r' || nome else dispositivo end as dispositivo from pbx_ramais where nome = '$ramalAgente'";
$query = "select case when( upper(tipo_ramal) = 'KHOMP')then upper(tipo_ramal) || '/r' || nome else dispositivo end as dispositivo from pbx_ramais where nome = '$ramalAgente' and org_id = $org_id";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = pg_fetch_row($result);
$row = pg_fetch_row($result);
$ret = $row[0];
$ret = $row[0];
@ -719,7 +745,9 @@ function GetRamalSip($dbcon, $ramalAgente)
function GetIdUserFromMatricula($dbcon, $matricula)
function GetIdUserFromMatricula($dbcon, $matricula)
{
{
$query = "select id from pbx_usuarios where matricula = '$matricula'";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "select id from pbx_usuarios where matricula = '$matricula' and org_id = $org_id";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$row = @pg_fetch_row($result);
$row = @pg_fetch_row($result);
$ret = $row[0];
$ret = $row[0];
@ -728,7 +756,9 @@ function GetIdUserFromMatricula($dbcon, $matricula)
function GetAgenteRamais($dbcon, $ramalAgente)
function GetAgenteRamais($dbcon, $ramalAgente)
{
{
$query = "select nome, nome from pbx_ramais";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "select nome, nome from pbx_ramais and org_id = $org_id";
@ -763,7 +793,9 @@ function VerificaRamalLogado($db, &$dac, &$agente, $org_id)
function VerificaModoAtendimento($db, $dac)
function VerificaModoAtendimento($db, $dac)
{
{
$query = "SELECT modo_atendimento FROM pbx_queues_grupos WHERE id = $dac";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT modo_atendimento FROM pbx_queues_grupos WHERE id = $dac and org_id = $org_id";
$result = pg_query($db, $query);
$result = pg_query($db, $query);
$modo = pg_fetch_assoc($result);
$modo = pg_fetch_assoc($result);
return $modo['modo_atendimento'];
return $modo['modo_atendimento'];
@ -874,9 +906,9 @@ function VerificaMaxAgenteLogado($db, $org_id)
*/
*/
$query = "select
$query = "select
count(*) as num_total_pa,
count(*) as num_total_pa,
coalesce(sum((select 1 from pbx_usuarios where matricula = a.matricula and pa_fixo = 0)),0) + 1 as num_pa_dinamico,
coalesce(sum((select 1 from pbx_usuarios where matricula = a.matricula and pa_fixo = 0)),0) + 1 as num_pa_dinamico,
coalesce(sum((select 1 from pbx_usuarios where matricula = a.matricula and pa_fixo = 1)),0) + 1 as num_pa_fixo
coalesce(sum((select 1 from pbx_usuarios where matricula = a.matricula and pa_fixo = 1)),0) + 1 as num_pa_fixo
from pbx_supervisor_agentes a";
from pbx_supervisor_agentes a where org_id = $org_id";
$result = pg_query($db, $query);
$result = pg_query($db, $query);
$dadosConexao = pg_fetch_assoc($result);
$dadosConexao = pg_fetch_assoc($result);
@ -904,11 +936,13 @@ function VerificaAgenteLogadoAstrisk($login)
function IsSupervisor($db)
function IsSupervisor($db)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
$matricula = GetMatricula();
$matricula = GetMatricula();
$query = "SELECT user_id, gp_id
$query = "SELECT user_id, gp_id
FROM pbx_usuarios a
FROM pbx_usuarios a
INNER JOIN pbx_grupo_usuario b ON a.id = b.user_id
INNER JOIN pbx_grupo_usuario b ON a.id = b.user_id and b.org_id = $org_id
WHERE matricula = '$matricula'
WHERE matricula = '$matricula'
AND gp_id = 30";
AND gp_id = 30";
if (IsAdmin()) {
if (IsAdmin()) {
@ -925,7 +959,9 @@ function IsSupervisor($db)
function GetClassificacao($db, $idClas, $dac, $useSelect = 1)
function GetClassificacao($db, $idClas, $dac, $useSelect = 1)
{
{
$query = " SELECT clas_id, clas_descricao FROM pbx_classifica_atendimento where clas_status = 1 and clas_id in(select clas_id from pbx_classifica_dacs where id_dac = '$dac' ) order by 2";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = " SELECT clas_id, clas_descricao FROM pbx_classifica_atendimento where org_id = $org_id and clas_status = 1 and clas_id in (select clas_id from pbx_classifica_dacs where id_dac = '$dac' and org_id = $org_id) order by 2";
$result = pg_query($dbcon, "select matricula, apelido as nome from pbx_usuarios_cs u order by 2");
$result = pg_query($dbcon, "select matricula, apelido as nome from pbx_usuarios_cs u where org_id = $org_id order by 2");
while ($dados = pg_fetch_row($result)) {
while ($dados = pg_fetch_row($result)) {
if ($codSel == $dados[0]) {
if ($codSel == $dados[0]) {
@ -1109,7 +1152,9 @@ function GetFileAgente()
function GetUsuario($dbcon, $matricula)
function GetUsuario($dbcon, $matricula)
{
{
$query = "SELECT id, nome, apelido, matricula, email FROM pbx_usuarios WHERE matricula = '{$matricula}'";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "SELECT id, nome, apelido, matricula, email FROM pbx_usuarios pu INNER JOIN pbx_organizacao_usuarios pou ON pu.id = pou.id_usuario and pou.id_organizacao = $org_id WHERE matricula = '{$matricula}'";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
$data = pg_fetch_assoc($result);
$data = pg_fetch_assoc($result);
return $data;
return $data;
@ -1127,9 +1172,12 @@ function VerificaCharFinal($str, $ch = "/")
$query = "insert into pbx_protocolo_reg(uniqueid, ano, numProto, protocolo)
$query = "insert into pbx_protocolo_reg(uniqueid, ano, numProto, protocolo, org_id)
select '$uniqueId', $anoAtu, $numProto, $proto where not exists(select '' from pbx_protocolo_reg where uniqueid = '$uniqueId')";
select '$uniqueId', $anoAtu, $numProto, $proto,org_id where not exists(select '' from pbx_protocolo_reg where uniqueid = '$uniqueId' and org_id = $org_id)";
$result = pg_query($db, $query);
$result = pg_query($db, $query);
if (pg_affected_rows($result) == 0) {
if (pg_affected_rows($result) == 0) {
$query = "select ano, numProto from pbx_protocolo_reg where uniqueid = '$uniqueId'";
$query = "select ano, numProto from pbx_protocolo_reg where uniqueid = '$uniqueId' and org_id = $org_id";
@ -1947,7 +2022,7 @@ function GravaCampanha($dbcon)
if (!$escreve)
if (!$escreve)
throw new Exception("Não foi possível abrir o arquivo $caminho_producao\"extensions_campanha.conf\"");
throw new Exception("Não foi possível abrir o arquivo $caminho_producao\"extensions_campanha.conf\"");
$query = "select cmp_id, cmp_numero,cmp_descricao, cmp_formato_gravacao, cmp_habilitar_gravacao, cmp_status, cmp_qt_tronco_pa from pbx_campanha where cmp_status not in(0)";
$query = "select cmp_id, cmp_numero,cmp_descricao, cmp_formato_gravacao, cmp_habilitar_gravacao, cmp_status, cmp_qt_tronco_pa from pbx_campanha where org_id = $org_id and cmp_status not in(0)";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
if (!$result)
if (!$result)
@ -2054,7 +2129,7 @@ function GravaCampanha($dbcon)
if (!$escreve)
if (!$escreve)
throw new Exception("Não foi possível acessar o arquivo \"extensions_transfere_campanha.conf\"!");
throw new Exception("Não foi possível acessar o arquivo \"extensions_transfere_campanha.conf\"!");
$query = "select cmp_id, cmp_numero from pbx_campanha where cmp_status not in(0)";
$query = "select cmp_id, cmp_numero from pbx_campanha where org_id = $org_id and cmp_status not in(0)";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
if (!$result)
if (!$result)
@ -2089,7 +2164,7 @@ function GravaCampanha($dbcon)
throw new Exception("Não foi possível acessar o arquivo \"queues_campanha.conf\"!");
throw new Exception("Não foi possível acessar o arquivo \"queues_campanha.conf\"!");
$query = "select cmp_id, cmp_descricao, cmp_estrategia_distribuicao, cmp_formato_gravacao, cmp_habilitar_gravacao from pbx_campanha where cmp_status not in(0)";
$query = "select cmp_id, cmp_descricao, cmp_estrategia_distribuicao, cmp_formato_gravacao, cmp_habilitar_gravacao from pbx_campanha where org_id = $org_id and cmp_status not in(0)";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
if (!$result)
if (!$result)
@ -2144,12 +2219,14 @@ function GravaCampanha($dbcon)
if (!$escreve)
if (!$escreve)
throw new Exception("Não foi possível acessar o arquivo \"extensions_rotas_saida_campanha.conf\"!");
throw new Exception("Não foi possível acessar o arquivo \"extensions_rotas_saida_campanha.conf\"!");
$query = "select cmp_id, cmp_descricao, cmp_estrategia_distribuicao, cmp_formato_gravacao, cmp_habilitar_gravacao from pbx_campanha where cmp_status not in(0)";
$query = "select cmp_id, cmp_descricao, cmp_estrategia_distribuicao, cmp_formato_gravacao, cmp_habilitar_gravacao from pbx_campanha where org_id = $org_id and cmp_status not in(0)";
$queryModelo = "select cpmd_id, cmp_id, cpmd_modelo, cpmd_recorte, cpmd_acrescenta from pbx_campanha_modelos where cmp_id = '%s' ";
$queryModelo = "select cpmd_id, cmp_id, cpmd_modelo, cpmd_recorte, cpmd_acrescenta from pbx_campanha_modelos where org_id = $org_id and cmp_id = '%s' ";
@ -2244,6 +2321,8 @@ function GravaCampanha($dbcon)
function SetAgente($db)
function SetAgente($db)
{
{
$org_id = $_SESSION['SSEmpresaPadrao'];
$idUser = GetIdUser();
$idUser = GetIdUser();
$query = "select
$query = "select
case when(
case when(
@ -2254,6 +2333,8 @@ function SetAgente($db)
and c.matricula = b.matricula
and c.matricula = b.matricula
and d.cmp_id = c.cmp_id
and d.cmp_id = c.cmp_id
and a.user_id = u.id
and a.user_id = u.id
and a.org_id = d.org_id
and a.org_id = $org_id
) > 0
) > 0
)then 1 else 0 end as campanha,
)then 1 else 0 end as campanha,
case when(
case when(
@ -2263,9 +2344,13 @@ function SetAgente($db)
where b.gp_id = a.gp_id
where b.gp_id = a.gp_id
and c.id = b.id
and c.id = b.id
and a.user_id = u.id
and a.user_id = u.id
and a.org_id = b.org_id
and a.org_id = c.org_id
and a.org_id = $org_id
) > 0
) > 0
)then 1 else 0 end as fila
)then 1 else 0 end as fila
from pbx_usuarios u
from pbx_usuarios u
inner join pbx_organizacao_usuarios pou ON pou.id_usuario = u.id and pou.id_organizacao = $org_id
where u.id = '$idUser' ";
where u.id = '$idUser' ";
@ -2276,7 +2361,9 @@ function SetAgente($db)
function IncluiAgenteFile($dbcon)
function IncluiAgenteFile($dbcon)
{
{
$query = "select matricula, apelido from pbx_usuarios where delete_ = 0";
$org_id = $_SESSION['SSEmpresaPadrao'];
$query = "select matricula, apelido from pbx_usuarios pu inner join pbx_organizacao_usuarios pou ON pou.id_usuarios = pu.id and pou.id_organizacao = $org_id where delete_ = 0";
$result = pg_query($dbcon, $query);
$result = pg_query($dbcon, $query);
if (!$result) {
if (!$result) {
@ -2304,10 +2391,14 @@ function IncluiAgenteFile($dbcon)
function GetListaCampanha($dbcon, $idCamp, $listId, $dtIni = '', $dtFim = '')
function GetListaCampanha($dbcon, $idCamp, $listId, $dtIni = '', $dtFim = '')
$query = " select distinct cmp_id as id, cmp_descricao as nome, 'A' as tipo, false as padrao from pbx_campanha a where 1=1 " . ($soAtivo ? " and cmp_status <> '0' " : "") .
$query = " select distinct cmp_id as id, cmp_descricao as nome, 'A' as tipo, false as padrao from pbx_campanha a where 1=1 and org_id = $org_id " . ($soAtivo ? " and cmp_status <> '0' " : "") .
" and cmp_id in(select cmp_id from pbx_campanha_contato_fone where conf_data::date >= '$dtIni' and conf_data::date <= '$dtFim' and cmp_id = a.cmp_id) order by 3 desc, 4 desc, 2 asc ";
" and cmp_id in(select cmp_id from pbx_campanha_contato_fone where org_id = $org_id and conf_data::date >= '$dtIni' and conf_data::date <= '$dtFim' and cmp_id = a.cmp_id) order by 3 desc, 4 desc, 2 asc ";
// echo $query;
// echo $query;
} else {
} else {
$query = "select distinct cmp_id as id, cmp_descricao as nome, 'A' as tipo, 'false' as padrao from pbx_campanha a where 1=1 and cmp_status <> '0'
$query = "select distinct cmp_id as id, cmp_descricao as nome, 'A' as tipo, 'false' as padrao from pbx_campanha a where 1=1 org_id = $org_id and cmp_status <> '0'
and exists(
and exists(
select ''
select ''
from pbx_campanha_usuarios b
from pbx_campanha_usuarios b
where matricula = '$matricula'
where matricula = '$matricula' and b.org_id = $org_id
)
)
and exists(select '' from pbx_campanha_contato_fone where conf_data::date >= '$dtIni' and conf_data::date <= '$dtFim' and cmp_id = a.cmp_id)
and exists(select '' from pbx_campanha_contato_fone where org_id = $org_id and conf_data::date >= '$dtIni' and conf_data::date <= '$dtFim' and cmp_id = a.cmp_id)
if (isset($_POST["btConsulta"]) && !empty($_POST["txtConsulta"])) {
if (isset($_POST["btConsulta"]) && !empty($_POST["txtConsulta"])) {
$query = "select * from pbx_dacs where dacStatus = 0 and upper(nome) like upper('%" . $_POST["txtConsulta"] . "%') order by nome";
$query = "select * from pbx_dacs where org_id = $org_id and dacStatus = 0 and upper(nome) like upper('%" . $_POST["txtConsulta"] . "%') order by nome";
$param = $_POST["txtConsulta"];
$param = $_POST["txtConsulta"];
} else {
} else {
$query = "select * from pbx_dacs where dacStatus = 0 order by nome";
$query = "select * from pbx_dacs where org_id = $org_id and dacStatus = 0 order by nome";