<?php



	$rs = $dbo->fetchArray("select id as idwizard , descrizione from co_tipidocumento_wizard");	
	$n2 = sizeof($rs);
	
	$rs_ana = $dbo->fetchArray("select idanagrafica as idanagrafica , ragione_sociale as descrizione from an_anagrafiche");	
	$n3 = sizeof($rs_ana);
	

	$module_name = 'Crea wizard';
	
	echo "<div class='panel panel-primary'>\n";
		echo "<div class='panel-heading'>\n";
			echo "	<h3 class='panel-title'>Dati</h3>\n";
		echo "	</div>\n";
		echo "<div class='panel-body'>\n";
		echo "<div class='row'>\n";
			echo "	<div class='col-md-12'>\n";
		//		echo "		<h3>Seleziona Modello Documento Wizard</h3>\n";
				echo "<form action=\"".$rootdir."/controller.php?id_module=".$modules_info[$module_name]['id']."\" method=\"post\" role=\"form\"  id='new-module'>\n";		
				echo "	<input type='hidden' name='op' value='upload'>\n";	  
			echo "	</div>\n";	
		echo "</div>\n";	


		echo "<div class='row'>\n";
			//Seleziona tipologia documento
			echo "		<div class='col-md-6'>\n";
				echo "			<div class='form-group'>\n";
				echo "				<label>Documento Wizard</label>\n";	
				if( ($n2) == 0 ){
					echo "				... Non ci sono tipologie modelli documenti wizard in archivio ...<br><br>\n";
					echo "				<input type=\"hidden\" id=\"idwizard\" value=\"\">\n";
				}	
				else{
					echo "				<select id=\"idwizard\" name=\"idwizard\" class=\"superselect\" onchange=\"$('#descrizione').val( $(this).find(':selected').text() );  ;\">\n";
					echo "				<option value=\"\">- Seleziona una tipologia -</option>\n";					
					for( $i=0;$i<$n2;$i++ ){					
						echo "				<option value=\"".$rs[$i]['idwizard']."\"  >".$rs[$i]['descrizione']." </option>\n";
					}		
					echo "				</optgroup>\n";
				}	
				echo "				</select>\n";		
				echo "		</div>\n";	
			echo "		</div>\n";	
	

			//Seleziona Anagrafica
			echo "		<div class='col-md-6'>\n";
			echo "			<div class='form-group'>\n";
			echo "				<label>Anagrafica</label>\n";	
			if( ($n3) == 0 ){
				echo "				... Non ci sono anagrafiche in archivio ...<br><br>\n";
				echo "				<input type=\"hidden\" id=\"idanagrafica\" value=\"\">\n";
			}	
			else{
				echo "				<select id=\"idanagrafica\" name=\"idanagrafica\" class=\"superselect\" onchange=\"$('#descrizione').val( $(this).find(':selected').text() );  ;\">\n";
				echo "				<option value=\"\">- Seleziona una Anagrafica -</option>\n";				
				for( $i=0;$i<$n3;$i++ ){					
					echo "				<option value=\"".$rs_ana[$i]['idanagrafica']."\"  >".$rs_ana[$i]['descrizione']." </option>\n";
				}		
				echo "				</optgroup>\n";
			}	
			echo "				</select>\n";
			echo "			</div>\n";
			echo "		</div>\n";	
		echo "</div>\n";	
	
	
	
	$giorno_uno="1";
	$giorno_due="31";
	
		echo "<div class='row'>\n";
			echo "	<div class='col-md-2'>\n";	
				echo "		<label>Dalla Data </label>\n";	
				echo "		<div class='form-group'>\n";				
				echo "			<input type='text' class='form-control  datepicker text-center '  id='data_i' name='data_i' required=\"true\" value=\"".$giorno_uno."/".date("m")."/".date("Y")."\">\n";												
				echo "		</div>\n";
			echo "	</div>\n";
			echo "	<div class='col-md-2'>\n";	
				echo "		<label>Alla Data </label>\n";	
				echo "		<div class='form-group'>\n";				
				echo "			<input type='text' class='form-control  datepicker text-center '  id='data_f' name='data_f' required=\"true\" value=\"".$giorno_due."/".date("m")."/".date("Y")."\">\n";												
				echo "		</div>\n";
			echo "	</div>\n";	
		echo "</div>\n";	
	

	
		echo "		</br>\n";	
	
	
	
		echo "<div class='row'>\n";	
			echo "<div class='col-md-4'>\n";			
			echo "		<div class='pull-left'>\n";								
			echo "			<div class='pull-left showcase sweet'>\n";		
			echo "			<button type='button'class='btn-app btn-primary'  ><i class='fa fa-plus'></i> Crea documento</span></button>	\n";
			echo "			</div>\n";				
			echo "		</div>\n";
			echo "	</div>\n";
		echo "</div>\n";	
	
	
		echo "</form><br>\n\n";
	
		echo "	</div>\n";
	echo "	</div>\n";


?>
  <script type="text/javascript">

		$('.datepicker').datepicker();
		$('.timepicker').timepicker()
		
		
		$(document).ready( function(){
			start_superselect();
			start_inputmask();
		});
		
		$('.showcase.sweet button').on('click', () => {
		swal({
		  title: 'Sei sicuro?',
		  text: "Creazione Documento Wizard!",
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: 'Conferma!'
		}).then((result) => {
		  if (result.value) {			
			{ $('#new-module').submit(); }
		  }
		})
	})	

</script> 
	

