<script src="<?php echo $js ?>/bootstrap-colorpicker.min.js"></script>
<link rel="stylesheet" href="<?php echo $css ?>/bootstrap-colorpicker.min.css">


<form action="" method="post" role="form">
	<input type="hidden" name="backto" value="record-edit">
	<input type="hidden" name="op" value="update">
	<input type="hidden" name="id_record" value="<?php echo $id_record ?>">
	<?php
		$rootdir1="";
        $rs_tmp = " SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=\"".$records[0][idanagrafica]."\" ";
		$rs_anag = $dbo->fetchArray( $rs_tmp );
		$ragione_sociale=$rs_anag[0][ragione_sociale];
	
		$google = get_var('Google Maps API key');
					
    ?>		
	
	
<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="clearfix"></div>
		</br>	
		<div class="col-md-4">				
			<div class="pull-left">		
				<button type="submit" class="btn-app btn-success "><i class="fa fa-check"></i> Salva </button>									
			</div>
		</div>
		<div class="col-md-4">				
			<div class="pull-right">								
				<div class="pull-left showcase sweet"> 		
					<button type="button" class="btn-app btn-danger" aria-label="Show SweetAlert2 success message" ><i class="fa fa-trash-o"></i> Elimina</span></button>		 
				</div>				
			</div>	
		</div>
		
		<div class="col-md-4">
			<div class="pull-right">
				<a  class="btn btn-app btn-info" target="_blank" href="<?php echo $rootdir ?>/editor.php?id_module=2&id_record=<?php echo $records[0][idanagrafica] ?>"><i class="fa fa-user"></i>Anagrafica</a>		
			</div>	
		</div>			
		<div class="clearfix"></div>
		
	</div>
	
	<!-- DATI ANAGRAFICI -->
	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">SEDE Dati anagrafici </h3>
		</div>	
		<div class="panel-body">		
			<div class="row">
				<div class="col-md-6">
					{[ "type": "text", "label": "Nome sede", "name": "nomesede", "required": 1, "class": "", "value": "$nomesede$", "extra": "" ]}
				</div>
				<div class="col-md-6"
					<div class="form-group">														
						{[ "type": "text", "label": "Ragione Sociale", "class": "form-control", "value": "<?php echo $ragione_sociale?>", "extra": "readonly" ]}							
					</div>
			</div>
				

			<div class="row">
				<div class="col-md-4">
					{[ "type": "text", "label": "Partita iva", "maxlength": 13, "name": "piva", "required": 0, "class": "text-center", "value": "$piva$", "extra": "" ]}
				</div>
	
				<div class="col-md-4">
					{[ "type": "text", "label": "Codice fiscale", "maxlength": 16, "name": "codice_fiscale", "required": 0, "class": "text-center", "value": "$codice_fiscale$", "extra": "" ]}
				</div>
	
			</div>
		
			

			<div class="row">
				<div class="col-md-6">
					{[ "type": "text", "label": "Indirizzo", "name": "indirizzo", "required": 0, "class": "", "value": "$indirizzo$", "extra": "" ]}
				</div>
	
				<div class="col-md-6">
					{[ "type": "text", "label": "Indirizzo2", "name": "indirizzo2", "required": 0, "class": "", "value": "$indirizzo2$", "extra": "" ]}
				</div>
			</div>

			<div class="row">
				<div class="col-md-3">
					{[ "type": "select", "label": "Nazione", "name": "nazione", "required": 0, "class": "", "values": "query=SELECT nome AS id, nome AS descrizione FROM an_nazioni ORDER BY nome ASC", "value": "$nazione$", "extra": "" ]}
				</div>
			
				<div class="col-md-2">
					{[ "type": "text", "label": "C.A.P.", "name": "cap", "maxlength": 5, "required": 0, "class": "text-center", "value": "$cap$", "extra": "" ]}
				</div>
	
				<div class="col-md-3">
					{[ "type": "text", "label": "Città", "name": "citta", "required": 0, "class": "text-center", "value": "$citta$", "extra": "" ]}
				</div>
			
				<div class="col-md-2">
					{[ "type": "text", "label": "Provincia", "name": "provincia", "maxlength": 2, "required": 0, "class": "text-center", "value": "$provincia$", "extra": "" ]}
				</div>
				
				<div class="col-md-2">
					{[ "type": "text", "label": "Km", "name": "km", "maxlength": 4, "required": 0, "class": "inputmask-decimal text-center", "value": "$km$", "extra": "" ]}
				</div>
			</div>
		</div>
	</div>

	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">Riferimenti </h3>
		</div>	
		<div class="panel-body">							
			<div class="row">
				<div class="col-md-4">
					{[ "type": "text", "label": "Telefono", "name": "telefono", "required": 0, "class": "text-center", "value": "$telefono$", "extra": "", "icon-before": "<i class='fa fa-phone'></i>" ]}
				</div>
				<div class="col-md-4">
					{[ "type": "text", "label": "Cellulare", "name": "cellulare", "required": 0, "class": "text-center", "value": "$cellulare$", "extra": "", "icon-before": "<i class='fa fa-mobile'></i>" ]}
				</div>
				<div class="col-md-4">							
					{[ "type": "text", "label": "Email", "name": "email", "required": 0, "class": "", "value": "$email$", "extra": "", "icon-before": "<i class='fa fa-envelope'></i>" ]}
				</div>	
			
			</div>
			<div class="row">
			<div class="col-md-4">
				{[ "type": "text", "label": "Fax", "name": "fax", "required": 0, "class": "text-center", "value": "$fax$", "extra": "", "icon-before": "<i class='fa fa-fax'></i>" ]}
			</div>						
			<div class="col-md-4">
				{[ "type": "select", "label": "Zona", "name": "idzona", "required": 0, "class": "", "values": "query=SELECT id, CONCAT_WS( ' - ', nome, descrizione) AS descrizione FROM an_zone ORDER BY descrizione ASC", "value": "$idzona$", "extra": "" ]}
			</div>						
		</div>	
	</div>
	</div>
	
	<!-- Moduli personalizzati -->
		<div role="tabpanel" class="tab-pane" id="googlemaps">
			<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-3">
							{[ "type": "text", "label": "Latitudine", "name": "lat", "required": 0, "class": "", "value": "$lat$", "extra": "" ]}
						</div>			
						<div class="col-md-3">
							{[ "type": "text", "label": "Longitudine", "name": "lng", "required": 0, "class": "", "value": "$lng$", "extra": "" ]}
						</div>
						<div class="col-md-3">
							{[ "type": "text", "label": "Colore Mappa", "name": "colore_marker", "required": 0, "class": "colorpicker text-center", "value": "$colore_marker$", "extra": "maxlength='7'", "icon-after": "<div class='img-circle square'></div>" ]}
						</div>						
					</div>	
					<div class="pull-right">
						<button type="submit" class="btn btn-app btn-success"><i class="fa fa-check"></i> Salva </button>			
					</div>	
					<div class="clearfix"></div>
					</br>					
					<?php 
				
					
						 if (!empty($google) && ($records[0]['lat'] !='0.000000') && (!empty($records[0]['lat']) && !empty($records[0]['lng']))) {
						
						
						echo '
							<div id="map" style="width:100%;height:400px;"></div>';						
						} else {
							echo '
								<div class="alert alert-danger">
									Per abilitare la visualizzazione delle anagrafiche nella mappa, inserire le coordinate GPS e la Google Maps API Key nella menu Strumenti -  Opzioni generali - Generali
								</div>';
					}
					?>
				</div>
			</div>	
		</div>
		
		<?php include ($docroot . "/lib/campi_personalizzati.php");	?>
</form>

<form action="" method="post" role="form" id="form-delete">
	<input type="hidden" name="backto" value="record-list">
	<input type="hidden" name="op" value="delete">
</form>

<script>
	function myMap() {
	  var myCenter = new google.maps.LatLng($("#lat").val(),$("#lng").val());
	  var mapCanvas = document.getElementById("map");
	  var mapOptions = {center: myCenter, zoom: 15};
	  var map = new google.maps.Map(mapCanvas, mapOptions);
	  var marker = new google.maps.Marker({position:myCenter});
	  marker.setMap(map);
	}	
	
	
</script>
<?php 
	if (!empty($google)) {		
	echo '
		<script src="https://maps.googleapis.com/maps/api/js?key='.$google.'&callback=myMap"></script>';
	}
?>


<script>
	$(document).ready( function(){
		$('.colorpicker').colorpicker().on('changeColor', function(){
			$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
		});

		$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
	});
	
	
	function load_contratti( idcontratto ){
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=Contratti&op=get_costo_orario&idcontratto='+idcontratto, function(data){
			$('#costo_orario').val( data);					
		});
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=Contratti&op=get_costo_km&idcontratto='+idcontratto, function(data){
			$('#costo_km').val( data);					
		});
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=Contratti&op=get_costo_chiamata&idcontratto='+idcontratto, function(data){
			$('#costo_diritto_chiamata').val( data);					
		});
		
	}
	
	
	
	
	
	$('.showcase.sweet button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Eliminare questo elemento!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			{ $('#form-delete').submit(); }
		  }
		})
	})
	
	
	
	
</script>
