//$imgClass = "<ahref=\"javaScript:NovaJanela('index.php?idProg=30&clas_id=$codItem&descitem=$descricao','clasCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgClass Novo Item</a>";
$imgClass = "<ahref=\"javaScript:NovaJanela('index.php?idProg=28$filtroNovo','clasCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgNovo Nova Classificação</a>";
$imgClass = "<ahref=\"javaScript:NovaJanela('index.php?idProg=28$filtroNovo','clasCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgNovo Nova Classificação</a>";
$imgItem = "<ahref=\"javaScript:NovaJanela('index.php?idProg=30&clas_id=$codItem&descitem={$desc}{$filtroNovo}','clasCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgItem Novo Item</a>";
$imgItem = "<ahref=\"javaScript:NovaJanela('index.php?idProg=30&clas_id=$codItem&descitem={$desc}{$filtroNovo}','clasCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgItem Novo Item</a>";
$delete = "<ahref=\"javaScript:DeltetaMotivoPausa('$id','¶mPesquisa=&pgn=0&bloco=0&pg=0');\"><imgsrc='imgSite/Sync.png'width='16'height='16'border='0'title='Ative este registro!'></a>";
$delete = "<ahref=\"javaScript:DeltetaMotivoPausa('$id','¶mPesquisa=&pgn=0&bloco=0&pg=0');\"><imgsrc='imgSite/Sync.png'width='16'height='16'border='0'title='Ative este registro!'></a>";
$sql = "select '' from pbx_troncos where upper(nome) = upper('$nome')";
$sql = "select '' from pbx_troncos where upper(nome) = upper('$nome')";
$result = pg_query($db, $sql);
$result = pg_query($db, $sql);
if (pg_num_rows($result)) {
if (pg_num_rows($result)) {
@ -2418,21 +2415,14 @@ function _VerificaNomeTronco($db, $nome)
if (pg_num_rows($result)) {
if (pg_num_rows($result)) {
return "Este \"Nome\" já esta associado a um \"Ramal\"!";
return "Este \"Nome\" já esta associado a um \"Ramal\"!";
}
}
return false;
return false;
}
}
function base64ToFile($base64)
function base64ToFile($base64)
{
{
$file = tempnam(sys_get_temp_dir(), time());
$file = tempnam(sys_get_temp_dir(), time());
// open the output file for writing
$ifp = fopen($file, 'wb');
$ifp = fopen($file, 'wb');
// we could add validation here with ensuring count( $data ) > 1
fwrite($ifp, base64_decode($base64));
fwrite($ifp, base64_decode($base64));
// clean up the file resource
fclose($ifp);
fclose($ifp);
return $file;
return $file;
@ -2444,7 +2434,11 @@ function base64ToFile($base64)
function GetNotExistsDacUser($dacPadraoSel, $idUser)
function GetNotExistsDacUser($dacPadraoSel, $idUser)
{
{
$query = sprintf("select '' from pbx_fila_grupos where id = %s and gp_id in(select gp_id from pbx_grupo_usuario where user_id = %s);", QuotedStr($dacPadraoSel), QuotedStr($idUser));
$query = sprintf(
"SELECT '' FROM pbx_fila_grupos WHERE id = %s AND gp_id IN(SELECT gp_id FROM pbx_grupo_usuario WHERE user_id = %s);",
@ -27,7 +25,7 @@ if (isset($fieldsForm['btIncAgente'])) {
try {
try {
$result = pg_query($dbcon, 'begin');
$result = pg_query($dbcon, 'begin');
$query = sprintf('select count(*) from pbx_grupo_usuario a, pbx_grupo b where b.gp_id = a.gp_id and b.user_id > 0 and b.gp_id = %s', $fieldsForm['gp_id']);
$query = sprintf('SELECT count(*) FROM pbx_grupo_usuario a, pbx_grupo b WHERE b.gp_id = a.gp_id AND b.user_id > 0 AND b.gp_id = %s', $fieldsForm['gp_id']);
if (RegistroInc($dbcon, $query)) {
if (RegistroInc($dbcon, $query)) {
throw new Exception('Operação inválida, "Usuários" só podem ser vinculados a "Grupos"!');
throw new Exception('Operação inválida, "Usuários" só podem ser vinculados a "Grupos"!');
}
}
@ -41,11 +39,12 @@ if (isset($fieldsForm['btIncAgente'])) {
if ($isLgpd && ($jaLgpd = JaInseridoLgps($idUser))) {
if ($isLgpd && ($jaLgpd = JaInseridoLgps($idUser))) {
throw new Exception($jaLgpd);
throw new Exception($jaLgpd);
}
}
$query = "insert into pbx_grupo_usuario(user_id, gp_id)values(%s, '%s')";
$query = "INSERT INTO pbx_grupo_usuario(user_id, gp_id, org_id) VALUES(%s, '%s', $org_id)";
@ -67,20 +66,17 @@ if (isset($fieldsForm['btIncAgente'])) {
$fieldsForm['erro'] = fmtMsg('Selecione um agente!');
$fieldsForm['erro'] = fmtMsg('Selecione um agente!');
} else {
} else {
try {
try {
$result = pg_query($dbcon, 'begin');
$result = pg_query($dbcon, 'begin');
if ($result) {
if ($result) {
$userAdmin = IsAdmin() || IsUserAdmin() ? 1 : 0;
$userAdmin = IsAdmin() || IsUserAdmin() ? 1 : 0;
$cont = 0;
$cont = 0;
foreach ($fieldsForm['user_inc'] as $idUser) {
foreach ($fieldsForm['user_inc'] as $idUser) {
$query = "delete from pbx_grupo_usuario"
$query = "DELETE from pbx_grupo_usuario
. "\nwhere user_id = '%s'"
WHERE user_id = '%s'
. "\nand gp_id = '%s'"
AND gp_id = '%s'
. "\nand user_id <> (select id from pbx_usuarios where apelido = 'administrador')" // Não permite remover o administrador.
AND user_id <> (SELECT id FROM pbx_usuarios WHERE apelido = 'administrador')
. "and not exists(select '' from pbx_grupo where gp_id = '%s' and gp_user = case when(%s=0)then '%s' else -1 end)\n"; //Nao permite o usuario remover o pai do grupo(quem criou).
AND not exists(select '' from pbx_grupo WHERE gp_id = '%s' AND gp_user = CASE WHEN(%s=0)THEN '%s' ELSE -1 END)"; //Nao permite o usuario remover o pai do grupo(quem criou).
$query = "select b.id, b.nome || (case when( (select count(*) from pbx_grupo where gp_id = a.gp_id and gp_user = a.user_id) > 0)then '*' else '' end) as apelido, b.matricula, a.gp_id from pbx_grupo_usuario a, pbx_usuarios b where b.id = a.user_id and a.gp_id = $codGp order by 2";
$query = "SELECT b.id, b.nome || (CASE WHEN( (SELECT count(*) FROM pbx_grupo WHERE gp_id = a.gp_id AND gp_user = a.user_id) > 0)THEN '*' ELSE '' END) AS apelido, b.matricula, a.gp_id FROM pbx_grupo_usuario a, pbx_usuarios b WHERE b.id = a.user_id AND a.gp_id = $codGp ORDER BY 2";
//$query = "select gp_id, gp_nome from pbx_grupo g where $flagSystem and gp_status = 1 {REST} order by 2";
$query = "SELECT gp_id,
$query = "select gp_id, case when(gp_system = 1)then (gp_nome || '#') else case when(user_id = 0)then gp_nome else (gp_nome || '**') end end gp_nome, case when(user_id = 0)then 0 else 1 end as ord from pbx_grupo g where $flagSystem and gp_status = 1 {REST} order by 3,2";
CASE WHEN(gp_system = 1) THEN (gp_nome || '#')
//restricao se o usuario nao for admin
ELSE
CASE WHEN(user_id = 0)THEN gp_nome
ELSE (gp_nome || '**') END END gp_nome,
CASE WHEN(user_id = 0)THEN 0 ELSE 1 END AS ord
FROM pbx_grupo g
WHERE $flagSystem
AND org_id = $org_id
AND gp_status = 1 {REST} ORDER BY 3,2";
$query = strtoupper(GetLogin()) == "ADMIN" ? str_replace("{REST}", "", $query) : str_replace("{REST}", " and exists(select '' from pbx_grupo_usuario where gp_id = g.gp_id and user_id = $idUser)", $query);
$query = strtoupper(GetLogin()) == "ADMIN" ? str_replace("{REST}", "", $query) : str_replace("{REST}", " and exists(select '' from pbx_grupo_usuario where gp_id = g.gp_id and user_id = $idUser)", $query);
// and b.fun_id not in(select b.fun_id from pbx_grupo_funcoes a, pbx_funcoes b where b.fun_id = a.fun_id and a.gp_id = '$idGrupo') ";
if (!IsAdmin())
$query .= " and b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu where gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
from pbx_funcoes b where coalesce(b.fun_id_pai, 0) = 0 and fun_public = 1";
$query .= " order by 1 ";
if (!IsAdmin()) {
$query .= " AND b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu WHERE gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
// and b.fun_id not in(select b.fun_id from pbx_grupo_funcoes a, pbx_funcoes b where b.fun_id = a.fun_id and a.gp_id = '$idGrupo') ";
if (!IsAdmin()) {
$query .= "AND b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu where gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
if (!IsAdmin())
}
$query .= " and b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu where gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
$imgNovo = "<ahref=\"javaScript:NovaJanela('index.php?idProg=22&idUser=0$filtroNovo','usuarioCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgNovo Novo Usuário</a>";
$imgNovo = "<ahref=\"javaScript:NovaJanela('index.php?idProg=22&idUser=0$filtroNovo','usuarioCad','$janW','$janH','resizable=NO,scrollbars=NO');\">$imgNovo Novo Usuário</a>";
$imgDelete = sprintf("<imgsrc=\"imgSite/%s\"width=\"16\"height=\"16\"border=\"0\"title=\"%s\">", ($dados['status'] == 1 ? 'deletaUser.png' : 'deletaUserOff.png'), ($dados['status'] == 1 ? "Desabilita e remove todo o perfil do usuário: $apelido" : "O usuário: $apelido foi desativado e seu perfil removido!"));
$imgDelete = sprintf("<imgsrc=\"imgSite/%s\"width=\"16\"height=\"16\"border=\"0\"title=\"%s\">", ($dados['status'] == 1 ? 'deletaUser.png' : 'deletaUserOff.png'), ($dados['status'] == 1 ? "Desabilita e remove todo o perfil do usuário: $apelido" : "O usuário: $apelido foi desativado e seu perfil removido!"));
$query = sprintf("insert into pbx_grupo(gp_nome, gp_status, user_id, gp_user) select apelido, 1, id, id from pbx_usuarios where apelido = %s", QuotedStr($userLogin));
$query = sprintf("INSERT INTO pbx_grupo(gp_nome, gp_status, user_id, gp_user, org_id)
$result = $result && pg_query($dbcon, $query);
SELECT apelido, 1, id, id, $org_id FROM pbx_usuarios WHERE apelido = %s", QuotedStr($userLogin));
$result2 = $result && pg_query($dbcon, $query);
echo pg_last_error() . "<br>";
/*
/*
* Insere o usuario no mesmo grupo criado com seu login.
* Insere o usuario no mesmo grupo criado com seu login.
*/
*/
$query = sprintf("insert into pbx_grupo_usuario(user_id, gp_id) select user_id, gp_id from pbx_grupo where gp_nome = %s", QuotedStr($userLogin));
$query = sprintf("INSERT INTO pbx_grupo_usuario(user_id, gp_id, org_id)
$result = $result && pg_query($dbcon, $query);
SELECT user_id, gp_id, $org_id FROM pbx_grupo WHERE gp_nome = %s", QuotedStr($userLogin));
$result3 = $result && pg_query($dbcon, $query);
echo pg_last_error() . "<br>";
/*
/*
* Se o dac for selecionado no cadastro do usuario, o mesmo sera atribuido para o proprio usuario.
* Se o dac for selecionado no cadastro do usuario, o mesmo sera atribuido para o proprio usuario.
*/
*/
if ($dacPadraoSel) {
if ($dacPadraoSel) {
$query = sprintf("insert into pbx_fila_grupos(id, gp_id) select $dacPadraoSel, gp_id from pbx_grupo where gp_nome = %s", QuotedStr($userLogin));
$query = sprintf("INSERT INTO pbx_fila_grupos(id, gp_id, org_id)
$result = $result && pg_query($dbcon, $query);
SELECT $dacPadraoSel, gp_id, $org_id FROM pbx_grupo WHERE gp_nome = %s", QuotedStr($userLogin));