units['conv'] = conversion table // $vars->units['fid'] = field id // $vars->units['aunit'] = author's working unit // $vars->units['precision'] = digit precision global $user; $vars->units = array(); // define the conversion table // 0 => universal conversion factor $vars->units['conv'] = array( 0 => 1, 'mm' => 0.1, 'cm' => 1, 'm' => 100, // We'll make inch 2.5 instead of 2.54, and Yard 91.5 instead of 91.44 'inch' => 2.5, 'yard' => 91.4); // define unit aliases $vars->units['alias'] = array( 'cm' => 'centimeter', 'mm' => 'milimeter', 'm' => 'meter'); // get the field name $fieldname = 'profile_working_units'; // <--------- change this according to your field name // get field ID from table {profile_fields} $unitfield = db_fetch_array( db_query("SELECT fid FROM {profile_fields} WHERE name='%s'", $fieldname)); $vars->units['fid'] = $unitfield['fid']; // get user (author) preferred unit $unitsel = db_fetch_array( db_query("SELECT value FROM {profile_values} WHERE fid=%d and uid=%d", $unitfield['fid'], $user->uid)); $unitsel['value'] = strtolower($unitsel['value']); // Check alias $aliaskey = array_search($unitsel['value'], $vars->units['alias']); if ($aliaskey) $unitsel['value'] = $aliaskey; // Set aunit to author's unit $vars->units['aunit'] = $unitsel['value']; // Set the digit precision $vars->units['precision'] = 2; return "";]]> units['alias']); if ($aliaskey) $unit = $aliaskey; // Converts all values to universal factor $valuex = $value * $vars->units['conv'][$unit]; return "units['precision']}) . ' ' . \$unit_unit; ?>";]]> units['conv'] as $unit => $factor) { $script .= "'$unit' => $factor, "; } $script .= ");"; $script .= "\$unit_aliases = array("; foreach ($vars->units['alias'] as $unit => $alias) { $script .= "'$unit' => '$alias', "; } $script .= ");"; // script to get current user's preferred unit $script .= "\$unitsel = db_fetch_array( db_query(\"SELECT value FROM {profile_values} WHERE fid=%d and uid=%d\", {$vars->units['fid']}, \$user->uid)); \$unit_unit = strtolower(\$unitsel['value']);"; // script to check alias $script .= "\$aliaskey = array_search(\$unit_unit, \$unit_aliases); if (\$aliaskey) \$unit_unit = \$aliaskey;"; $script .= "\$unit_precision = {$vars->units['precision']};"; return "";]]>