<?php
/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: market_ajax.php 1000 2011-6-31 15:41:43 by angelrain $
 */
 /**
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
*/
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
define('CURRENT_PATH','dzz/system');
$do = empty($_GET['do'])?'':$_GET['do'];
//判断数据唯一
$refer=dreferer();
$msg='';
$data=array();
	if(!$space['self']){
		 $msg=dzzlang('message','no_privilege');
		 $data['msg']=$msg;
		echo json_encode_gbk($data);
		exit();
	}
	$ukey=trim($_GET['ukey']);
	if($ukey!=DB::result_first("select `ukey` from ".DB::table('dzz_userconfig')." where uid='{$uid}'")){
		$msg=dzzlang('message','need_refresh');
		$data['msg']=$msg;
		echo json_encode_gbk($data);
		exit();
	}
	//if(!$space['self']) showmessage('no_privelege',DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));

	$sid=empty($_GET['id'])?0:$_GET['id'];
	
	list($prex,$id,$fuid)=explode('-',$sid);
	if($prex=='f'){
		$arr=array();
		$icos=array();
		
		if($folder=DB::fetch_first('select * from '.DB::table('dzz_folder')." where fid='{$id}'")){
			$open_p=1;
			if($folder['friend']==1){
				if(!$space['self']) $open_p=0;
			}elseif($folder['friend']==2){
				if(!$space['self'] && !$space['isfriend']) $open_p=0;
			}
			if($open_p){			
				$folder['opened']=1;
				if($folder['ids']){
					$icos=explode(',',$folder['ids']);
				}else{
					$icos=array();
				}
				$folder['ids']=$icos;
				if($icos){
					
					$query=DB::query("select * from ".DB::table('dzz_icos')." where icoid IN (".dimplode($icos).") ");
					while($value=DB::fetch($query)){
						$value['url']=replace_canshu($value['url']);
						$value['fsize']=formatsize($value['size']);
						$value['ftype']=getFileTypeName($value['type'],$value['ext']);
						$value['fdateline']=dgmdate($value['dateline']);
						$open_p=1;
						if($value['friend']==1){
							if(!$space['self']) $open_p=0;
						}elseif($value['friend']==2){
							if(!$space['self'] && !$space['isfriend']) $open_p=0;
						}
						if(!$open_p){
							$value['img']='dzz/images/default_ys/'.$value['type'].'.png';
						}
						$arr[$value['icoid']]=$value;
						
					}
					//按桌面目录内顺序排列
					foreach($icos as $value){
						$data[$value]=$arr[$value];
					}
				}
			}
		}
	}elseif($prex=='d'){
		if($config_u=DB::fetch_first("select * from ".DB::table('dzz_userconfig')." where uid='$fuid'")){
				//获取所有桌面的icoids；
				$screenlist_u=unserialize(stripslashes($config_u['screenlist']));
				$icos=$screenlist_u[$id]['icos'];
		}
		if($icos){
			$query=DB::query("select * from ".DB::table('dzz_icos')." where icoid IN (".dimplode($icos).") ");
			while($value=DB::fetch($query)){
				$value['url']=replace_canshu($value['url']);
				$value['fsize']=formatsize($value['size']);
				$value['ftype']=getFileTypeName($value['type'],$value['ext']);
				$value['fdateline']=dgmdate($value['dateline']);
				$open_p=1;
				if($value['friend']==1){
					if(!$space['self']) $open_p=0;
				}elseif($value['friend']==2){
					if(!$space['self'] && !$space['isfriend']) $open_p=0;
				}
				if(!$open_p){
					$value['img']='dzz/images/default_ys/'.$value['type'].'.png';
				}
				$arr[$value['icoid']]=$value;
			}
		}
		//按桌面内顺序排列
		foreach($icos as $icoid){
			$data[$icoid]=$arr[$icoid];
		}
		
	}elseif($prex=='type'){
		
	}elseif($prex=='friend'){
		
	}elseif($prex=='alluser'){
	}
	
	echo json_encode_gbk($data);
	exit();
?>