<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: site_game.php 10953 2009-01-12 02:55:37Z liguode $
*/

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}
@include_once(S_ROOT.'./data/site_config.php');
$list = $bar = $desktop = $siteid = array();
$cdtat_start = '****----****';
$cdtat_end = '####----####';
$arrow = '$';
$desktopId = 0;
$html = '';
if ( isset( $_POST['desktop_id'] ) && intval($_POST['desktop_id']) > 0)
{
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_desktop')." where desktop_id=".intval($_POST['desktop_id']));
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$desktop[] = $value;
	}
	$desktopId = $desktop[0]['desktop_id'];
	$str = explode("|", $desktop[0]['content']);
	foreach( $str as $key )
	{
		if ( $key != 0 && is_numeric($key) ){
			$siteid[] = $key;
		}
	}
	$tmp = implode( ',', $siteid );
	if ( $tmp )
	{
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site')." where id in (".$tmp.")");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$list[$value['id']] = $value;
		}
		$count = count($list);
		if ( $count == 20 )
		{
			foreach( $list as $key )
			{
				$html .= "<headurl name='".$key['title']."'>".$key['icon']."</headurl>";
			}
			unset($list);
		}
		elseif ( $count > 20 )
		{
			$rank_key = array_rand($list, 20);
			for ($x=0; $x < count($rank_key); $x++) 
			{
			   $html .= "<headurl name='".$list[$rank_key[$x]]['title']."'>".$list[$rank_key[$x]]['icon']."</headurl>";
			}
			unset($list);
		}
		else
		{
			$num = 20 - $count;
			foreach( $list as $key )
			{
				$html .= "<headurl name='".$key['title']."'>".$key['icon']."</headurl>";
			}
			unset($list);
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site')." where id not in (".$tmp.") limit ".$num);
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$list[$value['id']] = $value;
			}
			foreach( $list as $key )
			{
				$html .= "<headurl name='".$key['title']."'>".$key['icon']."</headurl>";
			}
			unset($list);
		}
	}
}
?>