Commit a92bc5f5bf3e346c5624c43511274dceb7a70992
1 parent
b1d268e2
Exists in
master
and in
7 other branches
Criação do formulário para upload de arquivos CSV para o servidor de banco de da…
…dos e criação automática do respectivo arquivo de configuração mapfile.
Showing
13 changed files
with
1044 additions
and
15 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin1/catalogo/mapfile/preview/index.php
| ... | ... | @@ -233,5 +233,204 @@ function nomeRand($n=10) |
| 233 | 233 | } |
| 234 | 234 | return $nomes; |
| 235 | 235 | } |
| 236 | +function autoClasses(&$nlayer, $mapa, $locaplic = null) { | |
| 237 | + $postgis_mapa = $_SESSION ["postgis_mapa"]; | |
| 238 | + ; | |
| 239 | + $substituicon = "nao"; | |
| 240 | + if ($nlayer->connectiontype == MS_POSTGIS) { | |
| 241 | + if ($nlayer->connection == " ") { | |
| 242 | + $nlayer->set ( "connection", $postgis_mapa ); | |
| 243 | + $substituicon = "sim"; | |
| 244 | + } | |
| 245 | + } | |
| 246 | + // | |
| 247 | + // gera classes automaticamente (temas vetoriais) | |
| 248 | + if ($nlayer->getmetadata ( "classesitem" ) != "") { | |
| 249 | + $itemnome = $nlayer->getmetadata ( "classesnome" ); | |
| 250 | + $itemid = $nlayer->getmetadata ( "classesitem" ); | |
| 251 | + $itemcor = $nlayer->getmetadata ( "classescor" ); | |
| 252 | + $itemsimbolo = $nlayer->getmetadata ( "classesimbolo" ); | |
| 253 | + $itemtamanho = $nlayer->getmetadata ( "classestamanho" ); | |
| 254 | + $classeoriginal = $nlayer->getclass ( 0 ); | |
| 255 | + // | |
| 256 | + // pega a extensao geografica que devera ser utilizada | |
| 257 | + // | |
| 258 | + $prjMapa = $mapa->getProjection (); | |
| 259 | + $prjTema = $nlayer->getProjection (); | |
| 260 | + $ret = $nlayer->getmetadata ( "extensao" ); | |
| 261 | + if ($ret == "") { | |
| 262 | + $ret = $nlayer->getextent (); | |
| 263 | + // reprojeta o retangulo | |
| 264 | + if (($prjTema != "") && ($prjMapa != $prjTema)) { | |
| 265 | + $projInObj = ms_newprojectionobj ( $prjTema ); | |
| 266 | + $projOutObj = ms_newprojectionobj ( $prjMapa ); | |
| 267 | + $ret->project ( $projInObj, $projOutObj ); | |
| 268 | + } | |
| 269 | + } else { | |
| 270 | + $temp = explode ( " ", $ret ); | |
| 271 | + $ret = ms_newRectObj (); | |
| 272 | + $ret->setextent ( $temp [0], $temp [1], $temp [2], $temp [3] ); | |
| 273 | + } | |
| 274 | + // | |
| 275 | + $sopen = $nlayer->open (); | |
| 276 | + if ($sopen == MS_FAILURE) { | |
| 277 | + return "erro"; | |
| 278 | + } | |
| 236 | 279 | |
| 280 | + $status = $nlayer->whichShapes ( $ret ); | |
| 281 | + $parametrosClasses = array (); | |
| 282 | + if ($status == 0) { | |
| 283 | + while ( $shape = $nlayer->nextShape () ) { | |
| 284 | + $id = trim ( $shape->values [$itemid] ); | |
| 285 | + if (! $parametrosClasses [$id]) { | |
| 286 | + $nome = ""; | |
| 287 | + if ($itemnome != "") | |
| 288 | + $nome = trim ( $shape->values [$itemnome] ); | |
| 289 | + $cor = ""; | |
| 290 | + if ($itemcor != "") | |
| 291 | + $cor = explode ( ",", trim ( $shape->values [$itemcor] ) ); | |
| 292 | + if (count ( $cor ) != 3) | |
| 293 | + $cor = explode ( " ", trim ( $shape->values [$itemcor] ) ); | |
| 294 | + $tamanho = ""; | |
| 295 | + if ($itemtamanho != "") | |
| 296 | + $tamanho = trim ( $shape->values [$itemtamanho] ); | |
| 297 | + $simbolo = ""; | |
| 298 | + if ($itemsimbolo != "") | |
| 299 | + $simbolo = trim ( $shape->values [$itemsimbolo] ); | |
| 300 | + $parametrosClasses [$id] = array ( | |
| 301 | + "nome" => $nome, | |
| 302 | + "cor" => $cor, | |
| 303 | + "tamanho" => $tamanho, | |
| 304 | + "simbolo" => $simbolo | |
| 305 | + ); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + $fechou = $nlayer->close (); | |
| 309 | + // echo "<pre>";var_dump($parametrosClasses); | |
| 310 | + if (count ( $parametrosClasses ) > 0) { | |
| 311 | + $ids = array_keys ( $parametrosClasses ); | |
| 312 | + for($i = 0; $i < count ( $parametrosClasses ); ++ $i) { | |
| 313 | + $p = $parametrosClasses [$ids [$i]]; | |
| 314 | + // echo "<pre>";var_dump($p); | |
| 315 | + $nclasse = ms_newClassObj ( $nlayer, $classeoriginal ); | |
| 316 | + if ($p ["nome"] != "") | |
| 317 | + $nclasse->set ( "name", $p ["nome"] ); | |
| 318 | + $estilo = $nclasse->getstyle ( 0 ); | |
| 319 | + if ($p ["cor"] != "") { | |
| 320 | + $cor = $p ["cor"]; | |
| 321 | + $ncor = $estilo->color; | |
| 322 | + if ($ncor == "") | |
| 323 | + $ncor = $estilo->outlinecolor; | |
| 324 | + $ncor->setrgb ( $cor [0], $cor [1], $cor [2] ); | |
| 325 | + } | |
| 326 | + if ($p ["tamanho"] != "") | |
| 327 | + $estilo->set ( "size", $p ["tamanho"] ); | |
| 328 | + if ($p ["simbolo"] != "") | |
| 329 | + $estilo->set ( "symbolname", $p ["simbolo"] ); | |
| 330 | + $strE = "('[" . $itemid . "]'eq'" . $ids [$i] . "')"; | |
| 331 | + $nclasse->setexpression ( $strE ); | |
| 332 | + } | |
| 333 | + $classeoriginal->set ( "status", MS_DELETE ); | |
| 334 | + } | |
| 335 | + } | |
| 336 | + if ($substituicon == "sim") { | |
| 337 | + $nlayer->set ( "connection", " " ); | |
| 338 | + } | |
| 339 | + } | |
| 340 | + $pf = $nlayer->getmetadata ( "palletefile" ); | |
| 341 | + if ($pf != "") { | |
| 342 | + if (! file_exists ( $pf )) { | |
| 343 | + return; | |
| 344 | + } | |
| 345 | + $ps = $nlayer->getmetadata ( "palletesteps" ); | |
| 346 | + if ($ps == "") | |
| 347 | + $ps = 8; | |
| 348 | + // | |
| 349 | + // pega os valores do arquivo | |
| 350 | + // | |
| 351 | + $rules = array (); | |
| 352 | + $abre = fopen ( $pf, "r" ); | |
| 353 | + $paletteRules = array (); | |
| 354 | + while ( ! feof ( $abre ) ) { | |
| 355 | + $line = trim ( fgets ( $abre ) ); | |
| 356 | + $pos = strpos ( $line, "#" ); | |
| 357 | + if ($pos === false || $pos > 0) { | |
| 358 | + $paletteEntry = explode ( " ", $line ); | |
| 359 | + $rules [] = array ( | |
| 360 | + "v0" => $paletteEntry [0], | |
| 361 | + "v1" => $paletteEntry [1], | |
| 362 | + "r0" => $paletteEntry [2], | |
| 363 | + "g0" => $paletteEntry [3], | |
| 364 | + "b0" => $paletteEntry [4], | |
| 365 | + "r1" => $paletteEntry [5], | |
| 366 | + "g1" => $paletteEntry [6], | |
| 367 | + "b1" => $paletteEntry [7] | |
| 368 | + ); | |
| 369 | + } | |
| 370 | + } | |
| 371 | + fclose ( $abre ); | |
| 372 | + foreach ( $rules as $rule ) { | |
| 373 | + $delta = ceil ( ($rule ["v1"] - $rule ["v0"]) / $ps ); | |
| 374 | + $legenda = true; | |
| 375 | + for($value = $rule ["v0"]; $value < $rule ["v1"]; $value += $delta) { | |
| 376 | + $class = ms_newClassObj ( $nlayer ); | |
| 377 | + $style = ms_newStyleObj ( $class ); | |
| 378 | + if ($legenda) { | |
| 379 | + $class->set ( name, round ( $value, 0 ) ); | |
| 380 | + $legenda = true; | |
| 381 | + } | |
| 382 | + $expression = "([pixel] > " . round ( $value, 0 ) . " AND [pixel] <= " . round ( $value + $delta, 0 ) . ")"; | |
| 383 | + $class->setExpression ( $expression ); | |
| 384 | + $rgb = getRGBpallete ( $rule, $value ); | |
| 385 | + $style->color->setRGB ( $rgb [0], $rgb [1], $rgb [2] ); | |
| 386 | + } | |
| 387 | + } | |
| 388 | + } | |
| 389 | + return; | |
| 390 | +} | |
| 391 | +function getRGBpallete($rule, $value) { | |
| 392 | + $escala = ($value - $rule ["v0"]) / ($rule ["v1"] - $rule ["v0"]); | |
| 393 | + $r = $rule ["r0"] + round ( ($rule ["r1"] - $rule ["r0"]) * $escala, 0 ); | |
| 394 | + $g = $rule ["g0"] + round ( ($rule ["g1"] - $rule ["g0"]) * $escala, 0 ); | |
| 395 | + $b = $rule ["b0"] + round ( ($rule ["b1"] - $rule ["b0"]) * $escala, 0 ); | |
| 396 | + return array ( | |
| 397 | + $r, | |
| 398 | + $g, | |
| 399 | + $b | |
| 400 | + ); | |
| 401 | +} | |
| 402 | +function cloneInlineSymbol($layern, $nmapa, $mapa) { | |
| 403 | + $numclasses = $layern->numclasses; | |
| 404 | + for($ci = 0; $ci < $numclasses; $ci ++) { | |
| 405 | + $classe = $layern->getclass ( $ci ); | |
| 406 | + $numestilos = $classe->numstyles; | |
| 407 | + for($ei = 0; $ei < $numestilos; $ei ++) { | |
| 408 | + $estilo = $classe->getstyle ( $ei ); | |
| 409 | + if ($estilo->symbolname != "") { | |
| 410 | + $nomesimbolo = $estilo->symbolname; | |
| 411 | + $simbolo = $nmapa->getSymbolObjectById ( $nmapa->getSymbolByName ( $nomesimbolo ) ); | |
| 412 | + if ($simbolo->inmapfile == MS_TRUE || file_exists ( $nomesimbolo )) { | |
| 413 | + $simbolon = new symbolObj ( $mapa, $nomesimbolo ); | |
| 414 | + $simbolon->set ( "inmapfile", MS_TRUE ); | |
| 415 | + | |
| 416 | + $simbolon->setImagePath ( $simbolo->imagepath ); | |
| 417 | + $simbolon->setPoints ( $simbolo->getPointsArray () ); | |
| 418 | + // $simbolon->setPattern($simbolo->getPatternArray()); | |
| 419 | + $simbolon->set ( "type", $simbolo->type ); | |
| 420 | + // $simbolon->set("antialias",$simbolo->antialias); | |
| 421 | + $simbolon->set ( "character", $simbolo->character ); | |
| 422 | + $simbolon->set ( "filled", $simbolo->filled ); | |
| 423 | + | |
| 424 | + // $simbolon->set("font",$simbolo->font); | |
| 425 | + // $simbolon->set("position",$simbolo->position); | |
| 426 | + $simbolon->set ( "sizex", $simbolo->sizex ); | |
| 427 | + $simbolon->set ( "sizey", $simbolo->sizey ); | |
| 428 | + $simbolon->set ( "transparent", $simbolo->transparent ); | |
| 429 | + $simbolon->set ( "transparentcolor", $simbolo->transparentcolor ); | |
| 430 | + // $simbolon->set("anchorpoint",$simbolo->anchorpoint); | |
| 431 | + } | |
| 432 | + } | |
| 433 | + } | |
| 434 | + } | |
| 435 | +} | |
| 237 | 436 | ?> | ... | ... |
admin1/dicionario/menup.js
admin1/dicionario/uploadshp.js
| ... | ... | @@ -146,5 +146,40 @@ i3GEOadmin.uploadshp.dicionario = { |
| 146 | 146 | pt : "Alias da conexão com o banco de dados. Será utilizado apenas para o caso de construção do arquivo mapfile.", |
| 147 | 147 | en : "", |
| 148 | 148 | es : "" |
| 149 | + } ], | |
| 150 | + 'txtTituloCsv2Pg' : [ { | |
| 151 | + pt : "Importação de arquivo CSV para Postgis", | |
| 152 | + en : "", | |
| 153 | + es : "" | |
| 154 | + } ], | |
| 155 | + 'txtDescCsv2Pg' : [ { | |
| 156 | + pt : "Faz o upload de um arquivo CSV e converte para o banco de dados Postgis existente no servidor web. Permite ainda a conversão de colunas com a latitude e longitude em uma coluna do tipo geometria.", | |
| 157 | + en : "", | |
| 158 | + es : "" | |
| 159 | + } ], | |
| 160 | + 'txtAjudaCsv2Pg' : [ { | |
| 161 | + pt : "No formulário deve-se indicar o arquivo no formato CSV. O arquivo é enviado ao servidor e armazenado temporariamente para que a conversão para Postgis seja possível. O resultado do processo será uma tabela no banco de dados no esquema escolhido pelo usuário. O acesso ao banco é feito por meio do usuário administrativo da aplicação i3Geo (o mesmo que gerencia o sistema de administração, veja em ms_configura.php). Esse usuário, definido pelo administrador do servidor, deve ter os direitos de escrita no esquema do banco de dados escolhido para importar os dados.", | |
| 162 | + en : "", | |
| 163 | + es : "" | |
| 164 | + } ], | |
| 165 | + 'txtArquivoCsv' : [ { | |
| 166 | + pt : "Escolha o arquivo texto no formato CSV", | |
| 167 | + en : "", | |
| 168 | + es : "" | |
| 169 | + } ], | |
| 170 | + 'sridOrigemCsv' : [ { | |
| 171 | + pt : "Código numérico SRID (projeção cartográfica) referente aos dados das colunas x e y caso sejam especificadas", | |
| 172 | + en : "", | |
| 173 | + es : "" | |
| 174 | + } ], | |
| 175 | + 'colunaX' : [ { | |
| 176 | + pt : "Nome da coluna no arquivo CSV que contém os valores de coordenadas do eixo x (longitude)", | |
| 177 | + en : "", | |
| 178 | + es : "" | |
| 179 | + } ], | |
| 180 | + 'colunaY' : [ { | |
| 181 | + pt : "Nome da coluna no arquivo CSV que contém os valores de coordenadas do eixo y (latitude)", | |
| 182 | + en : "", | |
| 183 | + es : "" | |
| 149 | 184 | } ] |
| 150 | 185 | }; | ... | ... |
admin1/menu.js
| ... | ... | @@ -66,6 +66,8 @@ menuPrincipal = [ |
| 66 | 66 | },{ |
| 67 | 67 | html: "<a href='" + i3GEO.configura.locaplic + "/admin1/upload/shp2pg/index.php' >"+$trad("shp2pg",i3GEOadmin.menup.dicionario)+"</a>" |
| 68 | 68 | },{ |
| 69 | + html: "<a href='" + i3GEO.configura.locaplic + "/admin1/upload/csv2pg/index.php' >"+$trad("csv2pg",i3GEOadmin.menup.dicionario)+"</a>" | |
| 70 | + },{ | |
| 69 | 71 | html: "<a href='" + i3GEO.configura.locaplic + "/admin1/upload/simbolo/index.php' >"+$trad("uploadSimbolo",i3GEOadmin.menup.dicionario)+"</a>" |
| 70 | 72 | } |
| 71 | 73 | ]},{ | ... | ... |
admin1/upload/arquivo/exec.php
| ... | ... | @@ -213,6 +213,7 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 213 | 213 | $layer->setprojection("AUTO"); |
| 214 | 214 | } |
| 215 | 215 | $mapa->save ( $_SESSION ["locaplic"] . "/temas/" . $codigo . ".map" ); |
| 216 | + \admin\php\funcoesAdmin\removeCabecalhoMapfile ( $_SESSION ["locaplic"] . "/temas/" . $codigo . ".map" ); | |
| 216 | 217 | echo "<div class='alert alert-success' role='alert'>Mapfile $nomePrefixo criado!!!</div>"; |
| 217 | 218 | } else { |
| 218 | 219 | echo "<div class='alert alert-danger' role='alert'>Mapfile não pode ser criado criado!!!</div>"; | ... | ... |
| ... | ... | @@ -0,0 +1,476 @@ |
| 1 | +<?php | |
| 2 | +/****************************************************************/ | |
| 3 | +// | |
| 4 | +// checa login | |
| 5 | +// valida _GET e _POST, juntando em _GET | |
| 6 | +// pega algumas variaveis de uso mais comum | |
| 7 | +// session_start | |
| 8 | +// | |
| 9 | +include ("../../php/checaLogin.php"); | |
| 10 | +\admin\php\login\checaLogin (); | |
| 11 | +// funcoes de administracao | |
| 12 | +include ($_SESSION ["locaplic"] . "/admin1/php/funcoesAdmin.php"); | |
| 13 | +// | |
| 14 | +// carrega outras funcoes e extensoes do PHP | |
| 15 | +// | |
| 16 | +include ($_SESSION ["locaplic"] . "/classesphp/carrega_ext.php"); | |
| 17 | +// | |
| 18 | +// conexao com o banco de administracao | |
| 19 | +// cria as variaveis $dbh e $dbhw alem de conexaoadmin | |
| 20 | +// | |
| 21 | +include ($_SESSION ["locaplic"] . "/admin1/php/conexao.php"); | |
| 22 | +/** | |
| 23 | + * ************************************************************ | |
| 24 | + */ | |
| 25 | +if (\admin\php\funcoesAdmin\verificaOperacaoSessao ( "admin/html/subirshapefile" ) === false) { | |
| 26 | + header ( "HTTP/1.1 403 Vc nao pode realizar essa operacao" ); | |
| 27 | + exit (); | |
| 28 | +} | |
| 29 | +if (! isset ( $idioma ) || $idioma == "") { | |
| 30 | + $idioma = "pt"; | |
| 31 | +} | |
| 32 | + | |
| 33 | +if (isset ( $_GET ["tipo"] )) { | |
| 34 | + $tipo = $_GET ["tipo"]; | |
| 35 | +} | |
| 36 | +if (! isset ( $_FILES ['i3GEOuploadcsv'] ['name'] )) { | |
| 37 | + return; | |
| 38 | +} | |
| 39 | +?> | |
| 40 | +<!DOCTYPE html> | |
| 41 | +<html lang="pt-br"> | |
| 42 | +<head> | |
| 43 | +<META HTTP-EQUIV="Content-Type"> | |
| 44 | +<meta charset='utf-8'> | |
| 45 | +<meta http-equiv='X-UA-Compatible' content='IE=edge'> | |
| 46 | +<meta name='viewport' content='width=device-width, initial-scale=1'> | |
| 47 | +<link rel='stylesheet' type='text/css' href='../../../pacotes/jquery/jquery-ui/jquery-ui.min.css'> | |
| 48 | +<link rel='stylesheet' type='text/css' href='//fonts.googleapis.com/css?family=Roboto:300,400,500,700'> | |
| 49 | +<link rel='stylesheet' type='text/css' href='//fonts.googleapis.com/icon?family=Material+Icons'> | |
| 50 | +<!-- Bootstrap core CSS --> | |
| 51 | +<link href='../../../pacotes/bootstrap/css/bootstrap.min.css' rel='stylesheet'> | |
| 52 | +<!-- Bootstrap Material Design --> | |
| 53 | +<link rel='stylesheet' type='text/css' href='../../../pacotes/bootstrap-material-design/dist/css/bootstrap-material-design.min.css'> | |
| 54 | +<link rel='stylesheet' type='text/css' href='../../../pacotes/bootstrap-material-design/dist/css/ripples.min.css'> | |
| 55 | +<!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> | |
| 56 | +<link href='../../../pacotes/bootstrap/css/ie10-viewport-bug-workaround.css' rel='stylesheet'> | |
| 57 | +<!-- Custom styles for this template --> | |
| 58 | +<link href='../../../pacotes/font-awesome/css/font-awesome.min.css' rel='stylesheet'> | |
| 59 | + | |
| 60 | +<link href='../../../pacotes/bootstrap-accessibility-plugin/plugins/css/bootstrap-accessibility.css' rel='stylesheet'> | |
| 61 | +<script src='../../../admin1/headjs.php'></script> | |
| 62 | +<script src="../../../classesjs/classe_util.js"></script> | |
| 63 | +</head> | |
| 64 | +<body bgcolor="white" style="background-color: white; text-align: left;"> | |
| 65 | + <p> | |
| 66 | +<?php | |
| 67 | +ob_flush (); | |
| 68 | +flush (); | |
| 69 | +sleep ( 2 ); | |
| 70 | +if (isset ( $_FILES ['i3GEOuploadcsv'] ['name'] )) { | |
| 71 | + if (empty ( $_SESSION ["dir_tmp"] )) { | |
| 72 | + echo "<div class='alert alert-danger' role='alert'>Pasta não encontrada</div>"; | |
| 73 | + exit (); | |
| 74 | + } | |
| 75 | + echo "<div class='alert alert-info' role='alert'>Carregando o arquivo...</div>"; | |
| 76 | + | |
| 77 | + ob_flush (); | |
| 78 | + flush (); | |
| 79 | + sleep ( 2 ); | |
| 80 | + | |
| 81 | + if (! file_exists ( $_SESSION ["dir_tmp"] ) || empty ( $_SESSION ["dir_tmp"] )) { | |
| 82 | + echo "<div class='alert alert-danger' role='alert'>Pasta temporária não existe no servidor</div>"; | |
| 83 | + exit (); | |
| 84 | + } | |
| 85 | + // verifica nomes | |
| 86 | + verificaNome ( $_FILES ['i3GEOuploadcsv'] ['name'] ); | |
| 87 | + // remove acentos | |
| 88 | + $nomePrefixo = "csv2pg" . (rand ( 9000, 10000 )) * - 1; | |
| 89 | + // sobe arquivo | |
| 90 | + $Arquivo = $_FILES ['i3GEOuploadcsv'] ['tmp_name']; | |
| 91 | + $status = move_uploaded_file ( $Arquivo, $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv" ); | |
| 92 | + if ($status != 1) { | |
| 93 | + echo "<div class='alert alert-danger' role='alert'>Ocorreu um erro no envio do arquivo CSV. Pode ser uma limitação quanto ao tamanho do arquivo ou permissão de escrita na pasta indicada.</div>"; | |
| 94 | + exit (); | |
| 95 | + } | |
| 96 | + if (! file_exists ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv" )) { | |
| 97 | + echo "<div class='alert alert-danger' role='alert'>Ocorreu algum problema no envio do arquivo</div>"; | |
| 98 | + exit (); | |
| 99 | + } | |
| 100 | + $checkphp = \admin\php\funcoesAdmin\fileContemString ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv", "<?php" ); | |
| 101 | + if ($checkphp == true) { | |
| 102 | + echo "<div class='alert alert-danger' role='alert'>Arquivo csv invalido</div>"; | |
| 103 | + unlink ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv" ); | |
| 104 | + exit (); | |
| 105 | + } | |
| 106 | + echo "<div class='alert alert-success' role='alert'>Arquivo enviado.</div>"; | |
| 107 | + // | |
| 108 | + // gera o script para inclusao no banco | |
| 109 | + // | |
| 110 | + // pega a lista de colunas e identifica o separador utilizado | |
| 111 | + $handle = fopen ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv", "r" ); | |
| 112 | + $cabecalho = fgets ( $handle ); | |
| 113 | + $buffer = str_replace ( '"', '', $cabecalho ); | |
| 114 | + $buffer = str_replace ( "'", '', $buffer ); | |
| 115 | + $buffer = str_replace ( "\n", '', $buffer ); | |
| 116 | + $buffer = str_replace ( "\r", '', $buffer ); | |
| 117 | + $colunas = explode ( ";", $buffer ); | |
| 118 | + $separador = ";"; | |
| 119 | + if (count ( $colunas ) == 1) { | |
| 120 | + $colunas = explode ( ",", $buffer ); | |
| 121 | + $separador = ","; | |
| 122 | + } | |
| 123 | + echo "<div class='alert alert-success' role='alert'>Separador de colunas identificado: <b>" . $separador . "</b></p></div>"; | |
| 124 | + echo "<div class='alert alert-success' role='alert'>Total de colunas: <b>" . count ( $colunas ) . "</b></p></div>"; | |
| 125 | + fclose ( $handle ); | |
| 126 | + echo "<div class='alert alert-success' role='alert'>Colunas: <p><pre>"; | |
| 127 | + print_r ( $colunas ); | |
| 128 | + echo "</pre></p></div>"; | |
| 129 | + echo "<div class='alert alert-info' role='alert'>Testando o arquivo <p></div>"; | |
| 130 | + ob_flush (); | |
| 131 | + flush (); | |
| 132 | + sleep ( 2 ); | |
| 133 | + // | |
| 134 | + // testa as linhas e separadores | |
| 135 | + // | |
| 136 | + $handle = fopen ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv", "r" ); | |
| 137 | + $linhas = array (); | |
| 138 | + $ncolunas = count ( $colunas ); | |
| 139 | + $linhas50 = array (); | |
| 140 | + while ( ! feof ( $handle ) ) { | |
| 141 | + $buffer = fgets ( $handle ); | |
| 142 | + if ($buffer != $cabecalho) { | |
| 143 | + $buffer = str_replace ( "'", '', $buffer ); | |
| 144 | + $buffer = str_replace ( "\n", '', $buffer ); | |
| 145 | + $buffer = str_replace ( "\r", '', $buffer ); | |
| 146 | + if ($buffer != "") { | |
| 147 | + $temp = explode ( $separador, $buffer ); | |
| 148 | + if (count ( $linhas50 ) < 51) { | |
| 149 | + $linhas50 [] = $temp; | |
| 150 | + } | |
| 151 | + if (count ( $temp ) != $ncolunas) { | |
| 152 | + echo "<div class='alert alert-danger' role='alert'>Linha com erro. Processo abortado. <p><pre>"; | |
| 153 | + print_r ( $temp ); | |
| 154 | + echo "</pre></p></div>"; | |
| 155 | + exit (); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + } | |
| 159 | + } | |
| 160 | + fclose ( $handle ); | |
| 161 | + // | |
| 162 | + // pega os tipos das colunas | |
| 163 | + // | |
| 164 | + $contador = 0; | |
| 165 | + foreach ( $colunas as $coluna ) { | |
| 166 | + $tipo = "numeric"; | |
| 167 | + for($i = 1; $i < 50; $i ++) { | |
| 168 | + $s = $linhas50 [$i]; | |
| 169 | + $v = $s [$contador]; | |
| 170 | + if (! is_numeric ( $v )) { | |
| 171 | + $tipo = "varchar"; | |
| 172 | + } | |
| 173 | + } | |
| 174 | + $tipoColuna [$colunas [$contador]] = $tipo; | |
| 175 | + $contador = $contador + 1; | |
| 176 | + } | |
| 177 | + echo "<div class='alert alert-success' role='alert'>Tipos das colunas: <p><pre>"; | |
| 178 | + print_r ( $tipoColuna ); | |
| 179 | + echo "</pre></p></div>"; | |
| 180 | + | |
| 181 | + $sqinsert = array (); | |
| 182 | + | |
| 183 | + // verifica autorizacao para o esquema | |
| 184 | + if (empty ( $_POST ["i3GEOuploadEsquemaDestino"] ) || ! in_array ( $_POST ["i3GEOuploadEsquemaDestino"], $_SESSION ["i3geoUploadDataWL"] ["postgis"] ["esquemas"] )) { | |
| 185 | + echo "<div class='alert alert-danger' role='alert'>Esquema não permitido</div>"; | |
| 186 | + exit (); | |
| 187 | + } | |
| 188 | + | |
| 189 | + $conexao = $_SESSION ["i3geoUploadDataWL"] ["postgis"] ["conexao"]; | |
| 190 | + try { | |
| 191 | + $dbh = new PDO ( 'pgsql:dbname=' . $conexao ["dbname"] . ';user=' . $conexao ["user"] . ';password=' . $conexao ["password"] . ';host=' . $conexao ["host"] . ';port=' . $conexao ["port"] ); | |
| 192 | + } catch ( PDOException $e ) { | |
| 193 | + echo "<div class='alert alert-danger' role='alert'>Falha ao conectar com o banco</div>"; | |
| 194 | + exit (); | |
| 195 | + } | |
| 196 | + if (empty ( $_POST ["i3GEOuploadNomeTabela"] ) || empty ( $_POST ["i3GEOuploadEsquemaDestino"] )) { | |
| 197 | + exit (); | |
| 198 | + } | |
| 199 | + // gera o script para criar a tabela | |
| 200 | + // verifica se a tabela ja existe | |
| 201 | + $sql = "SELECT table_name FROM information_schema.tables where table_schema = '" . $_POST ["i3GEOuploadEsquemaDestino"] . "' AND table_name = '" . $_POST ["i3GEOuploadNomeTabela"] . "'"; | |
| 202 | + $res = $dbh->query ( $sql, PDO::FETCH_ASSOC ); | |
| 203 | + if (count ( $res->fetchAll () ) > 0) { | |
| 204 | + $tabelaExiste = true; | |
| 205 | + } else { | |
| 206 | + $tabelaExiste = false; | |
| 207 | + } | |
| 208 | + // encoding do banco de dados | |
| 209 | + $sql = "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = '" . $conexao ["dbname"] . "'"; | |
| 210 | + $res = $dbh->query ( $sql, PDO::FETCH_ASSOC ); | |
| 211 | + $encodingdb = $res->fetchAll (); | |
| 212 | + $encodingdb = $encodingdb [0]; | |
| 213 | + $encodingdb = $encodingdb ["pg_encoding_to_char"]; | |
| 214 | + if ($encodingdb == "UTF8") { | |
| 215 | + $encodingdb = "UTF-8"; | |
| 216 | + } | |
| 217 | + if ($encodingdb == "LATIN1") { | |
| 218 | + $encodingdb = "ISO-8859-1"; | |
| 219 | + } | |
| 220 | + // a tabela nao existe e e do tipo create | |
| 221 | + $sqltabela = array (); | |
| 222 | + | |
| 223 | + if ($tabelaExiste == false && $_POST ["i3GEOuploadTipoOperacao"] == "criar") { | |
| 224 | + $sql = "CREATE TABLE " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . "("; | |
| 225 | + $temp = array (); | |
| 226 | + if (! empty ( $_POST ["i3GEOuploadColunaX"] ) && ! empty ( $_POST ["i3GEOuploadColunaY"] )) { | |
| 227 | + $temp [] = "the_geom geometry"; | |
| 228 | + } | |
| 229 | + foreach ( $colunas as $coluna ) { | |
| 230 | + $temp [] = \admin\php\funcoesAdmin\removeAcentos ( strtolower ( $coluna ) ) . " " . $tipoColuna [$coluna]; | |
| 231 | + } | |
| 232 | + $sql .= implode ( ",", $temp ) . ")WITH(OIDS=FALSE)"; | |
| 233 | + $sqltabela [] = $sql; | |
| 234 | + $sqltabela [] = "ALTER TABLE " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " OWNER TO " . $conexao ["user"]; | |
| 235 | + if (! empty ( $_POST ["i3GEOuploadColunaX"] ) && ! empty ( $_POST ["i3GEOuploadColunaY"] )) { | |
| 236 | + $sqltabela [] = "CREATE INDEX " . $_POST ["i3GEOuploadNomeTabela"] . "_indx_thegeom ON " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " USING gist (the_geom )"; | |
| 237 | + } | |
| 238 | + if (! empty ( $_POST ["comentarioShp"] )) { | |
| 239 | + $enc = mb_detect_encoding ( $texto ); | |
| 240 | + $_POST ["i3GEOuploadComentario"] = mb_convert_encoding ( $_POST ["i3GEOuploadComentario"], $encodingdb, $enc ); | |
| 241 | + $sqltabela [] = "COMMENT ON TABLE " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " IS '" . $_POST ["i3GEOuploadComentario"] . "'"; | |
| 242 | + } | |
| 243 | + echo "<div class='alert alert-info' role='alert'>Sql tabela: <p><pre>"; | |
| 244 | + print_r ( $sqltabela ); | |
| 245 | + echo "</pre></p></div>"; | |
| 246 | + } | |
| 247 | + if ($tabelaExiste == true && $_POST ["i3GEOuploadTipoOperacao"] == "criar") { | |
| 248 | + echo "<div class='alert alert-danger' role='alert'>A tabela existe. Não pode ser criada.</div>"; | |
| 249 | + exit (); | |
| 250 | + } | |
| 251 | + // se a tabela existe e e para atualizar os registros | |
| 252 | + if ($tabelaExiste == true && $_POST ["i3GEOuploadTipoOperacao"] == "atualizar") { | |
| 253 | + $sqltabela [] = "delete from " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"]; | |
| 254 | + } | |
| 255 | + | |
| 256 | + // gera o script para inserir os dados | |
| 257 | + echo "<div class='alert alert-success' role='alert'>Preparando inclusão de dados...</div>"; | |
| 258 | + ob_flush (); | |
| 259 | + flush (); | |
| 260 | + sleep ( 1 ); | |
| 261 | + | |
| 262 | + $linhas = array (); | |
| 263 | + $insert = "INSERT INTO " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " (" . strtolower ( \admin\php\funcoesAdmin\removeAcentos ( implode ( ",", $colunas ) ) ) . ")"; | |
| 264 | + if (! empty ( $_POST ["i3GEOuploadColunaX"] ) && ! empty ( $_POST ["i3GEOuploadColunaY"] )) { | |
| 265 | + $insert = "INSERT INTO " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " (" . strtolower ( \admin\php\funcoesAdmin\removeAcentos ( implode ( ",", $colunas ) ) ) . ",the_geom)"; | |
| 266 | + } | |
| 267 | + | |
| 268 | + $escapar = "'"; | |
| 269 | + | |
| 270 | + //descobre o indice do array que contem a coluna com x e com y | |
| 271 | + $x = ""; | |
| 272 | + $y = ""; | |
| 273 | + if (! empty ( $_POST ["i3GEOuploadColunaX"] ) && ! empty ( $_POST ["i3GEOuploadColunaY"] )) { | |
| 274 | + for($i = 0; $i < count ( $colunas ); $i ++) { | |
| 275 | + if($colunas[$i] == $_POST ["i3GEOuploadColunaX"]){ | |
| 276 | + $x = $i; | |
| 277 | + } | |
| 278 | + if($colunas[$i] == $_POST ["i3GEOuploadColunaY"]){ | |
| 279 | + $y = $i; | |
| 280 | + } | |
| 281 | + } | |
| 282 | + } | |
| 283 | + | |
| 284 | + $handle = fopen ( $_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".csv", "r" ); | |
| 285 | + $numcsv = 0; | |
| 286 | + while ( ! feof ( $handle ) ) { | |
| 287 | + $buffer = fgets ( $handle ); | |
| 288 | + $numcsv = $numcsv + 1; | |
| 289 | + if ($buffer != $cabecalho) { | |
| 290 | + $buffer = str_replace ( "'", '', $buffer ); | |
| 291 | + $buffer = str_replace ( '"', '', $buffer ); | |
| 292 | + $buffer = str_replace ( "\n", '', $buffer ); | |
| 293 | + $buffer = str_replace ( "\r", '', $buffer ); | |
| 294 | + if ($buffer != "") { | |
| 295 | + $l = explode ( $separador, $buffer ); | |
| 296 | + $vs = array (); | |
| 297 | + for($i = 0; $i < count ( $colunas ); $i ++) { | |
| 298 | + $escape = ""; | |
| 299 | + if ($tipoColuna [$colunas [$i]] == "varchar") { | |
| 300 | + $texto = str_replace(array("'",'"'),"",$l [$i]); | |
| 301 | + $enc = mb_detect_encoding ( $texto ); | |
| 302 | + $textosl = addcslashes ( $texto, $escapar ); | |
| 303 | + if ($textosl != $texto) { | |
| 304 | + $escape = "E"; | |
| 305 | + } | |
| 306 | + if ($enc != "" && $enc != $encodingdb) { | |
| 307 | + $textosl = "$escape'" . mb_convert_encoding ( $textosl, $encodingdb, $enc ) . "'"; | |
| 308 | + } else { | |
| 309 | + $textosl = "$escape'" . $textosl . "'"; | |
| 310 | + } | |
| 311 | + if ($textosl == "''") { | |
| 312 | + $textosl = 'null'; | |
| 313 | + } | |
| 314 | + $vs [] = $textosl; | |
| 315 | + } else { | |
| 316 | + $valor = $l [$i]; | |
| 317 | + if ($valor == "" || (empty ( $valor ) && $valor != 0)) { | |
| 318 | + $valor = 'nulo'; | |
| 319 | + } | |
| 320 | + $vs [] = $valor; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + if (! empty ( $_POST ["i3GEOuploadColunaX"] ) && ! empty ( $_POST ["i3GEOuploadColunaY"] )) { | |
| 324 | + $vx = str_replace(",",".",$l [$x]); | |
| 325 | + $vy = str_replace(",",".",$l [ $y]); | |
| 326 | + if ($_POST ["i3GEOuploadSridDestino"] == $_POST ["i3GEOuploadSridOrigem"]) { | |
| 327 | + $vs[] = "ST_PointFromText('POINT(". $vx . " " . $vy .")','".$_POST["i3GEOuploadSridDestino"]."')"; | |
| 328 | + } else { | |
| 329 | + $vs[] = "ST_transform (ST_PointFromText('POINT(". $vx . " " . $vy .")','".$_POST["i3GEOuploadSridDestino"]."')," . $_POST["i3GEOuploadSridDestino"] . ")"; | |
| 330 | + } | |
| 331 | + } | |
| 332 | + $str = implode ( ",", $vs ); | |
| 333 | + $str = str_replace ( "nulo", 'null', $str ); | |
| 334 | + $linhas [] = $insert . "VALUES(" . $escape . "" . $str . ")"; | |
| 335 | + } | |
| 336 | + } | |
| 337 | + } | |
| 338 | + fclose ( $handle ); | |
| 339 | + | |
| 340 | + if (! in_array ( $_POST ["i3GEOuploadColunaGid"], $colunas ) && $_POST ["i3GEOuploadTipoOperacao"] == "criar") { | |
| 341 | + $linhas [] = "alter table " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . " add " . $_POST ["i3GEOuploadColunaGid"] . " serial CONSTRAINT " . $_POST ["i3GEOuploadNomeTabela"] . "_gid_pkey PRIMARY KEY"; | |
| 342 | + } | |
| 343 | + | |
| 344 | + if ($_POST ["i3GEOuploadApenasScript"] == "on") { | |
| 345 | + echo "<div class='alert alert-info' role='alert'>Sql de inserção de dados: <p><pre>"; | |
| 346 | + foreach ( $linhas as $linha ) { | |
| 347 | + echo ( $linha ) . "\n"; | |
| 348 | + } | |
| 349 | + echo "</pre></p></div>"; | |
| 350 | + } else { | |
| 351 | + // aqui o sql e executado verdadeiramente | |
| 352 | + // antes e feito um backup da tabela | |
| 353 | + | |
| 354 | + // $sqltabela sera vazio se a tabela ja existir | |
| 355 | + foreach ( $sqltabela as $linha ) { | |
| 356 | + try { | |
| 357 | + $dbh->query ( $linha ); | |
| 358 | + } catch ( PDOException $e ) { | |
| 359 | + echo "<div class='alert alert-danger' role='alert'>Não foi possível criar a tabela<p><pre>"; | |
| 360 | + exit (); | |
| 361 | + } | |
| 362 | + } | |
| 363 | + // para testar com acentuacao diferente | |
| 364 | + $conexao = $_SESSION ["i3geoUploadDataWL"] ["postgis"] ["conexao"]; | |
| 365 | + $bdcon = pg_connect ( 'dbname=' . $conexao ["dbname"] . ' user=' . $conexao ["user"] . ' password=' . $conexao ["password"] . ' host=' . $conexao ["host"] . ' port=' . $conexao ["port"] . "options='-c client_encoding=LATIN1'" ); | |
| 366 | + echo "<div class='alert alert-info' role='alert'>Sql de inserção de dados com erros ou modificados: <p><pre>"; | |
| 367 | + foreach ( $linhas as $linha ) { | |
| 368 | + try { | |
| 369 | + | |
| 370 | + $res = $dbh->query ( $linha ); | |
| 371 | + if ($res == false) { | |
| 372 | + $res = pg_query ( $bdcon, $linha ); | |
| 373 | + if ($res == false) { | |
| 374 | + $linha = remove_accents ( $linha ); | |
| 375 | + $res = $dbh->query ( $linha ); | |
| 376 | + if ($res == false) { | |
| 377 | + $res = pg_query ( $bdcon, $linha ); | |
| 378 | + if ($res == false) { | |
| 379 | + echo "<p><span style=color:red >Erro em: </span>$linha</p>"; | |
| 380 | + } | |
| 381 | + } else { | |
| 382 | + echo "<p><span style=color:red >Acentos removidos: $linha</span></p>"; | |
| 383 | + } | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | + } catch ( PDOException $e ) { | |
| 388 | + echo "<div class='alert alert-danger' role='alert'>Não foi possível executar os SQLs<p><pre>"; | |
| 389 | + } | |
| 390 | + } | |
| 391 | + echo "</pre></p></div>"; | |
| 392 | + $sql = "select * from " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"]; | |
| 393 | + $q = $dbh->query ( $sql, PDO::FETCH_ASSOC ); | |
| 394 | + $r = $q->fetchAll (); | |
| 395 | + | |
| 396 | + echo "<div class='alert alert-info' role='alert'>"; | |
| 397 | + echo "<p>Registros existentes no CSV: $numcsv</p>"; | |
| 398 | + | |
| 399 | + echo "<p>Registros na tabela final: " . count ( $r ) . "</p>"; | |
| 400 | + echo "<p>Diferenças podem ocorrer em função de caracteres acentuados não suportados pelo banco de dados</p>"; | |
| 401 | + echo "<p><b>Feito!!!</p>"; | |
| 402 | + echo "</div>"; | |
| 403 | + } | |
| 404 | + // | |
| 405 | + ob_flush (); | |
| 406 | + flush (); | |
| 407 | + sleep ( 2 ); | |
| 408 | + | |
| 409 | + $nomeMapfile = $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map"; | |
| 410 | + if ($_POST ["i3GEOuploadCriaMapfile"] == "on" && file_exists ( $nomeMapfile )) { | |
| 411 | + echo "<div class='alert alert-danger' role='alert'>Arquivo mapfile com o nome " . $_POST ["i3GEOuploadNomeTabela"] . "já existe.</div>"; | |
| 412 | + $_POST ["i3GEOuploadCriaMapfile"] = ""; | |
| 413 | + } | |
| 414 | + if ($_POST ["i3GEOuploadCriaMapfile"] == "on" && $_POST ["i3GEOuploadAliasConexao"] != "") { | |
| 415 | + $mapObj = ms_newMapObjFromString ( "MAP END" ); | |
| 416 | + $layer = ms_newLayerObj ( $mapObj ); | |
| 417 | + $mapObj->setProjection ( "init=epsg:" . $_POST ["i3GEOuploadSridDestino"] ); | |
| 418 | + $layer->setProjection ( "init=epsg:" . $_POST ["i3GEOuploadSridDestino"] ); | |
| 419 | + | |
| 420 | + $_POST ["i3GEOuploadAliasConexao"] = str_replace ( " ", "", $_POST ["i3GEOuploadAliasConexao"] ); | |
| 421 | + if (! in_array ( $_POST ["i3GEOuploadAliasConexao"], array_keys ( $_SESSION ["postgis_mapa"] ) )) { | |
| 422 | + echo "<div class='alert alert-danger' role='alert'>Alias para a conexão com o banco não definida</div>"; | |
| 423 | + } else { | |
| 424 | + echo "<div class='alert alert-success' role='alert'>Criando mapfile...</div>"; | |
| 425 | + ob_flush (); | |
| 426 | + flush (); | |
| 427 | + sleep ( 2 ); | |
| 428 | + $tipoLayer = MS_LAYER_POINT; | |
| 429 | + include ($_SESSION ["locaplic"] . "/admin1/catalogo/mapfile/funcoes.php"); | |
| 430 | + $cria = \admin\catalogo\mapfile\adicionar ( $_SESSION ["locaplic"], $_POST ["i3GEOuploadNomeTabela"], "", $_POST ["i3GEOuploadNomeTabela"], "", "", $_POST ["i3GEOuploadNomeTabela"], "", $_POST ["i3GEOuploadNomeTabela"], $_POST ["i3GEOuploadNomeTabela"], true, $dbhw ); | |
| 431 | + if ($cria == true && file_exists ( $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map" )) { | |
| 432 | + $mapa = ms_newMapObj ( $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map" ); | |
| 433 | + $layer = $mapa->getLayerByName ( $_POST ["i3GEOuploadNomeTabela"] ); | |
| 434 | + $layer->set ( "data", "the_geom from (select * from " . $_POST ["i3GEOuploadEsquemaDestino"] . "." . $_POST ["i3GEOuploadNomeTabela"] . ") as foo using unique " . $_POST ["i3GEOuploadColunaGid"] . " using srid=" . $_POST ["i3GEOuploadSridDestino"] ); | |
| 435 | + $layer->set ( "connection", $_POST ["i3GEOuploadAliasConexao"] ); | |
| 436 | + $layer->setconnectiontype ( 6 ); | |
| 437 | + $layer->set ( "type", $tipoLayer ); | |
| 438 | + $c = $layer->getclass(0); | |
| 439 | + $s = $c->getsymbol(0); | |
| 440 | + $s->set("symbol","ponto"); | |
| 441 | + $mapa->save ( $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map" ); | |
| 442 | + \admin\php\funcoesAdmin\removeCabecalhoMapfile ( $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map" ); | |
| 443 | + echo "<div class='alert alert-success' role='alert'>Mapfile " . $_POST ["i3GEOuploadNomeTabela"] . " criado!!!</div>"; | |
| 444 | + } else { | |
| 445 | + echo "<div class='alert alert-danger' role='alert'>Mapfile não pode ser criado criado!!!</div>"; | |
| 446 | + } | |
| 447 | + } | |
| 448 | + } | |
| 449 | + echo "<div class='alert alert-success' role='alert'>Pode fechar essa janela.</div>"; | |
| 450 | +} else { | |
| 451 | + echo "<div class='alert alert-danger' role='alert'>Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</div>"; | |
| 452 | +} | |
| 453 | +if (file_exists ( $_SESSION ["locaplic"] . "/temas/" . $_POST ["i3GEOuploadNomeTabela"] . ".map" )) { | |
| 454 | + echo "<div class='alert alert-info' role='alert'><a href='#' onclick=\"abreEditor('" . $_POST ["i3GEOuploadNomeTabela"] . "')\" class='alert-link'>Editar mapfile</a></div>"; | |
| 455 | +} | |
| 456 | +function verificaNome($nome) { | |
| 457 | + if (strlen ( basename ( $nome ) ) > 200) { | |
| 458 | + exit (); | |
| 459 | + } | |
| 460 | + $nome = strtolower ( $nome ); | |
| 461 | + $lista = explode ( ".", $nome ); | |
| 462 | + $extensao = $lista [count ( $lista ) - 1]; | |
| 463 | + if (($extensao != "csv")) { | |
| 464 | + echo "Nome de arquivo inválido. $nome"; | |
| 465 | + exit (); | |
| 466 | + } | |
| 467 | +} | |
| 468 | +?> | |
| 469 | +<script> | |
| 470 | +function abreEditor (codigo){ | |
| 471 | + window.parent.location.href = "../../catalogo/mapfile/opcoes/index.php?codigo=" + codigo + "&id_tema"; | |
| 472 | +} | |
| 473 | +</script> | |
| 474 | + | |
| 475 | +</body> | |
| 476 | +</html> | ... | ... |
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +/* | |
| 2 | +Licenca: | |
| 3 | + | |
| 4 | +GPL2 | |
| 5 | + | |
| 6 | +i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
| 7 | + | |
| 8 | +Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
| 9 | +Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com | |
| 10 | + | |
| 11 | +Este programa é software livre; você pode redistribuí-lo | |
| 12 | +e/ou modificá-lo sob os termos da Licença Pública Geral | |
| 13 | +GNU conforme publicada pela Free Software Foundation; | |
| 14 | + | |
| 15 | +Este programa é distribuído na expectativa de que seja útil, | |
| 16 | +porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
| 17 | +de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
| 18 | +Consulte a Licença Pública Geral do GNU para mais detalhes. | |
| 19 | +Você deve ter recebido uma cópia da Licença Pública Geral do | |
| 20 | +GNU junto com este programa; se não, escreva para a | |
| 21 | +Free Software Foundation, Inc., no endereço | |
| 22 | +59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 23 | + | |
| 24 | + */ | |
| 25 | +i3GEOadmin.csv2pg = {}; | |
| 0 | 26 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,253 @@ |
| 1 | +<?php | |
| 2 | +define ( "ONDEI3GEO", "../../.." ); | |
| 3 | +include ("exec.php"); | |
| 4 | +include "../../head.php"; | |
| 5 | +// monta o combo com a lista de pastas para armazenar os arquivos | |
| 6 | +$comboEsquemas = '<select name="i3GEOuploadEsquemaDestino" class="form-control" required ><option value=""></option>'; | |
| 7 | +if (!empty ( $_SESSION ["i3geoUploadDataWL"] )) { | |
| 8 | + foreach ( $_SESSION ["i3geoUploadDataWL"]["postgis"]["esquemas"] as $c ) { | |
| 9 | + $comboEsquemas .= "<option value='$c'>$c</option>"; | |
| 10 | + } | |
| 11 | +} | |
| 12 | +$comboEsquemas .= "</select>"; | |
| 13 | +// monta o combo com a lista de alias para conexao com o banco de dados | |
| 14 | +$comboAliasConexao = '<select name="i3GEOuploadAliasConexao" class="form-control" ><option value=""></option>'; | |
| 15 | +foreach ( array_keys($_SESSION ["postgis_mapa"]) as $c ) { | |
| 16 | + $comboAliasConexao .= "<option value='$c'>$c</option>"; | |
| 17 | +} | |
| 18 | +$comboAliasConexao .= "</select>"; | |
| 19 | +?> | |
| 20 | +<div class="container-fluid migalha"> | |
| 21 | + <div class="row"> | |
| 22 | + <div class="btn-group btn-breadcrumb"> | |
| 23 | + <a class="btn btn-default" href="../../../init/index.php"> | |
| 24 | + <span>i3Geo</span> | |
| 25 | + </a> | |
| 26 | + <a class="btn btn-default" href="../../index.php"> | |
| 27 | + <span>Admin</span> | |
| 28 | + </a> | |
| 29 | + <a class="btn btn-default" style="pointer-events: none"> | |
| 30 | + <span>Upload</span> | |
| 31 | + </a> | |
| 32 | + <a class="btn btn-default" style="pointer-events: none"> | |
| 33 | + <span>CSV->Postgis</span> | |
| 34 | + </a> | |
| 35 | + </div> | |
| 36 | + </div> | |
| 37 | +</div> | |
| 38 | +<div class="container"> | |
| 39 | + <div class="row center-block"> | |
| 40 | + <div class="col-md-12"> | |
| 41 | + <div class="well hidden" id="titulo"> | |
| 42 | + <button data-toggle="modal" data-target="#ajudaPrincipal" class="btn btn-primary btn-fab btn-fab-mini pull-right"> | |
| 43 | + <i class="material-icons">help</i> | |
| 44 | + </button> | |
| 45 | + <h2> | |
| 46 | + <small>{{{txtTituloCsv2Pg}}}</small> | |
| 47 | + </h2> | |
| 48 | + <blockquote>{{{txtDescCsv2Pg}}}</blockquote> | |
| 49 | + <!--Modal ajuda--> | |
| 50 | + <div id="ajudaPrincipal" class="modal fade" tabindex="-1"> | |
| 51 | + <div class="modal-dialog"> | |
| 52 | + <div class="modal-content"> | |
| 53 | + <div class="modal-body"> | |
| 54 | + <p>{{{txtAjudaCsv2Pg}}}</p> | |
| 55 | + </div> | |
| 56 | + </div> | |
| 57 | + </div> | |
| 58 | + </div> | |
| 59 | + </div> | |
| 60 | + | |
| 61 | + <form style="" target="i3GEOuploadiframe" action="exec.php" method="post" ENCTYPE="multipart/form-data" onsubmit="javascript:$('#modalUpload').modal('show');" class="form-horizontal" role="form" | |
| 62 | + method="post"> | |
| 63 | + <div class="row center-block well hidden" id="corpo"> | |
| 64 | + <div class="col-md-12"> | |
| 65 | + <div class="form-group form-group-lg"> | |
| 66 | + <label class="col-md-5 control-label">{{{txtArquivoCsv}}}</label> | |
| 67 | + <div class="col-md-7"> | |
| 68 | + <div class="form-group form-group-lg col-md-12"> | |
| 69 | + <div class="input-group-btn"> | |
| 70 | + <button type="button" class="btn btn-primary pull-left" onclick="$(this).parent().find('input[type=file]').click();">CSV</button> | |
| 71 | + <input name="i3GEOuploadcsv" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none;" type="file"> | |
| 72 | + <span class="form-control"></span> | |
| 73 | + </div> | |
| 74 | + </div> | |
| 75 | + </div> | |
| 76 | + </div> | |
| 77 | + </div> | |
| 78 | + <div class="col-md-12"> | |
| 79 | + <div class="form-group form-group-lg"> | |
| 80 | + <label class="col-md-5 control-label" for="i3GEOuploadEsquemaDestino">{{{esquemaArmazenamento}}}</label> | |
| 81 | + <div class="col-md-7"> | |
| 82 | + <?php echo $comboEsquemas; ?> | |
| 83 | + </div> | |
| 84 | + </div> | |
| 85 | + <div class="form-group form-group-lg"> | |
| 86 | + <label class="col-md-5 control-label" for="i3GEOuploadNomeTabela">{{{nomeTabela}}}</label> | |
| 87 | + <div class="col-md-7"> | |
| 88 | + <input type="text" value="" class="form-control" name="i3GEOuploadNomeTabela" required> | |
| 89 | + <div class="input-group-btn"> | |
| 90 | + <a role="button" class="btn btn-danger btn-fab btn-fab-mini" style="height: 20px; min-width: 20px; width: 20px;" onclick="listaTabelasUpload('i3GEOuploadNomeTabela')" href="javascript:void(0)"> | |
| 91 | + <i class="material-icons md-18">list</i> | |
| 92 | + </a> | |
| 93 | + </div> | |
| 94 | + </div> | |
| 95 | + </div> | |
| 96 | + <div class="form-group form-group-lg"> | |
| 97 | + <label class="col-md-5 control-label" for="i3GEOuploadSridOrigem">{{{sridOrigemCsv}}}</label> | |
| 98 | + <div class="col-md-7"> | |
| 99 | + <input type="text" value="<?php echo $_SESSION["i3GeoProjDefault"]["epsg"]; ?>" class="form-control" name="i3GEOuploadSridOrigem" > | |
| 100 | + </div> | |
| 101 | + </div> | |
| 102 | + <div class="form-group form-group-lg"> | |
| 103 | + <label class="col-md-5 control-label" for="i3GEOuploadSridDestino">{{{sridDestino}}}</label> | |
| 104 | + <div class="col-md-7"> | |
| 105 | + <input type="text" value="<?php echo $_SESSION["i3GeoProjDefault"]["epsg"]; ?>" class="form-control" name="i3GEOuploadSridDestino" > | |
| 106 | + </div> | |
| 107 | + </div> | |
| 108 | + <div class="form-group form-group-lg"> | |
| 109 | + <label class="col-md-5 control-label" for="i3GEOuploadColunaX">{{{colunaX}}}</label> | |
| 110 | + <div class="col-md-7"> | |
| 111 | + <input type="text" value="" class="form-control" name="i3GEOuploadColunaX"> | |
| 112 | + </div> | |
| 113 | + </div> | |
| 114 | + <div class="form-group form-group-lg"> | |
| 115 | + <label class="col-md-5 control-label" for="i3GEOuploadColunaY">{{{colunaY}}}</label> | |
| 116 | + <div class="col-md-7"> | |
| 117 | + <input type="text" value="" class="form-control" name="i3GEOuploadColunaY"> | |
| 118 | + </div> | |
| 119 | + </div> | |
| 120 | + <div class="form-group form-group-lg"> | |
| 121 | + <label class="col-md-5 control-label" for="i3GEOuploadComentario">{{{comentarioTabela}}}</label> | |
| 122 | + <div class="col-md-7"> | |
| 123 | + <input type="text" value="" class="form-control" name="i3GEOuploadComentario"> | |
| 124 | + </div> | |
| 125 | + </div> | |
| 126 | + <div class="form-group form-group-lg"> | |
| 127 | + <label class="col-md-5 control-label" for="i3GEOuploadTipoOperacao">{{{tipoOperacao}}}</label> | |
| 128 | + <div class="col-md-7"> | |
| 129 | + <select title="{{{tipoOperacao}}}" name="i3GEOuploadTipoOperacao" class="form-control"> | |
| 130 | + <option value="criar">{{{tabelaNova}}}</option> | |
| 131 | + <option value="inserir">{{{tabelaInsert}}}</option> | |
| 132 | + <option value="atualizar">{{{tabelaUpdate}}}</option> | |
| 133 | + </select> | |
| 134 | + </div> | |
| 135 | + </div> | |
| 136 | + <div class="form-group form-group-lg"> | |
| 137 | + <label class="col-md-5 control-label" style="margin-top: 0px;" for="i3GEOuploadColunaGid">{{{colunaGid}}}</label> | |
| 138 | + <div class="col-md-7"> | |
| 139 | + <input type="text" value="" class="form-control" name="i3GEOuploadColunaGid" required > | |
| 140 | + </div> | |
| 141 | + </div> | |
| 142 | + <div class="form-group form-group-lg"> | |
| 143 | + <label class="col-md-5 control-label" for="i3GEOuploadAliasConexao">{{{comboAliasConexao}}}</label> | |
| 144 | + <div class="col-md-7"> | |
| 145 | + <?php echo $comboAliasConexao; ?> | |
| 146 | + </div> | |
| 147 | + </div> | |
| 148 | + <div class="form-group form-group-lg"> | |
| 149 | + <label class="col-md-5 control-label" style="margin-top: 0px;" for="i3GEOuploadApenasScript">{{{apenasScript}}}</label> | |
| 150 | + <div class="col-md-7"> | |
| 151 | + <div class=" checkbox"> | |
| 152 | + <label> <input title="{{{apenasScript}}}" name="i3GEOuploadApenasScript" type="checkbox"> | |
| 153 | + </label> | |
| 154 | + </div> | |
| 155 | + </div> | |
| 156 | + </div> | |
| 157 | + <div class="form-group form-group-lg"> | |
| 158 | + <label class="col-md-5 control-label" style="margin-top: 0px;" for="i3GEOuploadCriaMapfile">{{{criaMapfile}}}</label> | |
| 159 | + <div class="col-md-7"> | |
| 160 | + <div class=" checkbox"> | |
| 161 | + <label> <input title="{{{criaMapfile}}}" name="i3GEOuploadCriaMapfile" type="checkbox"> | |
| 162 | + </label> | |
| 163 | + </div> | |
| 164 | + </div> | |
| 165 | + </div> | |
| 166 | + <div class="col-md-12"> | |
| 167 | + <div class="pull-right"> | |
| 168 | + <button type="submit" class="btn btn-primary" role="button" style="color: #008579;">{{envia}}</button> | |
| 169 | + </div> | |
| 170 | + </div> | |
| 171 | + </div> | |
| 172 | + </div> | |
| 173 | + </form> | |
| 174 | + </div> | |
| 175 | + <div id="modalUpload" class="modal fade" tabindex="-1"> | |
| 176 | + <div class="modal-dialog modal-lg"> | |
| 177 | + <div class="modal-content"> | |
| 178 | + <div class="modal-header"> | |
| 179 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
| 180 | + <span aria-hidden="true">×</span> | |
| 181 | + </button> | |
| 182 | + </div> | |
| 183 | + <div class="modal-content"> | |
| 184 | + <div class="modal-body modal-lg"> | |
| 185 | + <iframe name=i3GEOuploadiframe style="text-align: left; border: 0px solid gray;" width="100%" height="500px"></iframe> | |
| 186 | + </div> | |
| 187 | + </div> | |
| 188 | + </div> | |
| 189 | + </div> | |
| 190 | + </div> | |
| 191 | + </div> | |
| 192 | +</div> | |
| 193 | +<script id="templateProj" type="x-tmpl-mustache"> | |
| 194 | + <option value="{{{codigo}}}">{{{nome}}}</option> | |
| 195 | +</script> | |
| 196 | +<?php | |
| 197 | +if (empty ( $_SESSION ["i3geoUploadDataWL"] )) { | |
| 198 | + echo "<script>iniciaMenuPrincipal();i3GEOadmin.core.mostraErro('Nenhum esquema cadastrado para armazenar a tabela nas configurações do i3Geo (ms_configura)');</script>"; | |
| 199 | + exit (); | |
| 200 | +} | |
| 201 | +?> | |
| 202 | +<script type="text/javascript" src="index.js"></script> | |
| 203 | +<script type="text/javascript" src="../../dicionario/uploadshp.js"></script> | |
| 204 | +<script type="text/javascript" src="../../js/bdexplorer.js"></script> | |
| 205 | +<script> | |
| 206 | + $(document).ready(function(){ | |
| 207 | + //vem de admin1/index.js | |
| 208 | + iniciaMenuPrincipal(); | |
| 209 | + $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) { | |
| 210 | + event.preventDefault(); | |
| 211 | + event.stopPropagation(); | |
| 212 | + $(this).parent().siblings().removeClass('open'); | |
| 213 | + $(this).parent().toggleClass('open'); | |
| 214 | + }); | |
| 215 | + //traducao | |
| 216 | + var t = $("#titulo"); | |
| 217 | + //complementa dicionario | |
| 218 | + i3GEOadmin.csv2pg.dicionario = $.extend( | |
| 219 | + {}, | |
| 220 | + i3GEOadmin.uploadshp.dicionario, | |
| 221 | + i3GEOadmin.core.dicionario | |
| 222 | + ); | |
| 223 | + | |
| 224 | + i3GEOadmin.core.dicionario = null; | |
| 225 | + | |
| 226 | + i3GEOadmin.csv2pg.dicionario = i3GEO.idioma.objetoIdioma(i3GEOadmin.csv2pg.dicionario); | |
| 227 | + | |
| 228 | + t.html( | |
| 229 | + Mustache.to_html( | |
| 230 | + t.html(), | |
| 231 | + i3GEOadmin.csv2pg.dicionario | |
| 232 | + ) | |
| 233 | + ); | |
| 234 | + $.material.init(); | |
| 235 | + i3GEOadmin.core.loginOn(); | |
| 236 | + $(".hidden").removeClass('hidden'); | |
| 237 | + var t = $("#corpo"); | |
| 238 | + t.html( | |
| 239 | + Mustache.to_html( | |
| 240 | + t.html(), | |
| 241 | + i3GEOadmin.csv2pg.dicionario | |
| 242 | + ) | |
| 243 | + ); | |
| 244 | + }); | |
| 245 | + function listaTabelasUpload(destino){ | |
| 246 | + var esquema = $("form select[name='i3GEOuploadEsquemaDestino']").val(); | |
| 247 | + if(esquema != ""){ | |
| 248 | + i3GEOadmin.bdExplorer.listaTabelasUpload(esquema,destino); | |
| 249 | + } | |
| 250 | + } | |
| 251 | +</script> | |
| 252 | +</body> | |
| 253 | +</html> | |
| 0 | 254 | \ No newline at end of file | ... | ... |
admin1/upload/shp2pg/exec.php
| ... | ... | @@ -130,7 +130,7 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 130 | 130 | $shapefileObj = ms_newShapefileObj($_SESSION ["dir_tmp"] . "/" . $nomePrefixo . ".shp",-1); |
| 131 | 131 | $numshapes = $shapefileObj->numshapes; |
| 132 | 132 | |
| 133 | - echo "<div class='alert alert-info' role='alert'>Numshapes existentes no SHP: " . $numshapes . "</div>"; | |
| 133 | + echo "<div class='alert alert-success' role='alert'>Numshapes existentes no SHP: " . $numshapes . "</div>"; | |
| 134 | 134 | ob_flush ();flush (); sleep ( 2 ); |
| 135 | 135 | |
| 136 | 136 | $mapObj = ms_newMapObjFromString("MAP END"); |
| ... | ... | @@ -148,8 +148,8 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - echo "<div class='alert alert-info' role='alert'>Tipo do SHP: " . $shapefileObj->type . "</div>"; | |
| 152 | - echo "<div class='alert alert-info' role='alert'>Colunas: <p><pre>"; | |
| 151 | + echo "<div class='alert alert-success' role='alert'>Tipo do SHP: " . $shapefileObj->type . "</div>"; | |
| 152 | + echo "<div class='alert alert-success' role='alert'>Colunas: <p><pre>"; | |
| 153 | 153 | print_r( $colunas ); |
| 154 | 154 | echo "</pre></p></div>"; |
| 155 | 155 | |
| ... | ... | @@ -173,7 +173,7 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 173 | 173 | } |
| 174 | 174 | $tipoColuna[$coluna] = $tipo; |
| 175 | 175 | } |
| 176 | - echo "<div class='alert alert-info' role='alert'>Tipos das colunas: <p><pre>"; | |
| 176 | + echo "<div class='alert alert-success' role='alert'>Tipos das colunas: <p><pre>"; | |
| 177 | 177 | print_r( $tipoColuna ); |
| 178 | 178 | echo "</pre></p></div>"; |
| 179 | 179 | |
| ... | ... | @@ -248,7 +248,7 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 248 | 248 | //gera o script para inserir os dados |
| 249 | 249 | $linhas = array(); |
| 250 | 250 | $insert = "INSERT INTO ".$_POST["i3GEOuploadEsquemaDestino"].".".$_POST["i3GEOuploadNomeTabela"]." (".strtolower(\admin\php\funcoesAdmin\removeAcentos(implode(",",$colunas))).",the_geom)"; |
| 251 | - echo "<div class='alert alert-success' role='alert'>Preparando inclusão de dados...</div>"; | |
| 251 | + echo "<div class='alert alert-info' role='alert'>Preparando inclusão de dados...</div>"; | |
| 252 | 252 | ob_flush(); |
| 253 | 253 | flush(); |
| 254 | 254 | sleep(1); |
| ... | ... | @@ -314,9 +314,9 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | if($_POST["i3GEOuploadApenasScript"] == "on"){ |
| 317 | - echo "<div class='alert alert-info' role='alert'>Sql de inserção de dados: <p><pre>"; | |
| 317 | + echo "<div class='alert alert-success' role='alert'>Sql de inserção de dados: <p><pre>"; | |
| 318 | 318 | foreach($linhas as $linha){ |
| 319 | - print_r( $linha )."/n"; | |
| 319 | + echo( $linha )."\n"; | |
| 320 | 320 | } |
| 321 | 321 | echo "</pre></p></div>"; |
| 322 | 322 | |
| ... | ... | @@ -337,9 +337,10 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 337 | 337 | //para testar com acentuacao diferente |
| 338 | 338 | $conexao = $_SESSION["i3geoUploadDataWL"]["postgis"]["conexao"]; |
| 339 | 339 | $bdcon = pg_connect('dbname='.$conexao["dbname"].' user='.$conexao["user"].' password='.$conexao["password"].' host='.$conexao["host"].' port='.$conexao["port"]."options='-c client_encoding=LATIN1'"); |
| 340 | + echo "<div class='alert alert-success' role='alert'>Sql de inserção de dados com erros ou modificados: <p><pre>"; | |
| 341 | + | |
| 340 | 342 | foreach($linhas as $linha){ |
| 341 | 343 | try { |
| 342 | - echo "<div class='alert alert-info' role='alert'>Sql de inserção de dados com erros ou modificados: <p><pre>"; | |
| 343 | 344 | $res = $dbh->query($linha); |
| 344 | 345 | if($res == false){ |
| 345 | 346 | $res = pg_query($bdcon,$linha); |
| ... | ... | @@ -357,11 +358,12 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 357 | 358 | } |
| 358 | 359 | } |
| 359 | 360 | } |
| 360 | - echo "</pre></p></div>"; | |
| 361 | 361 | } catch (PDOException $e) { |
| 362 | 362 | echo "<div class='alert alert-danger' role='alert'>Não foi possível executar os SQLs<p><pre>"; |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | + echo "</pre></p></div>"; | |
| 366 | + | |
| 365 | 367 | $sql = "select * from ".$_POST["i3GEOuploadEsquemaDestino"].".".$_POST["i3GEOuploadNomeTabela"]; |
| 366 | 368 | $q = $dbh->query($sql,PDO::FETCH_ASSOC); |
| 367 | 369 | $r = $q->fetchAll(); |
| ... | ... | @@ -386,7 +388,7 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 386 | 388 | if(!in_array($_POST["i3GEOuploadAliasConexao"],array_keys($_SESSION ["postgis_mapa"]))){ |
| 387 | 389 | echo "<div class='alert alert-danger' role='alert'>Alias para a conexão com o banco não definida</div>"; |
| 388 | 390 | } else { |
| 389 | - echo "<div class='alert alert-success' role='alert'>Criando mapfile...</div>"; | |
| 391 | + echo "<div class='alert alert-info' role='alert'>Criando mapfile...</div>"; | |
| 390 | 392 | ob_flush ();flush (); sleep ( 2 ); |
| 391 | 393 | |
| 392 | 394 | if ($shapefileObj->type == 1) { |
| ... | ... | @@ -408,13 +410,14 @@ if (isset ( $_FILES ['i3GEOuploadshp'] ['name'] )) { |
| 408 | 410 | $layer->setconnectiontype(6); |
| 409 | 411 | $layer->set ( "type", $tipoLayer ); |
| 410 | 412 | $mapa->save ( $_SESSION ["locaplic"] . "/temas/" . $_POST["i3GEOuploadNomeTabela"] . ".map" ); |
| 413 | + \admin\php\funcoesAdmin\removeCabecalhoMapfile ( $_SESSION ["locaplic"] . "/temas/" . $_POST["i3GEOuploadNomeTabela"] . ".map" ); | |
| 411 | 414 | echo "<div class='alert alert-success' role='alert'>Mapfile " . $_POST["i3GEOuploadNomeTabela"] ." criado!!!</div>"; |
| 412 | 415 | } else { |
| 413 | 416 | echo "<div class='alert alert-danger' role='alert'>Mapfile não pode ser criado criado!!!</div>"; |
| 414 | 417 | } |
| 415 | 418 | } |
| 416 | 419 | } |
| 417 | - echo "<div class='alert alert-success' role='alert'>Pode fechar essa janela.</div>"; | |
| 420 | + echo "<div class='alert alert-info' role='alert'>Pode fechar essa janela.</div>"; | |
| 418 | 421 | } else { |
| 419 | 422 | echo "<div class='alert alert-danger' role='alert'>Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</div>"; |
| 420 | 423 | } | ... | ... |
admin1/upload/shp2pg/index.php
| ... | ... | @@ -3,9 +3,12 @@ define ( "ONDEI3GEO", "../../.." ); |
| 3 | 3 | include ("exec.php"); |
| 4 | 4 | include "../../head.php"; |
| 5 | 5 | // monta o combo com a lista de pastas para armazenar os arquivos |
| 6 | + | |
| 6 | 7 | $comboEsquemas = '<select name="i3GEOuploadEsquemaDestino" class="form-control" required ><option value=""></option>'; |
| 7 | -foreach ( $_SESSION ["i3geoUploadDataWL"]["postgis"]["esquemas"] as $c ) { | |
| 8 | - $comboEsquemas .= "<option value='$c'>$c</option>"; | |
| 8 | +if (!empty ( $_SESSION ["i3geoUploadDataWL"] )) { | |
| 9 | + foreach ( $_SESSION ["i3geoUploadDataWL"]["postgis"]["esquemas"] as $c ) { | |
| 10 | + $comboEsquemas .= "<option value='$c'>$c</option>"; | |
| 11 | + } | |
| 9 | 12 | } |
| 10 | 13 | $comboEsquemas .= "</select>"; |
| 11 | 14 | // monta o combo com a lista de alias para conexao com o banco de dados |
| ... | ... | @@ -194,7 +197,7 @@ $comboAliasConexao .= "</select>"; |
| 194 | 197 | <option value="{{{codigo}}}">{{{nome}}}</option> |
| 195 | 198 | </script> |
| 196 | 199 | <?php |
| 197 | -if (empty ( $_SESSION ["i3geoEsquemasWL"] )) { | |
| 200 | +if (empty ( $_SESSION ["i3geoUploadDataWL"] )) { | |
| 198 | 201 | echo "<script>iniciaMenuPrincipal();i3GEOadmin.core.mostraErro('Nenhum esquema cadastrado para armazenar a tabela nas configurações do i3Geo (ms_configura)');</script>"; |
| 199 | 202 | exit (); |
| 200 | 203 | } | ... | ... |
ms_configura.php
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +MAP | |
| 2 | +SYMBOLSET ../symbols/simbolosv6.sym | |
| 3 | +FONTSET "../symbols/fontes.txt" | |
| 4 | +LAYER | |
| 5 | + NAME "testecsv" | |
| 6 | + TEMPLATE "none.htm" | |
| 7 | + TYPE line | |
| 8 | + DATA "" | |
| 9 | + CONNECTION "" | |
| 10 | + STATUS DEFAULT | |
| 11 | + METADATA | |
| 12 | + TEMA "testecsv" | |
| 13 | + CLASSE "SIM" | |
| 14 | + permiteogc "SIM" | |
| 15 | + permitedownload "SIM" | |
| 16 | + permitekml "SIM" | |
| 17 | + permitekmz "SIM" | |
| 18 | + END | |
| 19 | + CLASS | |
| 20 | + NAME "" | |
| 21 | + STYLE | |
| 22 | + COLOR 0 0 0 | |
| 23 | + SIZE 12 | |
| 24 | + END | |
| 25 | + END | |
| 26 | +END | |
| 27 | +END | ... | ... |