<?php
!defined("MONKEYMAO") && die("Accessed Defined!");
if(checksubmit('updategroup')){
	$newgrouptitle=trim($newgrouptitle);
	$newid=0;
	if($newgrouptitle){
		$db -> query("INSERT INTO {$tablepre}admingroups (grouptitle, about) VALUES ('$newgrouptitle', '$newabout')");
		$newid = $db -> insert_id();
	}
	

	if(is_array($delete) && count($delete) && !in_array(1,$delete) && !in_array(2,$delete)){

		$ids=idarray($delete);
		$db -> query("DELETE FROM {$tablepre}admingroups WHERE adminid IN($ids)");
		$db -> query("UPDATE {$tablepre}members SET adminid=0 WHERE  adminid IN($ids)");
	}
	cache('admingroups');
	$newid ? cpmsg('group_uodate_succeeded', 'index.php?action=admingroups&edit='.$newid) : cpmsg('succeeded', 'index.php?action=admingroups');
}elseif($edit){
	$edit = ispage($edit) ? $edit : 0;
	$group = $db -> queryarray("SELECT * FROM {$tablepre}admingroups  WHERE adminid='$edit'");
	if(!$group){
		cpmsg('error');
	}
	if(!$group){
		cpmsg('error');
	}
	if(checksubmit('upgroup')){
		$db -> query("UPDATE {$tablepre}admingroups SET grouptitle = '$newgrouptitle',about='$newabout' WHERE adminid='$edit'");
		cpmsg('succeeded', "index.php?action=admingroups&edit=$edit");
		cache('admingroups');
	}else{
		include theme('admingroups_edit', 'themes/admin','admin');
	}
}else{
	$groups=array();
	$query = $db -> query("SELECT adminid, grouptitle, about FROM {$tablepre}admingroups");
	while($group = $db -> fetch_array($query)){
		$groups[$group['adminid']] = $group;
	}
	include theme('admingroups', 'themes/admin','admin');
}
?>