<?php





function crea_paginagps_ana_sedi(){
	global $dbo;
	global $docroot;


	$m="map";

	$google = get_var('Google Maps API key');
	$id_azienda=get_var('Azienda predefinita');
	$nfile = $docroot."/modules/anagrafiche_sedi/gps/index_gps.html";
// apertura e creazione file xml
	$myfile = fopen($nfile, "w") or die("Errore apertura file!");

// scrittura schema
	$_apertura = '<html>'. "\n";
	$_apertura .= '<head>'. "\n";
	$_apertura .= '<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>'. "\n";
	$_apertura .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>'. "\n";
	$_apertura .= '<title>Gest366</title>'. "\n";
	$_apertura .= '<script type="text/javascript" src="http://maps.google.com/maps/api/js?key='.$google.'"></script>'. "\n";
	$_apertura .= '<script type="text/javascript">'. "\n";
	$_apertura .= 'var initialize = function() {'. "\n";
	fwrite($myfile, $_apertura);

// ciclare per le coordiante travate

	$trovato=array();
	$colore=array();
	$testo_tips=array();
	$id_intervento=array();
	$id_anagrafica=array();
	$id_sede=array();

	$mappa_centra="";
	$mappa_centra_tmp="";

	$query=$_SESSION['query_controller'] ;

	$rs_tutti = $dbo->fetchArray($query);

	$record=sizeof($rs_tutti);


	for( $i=0; $i<$record; $i++ ){
		$trovato[$i]="0";
		$contatore[$i]="0";
		$colore[$i]="";
		$testo_tips[$i]="";
		$lati="";
		$long="";
		$id_anagrafica[$i]=$rs_tutti[$i]['id'];


		$rs_ana = $dbo->fetchArray("SELECT nomesede , indirizzo , citta , lat , lng , colore_marker FROM an_sedi WHERE lat<>'' and lng<>'' and id='".$rs_tutti[$i]['id']."'");
		if( sizeof($rs_ana)>0 ){
			$lati=$rs_ana[0]['lat'];
			$long=$rs_ana[0]['lng'];
			$trovato[$i]="1";
			$testo_tips[$i]=$rs_ana[0]['nomesede']." - ".$rs_ana[0]['indirizzo']." - ".$rs_ana[0]['citta'];
		}


		if( $trovato[$i] =="1"	){
			$mappa_centra_tmp=$i;
			$colore[$i]=str_replace( "#", "", $rs_ana[0]['colore_marker'] );
			$_schema = "var latlng".$i." = new google.maps.LatLng(".$lati.",".$long.");". "\n";
			fwrite($myfile, $_schema);
			if( $rs_tutti[$i]['id'] == $id_azienda	){
				$mappa_centra=$i;
			}
		}
	}

	if( $mappa_centra == ''	){
		$mappa_centra=$mappa_centra_tmp;
	}

	$_schema = 'var options = { zoom: 10,'. "\n";
		$_schema .= "center: latlng".$mappa_centra.",". "\n";
		$_schema .= 'mapTypeId: google.maps.MapTypeId.ROADMAP'. "\n";
		$_schema .= '};'. "\n";

	$_schema .= "var map = new google.maps.Map(document.getElementById('map'), options);". "\n";
	fwrite($myfile, $_schema);


	for( $i=0; $i<$record; $i++ ){
		if( $trovato[$i] =="1"	){
			$numero_sedi=0;
			$numero_anagrafica=1;
			$rs_conta="11";
			$rs_ana = $dbo->fetchArray("SELECT nomesede , indirizzo , citta , lat , lng , colore_marker FROM an_sedi WHERE lat<>'' and lng<>'' and idanagrafica='".$rs_tutti[$i]['id']."'");

			$contatore=$numero_anagrafica ;


			$testo=$id_anagrafica[$i]."-".$rs_ana[$i]['nomesede']." - ".$rs_ana[$i]['indirizzo'];
			$colore_marker=  $colore[$i];
			$testo=  $id_anagrafica[$i]."-".$testo_tips[$i];
			$_schema ='var pinImage = new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/'.$colore_marker.'/");'. "\n";
			$testo = str_replace( "'", "", $testo );
			$_schema .=  "var marker = new google.maps.Marker({ position: latlng".$i.",". "\n";
			$_schema .= "		map: map, ". "\n";
			$_schema .="		icon: pinImage,". "\n";
			$_schema .= "		title: '".$testo."' });". "\n";
			fwrite($myfile, $_schema);
		}
	}

	$_chiusura = '}'. "\n";
	$_chiusura .= 'window.onload = initialize;'. "\n";
	$_chiusura .= '</script>'. "\n";
	$_chiusura .= '</head>'. "\n";
	$_chiusura .= '<body style="margin:0; padding:0;">'. "\n";
	$_chiusura .= '<div id="map" style="width:100%; height:100%"></div>'. "\n";
	$_chiusura .= '</body>'. "\n";
	$_chiusura .= '</html>'. "\n";

	fwrite($myfile, $_chiusura);


	fclose($myfile);



}


function crea_paginagps_ana(){
	global $dbo;
	global $docroot;


	$m="map";

	$google = get_var('Google Maps API key');
	$id_azienda=get_var('Azienda predefinita');
	$nfile = $docroot."/modules/anagrafiche/gps/index_gps.html";
// apertura e creazione file xml
	$myfile = fopen($nfile, "w") or die("Errore apertura file!");

// scrittura schema
	$_apertura = '<html>'. "\n";
	$_apertura .= '<head>'. "\n";
	$_apertura .= '<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>'. "\n";
	$_apertura .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>'. "\n";
	$_apertura .= '<title>Gest366</title>'. "\n";
	$_apertura .= '<script type="text/javascript" src="http://maps.google.com/maps/api/js?key='.$google.'"></script>'. "\n";
	$_apertura .= '<script type="text/javascript">'. "\n";
	$_apertura .= 'var initialize = function() {'. "\n";
	fwrite($myfile, $_apertura);

// ciclare per le coordiante travate

	$trovato=array();
	$colore=array();
	$testo_tips=array();
	$id_intervento=array();
	$id_anagrafica=array();
	$id_sede=array();

	$mappa_centra="";
	$mappa_centra_tmp="";

	$query=$_SESSION['query_controller'] ;

	$rs_tutti = $dbo->fetchArray($query);

	$record=sizeof($rs_tutti);


	for( $i=0; $i<$record; $i++ ){
		$trovato[$i]="0";
		$contatore[$i]="0";
		$colore[$i]="";
		$testo_tips[$i]="";
		$lati="";
		$long="";
		$id_anagrafica[$i]=$rs_tutti[$i]['id'];


		$rs_ana = $dbo->fetchArray("SELECT ragione_sociale , indirizzo , citta , lat , lng , colore_marker FROM an_anagrafiche WHERE lat<>'' and lng<>'' and idanagrafica='".$rs_tutti[$i]['id']."'");
		if( sizeof($rs_ana)>0 ){
			$lati=$rs_ana[0]['lat'];
			$long=$rs_ana[0]['lng'];
			$trovato[$i]="1";
			$testo_tips[$i]=$rs_ana[0]['ragione_sociale']." - ".$rs_ana[0]['indirizzo']." - ".$rs_ana[0]['citta'];
		}


		if( $trovato[$i] =="1"	){
			$mappa_centra_tmp=$i;
			$colore[$i]=str_replace( "#", "", $rs_ana[0]['colore_marker'] );
			$_schema = "var latlng".$i." = new google.maps.LatLng(".$lati.",".$long.");". "\n";
			fwrite($myfile, $_schema);
			if( $rs_tutti[$i]['id'] == $id_azienda	){
				$mappa_centra=$i;
			}
		}
	}

	if( $mappa_centra == ''	){
		$mappa_centra=$mappa_centra_tmp;
	}

	$_schema = 'var options = { zoom: 10,'. "\n";
		$_schema .= "center: latlng".$mappa_centra.",". "\n";
		$_schema .= 'mapTypeId: google.maps.MapTypeId.ROADMAP'. "\n";
		$_schema .= '};'. "\n";

	$_schema .= "var map = new google.maps.Map(document.getElementById('map'), options);". "\n";
	fwrite($myfile, $_schema);


	for( $i=0; $i<$record; $i++ ){
		if( $trovato[$i] =="1"	){
			$numero_sedi=0;
			$numero_anagrafica=1;
			$rs_conta="11";
			$rs_ana = $dbo->fetchArray("SELECT ragione_sociale , indirizzo , citta , lat , lng , colore_marker FROM an_anagrafiche WHERE lat<>'' and lng<>'' and idanagrafica='".$rs_tutti[$i]['id']."'");

			$contatore=$numero_anagrafica ;


			$testo=$id_anagrafica[$i]."-".$rs_ana[$i]['ragione_sociale']." - ".$rs_ana[$i]['indirizzo'];
			$colore_marker=  $colore[$i];
			$testo=  $id_anagrafica[$i]."-".$testo_tips[$i];
			$_schema ='var pinImage = new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/'.$colore_marker.'/");'. "\n";
			$testo = str_replace( "'", "", $testo );
			$_schema .=  "var marker = new google.maps.Marker({ position: latlng".$i.",". "\n";
			$_schema .= "		map: map, ". "\n";
			$_schema .="		icon: pinImage,". "\n";
			$_schema .= "		title: '".$testo."' });". "\n";
			fwrite($myfile, $_schema);
		}
	}

	$_chiusura = '}'. "\n";
	$_chiusura .= 'window.onload = initialize;'. "\n";
	$_chiusura .= '</script>'. "\n";
	$_chiusura .= '</head>'. "\n";
	$_chiusura .= '<body style="margin:0; padding:0;">'. "\n";
	$_chiusura .= '<div id="map" style="width:100%; height:100%"></div>'. "\n";
	$_chiusura .= '</body>'. "\n";
	$_chiusura .= '</html>'. "\n";

	fwrite($myfile, $_chiusura);


	fclose($myfile);



}




function crea_paginagps_pianificazione(){
	global $dbo;
	global $docroot;


	$m="map";

	$google = get_var('Google Maps API key');
	$id_azienda=get_var('Azienda predefinita');
	$nfile = $docroot."/modules/documenti/gps/index_gps.html";


// apertura e creazione file xml
	$myfile = fopen($nfile, "w") or die("Errore apertura file!");



// scrittura schema

	$_apertura = '<html>'. "\n";
	$_apertura .= '<head>'. "\n";
	$_apertura .= '<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>'. "\n";
	$_apertura .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>'. "\n";
	$_apertura .= '<title>Gest366</title>'. "\n";
	$_apertura .= '<script type="text/javascript" src="http://maps.google.com/maps/api/js?key='.$google.'"></script>'. "\n";
	$_apertura .= '<script type="text/javascript">'. "\n";
	$_apertura .= 'var initialize = function() {'. "\n";
	fwrite($myfile, $_apertura);

// ciclare per le coordiante travate


	$trovato=array();
	$colore=array();
	$testo_tips=array();
	$id_intervento=array();
	$id_anagrafica=array();
	$id_sede=array();

	$mappa_centra="";

	$query=$_SESSION['query_controller'] ;

	$rs_tutti = $dbo->fetchArray($query);

	$record=sizeof($rs_tutti);


	for( $i=0; $i<$record; $i++ ){
		$trovato[$i]="0";
		$contatore[$i]="0";
		$colore[$i]="";
		$testo_tips[$i]="";
		$lati="";
		$long="";
		$id_intervento[$i]=$rs_tutti[$i]['id'];
		$id_anagrafica[$i]=$rs_tutti[$i]['idanagrafica'];

		$rs_ana = $dbo->fetchArray("SELECT ragione_sociale , indirizzo , citta , lat , lng , colore_marker FROM an_anagrafiche WHERE lat<>'' and lng<>'' and idanagrafica='".$rs_tutti[$i]['idanagrafica']."'");
		if( sizeof($rs_ana)>0 ){
			$lati=$rs_ana[0]['lat'];
			$long=$rs_ana[0]['lng'];
			$trovato[$i]="1";
			$testo_tips[$i]=$rs_ana[0]['ragione_sociale']." - ".$rs_ana[0]['indirizzo']." - ".$rs_ana[0]['citta'];
		}



		if( $trovato[$i] =="1"	){
			$mappa_centra=$i;
			$colore[$i]=str_replace( "#", "", $rs_ana[0]['colore_marker'] );
			$_schema = "var latlng".$i." = new google.maps.LatLng(".$lati.",".$long.");". "\n";
			fwrite($myfile, $_schema);
		}
	}




	$_schema = 'var options = { zoom: 8,'. "\n";
		$_schema .= "center: latlng".$mappa_centra.",". "\n";
		$_schema .= 'mapTypeId: google.maps.MapTypeId.ROADMAP'. "\n";
		$_schema .= '};'. "\n";

	$_schema .= "var map = new google.maps.Map(document.getElementById('map'), options);". "\n";
	fwrite($myfile, $_schema);



	for( $i=0; $i<$record; $i++ ){
		if( $trovato[$i] =="1"	){
			$numero_sedi=0;
			$numero_anagrafica=1;
			$rs_conta="11";
			$rs_ana = $dbo->fetchArray("SELECT ragione_sociale , indirizzo , citta , lat , lng , colore_marker FROM an_anagrafiche WHERE lat<>'' and lng<>'' and idanagrafica='".$rs_tutti[$i]['idanagrafica']."'");

			$contatore=$numero_anagrafica ;


			$testo=$id_anagrafica[$i]."-".$rs_ana[$i]['ragione_sociale']." - ".$rs_ana[$i]['indirizzo'];
			$colore_marker=  $colore[$i];
			$testo=  $id_anagrafica[$i]."-".$testo_tips[$i];
			$_schema ='var pinImage = new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/'.$colore_marker.'/");'. "\n";
			$testo = str_replace( "'", "", $testo );
			$_schema .=  "var marker = new google.maps.Marker({ position: latlng".$i.",". "\n";
			$_schema .= "		map: map, ". "\n";
			$_schema .="		icon: pinImage,". "\n";
			$_schema .= "		title: '".$testo."' });". "\n";
			fwrite($myfile, $_schema);
		}
	}

	$_chiusura = '}'. "\n";
	$_chiusura .= 'window.onload = initialize;'. "\n";
	$_chiusura .= '</script>'. "\n";
	$_chiusura .= '</head>'. "\n";
	$_chiusura .= '<body style="margin:0; padding:0;">'. "\n";
	$_chiusura .= '<div id="map" style="width:100%; height:100%"></div>'. "\n";
	$_chiusura .= '</body>'. "\n";
	$_chiusura .= '</html>'. "\n";

	fwrite($myfile, $_chiusura);









	fclose($myfile);



}








?>