Commit 3be413c37b5bb4e77263d962491bb092502d39a2
1 parent
fc2a35e8
Exists in
master
and in
7 other branches
$1
Showing
3 changed files
with
108 additions
and
6 deletions
Show diff stats
admin/js/estat_editor.js
@@ -45,18 +45,33 @@ i3GEOadmin.editor = { | @@ -45,18 +45,33 @@ i3GEOadmin.editor = { | ||
45 | }, | 45 | }, |
46 | esquema: { | 46 | esquema: { |
47 | onde: "i3GEOadminEditorEsquema", | 47 | onde: "i3GEOadminEditorEsquema", |
48 | - lista: function(){ | 48 | + lista: function(selecao){ |
49 | var callback = { | 49 | var callback = { |
50 | success:function(o){ | 50 | success:function(o){ |
51 | try { | 51 | try { |
52 | var dados = YAHOO.lang.JSON.parse(o.responseText), | 52 | var dados = YAHOO.lang.JSON.parse(o.responseText), |
53 | - temp = "<fieldset><p>Escolha um esquema: "; | ||
54 | - temp += "<select id='i3GEOadminesquema' onchange='i3GEOadmin.editor.tabela.lista()'>"; | ||
55 | - temp += core_comboObjeto(dados,"esquema","esquema"); | ||
56 | - temp += "</select></p>"; | 53 | + temp = "<fieldset><p>Escolha um esquema: " + |
54 | + "<select id='i3GEOadminesquema' onchange='i3GEOadmin.editor.tabela.lista()'>" + | ||
55 | + core_comboObjeto(dados,"esquema","esquema") + | ||
56 | + "</select></p>" + | ||
57 | + "<p class=paragrafo ><input type=button value='Criar um novo esquema' id='i3GEOadminesquemaCriar' />" + | ||
58 | + " <input type=button value='Alterar nome atual' id='i3GEOadminesquemaAlterarNome' /></p>"; | ||
59 | + | ||
57 | $i(i3GEOadmin.editor.esquema.onde).innerHTML = temp+"</fieldset>"; | 60 | $i(i3GEOadmin.editor.esquema.onde).innerHTML = temp+"</fieldset>"; |
61 | + if(selecao){ | ||
62 | + $i("i3GEOadminesquema").value = selecao; | ||
63 | + i3GEOadmin.editor.tabela.lista(); | ||
64 | + } | ||
58 | core_carregando("desativa"); | 65 | core_carregando("desativa"); |
59 | $i(i3GEOadmin.editor.tabela.onde).innerHTML = ""; | 66 | $i(i3GEOadmin.editor.tabela.onde).innerHTML = ""; |
67 | + new YAHOO.widget.Button( | ||
68 | + "i3GEOadminesquemaCriar", | ||
69 | + {onclick:{fn: i3GEOadmin.editor.esquema.criar}} | ||
70 | + ); | ||
71 | + new YAHOO.widget.Button( | ||
72 | + "i3GEOadminesquemaAlterarNome", | ||
73 | + {onclick:{fn: i3GEOadmin.editor.esquema.alterarNome}} | ||
74 | + ); | ||
60 | } | 75 | } |
61 | catch(e){core_handleFailure(e,o.responseText);} | 76 | catch(e){core_handleFailure(e,o.responseText);} |
62 | }, | 77 | }, |
@@ -73,6 +88,68 @@ i3GEOadmin.editor = { | @@ -73,6 +88,68 @@ i3GEOadmin.editor = { | ||
73 | core_carregando("buscando dados..."); | 88 | core_carregando("buscando dados..."); |
74 | core_makeRequest("../php/metaestat.php?funcao=esquemasConexao&formato=json&codigo_estat_conexao="+codigo_estat_conexao,callback); | 89 | core_makeRequest("../php/metaestat.php?funcao=esquemasConexao&formato=json&codigo_estat_conexao="+codigo_estat_conexao,callback); |
75 | }, | 90 | }, |
91 | + criar: function(){ | ||
92 | + var callback = { | ||
93 | + success:function(o){ | ||
94 | + try { | ||
95 | + core_carregando("desativa"); | ||
96 | + i3GEOadmin.editor.esquema.lista(novoEsquema); | ||
97 | + } | ||
98 | + catch(e){core_handleFailure(e,o.responseText);} | ||
99 | + }, | ||
100 | + failure:core_handleFailure, | ||
101 | + argument: { foo:"foo", bar:"bar" } | ||
102 | + }, | ||
103 | + novoEsquema = window.prompt("Novo nome:",""); | ||
104 | + if (novoEsquema != null && novoEsquema != ""){ | ||
105 | + if(i3GEOadmin.editor.esquema.verificaExiste(novoEsquema) == false){ | ||
106 | + core_carregando("adicionando..."); | ||
107 | + core_makeRequest("../php/metaestat.php?funcao=criaEsquemaDB&formato=json&nome_esquema="+novoEsquema+"&codigo_estat_conexao="+$i("i3GEOadmincodigo_estat_conexao").value,callback); | ||
108 | + } | ||
109 | + else{ | ||
110 | + alert("Esquema ja existe"); | ||
111 | + } | ||
112 | + } | ||
113 | + }, | ||
114 | + alterarNome: function(){ | ||
115 | + if($i("i3GEOadminesquema").value == ""){ | ||
116 | + alert("Escolha o esquema"); | ||
117 | + return; | ||
118 | + } | ||
119 | + var callback = { | ||
120 | + success:function(o){ | ||
121 | + try { | ||
122 | + core_carregando("desativa"); | ||
123 | + i3GEOadmin.editor.esquema.lista(); | ||
124 | + } | ||
125 | + catch(e){core_handleFailure(e,o.responseText);} | ||
126 | + }, | ||
127 | + failure:core_handleFailure, | ||
128 | + argument: { foo:"foo", bar:"bar" } | ||
129 | + }, | ||
130 | + nomeEsquema = $i("i3GEOadminesquema").value; | ||
131 | + novoEsquema = window.prompt("Novo nome:",""); | ||
132 | + if (novoEsquema != null && novoEsquema != ""){ | ||
133 | + if(i3GEOadmin.editor.esquema.verificaExiste(novoEsquema) == false){ | ||
134 | + core_carregando("adicionando..."); | ||
135 | + core_makeRequest("../php/metaestat.php?funcao=alteraNomeEsquemaDB&formato=json&nome_esquema="+nomeEsquema+"&novonome_esquema="+novoEsquema+"&codigo_estat_conexao="+$i("i3GEOadmincodigo_estat_conexao").value,callback); | ||
136 | + } | ||
137 | + else{ | ||
138 | + alert("Esquema ja existe"); | ||
139 | + } | ||
140 | + } | ||
141 | + }, | ||
142 | + verificaExiste: function(valor){ | ||
143 | + var combo = $i("i3GEOadminesquema"), | ||
144 | + n = combo.options.length, | ||
145 | + i; | ||
146 | + for(i=0;i<n;i++){ | ||
147 | + if(combo.options[i].value == valor){ | ||
148 | + return true; | ||
149 | + } | ||
150 | + } | ||
151 | + return false; | ||
152 | + } | ||
76 | }, | 153 | }, |
77 | tabela:{ | 154 | tabela:{ |
78 | onde: "i3GEOadminEditorTabela", | 155 | onde: "i3GEOadminEditorTabela", |
admin/php/classe_metaestat.php
@@ -2002,7 +2002,7 @@ class Metaestat{ | @@ -2002,7 +2002,7 @@ class Metaestat{ | ||
2002 | } | 2002 | } |
2003 | /** | 2003 | /** |
2004 | * ALtera o nome de uma tabela | 2004 | * ALtera o nome de uma tabela |
2005 | - * Atualiza as tabelas i3geoestat_medida_variavel e i3geoestat_tipo_regiao | 2005 | + * Nao atualiza as tabelas i3geoestat_medida_variavel e i3geoestat_tipo_regiao |
2006 | * @param codigo da conexao | 2006 | * @param codigo da conexao |
2007 | * @param nome do esquema | 2007 | * @param nome do esquema |
2008 | * @param nome da tabela atual | 2008 | * @param nome da tabela atual |
@@ -2011,6 +2011,7 @@ class Metaestat{ | @@ -2011,6 +2011,7 @@ class Metaestat{ | ||
2011 | */ | 2011 | */ |
2012 | function alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ | 2012 | function alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ |
2013 | $res = $this->execSQLDB($codigo_estat_conexao,"ALTER TABLE ".$nome_esquema.".".$nome_tabela." RENAME TO ".$novonome_tabela ); | 2013 | $res = $this->execSQLDB($codigo_estat_conexao,"ALTER TABLE ".$nome_esquema.".".$nome_tabela." RENAME TO ".$novonome_tabela ); |
2014 | + /* | ||
2014 | $tabela = $this->execSQLDB($codigo_estat_conexao,"SELECT table_name FROM information_schema.tables where table_name = '$novonome_tabela' and table_schema = '$nome_esquema'"); | 2015 | $tabela = $this->execSQLDB($codigo_estat_conexao,"SELECT table_name FROM information_schema.tables where table_name = '$novonome_tabela' and table_schema = '$nome_esquema'"); |
2015 | if(count($tabela) > 0){ | 2016 | if(count($tabela) > 0){ |
2016 | $sql = "UPDATE i3geoestat_medida_variavel SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; | 2017 | $sql = "UPDATE i3geoestat_medida_variavel SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; |
@@ -2018,6 +2019,7 @@ class Metaestat{ | @@ -2018,6 +2019,7 @@ class Metaestat{ | ||
2018 | $sql = "UPDATE i3geoestat_tipo_regiao SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; | 2019 | $sql = "UPDATE i3geoestat_tipo_regiao SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; |
2019 | $this->execSQL($sql,"",false); | 2020 | $this->execSQL($sql,"",false); |
2020 | } | 2021 | } |
2022 | + */ | ||
2021 | return $res; | 2023 | return $res; |
2022 | } | 2024 | } |
2023 | /** | 2025 | /** |
@@ -2031,6 +2033,17 @@ class Metaestat{ | @@ -2031,6 +2033,17 @@ class Metaestat{ | ||
2031 | function copiaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ | 2033 | function copiaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ |
2032 | return $this->execSQLDB($codigo_estat_conexao,"CREATE TABLE ".$nome_esquema.".".$novonome_tabela." AS select * from ".$nome_esquema.".".$nome_tabela ); | 2034 | return $this->execSQLDB($codigo_estat_conexao,"CREATE TABLE ".$nome_esquema.".".$novonome_tabela." AS select * from ".$nome_esquema.".".$nome_tabela ); |
2033 | } | 2035 | } |
2036 | + /** | ||
2037 | + * ALtera o nome de um esquema | ||
2038 | + * @param codigo da conexao | ||
2039 | + * @param nome do esquema | ||
2040 | + * @param novo nome do esquema | ||
2041 | + * @return execSQLDB | ||
2042 | + */ | ||
2043 | + function alteraNomeEsquemaDB($codigo_estat_conexao,$nome_esquema,$novonome_esquema){ | ||
2044 | + $res = $this->execSQLDB($codigo_estat_conexao,"ALTER SCHEMA ".$nome_esquema." RENAME TO ".$novonome_esquema ); | ||
2045 | + return $res; | ||
2046 | + } | ||
2034 | /** | 2047 | /** |
2035 | * Lista as colunas de uma tabela e seus metadados | 2048 | * Lista as colunas de uma tabela e seus metadados |
2036 | * @param codigo da conexao | 2049 | * @param codigo da conexao |
admin/php/metaestat.php
@@ -75,7 +75,9 @@ $funcoesEdicao = array( | @@ -75,7 +75,9 @@ $funcoesEdicao = array( | ||
75 | "EXCLUIRCLASSECLASSIFICACAO", | 75 | "EXCLUIRCLASSECLASSIFICACAO", |
76 | "EXCLUIRLINKMEDIDA", | 76 | "EXCLUIRLINKMEDIDA", |
77 | "CRIATABELADB", | 77 | "CRIATABELADB", |
78 | + "CRIAESQUEMADB", | ||
78 | "ALTERANOMETABELADB", | 79 | "ALTERANOMETABELADB", |
80 | + "ALTERANOMEESQUEMADB", | ||
79 | "COPIATABELADB", | 81 | "COPIATABELADB", |
80 | "CRIACOLUNADB", | 82 | "CRIACOLUNADB", |
81 | "ALTERANOMECOLUNADB", | 83 | "ALTERANOMECOLUNADB", |
@@ -1306,6 +1308,11 @@ switch (strtoupper($funcao)) | @@ -1306,6 +1308,11 @@ switch (strtoupper($funcao)) | ||
1306 | retornaJSON($m->criaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela)); | 1308 | retornaJSON($m->criaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela)); |
1307 | exit; | 1309 | exit; |
1308 | break; | 1310 | break; |
1311 | + case "CRIAESQUEMADB": | ||
1312 | + $m = new Metaestat(); | ||
1313 | + retornaJSON($m->criaEsquemaDB($codigo_estat_conexao,$nome_esquema)); | ||
1314 | + exit; | ||
1315 | + break; | ||
1309 | case "ALTERANOMETABELADB": | 1316 | case "ALTERANOMETABELADB": |
1310 | $m = new Metaestat(); | 1317 | $m = new Metaestat(); |
1311 | if($nome_esquema != "i3geo_metaestat"){ | 1318 | if($nome_esquema != "i3geo_metaestat"){ |
@@ -1315,6 +1322,11 @@ switch (strtoupper($funcao)) | @@ -1315,6 +1322,11 @@ switch (strtoupper($funcao)) | ||
1315 | retornaJSON($m->alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela)); | 1322 | retornaJSON($m->alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela)); |
1316 | exit; | 1323 | exit; |
1317 | break; | 1324 | break; |
1325 | + case "ALTERANOMEESQUEMADB": | ||
1326 | + $m = new Metaestat(); | ||
1327 | + retornaJSON($m->alteraNomeEsquemaDB($codigo_estat_conexao,$nome_esquema,$novonome_esquema)); | ||
1328 | + exit; | ||
1329 | + break; | ||
1318 | case "COPIATABELADB": | 1330 | case "COPIATABELADB": |
1319 | $m = new Metaestat(); | 1331 | $m = new Metaestat(); |
1320 | if($nome_esquema != "i3geo_metaestat"){ | 1332 | if($nome_esquema != "i3geo_metaestat"){ |