<?php
//引入语言包
$g_langpackage=new grouplp;

//变量区
$group_id=short_check(get_argg('group_id'));
$userid=short_check(get_argg('userid'));
$creat_group=get_sess_cgroup();

//权限判断
if(!preg_match("/,$group_id,/",$creat_group)){
	action_return(0,$g_langpackage->g_no_privilege,"-1");
}

//数据表定义
	$t_users=$tablePreStr."users";
	$t_groups=$tablePreStr."groups";
  $t_group_members=$tablePreStr."group_members";
  
//定义读操作
		dbtarget('r',$dbServs);	
		$dbo=new dbex();
		
//判断管理员是否已经为3个
		$sql="select group_manager_name,group_manager_id from $t_groups where group_id=$group_id";
		$manager_name=$dbo->getRow($sql);		
		
	  $group_manager_name=$manager_name['group_manager_name'];
	  $group_manager_id=$manager_name['group_manager_id'];
	  
	  if(count(explode(",",$group_manager_id))>=$set_manager_num+2)
	  {
		  	action_return(0,$g_langpackage->g_m_limit,"-1");
		}
	  	  
//取得委任管理员的名字	  
	  $sql="select user_name from $t_users where user_id=$userid";
	  $user_name=$dbo->getRow($sql);
	  $user_name=$user_name['user_name'];
	  
//定义写操作
	  dbtarget('w',$dbServs);	
	  $group_manager_name=empty($group_manager_name)?"|".$user_name."|":$group_manager_name.$user_name."|";
	  $group_manager_id=empty($group_manager_id)?",".$userid.",":$group_manager_id.$userid.",";	 
	   
	  $sql="update $t_groups set group_manager_name='$group_manager_name',group_manager_id='$group_manager_id' where group_id=$group_id";
	  $dbo->exeUpdate($sql);
	  
    $sql="update $t_group_members set role=1 where user_id=$userid&&group_id=$group_id";
    $dbo->exeUpdate($sql);
    
    $jump="modules.php?app=group_member_manager&group_id=$group_id";
    action_return(1,'',$jump);
?>

