<?php
	$upload_max_filesize = ini_get("upload_max_filesize");
	$post_max_size = ini_get("post_max_size");
	$upload_max_filesize = str_replace( "k", "000", $upload_max_filesize );
	$upload_max_filesize = str_replace( "M", "000000", $upload_max_filesize );
	$post_max_size = str_replace( "k", "000", $post_max_size );
	$post_max_size = str_replace( "M", "000000", $post_max_size );
	
	//Dimensione minima: 12MB
	$alerts = '';
	
	if( $upload_max_filesize < 16000000 ){
		$alerts .= "Devi modificare il tuo <b>php.ini</b> impostando <b>upload_max_filesize</b> almeno a 16MB altrimenti non riuscirai a caricare l&rsquo;aggiornamento.<br>";
	}
	
	if( $post_max_size < 16000000 ){
		$alerts .= "Devi modificare il tuo <b>php.ini</b> impostando <b>post_max_size</b> almeno a 16MB altrimenti non riuscirai a caricare l&rsquo;aggiornamento.<br>";
	}
	
	if( strlen($alerts) > 0 ){
		echo "<div class='alert alert-warning'>".$alerts."</div>\n";
	}
	


	//UPLOAD MODULO
	if( get_var("Attiva aggiornamenti") ){
		echo "<br><br>\n";
	
		echo "<form action=\"".$rootdir."/controller.php?id_module=".$id_module."\" method=\"post\" enctype=\"multipart/form-data\" class='form-inline' id='new-module'>\n";
		echo "	<input type='hidden' name='op' value='upload'>\n";
	
		echo "	<label>Carica un </label>\n";
		echo "	<select class=\"form-control\" name=\"type\">\n";
		echo "		<option value=\"new\">Nuovo/Aggiorna Modulo</option>\n";
		echo "	</select>\n";
		echo "	<br><br>\n\n";
	
		echo "	<label><input type=\"file\" name=\"blob\"></label><button type='button' class='btn btn-app btn-success' onclick=\"if( confirm('Avviare la procedura?') ){ $('#new-module').submit(); }\"><i class='fa fa-upload'></i> Carica...</button>\n";
		echo "</form><br>\n\n";
	}


	/*
		Elenco moduli installati
	*/
	$query = "SELECT * FROM zz_modules WHERE parent=0 and moduli_add = 1 ORDER BY `order` ASC";
	$rs = $dbo->fetchArray($query);
	
	
	
	echo "<div class='row'>\n";
	echo "	<div class='col-md-12 col-lg-6'>\n";
	
	echo "		<h3>Moduli Aggiuntivi installati</h3>\n";
	
	echo "		<table class='table table-hover table-bordered table-condensed'>\n";
	echo "		<tr><th>Nome</th>\n";
	echo "		<th width='50'>Versione</th>\n";
	echo "		<th width='30'>Stato</th>\n";
	echo "		<th width='30'>Compatibilit&agrave;</th>\n";
	echo "		<th width='20'></th></tr>\n";
	
	$osm_version = getVersion();

	for( $m=0; $m<sizeof($rs); $m++ ){
		//Prima di cambiare modulo verifico se ci sono sottomoduli
		if( $m > 0 && $rs[$m]['id'] != $rs[$m-1]['id'] ){
			$query2 = "SELECT * FROM zz_modules WHERE parent='".$rs[$m-1]['id']."' ORDER BY `order` ASC";
			$rs2 = $dbo->fetchArray($query2);

			for( $m2=0; $m2<sizeof($rs2); $m2++ ){
				$compatibility = explode( ',', $rs2[$m2]['compatibility'] );
				for( $i=0; $i<sizeof($compatibility); $i++ ){
						$compatible = "		<i class='fa fa-check-circle text-success' data-toggle='tooltip' title='Compatibile'></i>";
						$class = "success";
				}

				//NOME
				echo "		<tr class='".$class."'><td><small>&nbsp;&nbsp;- ".$rs2[$m2]['name']."</small></td>\n";
				echo "		<td align='right'>".$rs2[$m2]['version']."</td>\n";
				echo "		<td align='center'>".$stato."</td>\n";	

				//COMPATIBILITA'
				echo "		<td align='center'>".$compatible."</td>\n";
				echo "		<td>\n";		
				echo "		</td></tr>\n";
			}
		}
	
		
		
		$compatibility = explode( ',', $rs[$m]['compatibility'] );

	
		$compatible = "		<i class='fa fa-check-circle text-success' data-toggle='tooltip' title='Compatibile'></i>";
		$class = "success";

		
		
		//STATO
		if( $rs[$m]['enabled'] ){
				$stato = "		<i class='fa fa-cog fa-spin text-success' data-toggle='tooltip' title=\"Abilitato\"></i>";
		}
		
		else{
			$stato = "		<i class='fa fa-cog text-warning' data-toggle='tooltip' title=\"Non abilitato\"></i>";
			
			if( $class != 'danger' ){
				$class = 'warning';
			}
		}
			

		//NOME
		echo "		<tr class='".$class."'><td>".$rs[$m]['name']."</td>\n";
		echo "		<td align='right'>".$rs[$m]['version']."</td>\n";
		

		echo "		<td align='center'>".$stato."</td>\n";	

		//COMPATIBILITA'
		echo "		<td align='center'>".$compatible."</td>\n";
		

		//Possibilità di disinstallare solo se non di default
		echo "		<td>\n";
		
		
		
		echo "		</td></tr>\n";
	}
	
	echo "		</table>\n";
	echo "	</div>\n";
	
	
	
	
	
	
	
?>