<?php
/**
 * 活动发布完成
 * $Id: event_publishing_result.php,v 1.1 2020/01/03 11:18:46  Exp $
 * @author lixq
 * @package manager.public_html
 */
// 底层包含
require_once("manager_include.inc");

// 登录检查
require_once("check_login.inc");

// 权限检查
if (!checkAuthority("14")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["left"] = "menu.inc";
	$layout_pages["right"] = "error.inc";
	$message = "权限不足，请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
	exit;
}

// 参数取得
$title = ParamUtil::getRequestString("title");
$comment = ParamUtil::getRequestString("comment");
$position = ParamUtil::getRequestString("position");
$position_longitude = ParamUtil::getRequestString("position_longitude");
$position_latitude = ParamUtil::getRequestString("position_latitude");
$scope = ParamUtil::getRequestArray("scope", array());
$province = ParamUtil::getRequestString("province");
$city = ParamUtil::getRequestString("city");
$district = ParamUtil::getRequestString("district");
$max_member_flg = ParamUtil::getRequestString("max_member_flg");
$max_member = ParamUtil::getRequestNumber("max_member");
$start_time = ParamUtil::getRequestString("start_time");
$finish_time = ParamUtil::getRequestString("finish_time");
$time_length = ParamUtil::getRequestString("time_length");
$enroll_time = ParamUtil::getRequestString("enroll_time");
$leader_name = ParamUtil::getRequestString("leader_name");
$leader_contact = ParamUtil::getRequestString("leader_contact");
$venue = ParamUtil::getRequestString("venue");
$venue_time = ParamUtil::getRequestString("venue_time");
$author= ParamUtil::getRequestString("author");

$volunteer_event_dat = new VolunteerEventDat();
$volunteer_event_dat->title = $title;
$volunteer_event_dat->comment = $comment;
$volunteer_event_dat->start_time = $start_time;
$volunteer_event_dat->finish_time = $finish_time;
$volunteer_event_dat->enroll_time = $enroll_time;
$volunteer_event_dat->position = $position;
$volunteer_event_dat->position_latitude = $position_latitude;
$volunteer_event_dat->position_longitude = $position_longitude;
$volunteer_event_dat->account_id = $_account->id;
if(empty($author)){
  $volunteer_event_dat->author = $_account->name;
}else{
  $volunteer_event_dat->author = $author;
}
$volunteer_event_dat->author_role = $_account->role;
if($_account->school_id != 0){
  $school_mst = SchoolMst::getById($_account->school_id);
  $volunteer_event_dat->school_no = $school_mst->school_no;
  $volunteer_event_dat->original_source = $school_mst->original_source;
}
if(in_array("school", $scope)){
  if($_account->user_id != 0){
    $user_mst = UserMst::getById($_account->user_id);
    $volunteer_event_dat->province = $user_mst->province;
    $volunteer_event_dat->city = $user_mst->city;
    $volunteer_event_dat->district = $user_mst->district;
  }else if($_account->school_id != 0){
    $school_mst = SchoolMst::getById($_account->school_id);
    $volunteer_event_dat->province = $school_mst->province;
    $volunteer_event_dat->city = $school_mst->city;
    $volunteer_event_dat->district = $school_mst->district;
  }else if($_account->government_id != 0){
    $government_mst = GovernmentMst::getById($_account->government_id);
    $volunteer_event_dat->province = $government_mst->province;
    $volunteer_event_dat->city = $government_mst->city;
    $volunteer_event_dat->district = $government_mst->district;
  }else {
    $volunteer_event_dat->province = $province;
    $volunteer_event_dat->city = $city;
    $volunteer_event_dat->district = $district;
  }
}else if(in_array("social", $scope)){
  $volunteer_event_dat->include_social_user = true;
}
if($max_member_flg == "2"){
  $volunteer_event_dat->max_member = $max_member;
}
$volunteer_event_dat->time_length = $time_length;
$volunteer_event_dat->leader_name = $leader_name;
$volunteer_event_dat->leader_contact = $leader_contact;
$volunteer_event_dat->venue = $venue;
$volunteer_event_dat->venue_time = $venue_time;
$volunteer_event_dat->status = "NEW";

if(!empty($_FILES['front_image']['tmp_name'])){
  $upload_file = FileUploadUtil::getScalarFile(@$_FILES["front_image"]);
  $tmp_file_name = date("YmdHis") . "_" . trim(basename($upload_file->name));
  
  $aliHandler = new AliUploadHandler();
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  $volunteer_event_dat->front_image = $url;
}
$volunteer_event_dat->save();

// ページ
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "event_publishing_result.inc";
$layout_pages["menu_clicked"] = "3-2";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;