<?php

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

ErrorLogger::doOutput("Compass...synchronize_social_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;
$socialEventList = SocialEventDat::getList($param,'id','desc', 0, 1);
if(empty($socialEventList)) {
	$socialEventList = new SocialEventDat();
	$socialEventList->school_no = $schoolNo;
	$socialEventList->class_no = $classNo;
	$socialEventList->original_source = $originalSource;
	$socialEventList->event_id = $eventId;
	$socialEventList->title = $title;
	$socialEventList->author = $author;
	$socialEventList->publish_time = $publishTime;
	$socialEventList->content = $content;
	$socialEventList->images = $images;
	$socialEventList->save();
} else {
	$socialEventList = $schoolList[0];
	$socialEventList->title = $title;
	$socialEventList->author = $author;
	$socialEventList->publish_time = $publishTime;
	$socialEventList->content = $content;
	$socialEventList->images = $images;
	$socialEventList->save();
	$socialEventList->save();
}

ErrorLogger::doOutput("Compass...synchronize_social_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;
}
?>