<?php
// read the config file and set the conversion factors
$conffile = 'metalshop.conf';
$string = file_get_contents($conffile);
if(strpos($string, "#length = foot")===FALSE)
{
//foot not turned off
//wants metres
$l_unit = '100 ft';
$l_conv = 0.3048;
}
else
{
//foot turned off
//wants foot
$l_unit = '100 m';
$l_conv = 1;
}
if(strpos($string, "#weight = pound")===FALSE)
{
//pound not turned off
//wants kilograms
$w_unit = '1 oz';
$w_conv = 0.2835;
}
else
{
// pound turned off
// wants pounds
$w_unit = '100 g';
$w_conv = 1;
}
// read and unserialise the product prices array
$arrayfile = 'metalshop.array';
$arraystrings = file_get_contents($arrayfile);
$product_prices = unserialize($arraystrings);
// write the table as the main portion of the web page
print <<<THEAD
THEAD;
// write the column headers with the right units
// write each row in the right units and decimal places
foreach ($product_prices as $metal => $prices)
{
"
$metal |
".
round($prices[wire][28]*$l_conv*$w_conv,4).
" |
$metal |
".
round($prices[wire][36]*$l_conv*$w_conv,4).
" |
$metal |
".
round($prices[wire][45]*$l_conv*$w_conv,4).
" |
$metal |
".
round($prices[wire][100]*$l_conv*$w_conv,4).
" |
$metal |
".
round($prices[wire][10]*$l_conv*$w_conv,4).
" |
$metal |
".
round($prices[wire][1]*$l_conv*$w_conv,4).
" |
";
}
?>