<?php

/*
** DGS Search
** $Id: misc.php,v 1.4 2004/01/19 07:34:25 sella Exp $
** Copyright (c) 2000-2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

function getTime() {
	if (function_exists('microtime')) {
		$tm = microtime();
		$tm = explode(' ', $tm);
		return (float) sprintf('%f', $tm[1] + $tm[0]);
	}

	return time();
}

function currentDbTime($con) {
	if (($result = mysql_query('SELECT UNIX_TIMESTAMP(NOW()) AS now', $con)) != false) {
		return mysql_result($result, 0);
	}

	return time();
}

function percentage_shade($percent) {
	$green = ($percent > 58.33) ? 127 + ((100 - $percent) * 3.07) : ($percent * 4.37);
	$red = ($percent < 41.66) ? 127 + ($percent * 3.07) : ((100 - $percent) * 4.37);
	$blue = 5;

	return sprintf("%02x%02x%02x", $red, $green, $blue);
}

function ip_sort($ip_addresses) {
	foreach($ip_addresses as $ip_address=>$value) {
		$temp = split('\.', $ip_address);
		$index[$ip_address] = sprintf("%03s%03s%03s%03s", $temp[0], $temp[1], $temp[2], $temp[3]);
	}
	array_multisort($index, SORT_NUMERIC, $ip_addresses);

	return $ip_addresses;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/

?>
