<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="conn.asp"-->
<!--#include file="inc/Mo.Lib.Json.asp"-->
<%
dim muid,username,sign,avatar

muid = Session("Login_uid")
Set rs0 = Server.CreateObject("ADODB.Recordset")
rs0.Open "Select * From [jinke_user] where uid="&muid&" ",conn,1,1
username = rs0("uname")
sign = rs0("sign")
avatar = rs0("avatar")
	if isnull(avatar) or avatar = "" then
	avatar = "/theme/default/images/avatar.jpg"
	end if
rs0.Close
Set rs0 = Nothing

'set rs=server.createobject("adodb.recordset")
'sql="select fuid from layim_friends f where f.uid in (select g.id,g.gname from layim_group g where g.uid = "& uid &")"

dim init,data,mine,friend,group,list
set init = MoLibJson.new()
init.dateformat = "yyyy-MM-dd HH:mm:ss"
init.put "code","0" '//0表示成功，其它表示失败
init.put "msg","0"'//失败信息
set data = init.put("data")
'data.datatype="array"
data.dateformat="yyyy-MM-dd"
set mine = data.put("mine") '绑定自己信息
'mine.datatype="array"
mine.put "id",muid
mine.put "username",username
mine.put "status","online"
mine.put "sign",sign
mine.put "avatar",avatar
set friend = data.put("friend") '绑定好友信息 好友分组列表
	friend.datatype="array"
set grouprs=server.createobject("adodb.recordset")
groupsql = "select gid,gname from jinke_set_group"
grouprs.open groupsql,conn
if not grouprs.eof then '判断
do while not grouprs.eof '遍历
	set f = friend.put()
	'friend.datatype="array"
	dim gid,grounname
		gid =grouprs("gid")
		grounname = grouprs("gname")
	f.put "id",gid '分组id
	f.put "groupname",grounname '分组name
	f.put "online","" '在线人数
	set list = f.put("list") '分组下的列表
		list.datatype="array"
	set listrs = server.createobject("adodb.recordset")
	    listsql = "select u.uid,u.uname,u.sign,u.avatar from jinke_user u where u.ugroup ="& gid&" and u.uid <> "& muid '获取当前分组的好友列表
		listrs.open listsql,conn
		if not listrs.eof then '判断数组
			do while not listrs.eof '遍历
				set l = list.put()
				uid = listrs("uid")
				username = listrs("uname")
				sign = listrs("sign")
				avatar = listrs("avatar")
				l.put "id",uid
				l.put "username",username
				l.put "status","online"
				l.put "sign",sign
				if isnull(avatar) then
				avatar = "/theme/default/images/avatar.jpg"
				end if
				l.put "avatar",avatar
				
				listrs.movenext
			loop
		else
			response.write ""		
		end if
		'关闭记录集
		listrs.Close			
		'释放数据库连接
		Set listrs = Nothing	
	grouprs.movenext
loop
else
response.write '{"code": 0 ,"msg": "没有数据"}'
end if
'关闭记录集
grouprs.Close			
'释放数据库连接
Set grouprs = Nothing
conn.close
'输出json init
response.Write init.toString()
%>

