Commit 959845e811fbbef6701490533a5f0a71b5f67e69

Authored by Edmar Moretti
1 parent f515c49c

--no commit message

admin/php/metaestat_uploadcsv_submit.php
@@ -65,6 +65,8 @@ if (ob_get_level() == 0) ob_start(); @@ -65,6 +65,8 @@ if (ob_get_level() == 0) ob_start();
65 $colunas = explode(",",$buffer); 65 $colunas = explode(",",$buffer);
66 $separador = ","; 66 $separador = ",";
67 } 67 }
  68 + echo "<p class='paragrafo' >Separador de colunas identificado: <b>".$separador."</b></p>";
  69 + echo "<p class='paragrafo' >Total de colunas: <b>".count($colunas)."</b></p>";
68 //var_dump($colunas); 70 //var_dump($colunas);
69 fclose ($handle); 71 fclose ($handle);
70 //le o csv em um array 72 //le o csv em um array
@@ -79,14 +81,22 @@ if (ob_get_level() == 0) ob_start(); @@ -79,14 +81,22 @@ if (ob_get_level() == 0) ob_start();
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 = 500;
90 if(count($linhas) < $testar){ 100 if(count($linhas) < $testar){
91 $testar = count($linhas); 101 $testar = count($linhas);
92 } 102 }
@@ -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);
@@ -152,7 +164,7 @@ if (ob_get_level() == 0) ob_start(); @@ -152,7 +164,7 @@ if (ob_get_level() == 0) ob_start();
152 if(!empty($_POST["comentarioCsv"])){ 164 if(!empty($_POST["comentarioCsv"])){
153 $enc = mb_detect_encoding($texto); 165 $enc = mb_detect_encoding($texto);
154 $_POST["comentarioCsv"] = mb_convert_encoding($_POST["comentarioCsv"],$encodingdb,$enc); 166 $_POST["comentarioCsv"] = mb_convert_encoding($_POST["comentarioCsv"],$encodingdb,$enc);
155 - $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".$_POST["comentarioCsv"]."'"; 167 + $sqltabela[] = "COMMENT ON TABLE ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." IS '".addcslashes($_POST["comentarioCsv"])."'";
156 } 168 }
157 echo "<br>Sql tabela: <pre>"; 169 echo "<br>Sql tabela: <pre>";
158 var_dump($sqltabela); 170 var_dump($sqltabela);
@@ -183,20 +195,19 @@ if (ob_get_level() == 0) ob_start(); @@ -183,20 +195,19 @@ if (ob_get_level() == 0) ob_start();
183 $nlinhas = count($linhas); 195 $nlinhas = count($linhas);
184 $valorX = 0; 196 $valorX = 0;
185 $valorY = 0; 197 $valorY = 0;
  198 + $escapar = "',<,>,%,#,@,(,)";
186 for ($i=0; $i<$nlinhas;$i++){ 199 for ($i=0; $i<$nlinhas;$i++){
187 $s = $linhas[$i]; 200 $s = $linhas[$i];
  201 + $enc = mb_detect_encoding($s);
  202 + if($enc != ""){
  203 + $s = mb_convert_encoding($s,$encodingdb,$enc);
  204 + }
188 $vs = array(); 205 $vs = array();
189 for ($j=0; $j<$ncolunas;$j++){ 206 for ($j=0; $j<$ncolunas;$j++){
190 if($tipoColuna[$colunas[$j]] == "varchar"){ 207 if($tipoColuna[$colunas[$j]] == "varchar"){
191 $texto = $s[$j]; 208 $texto = $s[$j];
192 $texto = str_replace("'","",$texto); 209 $texto = str_replace("'","",$texto);
193 - $enc = mb_detect_encoding($texto);  
194 - if(enc != ""){  
195 - $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'";  
196 - }  
197 - else{  
198 - $texto = "'".$texto."'";  
199 - } 210 + $texto = "'".addcslashes($texto,$escapar)."'";
200 if($texto == "''"){ 211 if($texto == "''"){
201 $texto = 'null'; 212 $texto = 'null';
202 } 213 }
admin/php/metaestat_uploadshp_submit.php
@@ -92,11 +92,9 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){ @@ -92,11 +92,9 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
92 $sqinsert = array(); 92 $sqinsert = array();
93 //verifica o tipo de coluna 93 //verifica o tipo de coluna
94 $tipoColuna = array(); 94 $tipoColuna = array();
95 - if($numshapes < 10){  
96 - $testar = $numshapes;  
97 - }  
98 - else{  
99 - $testar = 10; 95 + $testar = $numshapes;
  96 + if($numshapes > 500){
  97 + $testar = 500;
100 } 98 }
101 foreach($colunas as $coluna){ 99 foreach($colunas as $coluna){
102 $tipo = "numeric"; 100 $tipo = "numeric";
@@ -188,6 +186,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){ @@ -188,6 +186,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
188 flush(); 186 flush();
189 sleep(1); 187 sleep(1);
190 $srid = 4326; 188 $srid = 4326;
  189 + $escapar = "'";
191 for ($i=0; $i<$numshapes;$i++){ 190 for ($i=0; $i<$numshapes;$i++){
192 $s = $layer->getShape(new resultObj($i)); 191 $s = $layer->getShape(new resultObj($i));
193 $vs = array(); 192 $vs = array();
@@ -195,9 +194,10 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){ @@ -195,9 +194,10 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
195 if($tipoColuna[$coluna] == "varchar"){ 194 if($tipoColuna[$coluna] == "varchar"){
196 $texto = $s->getValue($layer,$coluna); 195 $texto = $s->getValue($layer,$coluna);
197 //echo $i." - ".mb_detect_encoding($texto)."<br>"; 196 //echo $i." - ".mb_detect_encoding($texto)."<br>";
198 - $texto = str_replace("'","",$texto); 197 + //$texto = str_replace("'","",$texto);
199 $enc = mb_detect_encoding($texto); 198 $enc = mb_detect_encoding($texto);
200 - if(enc != ""){ 199 + $texto = addcslashes($texto,$escapar);
  200 + if($enc != ""){
201 $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'"; 201 $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'";
202 } 202 }
203 else{ 203 else{