Commit a4f4dac915ee9d9c2b8017a2d3df5fe8e7898974
1 parent
291a8719
Exists in
master
and in
6 other branches
i3geo/i3geo#85 Correção na função de substituição de chaves da ferramenta parame…
…trossql. Ocorriam erros quando campos de tipos diferentes não seguiam a mesma ordem das chaves
Showing
1 changed file
with
29 additions
and
12 deletions
Show diff stats
ferramentas/parametrossql/exec.php
@@ -57,7 +57,24 @@ switch (strtoupper($funcao)) | @@ -57,7 +57,24 @@ switch (strtoupper($funcao)) | ||
57 | */ | 57 | */ |
58 | case "APLICAR": | 58 | case "APLICAR": |
59 | $valores = $_GET["valores"]; | 59 | $valores = $_GET["valores"]; |
60 | + $valores = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--","drop",";"),"",$valores); | ||
61 | + $valores = explode(",",$valores); | ||
60 | $titulos = $_GET["titulos"]; | 62 | $titulos = $_GET["titulos"]; |
63 | + $titulos = explode(",",$titulos); | ||
64 | + $chaves = $_GET["chaves"]; | ||
65 | + $chaves = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--","drop",";"),"",$chaves); | ||
66 | + $chaves = explode(",",$chaves); | ||
67 | + if(count($chaves) <> count($valores)){ | ||
68 | + echo "erro"; | ||
69 | + exit; | ||
70 | + } | ||
71 | + //cria um array cuja key e a chave | ||
72 | + $dados = array(); | ||
73 | + $n = count($chaves); | ||
74 | + for($i = 0; $i < $n; $i++){ | ||
75 | + $dados[$chaves[$i]] = array("valor"=>$valores[$i],"titulo"=>$titulos[$i]); | ||
76 | + } | ||
77 | + | ||
61 | $map = ms_newMapObj($map_file); | 78 | $map = ms_newMapObj($map_file); |
62 | //pega o layer | 79 | //pega o layer |
63 | $layer = $map->getlayerbyname($tema); | 80 | $layer = $map->getlayerbyname($tema); |
@@ -75,6 +92,7 @@ switch (strtoupper($funcao)) | @@ -75,6 +92,7 @@ switch (strtoupper($funcao)) | ||
75 | $retorno = "erro"; | 92 | $retorno = "erro"; |
76 | } | 93 | } |
77 | if($c != ""){ | 94 | if($c != ""){ |
95 | + //pega as chaves originais do mapfile | ||
78 | $cs = json_decode(utf8_encode($c),true); | 96 | $cs = json_decode(utf8_encode($c),true); |
79 | $cs = $cs["parametros"]; | 97 | $cs = $cs["parametros"]; |
80 | $chaves = array(); | 98 | $chaves = array(); |
@@ -82,20 +100,19 @@ switch (strtoupper($funcao)) | @@ -82,20 +100,19 @@ switch (strtoupper($funcao)) | ||
82 | $chaves[] = $c["chave"]; | 100 | $chaves[] = $c["chave"]; |
83 | } | 101 | } |
84 | $chaves = implode(",",$chaves); | 102 | $chaves = implode(",",$chaves); |
103 | + $chaves = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--","drop",";"),"",$chaves); | ||
104 | + $chaves = explode(",",$chaves); | ||
85 | $filtro = $layer1->getFilterString(); | 105 | $filtro = $layer1->getFilterString(); |
86 | - if(!empty($valores)){ | ||
87 | - $chaves = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--","drop",";"),"",$chaves); | ||
88 | - $chaves = explode(",",$chaves); | ||
89 | - $valores = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--","drop",";"),"",$valores); | ||
90 | - $valores = explode(",",strip_tags($valores)); | ||
91 | - $n = count($chaves); | ||
92 | - for($i = 0; $i < $n; $i++){ | ||
93 | - if($chaves[$i] != ""){ | ||
94 | - $v = $valores[$i]; | ||
95 | - $data = str_replace($chaves[$i],$v,$data); | 106 | + $titulofim = array(); |
107 | + if(!empty($dados)){ | ||
108 | + foreach($chaves as $k){ | ||
109 | + if($k != ""){ | ||
110 | + $v = $dados[$k]["valor"]; | ||
111 | + $data = str_replace($k,$v,$data); | ||
96 | if($filtro != ""){ | 112 | if($filtro != ""){ |
97 | - $filtro = str_replace($chaves[$i],$v,$filtro); | 113 | + $filtro = str_replace($k,$v,$filtro); |
98 | } | 114 | } |
115 | + $titulofim[] = $dados[$k]["titulo"]." ".$v; | ||
99 | } | 116 | } |
100 | } | 117 | } |
101 | if($filtro != ""){ | 118 | if($filtro != ""){ |
@@ -107,7 +124,7 @@ switch (strtoupper($funcao)) | @@ -107,7 +124,7 @@ switch (strtoupper($funcao)) | ||
107 | $layer->set("status",MS_DEFAULT); | 124 | $layer->set("status",MS_DEFAULT); |
108 | } | 125 | } |
109 | $layer->setmetadata("PLUGINI3GEO",'{"plugin":"parametrossql","ativo":"sim"}'); | 126 | $layer->setmetadata("PLUGINI3GEO",'{"plugin":"parametrossql","ativo":"sim"}'); |
110 | - $layer->setmetadata("TEMA",$layer1->getmetadata("TEMA")." - ".$titulos); | 127 | + $layer->setmetadata("TEMA",$layer1->getmetadata("TEMA")." - ".implode(". ",$titulofim)); |
111 | 128 | ||
112 | //$layer->set("name","plugin".nomeRandomico()); | 129 | //$layer->set("name","plugin".nomeRandomico()); |
113 | $layer->setmetadata("nomeoriginal",$layer1->name); | 130 | $layer->setmetadata("nomeoriginal",$layer1->name); |