4 function convert_install() {
\r
5 register_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu');
\r
8 function convert_uninstall() {
\r
9 unregister_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu');
\r
12 function convert_app_menu($a,&$b) {
\r
13 $b['app_menu'] .= '<div class="app-title"><a href="convert">Units Conversion</a></div>';
\r
17 function convert_module() {}
\r
25 function convert_content($app) {
\r
27 include("UnitConvertor.php");
\r
29 class TP_Converter extends UnitConvertor {
\r
30 function TP_Converter($lang = "en")
\r
32 if ($lang != 'en' ) {
\r
33 $dec_point = '.'; $thousand_sep = "'";
\r
35 $dec_point = '.'; $thousand_sep = ",";
\r
38 $this->UnitConvertor($dec_point , $thousand_sep );
\r
40 } // end func UnitConvertor
\r
42 function find_base_unit($from,$to) {
\r
43 while (list($skey,$sval) = each($this->bases)) {
\r
44 if ($skey == $from || $to == $skey || in_array($to,$sval) || in_array($from,$sval)) {
\r
51 function getTable($value, $from_unit, $to_unit, $precision) {
\r
53 if ($base_unit = $this->find_base_unit($from_unit,$to_unit)) {
\r
55 // A baseunit was found now lets convert from -> $base_unit
\r
57 $cell ['value'] = $this->convert($value, $from_unit, $base_unit, $precision)." ".$base_unit;
\r
58 $cell ['class'] = ($base_unit == $from_unit || $base_unit == $to_unit) ? "framedred": "";
\r
60 // We now have the base unit and value now lets produce the table;
\r
61 while (list($key,$val) = each($this->bases[$base_unit])) {
\r
62 $cell ['value'] = $this->convert($value, $from_unit, $val, $precision)." ".$val;
\r
63 $cell ['class'] = ($val == $from_unit || $val == $to_unit) ? "framedred": "";
\r
67 $cc = count($cells);
\r
68 $string = "<table class=\"framed grayish\" border=\"1\" cellpadding=\"5\" width=\"80%\" align=\"center\"><tr>";
\r
69 $string .= "<td rowspan=\"$cc\" align=\"center\">$value $from_unit</td>";
\r
71 foreach ($cells as $cell) {
\r
73 $string .= "<td class=\"".$cell['class']."\">".$cell['value']."</td>";
\r
76 $string .= "</tr><tr><td class=\"".$cell['class']."\">".$cell['value']."</td>";
\r
79 $string .= "</tr></table>";
\r
87 $conv = new TP_Converter('en');
\r
90 $conversions = array(
\r
91 'Temperature'=>array('base' =>'Celsius',
\r
93 'Fahrenheit'=>array('ratio'=>1.8, 'offset'=>32),
\r
94 'Kelvin'=>array('ratio'=>1, 'offset'=>273),
\r
98 'Weight' => array('base' =>'kg',
\r
106 'cwt(UK)' => 0.019684,
\r
107 'cwt(US)' => 0.022046,
\r
108 'ton (US)' => 0.0011023,
\r
109 'ton (UK)' => 0.0009842
\r
112 'Distance' => array('base' =>'km',
\r
119 'naut.mile'=>0.53996,
\r
123 'furlong'=>4.970969537898672,
\r
124 'fathom'=>546.8066491688539
\r
127 'Area' => array('base' =>'km 2',
\r
131 'm 2'=>pow(1000,2),
\r
132 'dm 2'=>pow(10000,2),
\r
133 'cm 2'=>pow(100000,2),
\r
134 'mm 2'=>pow(1000000,2),
\r
135 'mile 2'=>pow(0.62137,2),
\r
136 'naut.miles 2'=>pow(0.53996,2),
\r
137 'in 2'=>pow(39370,2),
\r
138 'ft 2'=>pow(3280.8,2),
\r
139 'yd 2'=>pow(1093.6,2),
\r
142 'Volume' => array('base' =>'m 3',
\r
151 'gal(US)'=>264.172,
\r
152 'gal(UK)'=>219.969,
\r
153 'pint' => 2113.376,
\r
154 'quart' => 1056.688,
\r
156 'fl oz' => 33814.02,
\r
157 'tablespoon' => 67628.04,
\r
158 'teaspoon' => 202884.1,
\r
159 'pt (UK)'=>1000/0.56826,
\r
160 'barrel petroleum'=>1000/158.99,
\r
161 'Register Tons'=>2.832,
\r
162 'Ocean Tons'=>1.1327
\r
165 'Speed' =>array('base' =>'kmph',
\r
167 'mps'=>0.0001726031,
\r
168 'milesph'=>0.62137,
\r
170 'mach STP'=>0.0008380431,
\r
171 'c (warp)'=>9.265669e-10
\r
177 while (list($key,$val) = each($conversions)) {
\r
178 $conv->addConversion($val['base'], $val['conv']);
\r
179 $list[$key][] = $val['base'];
\r
180 while (list($ukey,$uval) = each($val['conv'])) {
\r
181 $list[$key][] = $ukey;
\r
185 $o .= '<h3>Unit Conversions</h3>';
\r
188 if (isset($_POST['from_unit']) && isset($_POST['value'])) {
\r
189 $_POST['value'] = $_POST['value'] + 0;
\r
192 $o .= ($conv->getTable($_POST['value'], $_POST['from_unit'], $_POST['to_unit'], 5))."</p>";
\r
194 $o .= "<p>Select:</p>";
\r
197 if(isset($_POST['value']))
\r
198 $value = $_POST['value'];
\r
202 $o .= '<form action="convert" method="post" name="conversion">';
\r
203 $o .= '<input name="value" type="text" id="value" value="' . $value . '" size="10" maxlength="10" />';
\r
204 $o .= '<select name="from_unit" size="12">';
\r
209 while(list($key,$val) = each($list)) {
\r
210 $o .= "\n\t<optgroup label=\"$key\">";
\r
211 while(list($ukey,$uval) = each($val)) {
\r
212 $selected = (($uval == $_POST['from_unit']) ? ' selected="selected" ' : '');
\r
213 $o .= "\n\t\t<option value=\"$uval\" $selected >$uval</option>";
\r
215 $o .= "\n\t</optgroup>";
\r
220 $o .= '<input type="submit" name="Submit" value="Submit" /></form>';
\r