Browse Source

correcao importa dados empresa

correcao_departamento_agenda
Lucas Awade 10 months ago
parent
commit
7275751e25
  1. 21
      asterisk/var_lib_asterisk/scripts/manutencaoDB/importaEmpresa.php
  2. 8
      include/util/funcoesApl.php
  3. 1
      projeto/base/sql/versao-1.9.0.sql

21
asterisk/var_lib_asterisk/scripts/manutencaoDB/importaEmpresa.php

@ -46,13 +46,15 @@ try {
/*
* Cria as empresas padrao.
*/
//CriaOrgPadrao($dbcon);
CriaOrgPadrao($dbcon);
/*
* Cria a coluna org_id em todas as tabelas.
*/
CriaCampo($dbcon);
importIdTables($dbcon);
/*
* Apaga todas as fk.
*/
@ -94,8 +96,13 @@ function CriaCampo($dbcon)
continue;
}
$query = sprintf("alter table \"%s\" drop column org_id;", $table["table_name"]);
$query .= sprintf("alter table \"%s\" add org_id int not null default 0;", $table["table_name"]);
$query = "DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = '{$table["table_name"]}' AND column_name = 'org_id') THEN
ALTER TABLE {$table["table_name"]} DROP COLUMN IF EXISTS org_id;
END IF;
END $$;";
$query .= sprintf("alter table %s add org_id int not null default 0;", $table["table_name"]);
if (!$result = pg_query($dbcon, $query)) {
throw new Exception("Não foi possivel criar a coluna \"org_id\" na table!" . $table["table_name"] . "\"!\n");
@ -137,6 +144,14 @@ function ApagaFK($dbcon)
function CriaOrgPadrao($dbcon)
{
$query = "SELECT * FROM pbx_organizacao WHERE master = 1;";
$result = pg_query($dbcon, $query);
$res = pg_fetch_assoc($result);
if ($res) {
return;
}
$query = "INSERT INTO pbx_organizacao(nome, master, status, updated_at) VALUES ('Simples IP', 1, 1, NOW()) RETURNING id;";
$result = pg_query($dbcon, $query);
$res = pg_fetch_assoc($result);

8
include/util/funcoesApl.php

@ -581,7 +581,11 @@ function IsSuper()
function IsUserAdmin()
{
$query = sprintf("select count(*) from pbx_grupo_usuario where gp_id = (select gp_id from pbx_grupo where gp_nome = 'ADMINISTRADOR') and user_id = '%s'", GetIdUser());
$org_id = GetOrganizacao();
$query = sprintf("SELECT count(*) FROM pbx_grupo_usuario
WHERE gp_id = (SELECT gp_id FROM pbx_grupo WHERE gp_nome = 'ADMINISTRADOR' AND org_id = {$org_id})
AND user_id = '%s'", GetIdUser());
$result = pg_query($query);
$row = @pg_fetch_row($result);
return $row[0] ? true : false;
@ -601,7 +605,7 @@ function AgenteON($idUser = null)
return pg_num_rows(pg_query($query));
} else {
$query = sprintf("select '' from pbx_supervisor_agentes where matricula = '%s' and ramal = '%s' ", GetMatricula(), GetRamalMonitorar(RAMAL_MONITOR_AGENTE));
$query = sprintf("SELECT '' FROM pbx_supervisor_agentes WHERE matricula = '%s' AND ramal = '%s' ", GetMatricula(), GetRamalMonitorar(RAMAL_MONITOR_AGENTE));
return pg_num_rows(pg_query($query));
}

1
projeto/base/sql/versao-1.9.0.sql

@ -82,6 +82,7 @@ END;
$function$
;
ALTER TABLE pbx_usuarios ADD COLUMN org_padrao int
------------------------------------------
----- ADICAO DE ID NAS TABELAS -----
------------------------------------------

Loading…
Cancel
Save