<?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($operation=='delete'){
	$ids=$_POST['ids'];
	if($ids){
		$query=DB::query("select typeid,gid,uid from ".DB::table('dzz_widget')." where gid IN (".dimplode($ids).")");
		while($widget=DB::fetch($query)){
			dzz_delete_widget($widget['gid']);
		}
	}
	cpmsg($lang['do_success'],$_G['siteurl'].$_POST['refer'],'succeed');

}elseif($operation=='edit'){
	$gid=intval($_GET['gid']);
	if(submitcheck('editsubmit')){
		$setarr=array('url'=>trim($_POST['url']),
					  'width'=>intval($_POST['width']),
					  'height'=>intval($_POST['height']),
					  'classname'=>trim($_POST['classname']),
					  'href'=>trim($_POST['href']),
					  'open'=>intval($_POST['open']),
					  'type'=>trim($_POST['type'])
					  );
		DB::update('dzz_widget',daddslashes($setarr),"gid='{$gid}'");
		cpmsg($lang['do_success'],$refer,'succeed');
	}else{
		$back=base64_decode(trim($_GET['back']));
		if(!$widget=DB::fetch_first("select * from ".DB::table('dzz_widget')." where gid='{$gid}'")){
			cpmsg(dzzlang('admin/template','widget_not_exist'),$back,'error');
		}
	}
}else{
	$page = empty($_GET['page'])?1:intval($_GET['page']);
		$username=trim($_GET['username']);
		$day=intval($_GET['day'])?intval($_GET['day']):604800;
		$uid=intval($_GET['uid']);
		$url=intval($_GET['url']);
		$type=trim($_GET['type']);
		$perpage = 12;
		$start = ($page-1)*$perpage;
		$gets = array(
				'action'=>$action,
				'operation'=>$operation,
				'username' => $username,
				'day'=>$day,
				'url'=>$url,
				'uid'=>$uid
			);
		$theurl = ADMINSCRIPT."?".url_implode($gets);
		
		
			$time=$_G['timestamp']-$day;
			$wheresql="1";
			
			//日期选项
			if($day>0) $wheresql.=" and dateline>$time";
			//用户选项
			if($username) $wheresql.=" and username='{$username}'";
			$ordersql=" ORDER BY `dateline` DESC";
			//url模糊搜索
		
			if($url){
				$wheresql.=" and url LIKE '%".$url."%'";
			}
			
			//uid
			if($uid){
				$wheresql.=" and uid ='{$uid}'";
			}
			//挂件类型
			if($type){
				$wheresql.=" and type ='{$type}'";
			}
			//取得所有符合条件的应用列表
			$list=array();
			$count=DB::result_first("SELECT COUNT(*) FROM ".DB::table('dzz_widget')." where $wheresql  ");
			if($count){
				$query=DB::query("SELECT * FROM ".DB::table('dzz_widget')."  where $wheresql $ordersql   LIMIT $start,$perpage" );
				while($value=DB::fetch($query)){
						$value['dateline'] = dgmdate($value['dateline']);
						$value['type']=dzzlang('admin/template','widget_type_'.$value['type']);
						$list[]=$value;
					}
				}
			$multi = multi($count, $perpage, $page,$theurl);
			$theurl1=base64_encode($theurl.'&page='.$page);
}

include dzztemplate('admin/dzz_widget');
dzzfooter();


?>