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 65 $colunas = explode(",",$buffer);
66 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 70 //var_dump($colunas);
69 71 fclose ($handle);
70 72 //le o csv em um array
... ... @@ -79,14 +81,22 @@ if (ob_get_level() == 0) ob_start();
79 81 $buffer = str_replace("'",'',$buffer);
80 82 $buffer = str_replace("\n",'',$buffer);
81 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 97 fclose ($handle);
88 98 //decobre o tipo de coluna
89   - $testar = 10;
  99 + $testar = 500;
90 100 if(count($linhas) < $testar){
91 101 $testar = count($linhas);
92 102 }
... ... @@ -126,6 +136,8 @@ if (ob_get_level() == 0) ob_start();
126 136 if($encodingdb == "LATIN1"){
127 137 $encodingdb = "ISO-8859-1";
128 138 }
  139 + echo "<p class='paragrafo' >Codifica&ccedil;&atilde;o do banco: <b>".$encodingdb."</b></p>";
  140 +
129 141 //gera o script para criar a tabela e verifica se ja existe
130 142 $sql = "SELECT table_name FROM information_schema.tables where table_schema = '".$_POST["i3GEOuploadcsvesquema"]."' AND table_name = '".$_POST["tabelaDestinocsv"]."'";
131 143 $res = $dbh->query($sql,PDO::FETCH_ASSOC);
... ... @@ -152,7 +164,7 @@ if (ob_get_level() == 0) ob_start();
152 164 if(!empty($_POST["comentarioCsv"])){
153 165 $enc = mb_detect_encoding($texto);
154 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 169 echo "<br>Sql tabela: <pre>";
158 170 var_dump($sqltabela);
... ... @@ -183,20 +195,19 @@ if (ob_get_level() == 0) ob_start();
183 195 $nlinhas = count($linhas);
184 196 $valorX = 0;
185 197 $valorY = 0;
  198 + $escapar = "',<,>,%,#,@,(,)";
186 199 for ($i=0; $i<$nlinhas;$i++){
187 200 $s = $linhas[$i];
  201 + $enc = mb_detect_encoding($s);
  202 + if($enc != ""){
  203 + $s = mb_convert_encoding($s,$encodingdb,$enc);
  204 + }
188 205 $vs = array();
189 206 for ($j=0; $j<$ncolunas;$j++){
190 207 if($tipoColuna[$colunas[$j]] == "varchar"){
191 208 $texto = $s[$j];
192 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 211 if($texto == "''"){
201 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 92 $sqinsert = array();
93 93 //verifica o tipo de coluna
94 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 99 foreach($colunas as $coluna){
102 100 $tipo = "numeric";
... ... @@ -188,6 +186,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
188 186 flush();
189 187 sleep(1);
190 188 $srid = 4326;
  189 + $escapar = "'";
191 190 for ($i=0; $i<$numshapes;$i++){
192 191 $s = $layer->getShape(new resultObj($i));
193 192 $vs = array();
... ... @@ -195,9 +194,10 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
195 194 if($tipoColuna[$coluna] == "varchar"){
196 195 $texto = $s->getValue($layer,$coluna);
197 196 //echo $i." - ".mb_detect_encoding($texto)."<br>";
198   - $texto = str_replace("'","",$texto);
  197 + //$texto = str_replace("'","",$texto);
199 198 $enc = mb_detect_encoding($texto);
200   - if(enc != ""){
  199 + $texto = addcslashes($texto,$escapar);
  200 + if($enc != ""){
201 201 $texto = "'".mb_convert_encoding($texto,$encodingdb,$enc)."'";
202 202 }
203 203 else{
... ...