<?php
/**
 * 证书管理编辑
 * $Id: certificate_edit_result.php,v 1.1 2015/10/08 11:18:46 wanggb Exp $
 * @author lixq
 * @package manager.public_html
 */

// 底层包含
require_once("manager_include.inc");

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

// 权限检查
if (!checkAuthority("12")) {
	// エラー表示
  $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;
}

// 参数取得
$action_type = ParamUtil::getRequestString("action_type");//new edit
$id = ParamUtil::getRequestString("id");
$title = ParamUtil::getRequestString("title");

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 ( $tmp_file_name, "/" ) + 1 ));
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  $school_mst->front_image = $url;
}
//创建的时候
if($action_type=="new") {
  $certificate_mst = new CertificateMst();
}

//编辑
if($action_type=="edit") {
  $certificate_mst = GradeMst::getById($id);
  if ($certificate_mst == null) {
		// エラー表示
		$layout_pages = array();
		$layout_pages["left"] = "menu.inc";
		$layout_pages["right"] = "error.inc";
		$layout_pages["menu_clicked"] = "5-4";
		require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
		exit;
	}
}

// 数据库更新
$certificate_mst->title = $title;
$certificate_mst->save();

// 跳到一览页
header("Location:certificate_list.php");
exit;