<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: site_desktop_show_empty.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;
if ( !empty($_SGLOBAL['supe_uid']) )
{
	if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != 0 && $_SC['domain'] )
	{
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_desktop')." where uid=".$_SC['domain_uid']." and desktop_id=".intval($_POST['desktop_id']));
	}
	else
	{
		if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != 0 )
		{
			$query = $_SGLOBAL['db']->query("SELECT share,publish FROM ".tname('site_visitor')." where cookie='".$_SC['site_key']."'");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$visitor[] = $value;
			}
			$visitor_share = unserialize($visitor[0]['share']);
			$visitor_publish = unserialize($visitor[0]['publish']);
			if ( !in_array( $_POST['desktop_id'], $visitor_share ) && !in_array( $_POST['desktop_id'], $visitor_publish ) )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_desktop')." where uid=".$_SGLOBAL['supe_uid']." and desktop_id=".intval($_POST['desktop_id']));
			}
			else
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_desktop')." where desktop_id=".intval($_POST['desktop_id']));
			}
		}
		else
		{
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_desktop')." where uid=".$_SGLOBAL['supe_uid']." and active=1");
		}
	}
	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;
		}
	}
	$js = "[";
	foreach ( $str as $key )
	{
		$js .= "'";
		if ( $key != 0 && is_numeric($key) ){
			if ( $list[$key]['hot'] == 1 )
			{
				$js .= $key;
			}
			else
			{
				$js .= "c".$key;
			}
		}
		else{
			$js .= $key;
		}
		$js .="',";
	}
	$js = substr($js,0,-1)."]";
	$row = 0;
	$col = 0;
	$js_x_y = '';
	$listkey = 0;
	foreach( $_SITE as $key ){
		foreach( $key as $val ){
			if ( $str[$listkey] != 0 && is_numeric($str[$listkey]) ){
				$js_x_y .= '"';
				if ( $list[$str[$listkey]]['hot'] == 1 )
				{
					$js_x_y .= $str[$listkey];
				}
				else
				{
					$js_x_y .= "c".$str[$listkey];
				}
				$js_x_y .= '",';
			}else{
				$js_x_y .= '"'.($col*90).'_'.($row*90).'",';
			}
			$row++;
			$listkey++;
			if( $row == 10 ){
				$row = 0;
			}
		}
		$col++;
	}
	$js_x_y = '['.substr($js_x_y,0,-1).']';
	$action = 'add_icon';
	$width = 8;
	$height = 6;

}
else
{
	$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;
		}
	}
	$js = "[";
	foreach ( $str as $key )
	{
		$js .= "'";
		if ( $key != 0 && is_numeric($key) ){
			if ( $list[$key]['hot'] == 1 )
			{
				$js .= $key;
			}
			else
			{
				$js .= "c".$key;
			}
		}
		else{
			$js .= $key;
		}
		$js .="',";
	}
	$js = substr($js,0,-1)."]";
	$row = 0;
	$col = 0;
	$js_x_y = '';
	$listkey = 0;
	foreach( $_SITE as $key ){
		foreach( $key as $val ){
			if ( $str[$listkey] != 0 && is_numeric($str[$listkey]) ){
				$js_x_y .= '"';
				if ( $list[$str[$listkey]]['hot'] == 1 )
				{
					$js_x_y .= $str[$listkey];
				}
				else
				{
					$js_x_y .= "c".$str[$listkey];
				}
				$js_x_y .= '",';
			}else{
				$js_x_y .= '"'.($col*90).'_'.($row*90).'",';
			}
			$row++;
			$listkey++;
			if( $row == 10 ){
				$row = 0;
			}
		}
		$col++;
	}
	$js_x_y = '['.substr($js_x_y,0,-1).']';
	$action = 'add_icon';
	$width = 8;
	$height = 6;
}
?>