<?php

// 5.家园平台社会实践活动同步接口
require_once ("../user_include.inc");

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

//获取参数
$schoolNo = ParamUtil::getRequestString("schoolNo");
$classNo = ParamUtil::getRequestString("classNo");
$originalSource = ParamUtil::getRequestNumber("originalSource", 0);
$eventId = ParamUtil::getRequestNumber("eventId", 0);
$title = ParamUtil::getRequestString("title");
$author = ParamUtil::getRequestString("author");
$publishTime = ParamUtil::getRequestString("publishTime");
$content = ParamUtil::getRequestString("content");
$images = ParamUtil::getRequestString("images");

//参数检查
if(empty($schoolNo) || empty($originalSource) || empty($title) ||  $eventId <= 0) {
	responseNG("参数错误！");
}

//originalSource为1或者2
if($originalSource <> 1 && $originalSource <> 2) {
	responseNG("参数错误！");
}

//判断该活动是否已经存在
$param = array();
$param['school_no'] = $schoolNo;
$param['original_source'] = $originalSource;
$param['event_id'] = $eventId;
$param['delete_flg'] = false;
$familyEventList = FamilyEventDat::getList($param,'id','desc', 0, 1);
if(empty($familyEventList)) {
	$familyEventList = new FamilyEventDat();
	$familyEventList->school_no = $schoolNo;
	$familyEventList->class_no = $classNo;
	$familyEventList->original_source = $originalSource;
	$familyEventList->event_id = $eventId;
	$familyEventList->title = $title;
	$familyEventList->author = $author;
	$familyEventList->publish_time = $publishTime;
	$familyEventList->content = $content;
	$familyEventList->images = $images;
	$familyEventList->save();
} else {
	$familyEventList = $schoolList[0];
	$familyEventList->title = $title;
	$familyEventList->author = $author;
	$familyEventList->publish_time = $publishTime;
	$familyEventList->content = $content;
	$familyEventList->images = $images;
	$familyEventList->save();
	$familyEventList->save();
}

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

responseOK("更新成功！");

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