<?php
//引入模块公共方法文件
require("foundation/adata_count.php");
require("foundation/arecent_affair.php");
require("foundation/module_users.php");

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

//变量区
	$user_id=get_sess_userid();
	$group_id=short_check(get_argg('group_id'));
	$userid=short_check(get_argg('userid'));	
	$type=short_check(get_argg('type'));
	
//数据表定义
	$t_groups=$tablePreStr."groups";
  $t_group_members=$tablePreStr."group_members";  
  $t_users=$tablePreStr."users";	
  
//定义读操作
	dbtarget('r',$dbServs);
	$dbo=new dbex();	
	
//引入公共函数
	require("foundation/module_group.php");

//权限判断
	$role=pri_limit($dbo,$user_id,$group_id);
	if($role==2){
	action_return(0,"$g_langpackage->g_no_privilege","-1");
	}
	
//取得被批准组员的信息
$user_info=get_user_info($dbo,$t_users,$userid);
$user_join_group=$user_info['join_group'];
$user_join_group=empty($user_join_group)? ",".$group_id.",":$user_join_group.$group_id.",";

//取得群组信息
$group_info=get_group_info($dbo,$t_groups,$group_id);
	
//定义写操作
	dbtarget('w',$dbServs);
	
	$group_r_id=preg_replace("/,$userid,/",",",$group_info['group_req_id']);
	
	$sql="update $t_group_members set state=1 where group_id=$group_id&&user_id=$userid";
	$dbo->exeUpdate($sql);
	
  $sql="update $t_groups set member_count=member_count+1,group_req_id='$group_r_id' where group_id=$group_id";
  $dbo->exeUpdate($sql);
  
//更新用户表
	$sql="update $t_users set join_group='$user_join_group' where user_id=$userid";
	$dbo->exeUpdate($sql);

  //刷新提醒页面
        echo "<script type='text/javascript'>
  parent.frames['remind'].location.reload();
  </script>";

  
  //纪录新鲜事
	set_ugroup_log($dbo,$userid,$user_info['user_name'],$user_info['user_ico'],$ugroup_joined_affair_log,$group_info['group_id'],$group_info['group_name']);
	update_count($dbo,$userid,"group_num",1);
	if(isset($type)&&$type=="remind"){
		$jump="modules.php?app=remind_group&group_id=".$group_id;
		action_return(1,"",$jump);
	}else{
		$jump="modules.php?app=group_member_manager&group_id=".$group_id;
		action_return(1,"",$jump);		
		}

?>

