Commit c9dfcd39c14bcb12cf86fa86c18e3fddfb4156a4
1 parent
5bf6f9c1
Exists in
master
and in
6 other branches
Alteração na forma como o download de um tema é feito, para gerar um arquivo zip…
… apenas e fazer o download automaticamente
Showing
5 changed files
with
96 additions
and
76 deletions
Show diff stats
classesphp/funcoes_gerais.php
... | ... | @@ -1807,60 +1807,47 @@ function downloadTema2($map_file, $tema, $locaplic, $dir_tmp, $postgis_mapa) |
1807 | 1807 | $map = ms_newMapObj($map_file); |
1808 | 1808 | $rectextent = $map->extent; |
1809 | 1809 | $extensao = ".map"; |
1810 | - if (file_exists($locaplic . "/temas/" . $tema . ".gvp")) { | |
1811 | - $extensao = ".gvp"; | |
1812 | - } | |
1813 | - if ($extensao == ".map") { | |
1814 | - // | |
1815 | - // problema aqui | |
1816 | - // $tema pode ser diferente do nome do mapfile | |
1817 | - // | |
1818 | - $teste = @$map->getlayerbyname($tema); | |
1819 | - // caso o usuario tenha usado caixa alta no nome do layer | |
1820 | - if ($teste == "") { | |
1821 | - $teste = @$map->getlayerbyname(strtoupper($tema)); | |
1810 | + // | |
1811 | + // problema aqui | |
1812 | + // $tema pode ser diferente do nome do mapfile | |
1813 | + // | |
1814 | + $teste = @$map->getlayerbyname($tema); | |
1815 | + // caso o usuario tenha usado caixa alta no nome do layer | |
1816 | + if ($teste == "") { | |
1817 | + $teste = @$map->getlayerbyname(strtoupper($tema)); | |
1818 | + } | |
1819 | + // se o layer não existir no mapfile, pega da pasta i3geo/temas e adiciona em $map | |
1820 | + if ($teste == "") { | |
1821 | + // tema pode ser o nome de um arquivo mapfile | |
1822 | + if (file_exists($tema . ".map")) { | |
1823 | + $maptemp = ms_newMapObj($tema . ".map"); | |
1824 | + $tema = basename($tema); | |
1825 | + } else { | |
1826 | + $maptemp = ms_newMapObj($temasdir . "/" . $tema . ".map"); | |
1822 | 1827 | } |
1823 | - // se o layer não existir no mapfile, pega da pasta i3geo/temas e adiciona em $map | |
1824 | - if ($teste == "") { | |
1825 | - // tema pode ser o nome de um arquivo mapfile | |
1826 | - if (file_exists($tema . ".map")) { | |
1827 | - $maptemp = ms_newMapObj($tema . ".map"); | |
1828 | - $tema = basename($tema); | |
1829 | - } else { | |
1830 | - $maptemp = ms_newMapObj($temasdir . "/" . $tema . ".map"); | |
1831 | - } | |
1832 | - $numlayers = $maptemp->numlayers; | |
1833 | - for ($i = 0; $i < $numlayers; ++ $i) { | |
1834 | - $ll = $maptemp->getlayer($i); | |
1835 | - $permite = $ll->getmetadata("permitedownload"); | |
1836 | - if ($permite != "nao") { | |
1837 | - ms_newLayerObj($map, $ll); | |
1838 | - } | |
1828 | + $numlayers = $maptemp->numlayers; | |
1829 | + for ($i = 0; $i < $numlayers; ++ $i) { | |
1830 | + $ll = $maptemp->getlayer($i); | |
1831 | + $permite = $ll->getmetadata("permitedownload"); | |
1832 | + if ($permite != "nao") { | |
1833 | + ms_newLayerObj($map, $ll); | |
1839 | 1834 | } |
1840 | - $teste = @$map->getlayerbyname($tema); | |
1841 | - if ($teste == "") { | |
1842 | - $ll = $maptemp->getlayer(0); | |
1843 | - $permite = $ll->getmetadata("permitedownload"); | |
1844 | - if ($permite != "nao") { | |
1845 | - ms_newLayerObj($map, $ll); | |
1846 | - $tema = $ll->name; | |
1847 | - } | |
1835 | + } | |
1836 | + $teste = @$map->getlayerbyname($tema); | |
1837 | + if ($teste == "") { | |
1838 | + $ll = $maptemp->getlayer(0); | |
1839 | + $permite = $ll->getmetadata("permitedownload"); | |
1840 | + if ($permite != "nao") { | |
1841 | + ms_newLayerObj($map, $ll); | |
1842 | + $tema = $ll->name; | |
1848 | 1843 | } |
1849 | - } else { | |
1850 | - // remove o metadata com um nome de arquivo opcional, pois a função de download pode estar sendo executada da árvore de camadas | |
1851 | - $teste = $map->getlayerbyname($tema); | |
1852 | - $teste->setmetadata("arquivodownload", ""); | |
1853 | 1844 | } |
1854 | 1845 | } else { |
1855 | - include_once ($locaplic . "/pacotes/gvsig/gvsig2mapfile/class.gvsig2mapfile.php"); | |
1856 | - $gm = new gvsig2mapfile($locaplic . "/temas/" . $tema . ".gvp"); | |
1857 | - $gvsigview = $gm->getViewsNames(); | |
1858 | - foreach ($gvsigview as $gv) { | |
1859 | - $dataView = $gm->getViewData($gvsigview); | |
1860 | - $map = $gm->addLayers($map, $gvsigview, $dataView["layerNames"]); | |
1861 | - $temas = array_merge($temas, $gm->nomesLayersAdicionados); | |
1862 | - } | |
1846 | + // remove o metadata com um nome de arquivo opcional, pois a função de download pode estar sendo executada da árvore de camadas | |
1847 | + $teste = $map->getlayerbyname($tema); | |
1848 | + $teste->setmetadata("arquivodownload", ""); | |
1863 | 1849 | } |
1850 | + | |
1864 | 1851 | // |
1865 | 1852 | // salva o mapfile com um outro nome para evitar que o mapa atual, se estiver aberto, seja modificado |
1866 | 1853 | // |
... | ... | @@ -1883,7 +1870,6 @@ function downloadTema2($map_file, $tema, $locaplic, $dir_tmp, $postgis_mapa) |
1883 | 1870 | // verifica se existe mais de um tema (grupo) montando o array com os temas |
1884 | 1871 | // os grupos podem ter o nome do layer em GROUP ao invés de NAME |
1885 | 1872 | // |
1886 | - if ($extensao == ".map") { | |
1887 | 1873 | $multilayer = 0; |
1888 | 1874 | $grupos = $map->getAllGroupNames(); |
1889 | 1875 | foreach ($grupos as $grupo) { |
... | ... | @@ -1904,7 +1890,6 @@ function downloadTema2($map_file, $tema, $locaplic, $dir_tmp, $postgis_mapa) |
1904 | 1890 | if ($multilayer == 0) { |
1905 | 1891 | $temas[] = $tema; |
1906 | 1892 | } |
1907 | - } | |
1908 | 1893 | // $temas agora é um array com os NAMEs dos LAYERS que serão baixados |
1909 | 1894 | $radtmp = dirname($dir_tmp); |
1910 | 1895 | $ziper = new zipfile(); |
... | ... | @@ -2472,16 +2457,16 @@ function seems_utf8($Str) |
2472 | 2457 | */ |
2473 | 2458 | function removeAcentos($s) |
2474 | 2459 | { |
2475 | - $s = ereg_replace("[áàâã]", "a", $s); | |
2476 | - $s = ereg_replace("[ÁÀÂÃ]", "A", $s); | |
2477 | - $s = ereg_replace("[éèê]", "e", $s); | |
2460 | + $s = ereg_replace("[á�âã]", "a", $s); | |
2461 | + $s = ereg_replace("[Á�ÂÃ]", "A", $s); | |
2462 | + $s = ereg_replace("[é�ê]", "e", $s); | |
2478 | 2463 | $s = ereg_replace("[í]", "i", $s); |
2479 | 2464 | $s = ereg_replace("[Í]", "I", $s); |
2480 | - $s = ereg_replace("[ÉÈÊ]", "E", $s); | |
2481 | - $s = ereg_replace("[óòôõ]", "o", $s); | |
2482 | - $s = ereg_replace("[ÓÒÔÕ]", "O", $s); | |
2483 | - $s = ereg_replace("[úùû]", "u", $s); | |
2484 | - $s = ereg_replace("[ÚÙÛ]", "U", $s); | |
2465 | + $s = ereg_replace("[É�Ê]", "E", $s); | |
2466 | + $s = ereg_replace("[��ôõ]", "o", $s); | |
2467 | + $s = ereg_replace("[��ÔÕ]", "O", $s); | |
2468 | + $s = ereg_replace("[ú��]", "u", $s); | |
2469 | + $s = ereg_replace("[��]", "U", $s); | |
2485 | 2470 | $s = str_replace("ç", "c", $s); |
2486 | 2471 | $s = str_replace("Ç", "C", $s); |
2487 | 2472 | // $str = htmlentities($s); | ... | ... |
classesphp/mapa_controle.php
... | ... | @@ -1035,6 +1035,19 @@ switch (strtoupper($funcao)) { |
1035 | 1035 | case "DOWNLOAD2": |
1036 | 1036 | $retorno = downloadTema2($map_file, $_pg["tema"], $locaplic, $dir_tmp, $postgis_mapa); |
1037 | 1037 | break; |
1038 | + /* | |
1039 | + * Valor: DOWNLOAD3 | |
1040 | + * | |
1041 | + * Gera um arquivo para download de um tema. | |
1042 | + */ | |
1043 | + case "DOWNLOAD3": | |
1044 | + $retorno = downloadTema2($map_file, $_pg["tema"], $locaplic, $dir_tmp, $postgis_mapa); | |
1045 | + $retorno["arquivos"] = ""; | |
1046 | + $retorno["datas"] = ""; | |
1047 | + $_SESSION["downloadZipTema"] = $retorno["shape-zip"]; | |
1048 | + $retorno["shape-zip"] = ""; | |
1049 | + session_write_close(); | |
1050 | + break; | |
1038 | 1051 | /* |
1039 | 1052 | * Valor: DOWNLOAD3 |
1040 | 1053 | * | ... | ... |
ferramentas/download/dicionario.js
1 | 1 | //+$trad(1,i3GEOF.download.dicionario)+ |
2 | 2 | i3GEOF.download.dicionario = { |
3 | 3 | 'download' : [ { |
4 | - pt : "Clique com o botão da direita do mouse sobre o(s) arquivo(s) abaixo para fazer o download.", | |
5 | - en : "Click the right mouse button on the file(s) below to download.", | |
6 | - es : "Haga clic con el botón derecho del ratón sobre el (los) archivo (s) abajo para descargar." | |
4 | + pt : "Gerando arquivo...", | |
5 | + en : "", | |
6 | + es : "" | |
7 | 7 | } ], |
8 | 8 | 'erroTema' : [ { |
9 | 9 | pt : "Ocorreu um erro. O tema não foi encontrado. Pode ser que o código do tema não existe na definição do mapfile. Informe o administrador do sistema.", |
... | ... | @@ -15,9 +15,9 @@ i3GEOF.download.dicionario = { |
15 | 15 | en : "Number of records", |
16 | 16 | es : "Número de registros" |
17 | 17 | } ], |
18 | - 'pagdownload' : [ { | |
19 | - pt : "Acesse aqui a página de download, que contém mais opções", | |
20 | - en : "For more options, access the download page here", | |
21 | - es : "Para más opciones, acceda aquí a la página de descarga" | |
22 | - } ] | |
18 | + 'arquivook' : [ { | |
19 | + pt : "Arquivo gerado", | |
20 | + en : "", | |
21 | + es : "" | |
22 | + } ] | |
23 | 23 | }; |
24 | 24 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +<?php | |
2 | +if(empty($_REQUEST["g_sid"])){ | |
3 | + exit; | |
4 | +} | |
5 | +$g_sid = $_REQUEST["g_sid"]; | |
6 | +session_name("i3GeoPHP"); | |
7 | +session_id($g_sid); | |
8 | +session_start(); | |
9 | +if($_SESSION["downloadZipTema"] != ""){ | |
10 | + $arquivo = $_SESSION["downloadZipTema"]; | |
11 | + $_SESSION["downloadZipTema"] = ""; | |
12 | + session_write_close(); | |
13 | + header("Content-Transfer-Encoding: binary"); | |
14 | + header('Content-Disposition: attachment; filename="'.basename($arquivo).'"'); | |
15 | + readfile($arquivo); | |
16 | + exit; | |
17 | +} else { | |
18 | + $_SESSION["downloadZipTema"] = ""; | |
19 | + session_write_close(); | |
20 | +} | |
21 | +?> | |
0 | 22 | \ No newline at end of file | ... | ... |
ferramentas/download/index.js
... | ... | @@ -91,7 +91,7 @@ i3GEOF.download = { |
91 | 91 | */ |
92 | 92 | html:function(divid,tema){ |
93 | 93 | var cp,p,ins,mostraDownload,c; |
94 | - ins = '<div class="container-fluid" style="top:0px;position:absolute;"><h5 class="alert alert-info">'+$trad('download',i3GEOF.download.dicionario)+'</h5>'; | |
94 | + ins = '<div class="container-fluid" style="top:0px;position:absolute;"><h5>'+$trad('download',i3GEOF.download.dicionario)+'</h5>'; | |
95 | 95 | ins += '<div id=i3GEOdownloadResultado ></div></div>'; |
96 | 96 | $i(divid).innerHTML += ins; |
97 | 97 | c = i3GEO.arvoreDeCamadas.pegaTema(tema); |
... | ... | @@ -113,17 +113,18 @@ i3GEOF.download = { |
113 | 113 | ins = "<h5 class='alert alert-warning'>"+$trad('erroTema',i3GEOF.download.dicionario)+"</h5>"; |
114 | 114 | } |
115 | 115 | else{ |
116 | - for (arq=0;arq<n;arq++){ | |
117 | - ins += "<li><a href='"+window.location.protocol+"//"+window.location.host+"/"+arqs[arq]+"'>"+arqs[arq]+"</a></li>"; | |
118 | - } | |
116 | + ins += "<h5>" + $trad('arquivook',i3GEOF.download.dicionario) + "</h5>"; | |
117 | + var url = i3GEO.configura.locaplic + "/ferramentas/download/forcedownload.php?g_sid=" + i3GEO.configura.sid; | |
118 | + var link = document.createElement("a"); | |
119 | + $(link).click(function(e) { | |
120 | + e.preventDefault(); | |
121 | + window.location.href = url; | |
122 | + }); | |
123 | + $(link).click(); | |
119 | 124 | } |
120 | 125 | if(retorno.nreg){ |
121 | - ins += "<h5 class='alert alert-info'>"+$trad('registros',i3GEOF.download.dicionario)+" ="+retorno.nreg + "</h5>"; | |
126 | + ins += "<h5>"+$trad('registros',i3GEOF.download.dicionario)+" ="+retorno.nreg + "</h5>"; | |
122 | 127 | } |
123 | - temp = i3GEO.configura.locaplic+"/datadownload.htm?tema="+tema+"&temaDownload="+tema; | |
124 | - ins += "<h5 class='alert alert-info'>"; | |
125 | - ins += "<a href='"+temp+"' target=_blank >"+$trad('pagdownload',i3GEOF.download.dicionario)+"</a></h5>"; | |
126 | - | |
127 | 128 | } |
128 | 129 | else{ |
129 | 130 | ins = "<h5 class='alert alert-warning'>"+$trad("x66")+"</h5>"; |
... | ... | @@ -131,7 +132,7 @@ i3GEOF.download = { |
131 | 132 | $i("i3GEOdownloadResultado").innerHTML = ins + "</div>"; |
132 | 133 | i3GEOF.download.aguarde.visibility = "hidden"; |
133 | 134 | }; |
134 | - p = i3GEO.configura.locaplic+"/classesphp/mapa_controle.php?g_sid="+i3GEO.configura.sid+"&funcao=download2&tema="+tema; | |
135 | + p = i3GEO.configura.locaplic+"/classesphp/mapa_controle.php?g_sid="+i3GEO.configura.sid+"&funcao=download3&tema="+tema; | |
135 | 136 | cp = new cpaint(); |
136 | 137 | cp.set_response_type("JSON"); |
137 | 138 | cp.call(p,"downloadTema",mostraDownload); | ... | ... |