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 table.vpsinfo th
{ {
width: 150px; width: 150px;
text-align: right;
} }
table.console th table.console th

@ -96,3 +96,70 @@ function first_unused_ctid()
return $highest + 1; 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-burstable; Burstable RAM
overview-title-disk; Disk space overview-title-disk; Disk space
overview-title-traffic; Traffic overview-title-traffic; Traffic
overview-title-traffic-incoming; Incoming traffic
overview-title-traffic-outgoing; Outgoing traffic
overview-title-bandwidth; Bandwidth overview-title-bandwidth; Bandwidth
overview-status-running; Running overview-status-running; Running
overview-status-stopped; Stopped overview-status-stopped; Stopped

@ -67,5 +67,8 @@ var_dump(
parse_size("20gb", 1000), parse_size("14.6 TiB", 1000), parse_size("84YB") parse_size("20gb", 1000), parse_size("14.6 TiB", 1000), parse_size("84YB")
); );
*/ */
/*
var_dump(first_unused_ctid()); 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", 'guaranteed-ram' => "{$sContainer->sGuaranteedRam}MB",
'burstable-ram' => "{$sContainer->sBurstableRam}MB", 'burstable-ram' => "{$sContainer->sBurstableRam}MB",
'disk-space' => "{$sContainer->sDiskSpace}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", 'bandwidth-limit' => "100mbit",
'status' => $sContainer->sStatusText, 'status' => $sContainer->sStatusText,
'traffic-used' => number_format(($sContainer->sIncomingTrafficUsed + $sContainer->sOutgoingTrafficUsed) / 1024 / 1024 / 1024, 2), 'traffic-used' => number_format(($sContainer->sIncomingTrafficUsed + $sContainer->sOutgoingTrafficUsed) / 1024 / 1024 / 1024, 2),

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

Loading…
Cancel
Save