function getRounding($val = '0', $coin = 0) { //FB::log($val, "Rounding.php val="); global $db; $smallcoin = $db->QPResults("SELECT value FROM system WHERE name='smallcoin'"); $smallcoin = $smallcoin['value']; $roundup = $db->QPResults("SELECT value FROM system WHERE name='roundup'"); $roundup = $roundup['value']; $rounddown = $db->QPResults("SELECT value FROM system WHERE name='rounddown'"); $rounddown = $rounddown['value']; $newval = '0'; //set swedish rounding defaults if values are not set if (!isset($smallcoin) || empty($smallcoin)) { $smallcoin = '.10'; } if (!isset($roundup) || empty($roundup)) { $roundup = '6,7,8,9'; } if (!isset($rounddown) || empty($rounddown)) { $rounddown = '1,2,3,4,5'; } if (!empty($val)) { //make sure $val is a string $val = strval(number_format($val, 2)); $last = $smallcoin[strlen($smallcoin) - 1]; $lastval = $val[strlen($val) - 1]; $downcheck = strpos($rounddown, $lastval); $upcheck = strpos($roundup, $lastval); if ($downcheck !== false) { //then round down $newval = rounddown($val, $lastval, $last); } elseif ($upcheck !== false) { //then round up $newval = roundup($val, $lastval, $smallcoin); } else { $newval = $val; } // FB::log($newval, "Rounding.php in not empty val, newval="); } if (!empty($coin)) { // return the denomination of coinage for payments.php javascript $newval = $smallcoin; //FB::log($val, "Rounding.php not empty coin newval="); } //FB::log($newval, "Rounding.php in not empty val, newval="); return floatval($newval); }
function add_directory($base, $path = '/') { global $files; global $filedata; $objects = scandir($base . $path); foreach ($objects as $obj) { if ($obj == '' || $obj[0] == '.') { continue; } if (is_dir("{$base}/{$path}{$obj}")) { add_directory($base, "{$path}{$obj}/"); } else { $contents = file_get_contents("{$base}/{$path}{$obj}"); $offset = roundup(strlen($filedata), 16); while (strlen($filedata) % 16 != 0) { $filedata .= chr(0); } $filedata .= $contents; $name = substr("{$path}{$obj}", 1); $files[$name] = array($offset, strlen($contents)); unset($contents); } } }
function chart_data($Wvisits, $pages = null, $atime = null, $type, $charttype = null, $axes = null, $chart_type = null) { // Port of JavaScript from http://code.google.com/apis/chart/ // http://james.cridland.net/code // First, find the maximum value from the values given if ($axes == 1) { $maxValue = roundup(max(array_merge($Wvisits, $pages))); //$maxValue = roundup(max($Wvisits)); $halfValue = $maxValue / 2; $maxPage = $maxValue; } else { $maxValue = roundup(max($Wvisits)); $halfValue = $maxValue / 2; $maxPage = roundup(max($pages)); $halfPage = $maxPage / 2; } // A list of encoding characters to help later, as per Google's example $simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $chartData = "s:"; // Chart type has two datasets if ($charttype == "main") { $label_time = ""; for ($i = 0; $i < count($Wvisits); $i++) { $currentValue = $Wvisits[$i]; $currentTime = $atime[$i]; if ($chart_type == "dashboard") { $label_time = "|"; } else { $label_time .= ereg_replace(" ", "+", $currentTime) . "|"; } if ($currentValue > -1) { $chartData .= substr($simpleEncoding, 61 * ($currentValue / $maxValue), 1); } else { $chartData .= '_'; } } // Add pageviews line to the chart if (count($pages) != 0) { $chartData .= ","; for ($i = 0; $i < count($pages); $i++) { $currentPage = $pages[$i]; $currentTime = $atime[$i]; if ($currentPage > -1) { $chartData .= substr($simpleEncoding, 61 * ($currentPage / $maxPage), 1); } else { $chartData .= '_'; } } } // Return the chart data - and let the Y axis to show the maximum value if ($axes == 1) { return $chartData . "&chxt=x,y&chxl=0:|" . $label_time . "1:|0|" . $halfValue . "|" . $maxValue . "&chxs=0,6b6b6b,9"; } else { return $chartData . "&chxt=x,y,r&chxl=0:|" . $label_time . "1:|0|" . $halfValue . "|" . $maxValue . "|2:|0|" . $halfPage . "|" . $maxPage . "&chxs=0,6b6b6b,9"; } // Chart type has one one dataset // It's unused now } else { for ($i = 0; $i < count($Wvisits); $i++) { $currentValue = $Wvisits[$i]; $currentTime = $atime[$i]; $label_time .= ereg_replace(" ", "+", $currentTime) . "|"; if ($currentValue > -1) { $chartData .= substr($simpleEncoding, 61 * ($currentValue / $maxValue), 1); } else { $chartData .= '_'; } } return $chartData . "&chxt=x,y&chxl=0:|" . $label_time . "|1:|0|" . $halfValue . "|" . $maxValue . "&chxs=0,6b6b6b,9"; } }