
<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
		$_SESSION['filtro_categoria']="0";
		$_SESSION['filtro_fornitore']="0";
		
		$rootdir1="";
        $mappaTmp = " SELECT indirizzo,citta,cellulare,cap,ragione_sociale , id_anagrafica FROM an_anagrafiche_prospect WHERE id=\"".$id_record."\" ";
		$rsmappa = $dbo->fetchArray( $mappaTmp );
		$id_ind = $rsmappa[0]['indirizzo'];
        $id_ragsoc = $rsmappa[0]['ragione_sociale'];
        $id_citta = $rsmappa[0]['citta'];
        $id_cap = $rsmappa[0]['cap'];
		 $id_anagrafica = $rsmappa[0]['id_anagrafica'];
        $id_tel = "tel://" . $rsmappa[0]['cellulare'];
		$id_mappa= $id_ind . " " . $id_citta . " " . $id_cap;
		$google = get_var('Google Maps API key');
		include ($docroot . "/modules/anagrafiche/avvisi.php");	
		// lettura id module_name
		$module_name1="Agenda";
		$id_modulo_agenda=$modules_info[$module_name1]['id'];

		$read="readonly";
		
    ?>


	<?php
		if( $records[0]['deleted'] == '0' ){	
		$read="";
	?>
	
	
	<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>																		
				<button type="button" class="btn-app btn-primary" data-href="<?php echo $rootdir ?>/modules/anagrafiche_prospect/edit_pianifica.php?id_module=<?php echo $id_module ?>&idanagrafica=<?php echo $idanagrafica ?>&id_record=<?php echo $id_record ?>" data-toggle="modal" data-title="Crea transazione" data-target="#bs-popup"><i class="fa fa-plus"></i>Appuntamento</a>										
			</div>
		</div>
		<div class="col-md-4">				
			<div class="pull-left">														
				<div class="pull-left showcase sweet"> 		
					<button type="button" class="btn-app btn-danger"  ><i class="fa fa-trash-o"></i> Elimina</span></button>	
				</div>				
			</div>
			<div class="pull-left">							
				<div class="pull-left showcase sweet_cliente"> 		
					<button type="button" class="btn-app btn-primary"  ><i class="fa fa-users"></i> Trasforma in Cliente</span></button>	
				</div>		
			</div>	
		</div>
		
		<div class="col-md-4">
			<div class="pull-right">	
				<div class="btn-group">
					<button type="button" class="btn btn-app btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-th"></i>Contatta <span class="caret"></span>
					<span class="sr-only">Toggle Dropdown</span></button>
					<ul class="dropdown-menu dropdown-menu-right">
						<li><a onclick="launch_modal( 'Invio SMS tramite E-mail', '<?php echo $rootdir ?>/modules/anagrafiche_prospect/mail_sms.php?id_module=<?php echo $id_module ?>&idanagrafica=<?php echo $id_record ?>',1);"><i class="fa fa-comments-o"></i> Mail to SMS</a></a> </li>
						<li><a onclick="launch_modal( 'Invio messaggio E-mail', '<?php echo $rootdir ?>/modules/anagrafiche_prospect/mail_pdf.php?id_module=<?php echo $id_module ?>&idanagrafica=<?php echo $id_record ?>',1);"><i class="fa fa-envelope"></i> Invia Mail</a>	</li>
					
					</ul>
				</div>	
				<div class="btn-group">
					<button type="button" class="btn btn-app btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-th"></i>Funzioni <span class="caret"></span>
					<span class="sr-only">Toggle Dropdown</span></button>

					<ul class="dropdown-menu dropdown-menu-right">
						<li><a  target="_blank" href="<?php echo $rootdir1 ?>https://www.google.it/maps/place/<?php echo $id_mappa ?>"><i class="fa fa-map-marker"></i> Google Maps</a> </li>
						<li><a  target="_blank" href="<?php echo $id_tel ?>"><i class="fa fa-mobile"></i> Chiama Ora</a></li>
					</ul>
				</div>		
			</div>			
		</div>			
		<div class="clearfix"></div>
		
	</div>
	<?php
	}	
	?>	

	
	<!-- Creazione Pannelli -->
	<ul class="nav nav-pills nav-justified" role="tablist"> 
		<li role="presentation" class="active"><a href="#principale" aria-controls="principale" role="tab" data-toggle="tab">Principale</a></li>
		<li role="presentation"><a href="#personalizza" aria-controls="personalizza" role="tab" data-toggle="tab">Moduli personalizzati</a></li>	
		<li role="presentation"><a href="#allegati" aria-controls="allegati" role="tab" data-toggle="tab">Allegati</a></li>				
    </ul>
	<div class="tab-content">
		<!-- Principale -->
		<div role="tabpanel" class="tab-pane active" id="principale">
			<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">				
				<div class="panel-body">		
					<div class="row">
						<div class="col-md-4">
							{[ "type": "text", "label": "Ragione sociale Prospect", "name": "ragione_sociale", "required": 1, "class": "", "value": "$ragione_sociale$", "extra": "<?php echo $read ?>" ]}
						</div>
						<div class="col-md-2">
							{[ "type": "text", "label": "Codice", "name": "codice", "required": 1, "class": "text-center", "value": "$codice$", "extra": "<?php echo $read ?>" ]}
						</div>
						<div class="col-md-2">
							{[ "type": "text", "label": "Nome", "name": "nome", "required": 1, "class": "text-center", "value": "$nome$", "extra": "<?php echo $read ?>" ]}
						</div>
						<div class="col-md-3">
							{[ "type": "text", "label": "Cognome", "name": "cognome", "required": 1, "class": "text-center", "value": "$cognome$", "extra": "<?php echo $read ?>" ]}
						</div>

					</div>

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

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

					</div>
				</div>
			</div>
			
			<!-- Creazione Pannelli -->
			
			<ul class="nav nav-pills nav-justified" role="tablist">
				<li role="presentation" class="active"><a href="#contatti" aria-controls="contatti" role="tab" data-toggle="tab">Contatti</a></li>
				<li role="presentation" ><a href="#interessi" aria-controls="interessi" role="tab" data-toggle="tab">Interessi</a></li>
				<li role="presentation" ><a href="#visite" aria-controls="visite" role="tab" data-toggle="tab">Visite</a></li>
			</ul>
			
			<div class="tab-content">
				<!-- CONTATTI -->
				<div role="tabpanel" class="tab-pane active" id="contatti">
					<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">					
						<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": "<?php echo $read ?>", "icon-before": "<i class='fa fa-phone'></i>" ]}
								</div>
					
								<div class="col-md-4">
									{[ "type": "text", "label": "Fax", "name": "fax", "required": 0, "class": "text-center", "value": "$fax$", "extra": "<?php echo $read ?>", "icon-before": "<i class='fa fa-fax'></i>" ]}
								</div>
					
								<div class="col-md-4">
									{[ "type": "text", "label": "Cellulare", "name": "cellulare", "required": 0, "class": "text-center", "value": "$cellulare$", "extra": "<?php echo $read ?>", "icon-before": "<i class='fa fa-mobile'></i>" ]}
								</div>
							</div>		
							<div class="row">
								<div class="col-md-4">
									{[ "type": "text", "label": "Email", "name": "email", "required": 0, "class": "", "value": "$email$", "extra": "<?php echo $read ?>", "icon-before": "<i class='fa fa-envelope'></i>" ]}
								</div>			
								<div class="col-md-4">
									{[ "type": "text", "label": "Sito web", "name": "sitoweb", "required": 0, "class": "", "value": "$sitoweb$", "extra": "<?php echo $read ?>", "icon-before": "<i class='fa fa-globe'></i>" ]}
								</div>			

							</div>
							
							

						</div>	
					</div>
				</div>
				<!-- INTERESSI -->
				<div role="tabpanel" class="tab-pane" id="interessi">
					<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">					
						<div class="panel-body">
							<div class="row">
								<div class="col-md-12">
									<div class="pull-left">								
										<a class="btn btn-sm btn-info" data-href="<?php echo $rootdir ?>/modules/anagrafiche_prospect/add_articolo.php?iddocumento=<?php echo $id_record ?>&dir=<?php echo $dir ?>" data-toggle="modal" data-title="Interesse" data-target="#bs-popup"><i class="fa fa-plus"></i> Interesse</a>																					
									</div>
								</div>
							</div>
							<div class="clearfix"></div>
							<br>
							<div class="row">													
								<div class="col-md-12">
									<table class="table table-striped table-hover table-condensed">
										<tr>
											<th width='20%'>Articolo</th>											
											<th width='75%'>Descrizione</th>
											<th width='5%'></th>
										</tr>					
									<?php include($docroot."/modules/anagrafiche_prospect/row-list.php"); ?>
									</table>
								</div>														
							</div>	
						</div>	
			
					</div>
				</div>
				
				<!-- VISITE -->
				<div role="tabpanel" class="tab-pane" id="visite">
					<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">					
						<div class="panel-body">
							<div class="row">													
								<div class="col-md-12">
									<table class="table table-striped table-hover table-condensed">
										<tr>
											<th width='50%'>Articolo</th>											
											<th width='45%'>Descrizione</th>
											<th width='5%'></th>
										</tr>					
									<?php include($docroot."/modules/anagrafiche_prospect/row-list-visite.php"); ?>
									</table>
								</div>														
							</div>	
						</div>	
					</div>
				</div>
			</div>	
		</div>
		
		
		
		<div role="tabpanel" class="tab-pane " id="allegati">	
			<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">					
				<div class="panel-body">											
					<?php
						echo filelist_and_upload( $module_name, $id_record );					
					?>															
				</div>
			</div>
		</div>

		<!-- Moduli personalizzati -->
		<div role="tabpanel" class="tab-pane" id="personalizza">
			<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">				
				<div class="panel-body">					
					<?php
	
						/* necesario per funzione get_componenti */
						include($docroot."/modules/my_impianti/modutil.php");
						echo "<div class='row'>\n";
						echo "	<div class='col-md-4'>\n";
						echo "		<div class='form-group'>\n";
						echo "		<label for='componente_filename'>Seleziona un componente:</label>\n";
						echo "		<select class=\"form-control\" id=\"componente_filename\" name=\"componente_filename\" onchange=\"$.post( '".$rootdir."/modules/my_impianti/actions.php', {op: 'load_componente', idarticolo: '".$id_record."', filename: $(this).find('option:selected').val() }, function(response){ $('#info_componente').html( response ); } );\">\n";
						echo "			<option value=\"0\">- Collega ad un componente -</option>";
						$cmp = get_componenti( $docroot."/files/my_impianti/", '' );
						if( sizeof($cmp)>0 ){	
							for( $c=0; $c<sizeof($cmp); $c++ ){
								( $records[0]['componente_filename'] == $cmp[$c][0] ) ? $attr='selected="selected"' : $attr='';
								echo "<option value=\"".$cmp[$c][0]."\" $attr>".$cmp[$c][1]."</option>\n";
							}
						}	
						echo "		</select>\n";
						echo "		</div>\n";
						echo "	</div>\n";
						echo "</div>\n";
						echo "<div id='info_componente'>\n";
						genera_form_componente( $records[0]['componente_filename'], $records[0]['contenuto'] );	
						echo "</div>\n";
					?>
					<div class="pull-right">
						<button type="submit" class="btn btn-app btn-success"><i class="fa fa-check"></i> Salva </button>			
					</div>	
					</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>
<form action="" method="post" role="form" id="form-trasforma">
	<input type="hidden" name="backto" value="record-list">
	<input type="hidden" name="op" value="trasforma">
</form>

<script>

	var id_module = "<?php echo $_GET['id_module'] ?>";
	
	
	
	$('#idcategoria').change( function(){ 			
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=FiltroCat&idcategoria='+this.value+'&idmodulo='+id_module , function(data,response){ 				
		start_jquerychosen();
			start_inputmask();		
		});	
	});	
	
	$('#filtro').change( function(){ 	
		$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=Filtro&idfiltro='+this.value+'&idmodulo='+id_module , function(data,response){ 				
		start_jquerychosen();
			start_inputmask();		
		});	
	});	
	
 
	
	$(document).ready( function(){
		$('.colorpicker').colorpicker().on('changeColor', function(){
			$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
		});

		$('#colore').parent().find('.square').css( 'background', $('#colore').val() );
	});
	
	$('.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(); }
		  }
		})
	})
	$('.showcase.sweet_cliente button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Trasformalo in Cliente!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			{ $('#form-trasforma').submit(); }
		  }
		})
	})
	

	  
</script>

