Revision 3357

View differences:

i3geo/admin/html/estat_editor.html
43 43
			Apenas as tabelas e os dados existentes no esquema i3geo_metaestat podem ser editados<br>
44 44
			<div id="i3GEOadminEditorConexao" style="left: -5px;"></div><br>
45 45
			<div id="i3GEOadminEditorEsquema" style="left: -5px;"></div>
46
			<div id="i3GEOadminEditorUpload" style="left: -5px;"></div>
46 47
			<div id="i3GEOadminEditorTabela" style="left: -5px;"></div>
47 48
			<div id="i3GEOadminEditorColuna" style="left: -5px;"></div>
48 49
		</div>
i3geo/admin/html/estat_tipo_regiao.html
41 41
					<div class="ft"></div>
42 42
				</div>
43 43
				<br> <input type=button id=adicionaNovaLinha
44
					value="Adicionar um novo registro" style="left: -5px;" />
44
					value="Adicionar um novo registro" style="left: -5px;" /> Utilize a op&ccedil;&atilde;o &quot;Editor&quot; no menu superior caso voc&ecirc; queira fazer o upload de shapefile para criar uma nova tabela com os dados que ser&atilde;o utilizados em uma determinada regi&atilde;o
45 45
				<p>
46 46
					<br>
47 47
				<div id="tabela" style="left: -5px;"></div>
i3geo/admin/index.html
188 188
						</tr>
189 189
						<tr onclick="abre('html/estat_uploaddados.html')">
190 190
							<td><div class=aplicar></div></td>
191
							<td>Upload de dados</td>
191
							<td>Upload de dados para uma vari&aacute;vel (para upload de shapefile, utilize o gerenciador de tabelas)</td>
192 192
						</tr>
193 193
						<tr onclick="abre('html/estat_editor.html')">
194 194
							<td><div class=aplicar></div></td>
i3geo/admin/js/estat_editor.js
81 81
					success:function(o){
82 82
						try	{
83 83
							var dados = YAHOO.lang.JSON.parse(o.responseText),
84
							temp = "<fieldset>Escolha uma tabela: ";
85
							temp += "<select id='i3GEOadmintabela' onchange='i3GEOadmin.editor.coluna.lista()'>";
84
							temp = "<fieldset>" +
85
							"<p><input type=button value='Upload Shapefile' id='i3GEOadmin_botaoupload' /></p>" +
86
							"<div id='i3GEOadmin_formupload'></div>" +
87
							"Escolha uma tabela existente: " +
88
							"<select id='i3GEOadmintabela' onchange='i3GEOadmin.editor.coluna.lista()'>";
86 89
							temp += core_comboObjeto(dados,"tabela","tabela");
87
							temp += "</select>";
88
							temp += "" +
90
							temp += "</select>" +
89 91
								"<p><input type=button value='Relat&oacute;rio' id='i3GEOadmintabelaMostrar' />" +
90 92
								"<input type=button value='CSV' id='i3GEOadmintabelaCsv'/>" +
91 93
								"<input type=button value='Criar uma nova tabela' id='i3GEOadmintabelaCriar' />" +
......
93 95
								"<input type=button value='Copiar para' id='i3GEOadmintabelaCopiar' />";
94 96
							$i(i3GEOadmin.editor.tabela.onde).innerHTML = temp+"</fieldset>";
95 97
							new YAHOO.widget.Button(
98
								"i3GEOadmin_botaoupload",
99
								{onclick:{fn: i3GEOadmin.editor.uploadshp.inicia}}
100
							);
101
							new YAHOO.widget.Button(
96 102
								"i3GEOadmintabelaMostrar",
97 103
								{onclick:{fn: i3GEOadmin.editor.tabela.mostrar}}
98 104
							);
......
399 405
			}
400 406
			return false;
401 407
		}
408
	},
409
	uploadshp: {
410
		inicia: function(){
411
			var onde = $i("i3GEOadmin_formupload");
412
			if(onde.innerHTML != ""){
413
				onde.innerHTML = "";
414
				return;
415
			}
416
			$i("i3GEOadmin_formupload").innerHTML = i3GEOadmin.editor.uploadshp.formulario();
417
			new YAHOO.widget.Button(
418
				"i3GEOuploadsubmit",
419
				{onclick:{fn: i3GEOadmin.editor.uploadshp.submit}}
420
			);
421
		},
422
		formulario: function(){
423
			var ins = '<fieldset><form id=i3GEOuploadf target="i3GEOuploadiframe" action="../php/metaestat_uploadshp_submit.php" method="post" ENCTYPE="multipart/form-data">' +
424
			'<p class="paragrafo" >shp: <br><input class=digitar type="file" size=22 name="i3GEOuploadshp" style="top:0px;left:0px;cursor:pointer;"></p>' +
425
			'<p class="paragrafo" >shx: <br><input class=digitar type="file" size=22 name="i3GEOuploadshx" style="top:0px;left:0px;cursor:pointer;"></p>' +
426
			'<p class="paragrafo" >dbf: <br><input class=digitar type="file" size=22 name="i3GEOuploaddbf" style="top:0px;left:0px;cursor:pointer;"></p>' +
427
			'<p class="paragrafo" >Nome da nova tabela:<br><input class=digitar type="text" size=20 id="tabelaDestino" name="tabelaDestino" style="top:0px;left:0px;cursor:pointer;"></p>' +
428
			'<p class="paragrafo" >C&oacute;digo da proje&ccedil;&atilde;o (SRID):<br><input class=digitar type="text" value="4326" size=20 id="srid" name="srid" style="top:0px;left:0px;cursor:pointer;"></p>' +
429

  
430
			'<p class="paragrafo" ><input id=i3GEOuploadsubmit type="button" value="Enviar" size=12 />' +
431
			'<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' +
432
			'<input type="hidden" id="i3GEOuploadcodigoconexao" name="i3GEOuploadcodigoconexao" value="">' +
433
			'<input type="hidden" id="i3GEOuploadesquema" name="i3GEOuploadesquema" value="">' +
434
			'</form>' +
435
			"<p class='paragrafo' style=color:red >N&atilde;o utilize '_' no nome do arquivo. Apenas letras e n&uacute;meros s&atilde;o aceitos!!!</p>" +
436
			'<iframe name=i3GEOuploadiframe style="text-align:left;border:1px solid gray;" width="98%" height="60px"></iframe></fieldset>';
437
			return ins;
438
		},
439
		submit: function(){
440
			if($i("tabelaDestino").value == ""){
441
				alert("Digite o nome da tabela a ser criada");
442
				return;
443
			}
444
			if($i("srid").value == ""){
445
				alert("Digite o valor do SRID");
446
				return;
447
			}
448
			$i("i3GEOuploadcodigoconexao").value = $i("i3GEOadmincodigo_estat_conexao").value;
449
			$i("i3GEOuploadesquema").value = $i("i3GEOadminesquema").value;
450
			$i("i3GEOuploadf").submit();
451
		}
402 452
	}
453

  
403 454
};
i3geo/admin/js/estat_tipo_regiao.js
55 55
			elCell.innerHTML = "<div class=editar style='text-align:center' ></div>";
56 56
		},
57 57
		formatShp = function(elCell, oRecord, oColumn){
58
			elCell.innerHTML = "<div class=download style='text-align:center' ></div>";
58
			elCell.innerHTML = "<div class=download style='text-align:center' title='shape file' ></div>";
59 59
		},
60 60
		myColumnDefs = [
61 61
		                {key:"excluir",label:"excluir",formatter:formatExclui},
62
		                {key:"shapefile",label:"shapefile",formatter:formatShp},
62
		                {key:"shapefile",label:"download",formatter:formatShp},
63 63
		                {key:"rel",label:"agrega&ccedil;&otilde;es",formatter:formatRel},
64
		                {key:"mais",label:"editar",formatter:formatMais},
64
		                {key:"mais",label:"propriedades",formatter:formatMais},
65 65
		                {label:"c&oacute;digo",key:"codigo_tipo_regiao", formatter:formatTexto},
66 66
		                {label:"Nome",resizeable:true,key:"nome_tipo_regiao", formatter:formatTexto},
67 67
		                {label:"Descri&ccedil;&atilde;o",resizeable:true,key:"descricao_tipo_regiao", formatter:formatTexto},
i3geo/admin/php/upgradebanco46_47.php
176 176
	$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('17', 'admin/html/usuarios', 'cadastro de usuarios')");
177 177
if(!in_array($teste,18))
178 178
	$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('18', 'admin/metaestat/geral', 'permite edicoes mais comuns do sistema de metadados estatisticos')");
179
if(!in_array($teste,19))
180
	$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('19', 'admin/metaestat/editorbanco', 'permite gerenciar as tabelas do banco')");
179 181

  
180 182

  
183

  
181 184
$teste = lista("select * from ".$esquemaadmin."i3geousr_operacoes","id_operacao","id_papel");
182 185
if(!in_array($teste,'1-2'))
183 186
	$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoespapeis VALUES(1,2)");
i3geo/admin/php/criabanco.php
173 173
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('16', 'admin/php/editortexto', 'editor de textos para edicao de mapfiles')");
174 174
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('17', 'admin/html/usuarios', 'cadastro de usuarios')");
175 175
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('18', 'admin/metaestat/geral', 'permite edicoes mais comuns do sistema de metadados estatisticos')");
176
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoes VALUES('19', 'admin/metaestat/editorbanco', 'permite gerenciar as tabelas do banco')");
177

  
176 178
			//papeis por operacao
177 179
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoespapeis VALUES(1,2)");
178 180
			$dbhw->query("INSERT INTO ".$esquemaadmin."i3geousr_operacoespapeis VALUES(1,3)");
i3geo/admin/php/metaestat_uploadshp_submit.php
1
<?php
2
/*
3
 * Faz o upload de shapefile e insere no banco de dados
4
 */
5
include_once("admin.php");
6
include_once("login.php");
7
if(verificaOperacaoSessao("admin/metaestat/editorbanco") == false){
8
	echo "Vc nao pode realizar essa operacao.";exit;
9
}
10
error_reporting(E_ALL);
11
?>
12
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
13
<html>
14
<head>
15
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
16
<link rel="stylesheet" type="text/css" href="../../css/geral.css" />
17
<title></title>
18
</head>
19
<body bgcolor="white" style="background-color:white;text-align:left;">
20
<p>
21
<?php
22
if($_POST["tabelaDestino"] == ""){
23
	echo "Nome da tabela n&atilde;o definido";
24
	exit;
25
}
26
if($_POST["srid"] == ""){
27
	echo "SRID n&atilde;o definido";
28
	exit;
29
}
30
if ($_FILES['i3GEOuploadshp']['name'] == ""){
31
	echo "Arquivo n&atilde;o definido";
32
	exit;
33
}
34
if (isset($_FILES['i3GEOuploadshp']['name'])){
35
	require_once ("../../ms_configura.php");
36
	echo "<p class='paragrafo' >Carregando o arquivo...</p>";
37
	$arqshp = $_FILES['i3GEOuploadshp']['tmp_name'];
38
	//verifica nomes e sobe arquivo
39
	verificaNome($_FILES['i3GEOuploadshp']['name'],"shp");
40
	$nomePrefixo = str_replace(" ","_",removeAcentos(str_replace(".shp","",$_FILES['i3GEOuploadshp']['name'])));
41
	$nomePrefixo = $nomePrefixo."_".(nomeRandomico(4));
42

  
43
	$Arquivo = $_FILES['i3GEOuploadshp']['tmp_name'];
44
	$status =  move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo.".shp");
45
	if($status != 1)
46
	{echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo SHP";exit;}
47
	$Arquivo = $_FILES['i3GEOuploadshx']['tmp_name'];
48
	$status =  move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo.".shx");
49
	if($status != 1)
50
	{echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo SHX";exit;}
51
	$Arquivo = $_FILES['i3GEOuploaddbf']['tmp_name'];
52
	$status =  move_uploaded_file($Arquivo,$dir_tmp."/".$nomePrefixo.".dbf");
53
	if($status != 1)
54
	{echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo DBF";exit;}
55

  
56
	if(!file_exists($dir_tmp."/".$nomePrefixo.".shp"))
57
	{echo "<p class='paragrafo' >Ocorreu algum problema no envio do arquivo ".$dir_tmp."/".$nomePrefixo;paraAguarde();exit;}
58
	$arqshp = $dir_tmp."/".$nomePrefixo.".shp";
59

  
60
	//pega os parametros de conexao
61
	include("classe_metaestat.php");
62
	$m = new Metaestat();
63
	$conexao = $m->listaConexao($_POST["i3GEOuploadcodigoconexao"],true);
64
	//array(5) { ["codigo_estat_conexao"]=> string(1) "1" ["bancodedados"]=> string(8) "geosaude" ["host"]=> string(9) "localhost" ["porta"]=> string(4) "5432" ["usuario"]=> string(8) "postgres" }
65
	//pega as colunas do shapefile
66
	$shapefileObj = ms_newShapefileObj($arqshp,-1);
67
	$numshapes = $shapefileObj->numshapes;
68
	$mapObj = ms_newMapObjFromString("MAP END");
69
	$layer = ms_newLayerObj($mapObj);
70
	$layer->set("data",$arqshp);
71
	$layer->open();
72
	$colunas = $layer->getItems();
73

  
74
	echo "<br>Numshapes: ". $numshapes;
75
	$tipo = $shapefileObj->type;
76
	echo "<br>Tipo: ". $tipo;
77
	echo "<br>Colunas: ";
78
	var_dump($colunas);
79

  
80
	$sqinsert = array();
81

  
82

  
83

  
84
	//verifica o tipo de coluna
85
	$tipoColuna = array();
86
	if($numshapes < 10){
87
		$testar = $numshapes;
88
	}
89
	else{
90
		$testar = 10;
91
	}
92
	foreach($colunas as $coluna){
93
		$tipo = "numeric";
94
		for ($i=0; $i<$testar;$i++){
95
			$s = $layer->getShape(new resultObj($i));
96
			$v = $s->getValue($layer,$coluna);
97
			if(!is_numeric($v)){
98
				$tipo = "varchar";
99
			}
100
		}
101
		$tipoColuna[$coluna] = $tipo;
102
	}
103
	echo "<br>Tipos das colunas: <pre>";
104
	var_dump($tipoColuna);
105
	echo "</pre>";
106
	//gera o script para criar a tabela
107
	$sqltabela = array();
108
	$sql = "CREATE TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."(gid integer, the_geom geometry";
109
	foreach($colunas as $coluna){
110
		$sql .= ",".strtolower($coluna)." ".$tipoColuna[$coluna];
111
	}
112
	$sql .= ")WITH(OIDS=FALSE)";
113
	$sqltabela[] = $sql;
114
	$sqltabela[] = "ALTER TABLE ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." OWNER TO ".$conexao["usuario"];
115
	$sqltabela[] = "CREATE INDEX ".$_POST["tabelaDestino"]."_indx_thegeom ON ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." USING gist (the_geom )";
116
	echo "<br>Sql tabela: <pre>";
117
	var_dump($sqltabela);
118
	echo "</pre>";
119
	//gera o script para inserir os dados
120
	$linhas = array();
121
	$insert = "INSERT INTO ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]."( gid,".strtolower(implode(",",$colunas)).",the_geom)";
122
	for ($i=0; $i<$numshapes;$i++){
123
		$s = $layer->getShape(new resultObj($i));
124
		$vs = array();
125
		$vs[] = $i;
126
		foreach($colunas as $coluna){
127
			if($tipoColuna[$coluna] == "varchar"){
128
				$vs[] = "'".$s->getValue($layer,$coluna)."'";
129
			}
130
			else{
131
				$vs[] = $s->getValue($layer,$coluna);
132
			}
133
		}
134
		$vs[] = "st_geomfromtext('".$s->toWkt()."','".$_POST["srid"]."')";
135
		$linhas[] = $insert."VALUES(".implode(",",$vs).")";
136
	}
137
	$layer->close();
138
	try {
139
		$dbh = new PDO('pgsql:dbname='.$conexao["bancodedados"].';user='.$conexao["usuario"].';password='.$conexao["senha"].';host='.$conexao["host"].';port='.$conexao["porta"]);
140
	} catch (PDOException $e) {
141
		echo 'Connection failed: ' . $e->getMessage();
142
	}
143
	foreach($sqltabela as $linha){
144
		try {
145
			$dbh->query($linha);
146
		} catch (PDOException $e) {
147
			echo 'Erro: ' . $e->getMessage();
148
		}
149
	}
150
	foreach($linhas as $linha){
151
		try {
152
			$dbh->query($linha);
153
		} catch (PDOException $e) {
154
			echo 'Erro: ' . $e->getMessage();
155
		}
156
	}
157
	echo "<br>Feito!!!";
158
}
159
else{
160
	echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>";
161
}
162
function verificaNome($nome,$ext){
163
	$nome = strtolower($nome);
164
	$lista = explode(".",$nome);
165
	$extensao = $lista[count($lista) - 1];
166
	if($extensao != $ext){
167
		echo "Nome de arquivo inv&aacute;lido.";
168
		exit;
169
	}
170
}
171
?>
172
</body>
173
</html>
0 174

  

Also available in: Unified diff