<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: site_desktop_delete.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 = $visitor = array();
$cdtat_start = '****----****';
$cdtat_end = '####----####';
if ( !empty($_SGLOBAL['supe_uid']) )
{
	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( intval($_POST['desktop_id']), $visitor_share ) )
		{
			foreach ( $visitor_share as $key )
			{
				if ( !$key == intval($_POST['desktop_id']) )
				{
					$str[] = $key;
				}
			}
			$setarr = array(
				'share' => serialize($str)
			);
			updatetable('site_visitor', $setarr, array('cookie'=>$_SC['site_key']));
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']);
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				if ( $value['active'] == 1 )
				{
					$msg = "loadDesktop(".$value['desktop_id'].");";
				}
			}
		}
		elseif ( in_array( intval($_POST['desktop_id']), $visitor_publish ) )
		{
			foreach ( $visitor_publish as $key )
			{
				if ( !$key == intval($_POST['desktop_id']) )
				{
					$str[] = $key;
				}
			}
			$setarr = array(
				'publish' => serialize($str)
			);
			updatetable('site_visitor', $setarr, array('cookie'=>$_SC['site_key']));
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']);
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				if ( $value['active'] == 1 )
				{
					$msg = "loadDesktop(".$value['desktop_id'].");";
				}
			}
		}
		else
		{
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']." and desktop_id=".intval($_POST['desktop_id']));
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$list[] = $value;
			}
			if ( $list[0]['active'] == 1 )
			{
				$msg = "showAlert({ content: '删除失败：不能删除主桌面！' });";
			}
			else
			{
				$_SGLOBAL['db']->query("DELETE FROM ".tname('site_bar')." WHERE uid=".$_SGLOBAL['supe_uid']." and desktop_id=".intval($_POST['desktop_id']));
				$_SGLOBAL['db']->query("DELETE FROM ".tname('site_desktop')." WHERE uid=".$_SGLOBAL['supe_uid']." and desktop_id=".intval($_POST['desktop_id']));
				$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site_bar')." where uid=".$_SGLOBAL['supe_uid']);
				while ($value = $_SGLOBAL['db']->fetch_array($query)) {
					if ( $value['active'] == 1 )
					{
						$msg = "loadDesktop(".$value['desktop_id'].");";
					}
				}
			}
		}
	}
}
else
{
	header("location: /window/login.php");
}
?>