<table id="models">
	<thead>
		<tr>
			<th width="150">Modell</th>
			<th>Erstinstallation</th>
			<th>Aktualisierung</th>
		</tr>
	</thead>
	<tbody>

<?php
$modelsfile = 'https://firmware.ffho.net/models.json';
$lines = file($modelsfile);
foreach($lines as $line)
	$data .= $line;
$data = json_decode($data, $assoc=TRUE);
ksort($data);

function linkOpenwrt($model) {
	print '<a href="https://openwrt.org/start?do=search&q=';
	print $model['vendor'].'/'.$model['model'];
	print '" target="_new">Info</a>';
}

function linkFirmware($model, $factory=False) {
	print '<a href="https://firmware.ffho.net/stable/';
	if ($factory)
		print 'factory';
	else
		print 'sysupgrade';
	print '/gluon-ffho-'.$model['imageversion'].'-'.$model['firmware'];
	if (!$factory)
		print '-sysupgrade';
	print '.'.$model['imagetype'];
	print '" target="_new">';
	if ($factory)
		print 'Erstinstallation';
	else
		if ($model['factory'])
			print 'Updatefile';
		else
			print 'Erstinstallation / Updatefile';
	print '</a>';
}


foreach (array_keys($data) as $vendor) {
	print '<tr><th colspan="3">'.$vendor."</th></tr>\n";
	$models = $data[$vendor];
	ksort($models);
	foreach ($models as $model) {
		print '<tr><td>'.$model['model'].'<br>'.linkInfo($model).'</td><td>';
		if ($model['factory'] == True) {
			linkFirmware($model, True);
		}
		print '</td><td>';
		linkFirmware($model);
		print "</td></tr>\n";
	}
}

?>
</tbody>
</table>