";
echo "OBJ = ".$obj."
";
echo "RISK ID = ".$risk."
";
if(!$conn) { ?>
';
}
switch ($obj) {
case 'point':
$objtable = "objpoint";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'gate':
$objtable = "objgate";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'area':
$objtable = "objarea";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'fire':
$objtable = "incendi";
$schema = "public";
$idgeom = "id_aib";
break;
case 'sce':
$objtable = "objscenari";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'line':
$objtable = "objline";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'sog':
$objtable = "objsoggetti";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_obj";
break;
case 'trash':
$objtable = "discarica";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id";
break;
case 'int':
$objtable = "interventi";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "id_inter";
break;
case 'suolo_pub':
$objtable = "objsoggetti";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "suolo_id";
break;
case 'passi':
$objtable = "objsoggetti";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "passi_id";
break;
case 'pubblicita':
$objtable = "objsoggetti";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "pubbli_id";
break;
case 'civici':
$objtable = "topo_civici";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "civico_id";
break;
case 'sign':
$objtable = "segnalazioni";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "segnalazione_id";
break;
case 'zoning_compare':
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "compare_id";
break;
case 'zpoi':
$objtable = "zoning_poi";
$schema = strtolower($_SESSION['COMUNE_BELF']);
$idgeom = "poi_id";
break;
default:
$schema = "public";
}
/**/
//RECUPERA L'ULTIMO ID DALLA TABELLA GEOMETRY_TEST
if(!$last_idtable = @pg_query("SELECT ".$idgeom." AS idgeometria FROM ".$schema.".".$objtable." ORDER BY ".$objtable.".".$idgeom." DESC LIMIT 1"))
die("Errore nella query RECUPERA ID: " . pg_last_error($conn));
echo "SELECT = ".$last_idtable."
";
while($last_idtable_result = pg_fetch_assoc($last_idtable)) {
$id_new_geometry = $last_idtable_result['idgeometria'];
}
//echo "1 FEATURE: ".$feature."
2 MODE: ".$mode."
3 OBJ: ".$obj."
";
//$featuredati = explode(".", $feature);
//echo "3 TABELLA: ".$featuredati[0]."
4 ID: ".$featuredati[1]."
5 SCHEMA: ".$schema."
6 ID: ".$idgeom."
";
//$id_new_geometry = $featuredati[1];
$tabella = $_SESSION['TAB'];
//echo "5 TABELLA: ".$tabella."
";
//######################### FIRE
if ($obj == "fire") {
//RECUPERA AREA
if(!$last_gid = @pg_query("SELECT ST_AREA(the_geom) AS area FROM public.incendi WHERE id_aib = ".$id_new_geometry.""))
die("ERROR FIRE AREA: " . pg_last_error($conn));
while($last_result = pg_fetch_assoc($last_gid)) {
$areaincendio = round($last_result['area']/10000,2);
}
//echo "AREA INCENDIO ".$areaincendio ."
";
//CERCA I COMUNI INTERESSATI DALL'INCENDIO
if(!$query8 = @pg_query("SELECT comune FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.comune FROM ".
" (SELECT a.the_geom, a.comune FROM public.comuni_italia_3004 a inner join ".
" (SELECT ST_UNION(the_geom) as the_geom FROM ".$schema.".".$objtable." WHERE ".$idgeom." = ".$id_new_geometry.") b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM public.incendi WHERE id_aib = ".$id_new_geometry.") f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("ERROR STR3: " . pg_last_error($conn));
while($row8 = pg_fetch_assoc($query8)) {
$comuni[] = $row8['comune'];
}
$lista_comuni = implode(', ', $comuni);
//CERCA I TOPONIMI INTERESSATI DALL'INCENDIO
if(!$query_toponimi = @pg_query("SELECT toponimo, secondo_no FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.toponimo, e.secondo_no FROM ".
" (SELECT a.the_geom, a.toponimo, a.secondo_no FROM public.toponimi a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM public.incendi WHERE id_aib = ".$id_new_geometry.") b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM public.incendi WHERE id_aib = ".$id_new_geometry.") f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("Errore nella query STR2: " . pg_last_error($conn));
while($row_toponimi = pg_fetch_assoc($query_toponimi)) {
$topo[] = str_replace("'", "’" ,$row_toponimi['toponimo'])." ".str_replace("'", "’" ,$row_toponimi['secondo_no']);
}
$lista_toponimi = implode(', ', $topo);
//echo "TOPONIMI ".$lista_toponimi."
";
//CERCA I CATASTALI CHE INTERESSA IL PUNTO
if(!$query4 = @pg_query("SELECT mappale FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.mappale FROM ".
" (SELECT a.the_geom, a.mappale FROM ".strtolower($_SESSION['COMUNE_BELF']).".particelle a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM public.incendi WHERE id_aib = $id_new_geometry) b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM public.incendi WHERE id_aib = $id_new_geometry) f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("ERROR STR3: " . pg_last_error($conn));
while($row4 = pg_fetch_assoc($query4)) {
$mappale[] = $row4['mappale'];
}
$cataincendio = implode(', ', $mappale);
if(!$rs_update = @pg_query("UPDATE public.incendi SET comune_app = '".$_SESSION['COMUNE_NAME']."', localita = '".$lista_toponimi."', altri_com='".$lista_comuni."', catasto ='".$cataincendio."', totsup = ".$areaincendio.", archiviato = 0, attivo=1, comune = '".$_SESSION['COMUNE_BELF']."', operatore = '".$_SESSION['USER_NAME']."', data_agg = '".date("Y-m-d h:i:sa", time())."' WHERE id_aib = ".$id_new_geometry.""))
die("ERROR 1: " . pg_last_error($conn));
}
//######################### AREA
if ($obj == "area") {
//RECUPERA AREA
if(!$last_gid = @pg_query("SELECT ST_AREA(the_geom) AS area FROM ".strtolower($_SESSION['COMUNE_BELF']).".objarea WHERE id_obj = ".$id_new_geometry.""))
die("ERROR AREA PROTEZIONE CIVILE: " . pg_last_error($conn));
while($last_result = pg_fetch_assoc($last_gid)) {
$areaincendio = round($last_result['area'],0);
}
//echo "AREA INCENDIO ".$areaincendio ."
";
//CERCA I TOPONIMI INTERESSATI DALL'INCENDIO
if(!$query_toponimi = @pg_query("SELECT toponimo, secondo_no FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.toponimo, e.secondo_no FROM ".
" (SELECT a.the_geom, a.toponimo, a.secondo_no FROM public.toponimi a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM ".strtolower($_SESSION['COMUNE_BELF']).".objarea WHERE id_obj = ".$id_new_geometry.") b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM ".strtolower($_SESSION['COMUNE_BELF']).".objarea WHERE id_obj = ".$id_new_geometry.") f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("Errore nella query STR2: " . pg_last_error($conn));
while($row_toponimi = pg_fetch_assoc($query_toponimi)) {
$topo[] = str_replace("'", "’" ,$row_toponimi['toponimo'])." ".str_replace("'", "’" ,$row_toponimi['secondo_no']);
}
$lista_toponimi = implode(', ', $topo);
//echo "TOPONIMI ".$lista_toponimi."
";
//CERCA I CATASTALI CHE INTERESSA IL PUNTO
if(!$query4 = @pg_query("SELECT mappale FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.mappale FROM ".
" (SELECT a.the_geom, a.mappale FROM ".strtolower($_SESSION['COMUNE_BELF']).".particelle a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM ".strtolower($_SESSION['COMUNE_BELF']).".objarea WHERE id_obj = $id_new_geometry) b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM ".strtolower($_SESSION['COMUNE_BELF']).".objarea WHERE id_obj = $id_new_geometry) f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("ERROR STR3: " . pg_last_error($conn));
while($row4 = pg_fetch_assoc($query4)) {
$mappale[] = $row4['mappale'];
}
$cataincendio = implode(', ', $mappale);
if(!$rs_update = @pg_query("UPDATE ".strtolower($_SESSION['COMUNE_BELF']).".objarea SET comune_app='".$_SESSION['COMUNE_NAME']."', localita='".$lista_toponimi."', catasto='".$cataincendio."', area_totale='".$areaincendio."', archiviato = false, attivo=1, comune = '".$_SESSION['COMUNE_BELF']."', operatore = '".$_SESSION['USER_NAME']."', data_agg = '".date("Y-m-d h:i:sa", time())."' WHERE id_obj = ".$id_new_geometry.""))
die("ERROR 8: " . pg_last_error($conn));
}
//######################### SCE
if ($obj == "sce") {
switch ($risk) {
case 'ind': // AREA
$tipo = "Rischio industriale";
break;
case 'tsu': // AREA
$tipo = "Rischio tsunami";
break;
case 'inc': // AREA
$tipo = "Rischio incendi";
break;
case 'idr': // AREA
$tipo = "Rischio idrogeologico";
break;
default:
$tipo = "";
}
// INSERISCE AREA E GEOMETRIA IN TABELLA
if(!$testpoint = @pg_query("INSERT INTO ".strtolower($_SESSION['COMUNE_BELF']).".objscenari (tipo,attivo,comune,the_geom) VALUES ('".$tipo."',3,'".$_SESSION['COMUNE_BELF']."',
(SELECT ST_MULTI(the_geom) FROM public.polygon_support3004 WHERE gid=".$featuredati[1]."))"))
die("ERROR INSER GEOM: " . pg_last_error($conn));
//RECUPERA L'ULTIMO ID DALLA TABELLA GEOMETRY_TEST
if(!$last_gid = @pg_query("SELECT id_obj, ST_AREA(the_geom) AS area FROM ".strtolower($_SESSION['COMUNE_BELF']).".objscenari ORDER BY id_obj DESC LIMIT 1"))
die("Errore nella query RECUPERA ID: " . pg_last_error($conn));
while($last_result = pg_fetch_assoc($last_gid)) {
$id_new = $last_result['id_obj'];
$areascenario = round($last_result['area'],2);
}
//CERCA I TOPONIMI INTERESSATI DALL'INCENDIO
if(!$query_toponimi = @pg_query("SELECT toponimo, secondo_no FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.toponimo, e.secondo_no FROM ".
" (SELECT a.the_geom, a.toponimo, a.secondo_no FROM public.toponimi a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM ".strtolower($_SESSION['COMUNE_BELF']).".objscenari WHERE id_obj = ".$id_new.") b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM ".strtolower($_SESSION['COMUNE_BELF']).".objscenari WHERE id_obj = ".$id_new.") f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("Errore nella query STR2: " . pg_last_error($conn));
while($row_toponimi = pg_fetch_assoc($query_toponimi)) {
$topo[] = str_replace("'", "’" ,$row_toponimi['toponimo'])." ".str_replace("'", "’" ,$row_toponimi['secondo_no']);
}
$lista_toponimi = implode(', ', $topo);
//echo "TOPONIMI ".$lista_toponimi."
";
//CERCA I CATASTALI CHE INTERESSA IL PUNTO
if(!$query4 = @pg_query("SELECT mappale FROM ".
" (SELECT ST_Intersection(e.the_geom, f.the_geom) as the_geom, e.mappale FROM ".
" (SELECT a.the_geom, a.mappale FROM ".strtolower($_SESSION['COMUNE_BELF']).".particelle a inner join ".
" (SELECT ST_UNION(the_geom) AS the_geom FROM ".strtolower($_SESSION['COMUNE_BELF']).".objscenari WHERE id_obj = $id_new) b on ST_Intersects(a.the_geom, b.the_geom)) e inner join ".
" (SELECT * FROM ".strtolower($_SESSION['COMUNE_BELF']).".objscenari WHERE id_obj = $id_new) f on ST_Intersects(e.the_geom, f.the_geom)) a;"))
die("ERROR STR3: " . pg_last_error($conn));
while($row4 = pg_fetch_assoc($query4)) {
$mappale[] = $row4['mappale'];
}
$cataincendio = implode(', ', $mappale);
if(!$rs_update = @pg_query("UPDATE ".strtolower($_SESSION['COMUNE_BELF']).".objscenari SET comune_app = '".$_SESSION['COMUNE_NAME']."', localita = '".$lista_toponimi."', catasto ='".$cataincendio."', area = ".$areascenario.", archiviato = 0, attivo=1, comune = '".$_SESSION['COMUNE_BELF']."', operatore = '".$_SESSION['USER_NAME']."', data_agg = '".date("Y-m-d h:i:sa", time())."' WHERE id_obj = ".$id_new.""))
die("ERROR 1: " . pg_last_error($conn));
}
//######################### SCE
if ($obj == "line") {
//RECUPERA L'ULTIMO ID DALLA TABELLA GEOMETRY_TEST
if(!$last_gid = @pg_query("SELECT id_obj FROM ".strtolower($_SESSION['COMUNE_BELF']).".objline ORDER BY id_obj DESC LIMIT 1"))
die("Errore nella query RECUPERA ID: " . pg_last_error($conn));
while($last_result = pg_fetch_assoc($last_gid)) {
$id_new = $last_result['id_obj'];
}
}
if ($obj == "point" OR $obj == "trash" OR $obj == "gate" OR $obj == "sign" OR $obj == "int" OR $obj == "sog" OR $obj == "civ" OR $obj == "pas" OR $obj == "pub" OR $obj == "zoning_compare" OR $obj == "zpoi") {
//INIZIO ALTRI PUNTI
//------------------------------------------------------------------------------
// CERCA LE COORDINATE DEL PUNTO
/*
if(!$query_xy = @pg_query("SELECT ST_Y(ST_Transform(the_geom,3004)) as lat, ST_X(ST_Transform(the_geom,3004)) as long FROM ".$schema.".".$featuredati[0]." WHERE ".$idgeom."=".$featuredati[1].""))
die("Errore nella query LAT-LONG : " . pg_last_error($conn));
$row_obj = pg_num_rows($query_xy);
echo "ROW = ".$row_obj."
";
while($row_xy = pg_fetch_assoc($query_xy)) {
$long = $row_xy['long'];
$lat = $row_xy['lat'];
echo "LAT2: ".$lat." - LONG2: ".$long."
";
}
//CERCA I TOPONIMI ENTRO UN RAGGIO DI 750 M INTERESSATI DAL PUNTO
if(!$query_toponimi = @pg_query("SELECT toponimo, secondo_no FROM toponimi WHERE
ST_DWithin(Geography(the_geom)),
Geography(ST_MakePoint($long, $lat)),750);"))
die("Errore nella query STR21: " . pg_last_error($conn));
while($row_toponimi = pg_fetch_assoc($query_toponimi)) {
$topo[] = $row_toponimi['toponimo']." ".$row_toponimi['secondo_no'];
}
$toponimi = implode(', ', $topo);
//CERCA I CATASTALI CHE INTERESSA IL PUNTO
if(!$query_cata = @pg_query("SELECT mappale FROM ".strtolower($_SESSION['COMUNE_BELF']).".particelle WHERE
ST_DWithin(Geography(the_geom),
Geography(ST_MakePoint($long, $lat)),0.1);"))
die("Errore nella query STR22: " . pg_last_error($conn));
while($row_cata = pg_fetch_assoc($query_cata)) {
//$cata = substr($row_cata['mappale'],5,10);
$cata = $row_cata['mappale'];
}
*/
// if(!$rs_update = @pg_query("UPDATE ".$schema.".".$featuredati[0]." SET comune_app='".$_SESSION['COMUNE_NAME']."', localita='".$toponimi."', catasto='".$cata."', archiviato = 0, attivo=1, comune = '".$_SESSION['COMUNE_BELF']."', operatore = '".$_SESSION['USER_NAME']."', data_agg = '".date("Y-m-d h:i:sa", time())."' WHERE ".$idgeom." = ".$id_new_geometry.""))
if(!$rs_update = @pg_query("UPDATE ".$schema.".".$objtable." SET comune_app='".$_SESSION['COMUNE_NAME']."', archiviato = 0, attivo=1, comune = '".$_SESSION['COMUNE_BELF']."', operatore = '".$_SESSION['USER_NAME']."', data_agg = '".date("Y-m-d h:i:sa", time())."' WHERE ".$idgeom." = ".$id_new_geometry.""))
die("ERROR 111: " . pg_last_error($conn));
}
if ($obj == "sce") { ?>