<?php

// 获取指定圈子首页信息
require_once ("../user_include.inc");

ErrorLogger::doOutput("Compass...ajax_get_circle_info.php....Start.", 0);

//获取参数
$unionId = ParamUtil::getRequestString("unionId");
$circleId = ParamUtil::getRequestNumber("circleId", 0);//圈子id

$result = array();

//参数检查
if(empty($unionId) || empty($circleId)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}

$result = array();

//判断用户是否存在
$param = array();
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$userList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($userList)) {
	$result["message"] = "用户不存在！";
	responseNG($result);
}
$userMst = $userList[0];

//判断圈子是否存在
$circleDat = CircleDat::getById($circleId);
if(empty($circleDat)) {
	$result["message"] = "圈子不存在！";
	responseNG($result);
}

$isOwner = false;
if($circleDat->owner_id == $userMst->id) {
	$isOwner = true;
}

$noticeDat = null;
//获取圈子最新一条公告信息
$param = array();
$param['circle_id'] = $circleDat->id;
$param['delete_flg'] = false;
$tmpList = CircleNoticeDat::getList($param, "id", "desc", 0, 1);
if(!empty($tmpList)) {
	$noticeDat = $tmpList[0];
}


ErrorLogger::doOutput("Compass...ajax_get_circle_info.php....End.", 0);

//返回结果
$result["isOwner"] = $isOwner;
$result["circleDat"] = $circleDat;
$result["noticeDat"] = $noticeDat;
responseOK($result);

function responseNG($result) {
	$result = array("status"=>"NG", "result"=>$result);
	print json_encode($result);
	exit;
}
function responseOK($result) {
	$result = array("status"=>"OK", "result"=>$result);
	print json_encode($result);
	exit;
}
?>