<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: site_desktop_show_bar.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 = array();
$cdtat_start = '****----****';
$cdtat_end = '####----####';
$js_empty = '';
if ( $_SGLOBAL['supe_uid'] )
{
	if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != '' )
	{
		$desktop_id = $_POST['desktop_id'];
	}
	else
	{
		$desktop_id = -1;
	}
	if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != 0 && $_SC['domain'] )
	{
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SC['domain_uid']." order by bar_id");
	}
	else
	{
		$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;
		}
		if ( isset( $visitor[0]['share'] ) || isset( $visitor[0]['publish'] ) )
		{
			$visitor_share = unserialize($visitor[0]['share']);
			$all_id = implode(',',$visitor_share);
			$visitor_publish = unserialize($visitor[0]['publish']);
			$publish_id = implode(',',$visitor_publish);
			if ( strlen($all_id) != '' && strlen($publish_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." or desktop_id in (".$all_id.") or desktop_id in (".$publish_id.") order by bar_id");
			}
			elseif( strlen($all_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." or desktop_id in (".$all_id.") order by bar_id");
			}
			elseif( strlen($publish_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." or desktop_id in (".$publish_id.") order by bar_id");
			}
			else
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." order by bar_id");
			}
		}
		else
		{
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." order by bar_id");
		}
	}
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$list[] = $value;
	}
	$js_func = 'menuBarScrollJumpToItem("';
	if ( $desktop_id == -1 )
	{
		foreach ( $list as $val )
		{
			if ( $val['active'] == 1 )
			{
				$js_id = $val['desktop_id'];
				break;
			}
			else
			{
				$js_empty = $val['desktop_id'].',';
			}
		}
	}
	else
	{
		foreach ( $list as $val )
		{
			if ( $val['desktop_id'] < $desktop_id )
			{
				$js_empty = $val['desktop_id'].',';
			}
		}
		$js_id = $desktop_id;
	}
	if ( strlen($js_empty) > 0 )
	{
		$js_empty = substr($js_empty,0,-1);
	}
	$js_func .= $js_empty.'");';
	if ( count($list) > 1 )
	{
		$num = 'a';
	}
	else
	{
		$num = 'b';
	}
	$width = $height = 6;
}
else
{
	if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != '' )
	{
		$desktop_id = $_POST['desktop_id'];
	}
	else
	{
		$desktop_id = -1;
	}
	if ( isset($_POST['desktop_id']) && $_POST['desktop_id'] != 0 && $_SC['domain'] )
	{
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SC['domain_uid']." order by bar_id");
	}
	else
	{
		$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;
		}
		if ( isset( $visitor[0]['share'] ) || isset( $visitor[0]['publish'] ) )
		{
			$visitor_share = unserialize($visitor[0]['share']);
			$all_id = implode(',',$visitor_share);
			$visitor_publish = unserialize($visitor[0]['publish']);
			$publish_id = implode(',',$visitor_publish);
			if ( strlen($all_id) != '' && strlen($publish_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].",".$all_id.",".$publish_id.") order by bar_id");
			}
			elseif( strlen($all_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].",".$all_id.") order by bar_id");
			}
			elseif( strlen($publish_id) != '' )
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].",".$publish_id.") order by bar_id");
			}
			else
			{
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].") order by bar_id");
			}
		}
		else
		{
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where desktop_id in (".$_SC['default_desktop'].",".$_SC['default_rss_desktop'].") order by bar_id");
		}
	}
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$list[] = $value;
	}
	$js_func = 'menuBarScrollJumpToItem("';
	if ( $desktop_id == -1 )
	{
		foreach ( $list as $val )
		{
			if ( $val['active'] == 1 )
			{
				$js_id = $val['desktop_id'];
				break;
			}
			else
			{
				$js_empty = $val['desktop_id'].',';
			}
		}
	}
	else
	{
		foreach ( $list as $val )
		{
			if ( $val['desktop_id'] < $desktop_id )
			{
				$js_empty = $val['desktop_id'].',';
			}
		}
		$js_id = $desktop_id;
	}
	if ( strlen($js_empty) > 0 )
	{
		$js_empty = substr($js_empty,0,-1);
	}
	$js_func .= $js_empty.'");';
	if ( count($list) > 1 )
	{
		$num = 'a';
	}
	else
	{
		$num = 'b';
	}
	$width = 6;
	$height = 3;
}
?>