Reformat VPS configuration table, and properly format numbers in the table

feature/node-rewrite
Sven Slootweg 12 years ago
parent 640fb23892
commit dd778c58ef

@ -81,6 +81,7 @@ table.console
table.vpsinfo th
{
width: 150px;
text-align: right;
}
table.console th

@ -96,3 +96,70 @@ function first_unused_ctid()
return $highest + 1;
}
}
function format_size($input, $multiplier = 1024, $group = false, $decimal_places = 0, $return_array = false)
{
if($input > pow($multiplier, 8))
{
$unit = "Y";
$number = $input / pow($multiplier, 8);
}
elseif($input > pow($multiplier, 7))
{
$unit = "Z";
$number = $input / pow($multiplier, 7);
}
elseif($input > pow($multiplier, 6))
{
$unit = "E";
$number = $input / pow($multiplier, 6);
}
elseif($input > pow($multiplier, 5))
{
$unit = "P";
$number = $input / pow($multiplier, 5);
}
elseif($input > pow($multiplier, 4))
{
$unit = "T";
$number = $input / pow($multiplier, 4);
}
elseif($input > pow($multiplier, 3))
{
$unit = "G";
$number = $input / pow($multiplier, 3);
}
elseif($input > pow($multiplier, 2))
{
$unit = "M";
$number = $input / pow($multiplier, 2);
}
elseif($input > $multiplier)
{
$unit = "K";
$number = $input / $multiplier;
}
else
{
$unit = "";
$number = $input;
}
if($group === true)
{
$number = number_format($number, $decimal_places);
}
else
{
$number = round($number, $decimal_places);
}
if($return_array == true)
{
return array($number, $unit);
}
else
{
return $number . $unit;
}
}

@ -95,6 +95,8 @@ overview-title-guaranteed; Guaranteed RAM
overview-title-burstable; Burstable RAM
overview-title-disk; Disk space
overview-title-traffic; Traffic
overview-title-traffic-incoming; Incoming traffic
overview-title-traffic-outgoing; Outgoing traffic
overview-title-bandwidth; Bandwidth
overview-status-running; Running
overview-status-stopped; Stopped

@ -67,5 +67,8 @@ var_dump(
parse_size("20gb", 1000), parse_size("14.6 TiB", 1000), parse_size("84YB")
);
*/
/*
var_dump(first_unused_ctid());
*/
var_dump(format_size(900), format_size(900000), format_size(900000000), format_size(900000000000), format_size(900000000000000), format_size(9000000000000000));

@ -45,7 +45,9 @@ $sVariables = array(
'guaranteed-ram' => "{$sContainer->sGuaranteedRam}MB",
'burstable-ram' => "{$sContainer->sBurstableRam}MB",
'disk-space' => "{$sContainer->sDiskSpace}MB",
'total-traffic-limit' => "{$sContainer->sTotalTrafficLimit} bytes",
'total-traffic-limit' => format_size($sContainer->sTotalTrafficLimit, 1024, true, 0) . "B",
'incoming-traffic-limit'=> format_size($sContainer->sIncomingTrafficLimit, 1024, true, 0) . "B",
'outgoing-traffic-limit'=> format_size($sContainer->sOutgoingTrafficLimit, 1024, true, 0) . "B",
'bandwidth-limit' => "100mbit",
'status' => $sContainer->sStatusText,
'traffic-used' => number_format(($sContainer->sIncomingTrafficUsed + $sContainer->sOutgoingTrafficUsed) / 1024 / 1024 / 1024, 2),

@ -56,42 +56,43 @@
<span class="unknown">{%!overview-status-unknown}</span>
{%/if}
</td>
</tr>
<tr>
<th>{%!overview-title-location}</th>
<td>{%?server-location}</td>
</tr>
<tr>
<th>{%!overview-title-os}</th>
<td>{%?operating-system}</td>
</tr>
<tr>
<th>{%!overview-title-ipv4}</th>
<td></td>
</tr>
<tr>
<th>{%!overview-title-ipv6}</th>
<td></td>
</tr>
<tr>
<th>{%!overview-title-guaranteed}</th>
<td>{%?guaranteed-ram}</td>
</tr>
<tr>
<th>{%!overview-title-burstable}</th>
<td>{%?burstable-ram}</td>
</tr>
<tr>
<th>{%!overview-title-disk}</th>
<td>{%?disk-space}</td>
<th>{%!overview-title-bandwidth}</th>
<td>{%?bandwidth-limit}</td>
</tr>
<tr>
{%if total-traffic-limit == "0B"}
<th>{%!overview-title-traffic-incoming}</th>
<td>{%?incoming-traffic-limit}</td>
<th>{%!overview-title-traffic-outgoing}</th>
<td>{%?outgoing-traffic-limit}</td>
{%else}
<th>{%!overview-title-traffic}</th>
<td>{%?total-traffic-limit}</td>
<td colspan="3">{%?total-traffic-limit}</td>
{%/if}
</tr>
<tr>
<th>{%!overview-title-bandwidth}</th>
<td>{%?bandwidth-limit}</td>
<th>{%!overview-title-location}</th>
<td colspan="3">{%?server-location}</td>
</tr>
<tr>
<th>{%!overview-title-ipv4}</th>
<td colspan="3"></td>
</tr>
<tr>
<th>{%!overview-title-ipv6}</th>
<td colspan="3"></td>
</tr>
</table>

Loading…
Cancel
Save