Commit a07cf91e5622f96b870d6990f358299094801cc2
1 parent
4970e7ee
Exists in
master
and in
7 other branches
--no commit message
Showing
2 changed files
with
79 additions
and
25 deletions
Show diff stats
admin/js/estat_editor.js
| @@ -76,11 +76,12 @@ i3GEOadmin.editor = { | @@ -76,11 +76,12 @@ i3GEOadmin.editor = { | ||
| 76 | }, | 76 | }, |
| 77 | tabela:{ | 77 | tabela:{ |
| 78 | onde: "i3GEOadminEditorTabela", | 78 | onde: "i3GEOadminEditorTabela", |
| 79 | + optionsTabela: "", | ||
| 79 | lista: function(){ | 80 | lista: function(){ |
| 80 | var callback = { | 81 | var callback = { |
| 81 | success:function(o){ | 82 | success:function(o){ |
| 82 | try { | 83 | try { |
| 83 | - var dados = YAHOO.lang.JSON.parse(o.responseText), | 84 | + var opt,dados = YAHOO.lang.JSON.parse(o.responseText), |
| 84 | temp = "<fieldset>" + | 85 | temp = "<fieldset>" + |
| 85 | "<p class=paragrafo >Crie uma tabela no banco contendo limites ou localidades que poderá ser utilizada para espacializar os dados estatísticos existentes em outras tabelas<br>" + | 86 | "<p class=paragrafo >Crie uma tabela no banco contendo limites ou localidades que poderá ser utilizada para espacializar os dados estatísticos existentes em outras tabelas<br>" + |
| 86 | "<input type=button value='Upload Shapefile' id='i3GEOadmin_botaoupload' /></p>" + | 87 | "<input type=button value='Upload Shapefile' id='i3GEOadmin_botaoupload' /></p>" + |
| @@ -95,7 +96,9 @@ i3GEOadmin.editor = { | @@ -95,7 +96,9 @@ i3GEOadmin.editor = { | ||
| 95 | temp += "<fieldset>" + | 96 | temp += "<fieldset>" + |
| 96 | "<p>Escolha uma tabela existente: " + | 97 | "<p>Escolha uma tabela existente: " + |
| 97 | "<select id='i3GEOadmintabela' onchange='i3GEOadmin.editor.coluna.lista()'>"; | 98 | "<select id='i3GEOadmintabela' onchange='i3GEOadmin.editor.coluna.lista()'>"; |
| 98 | - temp += core_comboObjeto(dados,"tabela","tabela"); | 99 | + opt = core_comboObjeto(dados,"tabela","tabela"); |
| 100 | + i3GEOadmin.editor.tabela.optionsTabela = opt; | ||
| 101 | + temp += opt; | ||
| 99 | temp += "</select>" + | 102 | temp += "</select>" + |
| 100 | "<p class=paragrafo ><input type=button value='Mostrar dados' id='i3GEOadmintabelaMostrar' />" + | 103 | "<p class=paragrafo ><input type=button value='Mostrar dados' id='i3GEOadmintabelaMostrar' />" + |
| 101 | "<input type=button value='CSV' id='i3GEOadmintabelaCsv'/>" + | 104 | "<input type=button value='CSV' id='i3GEOadmintabelaCsv'/>" + |
| @@ -441,9 +444,18 @@ i3GEOadmin.editor = { | @@ -441,9 +444,18 @@ i3GEOadmin.editor = { | ||
| 441 | '<p class="paragrafo" >shp: <br><input class=digitar type="file" size=22 name="i3GEOuploadshp" style="top:0px;left:0px;cursor:pointer;"></p>' + | 444 | '<p class="paragrafo" >shp: <br><input class=digitar type="file" size=22 name="i3GEOuploadshp" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 442 | '<p class="paragrafo" >shx: <br><input class=digitar type="file" size=22 name="i3GEOuploadshx" style="top:0px;left:0px;cursor:pointer;"></p>' + | 445 | '<p class="paragrafo" >shx: <br><input class=digitar type="file" size=22 name="i3GEOuploadshx" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 443 | '<p class="paragrafo" >dbf: <br><input class=digitar type="file" size=22 name="i3GEOuploaddbf" style="top:0px;left:0px;cursor:pointer;"></p>' + | 446 | '<p class="paragrafo" >dbf: <br><input class=digitar type="file" size=22 name="i3GEOuploaddbf" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 444 | - '<p class="paragrafo" >Nome da nova tabela (não utilize caracteres incompatíveis com o banco de dados, como -, acentos ou espaços em branco):<br><input class=digitar type="text" size=20 id="tabelaDestino" name="tabelaDestino" style="top:0px;left:0px;cursor:pointer;"></p>' + | 447 | + '<p class="paragrafo" >Nome da tabela (não utilize caracteres incompatíveis com o banco de dados, como -, acentos ou espaços em branco):<br><input class=digitar type="text" size=20 id="tabelaDestino" name="tabelaDestino" style="top:0px;left:0px;cursor:pointer;"> ' + |
| 448 | + 'Ou escolha da lista: ' + | ||
| 449 | + '<select onchange="javascript:$i(\'tabelaDestino\').value = this.value;">' + | ||
| 450 | + i3GEOadmin.editor.tabela.optionsTabela + | ||
| 451 | + '</select></p>' + | ||
| 452 | + '<p class="paragrafo" >Tipo de operação:</p>' + | ||
| 453 | + '<p class="paragrafo" ><select id=i3GEOtipoOperacao name=tipoOperacao >' + | ||
| 454 | + '<option value=criar >Criar a tabela nova e incluir registros do SHP</option>' + | ||
| 455 | + '<option value=incluir >Adicionar novos registros</option>' + | ||
| 456 | + '<option value=apagar >Apagar dados atuais e incluir do SHP</option>' + | ||
| 457 | + '</select></p>' + | ||
| 445 | '<p class="paragrafo" >Código da projeção (SRID) Assegure-se que o shapefile esteja na projeção geográfica se você for usar com o sistema de metadados estatísticos :<br><input class=digitar type="text" value="4326" size=20 id="srid" name="srid" style="top:0px;left:0px;cursor:pointer;"></p>' + | 458 | '<p class="paragrafo" >Código da projeção (SRID) Assegure-se que o shapefile esteja na projeção geográfica se você for usar com o sistema de metadados estatísticos :<br><input class=digitar type="text" value="4326" size=20 id="srid" name="srid" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 446 | - | ||
| 447 | '<p class="paragrafo" ><input id=i3GEOuploadsubmit type="button" value="Enviar" size=12 />' + | 459 | '<p class="paragrafo" ><input id=i3GEOuploadsubmit type="button" value="Enviar" size=12 />' + |
| 448 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + | 460 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + |
| 449 | '<input type="hidden" id="i3GEOuploadcodigoconexao" name="i3GEOuploadcodigoconexao" value="">' + | 461 | '<input type="hidden" id="i3GEOuploadcodigoconexao" name="i3GEOuploadcodigoconexao" value="">' + |
| @@ -457,6 +469,12 @@ i3GEOadmin.editor = { | @@ -457,6 +469,12 @@ i3GEOadmin.editor = { | ||
| 457 | return ins; | 469 | return ins; |
| 458 | }, | 470 | }, |
| 459 | submit: function(){ | 471 | submit: function(){ |
| 472 | + if($i("i3GEOtipoOperacao").value === "apagar"){ | ||
| 473 | + var confirma = window.confirm("Apaga mesmo os registros? (nao pode ser revertido)"); | ||
| 474 | + if(!confirma){ | ||
| 475 | + return; | ||
| 476 | + } | ||
| 477 | + } | ||
| 460 | if($i("tabelaDestino").value == ""){ | 478 | if($i("tabelaDestino").value == ""){ |
| 461 | alert("Digite o nome da tabela a ser criada"); | 479 | alert("Digite o nome da tabela a ser criada"); |
| 462 | return; | 480 | return; |
| @@ -488,7 +506,6 @@ i3GEOadmin.editor = { | @@ -488,7 +506,6 @@ i3GEOadmin.editor = { | ||
| 488 | var ins = '<fieldset><form id=i3GEOuploadcsvf target="i3GEOuploadcsviframe" action="../php/metaestat_uploadcsv_submit.php" method="post" ENCTYPE="multipart/form-data">' + | 506 | var ins = '<fieldset><form id=i3GEOuploadcsvf target="i3GEOuploadcsviframe" action="../php/metaestat_uploadcsv_submit.php" method="post" ENCTYPE="multipart/form-data">' + |
| 489 | '<p class="paragrafo" >CSV (utilize ponto como separador de valores decimais ou a importação poderá não ocorrer): <br><input class=digitar type="file" size=22 name="i3GEOuploadcsv" style="top:0px;left:0px;cursor:pointer;"></p>' + | 507 | '<p class="paragrafo" >CSV (utilize ponto como separador de valores decimais ou a importação poderá não ocorrer): <br><input class=digitar type="file" size=22 name="i3GEOuploadcsv" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 490 | '<p class="paragrafo" >Nome da nova tabela (não utilize caracteres incompatíveis com o banco de dados, como -, acentos ou espaços em branco):<br><input class=digitar type="text" size=20 id="tabelaDestinocsv" name="tabelaDestinocsv" style="top:0px;left:0px;cursor:pointer;"></p>' + | 508 | '<p class="paragrafo" >Nome da nova tabela (não utilize caracteres incompatíveis com o banco de dados, como -, acentos ou espaços em branco):<br><input class=digitar type="text" size=20 id="tabelaDestinocsv" name="tabelaDestinocsv" style="top:0px;left:0px;cursor:pointer;"></p>' + |
| 491 | - | ||
| 492 | '<p class="paragrafo" ><input id=i3GEOuploadcsvsubmit type="button" value="Enviar" size=12 />' + | 509 | '<p class="paragrafo" ><input id=i3GEOuploadcsvsubmit type="button" value="Enviar" size=12 />' + |
| 493 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + | 510 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + |
| 494 | '<input type="hidden" id="i3GEOuploadcsvcodigoconexao" name="i3GEOuploadcsvcodigoconexao" value="">' + | 511 | '<input type="hidden" id="i3GEOuploadcsvcodigoconexao" name="i3GEOuploadcsvcodigoconexao" value="">' + |
admin/php/metaestat_uploadshp_submit.php
| @@ -77,7 +77,6 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | @@ -77,7 +77,6 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | ||
| 77 | $colunas[] = $c; | 77 | $colunas[] = $c; |
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | - | ||
| 81 | echo "<br>Numshapes: ". $numshapes; | 80 | echo "<br>Numshapes: ". $numshapes; |
| 82 | $tipo = $shapefileObj->type; | 81 | $tipo = $shapefileObj->type; |
| 83 | echo "<br>Tipo: ". $tipo; | 82 | echo "<br>Tipo: ". $tipo; |
| @@ -106,19 +105,61 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | @@ -106,19 +105,61 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | ||
| 106 | echo "<br>Tipos das colunas: <pre>"; | 105 | echo "<br>Tipos das colunas: <pre>"; |
| 107 | var_dump($tipoColuna); | 106 | var_dump($tipoColuna); |
| 108 | echo "</pre>"; | 107 | echo "</pre>"; |
| 108 | + | ||
| 109 | + try { | ||
| 110 | + $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); | ||
| 111 | + } catch (PDOException $e) { | ||
| 112 | + echo '<span style=color:red >Connection failed: ' . $e->getMessage(); | ||
| 113 | + exit; | ||
| 114 | + } | ||
| 115 | + | ||
| 109 | //gera o script para criar a tabela | 116 | //gera o script para criar a tabela |
| 117 | + //verifica se a tabela ja existe | ||
| 118 | + $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadesquema"]."' AND table_name = '".$_POST["tabelaDestino"]."'"; | ||
| 119 | + $res = $dbh->query($sql,PDO::FETCH_ASSOC); | ||
| 120 | + if(count($res->fetchAll())>0){ | ||
| 121 | + $tabelaExiste = true; | ||
| 122 | + } | ||
| 123 | + else{ | ||
| 124 | + $tabelaExiste = false; | ||
| 125 | + } | ||
| 126 | + //encoding do banco de dados | ||
| 127 | + $sql = "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = '".$conexao["bancodedados"]."'"; | ||
| 128 | + $res = $dbh->query($sql,PDO::FETCH_ASSOC); | ||
| 129 | + $encodingdb = $res->fetchAll()[0]["pg_encoding_to_char"]; | ||
| 130 | + if($encodingdb == "UTF8"){ | ||
| 131 | + $encodingdb = "UTF-8"; | ||
| 132 | + } | ||
| 133 | + if($encodingdb == "LATIN1"){ | ||
| 134 | + $encodingdb = "ISO-8859-1"; | ||
| 135 | + } | ||
| 136 | + //a tabela nao existe e e do tipo create | ||
| 110 | $sqltabela = array(); | 137 | $sqltabela = array(); |
| 111 | - $sql = "CREATE TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."(gid integer, the_geom geometry"; | ||
| 112 | - foreach($colunas as $coluna){ | ||
| 113 | - $sql .= ",".strtolower($coluna)." ".$tipoColuna[$coluna]; | ||
| 114 | - } | ||
| 115 | - $sql .= ")WITH(OIDS=FALSE)"; | ||
| 116 | - $sqltabela[] = $sql; | ||
| 117 | - $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." OWNER TO ".$conexao["usuario"]; | ||
| 118 | - $sqltabela[] = "CREATE INDEX ".$_POST["tabelaDestino"]."_indx_thegeom ON ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." USING gist (the_geom )"; | ||
| 119 | - echo "<br>Sql tabela: <pre>"; | ||
| 120 | - var_dump($sqltabela); | ||
| 121 | - echo "</pre>"; | 138 | + if($tabelaExiste == false && $_POST["tipoOperacao"] == "criar"){ |
| 139 | + $sql = "CREATE TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."(gid integer, the_geom geometry"; | ||
| 140 | + foreach($colunas as $coluna){ | ||
| 141 | + $sql .= ",".strtolower($coluna)." ".$tipoColuna[$coluna]; | ||
| 142 | + } | ||
| 143 | + $sql .= ")WITH(OIDS=FALSE)"; | ||
| 144 | + $sqltabela[] = $sql; | ||
| 145 | + $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." OWNER TO ".$conexao["usuario"]; | ||
| 146 | + $sqltabela[] = "CREATE INDEX ".$_POST["tabelaDestino"]."_indx_thegeom ON ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." USING gist (the_geom )"; | ||
| 147 | + echo "<br>Sql tabela: <pre>"; | ||
| 148 | + var_dump($sqltabela); | ||
| 149 | + echo "</pre>"; | ||
| 150 | + } | ||
| 151 | + if($tabelaExiste == true && $_POST["tipoOperacao"] == "criar"){ | ||
| 152 | + echo "<span style=color:red >A tabela existe. Não pode ser criada.</span>"; | ||
| 153 | + exit; | ||
| 154 | + } | ||
| 155 | + //se a tabela existe e e para remover os registros | ||
| 156 | + if($tabelaExiste == true && $_POST["tipoOperacao"] == "apagar"){ | ||
| 157 | + $sqltabela[] = "delete from ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]; | ||
| 158 | + } | ||
| 159 | + if($tabelaExiste == true && $_POST["tipoOperacao"] == "apagar" && $_POST["i3GEOuploadesquema"] != "i3geo_metaestat"){ | ||
| 160 | + echo "<span style=color:red >Não é possível executar essa operação nesse esquema.</span>"; | ||
| 161 | + exit; | ||
| 162 | + } | ||
| 122 | //gera o script para inserir os dados | 163 | //gera o script para inserir os dados |
| 123 | $linhas = array(); | 164 | $linhas = array(); |
| 124 | $insert = "INSERT INTO ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."( gid,".strtolower(implode(",",$colunas)).",the_geom)"; | 165 | $insert = "INSERT INTO ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."( gid,".strtolower(implode(",",$colunas)).",the_geom)"; |
| @@ -128,7 +169,9 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | @@ -128,7 +169,9 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | ||
| 128 | $vs[] = $i; | 169 | $vs[] = $i; |
| 129 | foreach($colunas as $coluna){ | 170 | foreach($colunas as $coluna){ |
| 130 | if($tipoColuna[$coluna] == "varchar"){ | 171 | if($tipoColuna[$coluna] == "varchar"){ |
| 131 | - $vs[] = "'".$s->getValue($layer,$coluna)."'"; | 172 | + $texto = $s->getValue($layer,$coluna); |
| 173 | + //echo mb_detect_encoding($texto); | ||
| 174 | + $vs[] = "'".mb_convert_encoding($texto,$encodingdb,mb_detect_encoding($texto))."'"; | ||
| 132 | } | 175 | } |
| 133 | else{ | 176 | else{ |
| 134 | $vs[] = $s->getValue($layer,$coluna); | 177 | $vs[] = $s->getValue($layer,$coluna); |
| @@ -138,12 +181,6 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | @@ -138,12 +181,6 @@ if (isset($_FILES['i3GEOuploadshp']['name'])){ | ||
| 138 | $linhas[] = $insert."VALUES(".implode(",",$vs).")"; | 181 | $linhas[] = $insert."VALUES(".implode(",",$vs).")"; |
| 139 | } | 182 | } |
| 140 | $layer->close(); | 183 | $layer->close(); |
| 141 | - try { | ||
| 142 | - $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); | ||
| 143 | - } catch (PDOException $e) { | ||
| 144 | - echo 'Connection failed: ' . $e->getMessage(); | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | foreach($sqltabela as $linha){ | 184 | foreach($sqltabela as $linha){ |
| 148 | try { | 185 | try { |
| 149 | $dbh->query($linha); | 186 | $dbh->query($linha); |
| @@ -174,4 +211,4 @@ function verificaNome($nome,$ext){ | @@ -174,4 +211,4 @@ function verificaNome($nome,$ext){ | ||
| 174 | } | 211 | } |
| 175 | ?> | 212 | ?> |
| 176 | </body> | 213 | </body> |
| 177 | -</html> | ||
| 178 | \ No newline at end of file | 214 | \ No newline at end of file |
| 215 | +</html> |