diff --git a/banco_dados/bd_atlas.sql b/banco_dados/bd_atlas.sql
index 5d48efc..6d8106e 100755
--- a/banco_dados/bd_atlas.sql
+++ b/banco_dados/bd_atlas.sql
@@ -18,7 +18,7 @@ CREATE TABLE usuario (
senha VARCHAR(50) NOT NULL,
tipo int NOT NULL,
instituicao_id int NOT NULL,
- FOREIGN KEY (instituicao_id) REFERENCES cidades (instituicao)
+ FOREIGN KEY (instituicao_id) REFERENCES instituicao (id)
);
CREATE TABLE mapas (
@@ -29,5 +29,5 @@ CREATE TABLE mapas (
status int NOT NULL,
codigo VARCHAR(40),
usuario_id int NOT NULL,
- FOREIGN KEY (usuario_id) REFERENCES cidades (usuario)
+ FOREIGN KEY (usuario_id) REFERENCES usuario (id)
);
diff --git a/web/acessoprivado.php b/web/acessoprivado.php
index c71ce02..2fbb588 100755
--- a/web/acessoprivado.php
+++ b/web/acessoprivado.php
@@ -3,10 +3,10 @@ error_reporting(E_ERROR | E_PARSE);
include "includes/connect.php";
if (isset($_POST['codigo'])){
- $cidade = $_POST['codigo'];
+ $codigo = $_POST['codigo'];
- $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join cidades on mapas.cidade_id = cidades.id WHERE mapas.id < 21 ;");
+ $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join usuario on mapas.usuario_id = usuario.id inner join instituicao on usuario.instituicao_id = instituicao.id inner join cidades on instituicao.cidade_id = cidades.id WHERE mapas.codigo = '".$codigo."' ;");
}
diff --git a/web/mapas.php b/web/mapas.php
index 16a2c23..ae61c31 100755
--- a/web/mapas.php
+++ b/web/mapas.php
@@ -7,7 +7,7 @@ if (isset($_POST['cidade'])){
$cidade = $_POST['cidade'];
- $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join cidades on mapas.cidade_id = cidades.id where cidades.nome = '".$cidade."';");
+ $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join usuario on mapas.usuario_id = usuario.id inner join instituicao on usuario.instituicao_id = instituicao.id inner join cidades on instituicao.cidade_id = cidades.id where cidades.nome = '".$cidade."' and mapas.status = 1;");
}
diff --git a/web/processa.php b/web/processa.php
index 30b9d7e..34cfe51 100755
--- a/web/processa.php
+++ b/web/processa.php
@@ -1,11 +1,8 @@
".pg_last_error($dbcon));
include "includes/connect.php";
function rmdir_recursive($dir) {
@@ -37,17 +34,13 @@ if($_FILES["zip_file"]["name"]) {
$message = "The file you are trying to upload is not a .zip file. Please try again.";
}
- /* PHP current path */
- $path = dirname(__FILE__).'/'; // absolute path to the directory where zipper.php is in
- $filenoext = basename ($filename, '.zip'); // absolute path to the directory where zipper.php is in (lowercase)
- $filenoext = basename ($filenoext, '.ZIP'); // absolute path to the directory where zipper.php is in (when uppercase)
+ $path = dirname(__FILE__).'/';
+ $filenoext = basename ($filename, '.zip');
+ $filenoext = basename ($filenoext, '.ZIP');
- $targetdir = $filenoext; // target directory
- $targetzip = $path . $filename; // target zip file
+ $targetdir = $filenoext;
+ $targetzip = $path . $filename;
$diretrio = 'mapas/'.$targetdir;
- /* create directory if not exists', otherwise overwrite */
- /* target directory is same as filename without extension */
- #$bdcon = pg_connect("dbname=atlas2");
if (is_dir($diretrio)) rmdir_recursive ($diretrio);
@@ -56,14 +49,13 @@ if($_FILES["zip_file"]["name"]) {
mkdir($diretrio, 0777);
-
- /* here it is really happening */
+
if(move_uploaded_file($source, $targetzip)) {
$zip = new ZipArchive();
- $x = $zip->open($targetzip); // open the zip file to extract
+ $x = $zip->open($targetzip);
if ($x === true) {
- $zip->extractTo($diretrio); // place in the directory with same name
+ $zip->extractTo($diretrio);
$zip->close();
unlink($targetzip);
@@ -71,23 +63,14 @@ if($_FILES["zip_file"]["name"]) {
$nome = $_POST['nome'];
$descricao = $_POST['descricao'];
$status = $_POST['status'];
- $estado = $_POST['estado'];
- $cidade = $_POST['cidade'];
+ $codigo_cadastro = $_POST['codigo_cadastro'];
$enderco = $diretrio.'/index.html';
- $insertcidades = pg_query($dbcon, "INSERT INTO cidades VALUES(default, '".$cidade."','".$estado."');");
-
- if($insertcidades){
- $id_cidade = pg_query($dbcon, "SELECT id FROM cidades ORDER BY id DESC LIMIT 1");
- if($id_cidade){
- while ($resultado_city = pg_fetch_array($id_cidade)) {
- $id_city = $resultado_city["id"];
- }
- $sql_mapas = pg_query($dbcon,"INSERT INTO mapas VALUES(default, '".$enderco."', '".$nome."', '".$descricao."','".$status."', '".$id_city."', '".$id_usuario."');");
- $message = "Your .zip file was uploaded and unpacked.";
- }
- }
+
+ $sql_mapas = pg_query($dbcon,"INSERT INTO mapas VALUES(default, '".$enderco."', '".$nome."', '".$descricao."','".$status."', '".$codigo_cadastro."', '".$id_usuario."');");
+ $message = "Sucesso!!!";
+
} else {
- $message = "There was a problem with the upload. Please try again.";
+ $message = "Erro!!!";
}
}
if (isset($_GET['dado'])){
@@ -102,35 +85,39 @@ if (isset($_GET['editar'])){
}
+function delTree($dir) {
+ $files = array_diff(scandir($dir), array('.','..'));
+ foreach ($files as $file) {
+ (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
+ }
+ return rmdir($dir);
+}
function deletemapa($id_dado){
include "includes/connect.php";
- // $con_string = "host=localhost dbname=atlas_v4 user=postgres password='123'";
- // if(!$dbconn = pg_connect($con_string)) die ("Erro ao conectar ao banco
".pg_last_error($dbconn));
-
- $id_cidade = pg_query($dbcon, "SELECT cidade_id, end_arquivo FROM mapas where id = '".$id_dado."'");
+ $id_cidade = pg_query($dbcon, "SELECT end_arquivo FROM mapas where id = '".$id_dado."'");
if($id_cidade){
- while ($resultado_city = pg_fetch_array($id_cidade)) {
- $id_city = $resultado_city["cidade_id"];
- $end = $resultado_city["end_arquivo"];
+ while ($resultado = pg_fetch_array($id_cidade)) {
+ $end = $resultado["end_arquivo"];
}
$result = pg_query($dbcon, "DELETE FROM mapas where id = '" . $id_dado . "';");
if($result ){
- $deletcidade = pg_query($dbcon, "DELETE FROM cidades where id = '".$id_city ."'");
- if ($deletcidade) {
-
+ $text = strstr($end, "/index.html", true);
+ delTree($text);
+
return pg_query($deletcidade);
} else {
- }
}
}
}
- $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join cidades on mapas.cidade_id = cidades.id where mapas.usuario_id = '".$id_usuario."';");
+
+
+ $exec_sql_select = pg_query($dbcon, "select mapas.id as id_mapa, mapas.nome as titulo, cidades.nome as cidade, descricao, end_arquivo from mapas inner join usuario on mapas.usuario_id = usuario.id inner join instituicao on usuario.instituicao_id = instituicao.id inner join cidades on instituicao.cidade_id = cidades.id where mapas.usuario_id = '".$id_usuario."';");
?>
@@ -187,6 +174,15 @@ function deletemapa($id_dado){
});
});
+ function habilitar(value) {
+ var input = document.getElementById("codigo_cadastro");
+
+ if (value == 1) {
+ input.disabled = true;
+ } else {
+ input.disabled = false;
+ }
+ }
@@ -236,10 +232,10 @@ function deletemapa($id_dado){