<?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');
}
$do = empty($_GET['do'])?'':$_GET['do'];
//判断数据唯一
$refer=dreferer();
$msg='';
	if(!$space['self'] && $do!='userdetail') showmessage(dzzlang('message','no_privilege'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));


if($do=='newlink'){
	$ukey=trim($_GET['ukey']);
	if($ukey!=DB::result_first("select `ukey` from ".DB::table('dzz_userconfig')." where uid='{$uid}'")){
		showmessage(dzzlang('message','need_refresh'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
	}
	$container=trim($_GET['container']);
}elseif($do=='widget'){
	$ukey=trim($_GET['ukey']);
	if($ukey!=DB::result_first("select `ukey` from ".DB::table('dzz_userconfig')." where uid='{$uid}'")){
		showmessage(dzzlang('message','need_refresh'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
	}
	$gid=intval($_GET['gid']);
	$icoid=intval($_GET['icoid']);
	$widget=array();
	if($icoid){
		 $ico=DB::fetch_first("select * from ".DB::table('dzz_icos')." where icoid='$icoid'");
		 switch($ico['type']){
			case 'image':
				$widget=array(
								'type'=>'image',
								'width'=>$ico['wwidth'],
								'height'=>$ico['wheight'],
								'url'=>$ico['url']
							);
				break;
			
			default:
				static $imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
				static $videoext  = array('swf', 'flv');
				$ext=strtolower(substr(strrchr($ico['url'], '.'), 1, 50));
				$type='link';
				if(in_array($ext,$imgext)) $type='image';
				elseif(in_array($ext,$videoext)) $type='flash';
				$widget=array(
								'type'=>$type,
								'width'=>$ico['wwidth']?$ico['wwidth']:460,
								'height'=>$ico['wheight']?$ico['wheight']:300,
								'url'=>$ico['url'],
							);
				break;						
			 
		 }
	}
	if($gid) $widget=DB::fetch_first("select * from ".DB::table('dzz_widget')." where gid='$gid'");
	
}elseif($do=='widget_delete'){
	$ukey=trim($_GET['ukey']);
	if($ukey!=DB::result_first("select `ukey` from ".DB::table('dzz_userconfig')." where uid='{$uid}'")){
		showmessage(dzzlang('message','need_refresh'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
	}
	$gid=intval($_GET['gid']);
	if($gid) $widget=DB::fetch_first("select * from ".DB::table('dzz_widget')." where gid='$gid'");

}elseif($do=='edit'){
	$ukey=trim($_GET['ukey']);
	if($ukey!=DB::result_first("select `ukey` from ".DB::table('dzz_userconfig')." where uid='{$uid}'")){
		showmessage(dzzlang('message','need_refresh'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
	}
	$icoid=intval($_GET['icoid']);
	//获取icoarr
	if(!$icoarr=dstripslashes(DB::fetch_first("select * from ".DB::table('dzz_icos')." where icoid='{$icoid}'"))){
		showmessage(dzzlang('system/message','edit_ico_not_exist'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
	}
	$type=$icoarr['type'];
	switch($type){
		case 'folder':
			//获取目录
			if(!$folder=DB::fetch_first("select * from ".DB::table('dzz_folder')." where fid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','folder_not_exist'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
			}
			break;
		case 'link':
			//获取目录
			$parseurl=parse_url($icoarr['url']);
			$host=$parseurl['host'];
			$host=preg_replace("/^www./",'',$host);
			$domainlist=array();
			$query=DB::query("select * from ".DB::table('dzz_icon')." where domain='{$host}' and `check`>1 order by disp");
			while($value=DB::fetch($query)){
				$value['pic']=$_G['setting']['attachurl'].$value['pic'];
				$domainlist[]=$value;
			}
			if(!$link=DB::fetch_first("select * from ".DB::table('dzz_link')." where lid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','link_not_exist'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
			}
			$icoarr['did']=$link['did'];
			break;
		case 'app':
			//获取目录
			if($app=DB::fetch_first("select * from ".DB::table('dzz_apps')." where appid='{$icoarr[oid]}'")){
				if($app['uid']==$uid){
					$ismyapp=1;
					//获取应用市场分类
					$appclass=array();
					$query=DB::query("select * from ".DB::table('dzz_appclass')." where fupid=0 order by disp");
					while($value=DB::fetch($query)){
						$appclass[$value['classid']]=$value;
					}
				}
			}else{
				showmessage(dzzlang('system/message','app_not_exist'),DZZSCRIPT,'',array('showdialog'=>1, 'showmsg' => true, 'closetime' => 3));
			}
			break;
	}
}elseif($do=='geticon'){
	$type=$_GET['type'];
	$page = empty($_GET['page'])?1:intval($_GET['page']);
	if($page<1) $page=1;
	$perpage = 16;
	$start = ($page-1)*$perpage;
	ckstart($start, $perpage);
	$gets = array(
		'mod' => 'system',
		'do' => 'geticon',
		'op' => 'ajax',
		'handlekey' => $_GET['handlekey'],
		'uid' => $uid,
		'type'=>$_GET['type'],
		
	);
	$theurl = DZZSCRIPT.'?'.url_implode($gets);
	$multi = '';
	
	switch($type){
		case 'folder':case 'url':
			$count=DB::result_first("select count(*) from ".DB::table('dzz_sysicon')." where type='{$type}'");
			if($count){
				$piclist=array();
				$query=DB::query("select * from ".DB::table('dzz_sysicon')." where type='{$type}' order by disp LIMIT $start , $perpage");
				while($value=DB::fetch($query)){
					if($value['type']=='folder'){
						$value['pic']='dzz/images/sysicon/foldericon/'.$value['icon'];
					}elseif($value['type']=='url'){
						$value['pic']='dzz/images/sysicon/urlicon/'.$value['icon'];
					}
					$piclist[]=$value;
				}
			}
			$multi = multi($count, $perpage, $page, $theurl);
			break;
		case 'mypic':
			$count=DB::result_first("select count(*) from ".DB::table('dzz_image')." where width<101 and height<101 and uid='{$uid}'");
			if($count){
				$piclist=array();
				$query=DB::query("select filepath from ".DB::table('dzz_image')." where width<101 and height<101 and uid='{$uid}' order by dateline DESC LIMIT $start , $perpage");
				while($value=DB::fetch($query)){
					$value['pic']=$_G['setting']['attachurl'].$value['filepath'];
					$piclist[]=$value;
				}
			}
			$multi = multi($count, $perpage, $page, $theurl);
			break;
	}
}
include dzztemplate('system/system_ajax');

?>