<?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();
dzz_shownav(dzzlang('admin/template','menu_user'),dzzlang('admin/template','menu_user_usergroup'));
if(!submitcheck('usergroupsubmit')) {
	$group_member=$group_system=$group_special=array();
	$dzzgroup=array();
	$query=DB::query("select * from ".DB::table('dzz_usergroup')." where 1");
	while($value=DB::fetch($query)){
		$dzzgroup[$value['groupid']]=$value;
	}
	$query = DB::query("SELECT g.groupid, g.radminid, g.type, g.grouptitle,f.maxattachsize,f.attachextensions,f.maxspacesize FROM ".DB::table('common_usergroup')." g
					LEFT JOIN ".DB::table('common_usergroup_field')." f ON g.groupid=f.groupid ORDER BY g.creditshigher");
		while($group = DB::fetch($query)) {
			$group['maxattachsize']=floor($group['maxattachsize']/1024);
			if($dzzgroup[$group['groupid']]){
				$group['maxattachsize']=floor($dzzgroup[$group['groupid']]['maxattachsize']/1024);
				$group['attachextensions']=$dzzgroup[$group['groupid']]['attachextensions'];
				$group['maxspacesize']=$dzzgroup[$group['groupid']]['maxspacesize'];
				$group['allowupload']=$dzzgroup[$group['groupid']]['allowupload'];
				$group['allownewfolder']=$dzzgroup[$group['groupid']]['allownewfolder'];
				$group['allownewlink']=$dzzgroup[$group['groupid']]['allownewlink'];
			}else{
				$group['allowupload']=1;
				$group['allownewfolder']=1;
				$group['allownewlink']=1;
			}
			
			if($group['type'] == 'member') {
				$group_member[]=$group;
			}elseif($group['type'] == 'system') {
				$group_system[]=$group;
			}elseif($group['type'] == 'special' && $group['radminid'] == '0') {
				$group_special[]=$group;
			}
		}
}else{
	$groupids=$_POST['groupid'];
	foreach($groupids as $groupid){
		$setarr=array('groupid'=>$groupid,
					  'maxattachsize'=>$_POST['maxattachsize'][$groupid]*1024,
					  'attachextensions'=>$_POST['attachextensions'][$groupid],
					  'maxspacesize'=>$_POST['maxspacesize'][$groupid],
					  'allowupload'=>$_POST['allowupload'][$groupid],
					  'allownewfolder'=>$_POST['allownewfolder'][$groupid],
					  'allownewlink'=>$_POST['allownewlink'][$groupid],
					  );
		DB::insert('dzz_usergroup',daddslashes($setarr),0,1);
	}
	cpmsg($lang['do_success'],$refer,'succeed');
}

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


?>