<?php
if ($id_record==""){
	$cmp = get_componenti( $docroot."/files/my_impianti/" );

	echo "				<table data-idmodule='".$id_module."' class='datatables table table-striped table-hover table-condensed table-bordered'>\n";

	echo "				<thead>\n";
	echo "					<tr>\n";
	echo "						<th id=\"id\" width=\"10%\" >#</th>\n";
	echo "						<th id=\"nomefile\">Nome file</th>\n";
	echo "					</tr>\n";
	echo "				</thead>\n";


	//Loop record
	echo "				<tbody>\n";
	
	for( $c=0; $c<sizeof($cmp); $c++ ){
	
		$link = "editor.php?id_module=".$modules_info['Gestione componenti']['id']."&id_record=".$c;
		
		echo "					<tr class=\"clickable\" onclick=\"location.href='".$link."';\"  >\n";
		echo "<td>".$c."</td>";
		echo "<td>".$cmp[$c][0]."</td>";
		echo "					</tr>\n";
	}

	echo "				</tbody>\n";
			
	echo "				</table>\n";
	echo '
<script>
$(".datatables").DataTable({
        "oLanguage": {
            "sUrl": "<?php echo $js ?>/i18n/datatables/jquery.datatables.lang-<?php echo $lang ?>.min.js"
        },
        "bPaginate": false,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": true,
        "bInfo": false,
        "iDisplayLength": -1,
        "aaSorting": [],
        "fixedColumns": true
	});
</script>';
}

else if ($id_record != ""){
?>
		<form action="<?php echo $link; ?>" method="post" role="form" enctype="multipart/form-data">
		
			<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 ?>">

			<!-- DATI ANAGRAFICI -->
			<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
				<div class="panel-heading">
					<h3 class="panel-title">Componente</h3>
				</div>

				<div class="panel-body">

					
					<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>			
					<div class="clearfix"></div>
					
				</div>
				
				<div class="clearfix"></div>
					
					
					
					
					<div class="row">
						
						<div class="col-md-6">
						
						<div class="form-group">
							<label for="nomefile">Nome file*</label>
							<input value="<?php echo $nomefile; ?>" required="true" id="nomefile" name="nomefile" class="form-control " data-parsley-id="4" readonly>
						</div>
	
						</div>
					</div>
					
					
					<div class="row">
						<div class="col-md-12">
							<div class="form-group">
								<label for="contenuto">Contenuto</label>
								<textarea id="contenuto" name="contenuto" class="form-control autosize" data-parsley-id="8"  rows="10" ><?php echo $contenuto; ?></textarea>
							</div>
						</div>
					</div>
					
				</div>
			</div>
		</form>
		
		
		<form id="form-delete" role="form" method="post" action="" novalidate="">
			<input type="hidden" value="record-list" name="backto">
			<input type="hidden" value="delete" name="op">
			<input type="hidden" value="<?php echo $nomefile; ?>" name="nomefile">
		</form>

<?php
}	
?>
<script>		
	$('.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>
