Commit a9f1c1c0d0803361fcee84d27966e4665808f4ab

Authored by Edmar Moretti
1 parent fd2e6af1
Exists in master

correcao nas ferramentas de upload

admin/php/estat_mapa_upload.php
@@ -8,6 +8,7 @@ error_reporting(0); @@ -8,6 +8,7 @@ error_reporting(0);
8 ?> 8 ?>
9 <html> 9 <html>
10 <head> 10 <head>
  11 +<link rel="stylesheet" type="text/css" href="../../css/input.css" />
11 <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> 12 <link rel="stylesheet" type="text/css" href="../../css/geral.css" />
12 <title></title> 13 <title></title>
13 </head> 14 </head>
@@ -27,7 +28,7 @@ if (isset($_FILES[&#39;uploadimagem&#39;][&#39;name&#39;])){ @@ -27,7 +28,7 @@ if (isset($_FILES[&#39;uploadimagem&#39;][&#39;name&#39;])){
27 //sobe arquivo 28 //sobe arquivo
28 $Arquivo = $_FILES['uploadimagem']['tmp_name']; 29 $Arquivo = $_FILES['uploadimagem']['tmp_name'];
29 //echo $Arquivo; 30 //echo $Arquivo;
30 - $status = move_uploaded_file($Arquivo,$arq); 31 + $status = move_uploaded_file($Arquivo,str_replace(".png","",$arq).".png");
31 if($status != 1) 32 if($status != 1)
32 {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;} 33 {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;}
33 if($status == 1){ 34 if($status == 1){
admin/php/metaestat_mapa_uploadimagem.php
@@ -12,6 +12,7 @@ error_reporting(0); @@ -12,6 +12,7 @@ error_reporting(0);
12 ?> 12 ?>
13 <html> 13 <html>
14 <head> 14 <head>
  15 +<link rel="stylesheet" type="text/css" href="../../css/input.css" />
15 <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> 16 <link rel="stylesheet" type="text/css" href="../../css/geral.css" />
16 <title></title> 17 <title></title>
17 </head> 18 </head>
@@ -31,12 +32,11 @@ if (isset($_FILES[&#39;uploadimagem&#39;][&#39;name&#39;])){ @@ -31,12 +32,11 @@ if (isset($_FILES[&#39;uploadimagem&#39;][&#39;name&#39;])){
31 //sobe arquivo 32 //sobe arquivo
32 $Arquivo = $_FILES['uploadimagem']['tmp_name']; 33 $Arquivo = $_FILES['uploadimagem']['tmp_name'];
33 //echo $Arquivo; 34 //echo $Arquivo;
34 - $status = move_uploaded_file($Arquivo,$arq); 35 + $status = move_uploaded_file($Arquivo,str_replace(".png","",$arq).".png");
35 if($status != 1) 36 if($status != 1)
36 {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;} 37 {echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo. Verifique as permissoes de escrita";exit;}
37 if($status == 1){ 38 if($status == 1){
38 echo "<p class='paragrafo' >Arquivo enviado.</p>"; 39 echo "<p class='paragrafo' >Arquivo enviado.</p>";
39 - chmod($arq,0777);  
40 } 40 }
41 else{ 41 else{
42 echo "<p class='paragrafo' >Erro ao enviar o arquivo.</p>"; 42 echo "<p class='paragrafo' >Erro ao enviar o arquivo.</p>";
admin/php/metaestat_uploadcsv_submit.php
@@ -15,6 +15,7 @@ if (ob_get_level() == 0) ob_start(); @@ -15,6 +15,7 @@ if (ob_get_level() == 0) ob_start();
15 <html> 15 <html>
16 <head> 16 <head>
17 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 17 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  18 +<link rel="stylesheet" type="text/css" href="../../css/input.css" />
18 <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> 19 <link rel="stylesheet" type="text/css" href="../../css/geral.css" />
19 <title></title> 20 <title></title>
20 </head> 21 </head>
@@ -37,7 +38,7 @@ if (ob_get_level() == 0) ob_start(); @@ -37,7 +38,7 @@ if (ob_get_level() == 0) ob_start();
37 sleep(1); 38 sleep(1);
38 $arqcsv = $_FILES['i3GEOuploadcsv']['tmp_name']; 39 $arqcsv = $_FILES['i3GEOuploadcsv']['tmp_name'];
39 $nomePrefixo = str_replace(" ","_",removeAcentos($_FILES['i3GEOuploadcsv']['name'])); 40 $nomePrefixo = str_replace(" ","_",removeAcentos($_FILES['i3GEOuploadcsv']['name']));
40 - $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)); 41 + $nomePrefixo = $nomePrefixo."_".(nomeRandomico(4)).".csv";
41 42
42 $Arquivo = $_FILES['i3GEOuploadcsv']['tmp_name']; 43 $Arquivo = $_FILES['i3GEOuploadcsv']['tmp_name'];
43 $status = move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo); 44 $status = move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo);
@@ -65,7 +66,8 @@ if (ob_get_level() == 0) ob_start(); @@ -65,7 +66,8 @@ if (ob_get_level() == 0) ob_start();
65 $colunas = explode(",",$buffer); 66 $colunas = explode(",",$buffer);
66 $separador = ","; 67 $separador = ",";
67 } 68 }
68 - //var_dump($colunas); 69 + echo "<p class='paragrafo' >Separador de colunas identificado: <b>".$separador."</b></p>";
  70 + echo "<p class='paragrafo' >Total de colunas: <b>".count($colunas)."</b></p>";
69 fclose ($handle); 71 fclose ($handle);
70 //le o csv em um array 72 //le o csv em um array
71 $handle = fopen ($arqcsv, "r"); 73 $handle = fopen ($arqcsv, "r");
@@ -75,18 +77,26 @@ if (ob_get_level() == 0) ob_start(); @@ -75,18 +77,26 @@ if (ob_get_level() == 0) ob_start();
75 while (!feof($handle)) { 77 while (!feof($handle)) {
76 $buffer = fgets($handle); 78 $buffer = fgets($handle);
77 if($buffer != $cabecalho){ 79 if($buffer != $cabecalho){
78 - $buffer = str_replace('"','',$buffer); 80 + //$buffer = str_replace('"','',$buffer);
79 $buffer = str_replace("'",'',$buffer); 81 $buffer = str_replace("'",'',$buffer);
80 $buffer = str_replace("\n",'',$buffer); 82 $buffer = str_replace("\n",'',$buffer);
81 $buffer = str_replace("\r",'',$buffer); 83 $buffer = str_replace("\r",'',$buffer);
82 - $temp = explode($separador,$buffer);  
83 - if(count($temp) == $ncolunas)  
84 - $linhas[] = $temp; 84 + if($buffer != ""){
  85 + $temp = explode($separador,$buffer);
  86 + if(count($temp) == $ncolunas){
  87 + $linhas[] = $temp;
  88 + }
  89 + else{
  90 + echo "<p class='paragrafo' >A linha abaixo apresentou um erro - n&uacute;mero de colunas n&atilde;o bate com o cabe&ccedil;alho</p>";
  91 + var_dump($temp);
  92 + exit;
  93 + }
  94 + }
85 } 95 }
86 } 96 }
87 fclose ($handle); 97 fclose ($handle);
88 //decobre o tipo de coluna 98 //decobre o tipo de coluna
89 - $testar = 10; 99 + $testar = 50;
90 if(count($linhas) < $testar){ 100 if(count($linhas) < $testar){
91 $testar = count($linhas); 101 $testar = count($linhas);
92 } 102 }
@@ -112,7 +122,7 @@ if (ob_get_level() == 0) ob_start(); @@ -112,7 +122,7 @@ if (ob_get_level() == 0) ob_start();
112 try { 122 try {
113 $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]); 123 $dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]);
114 } catch (PDOException $e) { 124 } catch (PDOException $e) {
115 - echo 'Connection failed: ' . $e->getMessage(); 125 + echo 'Connection failed: ' . " ";
116 } 126 }
117 //encoding do banco de dados 127 //encoding do banco de dados
118 $sql = "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = '".$conexao["bancodedados"]."'"; 128 $sql = "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = '".$conexao["bancodedados"]."'";
@@ -126,6 +136,8 @@ if (ob_get_level() == 0) ob_start(); @@ -126,6 +136,8 @@ if (ob_get_level() == 0) ob_start();
126 if($encodingdb == "LATIN1"){ 136 if($encodingdb == "LATIN1"){
127 $encodingdb = "ISO-8859-1"; 137 $encodingdb = "ISO-8859-1";
128 } 138 }
  139 + echo "<p class='paragrafo' >Codifica&ccedil;&atilde;o do banco: <b>".$encodingdb."</b></p>";
  140 +
129 //gera o script para criar a tabela e verifica se ja existe 141 //gera o script para criar a tabela e verifica se ja existe
130 $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadcsvesquema"]."' AND table_name = '".$_POST["tabelaDestinocsv"]."'"; 142 $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadcsvesquema"]."' AND table_name = '".$_POST["tabelaDestinocsv"]."'";
131 $res = $dbh->query($sql,PDO::FETCH_ASSOC); 143 $res = $dbh->query($sql,PDO::FETCH_ASSOC);
@@ -149,6 +161,11 @@ if (ob_get_level() == 0) ob_start(); @@ -149,6 +161,11 @@ if (ob_get_level() == 0) ob_start();
149 $sql .= implode(",",$temp).") WITH(OIDS=FALSE)"; 161 $sql .= implode(",",$temp).") WITH(OIDS=FALSE)";
150 $sqltabela[] = $sql; 162 $sqltabela[] = $sql;
151 $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." OWNER TO ".$conexao["usuario"]; 163 $sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." OWNER TO ".$conexao["usuario"];
  164 + if(!empty($_POST["comentarioCsv"])){
  165 + $enc = mb_detect_encoding($texto);
  166 + $_POST["comentarioCsv"] = mb_convert_encoding($_POST["comentarioCsv"],$encodingdb,$enc);
  167 + $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".addcslashes($_POST["comentarioCsv"])."'";
  168 + }
152 echo "<br>Sql tabela: <pre>"; 169 echo "<br>Sql tabela: <pre>";
153 var_dump($sqltabela); 170 var_dump($sqltabela);
154 echo "</pre>"; 171 echo "</pre>";
@@ -178,29 +195,39 @@ if (ob_get_level() == 0) ob_start(); @@ -178,29 +195,39 @@ if (ob_get_level() == 0) ob_start();
178 $nlinhas = count($linhas); 195 $nlinhas = count($linhas);
179 $valorX = 0; 196 $valorX = 0;
180 $valorY = 0; 197 $valorY = 0;
  198 + $escapar = "',<,>,%,#,@,(,)";
181 for ($i=0; $i<$nlinhas;$i++){ 199 for ($i=0; $i<$nlinhas;$i++){
182 $s = $linhas[$i]; 200 $s = $linhas[$i];
  201 + $s = str_replace('"','',$s);
  202 + $enc = mb_detect_encoding($s);
  203 + if($enc != ""){
  204 + $s = mb_convert_encoding($s,$encodingdb,$enc);
  205 + }
183 $vs = array(); 206 $vs = array();
184 for ($j=0; $j<$ncolunas;$j++){ 207 for ($j=0; $j<$ncolunas;$j++){
185 - if($tipoColuna[$colunas[$j]] == "varchar"){ 208 + $escape = "";
  209 + if($tipoColuna[$coluna] == "varchar"){
186 $texto = $s[$j]; 210 $texto = $s[$j];
187 - $texto = str_replace("'","",$texto);  
188 $enc = mb_detect_encoding($texto); 211 $enc = mb_detect_encoding($texto);
189 - if(enc != ""){  
190 - $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'"; 212 + $textosl = addcslashes($texto,$escapar);
  213 + if($textosl != $texto){
  214 + $escape = "E";
  215 + }
  216 + if($enc != "" && $enc != $encodingdb){
  217 + $textosl = "$escape'".mb_convert_encoding($textosl,$encodingdb,$enc)."'";
191 } 218 }
192 else{ 219 else{
193 - $texto = "'".$texto."'"; 220 + $textosl = "$escape'".$textosl."'";
194 } 221 }
195 - if($texto == "''"){  
196 - $texto = 'null'; 222 + if($textosl == "''"){
  223 + $textosl = 'null';
197 } 224 }
198 - $vs[] = $texto; 225 + $vs[] = $textosl;
199 } 226 }
200 else{ 227 else{
201 $valor = $s[$j]; 228 $valor = $s[$j];
202 - if($valor == ""){  
203 - $valor = "nulo"; 229 + if($valor == "" || (empty($valor) && $valor != 0)){
  230 + $valor = 'nulo';
204 } 231 }
205 $vs[] = $valor; 232 $vs[] = $valor;
206 } 233 }
@@ -234,23 +261,42 @@ if (ob_get_level() == 0) ob_start(); @@ -234,23 +261,42 @@ if (ob_get_level() == 0) ob_start();
234 try { 261 try {
235 $dbh->query($linha); 262 $dbh->query($linha);
236 } catch (PDOException $e) { 263 } catch (PDOException $e) {
237 - echo 'Erro: ' . $e->getMessage(); 264 + echo 'Erro: ' . " ";
238 } 265 }
239 } 266 }
  267 + $bdcon = pg_connect('dbname='.$conexao["bancodedados"].' user='.$conexao["usuario"].' password='.$conexao["senha"].' host='.$conexao["host"].' port='.$conexao["porta"]."options='-c client_encoding=LATIN1'");
  268 +
240 foreach($linhasql as $linha){ 269 foreach($linhasql as $linha){
241 try { 270 try {
242 $res = $dbh->query($linha); 271 $res = $dbh->query($linha);
243 if($res == false){ 272 if($res == false){
244 - echo "<br><br><span style=color:red >Erro em: </span>".$linha; 273 + $res = pg_query($bdcon,$linha);
  274 + if($res == false){
  275 + $linha = remove_accents($linha);
  276 + $res = $dbh->query($linha);
  277 + if($res == false){
  278 + $res = pg_query($bdcon,$linha);
  279 + if($res == false){
  280 + echo "<br><br><span style=color:red >Erro em: </span>".$linha;
  281 + }
  282 + }
  283 + else{
  284 + echo "<br><br><span style=color:red >Linha com acentos removidos: </span>".$linha;
  285 + }
  286 + }
245 } 287 }
246 } catch (PDOException $e) { 288 } catch (PDOException $e) {
247 - echo 'Erro: ' . $e->getMessage(); 289 + echo 'Erro: ' . " ";
248 } 290 }
249 } 291 }
250 - echo "<br>Registros existentes no CSV: ". $nlinhas;  
251 $sql = "select * from ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]; 292 $sql = "select * from ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"];
252 $q = $dbh->query($sql,PDO::FETCH_ASSOC); 293 $q = $dbh->query($sql,PDO::FETCH_ASSOC);
253 $r = $q->fetchAll(); 294 $r = $q->fetchAll();
  295 + if($nlinhas != count($r)){
  296 + echo "<span style='color:red'>";
  297 + }
  298 + echo "<br>Registros existentes no CSV: ". $nlinhas;
  299 +
254 echo "<br>Registros na tabela final: ". count($r); 300 echo "<br>Registros na tabela final: ". count($r);
255 echo "<b><br>Feito!!!<br>Fa&ccedil;a o reload da p&aacute;gina"; 301 echo "<b><br>Feito!!!<br>Fa&ccedil;a o reload da p&aacute;gina";
256 } 302 }
@@ -258,8 +304,8 @@ if (ob_get_level() == 0) ob_start(); @@ -258,8 +304,8 @@ if (ob_get_level() == 0) ob_start();
258 echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>"; 304 echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>";
259 } 305 }
260 306
261 - ?>  
262 - <script>window.scrollTo(0,10000);</script> 307 + ?>
  308 + <script>window.scrollTo(0,10000);</script>
263 309
264 </body> 310 </body>
265 </html> 311 </html>
admin/php/metaestat_uploaddados_submit.php
@@ -7,7 +7,7 @@ if (isset($_FILES[&#39;i3GEOuploadArquivo&#39;][&#39;name&#39;])) @@ -7,7 +7,7 @@ if (isset($_FILES[&#39;i3GEOuploadArquivo&#39;][&#39;name&#39;]))
7 { 7 {
8 require_once (dirname(__FILE__)."/../../ms_configura.php"); 8 require_once (dirname(__FILE__)."/../../ms_configura.php");
9 $Arquivoup = $_FILES['i3GEOuploadArquivo']['tmp_name']; 9 $Arquivoup = $_FILES['i3GEOuploadArquivo']['tmp_name'];
10 - $nomearquivoserv = $dir_tmp."/upload".basename($Arquivoup); 10 + $nomearquivoserv = $dir_tmp."/upload".basename($Arquivoup).".csv";
11 //echo $nomearquivoserv; 11 //echo $nomearquivoserv;
12 if(file_exists($nomearquivoserv)){ 12 if(file_exists($nomearquivoserv)){
13 unlink($nomearquivoserv); 13 unlink($nomearquivoserv);
admin/php/uploadgvp.php
@@ -9,6 +9,7 @@ if (ob_get_level() == 0) ob_start(); @@ -9,6 +9,7 @@ if (ob_get_level() == 0) ob_start();
9 ?> 9 ?>
10 <html> 10 <html>
11 <head> 11 <head>
  12 +<link rel="stylesheet" type="text/css" href="../../css/input.css" />
12 <link rel="stylesheet" type="text/css" href="../../css/geral.css" /> 13 <link rel="stylesheet" type="text/css" href="../../css/geral.css" />
13 <title></title> 14 <title></title>
14 </head> 15 </head>
@@ -21,9 +22,10 @@ if (isset($_FILES[&#39;i3GEOuploadgvp&#39;][&#39;name&#39;])){ @@ -21,9 +22,10 @@ if (isset($_FILES[&#39;i3GEOuploadgvp&#39;][&#39;name&#39;])){
21 ob_flush(); 22 ob_flush();
22 flush(); 23 flush();
23 sleep(1); 24 sleep(1);
24 - $arq = $locaplic."/temas/".$_FILES['i3GEOuploadgvp']['name'];  
25 - //verifica nomes  
26 verificaNome($_FILES['i3GEOuploadgvp']['name']); 25 verificaNome($_FILES['i3GEOuploadgvp']['name']);
  26 + $ArquivoDest = $_FILES['i3GEOuploadgvp']['name'];
  27 + $ArquivoDest = str_replace(".gvp","",$ArquivoDest).".gvp";
  28 + $arq = $locaplic."/temas/".$ArquivoDest;
27 if(file_exists($arq)){ 29 if(file_exists($arq)){
28 unlink($arq); 30 unlink($arq);
29 } 31 }