0)
		$duration['hour'] = ($duration['day'] - (int)$duration['day']) * 24;
	if (isset($duration['hour'])) {
		if (($duration['hour'] - (int)$duration['hour']) > 0)
			$duration['minute'] = ($duration['hour'] - (int)$duration['hour']) * 60;
		if (isset($duration['minute'])) {
			if (($duration['minute'] - (int)$duration['minute']) > 0)
				$duration['second'] = ($duration['minute'] - (int)$duration['minute']) * 60;
		}
	}
	$tmp = array();
	foreach ($duration as $type => $value) {
		if ($value >= 1) {
			$pluralType = ((int)$value === 1) ? $type : $type . 's';
			if ($type !== 'second') $tmp[] = (int)$value . " $pluralType";
			else $tmp[] = (int)$value . " $pluralType";
		}
	}
	return implode(', ', $tmp);
}
// start
// Passive check to see if bid period has expired and someone won a deal
$time = time();
$expired_auctions = mysql_select_multi("
	SELECT `id`
	FROM `znote_auction_player`
	WHERE `sold` = 0
	AND `time_end` < {$time}
	AND `bidder_account_id` > 0
");
//data_dump($expired_auctions, $this_account_id, "expired_auctions");
if ($expired_auctions !== false) {
	$soldIds = array();
	foreach ($expired_auctions as $a) {
		$soldIds[] = $a['id'];
	}
	if (!empty($soldIds)) {
		mysql_update("
			UPDATE `znote_auction_player`
			SET `sold`=1
			WHERE `id` IN(".implode(',', $soldIds).")
			LIMIT ".COUNT($soldIds).";
		");
	}
}
// end passive check
// Pending auctions
$pending = mysql_select_multi("
	SELECT
		`za`.`id` AS `zaid`,
		`za`.`price`,
		`za`.`bid`,
		`za`.`time_begin`,
		`za`.`time_end`,
		`p`.`id` AS `player_id`,
		`p`.`name`,
		`p`.`vocation`,
		`p`.`level`,
		`p`.`lookbody` AS `body`,
		`p`.`lookfeet` AS `feet`,
		`p`.`lookhead` AS `head`,
		`p`.`looklegs` AS `legs`,
		`p`.`looktype` AS `type`,
		`p`.`lookaddons` AS `addons`
	FROM `znote_auction_player` za
	INNER JOIN `players` p
		ON `za`.`player_id` = `p`.`id`
	WHERE `p`.`account_id` = {$auction['storage_account_id']}
	AND `za`.`claimed` = 0
	AND `za`.`sold` = 1
	ORDER BY `za`.`time_end` desc
");
// ongoing auctions
$ongoing = mysql_select_multi("
	SELECT
		`za`.`id` AS `zaid`,
		`za`.`price`,
		`za`.`bid`,
		`za`.`time_begin`,
		`za`.`time_end`,
		`p`.`vocation`,
		`p`.`level`,
		`p`.`lookbody` AS `body`,
		`p`.`lookfeet` AS `feet`,
		`p`.`lookhead` AS `head`,
		`p`.`looklegs` AS `legs`,
		`p`.`looktype` AS `type`,
		`p`.`lookaddons` AS `addons`
	FROM `znote_auction_player` za
	INNER JOIN `players` p
		ON `za`.`player_id` = `p`.`id`
	WHERE `p`.`account_id` = {$auction['storage_account_id']}
	AND `za`.`sold` = 0
	ORDER BY `za`.`time_end` desc;
");
// Completed auctions
$completed = mysql_select_multi("
	SELECT
		`za`.`id` AS `zaid`,
		`za`.`price`,
		`za`.`bid`,
		`za`.`time_begin`,
		`za`.`time_end`,
		`p`.`id` AS `player_id`,
		`p`.`name`,
		`p`.`vocation`,
		`p`.`level`,
		`p`.`lookbody` AS `body`,
		`p`.`lookfeet` AS `feet`,
		`p`.`lookhead` AS `head`,
		`p`.`looklegs` AS `legs`,
		`p`.`looktype` AS `type`,
		`p`.`lookaddons` AS `addons`
	FROM `znote_auction_player` za
	INNER JOIN `players` p
		ON `za`.`player_id` = `p`.`id`
	WHERE `za`.`claimed` = 1
	ORDER BY `za`.`time_end` desc
");
?>
Character Auction History
Let players sell, buy and bid on characters.
	
Creates a deeper shop economy, encourages players to spend more money in shop for points.
	
Pay to win/progress mechanic, but also lets people who can barely afford points to gain it
	
by leveling characters to sell. It can also discourages illegal/risky third-party account
	
services. Since players can buy officially & support the server, dodgy competitors have to sell for cheaper.
	
Without admin interference this is organic to each individual community economy inflation.
Pending orders to be claimed
	
		
			| Player | 
			Level | 
			Vocation | 
			Price | 
			Bid | 
		
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
			
			
				| Added: | 
				 | 
				Ended: | 
				 | 
			
			
				 | 
			
		
	
Ongoing auctions
	
		
			| Level | 
			Vocation | 
			Details | 
			Price | 
			Bid | 
			Added | 
			Type | 
		
		
			
				 | 
				 | 
				VIEW | 
				 | 
				 | 
				 $character['time_end']) ? true : false;
					echo getClock($character['time_begin'], true);
					?>
				 | 
				('.toDuration(($character['time_end'] - time())).')'; ?> | 
			
		
	
Completed auctions
	
		
			| Player | 
			Level | 
			Vocation | 
			Price | 
			Bid | 
		
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
			
			
				| Added: | 
				 | 
				Ended: | 
				 | 
			
			
				 |