<?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']) )
{
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." WHERE uid=".$_SGLOBAL['supe_uid']);
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$bar[] = $value;
	}
	if ( empty( $bar ) )
	{
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." as a,".tname('site_desktop')." as b  where a.desktop_id=b.desktop_id and a.desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].") order by a.bar_id");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$list[] = $value;
		}
		if ( !empty($list) )
		{
			$first = 0;
			$active = 1;
			foreach( $list as $key )
			{
				if ( $first == 1 )
				{
					$active = 0;
				}
				$setarr = array(
					'uid' => $_SGLOBAL['supe_uid'],
					'content' => $key['content'],
					'active' => $active,
					'type' => $key['type'],
					'createtime' => $_SGLOBAL['timestamp']
				);
				$aid = inserttable('site_desktop', $setarr, 1);
				if ( $first == 0 )
				{
					$desktopId = $aid;
					$display = $key['type'];
					$str = explode("|", $key['content']);
				}
				$setbararr = array(
					'desktop_id' => $aid,
					'bar_name' => $key['bar_name'],
					'uid' => $_SGLOBAL['supe_uid'],			
					'active' => $active,
					'createtime' => $_SGLOBAL['timestamp']
				);
				inserttable('site_bar', $setbararr, 1);
				unset($setarr);
				unset($setbararr);
				$first++;
			}
			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)."]";
		}
		$action = 'add_icon';
		$width = 8;
		$height = 6;
	}
	else
	{
		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'];
		if ( $desktop[0]['type'] == 'multi' )
		{
			$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)."]";
			$action = 'add_icon';
			$width = 8;
			$height = 6;
			$display = 'multi';
		}
		elseif ( $desktop[0]['type'] == 'rss' )
		{
			$str = explode("|", $desktop[0]['content']);
			$js = "[";
			foreach ( $str as $key )
			{
				$js .= "'".$key."',";
			}
			$js = substr($js,0,-1)."]";
			$display = 'rss';
		}
	}
}
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'];
	if ( $desktop[0]['type'] == 'multi' )
	{
		$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)."]";
		$action = 'add_icon';
		$width = 8;
		$height = 6;
		$display = 'multi';
	}
	elseif ( $desktop[0]['type'] == 'rss' )
	{
		$str = explode("|", $desktop[0]['content']);
		$js = "[";
		foreach ( $str as $key )
		{
			$js .= "'".$key."',";
		}
		$js = substr($js,0,-1)."]";
		$display = 'rss';
	}
}
?>