|
|
|
@ -40,11 +40,11 @@ function setOrganizacao($dbcon, $dados, $id = null)
|
|
|
|
|
{ |
|
|
|
|
$isExists = ExisteRegistro($dbcon, "pbx_organizacao", "nome", strtoupper($dados['nome']), ($id ? " id <> $id" : null)); |
|
|
|
|
if (!$dados['nome'] || $isExists) { |
|
|
|
|
throw new Exception($isExists ? "O nome da organização já existe!" : "Por favor, preencha o campo nome!"); |
|
|
|
|
throw new Exception($isExists ? "O nome da organização já existe!" : "Por favor, preencha o campo nome!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$isExistsMaster = verificaMaster($dbcon); |
|
|
|
|
if ($isExistsMaster == true && $dados['master'] == "checked"){ |
|
|
|
|
if ($isExistsMaster == true && $dados['master'] == "checked") { |
|
|
|
|
throw new Exception("Já existe uma empresa master ativa!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,14 +62,14 @@ function setOrganizacao($dbcon, $dados, $id = null)
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
|
if (!$result) { |
|
|
|
|
throw new Exception("Não foi possível gravar as informações da organização!"); |
|
|
|
|
throw new Exception("Não foi possível gravar as informações da organizações!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$ret = pg_fetch_assoc($result); |
|
|
|
|
if ($ret['id'] && !$id) { |
|
|
|
|
$isImport = importIdTables($dbcon, $ret['id']); |
|
|
|
|
if (!$isImport) { |
|
|
|
|
throw new Exception("Não foi possível importar tabelas das organizações!"); |
|
|
|
|
throw new Exception("Não foi possível importar tabelas das organizações!"); |
|
|
|
|
} |
|
|
|
|
criarGruposDefault($dbcon, $ret['id']); |
|
|
|
|
addUserOrganizacaoGrupo($dbcon, $ret['id']); |
|
|
|
@ -82,7 +82,7 @@ function getOrganizacaoById($dbcon, $id)
|
|
|
|
|
$query = "SELECT id, nome, status, master FROM pbx_organizacao WHERE id = $id;"; |
|
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
|
if (!$result) { |
|
|
|
|
throw new Exception("Não foi possível buscar a organização selecionada!"); |
|
|
|
|
throw new Exception("Não foi possível buscar a organização selecionada!"); |
|
|
|
|
} |
|
|
|
|
$dados = pg_fetch_assoc($result); |
|
|
|
|
return $dados; |
|
|
|
@ -113,7 +113,7 @@ function importIdTables($dbcon, $organizacao)
|
|
|
|
|
$id = $resp['id']; |
|
|
|
|
if (!$resp['id']) { |
|
|
|
|
$id = 1; |
|
|
|
|
___Gravalog(" [ $sql ] - Não foi possível o ID da tabela {$table};"); |
|
|
|
|
___Gravalog(" [ $sql ] - Não foi possível o ID da tabela {$table};"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$query = "CREATE TEMPORARY TABLE t{$table} AS SELECT * FROM {$table} WHERE $column = $id;"; |
|
|
|
@ -123,7 +123,7 @@ function importIdTables($dbcon, $organizacao)
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
|
if (!$result) { |
|
|
|
|
throw new Exception("Não foi possível criar a tabela default [ {$table} ]!"); |
|
|
|
|
throw new Exception("Não foi possível criar a tabela default [ {$table} ]!"); |
|
|
|
|
} |
|
|
|
|
pg_query($dbcon, "DROP TABLE IF EXISTS t{$table};"); |
|
|
|
|
} |
|
|
|
@ -160,7 +160,13 @@ function addUserOrganizacaoGrupo($dbcon, $org_id)
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$query = "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at) |
|
|
|
|
$query = ""; |
|
|
|
|
if ($iduser != 342) { |
|
|
|
|
$query .= "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at) |
|
|
|
|
VALUES(342, $org_id, 'NOW()');"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$query .= "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at) |
|
|
|
|
VALUES($iduser, $org_id,'NOW()');"; |
|
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
|
if ($result) { |
|
|
|
@ -177,12 +183,13 @@ function ___Gravalog($message)
|
|
|
|
|
file_put_contents('/var/log/asterisk/cadOrganizacao.log', $line, FILE_APPEND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function verificaMaster($dbcon){ |
|
|
|
|
function verificaMaster($dbcon) |
|
|
|
|
{ |
|
|
|
|
$query = "SELECT id, master, status FROM pbx_organizacao;"; |
|
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
|
$resposta = false; |
|
|
|
|
if(!$result){ |
|
|
|
|
throw new Exception("Não foi possível verificar se existe organizaçao master!"); |
|
|
|
|
if (!$result) { |
|
|
|
|
throw new Exception("Não foi possível verificar se existe organização master!"); |
|
|
|
|
} |
|
|
|
|
$dados = pg_fetch_all($result); |
|
|
|
|
if ($dados) { |
|
|
|
|