<?php

/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
 */
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
$refer=dreferer();
dzz_cpheader();
if(submitcheck('iconssubmit')) {
		$ids=$_POST['ids'];
		$deletes=$_POST['delete'];
		foreach($ids as $id){
			if(!in_array($id,$deletes)){
				$setarr=array(
						'disp'=>intval($_POST['disp'][$id]),
						'title'=>trim($_POST['title'][$id]),
						'default'=>0
					);
				if($id==intval($_POST['default'])){
					$setarr['default']=1;
				}
				DB::update('dzz_sysicon',$setarr,"id='{$id}'");
			}
		}
		if($deletes) DB::delete('dzz_sysicon',"id IN (".dimplode($deletes).")");
	
	cpmsg($lang['do_success'],$refer,'succeed');
}else{
	if($operation=='folder'){
		if($do=='setup'){
			$folder=trim($_GET['icon']);
			$msg='';
			if(!$folder) cpmsg($lang['parameter_error'],$refer,'error');
			$setarr=array(
							'icon'=>$folder,
							'type'=>'folder',
							'title'=>$folder,
							'dateline'=>$_G['timestamp'],
							);
				DB::insert('dzz_sysicon',daddslashes($setarr));
				cpmsg($lang['do_success'],$refer,'succeed');
		}else{
			dzz_shownav($lang['menu_icon'],$lang['menu_icon_folder']);
			
			//获取目录中图片；
			$icons=array();
			$foldericondir = DISCUZ_ROOT.'./dzz/images/sysicon/foldericon';
			$dirhandle =dir($foldericondir);
			while($entry = $dirhandle->read()) {
				$imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
				$ext=(strtolower(substr(strrchr($entry, '.'), 1, 10)));
				if(!in_array($entry, array('.', '..')) && in_array($ext,$imgext)) {
					$icons[]=$entry;
				}
			}
			
			$folder=array();
			$folders=array();
			$query=DB::query("select * from ".DB::table('dzz_sysicon')." where type='folder' ORDER BY disp");
			while($value=DB::fetch($query)){
				$value['img']='dzz/images/sysicon/foldericon/'.$value['icon'];
				if(in_array($value['icon'],$icons)){
					 $folders[]=$value['icon'];
					 $folder[]=$value;
				}
				else DB::delete('dzz_sysicon',"id='{$value[id]}'");
			}
			$folder_no=array();
			foreach($icons as $value){
				if(!in_array($value,$folders)){
					$folder_no[]=array('icon'=>$value,'img'=>'dzz/images/sysicon/foldericon/'.$value);
				}
			}
		}
	}elseif($operation=='url'){
		if($do=='setup'){
			$icon=trim($_GET['icon']);
			$msg='';
			if(!$icon) cpmsg($lang['parameter_error'],$refer,'error');
			$setarr=array(
							'icon'=>$icon,
							'title'=>$icon,
							'type'=>'url',
							'dateline'=>$_G['timestamp']
							);
				DB::insert('dzz_sysicon',daddslashes($setarr));
				cpmsg($lang['do_success'],$refer,'succeed');
		}else{
			dzz_shownav($lang['menu_icon'],$lang['menu_icon_url']);
			
			//获取目录中图片；
			$icons=array();
			$urlicondir = DISCUZ_ROOT.'./dzz/images/sysicon/urlicon';
			$dirhandle =dir($urlicondir);
			while($entry = $dirhandle->read()) {
				$imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
				$ext=(strtolower(substr(strrchr($entry, '.'), 1, 10)));
				if(!in_array($entry, array('.', '..')) && in_array($ext,$imgext)) {
					$icons[]=$entry;
				}
			}
			
			$urlicon=array();
			$urlicons=array();
			$query=DB::query("select * from ".DB::table('dzz_sysicon')." where type='url' ORDER BY disp");
			while($value=DB::fetch($query)){
				$value['img']='dzz/images/sysicon/urlicon/'.$value['icon'];
				if(in_array($value['icon'],$icons)){
					 $urlicons[]=$value['icon'];
					 $urlicon[]=$value;
				}
				else DB::delete('dzz_sysicon',"id='{$value[id]}'");
			}
			$urlicon_no=array();
			foreach($icons as $value){
				if(!in_array($value,$urlicons)){
					$urlicon_no[]=array('icon'=>$value,'img'=>'dzz/images/sysicon/urlicon/'.$value);
				}
			}
		}
	}
}
include dzztemplate('admin/dzz_icons');

?>