<?php
/**
 * 学校管理编辑完成
 * $Id: school_edit_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("3")) {
	// エラー表示
	$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;
}

// 参数取得
$id = ParamUtil::getRequestString("id");
$comment = ParamUtil::getRequestString("comment");
$address = ParamUtil::getRequestString("address");
$province = ParamUtil::getRequestString("province");
$city = ParamUtil::getRequestString("city");
$district = ParamUtil::getRequestString("district");
$street = ParamUtil::getRequestString("street");
$longitude = ParamUtil::getRequestString("longitude");
$latitude = ParamUtil::getRequestString("latitude");

$school_mst = SchoolMst::getById($id);
if ($school_mst == null) {
  // エラー表示
  $message = "对象不存在。";
  $layout_pages = array();
  $layout_pages["left"] = "menu.inc";
  $layout_pages["right"] = "error.inc";
  $layout_pages["menu_clicked"] = "1-1";
  require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
  exit;
}

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();
  $aliHandler->delete(substr ( $school_mst->front_image, strrpos ( $school_mst->front_image, "/" ) + 1 ));
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  $school_mst->front_image = $url;
}

$school_mst->comment = $comment;
$school_mst->address = $address;
$school_mst->province = $province;
$school_mst->city = $city;
$school_mst->district = $district;
$school_mst->street = $street;
$school_mst->longitude = $longitude;
$school_mst->latitude = $latitude;
$school_mst->save();

// 页面表示
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "school_edit_result.inc";
$layout_pages["menu_clicked"] = "1-1";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;