diff --git a/audio.php b/audio.php index ac5d9fe4..4acd1ad4 100644 --- a/audio.php +++ b/audio.php @@ -282,13 +282,13 @@ 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 - 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}'; - CREATE INDEX \"tmpRestricaoRamalNome\" on tmp_restricao_ramal(nome);\n\n"; - $query .= "DROP TABLE IF EXISTS tmp_restricao_sigame; - CREATE TEMPORARY TABLE tmp_restricao_sigame as - SELECT sigame_externo FROM pbx_sip_ramais WHERE nome IN (SELECT nome FROM tmp_restricao_ramal) AND sigame_externo <> ''; "; + 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$org_id(nome);\n\n"; + $query .= "DROP TABLE IF EXISTS tmp_restricao_sigame$org_id; + 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 <> '' and org_id = $org_id; "; } $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, 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, - a.dst AS destino, + a.dst AS destino, a.userfield, e.protocolo, h.clas_id, h.clas_descricao, g.clit_id, g.clit_descricao, CASE WHEN(b.evento IN('TRANSFERORIG', 'TRANSFER') )THEN strtoint(param4) ELSE strtoint(param2) END AS duration, 1 AS acesso_audio \n"; } $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_dacs c ON c.nome = b.fila + 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 and c.org_id = b.org_id 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_classifica_reg f ON f.id_bilhetes = a.uniqueid - LEFT JOIN pbx_classifica_item g ON g.clas_id = f.clas_id and g.clit_id = f.clit_id - LEFT JOIN pbx_classifica_atendimento h ON h.clas_id = f.clas_id + 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 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 and g.org_id = f.org_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 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"; if ($isProto) { diff --git a/audio_algar.php b/audio_algar.php index a5315923..bf9ace3a 100644 --- a/audio_algar.php +++ b/audio_algar.php @@ -172,16 +172,19 @@ function GetAudioApi($servidor, $audio, $create = false) { function GetQuery($dataIni, $dataFim, $src, $dst, $protocolo, $empId, $agente, $classificacao, $item, $revendasUser, $param = null) { global $contaReg; + $org_id = GetOrganizacao(); + if ($param == 'query') { $query = "SELECT a.uid,e.emp_nome_fantasia,emp_cnpj,chm_fila,vdr_apelido,chm_calldate,chm_duration,chm_src, chm_dst,prt_proto_parceiro,clas_descricao,clas_descricao_item,a.uid,chm_userfield,emp_vpn,emp_diretorio_ftp FROM vds_chamadas a - INNER JOIN vds_vendedores b ON a.emp_id = b.emp_id - INNER JOIN vds_classificacoes c ON c.uid = a.uid - INNER JOIN vds_protcolos d ON d.uid = a.uid - INNER JOIN vds_empresas e ON e.emp_id = a.emp_id + INNER JOIN vds_vendedores b ON a.emp_id = b.emp_id and a.org_id = b.org_id + INNER JOIN vds_classificacoes c ON c.uid = a.uid and c.org_id = a.org_id + INNER JOIN vds_protcolos d ON d.uid = a.uid and d.org_id = a.org_id + INNER JOIN vds_empresas e ON e.emp_id = a.emp_id and e.org_id = a.org_id WHERE chm_matricula = vdr_matricula - AND a.chm_evento IN ('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETACALLER', 'TRANSFER') "; + AND a.chm_evento IN ('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETACALLER', 'TRANSFER') + AND a.org_id = $org_id"; if (!$protocolo) { $query .= $dataIni && $dataFim ? sprintf(" AND chm_data_bilhete >= '%s' AND chm_data_bilhete <= '%s' ", FormatDtMssql($dataIni), FormatDtMssql($dataFim)) : ''; @@ -266,16 +269,18 @@ function ___GetEmpresa($dataIni, $dataFim, $revendaUser, $empId = null) { function ___GetAgente($revendaUser, $agente = null, $empId = null) { global $dataIni, $dataFim; + $org_id = GetOrganizacao(); + if (!$empId) { $query = "SELECT vdr_apelido AS apelido, vdr_matricula AS matricula, emp_id FROM vds_vendedores WHERE "; - $query .= "emp_id IN ($revendaUser) ORDER BY apelido"; + $query .= "emp_id IN ($revendaUser) and org_id = $org_id ORDER BY apelido"; } else { $query = sprintf("SELECT DISTINCT vdr_apelido AS apelido, vdr_matricula AS matricula, a.emp_id FROM vds_chamadas a - INNER JOIN vds_vendedores b ON a.emp_id = b.emp_id - WHERE chm_data_bilhete >= '%s' AND chm_data_bilhete <= '%s' AND b.emp_id = %s", FormatDtMssql($dataIni), FormatDtMssql($dataFim), $empId); + 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 and org_id = %d", FormatDtMssql($dataIni), FormatDtMssql($dataFim), $empId, $org_id); $query .= " ORDER BY apelido"; } $select = $agente ? '' : 'selected="selected"'; diff --git a/configGeral.php b/configGeral.php index 0954f653..9df06d5a 100644 --- a/configGeral.php +++ b/configGeral.php @@ -147,7 +147,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { prm_abandonada_semretorno = {prm_abandonada_semretorno}, prm_max_licenca = {prm_max_licenca}, prm_max_ramal = {prm_max_ramal}, prm_normaliza_agenda = {prm_normaliza_agenda}, prm_max_dias_relatorio = {prm_max_dias_relatorio}, prm_ocultar_telefone = {prm_ocultar_telefone}, prm_ocultar_email = {prm_ocultar_email}, prm_ocultar_documento = {prm_ocultar_documento}, prm_max_licenca_fixo = {prm_max_licenca_fixo}, prm_relatorio_servico = {prm_relatorio_servico} - WHERE id = {$_SESSION['prm_id']}"; + WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; } $fileLogo = MoveLogo(); @@ -247,7 +247,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { prm_exige_proto_vendas, prm_bloqueio, prm_bloqueio_data, prm_abandonada_semretorno, prm_max_licenca, prm_max_ramal,prm_normaliza_agenda, prm_max_dias_relatorio, prm_ocultar_telefone, prm_ocultar_email, prm_ocultar_documento,prm_max_licenca_fixo, prm_relatorio_servico - FROM pbx_parametros WHERE id = {$_SESSION['prm_id']}"; + FROM pbx_parametros WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; $result = pg_query($dbcon, $query); $dados = @pg_fetch_array($result); foreach ($fields as $value) { @@ -294,8 +294,8 @@ if ($idSubProg == CONFIG_BASE_DADOS) { prm_agente_proto, prm_agente_contribuinte, prm_disponivel_fila, prm_boloco_notas_key, autologoff, trim(autologoffunavail) as autologoffunavail, endcall, custom_beep, wrapuptime, prm_agente_nova_janela, prm_label_protoco_pesquisa, prm_label_protoco_texto, prm_label_protoco_grid, prm_alerta_classificacao, prm_use_proto_parceiro, prm_ativa_integracao, prm_select_integracao, prm_aviso_desconnect, prm_link_audio - FROM pbx_parametros - WHERE id = {$_SESSION['prm_id']}"; + FROM pbx_parametros + WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; $result = pg_query($dbcon, $query); $dados = @pg_fetch_array($result); foreach ($fields as $value) { @@ -304,8 +304,8 @@ if ($idSubProg == CONFIG_BASE_DADOS) { } else { if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) { $query = "INSERT INTO pbx_parametros - (prm_agente_classifica, prm_agente_atualiza, prm_agente_proto, prm_agente_contribuinte, prm_classifica_municipio, prm_disponivel_fila, prm_boloco_notas_key, prm_exige_classificacao, prm_obs_pausaprod, autologoff, autologoffunavail, endcall, custom_beep, wrapuptime,prm_agente_nova_janela, prm_label_protoco_pesquisa, prm_label_protoco_texto, prm_label_protoco_grid, prm_alerta_classificacao, prm_use_proto_parceiro, prm_ativa_integracao,prm_select_integracao,prm_aviso_desconnect,prm_validacao_protocolo,prm_link_audio) - VALUES({prm_agente_classifica}, {prm_agente_atualiza}, {prm_agente_proto}, {prm_agente_contribuinte}, '0', {prm_disponivel_fila}, {prm_boloco_notas_key}, '0', '0', {autologoff}, {autologoffunavail}, {endcall}, {custom_beep}, {wrapuptime}, {prm_agente_nova_janela}, {prm_label_protoco_pesquisa}, {prm_label_protoco_texto}, {prm_label_protoco_grid}, {prm_alerta_classificacao}, {prm_use_proto_parceiro},{prm_ativa_integracao},{prm_select_integracao},{prm_aviso_desconnect},{prm_validacao_protocolo},{prm_link_audio})"; + (prm_agente_classifica, prm_agente_atualiza, prm_agente_proto, prm_agente_contribuinte, prm_classifica_municipio, prm_disponivel_fila, prm_boloco_notas_key, prm_exige_classificacao, prm_obs_pausaprod, autologoff, autologoffunavail, endcall, custom_beep, wrapuptime,prm_agente_nova_janela, prm_label_protoco_pesquisa, prm_label_protoco_texto, prm_label_protoco_grid, prm_alerta_classificacao, prm_use_proto_parceiro, prm_ativa_integracao,prm_select_integracao,prm_aviso_desconnect,prm_validacao_protocolo,prm_link_audio, org_id) + VALUES({prm_agente_classifica}, {prm_agente_atualiza}, {prm_agente_proto}, {prm_agente_contribuinte}, '0', {prm_disponivel_fila}, {prm_boloco_notas_key}, '0', '0', {autologoff}, {autologoffunavail}, {endcall}, {custom_beep}, {wrapuptime}, {prm_agente_nova_janela}, {prm_label_protoco_pesquisa}, {prm_label_protoco_texto}, {prm_label_protoco_grid}, {prm_alerta_classificacao}, {prm_use_proto_parceiro},{prm_ativa_integracao},{prm_select_integracao},{prm_aviso_desconnect},{prm_validacao_protocolo},{prm_link_audio}, $org_id)"; } else { $query = "UPDATE pbx_parametros SET prm_agente_classifica = {prm_agente_classifica}, prm_agente_atualiza = {prm_agente_atualiza}, @@ -318,7 +318,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { prm_label_protoco_grid = {prm_label_protoco_grid}, prm_alerta_classificacao = {prm_alerta_classificacao}, prm_use_proto_parceiro = {prm_use_proto_parceiro}, prm_ativa_integracao = {prm_ativa_integracao}, prm_select_integracao = {prm_select_integracao}, prm_aviso_desconnect = {prm_aviso_desconnect}, prm_validacao_protocolo = {prm_validacao_protocolo}, prm_link_audio = {prm_link_audio} - WHERE id = {$_SESSION['prm_id']}"; + WHERE id = {$_SESSION['prm_id']} and org_$org_id"; } foreach ($fields as $value) { @@ -363,7 +363,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { if (isset($_GET["idSubProg"])) { $query = "SELECT id, COALESCE(prm_super_atualiza, 5) AS prm_super_atualiza, prm_super_alerta_atende, prm_super_alerta_pausa, prm_super_alerta_livre, prm_max_agente_pausa, prm_aviso_lgpd_monitoria - FROM pbx_parametros WHERE id = {$_SESSION['prm_id']}"; + FROM pbx_parametros WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; $result = pg_query($dbcon, $query); $dados = @pg_fetch_array($result); foreach ($fields as $value) @@ -371,8 +371,8 @@ if ($idSubProg == CONFIG_BASE_DADOS) { } else { if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) { $query = "INSERT INTO pbx_parametros - (prm_super_atualiza, prm_super_alerta_atende, prm_super_alerta_pausa, prm_super_alerta_livre, prm_max_agente_pausa, prm_aviso_lgpd_monitoria) - VALUES({prm_super_atualiza}, {prm_super_alerta_atende}, {prm_super_alerta_pausa}, {prm_super_alerta_livre}, {prm_max_agente_pausa}, {prm_aviso_lgpd_monitoria})"; + (prm_super_atualiza, prm_super_alerta_atende, prm_super_alerta_pausa, prm_super_alerta_livre, prm_max_agente_pausa, prm_aviso_lgpd_monitoria, org_id) + VALUES({prm_super_atualiza}, {prm_super_alerta_atende}, {prm_super_alerta_pausa}, {prm_super_alerta_livre}, {prm_max_agente_pausa}, {prm_aviso_lgpd_monitoria}, $org_id)"; } else { $query = "UPDATE pbx_parametros SET prm_super_atualiza = {prm_super_atualiza}, @@ -381,7 +381,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { prm_super_alerta_livre = {prm_super_alerta_livre}, prm_max_agente_pausa = {prm_max_agente_pausa}, prm_aviso_lgpd_monitoria = {prm_aviso_lgpd_monitoria} - WHERE id = {$_SESSION['prm_id']}"; + WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; } if ($values['prm_super_alerta_pausa'] != $_POST['prm_super_alerta_pausa'] && $_POST['prm_super_alerta_pausa_checkebox']) { @@ -422,7 +422,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { $fields = array('prm_sk_host', 'prm_sk_port', 'prm_sk_login', 'prm_sk_password', 'prm_sk_host_externo', 'prm_sk_api_centrais'); $values = array(); if (isset($_GET["idSubProg"])) { - $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); $dados = pg_fetch_array($result); foreach ($fields as $value) { @@ -444,13 +444,13 @@ if ($idSubProg == CONFIG_BASE_DADOS) { } else { if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) { $query = "INSERT INTO pbx_parametros - (prm_sk_host, prm_sk_port, prm_sk_login, prm_sk_password, prm_sk_host_externo, prm_sk_api_centrais) - VALUES ({prm_sk_host}, {prm_sk_port}, {prm_sk_login}, {prm_sk_password}, {prm_sk_host_externo}, {prm_sk_api_centrais})"; + (prm_sk_host, prm_sk_port, prm_sk_login, prm_sk_password, prm_sk_host_externo, prm_sk_api_centrais, org_id) + VALUES ({prm_sk_host}, {prm_sk_port}, {prm_sk_login}, {prm_sk_password}, {prm_sk_host_externo}, {prm_sk_api_centrais}, $org_id)"; } else { $query = "UPDATE pbx_parametros SET prm_sk_host = {prm_sk_host}, prm_sk_port = {prm_sk_port}, prm_sk_login = {prm_sk_login}, prm_sk_password = {prm_sk_password}, prm_sk_host_externo = {prm_sk_host_externo}, prm_sk_api_centrais = {prm_sk_api_centrais} - WHERE id = {$_SESSION['prm_id']}"; + WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; } foreach ($fields as $value) { @@ -497,7 +497,7 @@ if ($idSubProg == CONFIG_BASE_DADOS) { $values = array(); if (isset($_GET["idSubProg"])) { - $query = "SELECT id, prm_sk_host_chat, prm_chat_api, prm_url_meet FROM pbx_parametros WHERE id = {$_SESSION['prm_id']}"; + $query = "SELECT id, prm_sk_host_chat, prm_chat_api, prm_url_meet FROM pbx_parametros WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; $result = pg_query($dbcon, $query); $dados = pg_fetch_array($result); foreach ($fields as $value) { @@ -506,14 +506,14 @@ if ($idSubProg == CONFIG_BASE_DADOS) { } else { if (!ExisteRegistro($dbcon, 'pbx_parametros', 'id', '1')) { $query = "INSERT INTO pbx_parametros - (prm_sk_host_chat, prm_chat_api, prm_url_meet) - values({prm_sk_host_chat}, {prm_chat_api}, {prm_url_meet})"; + (prm_sk_host_chat, prm_chat_api, prm_url_meet, org_id) + values({prm_sk_host_chat}, {prm_chat_api}, {prm_url_meet}, $org_id)"; } else { $query = "UPDATE pbx_parametros SET prm_sk_host_chat = {prm_sk_host_chat}, prm_chat_api = {prm_chat_api}, prm_url_meet = {prm_url_meet} - WHERE id = {$_SESSION['prm_id']}"; + WHERE id = {$_SESSION['prm_id']} and org_id = $org_id"; } foreach ($fields as $value) { diff --git a/contacteFunc.php b/contacteFunc.php index f3853651..24dbc18b 100644 --- a/contacteFunc.php +++ b/contacteFunc.php @@ -26,7 +26,7 @@ function GetDac($dbcon, $codDac, $disableb = "", $incTodos = 0, $soAtivo = 1, $i if ($isAdm) { $query = "SELECT DISTINCT id, nome AS nome, 'Receptivo' AS tipo FROM pbx_queues_grupos d - WHERE 1=1 AND org_id IN ($org_id, 0) " . ($soAtivo ? " AND status = 'A' " : "") . " ORDER BY 2"; + WHERE 1=1 AND org_id = $org_id " . ($soAtivo ? " AND status = 'A' " : "") . " ORDER BY 2"; } else { $query = "SELECT DISTINCT d.id, d.nome, 'Receptivo' AS tipo, 'false' AS padrao FROM pbx_usuarios a, pbx_grupo_usuario b, pbx_fila_grupos c, pbx_dacs d @@ -35,7 +35,7 @@ function GetDac($dbcon, $codDac, $disableb = "", $incTodos = 0, $soAtivo = 1, $i AND c.org_id = d.org_id AND c.gp_id = b.gp_id AND d.id = c.id - AND c.org_id IN ($org_id, 0) + AND c.org_id = $org_id AND lower(a.matricula) = lower('$matricula') " . ($soAtivo ? " and d.status = 'A' " : "") . " order by 1, 2 "; } @@ -156,6 +156,9 @@ function GetCombo($dbCon, $query, $codSel, $incTodos = true) function GetDacAgente($dbcon, $idUser, $codDac, $disableb = "", $getDac = 0) { + + $org_id = $_SESSION['SSEmpresaPadrao']; + /* * Carrega lista de dacs por usuarios * @@ -163,9 +166,10 @@ function GetDacAgente($dbcon, $idUser, $codDac, $disableb = "", $getDac = 0) $query = "select d.id, d.nome from pbx_usuarios a, pbx_grupo_usuario b, pbx_fila_grupos c, pbx_dacs d 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 a.id = '$idUser' "; + and a.id = '$idUser' + c.org_id = $org_id"; /* $query = "select d.id, d.nome from pbx_dac_usuario u, pbx_dacs d where d.id = u.id_dac @@ -194,9 +198,10 @@ function GetIdDacPadrao($dbcon, $idUser) { if (IsAdmin()) { 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); $ret = 0; @@ -209,10 +214,12 @@ function GetIdDacPadrao($dbcon, $idUser) function SetIdDacPadrao($dbcon, $idUser) { + $org_id = $_SESSION['SSEmpresaPadrao']; + $query = "SELECT DISTINCT id_dac,nome_dac FROM pbx_usuarios a 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 AND c.status = 'A' ORDER BY 1 @@ -237,15 +244,18 @@ function GetLoginFromId($dbcon, $idUser) function GetNomeDacPadrao($dbcon, $idUser) { + + $org_id = $_SESSION['SSEmpresaPadrao']; + $isAdm = !$idUser && IsAdmin(); if ($isAdm) { $query = "select d.id, d.nome from pbx_dacs d - where d.status = 'A' limit 1"; + where d.status = 'A' org_id = $org_id limit 1"; } 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 - 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); @@ -271,29 +281,32 @@ function GetDacDesc($dbcon, $id) function GetPausa($dbcon, $mat, $verPausa = false) { + + $org_id = $_SESSION['SSEmpresaPadrao']; + /* * Quando $verPausa é definido como true indica que apenas queremos * nos certificar se o agente entrou em pausa. Quando a pausa é ativa- * da pelo supervisor precisamos alimentar os parametro da sessao cor- * 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); $row = @pg_fetch_row($result); $ret = $row[0]; if ($verPausa && ($ret == 0)) { return false; - } else if ($verPausa) { + } elseif ($verPausa) { return true; } if ($ret > 0) { - $query = "SELECT id, id_motivo_pausa + $query = "SELECT id, id_motivo_pausa FROM pbx_eventos_agentes a WHERE matricula = '$mat' 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); $row = pg_fetch_row($result); $_SESSION[AGT_ID_PAUSA] = $row[0]; @@ -306,7 +319,9 @@ function GetPausa($dbcon, $mat, $verPausa = false) 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); $row = pg_fetch_row($result); return $row[0]; @@ -314,7 +329,9 @@ function GetPausaDescricao($dbcon, $codigo) 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); $row = pg_fetch_row($result); $ret = $row[0]; @@ -323,11 +340,13 @@ function GetDacCod($dbcon, $dac) function GetDacPadraoAgente($dbcon, $getId = true) { + $org_id = $_SESSION['SSEmpresaPadrao']; + $idUser = GetIdUser(); if (IsAdmin()) 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; $result = pg_query($dbcon, $query); $row = @pg_fetch_row($result); @@ -337,7 +356,9 @@ function GetDacPadraoAgente($dbcon, $getId = true) 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"; $result = pg_query($dbcon, $query); $row = pg_fetch_row($result); $ret = $row[0]; @@ -415,13 +436,16 @@ function GetMotivo($dbcon, $codMotivo, $disableb = "", $incTodos = 0, $incTpPaus function SetPbx($db, $idUser) { + $org_id = $_SESSION['SSEmpresaPadrao']; + // // Esta funcao retorna true se o usuario tiver algum menu ativado // para pbx $query = "select count(*) from pbx_grupo_usuario a, pbx_grupo_funcoes b, pbx_funcoes_menu_pbx c - where b.gp_id = a.gp_id - and c.fun_id = b.fun_id + where b.gp_id = a.gp_id and a.org_id = b.org_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"; @@ -709,8 +733,10 @@ function GetMenuAgente($idSub) function GetRamalSip($dbcon, $ramalAgente) { + $org_id = $_SESSION['SSEmpresaPadrao']; + //$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); $row = pg_fetch_row($result); $ret = $row[0]; @@ -719,7 +745,9 @@ function GetRamalSip($dbcon, $ramalAgente) 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); $row = @pg_fetch_row($result); $ret = $row[0]; @@ -728,7 +756,9 @@ function GetIdUserFromMatricula($dbcon, $matricula) 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"; $result = pg_query($dbcon, $query); $codSel = $ramalAgente; $ramais = "" : ""; @@ -1015,20 +1053,23 @@ function GetEmpresa() function GetAgentes($dbcon, $codSel, $idDac, $query = "") { + $org_id = $_SESSION['SSEmpresaPadrao']; + //carrega Atendente $codSel = ((!$_SESSION["listaAgente"]) || ($trocaDac)) ? 0 : $_SESSION["listaAgente"]; $sel = !$codSel ? "selected" : ""; $agentes = ""; //$agentes .= ""; - $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)) { if ($codSel == $dados[0]) { @@ -1109,7 +1152,9 @@ function GetFileAgente() 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); $data = pg_fetch_assoc($result); return $data; @@ -1127,9 +1172,12 @@ function VerificaCharFinal($str, $ch = "/") function GetHeadMenu($db) { + $org_id = $_SESSION['SSEmpresaPadrao']; + $query = "select fun_id, fun_nome, fun_menu, fun_menu_text, fun_menu_url, fun_menu_img, fun_id_pai from pbx_funcoes where fun_id_pai is null + and org_id = $org_id order by 4"; $head = array(); $result = pg_query($db, $query); @@ -1140,11 +1188,13 @@ function GetHeadMenu($db) function GetSites($dbcon, $codSite, $disableb = "") { + $org_id = $_SESSION['SSEmpresaPadrao']; + /* * Carrega lista de dacs disponivel * para ser inserdo entre as tags */ - $query = "select id, descricao from pbx_sites where status = 1 order by upper(descricao)"; + $query = "select id, descricao from pbx_sites where status = 1 order by upper(descricao) and org_id = $org_id"; $result = pg_query($dbcon, $query); $codSel = $codSite; $site = "'; $ret .= ""; @@ -1900,9 +1969,11 @@ function GetFormatoAudio($codSel, $nomeCampo = 'cmp_formato_gravacao') function GetStatusCampanha($dbcon, $codSel, $desabStatus, $filtro = "") { + $org_id = $_SESSION['SSEmpresaPadrao']; + $desab = $desabStatus ? "disabled" : ""; $filtro = $filtro ? " and cpst_id not in($filtro) " : ""; - $query = "select cpst_id as id, cpst_nome as nome from pbx_campanha_status where cpst_status = 1 $filtro order by 2"; + $query = "select cpst_id as id, cpst_nome as nome from pbx_campanha_status where org_id = $org_id and cpst_status = 1 $filtro order by 2"; //if(IsAdmin()) echo $query; $result = pg_query($dbcon, $query); @@ -1927,7 +1998,9 @@ function GetStatusCampanha($dbcon, $codSel, $desabStatus, $filtro = "") function GetCofigPadrao($dbcon) { - $query = "SELECT * FROM pbx_conf_padrao"; + $org_id = $_SESSION['SSEmpresaPadrao']; + + $query = "SELECT * FROM pbx_conf_padrao where org_id = $org_id"; $result = pg_query($dbcon, $query); $dados = pg_fetch_array($result); @@ -1940,6 +2013,8 @@ function GetCofigPadrao($dbcon) function GravaCampanha($dbcon) { + $org_id = $_SESSION['SSEmpresaPadrao']; + $caminho_producao = $_SESSION[CONF_PADRAO_CAMINHO_PRODUCAO]; $arq = $caminho_producao . "extensions_campanha.conf"; $escreve = fopen($arq, 'w+'); @@ -1947,7 +2022,7 @@ function GravaCampanha($dbcon) if (!$escreve) 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); if (!$result) @@ -2054,7 +2129,7 @@ function GravaCampanha($dbcon) if (!$escreve) 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); if (!$result) @@ -2089,7 +2164,7 @@ function GravaCampanha($dbcon) 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); if (!$result) @@ -2144,12 +2219,14 @@ function GravaCampanha($dbcon) if (!$escreve) 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)"; - $queryModelo = "select cpmd_id, cmp_id, cpmd_modelo, cpmd_recorte, cpmd_acrescenta from pbx_campanha_modelos where cmp_id = '%s' "; + $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 org_id = $org_id and cmp_id = '%s' "; $queryTronco = "select a.cptr_id, a.cmp_id, a.cpmd_id, a.cptr_tronco, a.cptr_nome_tronco, b.tipo, b.username from pbx_campanha_troncos a, pbx_troncos b where b.id = a.cptr_tronco + and a.org_id = b.org_id + and a.org_id = $org_id and a.cpmd_id = '%s' order by a.cptr_tronco"; $result = pg_query($dbcon, $query); @@ -2244,6 +2321,8 @@ function GravaCampanha($dbcon) function SetAgente($db) { + + $org_id = $_SESSION['SSEmpresaPadrao']; $idUser = GetIdUser(); $query = "select case when( @@ -2254,6 +2333,8 @@ function SetAgente($db) and c.matricula = b.matricula and d.cmp_id = c.cmp_id and a.user_id = u.id + and a.org_id = d.org_id + and a.org_id = $org_id ) > 0 )then 1 else 0 end as campanha, case when( @@ -2263,9 +2344,13 @@ function SetAgente($db) where b.gp_id = a.gp_id and c.id = b.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 )then 1 else 0 end as fila 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' "; @@ -2276,7 +2361,9 @@ function SetAgente($db) 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); if (!$result) { @@ -2304,10 +2391,14 @@ function IncluiAgenteFile($dbcon) function GetListaCampanha($dbcon, $idCamp, $listId, $dtIni = '', $dtFim = '') { + + $org_id = $_SESSION['SSEmpresaPadrao']; $query = "select distinct a.list_id, a.list_nome || ' [' || a.list_id::text || ']' as list_nome from pbx_campanha_lista a, pbx_campanha_contato_fone b where b.cmp_id = a.cmp_id and b.list_id = a.list_id - and b.cmp_id = $idCamp\n"; + and b.cmp_id = $idCamp + and a.org_id = b.org_id + and a.org_id = $org_id\n"; if ($dtIni) $query .= "and b.conf_data::date >= '$dtIni'\n"; if ($dtIni) @@ -2337,7 +2428,9 @@ function GetListaCampanha($dbcon, $idCamp, $listId, $dtIni = '', $dtFim = '') function GetCampanhaRetorno($dbcon, $codDac = -1, $matricula = 0, $size = 12, $mult = 1, $disableb = "") { - $query = " select distinct cmp_id as id, cmp_descricao as nome from pbx_campanha where 1=1 order by 2 "; + + $org_id = $_SESSION['SSEmpresaPadrao']; + $query = " select distinct cmp_id as id, cmp_descricao as nome from pbx_campanha where 1=1 and org_id = $org_id order by 2 "; $result = pg_query($dbcon, $query); $codSel = $codDac; @@ -2367,6 +2460,7 @@ function GetCampanhas($dbcon, $codDac = -1, $matricula = 0, $dataIni = '', $data * Carrega lista de dacs disponivel * para ser inserdo entre as tags */ + $org_id = $_SESSION['SSEmpresaPadrao']; $size = 1; $mult = 0; $disableb = ""; @@ -2387,17 +2481,17 @@ function GetCampanhas($dbcon, $codDac = -1, $matricula = 0, $dataIni = '', $data if ($isAdm) { - $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' " : "") . - " 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 "; + $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 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; } 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( select '' 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) order by 1, 2 "; } diff --git a/dacConsulta.php b/dacConsulta.php index 34d3602d..266a9841 100644 --- a/dacConsulta.php +++ b/dacConsulta.php @@ -18,12 +18,13 @@ $tpl = 'dacConsulta.tpl'; $linha = ""; $imgNovo = ""; $imgNovo = "$imgNovo"; +$org_id = $_SESSION['SSEmpresaPadrao']; 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"]; } 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"; } $result = pg_query($dbcon, $query);