<?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 ) )
	{
		@include_once(S_ROOT.'./data/data_site.php');
		$str = explode("|", $_SGLOBAL['site']['str'][0]);
		foreach ( $_SGLOBAL['site']['title'] as $key => $val )
		{
			$list[$_SGLOBAL['site']['id'][$key]] = array('id'=>$_SGLOBAL['site']['id'][$key],'title'=>$val,'url'=>$_SGLOBAL['site']['url'][$key],'color'=>$_SGLOBAL['site']['color'][$key],'icon'=>$_SGLOBAL['site']['icon'][$key]);
		}
		$js = "[";
		foreach ( $str as $key )
		{
			$js .= "'".$key."',";
		}
		$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 .= '"'.$str[$listkey].'",';
					$listkey++;
				}else{
					$js_x_y .= '"'.($col*90).'_'.($row*90).'",';
				}
				$row++;
				if( $row == 10 ){
					$row = 0;
				}
			}
			$col++;
		}
		$js_x_y = '['.substr($js_x_y,0,-1).']';
		$setarr = array(
			'uid' => $_SGLOBAL['supe_uid'],
			'content' => $_SGLOBAL['site']['str'][0],
			'active' => 1,
			'createtime' => $_SGLOBAL['timestamp']
		);
		$aid = inserttable('site_desktop', $setarr, 1);
		$desktopId = $aid;
		$setbararr = array(
			'desktop_id' => $aid,
			'bar_name' => '主桌面',
			'uid' => $_SGLOBAL['supe_uid'],			
			'active' => 1,
			'createtime' => $_SGLOBAL['timestamp']
		);
		inserttable('site_bar', $setbararr, 1);
	}
	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 * 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 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']);
		$num = 1;
		foreach( $str as $key )
		{
			if ( strlen($key) != 0 )
			{
				$siteid[$num] = explode(",", $key);
			}
			$num++;
		}
		if ( $siteid )
		{
			if ( isset( $siteid[1] ) )
			{
				$col_a = $siteid[1];
				$tmp .= implode( ',', $siteid[1] ).',';
			}
			if ( isset( $siteid[2] ) )
			{
				$col_b = $siteid[2];
				$tmp .= implode( ',', $siteid[2] ).',';
			}
			if ( isset( $siteid[3] ) )
			{
				$col_c = $siteid[3];
				$tmp .= implode( ',', $siteid[3] ).',';
			}
		}
		if ( $tmp )
		{
			$col_d = explode( ',', substr($tmp,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']);
	$num = 1;
	foreach( $str as $key )
	{
		if ( strlen($key) != 0 )
		{
			$siteid[$num] = explode(",", $key);
		}
		$num++;
	}
	if ( $siteid )
	{
		if ( isset( $siteid[1] ) )
		{
			$col_a = $siteid[1];
			$tmp .= implode( ',', $siteid[1] ).',';
		}
		if ( isset( $siteid[2] ) )
		{
			$col_b = $siteid[2];
			$tmp .= implode( ',', $siteid[2] ).',';
		}
		if ( isset( $siteid[3] ) )
		{
			$col_c = $siteid[3];
			$tmp .= implode( ',', $siteid[3] ).',';
		}
	}
	if ( $tmp )
	{
		$col_d = explode( ',', substr($tmp,0,-1) );
	}
	$action = 'add_icon';
	$width = 8;
	$height = 6;
}
?>